Skip to content

feat(Tactic): upstream @[mk_iff] from mathlib#1854

Open
YaelDillies wants to merge 9 commits into
leanprover-community:mainfrom
YaelDillies:mk_iff
Open

feat(Tactic): upstream @[mk_iff] from mathlib#1854
YaelDillies wants to merge 9 commits into
leanprover-community:mainfrom
YaelDillies:mk_iff

Conversation

@YaelDillies

Copy link
Copy Markdown
Contributor

Motivated by #1853.

@github-actions github-actions Bot added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Jun 15, 2026
@wrenna-robson

Copy link
Copy Markdown
Contributor

I would be happy (and it might be desirable) to add e.g. its usage for IsChain in practice (and other inductive props - your examples seem good).

Move `MVarId.existsi` from `Batteries.Lean.Meta.Basic` (its only user is
`MkIff`) into `Batteries/Tactic/MkIff.lean`, so the foundational `Meta.Basic`
no longer publicly imports the elaborator/tactic framework. Restore its
original imports.

Update the `mk_iff` docstrings from the non-existent `List.Chain` to the real
`List.IsChain` output, and switch the `Shape` example to `ReflTransGen` (which
actually exhibits variable elimination). Drop the dead `open` in `Lean.Name`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mathlib-nightly-testing

Copy link
Copy Markdown
Contributor

Mathlib CI status (docs):

- Replace hand-rolled `List.init`, `mkAndList`/`mkOrList`/`mkOpList`, and the
  `refine`/`evalTactic`-based `existsi`/`splitThenConstructor` with core
  `List.dropLast`, `mkAndN`, `MVarId.existsIntro`, and `MVarId.constructor`,
  dropping the now-dead `Lean.Elab.Tactic.Basic` import.
- Add `Lean.mkOrN` (mirroring core `mkAndN`) and `Lean.Meta.mkExistsFVars`
  (the existential analogue of `mkForallFVars`) as the only exported helpers.
- Use resolved (``) constant names throughout for compile-time checking.
- Invert section visibility: default-private `meta section` with `public`
  only on the two helpers and the `mk_iff` syntax/attribute surface, instead
  of `public meta section` plus eleven `private` markers.
- camelCase locals, drop the stale universe-names TODO.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
mathlib-nightly-testing Bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 15, 2026
@wrenna-robson

Copy link
Copy Markdown
Contributor

I had a bit of a think after digging into the file and with some Claude aid tried a refactor. What I'd like to do is avoid duplication with Core.

Having said that - in fact the elephant in the room is that Lean.Meta.MkIffOfInductiveProp exists in Core. But it doesn't actually export the command or the attribute - just the essential plumbing. (And it also has some of the redundancy I've got rid of here.)

I think the best strategy here - given that file already exists in Core - is that we consider a change to Core. Ideally they'd refactor as I have here - but at minimum mkIffOfInductivePropImpl should be made public, I think. Then we could add the command and attribute here in Batteries.

@mathlib-nightly-testing

Copy link
Copy Markdown
Contributor

Mathlib CI status (docs):

@YaelDillies

Copy link
Copy Markdown
Contributor Author

But the version in core does not properly decapitalise the iff lemma name, right?

@wrenna-robson

Copy link
Copy Markdown
Contributor

But the version in core does not properly decapitalise the iff lemma name, right?

Well, I think the decapitalization happens in the part that Core just doesn't have. I think its mkIffOfInductivePropImpl is the same - or nearly. It's a weird state of affairs.

@YaelDillies

YaelDillies commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

I am interested in things moving forward. Although a core change is possibly the better long term solution, is there any downside to just moving the code from mathlib to batteries for now?

Btw I have fixed the relevant batteries-pr-testing branch but I am waiting on someone to merge the fixes: leanprover-community/mathlib4-nightly-testing#247

@wrenna-robson

Copy link
Copy Markdown
Contributor

That is the nightly tests for 1853, not 1854.

@mathlib-nightly-testing

Copy link
Copy Markdown
Contributor

Mathlib CI status (docs):

@YaelDillies

YaelDillies commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@wrenna-robson

Copy link
Copy Markdown
Contributor

I think in principle I feel this is good to merge. I'd hope that if we do expose this in Core we can upstream the improvements this PR makes to there.

mathlib-nightly-testing Bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 18, 2026
@mathlib-nightly-testing

Copy link
Copy Markdown
Contributor

Mathlib CI status (docs):

@mathlib-nightly-testing

Copy link
Copy Markdown
Contributor

Mathlib CI status (docs):

mathlib-nightly-testing Bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 18, 2026
@wrenna-robson

Copy link
Copy Markdown
Contributor

I've altered the namespaces to match what Core does and made public the thing we want them to make public - that should make further upstreaming to Core more or less drag and drop.

@wrenna-robson

Copy link
Copy Markdown
Contributor

You look like you're still have issues with Mathlib though I have to assume this is some kind of imports bug?

@YaelDillies

Copy link
Copy Markdown
Contributor Author

I just checked and the breakage is completely unrelated to this PR. I assume this is because no one has yet adapted mathlib to recent changes in core

@wrenna-robson

Copy link
Copy Markdown
Contributor

Fiddlesticks. I assume it'll catch up but it'll hold this for now. Sorry.

@mathlib-nightly-testing

Copy link
Copy Markdown
Contributor

Mathlib CI status (docs):

Comment thread Batteries/Lean/Name.lean
public section

/-- Decapitalize the last component of a name. -/
def Lean.Name.decapitalize (n : Name) : Name :=

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.

Can we fix this?

#eval Lean.Name.decapitalize `Test.Me.That'sLife == `Test.Me.that'sLife -- true
#eval Lean.Name.decapitalize `Test.Me.Ç'estLaVie == `Test.Me.ç'estLaVie -- false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review This PR is ready for review; the author thinks it is ready to be merged. breaks-mathlib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants