70 lines
1.5 KiB
Text
70 lines
1.5 KiB
Text
'ternary logic
|
|
'0 1 2
|
|
'F ? T
|
|
'False Don't know True
|
|
'LB has NOT AND OR XOR, so we implement them.
|
|
'LB has no EQ, but XOR could be expressed via EQ. In 'normal' boolean at least.
|
|
|
|
global tFalse, tDontKnow, tTrue
|
|
tFalse = 0
|
|
tDontKnow = 1
|
|
tTrue = 2
|
|
|
|
print "Short and long names for ternary logic values"
|
|
for i = tFalse to tTrue
|
|
print shortName3$(i);" ";longName3$(i)
|
|
next
|
|
print
|
|
|
|
print "Single parameter functions"
|
|
print "x";" ";"=x";" ";"not(x)"
|
|
for i = tFalse to tTrue
|
|
print shortName3$(i);" ";shortName3$(i);" ";shortName3$(not3(i))
|
|
next
|
|
print
|
|
|
|
print "Double parameter fuctions"
|
|
print "x";" ";"y";" ";"x AND y";" ";"x OR y";" ";"x EQ y";" ";"x XOR y"
|
|
for a = tFalse to tTrue
|
|
for b = tFalse to tTrue
|
|
print shortName3$(a);" ";shortName3$(b);" "; _
|
|
shortName3$(and3(a,b));" "; shortName3$(or3(a,b));" "; _
|
|
shortName3$(eq3(a,b));" "; shortName3$(xor3(a,b))
|
|
next
|
|
next
|
|
|
|
function and3(a,b)
|
|
and3 = min(a,b)
|
|
end function
|
|
|
|
function or3(a,b)
|
|
or3 = max(a,b)
|
|
end function
|
|
|
|
function eq3(a,b)
|
|
select case
|
|
case a=tDontKnow or b=tDontKnow
|
|
eq3 = tDontKnow
|
|
case a=b
|
|
eq3 = tTrue
|
|
case else
|
|
eq3 = tFalse
|
|
end select
|
|
end function
|
|
|
|
function xor3(a,b)
|
|
xor3 = not3(eq3(a,b))
|
|
end function
|
|
|
|
function not3(b)
|
|
not3 = 2-b
|
|
end function
|
|
|
|
'------------------------------------------------
|
|
function shortName3$(i)
|
|
shortName3$ = word$("F ? T", i+1)
|
|
end function
|
|
|
|
function longName3$(i)
|
|
longName3$ = word$("False,Don't know,True", i+1, ",")
|
|
end function
|