A Lean 4 layer for symbolic logic.
The idea:
- Lean still checks every proof
- users get a much smaller proof vocabulary at the start
- the proof scripts can look closer to natural deduction
- the first few Logic 2010 moves now map to explicit Lean tactics
Leanlogic/ND.leanclassroom style helper lemmas such asmp,adj,sl,sr,bc_left, andbc_rightLeanlogic/Tactics.leancustom tactics likeASS_CD,EI,UI,MP,ADJ,EG,DM,QN, andLLLeanlogic/Examples.leancompiled examples showing the layer in useLeanlogic/Workbook/Chapter1.leansentential logic examples keyed to the basic and derived rule handoutsLeanlogic/Workbook/Chapter2.leanquantifier examples keyed to the quantifier handout and strategy notesLeanlogic/Workbook/Chapter3.leanidentity examples keyed to the identity handoutLeanlogic/Workbook.leanone import for the workbook modulesLeanlogic/Exercises/Week06.leanbasic rule exercises based on Logic 2010 and the sample test sheetLeanlogic/Exercises/Week07.leanderived rule exercises based on Logic 2010 chapter two style problemsLeanlogic/Exercises/Week09.leanquantifier exercises based on Logic 2010 chapter three problemsLeanlogic/Exercises/Week10.leanlater quantifier and identity exercisesLeanlogic/Exercises.leanone import for the week based exercise modulesLeanlogic/Theorems/Chapter2.leannumbered sentential theorems likeT33,T45,T66, andT90Leanlogic/Theorems/Chapter3.leannumbered quantifier theorems likeT201toT206andT231toT232Leanlogic/Theorems.leanone import for the theorem bankLeanlogic/TheoremTactics.leantheorem number commands likeT 45Leanlogic/TheoremDrills.leancompiled examples using numbered theoremsLeanlogic/Symbolization/Syntax.leana small symbolic formula language for english to symbols and backLeanlogic/Symbolization/Patterns.leancourse style builders likeunless,only if,all are, andevery loves someLeanlogic/Symbolization/Examples.leanchecked example cards pulled from the local symbolization materialLeanlogic/Symbolization/Tutorial.leanfollow along symbolization examples followed by exercises withsorryLeanlogic/Symbolization/Workflow.leana direct write inspect and check workflow with evalsLeanlogic/Symbolization/Practice/Easy.leana logic2010 style easy practice sheet with legends and answer cardsLeanlogic/Symbolization/Practice.leanone import for the practice sheetsLeanlogic/Symbolization/Questions/Chapter1Sentential.leanchapter one sentential logic symbolization questions withsorryslots and checksLeanlogic/Symbolization/Questions.leanone import for the question banksLeanlogic/Symbolization.leanone import for the symbolization layerLeanlogic.leanone import that pulls the whole layer in
From the repo root:
lake +leanprover-community/mathlib4:lean-toolchain buildThen in a Lean file:
import LeanlogicThe main tactics currently implemented:
ASS_CD hintroduces an assumption likeintro hASS_ID hstarts an indirect derivation by assuming the negation of the goalUD yintroduces a universally quantified variable likeintro yR h as h3repetitionDN h as h3query style double negation that can introduce or eliminateS h as h3query style simplification that can pick either conjunctSHOW φwrites the current goal explicitly asφSHOW_CONC φa Logic 2010 flavored alias forSHOWSHOW_CONS ha Logic 2010 flavored alias for assuming the antecedent of a conditional goalDD hdirect derivation close stepCD hconditional derivation close stepID h1, h2closes from an explicit contradiction in either orderEI h as u, huopens an existential witness and its factUI hu with t as h5instantiates a universal statement attSID tprovest = tSM h as h5symmetry of identityBC_LEFT h as h5fromP ↔ QgetsP → QBC_RIGHT h as h5fromP ↔ QgetsQ → PBC h as h5query style biconditional conditional stepBP h1, h2 as h3biconditional ponens in either directionBT h1, h2 as h3biconditional tollens in either directionSL h as h5gets the left half of a conjunctionSR h as h5gets the right half of a conjunctionMP h1, h2 as h3modus ponensADJ h1, h2 as h3conjunction introductionCB h1, h2 as h3biconditional introductionDNI h as h3double negation introductionDNE h as h3double negation eliminationMT h1, h2 as h3modus tollensHS h1, h2 as h3hypothetical syllogismADDL h as h3addition on the leftADDR h as h3addition on the rightADDL h with φ as h3left addition with an explicit parameter like Logic 2010 command modeADDR h with φ as h3right addition with an explicit parameter like Logic 2010 command modeDS_LEFT h1, h2 as h3disjunctive syllogism using¬PDS_RIGHT h1, h2 as h3disjunctive syllogism using¬QMTP h1, h2 as h3Logic 2010 style modus tollendo ponens in either directionNC h as h3negated conditional in or outNB h as h3negated biconditional in or outDM h as h3demorgan in or outCDJ h as h3corresponding conditional in or outSC h1, h2, h3 as h4separation of cases from a disjunction and two conditionalsSC h1, h2 as h3separation of cases from a conditional and its negated antecedent versionAV h as h3alphabetical variance for quantifiersQN h as h3quantifier negation in or outLL h1, h2 as h3leibniz for unary predicatesLL_WITH h1, h2 using (fun z => ...) as h3leibniz with an explicit abstraction for a chosen argument slotEG tstarts an existential proof with witnesst
The Logic 2010 help text leans hard on Show lines and commands like Show Conj,
Show Cond, and Show Conclusion.
leanlogic has:
SHOW_CONJ_LEFTstarts the left conjunct of a conjunction goalSHOW_CONJ_RIGHTstarts the right conjunct of a conjunction goalSHOW_COND_LEFTstarts the left conditional of a biconditional goalSHOW_COND_RIGHTstarts the right conditional of a biconditional goalSHOW_ALT_LEFTpicks the left side of a disjunction goalSHOW_ALT_RIGHTpicks the right side of a disjunction goalSHOW_CORRturns a disjunction goal into its corresponding conditionalSHOW_ANT hturns a matching conditional or biconditional line into an antecedent goalSHOW_ANT_LEFT hleft branch of the biconditional antecedent querySHOW_ANT_RIGHT hright branch of the biconditional antecedent querySHOW_NEGCONS hturns a matching conditional or biconditional line into a negated consequent goalSHOW_NEGCONS_LEFT hleft branch of the biconditional negated consequent querySHOW_NEGCONS_RIGHT hright branch of the biconditional negated consequent querySHOW_UNNEGturns a negated compound goal into the positive rule shape that proves itSHOW_NEGDISJ hturns a matching disjunction line into a negated disjunct goalSHOW_NEGDISJ_LEFT h as h2proves the negation of the left disjunct and then gives the right disjunct a nameSHOW_NEGDISJ_RIGHT h as h2proves the negation of the right disjunct and then gives the left disjunct a nameSHOW_INST ydoes the universal derivation move with a chosen fresh variable nameUD_CLOSE hcloses the instance step of a universal derivation
leanlogic also has a numbered theorem layer closer to Logic 2010:
- chapter 2 theorem numbers such as
T33,T42,T45,T49,T50,T63,T64,T65,T66,T74,T75,T76,T77, andT90 - chapter 3 theorem numbers such as
T201,T202,T203,T204,T205,T206,T231, andT232
There is also a theorem command:
have h : (P ∨ Q) ↔ (¬P → Q) := by
T 45and a shorter context-sensitive form:
T 45 as hwhen the local names line up with the theorem statement.
These tactics throw friendlier errors when the current goal has the wrong shape.
leanlogic has a chapter style workbook:
Leanlogic.Workbook.Chapter1sentential rules and strategy moves likeSHOW_CORR,DM,NC, andSCLeanlogic.Workbook.Chapter2quantifier rules and strategy moves likeSHOW_INST,QN,AV,EI,UI, andEGLeanlogic.Workbook.Chapter3identity rules likeSID,SM, andLL
If you just want everything loaded:
import Leanlogic.WorkbookThere is also a week based exercises layer built from the local Logic 2010 problem database and some common symbolic logic problems:
Leanlogic.Exercises.Week06basic rules and early strategy movesLeanlogic.Exercises.Week07derived rules and show command style problemsLeanlogic.Exercises.Week09quantifier exercisesLeanlogic.Exercises.Week10identity and later quantified exercises
If you want those loaded too:
import Leanlogic.ExercisesAs of now, there is no separate DD tactic in this repo and that is intentional. This is because Lean already handles discharge through proof block structure so the leanlogic pattern is:
theorem tiny {P Q : Prop} : P → Q → P := by
ASS_CD h
ASS_CD h2
exact hWhen the block closes, the assumptions are discharged!
This proof from Leanlogic/Examples.lean is fully checked by Lean:
theorem warmup_swap {P Q : Prop} : P ∧ Q → Q ∧ P := by
ASS_CD h
SL h as h5
SR h as h6
ADJ h6, h5 as h7
exact h7There is also a larger quantifier example in Leanlogic/Examples.lean:
warmup_show_conjwarmup_show_condwarmup_mtwarmup_ass_iddemo_forwarddemo_backwarddemo_full
And there are chapter-based examples such as:
Leanlogic.Workbook.Chapter1.c1_show_corrLeanlogic.Workbook.Chapter2.c2_ei_before_uiLeanlogic.Workbook.Chapter3.c3_identity_quantifier
And there are exercise style problems such as:
Leanlogic.Exercises.Week06.sample_test_basicLeanlogic.Exercises.Week06.deriv_1_015Leanlogic.Exercises.Week06.koo_t2_q5Leanlogic.Exercises.Week07.deriv_2_00gLeanlogic.Exercises.Week07.deriv_2_009Leanlogic.Exercises.Week07.deriv_2_019_show_negdisjLeanlogic.Exercises.Week09.deriv_3_010Leanlogic.Exercises.Week09.deriv_3_033Leanlogic.Exercises.Week10.deriv_4_010Leanlogic.Exercises.Week10.deriv_4_020
And there are theorem-number drills such as:
Leanlogic.TheoremDrills.use_t45Leanlogic.TheoremDrills.use_t203Leanlogic.TheoremDrills.use_t231
leanlogic has a first symbolization layer too.
NOTE: As of now this is not a full free form natural language parser yet.
It is a structured layer with:
- a formula and term syntax
- ascii and unicode renderers
- a plain english readback
- course style pattern builders for common english forms
- curated english to symbol example cards
If you want it directly:
import Leanlogic.SymbolizationSome useful entry points are:
Leanlogic.Symbolization.inspectLeanlogic.Symbolization.checkAgainstLeanlogic.Symbolization.exerciseReportLeanlogic.Symbolization.Patterns.unless5Leanlogic.Symbolization.Patterns.onlyIfLeanlogic.Symbolization.Patterns.allAreLeanlogic.Symbolization.Patterns.someAreLeanlogic.Symbolization.Patterns.noAreLeanlogic.Symbolization.Patterns.everyLovesSomeLeanlogic.Symbolization.Examples.cardsLeanlogic.Symbolization.Tutorial.ExamplesLeanlogic.Symbolization.Tutorial.ExercisesLeanlogic.Symbolization.Workflow.ExamplesLeanlogic.Symbolization.Workflow.ExercisesLeanlogic.Symbolization.Practice.EasyLeanlogic.Symbolization.Questions.Chapter1Sentential
Examples from the symbolization bank include:
P unless QP only if QP is necessary for Qneither P nor Qall dogs are mammalssome dogs are brownevery giraffe frolics only if it is happyevery giraffe loves some monkey
If you want a follow along file with finished examples first and then exercises to fill in yourself, start in:
Leanlogic/Symbolization/Tutorial.lean
That file intentionally includes sorry in the exercise section.
If you want the most direct workflow for writing your own symbolization and checking it against an answer, start in:
Leanlogic/Symbolization/Workflow.lean
That file shows the pattern:
def p : Formula := "P"
def q : Formula := "Q"
def mine : Formula :=
symb% p ∧ ¬ q
#eval inspect mine
#eval checkAgainst mine (symb% p ∧ ¬ q)If you want a sheet that feels more like the Logic 2010 symbolization screen with letter legends and ready made prompts, open:
Leanlogic/Symbolization/Practice/Easy.lean
If you want a real chapter one sentential logic question bank with sorry
attempts and ready made check commands, open:
Leanlogic/Symbolization/Questions/Chapter1Sentential.lean
There are also explicit close-step demos in Leanlogic.Examples:
warmup_ddwarmup_ass_idwarmup_ud_close
If you find leanlogic useful, feel free to reach out or open an issue if you have any extension suggestions (or if you encounter any bugs, of course). Thanks!