Zulip Chat Archive

Stream: Is there code for X?

Topic: set.card_to_finset_prod


Patrick Johnson (May 01 2022 at 12:19):

What is the easiest way to prove this? I have a very low-level proof, so I hope there is a better way.

import tactic
import tactic.induction

noncomputable theory
open_locale classical

def mk (W H : ) : set ( × ) :=
{p :  ×  | p.fst < W  p.snd < H}

instance {W H : } : fintype (mk W H) := by
{ apply set.finite.fintype, rw mk,
  apply @set.finite.prod   {x | x < W} {y | y < H};
  apply set.finite_lt_nat }

example {W H : } : (mk W H).to_finset.card = W * H :=
begin
  sorry
end

Proof

Eric Wieser (May 01 2022 at 12:29):

This is much less bad:

import tactic
import tactic.induction

noncomputable theory
open_locale classical

def mk (W H : ) : set ( × ) :=
{p :  ×  | p.fst < W  p.snd < H}

def mk_fin (W H : ) : finset ( × ) :=
(finset.range W).product (finset.range H)

lemma coe_mk_fin (W H : ) : (mk_fin W H) = mk W H :=
by { ext, simp [mk_fin, mk] }

instance {W H : } : fintype (mk W H) :=
fintype.of_equiv (mk_fin W H) $ equiv.set_congr (coe_mk_fin _ _)

example {W H : } : (mk W H).to_finset.card = W * H :=
begin
  simp_rw coe_mk_fin,
  -- or just `simp`
  simp_rw [mk_fin, set.to_finset_card, finset.coe_sort_coe, fintype.card_coe,
    finset.card_product, finset.card_range],
end

Eric Wieser (May 01 2022 at 12:31):

Of course, it would be easier to just use the finset in the first place

Patrick Johnson (May 01 2022 at 22:31):

Do we have this?

example {α : Type} {s t : finset α} (h : s  t) : s.card = t.card :=
begin
  sorry
end

Patrick Johnson (May 01 2022 at 22:31):

Or this?

import set_theory.cardinal.basic
open_locale cardinal

example {α : Type} {s t : set α} [fintype s] [fintype t]
  (h : # s = # t) : s.to_finset.card = t.to_finset.card :=
begin
  sorry
end

Eric Wieser (May 01 2022 at 22:34):

docs#fintype.card_congr and docs#cardinal.eq will make progress on the second one

Eric Wieser (May 01 2022 at 22:39):

docs#fintype.card_coe in reverse basically closes the first one


Last updated: Dec 20 2023 at 11:08 UTC