Finsets in product types #
This file defines finset constructions on the product type α × β
. Beware not to confuse with the
Finset.prod
operation which computes the multiplicative product.
Main declarations #
Finset.product
: Turnss : Finset α
,t : Finset β
into their product inFinset (α × β)
.Finset.diag
: Fors : Finset α
,s.diag
is theFinset (α × α)
of pairs(a, a)
witha ∈ s
.Finset.offDiag
: Fors : Finset α
,s.offDiag
is theFinset (α × α)
of pairs(a, b)
witha, b ∈ s
anda ≠ b
.
prod #
product s t
is the set of pairs (a, b)
such that a ∈ s
and b ∈ t
.
Equations
- Finset.product s t = { val := s.val ×ˢ t.val, nodup := (_ : Multiset.Nodup (s.val ×ˢ t.val)) }
Instances For
theorem
Finset.subset_product_image_fst
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
[DecidableEq α]
:
Finset.image Prod.fst (s ×ˢ t) ⊆ s
theorem
Finset.subset_product_image_snd
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
[DecidableEq β]
:
Finset.image Prod.snd (s ×ˢ t) ⊆ t
theorem
Finset.product_image_fst
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
[DecidableEq α]
(ht : Finset.Nonempty t)
:
Finset.image Prod.fst (s ×ˢ t) = s
theorem
Finset.product_image_snd
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
[DecidableEq β]
(ht : Finset.Nonempty s)
:
Finset.image Prod.snd (s ×ˢ t) = t
theorem
Finset.subset_product
{α : Type u_1}
{β : Type u_2}
[DecidableEq α]
[DecidableEq β]
{s : Finset (α × β)}
:
s ⊆ Finset.image Prod.fst s ×ˢ Finset.image Prod.snd s
theorem
Finset.map_swap_product
{α : Type u_1}
{β : Type u_2}
(s : Finset α)
(t : Finset β)
:
Finset.map { toFun := Prod.swap, inj' := (_ : Function.Injective Prod.swap) } (t ×ˢ s) = s ×ˢ t
@[simp]
theorem
Finset.image_swap_product
{α : Type u_1}
{β : Type u_2}
[DecidableEq (α × β)]
(s : Finset α)
(t : Finset β)
:
Finset.image Prod.swap (t ×ˢ s) = s ×ˢ t
theorem
Finset.product_eq_biUnion
{α : Type u_1}
{β : Type u_2}
[DecidableEq (α × β)]
(s : Finset α)
(t : Finset β)
:
s ×ˢ t = Finset.biUnion s fun a => Finset.image (fun b => (a, b)) t
theorem
Finset.product_eq_biUnion_right
{α : Type u_1}
{β : Type u_2}
[DecidableEq (α × β)]
(s : Finset α)
(t : Finset β)
:
s ×ˢ t = Finset.biUnion t fun b => Finset.image (fun a => (a, b)) s
@[simp]
theorem
Finset.product_biUnion
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
[DecidableEq γ]
(s : Finset α)
(t : Finset β)
(f : α × β → Finset γ)
:
Finset.biUnion (s ×ˢ t) f = Finset.biUnion s fun a => Finset.biUnion t fun b => f (a, b)
See also Finset.sup_product_left
.
@[simp]
theorem
Finset.card_product
{α : Type u_1}
{β : Type u_2}
(s : Finset α)
(t : Finset β)
:
Finset.card (s ×ˢ t) = Finset.card s * Finset.card t
theorem
Finset.nontrivial_prod_iff
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
:
Nontrivial { x // x ∈ s ×ˢ t } ↔ Finset.Nonempty s ∧ Finset.Nonempty t ∧ (Nontrivial { x // x ∈ s } ∨ Nontrivial { x // x ∈ t })
The product of two Finsets is nontrivial iff both are nonempty at least one of them is nontrivial.
theorem
Finset.filter_product
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
(p : α → Prop)
(q : β → Prop)
[DecidablePred p]
[DecidablePred q]
:
Finset.filter (fun x => p x.fst ∧ q x.snd) (s ×ˢ t) = Finset.filter p s ×ˢ Finset.filter q t
theorem
Finset.filter_product_left
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
(p : α → Prop)
[DecidablePred p]
:
Finset.filter (fun x => p x.fst) (s ×ˢ t) = Finset.filter p s ×ˢ t
theorem
Finset.filter_product_right
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
(q : β → Prop)
[DecidablePred q]
:
Finset.filter (fun x => q x.snd) (s ×ˢ t) = s ×ˢ Finset.filter q t
theorem
Finset.filter_product_card
{α : Type u_1}
{β : Type u_2}
(s : Finset α)
(t : Finset β)
(p : α → Prop)
(q : β → Prop)
[DecidablePred p]
[DecidablePred q]
:
Finset.card (Finset.filter (fun x => p x.fst = q x.snd) (s ×ˢ t)) = Finset.card (Finset.filter p s) * Finset.card (Finset.filter q t) + Finset.card (Finset.filter (fun x => ¬p x) s) * Finset.card (Finset.filter (fun x => ¬q x) t)
theorem
Finset.Nonempty.product
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
(hs : Finset.Nonempty s)
(ht : Finset.Nonempty t)
:
Finset.Nonempty (s ×ˢ t)
theorem
Finset.Nonempty.fst
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
(h : Finset.Nonempty (s ×ˢ t))
:
theorem
Finset.Nonempty.snd
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
(h : Finset.Nonempty (s ×ˢ t))
:
@[simp]
theorem
Finset.nonempty_product
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
:
Finset.Nonempty (s ×ˢ t) ↔ Finset.Nonempty s ∧ Finset.Nonempty t
@[simp]
theorem
Finset.singleton_product
{α : Type u_1}
{β : Type u_2}
{t : Finset β}
{a : α}
:
{a} ×ˢ t = Finset.map { toFun := Prod.mk a, inj' := (_ : Function.Injective (Prod.mk a)) } t
@[simp]
theorem
Finset.product_singleton
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{b : β}
:
s ×ˢ {b} = Finset.map { toFun := fun i => (i, b), inj' := (_ : Function.Injective fun a => (a, b)) } s
@[simp]
theorem
Finset.union_product
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{s' : Finset α}
{t : Finset β}
[DecidableEq α]
[DecidableEq β]
:
@[simp]
theorem
Finset.product_union
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
{t' : Finset β}
[DecidableEq α]
[DecidableEq β]
:
theorem
Finset.inter_product
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{s' : Finset α}
{t : Finset β}
[DecidableEq α]
[DecidableEq β]
:
theorem
Finset.product_inter
{α : Type u_1}
{β : Type u_2}
{s : Finset α}
{t : Finset β}
{t' : Finset β}
[DecidableEq α]
[DecidableEq β]
:
Given a finite set s
, the diagonal, s.diag
is the set of pairs of the form (a, a)
for
a ∈ s
.
Equations
- Finset.diag s = Finset.filter (fun a => a.fst = a.snd) (s ×ˢ s)
Instances For
Given a finite set s
, the off-diagonal, s.offDiag
is the set of pairs (a, b)
with a ≠ b
for a, b ∈ s
.
Equations
- Finset.offDiag s = Finset.filter (fun a => a.fst ≠ a.snd) (s ×ˢ s)
Instances For
@[simp]
@[simp]
@[simp]
theorem
Finset.coe_offDiag
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
:
↑(Finset.offDiag s) = Set.offDiag ↑s
@[simp]
theorem
Finset.diag_card
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
:
Finset.card (Finset.diag s) = Finset.card s
@[simp]
theorem
Finset.offDiag_card
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
:
Finset.card (Finset.offDiag s) = Finset.card s * Finset.card s - Finset.card s
@[simp]
theorem
Finset.diag_union_offDiag
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
:
Finset.diag s ∪ Finset.offDiag s = s ×ˢ s
@[simp]
theorem
Finset.disjoint_diag_offDiag
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
:
Disjoint (Finset.diag s) (Finset.offDiag s)
theorem
Finset.product_sdiff_diag
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
:
s ×ˢ s \ Finset.diag s = Finset.offDiag s
theorem
Finset.product_sdiff_offDiag
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
:
s ×ˢ s \ Finset.offDiag s = Finset.diag s
theorem
Finset.diag_inter
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
(t : Finset α)
:
Finset.diag (s ∩ t) = Finset.diag s ∩ Finset.diag t
theorem
Finset.offDiag_inter
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
(t : Finset α)
:
Finset.offDiag (s ∩ t) = Finset.offDiag s ∩ Finset.offDiag t
theorem
Finset.diag_union
{α : Type u_1}
[DecidableEq α]
(s : Finset α)
(t : Finset α)
:
Finset.diag (s ∪ t) = Finset.diag s ∪ Finset.diag t
theorem
Finset.offDiag_union
{α : Type u_1}
[DecidableEq α]
{s : Finset α}
{t : Finset α}
(h : Disjoint s t)
:
Finset.offDiag (s ∪ t) = Finset.offDiag s ∪ Finset.offDiag t ∪ s ×ˢ t ∪ t ×ˢ s
@[simp]
theorem
Finset.diag_insert
{α : Type u_1}
[DecidableEq α]
{s : Finset α}
(a : α)
:
Finset.diag (insert a s) = insert (a, a) (Finset.diag s)
theorem
Finset.offDiag_insert
{α : Type u_1}
[DecidableEq α]
{s : Finset α}
(a : α)
(has : ¬a ∈ s)
:
Finset.offDiag (insert a s) = Finset.offDiag s ∪ {a} ×ˢ s ∪ s ×ˢ {a}