leanprover / leanprover/lean4

`induction_eliminator` and `cases_eliminator` only key on the head symbol

Open
#4,577 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

The @[induction_eliminator] and @[cases_eliminator] attribute cannot be used to register eliminators for two different types with the same head symbol.

Context

This is necessary to register eliminators for quotients of additive and multiplicative groups in Mathlib, where both have head symbol HasQuotient.quotient (leanprover-community/mathlib#12605)

Steps to Reproduce
  1. Run the following:
inductive Foo : Bool → Type
  | ofTrue (x : Nat) : Foo true
  | ofFalse (x : Nat) : Foo false

-- insert an `id` term to make it easy to check these are actually being used.

@[elab_as_elim]
theorem Foo.true_rec {P : Foo true → Prop} (h : ∀ x, P (id <| .ofTrue x))
    (x : Foo true) : P x := by
  cases x; apply h

@[elab_as_elim]
theorem Foo.false_rec {P : Foo false → Prop} (h : ∀ x, P (id <| .ofFalse x))
    (x : Foo false) : P x := by
  cases x; apply h

example (x : Foo true) : x = x := by
  cases x using Foo.true_rec -- works
  sorry

example (x : Foo false) : x = x := by
  cases x using Foo.false_rec -- works
  sorry

attribute [cases_eliminator] Foo.true_rec Foo.false_rec

example (x : Foo true) : x = x := by
  cases x -- fails, tried to use `Foo.false_rec`
  sorry

example (x : Foo false) : x = x := by
  cases x --works
  sorry

Expected behavior: Both false_rec and true_rec can be registered, and the correct eliminator is chosen based on the full type of x

Actual behavior: The last-registered eliminator wins, causes the penultimate example to fail as the eliminator does not actually match the type of the major premise.

Versions

4.9.0-rc3

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal Lean reproducer in the issue and then trace the implementation of the cases_eliminator and induction_eliminator attributes and their eliminator-selection logic. Done means both eliminators can be registered for types sharing a head symbol, with the correct one selected from the full type and all four examples behaving as expected.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.