Course Test · University: upper level

Mathematical logic: RatMath answers

The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.

Agrees 20

Libraries used here: core, logic. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.

  1. 1.SatisfiabilityAgrees
    Is (p∨q)∧(¬p∨q)∧(p∨¬q)∧(¬p∨¬q)(p \lor q) \land (\lnot p \lor q) \land (p \lor \lnot q) \land (\lnot p \lor \lnot q) satisfiable?
    Independent answer
    The four clauses rule out each of the four assignments to p,qp, q: unsatisfiable.
    RatMath code
    logic.satisfiable("(p | q) & (~p | q) & (p | ~q) & (~p | ~q)").status
    Output
    unsatisfiable
  2. 2.EntailmentAgrees
    Show p→q, ¬q⊨¬pp \to q,\ \lnot q \models \lnot p.
    Independent answer
    In any valuation with pp true, p→qp \to q forces qq true, contradicting ¬q\lnot q. So pp is false (modus tollens).
    RatMath code
    logic.entails("p -> q, ~q", "~p").status
    Output
    valid
  3. 3.Conjunctive normal formAgrees
    Put p↔qp \leftrightarrow q in conjunctive normal form.
    Independent answer
    (p→q)∧(q→p)≡(¬p∨q)∧(p∨¬q)(p \to q) \land (q \to p) \equiv (\lnot p \lor q) \land (p \lor \lnot q).
    RatMath code
    String(logic.cnf("p <-> q"))
    Output
    (p ∨ ¬q) ∧ (¬p ∨ q)
  4. 4.Counting modelsAgrees
    How many of the 8 valuations of p,q,rp, q, r satisfy p∨q∨rp \lor q \lor r?
    Independent answer
    All but the all-false one: 7.
    RatMath code
    logic.countModels("p | q | r", ["p", "q", "r"])
    Output
    7n
  5. 5.Minimal DNFAgrees
    Find a minimal sum of products for f(a,b,c)=∑m(0,1,2,5,6,7)f(a, b, c) = \sum m(0, 1, 2, 5, 6, 7).
    Independent answer
    The minterms form a 6-cycle on the cube; it is covered by three of its edges, e.g. aˉbˉ+bcˉ+ac\bar a\bar b + b\bar c + ac (the other cover is aˉcˉ+bˉc+ab\bar a\bar c + \bar bc + ab). Three terms of two literals.
    RatMath code
    String(logic.minimize(logic.fromMinterms(["a", "b", "c"], [0, 1, 2, 5, 6, 7])).formula)
    Output
    (a ∧ c) ∨ (b ∧ ¬c) ∨ (¬a ∧ ¬b)
  6. 6.Natural deductionAgrees
    Give a natural-deduction proof of (p→q)→(¬q→¬p)(p \to q) \to (\lnot q \to \lnot p).
    Independent answer
    Assume p→qp \to q; assume ¬q\lnot q; assume pp; then qq by →\toE, contradiction with ¬q\lnot q; so ¬p\lnot p by ¬\lnotI; discharge twice with →\toI.
    RatMath code
    const r = logic.prove("", "(p -> q) -> (~q -> ~p)");
    [r.status, logic.checkProof(String(r.proof)).status]
    Output
    ["proved", "proof"]
  7. 7.Checking a proofAgrees
    Check this proof of p→q, ¬q⊢¬pp \to q,\ \lnot q \vdash \lnot p: 1. p→qp \to q premise; 2. ¬q\lnot q premise; 3. ∣p\mid p assumption; 4. ∣q\mid q →\toE 1, 3; 5. ∣⊥\mid \bot ¬\lnotE 4, 2; 6. ¬p\lnot p ¬\lnotI 3–5.
    Independent answer
    Each line follows by the rule cited; the assumption at 3 is discharged at 6. It is a correct proof of p→q,¬q⊢¬pp \to q, \lnot q \vdash \lnot p.
    RatMath code
    const r = logic.checkProof(`1. p -> q      premise
    2. ~q          premise
    3. | p         assumption
    4. | q         ->E 1, 3
    5. | _|_       ~E 4, 2
    6. ~p          ~I 3-5`);
    [r.status, r.proves]
    Output
    ["proof", "p → q, ¬q ⊢ ¬p"]
  8. 8.ResolutionAgrees
    Use resolution to show p∨q, ¬p∨q⊨qp \lor q,\ \lnot p \lor q \models q.
    Independent answer
    Add ¬q\lnot q. Resolve p∨qp \lor q with ¬p∨q\lnot p \lor q on pp: qq. Resolve qq with ¬q\lnot q: the empty clause.
    RatMath code
    const r = logic.entails("p | q, ~p | q", "q");
    [r.status, logic.checkResolution(r.refutation).ok ?? logic.checkResolution(r.refutation).status]
    Output
    ["valid", true]
  9. 9.Intuitionistic logicAgrees
    Which of these are provable intuitionistically: p∨¬pp \lor \lnot p; ¬¬(p∨¬p)\lnot\lnot(p \lor \lnot p); Peirce's law ((p→q)→p)→p((p \to q) \to p) \to p? Which classically?
    Independent answer
    Intuitionistically only ¬¬(p∨¬p)\lnot\lnot(p \lor \lnot p): assume ¬(p∨¬p)\lnot(p \lor \lnot p); then pp gives a contradiction, so ¬p\lnot p, so p∨¬pp \lor \lnot p, a contradiction. Excluded middle and Peirce's law are classical tautologies but not intuitionistic theorems.
    RatMath code
    const P = (f, logic_) => logic.prove("", f, { logic: logic_ }).status;
    [P("p | ~p", "intuitionistic"), P("~~(p | ~p)", "intuitionistic"), P("((p -> q) -> p) -> p", "intuitionistic"), P("((p -> q) -> p) -> p", "classical")]
    Output
    ["unprovable", "proved", "unprovable", "proved"]
  10. 10.First-order validityAgrees
    Is ∀x P(x)→∃x P(x)\forall x\,P(x) \to \exists x\,P(x) valid?
    Independent answer
    Yes, given that domains are non-empty: pick any element aa; P(a)P(a) holds, so ∃x P(x)\exists x\,P(x).
    RatMath code
    logic.foEntails([], "(forall x. P(x)) -> exists x. P(x)").status
    Output
    valid
  11. 11.Swapping quantifiersAgrees
    Show ∃x∀y R(x,y)⊨∀y∃x R(x,y)\exists x\forall y\,R(x, y) \models \forall y\exists x\,R(x, y), and that the converse fails.
    Independent answer
    If aa is related to every yy, then every yy has aa. Converse: on {0,1}\{0, 1\} with R={(0,0),(1,1)}R = \{(0, 0), (1, 1)\} every yy has some xx, but no xx works for all yy.
    RatMath code
    const fwd = logic.foEntails(["exists x. forall y. R(x,y)"], "forall y. exists x. R(x,y)");
    const back = logic.foEntails(["forall y. exists x. R(x,y)"], "exists x. forall y. R(x,y)");
    [fwd.status, back.status, back.countermodel.size]
    Output
    ["valid", "invalid", 2]
  12. 12.Prenex normal formAgrees
    Put ∀x P(x)→∃y Q(y)\forall x\,P(x) \to \exists y\,Q(y) in prenex form.
    Independent answer
    ¬∀x P(x)∨∃y Q(y)≡∃x∃y (¬P(x)∨Q(y))\lnot\forall x\,P(x) \lor \exists y\,Q(y) \equiv \exists x\exists y\,(\lnot P(x) \lor Q(y)).
    RatMath code
    String(logic.prenex("(forall x. P(x)) -> exists y. Q(y)"))
    Output
    ∃x ∃y (¬P(x) ∨ Q(y))
  13. 13.Skolem normal formAgrees
    Skolemize ∀x∃y R(x,y)\forall x\exists y\,R(x, y).
    Independent answer
    Replace yy by a new function of the universally quantified xx: ∀x R(x,f(x))\forall x\,R(x, f(x)). Equisatisfiable, not equivalent.
    RatMath code
    String(logic.skolemize("forall x. exists y. R(x,y)"))
    Output
    ∀x R(x, sk1(x))
  14. 14.Truth in a structureAgrees
    On the domain {1,2,3}\{1, 2, 3\} let L={(1,2),(2,3),(3,1)}L = \{(1,2), (2,3), (3,1)\}. Evaluate ∀x∃y L(x,y)\forall x\exists y\,L(x, y) and ∃x∀y L(x,y)\exists x\forall y\,L(x, y).
    Independent answer
    Each element has a successor in the cycle: the first is true. No element is related to all three: the second is false.
    RatMath code
    const M = logic.structure({ domain: [1, 2, 3], predicates: { L: [[1, 2], [2, 3], [3, 1]] } });
    [logic.evaluate("forall x. exists y. L(x, y)", M).value, logic.evaluate("exists x. forall y. L(x, y)", M).value]
    Output
    [true, false]
  15. 15.Finding a modelAgrees
    What is the smallest model of ∀x∃y R(x,y)∧∀x ¬R(x,x)\forall x\exists y\,R(x, y) \land \forall x\,\lnot R(x, x)?
    Independent answer
    One element cannot work (it would need R(a,a)R(a, a)). Two do: R={(0,1),(1,0)}R = \{(0, 1), (1, 0)\}. Smallest size 2.
    RatMath code
    logic.findModel("(forall x. exists y. R(x,y)) & forall x. ~R(x,x)").size
    Output
    2
  16. 16.Modal logic: KAgrees
    Is the distribution axiom □(p→q)→(□p→□q)\Box(p \to q) \to (\Box p \to \Box q) valid in every Kripke model? Is □p→p\Box p \to p?
    Independent answer
    The first is valid on all frames (axiom K). □p→p\Box p \to p fails at a world ww where pp is false but every world ww sees has pp (for example, ww sees nothing, so □p\Box p holds vacuously).
    RatMath code
    [logic.modalValid("[](p -> q) -> ([]p -> []q)").status, logic.modalValid("[]p -> p").status]
    Output
    ["valid", "invalid"]
  17. 17.Modal systems T and S5Agrees
    Is □p→p\Box p \to p valid in T (reflexive frames)? Is ◊p→□◊p\Diamond p \to \Box\Diamond p valid in S5?
    Independent answer
    Yes: every world sees itself. Yes: in an equivalence class every world sees the same worlds, so if some reachable world has pp, every world reaches it.
    RatMath code
    [logic.modalValid("[]p -> p", { system: "T" }).status, logic.modalValid("<>p -> []<>p", { system: "S5" }).status]
    Output
    ["valid", "valid"]
  18. 18.SyllogismsAgrees
    Is "All M are P; all S are M; therefore all S are P" valid? What is its traditional name?
    Independent answer
    Valid: mood AAA in the first figure, Barbara.
    RatMath code
    const r = logic.syllogism("All M are P", "All S are M", "All S are P");
    [r.valid, r.form, r.name]
    Output
    [true, "AAA-1", "Barbara"]
  19. 19.Counting valid syllogismsAgrees
    Of the 256 syllogistic forms, how many are valid in modern logic, and how many with Aristotle's existential import?
    Independent answer
    15 unconditionally valid; with existential import 9 more (the weakened and strengthened moods such as Darapti and Barbari): 24.
    RatMath code
    [logic.validSyllogisms().length, logic.validSyllogisms({ existentialImport: true }).length]
    Output
    [15, 24]
  20. 20.TautologiesAgrees
    Is ((p→q)∧(q→r))→(p→r)((p \to q) \land (q \to r)) \to (p \to r) a tautology?
    Independent answer
    Yes (hypothetical syllogism): if pp then qq, then rr.
    RatMath code
    logic.valid("((p -> q) & (q -> r)) -> (p -> r)").status
    Output
    valid