# How would one use “BUT” logic in a ternary logic computer in a practical way?

Using three valued logic one can define a multitude of ternary operations. When dealing with 5:3:1[1] operations, its very easy to see how OR and AND work, but I'm confused as to how ternary BUT is supposed to be useful. As mentioned here in TriINTERCAL's[4] docs the truth table for ternary BUT is as follows:

BUT(True, True) = True
BUT(False, True) = False
BUT(False, False) = False
BUT(True, False) = False
BUT(Unknown, x) = Unknown   for all x


This is a 5:3:1 operation, as out of the 9 possible cases, 1 of those leads to True, 3 lead to False, and 5 to Unknown.

How could such an operation be used in practice (either on single trits[2] or multiple trytes[3])?

The individual who created the Tunguska ternary computer emulator claims that other people found BUT a useful operation coming from TriINTERCAL, even though the author of TriINTERCAL mentions that they don't seem to be useful.

[1] 5:3:1 operations are what you call binary ternary operations where the 9 possible values of the operations are split up like so among True, False, and Unknown, but not necisarily in that order.

[2] A trit is a ternary bit. A trit holds the value 0,1,2, or False, Unknown, True.

[3] A tryte is a ternary byte. Though the value can vary, it is typically 6 trits (3^6 possible values = 729, so more than a byte).

[4] TriINTERCAL is a programming language based off of INTERCAL that utilizes ternary logic instead of binary.

• Quoting from the Wikipedia article on TriINTERCAL, "BUT and sharkfin aren't really that useful". TriINTERCAL is (probably) a language invented to be useful, but as a parody (see the Wikipedia article on INTERCAL). – Yuval Filmus Aug 11 '17 at 20:30
• If I'm correct, any ternary operation between two variables can be reduced to binary function of 4 variables. So, I don't see any usability. – rus9384 Aug 11 '17 at 20:41
• @YuvalFilmus tunguska.sourceforge.net claims that people found this useful (and he specifically kept it because of people who used it in TriINTERCAL found it useful), I should probably edit that in the post though. – whn Aug 11 '17 at 20:43
• @D.W. Ok, that makes sense. Also To clarify I'm asking how an operator like BUT would be useful at all, as of now I have no idea how it could be applied in a practical way. An answer that gave just one use of BUT would be good enough, I feel that is answerable and not overly broad. Also I don't think I was trying to elaborate on any points from my post in the comments as far as I can tell, I'd like to know where you thought that was happening. – whn Aug 12 '17 at 2:46

In the article "The A-Z of Programming Languages: INTERCAL" Naomi Hamilton (Techworld Australia) interviews Don Woods, one of the authors of INTERCAL. More about INTERCAL.

On page 3 of the article the last question is:

Naomi: "Is there anything else you'd like to add?"

Don: "... Much of the fun of INTERCAL comes from figuring out how it can be used to do something that would be trivial in other languages. More fun is had by extending the language with weird new features and then figuring out what can be done by creative use of those features."

Apparently the authors of TriINTERCAL took the spirit of the language to heart, yet avoided adding an entirely useless operation.

TriINTERCAL differs from INTERCAL only in the width of the data types (one-spot data types are 10 trits wide and two-spot data types are 20 trits wide), and in the operators available in expressions. "AND" and "OR" are generalizations of the INTERCAL binary versions, "BUT" is new, and "Sharkfin" and "What" are two different interpretations of "XOR" (both of which are available in TriINTERCAL). "Mingle" mingles trits, rather than bits, whereas "Select" ANDs the two original numbers, then sorts all the bits in the first number corresponding to 2's in the second number to the least significant end, 0's in the second number to the most significant end, and 1's in between them.

"AND", "OR", "Mingle", and "Select" operate just like their binary counterparts if no trits with the value 2 are present.

$$\begin{array}{cc|cc} \text{AND}\quad\qquad & \& & 0 & 1 & 2 \\ \hline & 0 & 0 & 0 & 0 \\ & 1 & 0 & 1 & 2 \\ & 2 & 0 & 2 & 2 \\ \end{array}$$

$$\begin{array}{cc|cc} \text{OR}\quad\qquad\;\;\; & \lor & 0 & 1 & 2 \\ \hline & 0 & 0 & 1 & 2 \\ & 1 & 1 & 1 & 2 \\ & 2 & 2 & 2 & 2 \\ \end{array}$$

$$\begin{array}{cc|cc} \text{BUT} \quad\qquad & @ & 0 & 1 & 2 \\ \hline & 0 & 0 & 1 & 0 \\ & 1 & 1 & 1 & 1 \\ & 2 & 0 & 1 & 2 \\ \end{array}$$

$$\begin{array}{cc|cc} \text{SHARKFIN} & \land & 0 & 1 & 2 \\ \hline & 0 & 0 & 1 & 2 \\ & 1 & 1 & 2 & 0 \\ & 2 & 2 & 0 & 1 \\ \end{array}$$

$$\begin{array}{cc|cc} \text{WHAT} \, \qquad & ? & 0 & 1 & 2 \\ \hline & 0 & 0 & 1 & 2 \\ & 1 & 2 & 0 & 1 \\ & 2 & 1 & 2 & 0 \\ \end{array}$$

Question: "How would one use “BUT” logic in a ternary logic computer in a practical way?"

Taking some liberty with the English language and the meaning of the TRiINTERCAL operators I'll explain it thusly:

The "AND" operator: Max(True), unless one is false.

The "OR" operator: Max(True), unless both are false.

The "BUT" operator: Find the 'middle ground' if allowed; if both sides fully agree then sway that way. Put another way: Always "1" unless one input is "0" or "2", then choose that instead; with "0" overriding "2".

The "SHARKFIN" operator: Addition (Mod 3). Put another way: Add and wrap, never exceeding two.

The "WHAT" operator: If both sides agree it's false, prefer "1" over "2"; oops, disregard that ... [But you weren't asking about what] ;)

Question: "How could such an operation be used in practice (either on single trits or multiple trytes)?"

The webpage "MuppetLabs" website describes it this way:

"In TriINTERCAL programs the whirlpool (@) denotes the unary tritwise BUT operation. You can think of the whirlpool as drawing values preferentially towards the central value 1. Alternatively, you can think of it as drawing your soul and your sanity inexorably down....".

"As for operators, ? is always subtract without borrow, and ^ is always add without carry. V is the OR operation and always returns the max of its inputs. & is the AND operation, which chooses 0 if possible but otherwise returns the max of the inputs. @ is BUT, which prefers 1, then 0, then the max of the remaining possibilities. Rather than add more special symbols forever, a numeric modifier may be placed directly before the @ to indicate the operation that prefers one of the digits not already represented. Thus in files ending in .5i, the permitted unary operators are ?, ^, &, @, 2@, 3@, and V. Use of such barbarisms as 0@ to represent & are not permitted, nor is the use of @ or ^ in files with either of the extensions .i or .2i. Why not? You just can't, that's why. Don't ask so many questions.".

[NOTE: In my opinion the Truth table provided by Esolangs (for "WHAT") is incorrect, it should be this:]

$$\begin{array}{cc|cc} \text{WHAT} \, \qquad & ? & 0 & 1 & 2 \\ \hline & 0 & 0 & 1 & 2 \\ & 1 & 1 & 0 & 1 \\ & 2 & 2 & 1 & 0 \\ \end{array}$$

Please see Esoteric Programming Languages for less information.