How to resolve the algorithm Ternary logic step by step in the ooRexx programming language
How to resolve the algorithm Ternary logic step by step in the ooRexx 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 ooRexx programming language
Source code in the oorexx programming language
tritValues = .array~of(.trit~true, .trit~false, .trit~maybe)
tab = '09'x
say "not operation (\)"
loop a over tritValues
say "\"a":" (\a)
end
say
say "and operation (&)"
loop aa over tritValues
loop bb over tritValues
say (aa" & "bb":" (aa&bb))
end
end
say
say "or operation (|)"
loop aa over tritValues
loop bb over tritValues
say (aa" | "bb":" (aa|bb))
end
end
say
say "implies operation (&&)"
loop aa over tritValues
loop bb over tritValues
say (aa" && "bb":" (aa&&bb))
end
end
say
say "equals operation (=)"
loop aa over tritValues
loop bb over tritValues
say (aa" = "bb":" (aa=bb))
end
end
::class trit
-- making this a private method so we can control the creation
-- of these. We only allow 3 instances to exist
::method new class private
forward class(super)
::method init class
expose true false maybe
-- delayed creation
true = .nil
false = .nil
maybe = .nil
-- read only attribute access to the instances.
-- these methods create the appropriate singleton on the first call
::attribute true class get
expose true
if true == .nil then true = self~new("True")
return true
::attribute false class get
expose false
if false == .nil then false = self~new("False")
return false
::attribute maybe class get
expose maybe
if maybe == .nil then maybe = self~new("Maybe")
return maybe
-- create an instance
::method init
expose value
use arg value
-- string method to return the value of the instance
::method string
expose value
return value
-- "and" method using the operator overload
::method "&"
use strict arg other
if self == .trit~true then return other
else if self == .trit~maybe then do
if other == .trit~false then return .trit~false
else return .trit~maybe
end
else return .trit~false
-- "or" method using the operator overload
::method "|"
use strict arg other
if self == .trit~true then return .trit~true
else if self == .trit~maybe then do
if other == .trit~true then return .trit~true
else return .trit~maybe
end
else return other
-- implies method...using the XOR operator for this
::method "&&"
use strict arg other
if self == .trit~true then return other
else if self == .trit~maybe then do
if other == .trit~true then return .trit~true
else return .trit~maybe
end
else return .trit~true
-- "not" method using the operator overload
::method "\"
if self == .trit~true then return .trit~false
else if self == .trit~maybe then return .trit~maybe
else return .trit~true
-- "equals" using the "=" override. This makes a distinction between
-- the "==" operator, which is real equality and the "=" operator, which
-- is trinary equality.
::method "="
use strict arg other
if self == .trit~true then return other
else if self == .trit~maybe then return .trit~maybe
else return \other
You may also check:How to resolve the algorithm 100 doors step by step in the TSE SAL programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Plain TeX programming language
You may also check:How to resolve the algorithm Find the last Sunday of each month step by step in the Java programming language
You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the PureBasic programming language