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.SatisfiabilityAgreesIs satisfiable?Independent answerThe four clauses rule out each of the four assignments to : unsatisfiable.RatMath code
logic.satisfiable("(p | q) & (~p | q) & (p | ~q) & (~p | ~q)").statusOutputunsatisfiable
- 2.EntailmentAgreesShow .Independent answerIn any valuation with true, forces true, contradicting . So is false (modus tollens).RatMath code
logic.entails("p -> q, ~q", "~p").statusOutputvalid
- 3.Conjunctive normal formAgreesPut in conjunctive normal form.Independent answer.RatMath code
String(logic.cnf("p <-> q"))Output(p ∨ ¬q) ∧ (¬p ∨ q)
- 4.Counting modelsAgreesHow many of the 8 valuations of satisfy ?Independent answerAll but the all-false one: 7.RatMath code
logic.countModels("p | q | r", ["p", "q", "r"])Output7n
- 5.Minimal DNFAgreesFind a minimal sum of products for .Independent answerThe minterms form a 6-cycle on the cube; it is covered by three of its edges, e.g. (the other cover is ). 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.Natural deductionAgreesGive a natural-deduction proof of .Independent answerAssume ; assume ; assume ; then by E, contradiction with ; so by I; discharge twice with I.RatMath code
const r = logic.prove("", "(p -> q) -> (~q -> ~p)"); [r.status, logic.checkProof(String(r.proof)).status]Output["proved", "proof"]
- 7.Checking a proofAgreesCheck this proof of : 1. premise; 2. premise; 3. assumption; 4. E 1, 3; 5. E 4, 2; 6. I 3–5.Independent answerEach line follows by the rule cited; the assumption at 3 is discharged at 6. It is a correct proof of .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.ResolutionAgreesUse resolution to show .Independent answerAdd . Resolve with on : . Resolve with : 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.Intuitionistic logicAgreesWhich of these are provable intuitionistically: ; ; Peirce's law ? Which classically?Independent answerIntuitionistically only : assume ; then gives a contradiction, so , so , 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.First-order validityAgreesIs valid?Independent answerYes, given that domains are non-empty: pick any element ; holds, so .RatMath code
logic.foEntails([], "(forall x. P(x)) -> exists x. P(x)").statusOutputvalid
- 11.Swapping quantifiersAgreesShow , and that the converse fails.Independent answerIf is related to every , then every has . Converse: on with every has some , but no works for all .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.Prenex normal formAgreesPut in prenex form.Independent answer.RatMath code
String(logic.prenex("(forall x. P(x)) -> exists y. Q(y)"))Output∃x ∃y (¬P(x) ∨ Q(y))
- 13.Skolem normal formAgreesSkolemize .Independent answerReplace by a new function of the universally quantified : . Equisatisfiable, not equivalent.RatMath code
String(logic.skolemize("forall x. exists y. R(x,y)"))Output∀x R(x, sk1(x))
- 14.Truth in a structureAgreesOn the domain let . Evaluate and .Independent answerEach 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.Finding a modelAgreesWhat is the smallest model of ?Independent answerOne element cannot work (it would need ). Two do: . Smallest size 2.RatMath code
logic.findModel("(forall x. exists y. R(x,y)) & forall x. ~R(x,x)").sizeOutput2
- 16.Modal logic: KAgreesIs the distribution axiom valid in every Kripke model? Is ?Independent answerThe first is valid on all frames (axiom K). fails at a world where is false but every world sees has (for example, sees nothing, so holds vacuously).RatMath code
[logic.modalValid("[](p -> q) -> ([]p -> []q)").status, logic.modalValid("[]p -> p").status]Output["valid", "invalid"]
- 17.Modal systems T and S5AgreesIs valid in T (reflexive frames)? Is valid in S5?Independent answerYes: every world sees itself. Yes: in an equivalence class every world sees the same worlds, so if some reachable world has , every world reaches it.RatMath code
[logic.modalValid("[]p -> p", { system: "T" }).status, logic.modalValid("<>p -> []<>p", { system: "S5" }).status]Output["valid", "valid"]
- 18.SyllogismsAgreesIs "All M are P; all S are M; therefore all S are P" valid? What is its traditional name?Independent answerValid: 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.Counting valid syllogismsAgreesOf the 256 syllogistic forms, how many are valid in modern logic, and how many with Aristotle's existential import?Independent answer15 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.TautologiesAgreesIs a tautology?Independent answerYes (hypothetical syllogism): if then , then .RatMath code
logic.valid("((p -> q) & (q -> r)) -> (p -> r)").statusOutputvalid