Skip to content

Commit 047b396

Browse files
benbrastmckieclaude
andcommitted
feat(Logics): five-primitive propositional signature with connective typeclasses
Refactors propositional logic to use an explicit five-primitive signature {atom, bot, imp, and, or} with connective typeclasses (HasBot, HasImp, HasAnd, HasOr, PropositionalConnectives), removing [Bot Atom] and [Inhabited Atom] constraints. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 87c249d commit 047b396

4 files changed

Lines changed: 249 additions & 106 deletions

File tree

Cslib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public import Cslib.Foundations.Data.RelatesInSteps
6969
public import Cslib.Foundations.Data.Set.Saturation
7070
public import Cslib.Foundations.Data.StackTape
7171
public import Cslib.Foundations.Lint.Basic
72+
public import Cslib.Foundations.Logic.Connectives
7273
public import Cslib.Foundations.Logic.InferenceSystem
7374
public import Cslib.Foundations.Logic.LogicalEquivalence
7475
public import Cslib.Foundations.Relation.Attr
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/-
2+
Copyright (c) 2026 Benjamin Brast-McKie. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Benjamin Brast-McKie
5+
-/
6+
7+
module
8+
9+
import Cslib.Init
10+
11+
/-! # Connective Typeclasses for Propositional Logic
12+
13+
This module defines a typeclass hierarchy for propositional logical connectives. Each formula
14+
type registers itself as an instance of the appropriate connective class, enabling polymorphic
15+
axiom definitions and notation that work uniformly across different formula types.
16+
17+
## Design
18+
19+
The hierarchy adopts a hybrid five-primitive propositional signature `{atom, bot, imp, and, or}`,
20+
following the operator-typeclass direction of fmontesi's PR #607 (one class per operator):
21+
- **Atomic classes**: `HasBot`, `HasImp`, `HasAnd`, `HasOr`
22+
- **Bundled class**: `PropositionalConnectives` (extends `HasBot` and `HasImp`)
23+
24+
Conjunction (`HasAnd`) and disjunction (`HasOr`) are treated as independent primitives rather
25+
than Łukasiewicz-derived connectives. The classical encodings `φ ∧ ψ := ¬(φ → ¬ψ)` and
26+
`φ ∨ ψ := ¬φ → ψ` are only propositionally equivalent to `∧` and `∨` in classical logic
27+
([Wajsberg1938], [McKinsey1939]); they fail in intuitionistic and minimal logic. Making `and`
28+
and `or` primitive via `HasAnd`/`HasOr` supports all three logic strengths with a single
29+
typeclass hierarchy.
30+
31+
Negation and verum stay derived: each concrete formula type defines `neg φ := φ → ⊥` and
32+
`top := ⊥ → ⊥` as `abbrev`s, which are valid in minimal, intuitionistic, and classical logic
33+
alike, so no typeclass machinery is needed for them.
34+
35+
## References
36+
37+
* [I. Johansson, *Der Minimalkalkül, ein reduzierter intuitionistischer Formalismus*][Johansson1937]
38+
* [M. Wajsberg, *Untersuchungen über den Aussagenkalkül von A. Heyting*][Wajsberg1938]
39+
* [J. C. C. McKinsey,
40+
*Proof of the Independence of the Primitive Symbols of Heyting's Calculus*][McKinsey1939]
41+
* [D. Prawitz, *Natural Deduction: A Proof-Theoretical Study*][Prawitz1965]
42+
* [A. S. Troelstra, D. van Dalen,
43+
*Constructivism in Mathematics: An Introduction*][TroelstraVanDalen1988]
44+
* [A. Church, *Introduction to Mathematical Logic*][Church1956]
45+
* [G. Gentzen, *Untersuchungen über das logische Schließen*][Gentzen1935]
46+
-/
47+
48+
@[expose] public section
49+
50+
namespace Cslib.Logic
51+
52+
/-- A type has a falsum (bottom) connective. -/
53+
class HasBot (F : Type*) where
54+
/-- The falsum/bottom connective. -/
55+
bot : F
56+
57+
/-- A type has an implication connective. -/
58+
class HasImp (F : Type*) where
59+
/-- The implication connective. -/
60+
imp : F → F → F
61+
62+
/-- A type has a conjunction connective. -/
63+
class HasAnd (F : Type*) where
64+
/-- The conjunction connective. -/
65+
and : F → F → F
66+
67+
/-- A type has a disjunction connective. -/
68+
class HasOr (F : Type*) where
69+
/-- The disjunction connective. -/
70+
or : F → F → F
71+
72+
/-- Propositional connectives: falsum and implication.
73+
74+
`HasAnd` and `HasOr` are defined as standalone atomic classes in this module.
75+
When all four connectives are needed, use
76+
`[PropositionalConnectives F] [HasAnd F] [HasOr F]`. -/
77+
class PropositionalConnectives (F : Type*) extends HasBot F, HasImp F
78+
79+
end Cslib.Logic

Cslib/Logics/Propositional/Defs.lean

Lines changed: 86 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,71 @@
11
/-
2-
Copyright (c) 2025 Thomas Waring. All rights reserved.
2+
Copyright (c) 2025 Thomas Waring, 2026 Benjamin Brast-McKie. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Thomas Waring
4+
Authors: Thomas Waring, Benjamin Brast-McKie
55
-/
66

77
module
88

9-
public import Cslib.Init
9+
import Cslib.Init
10+
public import Aesop.BuiltinRules
11+
public import Cslib.Foundations.Logic.Connectives
1012
public import Mathlib.Data.FunLike.Basic
11-
public import Mathlib.Data.Set.Image
13+
public import Mathlib.Data.Set.Basic
1214
public import Mathlib.Order.TypeTags
1315

1416
/-! # Propositions and theories
1517
1618
## Main definitions
1719
18-
- `Proposition` : the type of propositions over a given type of atom. This type has a `Bot`
19-
instance whenever `Atom` does, and a `Top` whenever `Atom` is inhabited.
20+
- `Proposition` : the type of propositions over a given type of atom. Primitives are `atom`,
21+
`bot` (falsum), `imp` (implication), `and` (conjunction), and `or` (disjunction). Negation
22+
(`neg`), verum (`top`), and biconditional (`iff`) are derived connectives (`abbrev`s). This
23+
follows natural deduction style ([Gentzen1935], [Prawitz1965], Ch. I sec. 1.2) and the
24+
constructive mathematics tradition ([Johansson1937], [TroelstraVanDalen1988]) in which `neg A`
25+
abbreviates `A → ⊥` rather than being taken as primitive.
2026
- `Theory` : set of `Proposition`.
2127
- `IsIntuitionistic` : a theory is intuitionistic if it contains the principle of explosion.
2228
- `IsClassical` : an intuitionistic theory is classical if it further contains double negation
23-
elimination.
29+
elimination.
2430
- `Proposition.subst` : replace `atom x` in a `A : Proposition Atom` with `f x`, for a function
2531
`f : Atom → Proposition Atom'`. This induces a monad structure on `Proposition`, with
2632
`pure := Proposition.atom`. `Theory` is a functor, by mapping each proposition `A ∈ T` to
2733
`f <$> A`.
2834
- `Theory.intuitionisticCompletion` : the freely generated intuitionistic theory extending a given
29-
theory.
35+
theory.
36+
37+
## Architecture
38+
39+
Two proof systems are defined for this propositional language:
40+
41+
- **Layer 1 — Natural Deduction** (`NaturalDeduction/Basic.lean`): a `Theory.Derivation` inductive
42+
with 10 primitive constructors (axiom, assumption, conjunction intro/elim ×2, disjunction
43+
intro ×2/elim, implication intro/elim). The theory parameter controls logic strength: `MPL`
44+
(Johansson's minimal logic, [Johansson1937]), `IPL` (intuitionistic), and `CPL` (classical).
45+
46+
- **Layer 2 — Hilbert System** (`ProofSystem/`): an axiom predicate hierarchy
47+
(`MinPropAxiom` / `IntPropAxiom` / `PropositionalAxiom`) with sequent derivability and a
48+
Hilbert-style proof-theoretic treatment.
49+
50+
- **Bridge**: `NaturalDeduction/Equivalence.lean` establishes extensional equivalence between the
51+
two proof systems for all three logic strengths, in both closed-context (`hilbert_iff_nd`,
52+
`hilbert_iff_nd_min`, `hilbert_iff_nd_int`, `hilbert_iff_nd_cl`) and context-based forms
53+
(`hilbert_iff_nd_ctx`, `hilbert_iff_nd_ctx_min`, `hilbert_iff_nd_ctx_int`,
54+
`hilbert_iff_nd_ctx_cl`).
3055
3156
## Notation
3257
3358
We introduce notation for the logical connectives: `⊥ ⊤ ∧ ∨ → ¬` for, respectively, falsum, verum,
3459
conjunction, disjunction, implication and negation.
60+
61+
## References
62+
63+
* [I. Johansson, *Der Minimalkalkül, ein reduzierter intuitionistischer Formalismus*][Johansson1937]
64+
* [G. Gentzen, *Untersuchungen über das logische Schließen*][Gentzen1935]
65+
* [D. Prawitz, *Natural Deduction: A Proof-Theoretical Study*][Prawitz1965]
66+
* [A. S. Troelstra, D. van Dalen,
67+
*Constructivism in Mathematics: An Introduction*][TroelstraVanDalen1988]
68+
* [A. Church, *Introduction to Mathematical Logic*][Church1956]
3569
-/
3670

3771
@[expose] public section
@@ -42,44 +76,61 @@ variable {Atom : Type u} [DecidableEq Atom]
4276

4377
namespace Cslib.Logic.PL
4478

45-
/-- Propositions. -/
79+
/-- Propositions. Primitives are atoms, falsum, implication, conjunction, and disjunction. -/
4680
inductive Proposition (Atom : Type u) : Type u where
4781
/-- Propositional atoms -/
4882
| atom (x : Atom)
83+
/-- Falsum / bottom -/
84+
| bot
85+
/-- Implication -/
86+
| imp (a b : Proposition Atom)
4987
/-- Conjunction -/
5088
| and (a b : Proposition Atom)
5189
/-- Disjunction -/
5290
| or (a b : Proposition Atom)
53-
/-- Implication -/
54-
| impl (a b : Proposition Atom)
5591
deriving DecidableEq, BEq
5692

57-
instance instBotProposition [Bot Atom] : Bot (Proposition Atom) := ⟨.atom ⊥⟩
58-
instance instInhabitedOfBot [Bot Atom] : Inhabited Atom := ⟨⊥⟩
59-
60-
/-- We view negation as a defined connective ~A := A → ⊥ -/
61-
abbrev Proposition.neg [Bot Atom] : Proposition Atom → Proposition Atom := (Proposition.impl · ⊥)
93+
/-- Negation as a derived connective: ¬A := A → ⊥ -/
94+
abbrev Proposition.neg : Proposition Atom → Proposition Atom := (Proposition.imp · .bot)
6295

63-
/-- A fixed choice of a derivable proposition (of course any two are equivalent). -/
64-
abbrev Proposition.top [Inhabited Atom] : Proposition Atom := impl (.atom default) (.atom default)
96+
/-- Verum / top as a derived connective: ⊤ := ⊥ → ⊥ -/
97+
abbrev Proposition.top : Proposition Atom := .imp .bot .bot
6598

66-
instance instTopProposition [Inhabited Atom] : Top (Proposition Atom) := ⟨.top⟩
99+
/-- Biconditional as a derived connective: A ↔ B := (A → B) ∧ (B → A) -/
100+
abbrev Proposition.iff (A B : Proposition Atom) : Proposition Atom :=
101+
(A.imp B).and (B.imp A)
67102

68-
example [Bot Atom] : (⊤ : Proposition Atom) = Proposition.impl ⊥ ⊥ := rfl
103+
instance : Bot (Proposition Atom) := ⟨.bot⟩
104+
instance : Top (Proposition Atom) := ⟨.top⟩
69105

70106
@[inherit_doc] scoped infix:36 " ∧ " => Proposition.and
71107
@[inherit_doc] scoped infix:35 " ∨ " => Proposition.or
72-
@[inherit_doc] scoped infix:30 " → " => Proposition.impl
108+
@[inherit_doc] scoped infix:30 " → " => Proposition.imp
109+
@[inherit_doc] scoped infix:20 " ↔ " => Proposition.iff
73110
@[inherit_doc] scoped prefix:40 " ¬ " => Proposition.neg
74111

112+
/-- Register `Proposition` as an instance of `PropositionalConnectives`. -/
113+
instance : PropositionalConnectives (Proposition Atom) where
114+
bot := .bot
115+
imp := .imp
116+
117+
/-- Register `HasAnd` instance for `Proposition`. -/
118+
instance : HasAnd (Proposition Atom) where
119+
and := .and
120+
121+
/-- Register `HasOr` instance for `Proposition`. -/
122+
instance : HasOr (Proposition Atom) where
123+
or := .or
124+
75125
/-- Substitute each atom in a proposition for a proposition, possibly changing the atomic
76126
language. -/
77127
def Proposition.subst {Atom Atom' : Type u} (f : Atom → Proposition Atom') :
78128
Proposition Atom → Proposition Atom'
79129
| atom x => f x
80-
| and A B => (A.subst f) ∧ (B.subst f)
81-
| or A B => (A.subst f) ∨ (B.subst f)
82-
| impl A B => (A.subst f) → (B.subst f)
130+
| bot => .bot
131+
| imp A B => .imp (A.subst f) (B.subst f)
132+
| and A B => .and (A.subst f) (B.subst f)
133+
| or A B => .or (A.subst f) (B.subst f)
83134

84135
-- This is probably a lawful monad, but that doesn't seem to be important.
85136
instance : Monad Proposition where
@@ -102,45 +153,45 @@ instance : Functor Theory where
102153
abbrev MPL : Theory (Atom) := ∅
103154

104155
/-- Intuitionistic propositional logic adds the principle of explosion (ex falso quodlibet). -/
105-
abbrev IPL [Bot Atom] : Theory Atom :=
106-
Set.range (⊥ → ·)
156+
abbrev IPL : Theory Atom :=
157+
Set.range (Proposition.imp ⊥ ·)
107158

108159
/-- Classical logic further adds double negation elimination. -/
109-
abbrev CPL [Bot Atom] : Theory Atom :=
160+
abbrev CPL : Theory Atom :=
110161
Set.range (fun (A : Proposition Atom) ↦ ¬¬A → A)
111162

112163
/-- A theory is intuitionistic if it validates ex falso quodlibet. -/
113164
@[scoped grind]
114-
class IsIntuitionistic [Bot Atom] (T : Theory Atom) where
165+
class IsIntuitionistic (T : Theory Atom) where
115166
efq (A : Proposition Atom) : (⊥ → A) ∈ T
116167

117168
omit [DecidableEq Atom] in
118169
@[scoped grind =]
119-
theorem isIntuitionisticIff [Bot Atom] (T : Theory Atom) : IsIntuitionistic T ↔ IPL ⊆ T := by grind
170+
theorem isIntuitionisticIff (T : Theory Atom) : IsIntuitionistic T ↔ IPL ⊆ T := by grind
120171

121172
/-- A theory is classical if it validates double-negation elimination. -/
122173
@[scoped grind]
123-
class IsClassical [Bot Atom] (T : Theory Atom) where
174+
class IsClassical (T : Theory Atom) where
124175
dne (A : Proposition Atom) : (¬¬A → A) ∈ T
125176

126177
omit [DecidableEq Atom] in
127178
@[scoped grind =]
128-
theorem isClassicalIff [Bot Atom] (T : Theory Atom) : IsClassical T ↔ CPL ⊆ T := by grind
179+
theorem isClassicalIff (T : Theory Atom) : IsClassical T ↔ CPL ⊆ T := by grind
129180

130-
instance instIsIntuitionisticIPL [Bot Atom] : IsIntuitionistic (Atom := Atom) IPL where
181+
instance instIsIntuitionisticIPL : IsIntuitionistic (Atom := Atom) IPL where
131182
efq A := Set.mem_range.mpr ⟨A, rfl⟩
132183

133-
instance instIsClassicalCPL [Bot Atom] : IsClassical (Atom := Atom) CPL where
184+
instance instIsClassicalCPL : IsClassical (Atom := Atom) CPL where
134185
dne A := Set.mem_range.mpr ⟨A, rfl⟩
135186

136187
omit [DecidableEq Atom] in
137188
@[scoped grind →]
138-
theorem instIsIntuitionisticExtention [Bot Atom] {T T' : Theory Atom} [IsIntuitionistic T]
189+
theorem instIsIntuitionisticExtention {T T' : Theory Atom} [IsIntuitionistic T]
139190
(h : T ⊆ T') : IsIntuitionistic T' := by grind
140191

141192
omit [DecidableEq Atom] in
142193
@[scoped grind →]
143-
theorem instIsClassicalExtention [Bot Atom] {T T' : Theory Atom} [IsClassical T] (h : T ⊆ T') :
194+
theorem instIsClassicalExtention {T T' : Theory Atom} [IsClassical T] (h : T ⊆ T') :
144195
IsClassical T' := by grind
145196

146197
/-- Attach a bottom element to a theory `T`, and the principle of explosion for that bottom. -/

0 commit comments

Comments
 (0)