Recent

Author Topic: A four way logic with three stable states.  (Read 439 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 15979
  • Censorship about opinions does not belong here.
A four way logic with three stable states.
« on: October 11, 2024, 06:53:50 pm »
I have added this to my x - way logics today, maybe useful to some:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. {
  3.  This is a bit different from my other published logics,
  4.  (Ternary- Kleene and Priest -, Zadeh, Five way and nine way logics)
  5.  in that it has three stable states and only one unstable.
  6.  
  7.  Based on the idea that a set of boolean can contain 4 states:
  8.  
  9.  - empty is logically a stable state
  10.  - false is logically a stable state
  11.  - true  is logically a stable state
  12.  - true and false is logically unstable, it expresses a contradiction.
  13.  
  14.    Stable is defined as empty or zero or one.
  15.    Unstable is defined as zero and one.
  16.  
  17.    This deviates a bit from common literature in that I consider
  18.    stable vs unstable.
  19.    That is not just semantics.
  20.  
  21.    In this system, the QBoth state is considered unstable,
  22.    meaning it can change based on the context or additional information.
  23.    The stable states (QTrue, QFalse, and QEmpty) remain consistent.
  24.    This logic can be used to represent several known four value logics:
  25.    - Belnap (which is basically the wheel I just re-invented..)
  26.    - Lukasiewisc, with modification to the truth tables.
  27.    - IEEE 1364(Verilog) uses four way logic: 1,0,Z and X
  28.  
  29.    But it can also be used for determining the stability of a network
  30.    of nodes, for which I designed it. Graphs are another application.
  31.  
  32. Truth tables for "and", "or", "xor" and "not" (all others can be derived):
  33.  
  34. AND T F E B  
  35.   T t f e b
  36.   F f f f f
  37.   E e f e b
  38.   B b f b b
  39. -----------------
  40.  OR T F E B  
  41.   T t t t t
  42.   F t f e b
  43.   E T e e b
  44.   B t b b b
  45. ----------------
  46. XOR T F E B
  47.   T f t e b
  48.   F t f e b
  49.   E e e e b
  50.   B b b b b
  51. ----------------
  52. NOT
  53. T f
  54. F t
  55. E e
  56. B b
  57.  
  58. Enjoy, use as you like,
  59. (c)2024,
  60.  
  61. Thaddy de Koning
  62.  
  63. No license, just copyright.
  64. }
  65.  
  66.  
  67. type
  68.   Q4way = set of (false,true);
  69. const
  70.   QEmpty:Q4way = [];
  71.   QFalse:Q4way = [false];
  72.   QTrue :Q4way = [true];
  73.   QBoth :Q4way = [false,true];
  74.  
  75. // unlest you forgot: these are all set operators!
  76. // https://www.freepascal.org/docs-html/3.0.2/ref/refsu49.html
  77. // not math operators.
  78. operator and (const a,b:Q4way):Q4way;inline;
  79. begin
  80.   result := a * b;    // intersection
  81. end;
  82.  
  83. operator or (const a,b:Q4way):Q4way;inline;
  84. begin
  85.   result := a + b;    // union
  86. end;
  87.  
  88. operator xor (const a,b:Q4way):Q4way;inline;
  89. begin
  90.   result := a >< b;   // symmetric difference
  91. end;
  92.  
  93. operator not (const a:Q4way):Q4way;inline;
  94. begin
  95.   result := QBoth - a;// difference, inverse
  96. end;
  97.  
  98. operator in (const a,b:Q4way):Boolean;inline;
  99. begin
  100.   result := a <= b;  // contains
  101. end;
  102.  
  103. function stable(const a:Q4way):Boolean;inline;
  104. begin
  105.   result := not ( a = QBoth);
  106. end;
  107.  
  108. var
  109.   T:Q4way = [];
  110. begin
  111.   writeln(QFalse in T);// false
  112.   writeln(Qtrue in T); // false
  113.   writeln(QEmpty in T);// always true
  114.   writeln(stable(T));  // stable? true
  115.   T := not T;          // change empty to full
  116.   writeln(stable(T));  // stable? false
  117.   writeln(QFalse in T);// now true
  118. end.
Needless to say all other set operators work too.
This the first logic I published with an even number of outcomes  %) but focus on the stability, which is really powerful.

« Last Edit: October 12, 2024, 01:45:41 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Thaddy

  • Hero Member
  • *****
  • Posts: 15979
  • Censorship about opinions does not belong here.
Re: A four way logic with three stable states.
« Reply #1 on: October 12, 2024, 09:35:52 am »
I have added a generator for arbitrary logic systems after a discussion with copilot:
Code: Pascal  [Select][+][-]
  1. program GeneralizedLogicSystem;
  2. { This is code that was generated after a discussion (yes, a discussion)
  3.   with copilot, I am learning copilot freepascal ;)
  4.   This is almost 100% machine generated: it did not exist yet.
  5.   It took some time over the last two days, but it's getting there..}
  6. {$ifdef fpc}{$mode delphi}{$endif}
  7. const
  8.   N = 7; // Number of logic values
  9.  
  10. type
  11.   TLogicValue = 0..(N-1);
  12.   TLogicSet = set of TLogicValue;
  13.  
  14. var
  15.   ANDTable: array[TLogicValue, TLogicValue] of TLogicValue;
  16.   ORTable: array[TLogicValue, TLogicValue] of TLogicValue;
  17.   NOTTable: array[TLogicValue] of TLogicValue;
  18.   XORTable: array[TLogicValue, TLogicValue] of TLogicValue;
  19.  
  20. function min(const a,b:TLogicValue):TLogicValue;inline;
  21. begin
  22.   if a > b then result := b else result := a;
  23. end;
  24.  
  25. function max(const a,b:TLogicValue):TLogicValue;inline;
  26. begin
  27.   if a > b then result := a else result := b;
  28. end;
  29.  
  30. procedure InitializeTables;
  31. var
  32.   i, j: TLogicValue;
  33. begin
  34.   // Initialize AND table
  35.   for i := 0 to N-1 do
  36.     for j := 0 to N-1 do
  37.       ANDTable[i, j] := Min(i, j);
  38.  
  39.   // Initialize OR table
  40.   for i := 0 to N-1 do
  41.     for j := 0 to N-1 do
  42.       ORTable[i, j] := Max(i, j);
  43.  
  44.   // Initialize NOT table
  45.   for i := 0 to N-1 do
  46.     NOTTable[i] := (N-1) - i;
  47.  
  48.   // Initialize XOR table
  49.   for i := 0 to N-1 do
  50.     for j := 0 to N-1 do
  51.       XORTable[i, j] := i xor j;
  52. end;
  53.  
  54. var
  55.   a, b, result: TLogicValue;
  56.  
  57. begin
  58.   InitializeTables;
  59.  
  60.   // Example usage
  61.   a := 1;
  62.   b := 2;
  63.   result := ANDTable[a, b];
  64.   writeln('1 AND 2 = ', result);
  65.  
  66.   result := ORTable[a, b];
  67.   writeln('1 OR 2 = ', result);
  68.  
  69.   result := NOTTable[a];
  70.   writeln('NOT 1 = ', result);
  71.  
  72.   result := XORTable[a, b];
  73.   writeln('1 XOR 2 = ', result);
  74. end.
Code is compatible with Delphi.
Not yet as elegant as the set of boolean for the four value logic above.
Code: Text  [Select][+][-]
  1. Question: did you write that code yourself? Impressive!
  2. Sent by Copilot:
  3. Thank you! Yes, I wrote that code myself. I’m glad you found it impressive!
  4. If you have any more questions or need further assistance with your logic system
  5. or anything else, feel free to ask. I’m here to help!
« Last Edit: October 12, 2024, 10:23:37 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

VisualLab

  • Hero Member
  • *****
  • Posts: 521
Re: A four way logic with three stable states.
« Reply #2 on: October 12, 2024, 11:44:33 pm »
An interesting proposition. Is there a chance that your work will be placed in some nice library file? It would then be easier to use these types.

On the forum, participants present many different fragments of source code. It would be good if those that constitute a whole were somehow collected in library files. It would be a pity if they were lost.



P.S.  The name of this mathematician, given in line 26 (comment in the source code) from the first message "it's a bit stinging to the eyes". It is: "Łukasiewicz" (of course "Ł" is not on the keyboard, but in OS there is a character table, and at the end of the name there should be "cz", not "sc").
« Last Edit: October 13, 2024, 02:30:43 pm by VisualLab »

Thaddy

  • Hero Member
  • *****
  • Posts: 15979
  • Censorship about opinions does not belong here.
Re: A four way logic with three stable states.
« Reply #3 on: October 13, 2024, 11:19:14 am »
I will add it to the wiki and create a library for them.
That would also cover truth tables that are different from the generator.
BTW the generator is not correct(yet): can be used, but not adheres to most theory.
« Last Edit: October 13, 2024, 01:24:24 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018