Skip to content

Commit f46056b

Browse files
benbrastmckieclaude
andcommitted
feat(Logics/Modal): refactor formula primitives to {atom, bot, imp, box}
Refactors `Cslib/Logics/Modal/Basic.lean` to use four classical primitives `{atom, bot, imp, box}` instead of `{atom, not, and, diamond}`. Negation, conjunction, disjunction, and diamond become derived connectives via the Lukasiewicz encoding. Adds `HasBox` class and `ModalConnectives` bundle in `Connectives.lean`, stacking on propositional five-primitive formula type with primitive bot. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e0573fb commit f46056b

10 files changed

Lines changed: 672 additions & 372 deletions

File tree

Cslib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public import Cslib.Foundations.Data.RelatesInSteps
7171
public import Cslib.Foundations.Data.Set.Saturation
7272
public import Cslib.Foundations.Data.StackTape
7373
public import Cslib.Foundations.Lint.Basic
74+
public import Cslib.Foundations.Logic.Connectives
7475
public import Cslib.Foundations.Logic.InferenceSystem
7576
public import Cslib.Foundations.Logic.LogicalEquivalence
7677
public import Cslib.Foundations.Relation.Attr
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 Composable Logics
12+
13+
This module defines a typeclass hierarchy for logical connectives, shared across propositional
14+
and modal logic levels. Each formula type registers itself as an instance of the appropriate
15+
connective class, enabling polymorphic axiom definitions and notation.
16+
17+
## Design
18+
19+
The hierarchy adopts a hybrid design,
20+
following the operator-typeclass direction of fmontesi's PR #607 (one class per operator):
21+
- **Atomic classes**: `HasBot`, `HasImp`, `HasAnd`, `HasOr`, `HasBox`
22+
- **Bundled classes**: `PropositionalConnectives`, `ModalConnectives`
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 necessity/box modality.
55+
56+
Box represents universal quantification over accessible worlds (`∀ w', r w w' → φ`),
57+
distributes over implication (axiom K), and is the subject of the necessitation rule.
58+
In classical systems,
59+
diamond (possibility) is derived as `¬□¬φ`. Non-classical modal logics (intuitionistic,
60+
minimal) require a separate `HasDia` typeclass, since `□` and `◇` become independent
61+
operators in those settings. -/
62+
class HasBox (F : Type*) where
63+
/-- The necessity/box modality. -/
64+
box : F → F
65+
66+
/-- A type has a conjunction connective. -/
67+
class HasAnd (F : Type*) where
68+
/-- The conjunction connective. -/
69+
and : F → F → F
70+
71+
/-- A type has a disjunction connective. -/
72+
class HasOr (F : Type*) where
73+
/-- The disjunction connective. -/
74+
or : F → F → F
75+
76+
/-- Propositional connectives: falsum and implication.
77+
78+
`HasAnd` and `HasOr` are defined as standalone atomic classes in this module.
79+
When all four connectives are needed, use
80+
`[PropositionalConnectives F] [HasAnd F] [HasOr F]`. -/
81+
class PropositionalConnectives (F : Type*) extends HasBot F, HasImp F
82+
83+
/-- Modal connectives: propositional connectives plus box (necessity).
84+
85+
Diamond (possibility) is derivable from box and propositional connectives via
86+
classical negation (`◇φ := ¬□¬φ`) and need not appear in the typeclass. Non-classical modal
87+
logics (intuitionistic, minimal) require extending this class with a primitive `HasDia` once
88+
those formula types are formalized. -/
89+
class ModalConnectives (F : Type*) extends PropositionalConnectives F, HasBox F
90+
91+
end Cslib.Logic

0 commit comments

Comments
 (0)