Zulip Chat Archive

Stream: general

Topic: from some equality to is_some


Bernd Losert (Dec 25 2021 at 16:52):

I have a proposition p that requires an is_some x, but I only have an equality x = some y. How do I convert it?

Bernd Losert (Dec 25 2021 at 16:59):

This seems to work:

have : is_some x, simp [h], -- h : x = some y

Patrick Johnson (Dec 25 2021 at 17:04):

A #mwe would be helpful. But in general, you can rewrite the assumption and use docs#option.is_some_some

import tactic
open option

example {α : Type*} {x : option α} {y : α}
  (h : x = some y) : is_some x = tt :=
by rw [h, is_some_some]

Bernd Losert (Dec 25 2021 at 17:05):

But is_some_some gives you an equality. What I want is a value of type is_some x.

Patrick Johnson (Dec 25 2021 at 17:06):

is_some x is not a type. It is a term. Note that is_some returns a bool, not a Prop. What you've done in have : is_some x, simp [h] is an implicit coercion.

Bernd Losert (Dec 25 2021 at 17:07):

Oh boy. So the type that I actually what then is is_some x = tt?

Patrick Johnson (Dec 25 2021 at 17:10):

It depends on your use case. It's impossible to tell without a mwe.

Bernd Losert (Dec 25 2021 at 17:11):

In your example, do I have to write is_some x = tt or could I just write is_some x?

Yaël Dillies (Dec 25 2021 at 17:14):

is_some x : Prop is defined as is_some x = tt

Bernd Losert (Dec 25 2021 at 17:16):

In the example given you need the = tt. Otherwise, it complains. Looks like lean doesn't realize it could coerce it to a Prop.

Yaël Dillies (Dec 25 2021 at 17:17):

This is unexpected. Give us a MWE.

Bernd Losert (Dec 25 2021 at 17:18):

import tactic
open option

example {α : Type*} {x : option α} {y : α}
  (h : x = some y) : is_some x :=
by rw [h, is_some_some]

Bernd Losert (Dec 25 2021 at 17:18):

It says: error: tactic failed, there are unsolved goals.

Yaël Dillies (Dec 25 2021 at 17:21):

This works:

import data.option.basic

open option

example {α : Type*} {x : option α} {y : α} (h : x = some y) : is_some x :=
by { rw h, exact is_some_some }

Yaël Dillies (Dec 25 2021 at 17:22):

This too:

example {α : Type*} {x : option α} {y : α} (h : x = some y) : is_some x :=
by { rw [h, is_some_some], exact rfl }

Bernd Losert (Dec 25 2021 at 17:25):

Ah, so you need exact rfl to do the coercion? OK.

Yaël Dillies (Dec 25 2021 at 17:28):

It's just that the goal at the end is tt, which is defeq to tt = tt, but rw doesn't see it so it doesn't automatically close the goal.

Bernd Losert (Dec 25 2021 at 17:30):

The goal for me looks like ⊢ ↥tt.

Yaël Dillies (Dec 25 2021 at 17:31):

Yes, which is defeq to tt = tt, as I just said.

Bernd Losert (Dec 25 2021 at 17:32):

I see. Thanks for explaining.

Eric Rodriguez (Dec 25 2021 at 18:28):

Subst may be a nice tactic too

Stuart Presnell (Dec 25 2021 at 18:48):

Why does is_some return a bool? I thought it was more common to define a property by a map into Prop.

Kevin Buzzard (Dec 25 2021 at 21:26):

It's a computer science function

Kevin Buzzard (Dec 25 2021 at 21:26):

It'll be used in tactics probably. You probably wouldn't use it in proofs

Adam Topaz (Dec 25 2021 at 21:53):

In proofs you would usually do a case match on a term of type option X


Last updated: Dec 20 2023 at 11:08 UTC