Zulip Chat Archive

Stream: new members

Topic: Why do I need to unfold here?


Bolton Bailey (Feb 05 2024 at 22:39):

I got tripped up on the example below. myType is defined as a pair, but that it is or what it's a pair of is actually totally irrelevant to the lemma I'm proving. You can see the monad does not use the A,B values it unpacks. Yet it is still necessary to unfold the definition for the code to work. Why is this?

import Mathlib

def myType :=  × 

example {F: Type} (a : F) :
    (fun stmt : myType =>
      (StateT.run (σ := List (List (F))) (m := Id) (α := Unit)
          (match stmt with
          | (A, B) => do
            let x  get
            set ([] :: x)
            let x  get
            set ([] :: x)
            let x  get
            set ((a :: List.headD x []) :: List.tailD x [])
            let x  get
            set ((a :: List.headD x []) :: List.tailD x [])
            let x  get
            set ([] :: x)
            let x  get
            set ([] :: x)
            let x  get
            set ([] :: x)
            let x  get
            set ((a :: List.headD x []) :: List.tailD x [])
            let x  get
            set ([] :: x)
            let x  get
            set ((a :: List.headD x []) :: List.tailD x []))
          [[]]).snd) =
    fun x => [[a], [a], [], [], [a, a], [], []] := by
  simp -- Doesn't do what I want
  unfold myType -- ???
  simp -- Now it does what I want

Bolton Bailey (Feb 05 2024 at 22:44):

Indeed, if I replace (A,B) with A it works on the first simp (unfortunately I don't think I can do this in my real code because the unpacking arises from a definition which is important for other things).

Matt Diamond (Feb 06 2024 at 00:41):

https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/.E2.9C.94.20power.20of.20a.20type.20using.20cartesian.20product/near/419134912

Matt Diamond (Feb 06 2024 at 00:42):

Eric Wieser said:

def Foo : Type := Bar roughly means "forget everything you know about Bar other than how it is represented"

Matt Diamond (Feb 06 2024 at 00:43):

oh wait, sorry, I just misread your question

Matt Diamond (Feb 06 2024 at 00:44):

you're saying you understand the behavior of def but you're still not sure why it matters in this case?

Bolton Bailey (Feb 06 2024 at 00:44):

Yes

Bolton Bailey (Feb 06 2024 at 00:47):

I don't understand why it affects how simp works here. The whole do expression never references the arguments from that function which returns it.

Bolton Bailey (Feb 06 2024 at 00:52):

Frankly, I don't understand why, when I have a match expression like that, it doesn't just automatically disappear with simp.


Last updated: May 02 2025 at 03:31 UTC