From becf5e4ebb485276fbff66612ee4203eaf1aa43b Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 4 Sep 2024 22:57:18 +0300 Subject: [PATCH] Improve documentation for truth table generator --- Math/Truth table calculator/doc/index.org | 45 ++++++++++- Math/Truth table calculator/truth.bas | 98 ++++++++++++++--------- 2 files changed, 103 insertions(+), 40 deletions(-) diff --git a/Math/Truth table calculator/doc/index.org b/Math/Truth table calculator/doc/index.org index 58783bd..cd58c50 100644 --- a/Math/Truth table calculator/doc/index.org +++ b/Math/Truth table calculator/doc/index.org @@ -16,7 +16,6 @@ the input variables, with the corresponding output value. Truth tables are cruci designing and understanding digital circuits, Boolean algebra, and logical expressions. * Implemented logical operations - ** Equivalent ( ⇔ , 1 ) The equivalent operation, also known as logical biconditional, is true if and only if @@ -47,7 +46,6 @@ Truth table: | F | T | T | | F | F | T | - ** OR ( ∨ , 3 ) The OR operation, also known as logical disjunction, is true if at @@ -77,7 +75,6 @@ Truth table: | F | T | F | | F | F | F | - ** NOT ( ¬ , 5 ) The NOT operation, also known as logical negation, inverts the value @@ -90,3 +87,45 @@ Truth Table: |---+----| | T | F | | F | T | +* Examples + +** Example: (A ∧ B) ∨ ¬C + +| A | B | C | (A ∧ B) ∨ ¬C | +|---+---+---+--------------| +| T | T | T | T | +| T | T | F | T | +| T | F | T | F | +| T | F | F | T | +| F | T | T | F | +| F | T | F | T | +| F | F | T | F | +| F | F | F | T | + +** Example: A ⇒ (B ∨ ¬C) + +| A | B | C | A ⇒ (B ∨ ¬C) | +|---+---+---+--------------| +| T | T | T | T | +| T | T | F | T | +| T | F | T | F | +| T | F | F | T | +| F | T | T | T | +| F | T | F | T | +| F | F | T | T | +| F | F | F | T | + +** Example: (A ⇔ B) ∧ C + +Truth Table: + +| A | B | C | (A ⇔ B) ∧ C | +|---+---+---+-------------| +| T | T | T | T | +| T | T | F | F | +| T | F | T | F | +| T | F | F | F | +| F | T | T | F | +| F | T | F | F | +| F | F | T | T | +| F | F | F | F | diff --git a/Math/Truth table calculator/truth.bas b/Math/Truth table calculator/truth.bas index 4692e89..9116de5 100755 --- a/Math/Truth table calculator/truth.bas +++ b/Math/Truth table calculator/truth.bas @@ -1,20 +1,36 @@ -' Logical equation solver -' made by Svjatoslav Agejenko -' in 2002 -' homepage: svjatoslav.eu -' email: svjatoslav@svjatoslav.eu - -' Solves logical equations. -' AND OR XOR etc... +' TRUTH TABLE CALCULATOR +' +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2002, Initial version +' 2024.09, Improved program readability using AI +' +' +' A truth table is a mathematical table used to determine the output of a +' logic function based on all possible combinations of inputs. Each row +' represents a possible state of the input variables, with the +' corresponding output value. Truth tables are crucial in designing and +' understanding digital circuits, Boolean algebra, and logical +' expressions. +' +' Implemented operations: +' Equivalent ( Keyboard shortcut: 1 ) +' Implies ( Keyboard shortcut: 2 ) +' OR ( Keyboard shortcut: 3 ) +' AND ( Keyboard shortcut: 4 ) +' NOT ( Keyboard shortcut: 5 ) DECLARE SUB rmslg (x1!, x3!, l!) -DECLARE SUB getp (a!, b!) -DECLARE SUB movm (x1!, n!) +DECLARE SUB getP (a!, b!) +DECLARE SUB movM (x1!, n!) DECLARE SUB lihts (x1, x2, l) DECLARE SUB klea () -DECLARE SUB lendm (x1!, m!) +DECLARE SUB lendM (x1!, m!) DECLARE SUB mov (x1!, n!) -DECLARE SUB lendp (x1!, m!) +DECLARE SUB lendP (x1!, m!) DECLARE SUB teeslg (x1!, x2!, l!) DECLARE SUB prepare () DECLARE SUB tee (x1!, x2!) @@ -41,7 +57,8 @@ sist prepare GOTO 13 -SUB getp (a, b) +SUB getP (a, b) +' Determines the priority of logical operators SELECT CASE a CASE 5 b = 1 @@ -57,20 +74,21 @@ END SELECT END SUB SUB klea +' Waits for user input to clear the screen buffer FOR a = 1 TO 50 a$ = INKEY$ NEXT a END SUB SUB lahend (x1, x2) - +' Analyzes and prepares the logical equation for solving DIM muu(65 TO 122) FOR a = 65 TO 122 muu(a) = 0 NEXT a -muu(116) = 1 -muu(118) = 1 +muu(116) = 1 ' t +muu(118) = 1 ' v nm = 0 FOR a = x1 TO x2 @@ -84,8 +102,8 @@ FOR a = x1 TO x2 END IF NEXT a -muun(nm + 1) = 116 -muun(nm + 2) = 118 +muun(nm + 1) = 116 ' t +muun(nm + 2) = 118 ' v f = 2 ^ nm tehl = f @@ -102,8 +120,8 @@ FOR a = 1 TO nm NEXT a FOR a = 1 TO tehl - muut(nm + 1, a) = 116 - muut(nm + 2, a) = 118 + muut(nm + 1, a) = 116 ' t + muut(nm + 2, a) = 118 ' v NEXT a nm = nm + 2 @@ -117,10 +135,6 @@ NEXT a LOCATE 5, 1 teeslg x1, x2, a -'FOR b = x1 TO x2 + a -'prn b, 20, 14, 1, CHR$(tehe(b)) -'NEXT b - tee x1, x2 + a FOR a = 0 TO 79 @@ -131,10 +145,10 @@ FOR a = 1 TO tehl prn x2 + 1, a, 14, 0, CHR$(vast(a)) NEXT a - END SUB -SUB lendm (x1, m) +SUB lendM (x1, m) +' Measures the length of a logical expression enclosed in parentheses IF tehe(x1) <> 41 THEN m = 1: GOTO 19 c = x1 d = 1 @@ -147,7 +161,8 @@ m = x1 - c 19 END SUB -SUB lendp (x1, m) +SUB lendP (x1, m) +' Measures the length of a logical expression enclosed in parentheses IF tehe(x1) <> 40 THEN m = 1: GOTO 17 c = x1 d = 1 @@ -161,6 +176,7 @@ m = c - x1 + 1 END SUB SUB lihts (x1, x2, l) +' Removes redundant parentheses from the logical expression rmslg x1, x2, l1 l = l1 'BEEP @@ -171,13 +187,15 @@ NEXT a END SUB SUB mov (x1, n) +' Moves a portion of the logical expression to the right FOR a = 79 - n TO x1 STEP -1 tehe(a + n) = tehe(a) xloc(a + n) = xloc(a) NEXT a END SUB -SUB movm (x1, n) +SUB movM (x1, n) +' Moves a portion of the logical expression to the left FOR a = x1 TO 79 - n tehe(a) = tehe(a + n) xloc(a) = xloc(a + n) @@ -185,6 +203,7 @@ NEXT a END SUB SUB prepare +' Prepares the logical equation for processing CLS ln = 79 @@ -227,6 +246,7 @@ a$ = INPUT$(1) END SUB SUB prn (x, y, c, c1, a$) +' Prints characters to the screen in a specific location and color x1 = x * 8 y1 = (y + prnp) * 8 @@ -247,6 +267,7 @@ NEXT b END SUB SUB rmslg (x1, x3, l) +' Removes redundant parentheses from the logical expression x2 = x3 l2 = 0 @@ -254,7 +275,7 @@ l2 = 0 a = x1 26 IF tehe(a) = 40 THEN - IF a = x1 THEN p1 = 100 ELSE getp tehe(a - 1), p1 + IF a = x1 THEN p1 = 100 ELSE getP tehe(a - 1), p1 c = a d = 1 p2 = 0 @@ -264,16 +285,16 @@ IF tehe(a) = 40 THEN IF tehe(c) = 41 THEN d = d - 1 IF d = 1 THEN IF (tehe(c) > 0) AND (tehe(c) <= 5) THEN - getp tehe(c), b + getP tehe(c), b IF b > p2 THEN p2 = b END IF END IF IF d > 0 THEN GOTO 25 - IF c + 1 > x2 THEN p3 = 100 ELSE getp tehe(c + 1), p3 + IF c + 1 > x2 THEN p3 = 100 ELSE getP tehe(c + 1), p3 IF (p1 > p2) AND (p3 >= p2) THEN - movm c, 1 - movm a, 1 + movM c, 1 + movM a, 1 l2 = l2 + 2 x2 = x2 - 2 a = a - 1 @@ -286,6 +307,7 @@ l = l2 END SUB SUB sist +' Interacts with the user to input a logical equation CLS prn 0, 0, 3, 0, "enter equation (ESC to quit) keys: 1 - " + CHR$(1) + " 2 - " + CHR$(2) + " 3 - " + CHR$(3) + " 4 - " + CHR$(4) + " 5 - " + CHR$(5) prn 0, 1, 3, 0, "example: a" + CHR$(1) + "b" + CHR$(2) + "(g" + CHR$(3) + "b)" @@ -340,6 +362,7 @@ GOTO 1 END SUB SUB start +' Initializes the screen and font prnp = 0 SCREEN 7 @@ -396,6 +419,7 @@ SCREEN 12 END SUB SUB tee (x1, x2) +' Processes the logical equation and applies logical operations DIM opr(1 TO 2, 1 TO tehl) ng = 0 ngx = 0 @@ -502,6 +526,7 @@ NEXT c END SUB SUB teeslg (x1, x4, l) +' Prepares the logical equation for solving by simplifying expressions within parentheses x2 = x4 h = 0 FOR e = 1 TO 4 @@ -515,8 +540,8 @@ FOR e = 1 TO 4 d = 1 14 c = c + 1 - IF tehe(c) = 40 THEN d = d + 1 - IF tehe(c) = 41 THEN d = d - 1 + IF tehe(c) = ASC("(") THEN d = d + 1 + IF tehe(c) = ASC(")") THEN d = d - 1 IF d = 0 THEN GOTO 15 GOTO 14 15 @@ -581,5 +606,4 @@ FOR e = 1 TO 4 IF a <= x2 THEN GOTO 21 NEXT e l = h -END SUB - +END SUB \ No newline at end of file -- 2.20.1