Ex 1 De Morgan's First Law equivalence

Verify the equivalence $\neg(p \land q) \equiv \neg p \lor \neg q$ by comparing truth table outputs row by row.

Ex 2 De Morgan's Second Law equivalence

Verify the equivalence $\neg(p \lor q) \equiv \neg p \land \neg q$ using the same are_equivalent helper from Exercise 1.

Ex 3 Double Negation simplify_logic

Use simplify_logic(Not(Not(p))) and verify that the result equals $p$.

Ex 4 Absorption Laws simplify_logic

Verify both absorption laws using simplify_logic:

Assert that both expressions simplify to the symbol $p$ alone. Why is this called an "absorption" law?

Ex 5 Distributive Laws equivalence

Verify both distributive laws using are_equivalent over three variables $(p, q, r)$:

How many rows does a truth table with 3 variables have?

Ex 6 Simplification with simplify_logic simplify_logic

Simplify the following compound formulas using simplify_logic and verify each result equals $p$:

Hint: Both expressions can be simplified by factoring out $p$ using the distributive law, then applying the tautology $q \lor \neg q \equiv \top$.
Ex 7 Conjunctive Normal Form (CNF) to_cnf

Convert each of the following formulas to CNF using sympy.to_cnf. A CNF is a conjunction (AND) of clauses, where each clause is a disjunction (OR) of literals.

Print the CNF form of each and verify it is logically equivalent to the original using are_equivalent.

Ex 8 Disjunctive Normal Form (DNF) to_dnf

Convert each formula to DNF using sympy.to_dnf. A DNF is a disjunction (OR) of terms, where each term is a conjunction (AND) of literals.

Print the DNF form and verify equivalence with the original formula.

Ex 9 Satisfiability satisfiable

Use sympy.logic.inference.satisfiable to determine whether each formula below is satisfiable, unsatisfiable, or a tautology. satisfiable returns a model (dictionary) if satisfiable, or False if not.

For each satisfiable formula, print the model (assignment that makes it True).

Ex 10 Counting Function — At Least $k$ of $n$ combinations

Implement at_least_k_of(variables, k) that returns a SymPy formula which is True iff at least $k$ of the given variables are True.

Hint: Use itertools.combinations — "at least $k$ variables are True" iff some $k$-element subset is simultaneously True: Or(*[And(*combo) for combo in combinations(variables, k)]).
Ex 11 Implication Equivalences equivalence

Verify each of the following equivalences using are_equivalent:

NameEquivalence
Implication as disjunction$p \to q \;\equiv\; \neg p \lor q$
Contrapositive$p \to q \;\equiv\; \neg q \to \neg p$
Negation of implication$\neg(p \to q) \;\equiv\; p \land \neg q$

For each equivalence, assert the result and print a confirmation message.