Ternary logic: Difference between revisions
Content added Content deleted
Line 2,432: | Line 2,432: | ||
"etc etc" |
"etc etc" |
||
</pre> |
</pre> |
||
=={{header|Julia}}== |
|||
{{works with|Julia|0.6}} |
|||
<lang julia>@enum Trit False Maybe True |
|||
const trits = (False, Maybe, True) |
|||
Base.:!(a::Trit) = a == False ? True : a == Maybe ? Maybe : False |
|||
∧(a::Trit, b::Trit) = a == b == True ? True : (a, b) ∋ False ? False : Maybe |
|||
∨(a::Trit, b::Trit) = a == b == False ? False : (a, b) ∋ True ? True : Maybe |
|||
⊃(a::Trit, b::Trit) = a == False || b == True ? True : (a, b) ∋ Maybe ? Maybe : False |
|||
≡(a::Trit, b::Trit) = (a, b) ∋ Maybe ? Maybe : a == b ? True : False |
|||
println("Not (!):") |
|||
println(join(@sprintf("%10s%s is %5s", "!", t, !t) for t in trits)) |
|||
println("And (∧):") |
|||
for a in trits |
|||
println(join(@sprintf("%10s ∧ %5s is %5s", a, b, a ∧ b) for b in trits)) |
|||
end |
|||
println("Or (∨):") |
|||
for a in trits |
|||
println(join(@sprintf("%10s ∨ %5s is %5s", a, b, a ∨ b) for b in trits)) |
|||
end |
|||
println("If Then (⊃):") |
|||
for a in trits |
|||
println(join(@sprintf("%10s ⊃ %5s is %5s", a, b, a ⊃ b) for b in trits)) |
|||
end |
|||
println("Equivalent (≡):") |
|||
for a in trits |
|||
println(join(@sprintf("%10s ≡ %5s is %5s", a, b, a ≡ b) for b in trits)) |
|||
end</lang> |
|||
{{out}} |
|||
<pre>Not (!): |
|||
!False is True !Maybe is Maybe !True is False |
|||
And (∧): |
|||
False ∧ False is False False ∧ Maybe is False False ∧ True is False |
|||
Maybe ∧ False is False Maybe ∧ Maybe is Maybe Maybe ∧ True is Maybe |
|||
True ∧ False is False True ∧ Maybe is Maybe True ∧ True is True |
|||
Or (∨): |
|||
False ∨ False is False False ∨ Maybe is Maybe False ∨ True is True |
|||
Maybe ∨ False is Maybe Maybe ∨ Maybe is Maybe Maybe ∨ True is True |
|||
True ∨ False is True True ∨ Maybe is True True ∨ True is True |
|||
If Then (⊃): |
|||
False ⊃ False is True False ⊃ Maybe is True False ⊃ True is True |
|||
Maybe ⊃ False is Maybe Maybe ⊃ Maybe is Maybe Maybe ⊃ True is True |
|||
True ⊃ False is False True ⊃ Maybe is Maybe True ⊃ True is True |
|||
Equivalent (≡): |
|||
False ≡ False is True False ≡ Maybe is Maybe False ≡ True is False |
|||
Maybe ≡ False is Maybe Maybe ≡ Maybe is Maybe Maybe ≡ True is Maybe |
|||
True ≡ False is False True ≡ Maybe is Maybe True ≡ True is True</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |