Skip to content

feat(ModalLogic+Congruence): modal reasoning for Lean - #799

Merged
fmontesi merged 42 commits into
mainfrom
fmontesi/modal-lean
Aug 20, 2026
Merged

fmontesi merged 42 commits into
mainfrom
fmontesi/modal-lean

Conversation

@fmontesi

@fmontesi fmontesi commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

This PR develops a concept of modal reasoning for Lean theorems, powered by the laws of modal logic. This development led to some polishing for Congruence and some definitions for Relation.

Specifically, the PR:

  • Introduces the first development where CSLib's modal logic is instantiated with Lean's Prop as the type of atomic propositions. We use this to construct models out of Lean predicates and containers and show some general properties in terms of logical equivalence.
  • Introduces a construction that, given any scalar multiplication operator, builds an accessibility relation. If the operator is an action of some kind (as defined in mathlib), this accessibility relation has interesting properties (like transitivity or diamond) that are relevant for modal reasoning.
  • Develops an example of how this framework can be used to prove mathematical theorems. In particular, we apply the new construction to obtain an accessibility relation on Ideals. In this interpretation, membership of radicals of ideals is characterised by the diamond connective in modal logic. This allows for applying modal logic to proving properties about radicals.
  • As examples, we show that Ideal.radical_inf and Ideal.radical_idem from mathlib can be proven by applying modal logical equivalence.

This put the ergonomics and expressive power of our infrastructure for modal logic, logical equivalence, relations, and congruence to the test. This PR also:

  • Polishes a bit the ergonomics of LawfulCongruence (e.g., by making Congruence.r an abbrev so that typeclass resolution works in proofs).
  • Adds a Preserves property for relations.
  • Defines and proves soundness and completeness of modal axioms for relations with the diamond property.
  • Refactors a bit LogicalEquivalence for modal logic so that it is more fundamental (based on a single model instead of a set of models, and then derives the latter on the first).

The last point not only helps with proofs, but also aligns logical equivalence with how it is handled in HML. This means that we can start working on a shared abstraction for this kind of logics, which would then derive the natural notion of logical equivalence for free.

Depends on #788

@thomaskwaring thomaskwaring left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preliminary review here, but overall i like this

one question (which i was thinking about as relates to the earlier axiom L PR) is whether we can state IsAxiom as an inference system, where the judgement is r ⊨ φ for "this the proposition is valid at every world for every valuation" — logically it is the same but it avoids introducing a new definition and might down-the-track mesh better with our infrastructure. what do you think?

Comment thread Cslib/Logics/Modal/Lean/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Lean/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Denotation.lean Resolved
fmontesi and others added 7 commits August 14, 2026 18:07
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
@fmontesi

fmontesi commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

preliminary review here, but overall i like this

one question (which i was thinking about as relates to the earlier axiom L PR) is whether we can state IsAxiom as an inference system, where the judgement is r ⊨ φ for "this the proposition is valid at every world for every valuation" — logically it is the same but it avoids introducing a new definition and might down-the-track mesh better with our infrastructure. what do you think?

Like this?


/-- Every accessibility relation induces an inference system tag for proving valid axioms under
the relation. -/
inductive Axiom (r : World → World → Prop)

/-- A proposition `φ` is an axiom under the relation `r` (the 'frame') if it holds for all
valuations and worlds. -/
instance (r : World → World → Prop) : InferenceSystem (Axiom r) (Proposition Atom) where
  derivation φ := ∀ v w, ⇓Modal[⟨r,v⟩,w ⊨ φ]

I think it's a good idea, might even go in the class for modal-like logics later on. I've tried it and the proofs don't work out of the box though, there's some plumbing that becomes necessary compared to the current abbrev, so it'll take some (unclear amount of) work.

EDIT: I've figured it out. :) Now in the PR, let me know what you think.

@thomaskwaring thomaskwaring left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like the new Axiom design i think! this review is mostly some further golfing / simplifying of proofs, plus a few natural extensions to Modal.Lean.SMul

Comment thread Cslib/Logics/Modal/Lean/SMul.lean Resolved
Comment thread Cslib/Logics/Modal/Lean/SMul.lean Resolved
Comment thread Cslib/Logics/Modal/Lean/SMul.lean Resolved
Comment thread Cslib/Logics/Modal/Lean/SMul.lean Resolved
Comment thread Cslib/Logics/Modal/Lean/SMul.lean Resolved
Comment thread CslibTests/Modal/Ideal.lean Resolved
Comment thread Cslib/Logics/Modal/Basic.lean Resolved
fmontesi and others added 12 commits August 17, 2026 08:18
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
fmontesi and others added 3 commits August 18, 2026 12:20
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
@fmontesi

Copy link
Copy Markdown
Collaborator Author

All caught up @thomaskwaring. :)

@thomaskwaring thomaskwaring left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for looking at those grind annotations, to my understanding it's working how we'd hope now (not unfolding definitions, etc).

i'm happy with this now, i'd appreciate one more pair of eyes on it to be sure, but i'll approve in the meantime. also, am i right in assuming this supercedes #788 ?

Comment thread Cslib/Logics/Modal/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Lean/Basic.lean Resolved
Comment thread CslibTests/Modal/Ideal.lean Resolved
Comment thread CslibTests/Modal/Ideal.lean Resolved
Comment thread Cslib/Logics/Modal/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Cube.lean Resolved
Comment thread Cslib/Logics/Modal/Denotation.lean Resolved
Comment thread Cslib/Logics/Modal/Lean/Basic.lean Resolved
Comment thread Cslib/Logics/Modal/Lean/SMul.lean Resolved
@fmontesi

Copy link
Copy Markdown
Collaborator Author

i'm happy with this now, i'd appreciate one more pair of eyes on it to be sure, but i'll approve in the meantime. also, am i right in assuming this supercedes #788 ?

Yes, it does! I'll close the other one.

fmontesi and others added 11 commits August 19, 2026 18:39
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>
Co-authored-by: Thomas Krishna Waring <51426330+thomaskwaring@users.noreply.github.com>

@chenson2018 chenson2018 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed very lightly. I'm suspicious of how much abbrev appears, but otherwise I trust Thomas's judgement.

@thomaskwaring

Copy link
Copy Markdown
Collaborator

@chenson2018 glad to hear it :)

i can't comment much on abbrev -- i don't properly understand the pros and cons -- we can experiment with changing to defs if you think it could become a problem, otherwise let's go ahead.

@chenson2018

Copy link
Copy Markdown
Collaborator

Let's leave it as is for now, I think this can be refactored later.

@fmontesi
fmontesi added this pull request to the merge queue Aug 20, 2026
Merged via the queue into main with commit 764c0af Aug 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants