Skip to content

Commit b041ae7

Browse files
committed
feat(Logics/Propositional): five-primitive formula type with connective typeclasses
1 parent 87c249d commit b041ae7

4 files changed

Lines changed: 228 additions & 105 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: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
/-
2-
Copyright (c) 2025 Thomas Waring. All rights reserved.
2+
Copyright (c) 2025 Thomas Waring, 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 Cslib.Foundations.Logic.Connectives
1011
public import Mathlib.Data.FunLike.Basic
11-
public import Mathlib.Data.Set.Image
12+
public import Mathlib.Data.Set.Basic
1213
public import Mathlib.Order.TypeTags
1314

1415
/-! # Propositions and theories
1516
1617
## Main definitions
1718
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.
19+
- `Proposition` : the type of propositions over a given type of atom. Primitives are `atom`,
20+
`bot` (falsum), `imp` (implication), `and` (conjunction), and `or` (disjunction). Negation
21+
(`neg`), verum (`top`), and biconditional (`iff`) are derived connectives (`abbrev`s). This
22+
follows natural deduction style ([Gentzen1935], [Prawitz1965], Ch. I sec. 1.2) and the
23+
constructive mathematics tradition ([Johansson1937], [TroelstraVanDalen1988]) in which `neg A`
24+
abbreviates `A → ⊥` rather than being taken as primitive.
2025
- `Theory` : set of `Proposition`.
2126
- `IsIntuitionistic` : a theory is intuitionistic if it contains the principle of explosion.
2227
- `IsClassical` : an intuitionistic theory is classical if it further contains double negation
23-
elimination.
28+
elimination.
2429
- `Proposition.subst` : replace `atom x` in a `A : Proposition Atom` with `f x`, for a function
2530
`f : Atom → Proposition Atom'`. This induces a monad structure on `Proposition`, with
2631
`pure := Proposition.atom`. `Theory` is a functor, by mapping each proposition `A ∈ T` to
2732
`f <$> A`.
2833
- `Theory.intuitionisticCompletion` : the freely generated intuitionistic theory extending a given
29-
theory.
34+
theory.
3035
3136
## Notation
3237
3338
We introduce notation for the logical connectives: `⊥ ⊤ ∧ ∨ → ¬` for, respectively, falsum, verum,
3439
conjunction, disjunction, implication and negation.
40+
41+
## References
42+
43+
* [I. Johansson, *Der Minimalkalkül, ein reduzierter intuitionistischer Formalismus*][Johansson1937]
44+
* [G. Gentzen, *Untersuchungen über das logische Schließen*][Gentzen1935]
45+
* [D. Prawitz, *Natural Deduction: A Proof-Theoretical Study*][Prawitz1965]
46+
* [A. S. Troelstra, D. van Dalen,
47+
*Constructivism in Mathematics: An Introduction*][TroelstraVanDalen1988]
48+
* [A. Church, *Introduction to Mathematical Logic*][Church1956]
3549
-/
3650

3751
@[expose] public section
@@ -42,44 +56,61 @@ variable {Atom : Type u} [DecidableEq Atom]
4256

4357
namespace Cslib.Logic.PL
4458

45-
/-- Propositions. -/
59+
/-- Propositions. Primitives are atoms, falsum, implication, conjunction, and disjunction. -/
4660
inductive Proposition (Atom : Type u) : Type u where
4761
/-- Propositional atoms -/
4862
| atom (x : Atom)
63+
/-- Falsum / bottom -/
64+
| bot
65+
/-- Implication -/
66+
| imp (a b : Proposition Atom)
4967
/-- Conjunction -/
5068
| and (a b : Proposition Atom)
5169
/-- Disjunction -/
5270
| or (a b : Proposition Atom)
53-
/-- Implication -/
54-
| impl (a b : Proposition Atom)
5571
deriving DecidableEq, BEq
5672

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

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

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)
79+
/-- Biconditional as a derived connective: A ↔ B := (A → B) ∧ (B → A) -/
80+
abbrev Proposition.iff (A B : Proposition Atom) : Proposition Atom :=
81+
(A.imp B).and (B.imp A)
6582

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

7086
@[inherit_doc] scoped infix:36 " ∧ " => Proposition.and
7187
@[inherit_doc] scoped infix:35 " ∨ " => Proposition.or
72-
@[inherit_doc] scoped infix:30 " → " => Proposition.impl
88+
@[inherit_doc] scoped infix:30 " → " => Proposition.imp
89+
@[inherit_doc] scoped infix:20 " ↔ " => Proposition.iff
7390
@[inherit_doc] scoped prefix:40 " ¬ " => Proposition.neg
7491

92+
/-- Register `Proposition` as an instance of `PropositionalConnectives`. -/
93+
instance : PropositionalConnectives (Proposition Atom) where
94+
bot := .bot
95+
imp := .imp
96+
97+
/-- Register `HasAnd` instance for `Proposition`. -/
98+
instance : HasAnd (Proposition Atom) where
99+
and := .and
100+
101+
/-- Register `HasOr` instance for `Proposition`. -/
102+
instance : HasOr (Proposition Atom) where
103+
or := .or
104+
75105
/-- Substitute each atom in a proposition for a proposition, possibly changing the atomic
76106
language. -/
77107
def Proposition.subst {Atom Atom' : Type u} (f : Atom → Proposition Atom') :
78108
Proposition Atom → Proposition Atom'
79109
| 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)
110+
| bot => .bot
111+
| imp A B => .imp (A.subst f) (B.subst f)
112+
| and A B => .and (A.subst f) (B.subst f)
113+
| or A B => .or (A.subst f) (B.subst f)
83114

84115
-- This is probably a lawful monad, but that doesn't seem to be important.
85116
instance : Monad Proposition where
@@ -102,45 +133,45 @@ instance : Functor Theory where
102133
abbrev MPL : Theory (Atom) := ∅
103134

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

108139
/-- Classical logic further adds double negation elimination. -/
109-
abbrev CPL [Bot Atom] : Theory Atom :=
140+
abbrev CPL : Theory Atom :=
110141
Set.range (fun (A : Proposition Atom) ↦ ¬¬A → A)
111142

112143
/-- A theory is intuitionistic if it validates ex falso quodlibet. -/
113144
@[scoped grind]
114-
class IsIntuitionistic [Bot Atom] (T : Theory Atom) where
145+
class IsIntuitionistic (T : Theory Atom) where
115146
efq (A : Proposition Atom) : (⊥ → A) ∈ T
116147

117148
omit [DecidableEq Atom] in
118149
@[scoped grind =]
119-
theorem isIntuitionisticIff [Bot Atom] (T : Theory Atom) : IsIntuitionistic T ↔ IPL ⊆ T := by grind
150+
theorem isIntuitionisticIff (T : Theory Atom) : IsIntuitionistic T ↔ IPL ⊆ T := by grind
120151

121152
/-- A theory is classical if it validates double-negation elimination. -/
122153
@[scoped grind]
123-
class IsClassical [Bot Atom] (T : Theory Atom) where
154+
class IsClassical (T : Theory Atom) where
124155
dne (A : Proposition Atom) : (¬¬A → A) ∈ T
125156

126157
omit [DecidableEq Atom] in
127158
@[scoped grind =]
128-
theorem isClassicalIff [Bot Atom] (T : Theory Atom) : IsClassical T ↔ CPL ⊆ T := by grind
159+
theorem isClassicalIff (T : Theory Atom) : IsClassical T ↔ CPL ⊆ T := by grind
129160

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

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

136167
omit [DecidableEq Atom] in
137168
@[scoped grind →]
138-
theorem instIsIntuitionisticExtention [Bot Atom] {T T' : Theory Atom} [IsIntuitionistic T]
169+
theorem instIsIntuitionisticExtention {T T' : Theory Atom} [IsIntuitionistic T]
139170
(h : T ⊆ T') : IsIntuitionistic T' := by grind
140171

141172
omit [DecidableEq Atom] in
142173
@[scoped grind →]
143-
theorem instIsClassicalExtention [Bot Atom] {T T' : Theory Atom} [IsClassical T] (h : T ⊆ T') :
174+
theorem instIsClassicalExtention {T T' : Theory Atom} [IsClassical T] (h : T ⊆ T') :
144175
IsClassical T' := by grind
145176

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

0 commit comments

Comments
 (0)