How to resolve the algorithm Truth table step by step in the Amazing Hopper programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Truth table step by step in the Amazing Hopper programming language

Table of Contents

Problem Statement

A truth table is a display of the inputs to, and the output of a Boolean function organized as a table where each row gives one combination of input values and the corresponding value of the function.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Truth table step by step in the Amazing Hopper programming language

Source code in the amazing programming language

#include basica/booleanos.h

#include 


algoritmo 

    variables( R0,R1,R2,R3,R4,T0,T1,T2,T3,T4,T5,T6 )

    VARS=3
    preparar valores de verdad

    preparar cabecera {
         
         "A","B","C","|","[A=>B","&","B=>C]","=>","A=>C"

    } enlistar en 'cabecera'

    expresión lógica a evaluar {

         OP=>( A, B ),   :: 'R1'
         OP=>( B, C ),   :: 'R2'
         OP&( R1, R2 ),  :: 'R0'
         OP=>( A, C ),   :: 'R3'
         OP=>( R0, R3 )

    } :: 'R4'

    unir columnas( tabla, tabla, separador tabla, R1, R0, R2, R4, R3 )

    insertar cabecera y desplegar tabla
 
 /* =============== otro ================== */
 
    VARS=2, preparar valores de verdad

    preparar cabecera {
         "A","B","|","value: A=>B <=> ~AvB"
    } enlistar en 'cabecera'
    
    expresión lógica a evaluar {
         OP<=>( OP=>(A,B), OP|(OP~(A), B) )

    } :: 'R0'
    
    unir columnas( tabla, tabla, separador tabla, R0 )

    insertar cabecera y desplegar tabla

 /* =============== otro ================== */
 
    VARS=4, preparar valores de verdad
    
    preparar cabecera {
         "A","B","C","D","|","[~AvB","&","A=>C","&","(B","=>","(C=>D))]","=>","A=>C"
    } enlistar en 'cabecera'
    expresión lógica a evaluar {
         
         OP|( OP~(A), B)     :: 'R0'
         OP=>(A,C)           :: 'R1'
         OP&( R0, R1 )       :: 'T0'
         OP=>( C,D )         :: 'R2'
         OP=>( B, R2 )       :: 'T2'
         OP&( T0, T2 )       :: 'T3'
         OP=>( T3, R1)

    } :: 'T4'
    
    unir columnas( tabla, tabla, separador tabla, R0, T0,R1, T3, B, T2, R2, T4, R1)

    insertar cabecera y desplegar tabla

 /* =============== otro ================== */

    VARS=2, preparar valores de verdad
    preparar cabecera {
         "A","B","~A","~B","A&B","AvB","A^B","A=>B","A<=>B","A~&B","A~vB"
    } enlistar en 'cabecera'
    
    expresión lógica a evaluar {
         
         OP~(A)             :: 'R0'
         OP~(B)             :: 'R1'
         OP&(A,B)           :: 'T0'
         OP|(A,B)           :: 'T1'
         OP^(A,B)           :: 'T2'
         OP=>(A,B)          :: 'T3'
         OP<=>(A,B)         :: 'T4'
         OP~&(A,B)          :: 'T5'
         OP~|(A,B)          :: 'T6'

    }
    
    unir columnas( tabla, tabla, R0,R1,T0,T1,T2,T3,T4, T5, T6)

    insertar cabecera y desplegar tabla

 /* =============== otro ================== */
 
    VARS=1, preparar valores de verdad
    preparar cabecera { "A","~A" } enlistar en 'cabecera'
    
    unir columnas( tabla, tabla, OP~(A) )

    insertar cabecera y desplegar tabla
terminar


/* BOOLEANOS.H */
#context-free  preparaciondedatos
    fijar separador (NULO)

    c=""
    tamaño binario (VARS)
    
    #( lpad("0",VARS,"0") ), separar para (tabla)
    #( TOTCOMB = 2^VARS )
    iterar para (i=1, #(i< TOTCOMB), ++i)
         
         i, cambiar a base(2), quitar laterales, mover a 'c',
         #( lpad("0",VARS,c) ); separar para (fila)
         unir filas ( tabla, tabla, fila )

    siguiente
    
    replicar( "|", TOTCOMB ), separar para (separador tabla)

retornar\\

#define A                  V(1)
#define B                  V(2)
#define C                  V(3)
#define D                  V(4)
#define E                  V(5)
#define F                  V(6)
#define G                  V(7)
#define H                  V(8)
// etcétera
#define V(_X_)             {1}{_X_}loc2;{TOTCOMB}{0}offset2;get(tabla);xtonum

#define-a       ::         mov  

#defn    OP<=>(_X_,_Y_)     #RAND; _V1_#RNDV_=0;_V2_#RNDV_=0;#ATOM#CMPLX;\
                            cpy(_V1_#RNDV_);\
                            #ATOM#CMPLX;cpy(_V2_#RNDV_);and;{_V1_#RNDV_}not;\
                            {_V2_#RNDV_}not;and;or; %RAND;
#defn    OP=>(_X_,_Y_)      #ATOM#CMPLX;not;#ATOM#CMPLX;or;
#defn    OP&(_X_,_Y_)       #ATOM#CMPLX;#ATOM#CMPLX;and;
#defn    OP|(_X_,_Y_)       #ATOM#CMPLX;#ATOM#CMPLX;or;
#defn    OP^(_X_,_Y_)       #ATOM#CMPLX;#ATOM#CMPLX;xor;
#defn    OP~&(_X_,_Y_)      #ATOM#CMPLX;#ATOM#CMPLX;nand;
#defn    OP~|(_X_,_Y_)      #ATOM#CMPLX;#ATOM#CMPLX;nor;
#defn    OP~(_X_)           #ATOM#CMPLX;not;

#defn    variables(*)      #GENCODE $$$*$$$ #LIST={#VOID};#ENDGEN

#define  expresiónlógicaaevaluar      {1}do
#synon   expresiónlógicaaevaluar      prepararcabecera

#define  centrar                      ;padcenter;

#define  insertarcabeceraydesplegartabla     {cabecera}length;\
                        mov(LENTABLA); \
                        dim (LENTABLA) matriz rellena ("-----",vsep),\
                        unir filas ( cabecera, cabecera, vsep,tabla ) \
                        {" ",7,cabecera}, convertir a cadena, centrar,\
                        mover a 'cabecera'\
                        transformar("1","T", transformar("0","F", cabecera)) \
                        guardar en 'cabecera',\
                        imprimir( cabecera, NL )

#define  prepararvaloresdeverdad    decimales '0' \
                        tabla={#VOID}, fila={#VOID}, separador tabla={#VOID},\
                        cabecera={#VOID}, TOTCOMB=0, LENTABLA=0,\
                        preparacion de datos

/* EOF */


  

You may also check:How to resolve the algorithm Sierpinski carpet step by step in the Rust programming language
You may also check:How to resolve the algorithm Combinations with repetitions step by step in the Elixir programming language
You may also check:How to resolve the algorithm Achilles numbers step by step in the Factor programming language
You may also check:How to resolve the algorithm Image convolution step by step in the Racket programming language
You may also check:How to resolve the algorithm Idiomatically determine all the lowercase and uppercase letters step by step in the COBOL programming language