Ternary logic: Difference between revisions
→{{header|langur}}
(Added Easylang) |
Langurmonkey (talk | contribs) |
||
(9 intermediate revisions by 4 users not shown) | |||
Line 933:
MAYBE EQV TRUE = MAYBE
TRUE EQV TRUE = TRUE
</pre>
=={{header|Bruijn}}==
Direct translations of the truth tables to lambda calculus. The operators could be golfed significantly. If you do so, please add them here!
For applications of Ternary logic, see bruijn's [[Balanced_ternary#Bruijn|balanced ternary]] implementation.
true [[[0]]]
maybe [[[1]]]
false [[[2]]]
¬‣ [0 true maybe false]
…⋀… [[1 (0 1 1 1) (0 0 0 1) (0 0 0 0)]]
…⋁… [[1 (0 0 0 0) (0 1 0 0) (0 1 1 1)]]
…⊃… [[1 (0 true 0 1) (0 true 1 1) (0 1 1 1)]]
…≡… [[1 (0 true 0 1) (0 1 1 1) (0 0 0 0)]]
# --- result samples ---
:import std/List .
main [[inp <> "=" <> !res ++ "\n"] <++> (cross3 ops trits trits)]
!‣ [0 "false" "maybe" "true"]
…<>… [[1 ++ " " ++ 0]]
inp 0 [[~1 <> (0 [[!1 <> (0 [[!1]])]])]]
res ^(^0) ^(~0) ^(~(~0))
ops (…⋀… : "and") : ((…⋁… : "or") : ((…⊃… : "if") : {}(…≡… : "equiv")))
trits true : (maybe : {}false)
</syntaxhighlight>
{{out}}
<pre>
and true true = true
and true maybe = maybe
and true false = false
and maybe true = maybe
and maybe maybe = maybe
and maybe false = false
and false true = false
and false maybe = false
and false false = false
or true true = true
or true maybe = true
or true false = true
or maybe true = true
or maybe maybe = maybe
or maybe false = maybe
or false true = true
or false maybe = maybe
or false false = false
if true true = true
if true maybe = true
if true false = true
if maybe true = maybe
if maybe maybe = maybe
if maybe false = true
if false true = false
if false maybe = maybe
if false false = true
equiv true true = true
equiv true maybe = maybe
equiv true false = false
equiv maybe true = maybe
equiv maybe maybe = maybe
equiv maybe false = maybe
equiv false true = false
equiv false maybe = maybe
equiv false false = true
</pre>
Line 1,677 ⟶ 1,751:
return x
.
print " (AND)
print " F ? T
print "
for i = -1 to 1
o$ = " " & sym$[i] & " | "
o$ &= sym$[tand -1 i] & " " & sym$[tand 0 i] & " " & sym$[tand 1 i]
o$ &= "
o$ &= sym$[tor -1 i] & " " & sym$[tor 0 i] & " " & sym$[tor 1 i]
o$ &= "
o$ &= sym$[timp -1 i] & " " & sym$[timp 0 i] & " " & sym$[timp 1 i]
o$ &= "
o$ &= sym$[timp -1 i] & " " & sym$[timp 0 i] & " " & sym$[timp 1 i]
o$ &= "
print o$
.
Line 3,390 ⟶ 3,464:
=={{header|langur}}==
{{trans|Go}}
<syntaxhighlight lang="langur"># borrowing null for "maybe"
val .trSet = [false, null, true]
val .and =
case true, null:
case null, true:
Line 3,402 ⟶ 3,474:
}
val .or =
case false, null:
case null, false:
Line 3,409 ⟶ 3,481:
}
val .imply =
# formatting function for the result values
# replacing null with "maybe"
# using left alignment of 5 code points
val .F =
writeln "a not a"
for .a in .trSet {
writeln
}
Line 3,424 ⟶ 3,496:
for .a in .trSet {
for .b in .trSet {
writeln
}
}
Line 3,431 ⟶ 3,503:
for .a in .trSet {
for .b in .trSet {
writeln
}
}
Line 3,438 ⟶ 3,510:
for .a in .trSet {
for .b in .trSet {
writeln
}
}
Line 3,445 ⟶ 3,517:
for .a in .trSet {
for .b in .trSet {
writeln
}
}
▲}</syntaxhighlight>
</syntaxhighlight>
{{out}}
Line 6,456 ⟶ 6,529:
end func;
const func trit: (in trit: aTrit1) xor (in trit: aTrit2) is
return tritImplies[succ(ord(aTrit1))][succ(ord(aTrit2))];
Line 6,463 ⟶ 6,536:
return tritImplies[succ(ord(aTrit1))][succ(ord(aTrit2))];
syntax expr: .(). == .() is <-> 12;
const func trit: (in trit: aTrit1) == (in trit: aTrit2) is
return tritEquiv[succ(ord(aTrit1))][succ(ord(aTrit2))];
# Begin of test code
|