Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
66
Task/Ternary-logic/Free-Pascal/ternary-logic-1.pas
Normal file
66
Task/Ternary-logic/Free-Pascal/ternary-logic-1.pas
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
{$mode objfpc}
|
||||
unit ternarylogic;
|
||||
|
||||
interface
|
||||
type
|
||||
{ ternary type, balanced }
|
||||
trit = (tFalse=-1, tMaybe=0, tTrue=1);
|
||||
|
||||
{ ternary operators }
|
||||
|
||||
{ equivalence = multiplication }
|
||||
operator * (const a,b:trit):trit;
|
||||
operator and (const a,b:trit):trit;inline;
|
||||
operator or (const a,b:trit):trit;inline;
|
||||
operator not (const a:trit):trit;inline;
|
||||
operator xor (const a,b:trit):trit;
|
||||
{ imp ==>}
|
||||
operator >< (const a,b:trit):trit;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
operator and (const a,b:trit):trit;inline;
|
||||
const lookupAnd:array[trit,trit] of trit =
|
||||
((tFalse,tFalse,tFalse),
|
||||
(tFalse,tMaybe,tMaybe),
|
||||
(tFalse,tMaybe,tTrue));
|
||||
begin
|
||||
Result:= LookupAnd[a,b];
|
||||
end;
|
||||
|
||||
operator or (const a,b:trit):trit;inline;
|
||||
const lookupOr:array[trit,trit] of trit =
|
||||
((tFalse,tMaybe,tTrue),
|
||||
(tMaybe,tMaybe,tTrue),
|
||||
(tTrue,tTrue,tTrue));
|
||||
begin
|
||||
Result := LookUpOr[a,b];
|
||||
end;
|
||||
|
||||
operator not (const a:trit):trit;inline;
|
||||
const LookupNot:array[trit] of trit =(tTrue,tMaybe,tFalse);
|
||||
begin
|
||||
Result:= LookUpNot[a];
|
||||
end;
|
||||
|
||||
operator xor (const a,b:trit):trit;
|
||||
const LookupXor:array[trit,trit] of trit =
|
||||
((tFalse,tMaybe,tTrue),
|
||||
(tMaybe,tMaybe,tMaybe),
|
||||
(tTrue,tMaybe,tFalse));
|
||||
begin
|
||||
Result := LookupXor[a,b];
|
||||
end;
|
||||
|
||||
operator * (const a,b:trit):trit;
|
||||
begin
|
||||
result := not (a xor b);
|
||||
end;
|
||||
|
||||
{ imp ==>}
|
||||
operator >< (const a,b:trit):trit;
|
||||
begin
|
||||
result := not(a) or b;
|
||||
end;
|
||||
end.
|
||||
46
Task/Ternary-logic/Free-Pascal/ternary-logic-2.pas
Normal file
46
Task/Ternary-logic/Free-Pascal/ternary-logic-2.pas
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
program ternarytests;
|
||||
{$mode objfpc}
|
||||
uses
|
||||
ternarylogic;
|
||||
begin
|
||||
writeln(' a AND b');
|
||||
writeln('F':7,'U':7, 'T':7);
|
||||
writeln('F|',tFalse and tFalse:7,tFalse and tMaybe:7,tFalse and tTrue:7);
|
||||
writeln('U|',tMaybe and tFalse:7,tMaybe and tMaybe:7,tMaybe and tTrue:7);
|
||||
writeln('T|',tTrue and tFalse:7,tTrue and tMaybe:7,tTrue and tTrue:7);
|
||||
writeln;
|
||||
|
||||
writeln(' a OR b');
|
||||
writeln('F':7,'U':7, 'T':7);
|
||||
writeln('F|',tFalse or tFalse:7,tFalse or tMaybe:7,tFalse or tTrue:7);
|
||||
writeln('U|',tMaybe or tFalse:7,tMaybe or tMaybe:7,tMaybe or tTrue:7);
|
||||
writeln('T|',tTrue or tFalse:7,tTrue or tMaybe:7,tTrue or tTrue:7);
|
||||
writeln;
|
||||
|
||||
writeln(' NOT a');
|
||||
writeln('F|',not tFalse:7);
|
||||
writeln('U|',not tMaybe:7);
|
||||
writeln('T|',not tTrue:7);
|
||||
writeln;
|
||||
|
||||
writeln(' a XOR b');
|
||||
writeln('F':7,'U':7, 'T':7);
|
||||
writeln('F|',tFalse xor tFalse:7,tFalse xor tMaybe:7,tFalse xor tTrue:7);
|
||||
writeln('U|',tMaybe xor tFalse:7,tMaybe xor tMaybe:7,tMaybe xor tTrue:7);
|
||||
writeln('T|',tTrue xor tFalse:7,tTrue xor tMaybe:7,tTrue xor tTrue:7);
|
||||
writeln;
|
||||
|
||||
writeln('equality/equivalence and multiplication');
|
||||
writeln('F':7,'U':7, 'T':7);
|
||||
writeln('F|', tFalse * tFalse:7,tFalse * tMaybe:7, tFalse * tTrue:7);
|
||||
writeln('U|', tMaybe * tFalse:7,tMaybe * tMaybe:7,tMaybe * tTrue:7);
|
||||
writeln('T|', tTrue * tFalse:7, tTrue * tMaybe:7, tTrue * tTrue:7);
|
||||
writeln;
|
||||
|
||||
writeln('IMP. a.k.a. IfThen -> not(a) or b');
|
||||
writeln('F':7,'U':7, 'T':7);
|
||||
writeln('T|',tTrue >< tTrue:7,tTrue >< tMaybe:7,tTrue >< tFalse:7);
|
||||
writeln('U|',tMaybe >< tTrue:7,tMaybe >< tMaybe:7,tMaybe >< tFalse:7);
|
||||
writeln('F|',tFalse >< tTrue:7, tFalse >< tMaybe:7,tFalse >< tFalse:7);
|
||||
writeln;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue