Skip to content

refactor(Vorspiel): rename clashing Matrix.map/forall_iff/exists_iff to vec* (Mathlib co-import)#835

Merged
SnO2WMaN merged 4 commits into
FormalizedFormalLogic:masterfrom
A-M-Berns:fix/vecMap-mathlib-clash
Jul 18, 2026
Merged

refactor(Vorspiel): rename clashing Matrix.map/forall_iff/exists_iff to vec* (Mathlib co-import)#835
SnO2WMaN merged 4 commits into
FormalizedFormalLogic:masterfrom
A-M-Berns:fix/vecMap-mathlib-clash

Conversation

@A-M-Berns

@A-M-Berns A-M-Berns commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This PR was prepared with the help of Claude Fable 5 to fix a naming clash between Mathlib and FFL that I encountered when working on my Formalized Agent Foundations project that uses both as a dependency. This rename would be useful for any project that requires both Mathlib and FFL to reduce naming conflicts.

--

What

Renames the three Foundation.Vorspiel.Matrix declarations that shadow existing Mathlib Matrix.* names, so Foundation can be imported alongside Mathlib's matrix/analysis theory:

Foundation decl collides with (Mathlib) renamed to
Matrix.map (a vector map (Fin k → α) → (Fin k → β)) Matrix.map (…Matrix.InvariantBasisNumber materializes Matrix.map.eq_1) Matrix.vecMap
Matrix.forall_iff Matrix.forall_iff (Mathlib.Data.Matrix.Reflection) Matrix.vecForall_iff
Matrix.exists_iff Matrix.exists_iff (Mathlib.Data.Matrix.Reflection) Matrix.vecExists_iff

The notation and all lemmas keep their behavior; the 12 call sites of forall_iff/exists_iff in BinderNotation.lean and Semantics.lean are updated.

Why

Each of these lives in the Matrix namespace and shares a name with a distinct Mathlib Matrix declaration. Importing Foundation together with the relevant Mathlib module fails at import time, e.g.:

import Foundation.Vorspiel.Matrix failed, environment already contains
'Matrix.map.eq_1' from Mathlib.LinearAlgebra.Matrix.InvariantBasisNumber
import ... failed, environment already contains 'Matrix.forall_iff'
from Mathlib.Data.Matrix.Reflection

Because Vorspiel.Matrix sits in Foundation's prelude, every Foundation module inherits the clash. It surfaces when co-importing Foundation with matrix-heavy Mathlib analysis — Mathlib.MeasureTheory.Integral.Bochner, and anything pulling EuclideanSpace/InnerProductSpace.PiL2 (which transitively imports Matrix.Reflection).

Scope / safety

  • These three are the complete set of Foundation-vs-Mathlib Matrix-namespace name collisions: I intersected every Matrix.* decl in Vorspiel/Matrix.lean against Mathlib and confirmed the rest (vecConsLast, toList, foldr, foldl, appendr, …) have no Mathlib Matrix counterpart.
  • Downstream, a project that co-imports Foundation with Bochner integration and with a from-scratch Brouwer development (over EuclideanSpace ℝ (Fin d)) now builds green with these renames; before them the roll-up module hit exactly the two clashes above in sequence.
  • I have not run lake build Foundation against master's current toolchain locally; these are pure renames of leaf decls with all call sites updated, so they should be toolchain-agnostic — happy to let CI confirm.

Note on lemma names

I kept the map_* lemma family (map_cons, map_app, map_map_comp', …) and the section map unchanged, to keep the diff to what's needed to clear the clash. Glad to rename those to vecMap_* for consistency with the foldr_*/foldl_* convention if you'd prefer.

A-M-Berns added 2 commits July 3, 2026 14:59
…ib clash

Foundation.Vorspiel.Matrix defined its own Matrix.map, a vector map
(Fin k → α) → (Fin k → β), shadowing Mathlib's Matrix.map. Both auto-generate
Matrix.map.eq_1, so importing Foundation alongside any Mathlib module that
materializes Mathlib's Matrix.map.eq_1 (e.g. Bochner integration, matrix-heavy
analysis) fails with an 'environment already contains Matrix.map.eq_1' clash.
Because Vorspiel.Matrix sits in Foundation's prelude, this blocks co-importing
Foundation with large parts of Mathlib.

Rename the def to vecMap. The postfix notation ⨟ and all lemmas are unchanged in
behavior; no qualified Matrix.map (vector) references exist elsewhere in the tree.
… Mathlib clash

Same clash as Matrix.map -> vecMap in this PR: Vorspiel.Matrix's forall_iff and
exists_iff collide by name with Mathlib.Data.Matrix.Reflection's Matrix.forall_iff
/ Matrix.exists_iff, blocking co-import of Foundation with that module (pulled in
transitively via EuclideanSpace / InnerProductSpace.PiL2). Rename to vecForall_iff
/ vecExists_iff and update the 12 call sites in BinderNotation and Semantics.
@A-M-Berns A-M-Berns changed the title refactor(Vorspiel): rename Matrix.map to Matrix.vecMap to avoid Mathlib clash refactor(Vorspiel): rename clashing Matrix.map/forall_iff/exists_iff to vec* (Mathlib co-import) Jul 3, 2026
@SnO2WMaN

SnO2WMaN commented Jul 3, 2026

Copy link
Copy Markdown
Member

Thanks for the PR!
Regarding this issue, I personally think that the naming in Mathlib is problematic to begin with.
I asked about it on Zulip but haven't respond yet: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Namespace.20confict.20of.20.60Matrix.60

@SnO2WMaN SnO2WMaN left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the lemmas involving Matrix.vecMap, I think renaming them to vecMap_* would be fine. The same goes for the other definitions.

…ency

Co-Authored-By: Claude <noreply@anthropic.com>
@SnO2WMaN

Copy link
Copy Markdown
Member

Verified: a scratch module importing Mathlib.MeasureTheory.Integral.Bochner.Basic, Mathlib.Analysis.InnerProductSpace.PiL2, and Foundation.Vorspiel.Matrix together builds cleanly with no name clashes (lake build succeeded, 2494/2494 jobs). This confirms the vecMap/vecForall_iff/vecExists_iff renames resolve the collisions this PR targets.

@SnO2WMaN
SnO2WMaN enabled auto-merge (squash) July 18, 2026 02:56
@SnO2WMaN

Copy link
Copy Markdown
Member

@A-M-Berns P.S.: I took a look at https://github.com/A-M-Berns/Formalized-Agent-Foundations and it looks like you're using something around the fixed-point theorem for modal logic GL.
Since we're planning to remove modal logic from Foundation, I think https://github.com/FormalizedFormalLogic/ProvabilityLogic would be useful for your purposes.
That's where we're putting the fixpoint theorem and related material.

@SnO2WMaN
SnO2WMaN merged commit b47cf44 into FormalizedFormalLogic:master Jul 18, 2026
4 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.

2 participants