Exercises · SymPy + Z3 · Topics: modus ponens, modus tollens, hypothetical syllogism, disjunctive syllogism, addition, simplification, conjunction, resolution, quantified rules, multi-step inference
Pr. Zouhair el Hadiq
Each rule is shown in natural-deduction (Gentzen) form: premises above the bar, conclusion below.
Helper to use in all exercises: write a function valid(premises_conj, conclusion) -> bool that returns True iff the argument is valid.
not satisfiable(And(premises, Not(conclusion))).Verify the validity of Modus Ponens using the valid helper.
valid(And(p, Implies(p, q)), q) and assert the result is True.Verify Modus Tollens:
And(Not(q), Implies(p, q)) and check against Not(p).Verify Hypothetical Syllogism:
Verify Disjunctive Syllogism:
Verify both rules:
Verify both rules:
valid helper and assert the results.Store all eight rules in a dictionary mapping rule names to (premises, conclusion) tuples. Iterate over the dictionary and verify every rule is valid.
"Modus Ponens : True", etc.True — if any assertion fails, which rule is broken?Model the following argument and verify its validity:
Conclusion: You will need a swimsuit or go to the gym. $\mathrm{Swimsuit} \vee \mathrm{Gym}$
And, and call valid.The following is a common logical fallacy. Show that it is not a valid argument:
valid and assert the result is False.satisfiable to find and print a counterexample (assignment where premises are True but conclusion is False).Use Z3 to verify two quantified rules of inference:
Universal Instantiation: $\forall x\; H(x) \to M(x)$ and $H(\text{socrates})$ implies $M(\text{socrates})$.
Person = DeclareSort('Person'), declare functions $H$ and $M$, add the axioms, assume $\neg M(\text{socrates})$, and check for unsat.Existential Generalization: $M(\text{socrates})$ implies $\exists x\; M(x)$.
unsat.Model and verify the following argument:
Conclusion: Someone gets a detention. $\mathrm{ExDetention}$
ExCheat, ExDirector, ExDetention).valid and identify which rules are applied (modus tollens + disjunctive syllogism).