### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

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

#### Thaddy

• Hero Member
• Posts: 10785
##### Re: Why do we use binary logic in programming languages?
« Reply #15 on: April 08, 2021, 09:26:08 pm »
Bart,
My five way logic can be used to model QBits (including spin)

#### dseligo

• Full Member
• Posts: 238
##### Re: Why do we use binary logic in programming languages?
« Reply #16 on: April 09, 2021, 09:21:52 am »
And 'if', 'while' and 'repeat ... until' must be extended then.

Code: Pascal  [Select][+][-]
1. if (ternary_expression) then
2. begin
3.   // expression is true
4. end
5. else
6. begin
7.   // expression is false
8. end
9. unknown
10. begin
11.   // expression is unknown
12. end;

But how is while and repeat..until supposed to work with ternary expressions?

#### Thaddy

• Hero Member
• Posts: 10785
##### Re: Why do we use binary logic in programming languages?
« Reply #17 on: April 09, 2021, 11:19:08 am »
I would write a case instead of if then.
And since a ternary operation can be compared to the ternary value and as such translates to a normal boolean there is no problem with loops that need a Boolean value to resolve.
Code: Pascal  [Select][+][-]
1. repeat
2. //do something that sets a ternary value
3. until ternaryvalue=T{ternarytrue}
Comparison is the key....that leads to a normal Boolean.
« Last Edit: April 09, 2021, 11:27:20 am by Thaddy »

#### dseligo

• Full Member
• Posts: 238
##### Re: Why do we use binary logic in programming languages?
« Reply #18 on: April 09, 2021, 12:56:20 pm »
I would write a case instead of if then.
And since a ternary operation can be compared to the ternary value and as such translates to a normal boolean there is no problem with loops that need a Boolean value to resolve.
Code: Pascal  [Select][+][-]
1. repeat
2. //do something that sets a ternary value
3. until ternaryvalue=T{ternarytrue}
Comparison is the key....that leads to a normal Boolean.
IOW, the normal Boolean is still base. Language doesn't know about ternary logic (in it's core).
As I am concerned, I hope it will stay as it is. I don't know what what be result of
Code: Pascal  [Select][+][-]
1. true or unknown
or
Code: Pascal  [Select][+][-]
1. true and unknown
.

What whould be result of
Code: Pascal  [Select][+][-]
1. not unknown
?

Also unknown, true or false?

#### Thaddy

• Hero Member
• Posts: 10785
##### Re: Why do we use binary logic in programming languages?
« Reply #19 on: April 09, 2021, 01:12:27 pm »
Also unknown, true or false?
At least for the logic I used (Kleene and Priest), the theory for that is clearly defined.
https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_logic. See the table:
not U equals U by definition. That means that a translation to boolean always results in true given both sides of a negation comparison.

It is firmly established mathematical theory and not computer science.The latter can be used for an implementation of the logic.

The theory is well explained in the link I gave you.
After all logically not u equals any other u and u so a comparison in trits from u and not u is always true, because it is u..which is boolean true.

Most other ternary logics do exactly or close to the same.
Try to understand the presented truth tables. I based all my code on that.
« Last Edit: April 09, 2021, 01:33:41 pm by Thaddy »

#### y.ivanov

• Jr. Member
• Posts: 98
##### Re: Why do we use binary logic in programming languages?
« Reply #20 on: April 10, 2021, 09:45:02 pm »
Actually, because it is the simplest one.

Regards,