### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Why do we use binary logic in programming languages?  (Read 1053 times)

#### Peter H

• Full Member
• Posts: 197
##### Why do we use binary logic in programming languages?
« on: April 08, 2021, 05:08:06 am »
Because a Boolean is a byte, we could instead use quad Logic this has four values:

true,false,undetermined, dont care.

This is fully compatible to binary logic, but practically problems can be expressed much more compact and clear.

#### Martin_fr

• Hero Member
• Posts: 7020
• Debugger - SynEdit - and more
##### Re: Why do we use binary logic in programming languages?
« Reply #1 on: April 08, 2021, 05:23:01 am »
Feel free to create an enum, and overload operators as needed and possible....

Also "Boolean is a byte" is mislead, if not wrong. Boolean can be stored in a byte. But when bitpacked (array/record) it can be stored in a single bit.
There is also the possibility to store it in a word, longword, or quadword.

Boolean is a concept. Storage is something added by implementation.

As for other concepts, there are languages that bring in undefined and/or null. And not just for booleans, but for other types too.

#### avra

• Hero Member
• Posts: 2144
##### Re: Why do we use binary logic in programming languages?
« Reply #2 on: April 08, 2021, 09:40:27 am »
This is fully compatible to binary logic, but practically problems can be expressed much more compact and clear.
Search the net for fuzzy logic. It's fun, very powerful and has wide appliance potential. You'll like it, I promise.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

#### MarkMLl

• Hero Member
• Posts: 2400
##### Re: Why do we use binary logic in programming languages?
« Reply #3 on: April 08, 2021, 09:51:24 am »
Search the net for fuzzy logic. It's fun, very powerful and has wide appliance potential. You'll like it, I promise.

I suppose that an answer to the "why" question is that we were building electrical switching circuits using relays a long time before we had electronics which could generate and compare voltage levels accurately.

There were obviously mechanical analysers/integrators of various types, but they were used to solve numerical calculations rather than for control purposes. I suppose that at a pinch we could call cam-based control systems non-binary, but by and large they didn't have a precise computerised equivalent.

/Technically/, Babbage could have built a relay-based computer in about 1850. In practice, it would not have been possible to get it to operate fast enough.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

#### Bart

• Hero Member
• Posts: 4224
##### Re: Why do we use binary logic in programming languages?
« Reply #4 on: April 08, 2021, 11:54:03 am »
The classic True, False, FileNotFound.

I have a Boolean factory which has support for True, False, Maybe (it compensates for the uncertainty principle in quantum mechanics).
I can give you the url if you need it.

Bart

#### Fred vS

• Hero Member
• Posts: 2196
##### Re: Why do we use binary logic in programming languages?
« Reply #5 on: April 08, 2021, 12:12:33 pm »
Hello.

I propose to switch from binary to ternary.

It is much more natural than binary.

For example, to store data in a hard disk, with binary 0 = one part no magnetic of the disk and 1 = magnetic.

But with ternary, you can store much more infos with the same place, for example with magnet, 0 = no magnetic, 1 = magnet North-South, 2 = South-North.

The same with electricity, 0 = no current, 1 = negative, 2 = positive.

Fre;D

I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

#### MarkMLl

• Hero Member
• Posts: 2400
##### Re: Why do we use binary logic in programming languages?
« Reply #6 on: April 08, 2021, 12:26:39 pm »
Don't forget spin: you can store twice as much info if you reverse the direction of the disc's rotation.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

#### Fred vS

• Hero Member
• Posts: 2196
##### Re: Why do we use binary logic in programming languages?
« Reply #7 on: April 08, 2021, 12:38:32 pm »
Don't forget spin: you can store twice as much info if you reverse the direction of the disc's rotation.

MarkMLl

Yes, of course, you may also store the info modulated, for example, 0 = 0 % magnet, 1 = 50 % magnet, 2 = 100 %, to keep simple and stay with ternary.
(But you may imagine base much bigger than ternary)

About the spin, yes but concretely, it will take some time for the disk to reverse the rotation, so ok, more data but slower access.
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

#### MarkMLl

• Hero Member
• Posts: 2400
##### Re: Why do we use binary logic in programming languages?
« Reply #8 on: April 08, 2021, 12:42:39 pm »
That can be accommodated by duplicating the r/w logic using positronic circuitry, which has concomitant time-reversal. Balance your data and the rotational latency averages to zero.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

• Hero Member
• Posts: 10729
##### Re: Why do we use binary logic in programming languages?
« Reply #9 on: April 08, 2021, 12:50:36 pm »
I already published ternary and fuzzy logic on this forum.
See here:

https://forum.lazarus.freepascal.org/index.php/topic,41144.msg290876.html#msg290876
https://forum.lazarus.freepascal.org/index.php/topic,41144.msg295325.html#msg295325 and the Zadeh fuzzer in the next post.

I also posted a five way logic.:
https://forum.lazarus.freepascal.org/index.php/topic,41144.msg290987.html#msg290987

I did do quite some improvements later, but these are the basics. Can put it in a library if you want and submit to the RTL maintainers.

These can all be basic on bit packed sets as well, except Zadeh's classic fuzzer.
« Last Edit: April 08, 2021, 01:07:52 pm by Thaddy »

#### Fred vS

• Hero Member
• Posts: 2196
##### Re: Why do we use binary logic in programming languages?
« Reply #10 on: April 08, 2021, 01:28:18 pm »
I already published ternary and fuzzy logic on this forum.
See here:

https://forum.lazarus.freepascal.org/index.php/topic,41144.msg290876.html#msg290876
https://forum.lazarus.freepascal.org/index.php/topic,41144.msg295325.html#msg295325 and the Zadeh fuzzer in the next post.

I also posted a five way logic.:
https://forum.lazarus.freepascal.org/index.php/topic,41144.msg290987.html#msg290987

I did do quite some improvements later, but these are the basics. Can put it in a library if you want and submit to the RTL maintainers.

These can all be basic on bit packed sets as well, except Zadeh's classic fuzzer.

OK, perfect, so we are ready for the software conversion from binary to ternary.

It just lacks the hardware .

Imho, the first thing to do is to build a cpu and ram ternary.

Those elements use electricity to represent the binary base ( 0 = no current, 1 = current).
For ternary, what do you prefer,  0 = no current, 1 = positive, 2 = negative or do you prefer modulated, 0 = no current, 1 = 50%, 2 = 100% ?

I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

• Hero Member
• Posts: 10729
##### Re: Why do we use binary logic in programming languages?
« Reply #11 on: April 08, 2021, 01:35:50 pm »
I'd prefer -1,0,1 so it becomes balanced.
This has an advantage for ternary in the sense that some logic can be easier defined from mixed operators..
Therefor I used F,U,T in the lookups (which are bitpacked in later versions)
« Last Edit: April 08, 2021, 01:43:56 pm by Thaddy »

#### Fred vS

• Hero Member
• Posts: 2196
##### Re: Why do we use binary logic in programming languages?
« Reply #12 on: April 08, 2021, 01:43:19 pm »
I'd prefer -1,0,1 so it becomes balanced.
This has an advantage for ternary

The same here.

And for the future, when our ternary system will be the default, we can easy create a multinary OS, with a modulated current using a sine (from -1 to 1).
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

• Hero Member
• Posts: 10729
##### Re: Why do we use binary logic in programming languages?
« Reply #13 on: April 08, 2021, 01:53:55 pm »
with Zaheh's logic you can easily get waveform representations.
In effect it is multinary. (I used it in a couple of VST plugins)

BTW SETUN is a ternary hardware...
See https://en.wikipedia.org/wiki/Setun
« Last Edit: April 08, 2021, 02:18:33 pm by Thaddy »

#### Bart

• Hero Member
• Posts: 4224
##### Re: Why do we use binary logic in programming languages?
« Reply #14 on: April 08, 2021, 06:21:08 pm »
Don't forget spin: you can store twice as much info if you reverse the direction of the disc's rotation.

Don't use the spin of the disk, it's too slow.
Use the quantum mechanical spin (now you also have halve spin's as a bonus).

Bart