Zulip Chat Archive

Stream: Is there code for X?

Topic: Cardinality of (fin).filter


Riccardo Brasca (Nov 04 2021 at 16:50):

What is the best way of proving this?

import data.fintype.card

example (n : ) (i : fin n) : (finset.univ.filter (λ j, i < j)).card = n - i := sorry

I've tried to play arund with data.fin.interval, but the results are not stated using filter.

Yaël Dillies (Nov 04 2021 at 16:53):

Hmm... that sounds like a job for me.

Riccardo Brasca (Nov 04 2021 at 16:55):

I thought writing directly to you :)
In any case it is surely not difficult, but I don't see a one line proof.

Floris van Doorn (Nov 04 2021 at 16:55):

one step should probably be docs#finset.card_sdiff. The other part probably involves some reasoning about the map fin i -> fin n.

Floris van Doorn (Nov 04 2021 at 16:55):

I believe there is also an off-by-1 error in the original post

Yaël Dillies (Nov 04 2021 at 16:55):

We can add:

lemma fin.card_Ioi (b : fin n) : (Ioi b).card = n - b := sorry

Yaël Dillies (Nov 04 2021 at 16:57):

It will be direct from the result about card_Ioc adn then your lemma boils down to showing finset.univ.filter (λ j, i < j) = Ioi i, which ext, simp should do.

Yaël Dillies (Nov 04 2021 at 17:01):

Where's fin.order_top?

Riccardo Brasca (Nov 04 2021 at 17:03):

Write n+1

Riccardo Brasca (Nov 04 2021 at 17:03):

I was fighting with the same problem

Riccardo Brasca (Nov 04 2021 at 17:03):

I hate that fin 0 is empty

Yaël Dillies (Nov 04 2021 at 17:03):

Uh, what is the instance called?

Floris van Doorn (Nov 04 2021 at 17:04):

from docs#fin.bounded_lattice, right?

Yaël Dillies (Nov 04 2021 at 17:04):

Ah yeah, of course :face_palm:

Riccardo Brasca (Nov 04 2021 at 17:56):

import data.fin.interval

namespace fin

open finset

lemma Ioi_eq_finset_subtype {n : } (a : fin (n + 1)) :
  Ioi a = (Ioo (a : ) (n + 1)).subtype (λ x, x < n + 1) :=
by { ext, simp [is_lt] }

lemma card_Ioi (n : ) (a : fin (n + 1)) : (Ioi a).card = n - a :=
begin
  rw [Ioi_eq_finset_subtype],
  simp only [and_imp, imp_self, mem_Ioo, filter_true_of_mem, nat.card_Ioo, card_subtype,
    implies_true_iff],
  have h₁ : 1  n + 1 - a := by simp [nat.one_le_iff_ne_zero, is_lt],
  rw [nat.sub_eq_iff_eq_add h₁, nat.sub_add_comm (is_le a)],
end

lemma Ioi_eq_filter {n : } (a : fin (n + 1)) : Ioi a = finset.univ.filter (λ j, a < j) :=
by { ext, simp }

lemma filter_gt_card {n : } (a : fin (n + 1)) : (finset.univ.filter (λ j, a < j)).card = n - a :=
by rw [ Ioi_eq_filter, card_Ioi]

end fin

Yaël Dillies (Nov 04 2021 at 18:06):

Ahah! Sorry, Riccardo. #10168

Yaël Dillies (Nov 04 2021 at 18:12):

@Riccardo Brasca, to be sure you see that before opening a PR.

Riccardo Brasca (Nov 04 2021 at 18:13):

No problem!

Yaël Dillies (Nov 05 2021 at 00:22):

Aaaand, you have it!


Last updated: Dec 20 2023 at 11:08 UTC