Ex 1 Basic Propositions SymPy

Use sympy.symbols to declare boolean variables $p$ and $q$. Build the compound expression $p \land (q \lor \neg p)$ and evaluate it for all four combinations of truth values.

Ex 2 NOT, AND, OR connectives

Using SymPy's Not, And, Or, compute $\neg p$, $p \land q$, and $p \lor q$ for all four assignments of $(p, q)$.

Ex 3 Implication Truth Table Implies

Build the expression $p \to q$ using sympy.Implies(p, q) and print its complete truth table using sympy.logic.boolalg.truth_table.

Reminder: $p \to q$ is False only when $p$ is True and $q$ is False.
Ex 4 Biconditional (↔) Equivalent

Build $p \leftrightarrow q$ using sympy.Equivalent(p, q) and print its full truth table.

Ex 5 Operator Precedence precedence

Evaluate two different parenthesisations of $\neg p \land q \lor r$ for the assignment $p = \text{True},\; q = \text{False},\; r = \text{True}$:

Show that A and B give different results and explain the standard precedence order: $\neg > \land > \lor > {\to} > {\leftrightarrow}$.

Ex 6 Converse, Contrapositive, Inverse implication

Given the implication $p \to q$, define and simplify (using simplify_logic) each of the following:

NameFormula
Original$p \to q$
Converse$q \to p$
Contrapositive$\neg q \to \neg p$
Inverse$\neg p \to \neg q$
Ex 7 Tautology Detection satisfiable

Write a helper is_tautology(expr) -> bool that returns True when an expression is a tautology (True for every assignment).

Hint: A formula is a tautology iff its negation is unsatisfiable — use not satisfiable(Not(expr)).

Apply it to each formula below and report the result:

Ex 8 Contradiction Detection satisfiable

Write is_contradiction(expr) -> bool that returns True when a formula is False for every assignment.

Hint: A formula is a contradiction iff it is not satisfiable — use not satisfiable(expr).

Test it on:

Ex 9 Exclusive OR (XOR) Xor

Use SymPy's Xor(p, q) and verify the equivalence:

$$p \oplus q \;\equiv\; (p \lor q) \land \neg(p \land q)$$

Ex 10 Logic Gates — NAND and NOR gates

Define Python functions NAND(a, b) and NOR(a, b) using SymPy's Not, And, Or.

Then show that NAND is functionally complete by expressing NOT, AND, and OR using only NAND:

Verify each equivalence using is_tautology(Equivalent(...)).

Ex 11 Three-Variable Truth Table truth_table

Consider the formula representing Hypothetical Syllogism:

$$\bigl((p \to q) \land (q \to r)\bigr) \to (p \to r)$$