by mcdonje · 6mo ago · 0 comments
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...
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...
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...
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>.
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.
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.
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.
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)
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_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.
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.
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 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/1wfdtsuaavI 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
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.
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.
The author also made a more approachable miniseries in Russian: https://habr.com/ru/articles/496366/
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.