Skip to content

simp not rewriting in binder #1926

Closed
Closed

Description

@javra

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

In Lean 3, simp works in the following snippet while in Lean 4 it doesn't. This is maybe due to simp using rw instead of subst internally?

example (q : p → Prop) (h : p = True)
  (h' : ∀(q : True → Prop), (∀ x, q x) ↔ q True.intro) :
    (∀ h', q h') ↔ q (h.symm ▸ trivial) := by
  simp only [h, h'] -- no change in goal in Lean 4
  -- rw [h] -- motive not type correct :-/
  subst h
  simp [h'] -- works fine now

Activity

  1. kbuzzard commented on Dec 8, 2022

    @kbuzzard
    Contributor

    This example above has been over-minimised: simp only [h, h'] does not make progress in Lean 3 either, without any imports. There are examples on Zulip which involve mathlib imports; I'll try and make an example which is mathlib-free.

  2. kbuzzard commented on Dec 8, 2022

    @kbuzzard
    Contributor

    OK so what is actually going on in this example is that in Lean 3, the congr attribute can apparently change the behaviour of simp only, and there are lemmas which are tagged @[congr] in Lean 3 which right now can't be tagged @[congr] in Lean 4. Here is Lean 3 code and Lean 4 code exhibiting the difference:

    -- lean 3
    
    @[simp] lemma forall_true_left (p : true → Prop) : (∀ x, p x) ↔ p true.intro :=
    sorry
    
    example (p : Prop) (q : p → Prop) (h : p) :
      (∀ (h2 : p), q h2) ↔ q h :=
    by simp only [h, forall_true_left] -- fails
    
    
    @[congr] lemma forall_prop_congr' {p p' : Prop} {q q' : p → Prop}
      (hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
    sorry
    
    example (p : Prop) (q : p → Prop) (h : p) :
      (∀ (h2 : p), q h2) ↔ q h :=
    by simp only [h, forall_true_left] -- works
    -- Lean 4
    theorem forall_true_left : ∀ (p : True → Prop), (∀ (x : True), p x) ↔ p True.intro := sorry
    
    theorem forall_prop_congr' {p p' : Prop} {q q' : p → Prop}
      (hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
    sorry
    
    --attribute [congr] forall_prop_congr'
    /-
    invalid 'congr' theorem, equality left/right-hand sides must be applications of the same function
      (∀ (h : ?p), ?q h) = ∀ (h : ?p'), ?q' (_ : ?p)
    -/
    
    example (p : Prop) (q : p → Prop) (h : p) :
      (∀ (h2 : p), q h2) ↔ q h :=
    by simp only [h, forall_true_left] -- fails

    Stepping back a bit, what is really happening is this. In the mathlib port, sometimes ported simp proofs don't work (there are other examples on the Zulip), and what we are trying to understand right now is whether we should just be fixing the proofs up and pressing on or whether we should be asking questions about the divergence in behaviour and trying to re-align. In short, is Lean 4 simp supposed to be at least as good as Lean 3 simp, or is it just supposed to be different? Furthermore, is @[congr] supposed to be working the way it did in Lean 3?

  3. eric-wieser commented on Mar 2, 2023

    @eric-wieser
    Contributor

    And again on Zulip: https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/simp.20on.20binders/near/339224450, with example

    example (A B : Prop) (f : A → ℕ) (h : A ↔ B) :
      ∀ h : A, f h = 0 := by
        simp_rw [h]
        -- goal is unchanged
        sorry
  4. added a commit that references this issue on Mar 4, 2023
  5. eric-wieser commented on Oct 12, 2023

    @eric-wieser
    Contributor

    I ran into this again today while trying to remove some duplication in leanprover-community/mathlib4#7608; it's so annoying to rewrite binders that we end up just proving things from scratch.

  6. eric-wieser commented on Oct 12, 2023

    @eric-wieser
    Contributor

    Here's a workaround that suggests this limitation is easy to fix:

    -- this is in mathlib, but can't be marked `@[congr]` because the head symbol is not a function
    theorem forall_prop_congr' {p p' : Prop} {q q' : p → Prop}
      (hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
    sorry
    
    -- an alias for `∀` to thwart checks that complain that `∀` is not a function
    def Forall {α} (β : α → Sort _) := ∀ a, β a
    
    -- now that we use this alias, `congr` is happy
    @[congr]
    theorem Forall_prop_congr' {p p' : Prop} {q q' : p → Prop}
        (hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (Forall fun h => q h) = Forall fun h : p' => q' (hp.2 h) :=
      forall_prop_congr' hq hp
    
    example (A B : Prop) (f : A → Nat) (h : A ↔ B) :
      ∀ h : A, f h = 0 := by
        rw [←Forall]
        simp [h]
        rw [Forall]
        -- goal is changed!
        sorry
  7. added
    Mathlib4 high prio
    on Oct 16, 2023
  8. added a commit that references this issue on Oct 21, 2023
    66d516b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Mathlib4 high prio

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions