How to resolve the algorithm Ternary logic step by step in the Julia programming language
How to resolve the algorithm Ternary logic step by step in the Julia programming language
Table of Contents
Problem Statement
In logic, a three-valued logic (also trivalent, ternary, or trinary logic, sometimes abbreviated 3VL) is any of several many-valued logic systems in which there are three truth values indicating true, false and some indeterminate third value.
This is contrasted with the more commonly known bivalent logics (such as classical sentential or boolean logic) which provide only for true and false.
Conceptual form and basic ideas were initially created by Łukasiewicz, Lewis and Sulski.
These were then re-formulated by Grigore Moisil in an axiomatic algebraic form, and also extended to n-valued logics in 1945.
Note: Setun (Сетунь) was a balanced ternary computer developed in 1958 at Moscow State University. The device was built under the lead of Sergei Sobolev and Nikolay Brusentsov. It was the only modern ternary computer, using three-valued ternary logic
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ternary logic step by step in the Julia programming language
This code implements the operations of a ternary logic system in Julia programming language.
It defines an @enum
called Trit
with three values: False
, Maybe
, and True
.
It then defines four functions: !
, ∧
, ∨
, ⊃
, and ≡
, which implement the logical NOT, AND, OR, IMPLICATION, and EQUIVALENCE operations, respectively.
Next, it prints out a table for each operation, showing the result of the operation for all possible combinations of input values.
NOT
Not (!):
! False is True
! Maybe is Maybe
! True is False
AND
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
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
IMPLICATION
If Then (⊃):
False ⊃ False is True
False ⊃ Maybe is Maybe
False ⊃ True is True
Maybe ⊃ False is False
Maybe ⊃ Maybe is Maybe
Maybe ⊃ True is Maybe
True ⊃ False is False
True ⊃ Maybe is False
True ⊃ True is True
EQUIVALENCE
Equivalent (≡):
False ≡ False is True
False ≡ Maybe is False
False ≡ True is False
Maybe ≡ False is False
Maybe ≡ Maybe is Maybe
Maybe ≡ True is False
True ≡ False is False
True ≡ Maybe is False
True ≡ True is True
Source code in the julia programming language
@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
You may also check:How to resolve the algorithm Associative array/Merging step by step in the Ring programming language
You may also check:How to resolve the algorithm Subtractive generator step by step in the Sidef programming language
You may also check:How to resolve the algorithm Introspection step by step in the Java programming language
You may also check:How to resolve the algorithm Box the compass step by step in the Fortran programming language
You may also check:How to resolve the algorithm Continued fraction/Arithmetic/Construct from rational number step by step in the C++ programming language