Vocabulary

  • Truth Table A truth table is a breakdown of a logic function by listing all possible values the function can attain. Such a table typically contains several rows and columns, with the top row representing the logical variables and combinations, in increasing complexity leading up to the final function.

  • Linear Sequence of code The order of executions is strictly from top to bottom. This is good for learning, but is typically a poor method for an Algorithm! This was my 1st exploration above.

  • Procedure (Function) A Procedure is a set of code instructions that has been abstracted into logical parts. Each code abstraction is called "Procedural Abstraction".

  • AND

  • OR
  • XOR
  • NOT
def xor(x,y): 
  return (x or y) and not (x and y) 
 
# The boolean function
def F(A, B, C, D): 
  P = xor(A, B) 
  Q = xor(C, D) 
  R = xor(P, Q) 
  return R 
 
# Translates between 'T'/'F' and True/False: 
def f(a,b,c,d): 
  t = 'T' 
  (A,B,C,D) = (a==t, b==t, c==t, d==t) 
  R = F(A, B, C, D) 
  return "FT"[R] 
 
print("Truth Table") 
print() 
print("A B C D | f(A,B,C,D)") 
print("========|===========") 
r = "TF" 
for a in r: 
  for b in r: 
    for c in r: 
      for d in r: 
        print(a, b, c, d, "|    ", f(a, b, c, d)) 
Truth Table

A B C D | f(A,B,C,D)
========|===========
T T T T |     F
T T T F |     T
T T F T |     T
T T F F |     F
T F T T |     T
T F T F |     F
T F F T |     F
T F F F |     T
F T T T |     T
F T T F |     F
F T F T |     F
F T F F |     T
F F T T |     F
F F T F |     T
F F F T |     T
F F F F |     F