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

Published on 12 May 2024 09:40 PM

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

Source code in the langur programming language

# borrowing null for "maybe"
val .trSet = [false, null, true]

val .and = f given .a, .b {
    case true, null:
    case null, true:
    case null: null
    default: .a and .b
}

val .or = f given .a, .b {
    case false, null:
    case null, false:
    case null: null
    default: .a or .b
}

val .imply = f if(.a nor .b: not? .a; .b)

# formatting function for the result values
# replacing null with "maybe"
# using left alignment of 5 code points
val .F = f $"\{nn [.r, "maybe"]:-5}"

writeln "a     not a"
for .a in .trSet {
    writeln $"\.a:.F; \(not? .a:.F)"
}

writeln "\na     b     a and b"
for .a in .trSet {
    for .b in .trSet {
        writeln $"\.a:.F; \.b:.F; \.and(.a, .b):.F;"
    }
}

writeln "\na     b     a or b"
for .a in .trSet {
    for .b in .trSet {
        writeln $"\.a:.F; \.b:.F; \.or(.a, .b):.F;"
    }
}

writeln "\na     b     a implies b"
for .a in .trSet {
    for .b in .trSet {
        writeln $"\.a:.F; \.b:.F; \.imply(.a, .b):.F;"
    }
}

writeln "\na     b     a eq b"
for .a in .trSet {
    for .b in .trSet {
        writeln $"\.a:.F; \.b:.F; \.a ==? .b:.F;"
    }
}

  

You may also check:How to resolve the algorithm Bitwise IO step by step in the Python programming language
You may also check:How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the REXX programming language
You may also check:How to resolve the algorithm Unbias a random generator step by step in the Perl programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Repeat step by step in the Haskell programming language