Skip to content

Commit 7cc0961

Browse files
benbrastmckieclaude
andcommitted
feat(Logics/Propositional): five-primitive formula type with primitive bot
Add `bot` as a primitive constructor of `Proposition Atom`, eliminating all `[Bot Atom]` constraints from propositional logic signatures. - New `Connectives.lean`: typeclass hierarchy (HasBot, HasImp, HasAnd, HasOr) - `Defs.lean`: five-primitive Proposition type with derived neg, top, iff - `Basic.lean`: natural deduction with impI/impE, andI/andE1/andE2, orI1/orI2 - `Theory.lean`: remove [Bot Atom], add instIsIntuitionisticIntuitionisticCompletion - Replace German-language references with Avigad 2022, Prawitz 1965 - Semantics files deferred to follow-up PR per reviewer request Reconciles with merged PR #536 (InferenceSystem-parameterized typeclasses). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 70c5bf5 commit 7cc0961

6 files changed

Lines changed: 280 additions & 145 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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
([Avigad2022]); 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+
* [J. Avigad, *Mathematical Logic and Computation*][Avigad2022]
38+
-/
39+
40+
@[expose] public section
41+
42+
namespace Cslib.Logic
43+
44+
/-- A type has a falsum (bottom) connective. -/
45+
class HasBot (F : Type*) where
46+
/-- The falsum/bottom connective. -/
47+
bot : F
48+
49+
/-- A type has an implication connective. -/
50+
class HasImp (F : Type*) where
51+
/-- The implication connective. -/
52+
imp : F → F → F
53+
54+
/-- A type has a conjunction connective. -/
55+
class HasAnd (F : Type*) where
56+
/-- The conjunction connective. -/
57+
and : F → F → F
58+
59+
/-- A type has a disjunction connective. -/
60+
class HasOr (F : Type*) where
61+
/-- The disjunction connective. -/
62+
or : F → F → F
63+
64+
/-- Propositional connectives: falsum and implication.
65+
66+
`HasAnd` and `HasOr` are defined as standalone atomic classes in this module.
67+
When all four connectives are needed, use
68+
`[PropositionalConnectives F] [HasAnd F] [HasOr F]`. -/
69+
class PropositionalConnectives (F : Type*) extends HasBot F, HasImp F
70+
71+
end Cslib.Logic

Cslib/Logics/Propositional/Defs.lean

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
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+
import Cslib.Init
10+
public import Cslib.Foundations.Logic.Connectives
911
public import Cslib.Foundations.Logic.InferenceSystem
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 the natural deduction tradition ([Avigad2022]) in which `neg A` abbreviates `A → ⊥`
24+
rather than being taken as primitive.
2025
- `Theory` : set of `Proposition`.
21-
- `IsIntuitionistic` : a theory is intuitionistic if it contains the principle of explosion.
22-
- `IsClassical` : an intuitionistic theory is classical if it further contains double negation
23-
elimination.
26+
- `IsIntuitionistic` : an inference system is intuitionistic if it derives the principle of
27+
explosion.
28+
- `IsClassical` : an inference system is classical if it further derives double negation
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.
3036
3137
## Notation
3238
3339
We introduce notation for the logical connectives: `⊥ ⊤ ∧ ∨ → ¬` for, respectively, falsum, verum,
3440
conjunction, disjunction, implication and negation.
41+
42+
## References
43+
44+
* [J. Avigad, *Mathematical Logic and Computation*][Avigad2022]
3545
-/
3646

3747
@[expose] public section
@@ -42,44 +52,61 @@ variable {Atom : Type u} [DecidableEq Atom]
4252

4353
namespace Cslib.Logic.PL
4454

45-
/-- Propositions. -/
55+
/-- Propositions. Primitives are atoms, falsum, implication, conjunction, and disjunction. -/
4656
inductive Proposition (Atom : Type u) : Type u where
4757
/-- Propositional atoms -/
4858
| atom (x : Atom)
59+
/-- Falsum / bottom -/
60+
| bot
61+
/-- Implication -/
62+
| imp (a b : Proposition Atom)
4963
/-- Conjunction -/
5064
| and (a b : Proposition Atom)
5165
/-- Disjunction -/
5266
| or (a b : Proposition Atom)
53-
/-- Implication -/
54-
| impl (a b : Proposition Atom)
5567
deriving DecidableEq, BEq
5668

57-
instance instBotProposition [Bot Atom] : Bot (Proposition Atom) := ⟨.atom ⊥⟩
58-
instance instInhabitedOfBot [Bot Atom] : Inhabited Atom := ⟨⊥⟩
69+
/-- Negation as a derived connective: ¬A := A → ⊥ -/
70+
abbrev Proposition.neg : Proposition Atom → Proposition Atom := (Proposition.imp · .bot)
5971

60-
/-- We view negation as a defined connective ~A := A → ⊥ -/
61-
abbrev Proposition.neg [Bot Atom] : Proposition Atom → Proposition Atom := (Proposition.impl · ⊥)
72+
/-- Verum / top as a derived connective: ⊤ := → ⊥ -/
73+
abbrev Proposition.top : Proposition Atom := .imp .bot .bot
6274

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)
75+
/-- Biconditional as a derived connective: A ↔ B := (A → B) ∧ (B → A) -/
76+
abbrev Proposition.iff (A B : Proposition Atom) : Proposition Atom :=
77+
(A.imp B).and (B.imp A)
6578

66-
instance instTopProposition [Inhabited Atom] : Top (Proposition Atom) := ⟨.top⟩
67-
68-
example [Bot Atom] : (⊤ : Proposition Atom) = Proposition.impl ⊥ ⊥ := rfl
79+
instance : Bot (Proposition Atom) := ⟨.bot⟩
80+
instance : Top (Proposition Atom) := ⟨.top⟩
6981

7082
@[inherit_doc] scoped infix:36 " ∧ " => Proposition.and
7183
@[inherit_doc] scoped infix:35 " ∨ " => Proposition.or
72-
@[inherit_doc] scoped infix:30 " → " => Proposition.impl
84+
@[inherit_doc] scoped infix:30 " → " => Proposition.imp
85+
@[inherit_doc] scoped infix:20 " ↔ " => Proposition.iff
7386
@[inherit_doc] scoped prefix:40 " ¬ " => Proposition.neg
7487

88+
/-- Register `Proposition` as an instance of `PropositionalConnectives`. -/
89+
instance : PropositionalConnectives (Proposition Atom) where
90+
bot := .bot
91+
imp := .imp
92+
93+
/-- Register `HasAnd` instance for `Proposition`. -/
94+
instance : HasAnd (Proposition Atom) where
95+
and := .and
96+
97+
/-- Register `HasOr` instance for `Proposition`. -/
98+
instance : HasOr (Proposition Atom) where
99+
or := .or
100+
75101
/-- Substitute each atom in a proposition for a proposition, possibly changing the atomic
76102
language. -/
77103
def Proposition.subst {Atom Atom' : Type u} (f : Atom → Proposition Atom') :
78104
Proposition Atom → Proposition Atom'
79105
| 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)
106+
| bot => .bot
107+
| imp A B => .imp (A.subst f) (B.subst f)
108+
| and A B => .and (A.subst f) (B.subst f)
109+
| or A B => .or (A.subst f) (B.subst f)
83110

84111
-- This is probably a lawful monad, but that doesn't seem to be important.
85112
instance : Monad Proposition where
@@ -99,41 +126,43 @@ instance : Functor Theory where
99126
map f := Set.image (f <$> ·)
100127

101128
/-- The empty theory corresponds to minimal propositional logic. -/
102-
abbrev MPL (Atom : Type u) : Theory (Atom) := ∅
129+
abbrev MPL : Theory (Atom) := ∅
103130

104131
/-- Intuitionistic propositional logic adds the principle of explosion (ex falso quodlibet). -/
105-
abbrev IPL (Atom : Type u) [Bot Atom] : Theory Atom := {⊥ → A | A : Proposition Atom}
132+
abbrev IPL : Theory Atom :=
133+
Set.range (Proposition.imp ⊥ ·)
106134

107135
omit [DecidableEq Atom] in
108-
lemma efq_mem_ipl [Bot Atom] (A : Proposition Atom) : (⊥ → A) ∈ IPL Atom := ⟨A, rfl⟩
109-
110-
/-- Attach a bottom element to a theory `T`, and the principle of explosion for that bottom. -/
111-
@[reducible]
112-
def intuitionisticCompletion (T : Theory Atom) : Theory (WithBot Atom) :=
113-
(WithBot.some <$> T) ∪ IPL (WithBot Atom)
136+
lemma efq_mem_ipl (A : Proposition Atom) : (⊥ → A) ∈ IPL (Atom := Atom) := ⟨A, rfl⟩
114137

115138
/-- Classical logic further adds double negation elimination. -/
116-
abbrev CPL (Atom : Type u) [Bot Atom] : Theory Atom := {¬¬A → A | A : Proposition Atom}
139+
abbrev CPL : Theory Atom :=
140+
Set.range (fun (A : Proposition Atom) ↦ ¬¬A → A)
117141

118142
omit [DecidableEq Atom] in
119-
lemma dne_mem_cpl [Bot Atom] (A : Proposition Atom) : (¬¬A → A) ∈ CPL Atom := ⟨A, rfl⟩
143+
lemma dne_mem_cpl (A : Proposition Atom) : (¬¬A → A) ∈ CPL (Atom := Atom) := ⟨A, rfl⟩
144+
145+
/-- Attach a bottom element to a theory `T`, and the principle of explosion for that bottom. -/
146+
@[reducible]
147+
def intuitionisticCompletion (T : Theory Atom) : Theory (WithBot Atom) :=
148+
(WithBot.some <$> T) ∪ IPL
120149

121150
open InferenceSystem
122151

123152
/-- An inference system is intuitionistic if it derives ex falso quodlibet. TODO: this should be
124153
generalised outside the `PL` scope, once we have typeclasses to express that a type possesses an
125154
implication connective. -/
126155
@[scoped grind]
127-
class IsIntuitionistic (Atom : Type u) [Bot Atom] (S : Type*)
156+
class IsIntuitionistic (Atom : Type u) (S : Type*)
128157
[InferenceSystem S (Proposition Atom)] where
129-
/-- The principle of explosion (ex falso quolibet). -/
158+
/-- The principle of explosion (ex falso quodlibet). -/
130159
efq (A : Proposition Atom) : S⇓(⊥ → A)
131160

132161
/-- An inference system is classical if it validates double-negation elimination. TODO: this should
133162
be generalised outside the `PL` scope, once we have typeclasses to express that a type possesses an
134163
implication connective. -/
135164
@[scoped grind]
136-
class IsClassical (Atom : Type u) [Bot Atom] (S : Type*)
165+
class IsClassical (Atom : Type u) (S : Type*)
137166
[InferenceSystem S (Proposition Atom)] where
138167
/-- Double-negation elimination. -/
139168
dne (A : Proposition Atom) : S⇓(¬¬A → A)

0 commit comments

Comments
 (0)