How to resolve the algorithm Ternary logic step by step in the Elena programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Ternary logic step by step in the Elena 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 Elena programming language

Source code in the elena programming language

import extensions;
import system'routines;
import system'collections;
 
sealed class Trit
{
   bool _value;
 
   bool cast() = _value;
 
   constructor(object v)
   {
      if (v != nil)
      {
         _value := cast bool(v);
      }        
   }
 
   Trit equivalent(b)
   {
      var val2 := cast bool(b) \ back:nil;

      if (val2 != nil && _value != nil)
      {
         ^ _value.equal(val2)
      };

      ^  nilValue;
   }
 
   Trit Inverted
      = _value.Inverted \ back:nilValue;
 
   Trit and(b)
   {
      if (nil == _value)
      {
         ^ b.and:nil \ back:nilValue
      }
      else
      {
         ^ _value.and(/*$lazy cast bool(*/b/*)*/) \ back:nilValue
      }
   }
 
   Trit or(b)
   {
      if (nil == _value)
      {
         ^ b.or:nilValue \ back:nilValue
      }
      else
      {
         ^ _value.or(/*$lazy cast bool(*/b/*)*/) \ back:nilValue
      }
   }
 
   Trit implies(b)
      = self.Inverted.or(b);
 
   string toPrintable() = _value.toPrintable() \ back:"maybe";
}
 
public program()
{
    List values := new Trit[]{true, nilValue, false};
    values.forEach:(left)
    {
        console.printLine("¬",left," = ", left.Inverted);
        values.forEach:(right)
        {
            console.printLine(left, " & ", right, " = ", left && right);
            console.printLine(left, " | ", right, " = ", left || right);
            console.printLine(left, " → ", right, " = ", left.implies:right);
            console.printLine(left, " ≡ ", right, " = ", left.equivalent:right)
        }
    }
}

  

You may also check:How to resolve the algorithm 100 doors step by step in the ML/I programming language
You may also check:How to resolve the algorithm Top rank per group step by step in the Action! programming language
You may also check:How to resolve the algorithm Terminal control/Coloured text step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the Mathematica/Wolfram Language programming language