Hacker News new | ask | show | jobs
by mcdonje 27 days ago
In one respect, boolean logic is popular because of bits. If we had ternary processors, ternary logic would be more popular.

In another respect, boolean logic is popular because it's easy to reason about. The truth tables are relatively small in size and quantity. Not the case with ternary.

Ternary is probably way better at modeling the real world, but the complexity could make code hard to understand. Maybe that can be solved.

That said, boolean logic is more expressive than I think the blog post gives it credit for because it's usually only a part of the code. Like, it gets used a lot in SQL, where you're reasoning about with several columns. So, yeah, it's binary thinking on each dimension, but there are N dimensions.

The alternative presented is intuitionist logic, which is practically what in the computing world? Where is it used? Or where could or should it be used? I guess it can be represented in lamba calculus...

8 comments

> The alternative presented is intuitionist logic, which is practically what in the computing world? Where is it used? Or where could or should it be used?

The Curry-Howard correspondence[1] tells us that every function is a proof (in the intuitionistic sense) of the proposition represented by its return type, given the axioms ("context" in the article) represented by its arguments.

This fact is leveraged heavily by proof assistants (as mentioned in the article), but is generally useful in any statically-typed programming language.

[1]: https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspon...

The Curry-Howard correspondence formal relationship between intuitionistic logic and typed lambda calculus.

Intuitionistic logic doesn’t hold PEM as a priori.

Due to many issues like [0] you actually lose the univalent in HoTT.

That is what allows you to say two programs are equivalent by behavior.

No comment on the OP, but be careful as it is a rabbit hole.

[0] https://ncatlab.org/nlab/show/Diaconescu-Goodman-Myhill+theo...

Fuzzy logic may be one approximation. Analog processors may be another.
Did you reply to the wrong comment? I don't see how this relates to what I wrote.
In one respect, boolean logic is popular because of bits. If we had ternary processors, ternary logic would be more popular.

Ternary truth values combines two dependent binary questions - do we know the truth value of X and what is the truth value of X. The second one is meaningless if the first one is false. You can merge the two binary values into one ternary unknown, true, and false but this does not really change much. Depending on the context one or the other might be easier to work with. Option types generalize this, there is always a binary choice between the value is known or unknown, and if it is known, then there will also be the actual value. A ternary logic value is just Maybe<Boolean>.

The known/unknown question is not separate in the real world, computing avoids it by asking binary questions only when they’re answerable. Considered generally, though, if I ask a true/false question then read your answer from a single bit, it may be the case that there is no possible way for you to not lie to me.
Which is exactly what I wrote. [...] two dependent binary questions [...] The second one is meaningless if the first one is false.

Considered generally, though, if I ask a true/false question then read your answer from a single bit, it may be the case that there is no possible way for you to not lie to me.

Then you are not asking a binary question. If there is, for example, the possibility that I might not know the answer, then you are actually asking two dependent questions - do you know the answer and if so, what is the answer.

Have you stopped beating your wife?
Two question, have you ever beaten your wife, if so, did you stop? You can not stop something that never started. Alternatively, if you know from context that the wife has been beaten in the past, then yes or no are perfectly fine as the only options.

That question is obviously made as a trap because you can defend both answers. Yes, I am not beating her and actually never have, focusing on the current state. No, I did not stop because I never started, focusing on the state change. And the other party can do the same. No, so you did not stop beating your wife, so you are beating her. Yes, so you stopped beating your wife, then must have beaten here in the past.

The correct response is of course that the question is not applicable because it assumes a state - the wife has been beaten in the past - that does not match reality. And not applicable is not a third answer to the question, it is a statement about the question itself. So in contexts where non-applicable binary question might occur, you have to first determine whether the question is applicable before proceeding to answer the question.

As a specific example. If I ask the true/false question "Have you stopped murdering people?" an entirely valid response is "that question is wrong"

It is reasonable to map the world in binary logic. but the map logic must be correct and raising an error when it is not is important.

The crucial point here is the difference between response and answer. Saying that the question is not applicable because you never started murdering people is a response but not an answer to the question. And that response answers an omitted binary question, is the actual question applicable in the current context, is the implied assumption - you started murdering people at some point in the past - satisfied?
Some of us have (balanced) ternary processors. Not even emulated on FPGAs anymore, somewhat more coarse ASIC, without all the IO, just PCIe. They aren't publically available, though.

OTOH there is stuff like this planned to launch, which may compensate that lack of commercial availability somewhat:

https://news.ycombinator.com/item?id=48177736

Though it's not ternary per se, it could be seen as several steps further above that.

Actually "fun fact" we use something "kinda like" boolean logic, but distinct of the original "Prototypical BL" https://en.wikipedia.org/wiki/Two-element_Boolean_algebra

It has 2 operators: + and x (or more commonly: dot (.) - but this is more confusing on HN)

Also both + and x operations distribute, so A+(BxC) = (A+B)x(A+C)

> If we had ternary processors, ternary logic would be more popular.

Why? Boolean logic is older than its namesake, George Boole (1815-1864). Syllogisms are ancient. And we've had ternary systems, as well as others.

And what does the third value represent? True and false are pretty universal when it comes to predicates, but anything in between is rather subjective.

    enum Bool
    { 
        True, 
        False, 
        FileNotFound 
    };
https://thedailywtf.com/articles/What_Is_Truth_0x3f_
According to one of my clients that I have doing database development over the last 15 years, that 3rd value would be 'maybe'. Frustrated me to no end during development in the early years.
A bool can be represented by a single bit. A tern(?) takes 2 bits or 1 trit to represent. Alternatively, a bool takes a trit to represent.

So, in terms of radix economy, ternary computing is the most efficient, but you're leaving information density unused if you use it for binary, and representing ternary with binary is inherently inefficient.

The third value could map to "mu" [1], or "unask the question".

[1] https://en.wikipedia.org/wiki/Mu_(negative)

generally a sort of Unknown though it depends on the formulation.

https://en.wikipedia.org/wiki/Three-valued_logic

It can also map unto "maybe", which opens another can of worms.

Not that there's anything wrong with having an extra value "unknown", but it doesn't fundamentally alter the logic. As unknown in most cases means "it will be true or false at some point", its usage in computing is that of a singleton (who needs a word with 64 potentially unknown bits?), so dealing with unknown values as an exception is easier than permeating hardware with it. Using ternary to represent unknown is just not efficient.

> Like, it gets used a lot in SQL

Except it explicitly is not strictly Boolean in SQL because of nulls.

X = Y can take the value true, false or null if either or both X and Y are null.

I thought about mentioning nulls, but it's a complicated subject. Not all columns are nullable. Null handling rules differ. It's not always ISO/ANSI.
From an information theory perspective, the most efficient base for computations would be e (2.718). And trinary is closer than binary.
I have an axe to grind. Radix economy makes a shallow argument when calculating the wrong per-digit information cost.

I need some functions to show what I mean. Calculate logarithms, calculate the number of digits, and convert a base-n unit of information into base-2 units of information. Finally, calculate the information cost: the number of digits, times the information needed per digit.

  import ln, floor
  define log := (num,base) -> ln(num) / ln(base)
  define digits := (num,base) -> floor(log(num,base) + 1)
  define tobits := (base) -> log(base,2)
  define infocost := (num,base) -> digits(num,base) * tobits(base)
  define infocost_wikipedia := (num,base) -> digits(num,base) * base
  define infocost_tbwtc := (num, base) -> (digits(num,base) - 1) * tobits(base) + tobits(base- 1)
https://www.desmos.com/calculator/1wfdtsuaav

I define a logarithmic per-digit information cost, following information theory. For example, 1 trit = log(3,2) bits. This results in no advantage for any base (in which case, choose base 2).

Wikipedia uses a linear per-digit information cost equal to the base. This holds when communicating options takes linear time (Wikipedia's example of a phone menu). This results in advantage for base e (in which case, choose base 3).

The video "The Best Way To Count" uses the logarithmic digit cost, and also notes that the leading digit carries less information (it excludes 0, like a IEEE floating point mantissa). This results in advantage for base 2.

Therefore, know the context to apply the right cost analysis!

https://en.wikipedia.org/wiki/Optimal_radix_choice

https://en.wikipedia.org/wiki/Talk:Optimal_radix_choice#Why_...?

https://en.wikipedia.org/wiki/Talk:Optimal_radix_choice#Bina...

https://youtu.be/rDDaEVcwIJM?t=701 timestamp 11:41

I still don't get what is being optimized for to get e as the answer
Optimizing for "radix economy", an argument that attempts to balance the digit cost against the choice of base. When the cost per digit equals the base, e turns out optimal. But when the cost per digit equals the digit's information content (bit, trit, etc; 1 trit = log(3,2) bits), all bases turn out about equal.

https://en.wikipedia.org/wiki/Optimal_radix_choice

True. Radix economy.
> Ternary is probably way better at modeling the real world, but the complexity could make code hard to understand. Maybe that can be solved.

Is it not true that the brain process in ternary?

From the point of view of perception, I believe that we process the world in terms of pairwise comparisons. For example, the atomic indivisible of visual processing is figure/ground separation.

Yes. In opposites and in lack of data (null). Ternary thus fits better.

Back in ancient CS classes my prof said that was a Russian attempt of building ternary processors with +1, 0, -1 represented as voltages.

Another strike in for-ternary column is that it's the most efficient in the number of digits for representing numbers. Pi is optimally efficient but non-integer bases would break anyone's brain, I think.

Here's a link documenting a the creation of a DIY ternary computer https://hackaday.io/project/28579-homebrew-ternary-computer

The author also made a more approachable miniseries in Russian: https://habr.com/ru/articles/496366/

I thought e was optimal
Let's just skip to quantum which models the "real" world in "real" terms.
No. Neurons are 'aggregate and fire', and they either fire or they do not.
The brain doesn't do any of that. The brain is neural goo.

It can arduously crank through simple logic problems with its ludicrously tiny memory (around 8 bytes). Everything else is intuition and guesswork.

You can try to model those heuristics with various logics. Some logics work better in certain situations. Classical first order logic is actually really bad at modeling brain work, but it's simple to automate, so we use it even where it's wildly inappropriate.