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

Published on 12 May 2024 09:40 PM

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

Source code in the bbc programming language

      INSTALL @lib$ + "CLASSLIB"
      
      REM Create a ternary class:
      DIM trit{tor, tand, teqv, tnot, tnor, s, v}
      DEF PRIVATE trit.s (t&) LOCAL t$():DIM t$(2):t$()="FALSE","MAYBE","TRUE":=t$(t&)
      DEF PRIVATE trit.v (t$) = INSTR("FALSE MAYBE TRUE", t$) DIV 6
      DEF trit.tnot (t$) = FN(trit.s)(2 - FN(trit.v)(t$))
      DEF trit.tor (a$,b$) LOCAL t:t=FN(trit.v)(a$)ORFN(trit.v)(b$):=FN(trit.s)(t+(t>2))
      DEF trit.tnor (a$,b$) = FN(trit.tnot)(FN(trit.tor)(a$,b$))
      DEF trit.tand (a$,b$) = FN(trit.tnor)(FN(trit.tnot)(a$),FN(trit.tnot)(b$))
      DEF trit.teqv (a$,b$) = FN(trit.tor)(FN(trit.tand)(a$,b$),FN(trit.tnor)(a$,b$))
      PROC_class(trit{})
      
      PROC_new(mytrit{}, trit{})
      
      REM Test it:
      PRINT "Testing NOT:"
      PRINT "NOT FALSE = " FN(mytrit.tnot)("FALSE")
      PRINT "NOT MAYBE = " FN(mytrit.tnot)("MAYBE")
      PRINT "NOT TRUE  = " FN(mytrit.tnot)("TRUE")
      
      PRINT '"Testing OR:"
      PRINT "FALSE OR FALSE = " FN(mytrit.tor)("FALSE","FALSE")
      PRINT "FALSE OR MAYBE = " FN(mytrit.tor)("FALSE","MAYBE")
      PRINT "FALSE OR TRUE  = " FN(mytrit.tor)("FALSE","TRUE")
      PRINT "MAYBE OR MAYBE = " FN(mytrit.tor)("MAYBE","MAYBE")
      PRINT "MAYBE OR TRUE  = " FN(mytrit.tor)("MAYBE","TRUE")
      PRINT "TRUE  OR TRUE  = " FN(mytrit.tor)("TRUE","TRUE")
      
      PRINT '"Testing AND:"
      PRINT "FALSE AND FALSE = " FN(mytrit.tand)("FALSE","FALSE")
      PRINT "FALSE AND MAYBE = " FN(mytrit.tand)("FALSE","MAYBE")
      PRINT "FALSE AND TRUE  = " FN(mytrit.tand)("FALSE","TRUE")
      PRINT "MAYBE AND MAYBE = " FN(mytrit.tand)("MAYBE","MAYBE")
      PRINT "MAYBE AND TRUE  = " FN(mytrit.tand)("MAYBE","TRUE")
      PRINT "TRUE  AND TRUE  = " FN(mytrit.tand)("TRUE","TRUE")
      
      PRINT '"Testing EQV (similar to EOR):"
      PRINT "FALSE EQV FALSE = " FN(mytrit.teqv)("FALSE","FALSE")
      PRINT "FALSE EQV MAYBE = " FN(mytrit.teqv)("FALSE","MAYBE")
      PRINT "FALSE EQV TRUE  = " FN(mytrit.teqv)("FALSE","TRUE")
      PRINT "MAYBE EQV MAYBE = " FN(mytrit.teqv)("MAYBE","MAYBE")
      PRINT "MAYBE EQV TRUE  = " FN(mytrit.teqv)("MAYBE","TRUE")
      PRINT "TRUE  EQV TRUE  = " FN(mytrit.teqv)("TRUE","TRUE")
      
      PROC_discard(mytrit{})


  

You may also check:How to resolve the algorithm Percentage difference between images step by step in the Lua programming language
You may also check:How to resolve the algorithm Heronian triangles step by step in the Elixir programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the Groovy programming language
You may also check:How to resolve the algorithm Command-line arguments step by step in the Toka programming language
You may also check:How to resolve the algorithm Range expansion step by step in the Dyalect programming language