Boolean algebra and logic circuits · A level · OCR H446 1.4.3, AQA 7517 4.6.5.1, Eduqas A500QS 1.2 · about 20 min
The identities, commutation, association, distribution, double negation and absorption, proved by truth table.
[1 mark]Which law is used in the step A ∧ (B ∨ C) = (A ∧ B) ∨ (A ∧ C)?
[1 mark]What is A ∨ 1?
[1 mark]What does A ∨ (A ∧ B) simplify to?
[1 mark]What does A ∨ (¬A ∧ B) simplify to?
[1 mark]Which of these are true for every value of A, B and C?
Tick every answer that is true.
[1 mark]What does this program print?
count = 0
for a in [0, 1]:
for b in [0, 1]:
for c in [0, 1]:
if (a | (b & c)) != ((a | b) & c):
count = count + 1
print(count)2
A ∨ (B ∧ C) and (A ∨ B) ∧ C differ whenever A = 1 and C = 0, which is 2 of the 8 rows.
Write equivalent(f, g). Its inputs f and g are functions of three bits, f(a, b, c), each returning 0 or 1. It tries all eight rows in binary order (a, then b, then c, each 0 then 1) and returns the first row where f and g give different results, as a tuple (a, b, c), or None if they agree on every row.
Then, for each (name, f, g) in the list laws, in order, print one line: <name>: equivalent if they agree, or <name>: not equivalent at A=<a> B=<b> C=<c> using the row equivalent returned. That makes six lines.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
laws = [
("distribution", lambda a, b, c: a & (b | c), lambda a, b, c: (a & b) | (a & c)),
("absorption", lambda a, b, c: a | (a & b), lambda a, b, c: a),
("association", lambda a, b, c: (a | b) | c, lambda a, b, c: a | (b | c)),
("OR over AND", lambda a, b, c: a | (b & c), lambda a, b, c: (a | b) & (a | c)),
("false friend", lambda a, b, c: a | (b & c), lambda a, b, c: (a | b) & c),
("half absorbed", lambda a, b, c: a & (a | b), lambda a, b, c: a | b),
]
def equivalent(f, g):
return NoneThe hint students can ask for: Two expressions are equal only if they agree on every row, so loop through all eight combinations in binary order and stop at the first row where they differ. Return that row, or None if there is none, and let the printing code decide which message to show.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
laws = [
("distribution", lambda a, b, c: a & (b | c), lambda a, b, c: (a & b) | (a & c)),
("absorption", lambda a, b, c: a | (a & b), lambda a, b, c: a),
("association", lambda a, b, c: (a | b) | c, lambda a, b, c: a | (b | c)),
("OR over AND", lambda a, b, c: a | (b & c), lambda a, b, c: (a | b) & (a | c)),
("false friend", lambda a, b, c: a | (b & c), lambda a, b, c: (a | b) & c),
("half absorbed", lambda a, b, c: a & (a | b), lambda a, b, c: a | b),
]
def equivalent(f, g):
for a in [0, 1]:
for b in [0, 1]:
for c in [0, 1]:
if f(a, b, c) != g(a, b, c):
return (a, b, c)
return None
for name, f, g in laws:
row = equivalent(f, g)
if row is None:
print(f"{name}: equivalent")
else:
print(f"{name}: not equivalent at A={row[0]} B={row[1]} C={row[2]}")
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.