Skip to content

induction_eliminator and cases_eliminator only key on the head symbol #4577

@eric-wieser

Description

@eric-wieser

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/mathlib3#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-mediumWe may work on this issue if we find the timebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions