Zulip Chat Archive

Stream: new members

Topic: Lean way to write {(x₁, x₂, 0) | x₁, x₂ ∈ F}


Martin C. Martin (Nov 14 2023 at 20:41):

How can I write {(x₁, x₂, 0) | x₁, x₂ : F} in Lean? {v : (F × F × F) | v.3 = 0} gets the job done, but isn't similar to the original form.

I guess I can phrase it as, given f : F → F → F × F × F, is there a syntactic sugar for {v ∈ F × F × F | ∃ x₁ x₂ : F, f(x₁, x₂) = v}?

Possibly related, what's this and how do I use it?

Kyle Miller (Nov 14 2023 at 20:50):

The syntax is more restrictive than you might want, but you can do

example (F : Type) := {(x₁, x₂, 0) | (x₁ : F) (x₂ : F)}

Martin C. Martin (Nov 14 2023 at 20:55):

Thanks! I feel like I tried that and just got errors, but perhaps I got the syntax wrong.

Martin C. Martin (Nov 15 2023 at 12:48):

Where can I read about the syntax that's accepted? For example, why {(x₁, x₂, 0) | (x₁ x₂ : F)} doesn't work.

Eric Wieser (Nov 15 2023 at 12:56):

import Mathlib.Data.Set.Basic fixes it

Eric Wieser (Nov 15 2023 at 13:05):

#8425 adds documentation

Martin C. Martin (Nov 15 2023 at 13:13):

It doesn't work for me:

import Mathlib.Data.Set.Basic

variable {F : Type _}

def firstTwo : (Set (F × F × F)) := {(x₁, x₂, 0)| (x₁ x₂ : F)}

On x₂, I get unexpected identifier; expected ')'.

Eric Wieser (Nov 15 2023 at 13:14):

(x₁ x₂ : F) isn't allowed, you have to write (x₁ : F) (x₂ : F)

Martin C. Martin (Nov 15 2023 at 13:15):

Ok, thanks. Where can I learn more about why, and what syntax is allowed and what isn't?

Eric Wieser (Nov 15 2023 at 13:16):

If you write a version that's legal, you can goto definition on the |

Martin C. Martin (Nov 15 2023 at 13:25):

Thanks. So it turns into ∃ᵉ, good to know.

Martin C. Martin (Nov 17 2023 at 19:32):

Is there a way to add a constraint to that? The equivalent of {(x₁, x₂, x₃, x₄)| x₃ = 5x₄ + b} ?

Kyle Miller (Nov 17 2023 at 19:52):

It's not pretty, but you can do {(x₁, x₂, x₃, x₄) | (_ : x₃ = 5*x₄ + b)}, since a constraint is the same as saying that there exists a proof that the constraint is satisfied.

Kyle Miller (Nov 17 2023 at 19:53):

Eric added such an example in the documentation in this change: https://github.com/leanprover-community/mathlib4/pull/8425/files


Last updated: Dec 20 2023 at 11:08 UTC