Zulip Chat Archive

Stream: lean4

Topic: Extracting `inr` having a proof of `isInr`


cognivore (Sep 20 2022 at 17:57):

With the following code:

def isInr (x : PSum α β) : Prop :=
  match x with
  | .inr _ => true
  | .inl _ => false

theorem extrr (x : PSum α β) (hE :  y : β, x = .inr y) : isInr x :=
  Exists.elim hE
    (fun ey =>
      fun xeq =>
        ??? (isInr $ .inr ey) (isInr x)
    )

I'm starting with the easy direction first: prove that if something is .inr y, then it is isInr.

cognivore (Sep 20 2022 at 17:58):

It feels like I got really close to finishing the easy proof, but I have no idea how to tell it that since x = .inr ey, isInr x = isInr $ .inr ey.

And since .inr ey is .inr, it's also isInr.

cognivore (Sep 20 2022 at 18:03):

I got help from Winston from Yatima:

theorem extrr (x : PSum α β) (hE :  y : β, x = .inr y) : isInr x :=
  Exists.elim hE
    (fun ey =>
      fun xeq => by
        exact xeq  rfl
    )

Now my only question is -- how to go back from isInr x isInr \ x to y:x=.inr y \exists y : x = .inr \ y

Adam Topaz (Sep 20 2022 at 18:40):

def isInr (x : PSum α β) : Prop :=
  match x with
  | .inr _ => True
  | .inl _ => False

example (x : PSum α β) (hx : isInr x) :  y : β, x = .inr y :=
match x with
| .inl _ => False.elim hx
| .inr b => b,rfl

Note that I changed true to True (and similarly for false) as these are the true/false props, whereas the lowercase ones are the bools

Adam Topaz (Sep 20 2022 at 18:45):

Here is an alternative construction

inductive isInr : PSum α β  Prop
| mk (b : β) : isInr (.inr b)

example (x : PSum α β) (hx : isInr x) :  y : β, x = .inr y := by
  cases hx
  exact _,rfl

cognivore (Sep 20 2022 at 19:04):

Adam Topaz said:

def isInr (x : PSum α β) : Prop :=
  match x with
  | .inr _ => True
  | .inl _ => False

example (x : PSum α β) (hx : isInr x) :  y : β, x = .inr y :=
match x with
| .inl _ => False.elim hx
| .inr b => b,rfl

Note that I changed true to True (and similarly for false) as these are the true/false props, whereas the lowercase ones are the bools

False.elim doesn't work on 09-15 toolchain :thinking:

cognivore (Sep 20 2022 at 19:05):

LOL

cognivore (Sep 20 2022 at 19:05):

Note that I changed true to True

cognivore (Sep 20 2022 at 19:05):

Sorry!

Adam Topaz (Sep 20 2022 at 19:06):

Right, note that false : Bool while False : Prop in Lean4

cognivore (Sep 20 2022 at 19:06):

Yes, I tried to do Prop straight away, but didn't understand that I got tricked by Coe.

Adam Topaz (Sep 20 2022 at 19:06):

I assumed you wanted to use props, given the type signature of isInr.

cognivore (Sep 20 2022 at 19:06):

Absolutely!

cognivore (Sep 20 2022 at 19:07):

Now this stopped working :)

theorem extrr (x : PSum α β) (hE :  y : β, x = .inr y) : isInr x :=
  Exists.elim hE
    (fun ey =>
      fun xeq => by
        exact xeq  rfl
    )

Adam Topaz (Sep 20 2022 at 19:07):

1 sec

cognivore (Sep 20 2022 at 19:07):

I'm trying to figure out how to rewrite it without the triangle anyway. I don't understand triangle yet.

Adam Topaz (Sep 20 2022 at 19:08):

def isInr (x : PSum α β) : Prop :=
  match x with
  | .inr _ => True
  | .inl _ => False

theorem extrr (x : PSum α β) (hE :  y : β, x = .inr y) : isInr x := by
  let y,hy := hE
  rw [hy]
  trivial

example (x : PSum α β) (hx : isInr x) :  y : β, x = .inr y :=
match x with
| .inl _ => False.elim hx
| .inr b => b,rfl

cognivore (Sep 20 2022 at 19:09):

I am trying to avoid tactics mode when I can so far. Your first line is equivalent to me calling Exists.elim hE, right?

cognivore (Sep 20 2022 at 19:11):

How does rw tactic understand what does it have to rewrite x = .inr y to? and how does trivial then pick it up?
My intuition was that I have to use rfl to show .inr y = x

Adam Topaz (Sep 20 2022 at 19:11):

yeah essentially, here is a term-mode proof

theorem extrr (x : PSum α β) (hE :  y : β, x = .inr y) : isInr x :=
Exists.elim hE (fun _ xeq => xeq  trivial)

cognivore (Sep 20 2022 at 19:12):

Also, why does trivial work, whereas simp doesn't? (Sorry for a ton of stupid questions, I'm too stupid to understand the "Theorem Proving" book from the first read)

Adam Topaz (Sep 20 2022 at 19:13):

trivial is the constructor of True.

Adam Topaz (Sep 20 2022 at 19:13):

docs4#True


Last updated: Dec 20 2023 at 11:08 UTC