{$mode objfpc}

{

This is a bit different from my other published logics,

(Ternary- Kleene and Priest -, Zadeh, Five way and nine way logics)

in that it has three stable states and only one unstable.

Based on the idea that a set of boolean can contain 4 states:

- empty is logically a stable state

- false is logically a stable state

- true is logically a stable state

- true and false is logically unstable, it expresses a contradiction.

Stable is defined as empty or zero or one.

Unstable is defined as zero and one.

This deviates a bit from common literature in that I consider

stable vs unstable.

That is not just semantics.

In this system, the QBoth state is considered unstable,

meaning it can change based on the context or additional information.

The stable states (QTrue, QFalse, and QEmpty) remain consistent.

This logic can be used to represent several known four value logics:

- Belnap (which is basically the wheel I just re-invented..)

- Lukasiewisc, with modification to the truth tables.

- IEEE 1364(Verilog) uses four way logic: 1,0,Z and X

But it can also be used for determining the stability of a network

of nodes, for which I designed it. Graphs are another application.

Truth tables for "and", "or", "xor" and "not" (all others can be derived):

AND T F E B

T t f e b

F f f f f

E e f e b

B b f b b

-----------------

OR T F E B

T t t t t

F t f e b

E T e e b

B t b b b

----------------

XOR T F E B

T f t e b

F t f e b

E e e e b

B b b b b

----------------

NOT

T f

F t

E e

B b

Enjoy, use as you like,

(c)2024,

Thaddy de Koning

No license, just copyright.

}

type

Q4way = set of (false,true);

const

QEmpty:Q4way = [];

QFalse:Q4way = [false];

QTrue :Q4way = [true];

QBoth :Q4way = [false,true];

// unlest you forgot: these are all set operators!

// https://www.freepascal.org/docs-html/3.0.2/ref/refsu49.html

// not math operators.

operator and (const a,b:Q4way):Q4way;inline;

begin

result := a * b; // intersection

end;

operator or (const a,b:Q4way):Q4way;inline;

begin

result := a + b; // union

end;

operator xor (const a,b:Q4way):Q4way;inline;

begin

result := a >< b; // symmetric difference

end;

operator not (const a:Q4way):Q4way;inline;

begin

result := QBoth - a;// difference, inverse

end;

operator in (const a,b:Q4way):Boolean;inline;

begin

result := a <= b; // contains

end;

function stable(const a:Q4way):Boolean;inline;

begin

result := not ( a = QBoth);

end;

var

T:Q4way = [];

begin

writeln(QFalse in T);// false

writeln(Qtrue in T); // false

writeln(QEmpty in T);// always true

writeln(stable(T)); // stable? true

T := not T; // change empty to full

writeln(stable(T)); // stable? false

writeln(QFalse in T);// now true

end.