Zulip Chat Archive

Stream: new members

Topic: building a set from a sequence


Connor Gordon (Oct 31 2022 at 00:57):

Suppose I have a sequence A i indexed by some set I. How would I build the set {A i : i ∈ I} in Lean?

Eric Rodriguez (Oct 31 2022 at 01:07):

docs#set.image

Junyan Xu (Oct 31 2022 at 01:19):

maybe docs#set.range instead

Connor Gordon (Oct 31 2022 at 01:30):

Alright, that makes sense, but I realized now that I said it was indexed by a set but in fact it is indexed by a type (i.e. I have a function f : ℕ → 'a and would like to construct the set {f n : n ∈ ℕ}. Using set.image doesn't seem to work because is a type, rather than a set. Any idea how to work with that?

Connor Gordon (Oct 31 2022 at 01:35):

Never mind, set.range got it! Thanks for the help!

Kyle Miller (Oct 31 2022 at 01:45):

By the way, for your original formulation you can write {(A i) : (i ∈ I)}. (This should work, but I didn't test it.)

Kyle Miller (Oct 31 2022 at 01:46):

The second would be {(f n) : (n : ℕ)}

Kyle Miller (Oct 31 2022 at 01:46):

It might be better to use docs#set.range though to get access to more lemmas.

Eric Rodriguez (Oct 31 2022 at 02:20):

you don't need it in this case as Junyan shows, but set.univ is the set of all elements of a type

Eric Rodriguez (Oct 31 2022 at 02:20):

Kyle, I can't seem to get that cool-looking notation to work.

Kyle Miller (Oct 31 2022 at 02:25):

These seem to work for me:

example : set  := {(2 * n) | (n : )}

def f (n : ) :  := 2 * n
example : set  := {(f n) | (n : )}

example (s : set ) := {(2 * n) | (n  s)}

Matt Diamond (Oct 31 2022 at 02:57):

@Kyle Miller your first example had : in the middle instead of |... I think that may have been why it wasn't working for Eric


Last updated: Dec 20 2023 at 11:08 UTC