Zulip Chat Archive

Stream: Is there code for X?

Topic: finset from a finite subset of an infinite set


Michael Stoll (Sep 16 2022 at 20:23):

I have the following.

import tactic
open_locale big_operators

def weight (n d : ) : Type := fin n.succ  
def wsum {n d : } (w : weight n d) :  :=  j, w j
def testvecs (n d : ) : set (weight n d) := {w | w.wsum = d}

Now I would like to produce a finset from testvecs n d. docs#set.to_finset requires a fintype instance on the subtype, but fintype needs the finset as a component. This looks like a chicken-and-egg problem. (docs#set.finite has the same problem.)

So what is the recommended way to produce a finset in such a case?

Michael Stoll (Sep 16 2022 at 20:24):

Or equivalently, a fintype instance on the subtype?

Kyle Miller (Sep 16 2022 at 20:28):

docs#finset.nat.antidiagonal_tuple is the finset

Michael Stoll (Sep 16 2022 at 20:29):

How on earth would I find that?

Kyle Miller (Sep 16 2022 at 20:29):

By asking here :smile:

Kyle Miller (Sep 16 2022 at 20:29):

But if you follow the Zulip and mathlib changelogs long enough you know that the key phrase is "antidiagonal"

Kyle Miller (Sep 16 2022 at 20:31):

If you do want a fintype (or a set.finite) you generally don't use their constructors, and there are instead usually other functions that will help you out. For example, if you want a fintype instance on testvecs you can use docs#fintype.of_finset (there are a number of example instances in https://leanprover-community.github.io/mathlib_docs/data/set/finite.html) along with finset.nat.antidiagonal_tuple

Michael Stoll (Sep 16 2022 at 20:32):

Why is it called "antidiagonal"?

Kyle Miller (Sep 16 2022 at 20:33):

I think you're supposed to think about how the diagonal consists of all coordinates where all indices are equal, and these are orthogonal complements of that

Kyle Miller (Sep 16 2022 at 20:34):

or, it's a minor diagonal of a matrix when there are two components, which is also known as the antidiagonal

Michael Stoll (Sep 16 2022 at 20:36):

I was looking for partition :smile:

Yaël Dillies (Sep 16 2022 at 20:43):

Usually a partition is considered unordered, which is the key difference here. See docs#nat.partition

Michael Stoll (Sep 16 2022 at 20:58):

That's what I figuered out, but then I didn't know what else to look for...

Eric Wieser (Sep 16 2022 at 21:37):

It's also worth noting that fin n → α is often called a tuple

Eric Wieser (Sep 16 2022 at 21:37):

I named that definition after docs#finset.nat.antidiagonal, which is the binary version

Eric Wieser (Sep 16 2022 at 21:38):

My original intent was to be able to use it for some generalized version of docs#exp_sum to match docs#exp_add_of_commute_of_mem_ball, but decided I didn't care enough to go through with it

Michael Stoll (Sep 17 2022 at 08:55):

My first thought when reading "antidiagonal" is "complement of the diagonal" or perhaps "graph of a nontrivial involution".

Eric Wieser (Sep 17 2022 at 11:34):

Complement of the diagonal is a good intuition; the antidiagonal tuples are a complement (in the sense of an affine subspace) to the diagonal formed by function.const

Michael Stoll (Sep 17 2022 at 12:01):

For my taste, this is one or two steps too removed. I'd probably have chosen ordered_partitions...

Eric Wieser (Sep 17 2022 at 12:22):

What names would you have chosen for docs#finset.nat.antidiagonal and docs#list.nat.antidiagonal (the prod rather than tuple versions)?

Michael Stoll (Sep 17 2022 at 13:05):

ordered_partitions_two? As the special case ordered_partitions n 2...

Michael Stoll (Sep 17 2022 at 13:05):

(Even though it is not formally a specialization from fin n → nat.)

Michael Stoll (Sep 17 2022 at 13:06):

Or pairs_with_sum :smile:


Last updated: Dec 20 2023 at 11:08 UTC