feat(library/data/set/basic,finite): add more finiteness facts

This commit is contained in:
Jeremy Avigad 2015-08-07 17:01:28 -04:00 committed by Leonardo de Moura
parent 06f20694c8
commit 1b0773b604
2 changed files with 54 additions and 14 deletions

View file

@ -215,6 +215,14 @@ theorem mem_diff_iff (s t : set X) (x : X) : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t
theorem mem_diff_eq (s t : set X) (x : X) : x ∈ s \ t = (x ∈ s ∧ x ∉ t) := rfl
theorem union_diff_cancel {s t : set X} [dec : Π x, decidable (x ∈ s)] (H : s ⊆ t) : s (t \ s) = t :=
setext (take x, iff.intro
(assume H1 : x ∈ s (t \ s), or.elim H1 (assume H2, !H H2) (assume H2, and.left H2))
(assume H1 : x ∈ t,
decidable.by_cases
(suppose x ∈ s, or.inl this)
(suppose x ∉ s, or.inr (and.intro H1 this))))
/- powerset -/
definition powerset (s : set X) : set (set X) := {x : set X | x ⊆ s}

View file

@ -123,6 +123,12 @@ by rewrite [finset.subset_eq_to_set_subset, *to_set_to_finset]
theorem finite_of_finite_insert {s : set A} {a : A} (finias : finite (insert a s)) : finite s :=
finite_subset (subset_insert a s)
theorem finite_upto [instance] (n : ) : finite {i | i < n} :=
by rewrite [-finset.to_set_upto n]; apply finite_finset
theorem to_finset_upto (n : ) : to_finset {i | i < n} = finset.upto n :=
by apply (to_finset_eq_of_to_set_eq !finset.to_set_upto)
-- question: how can I avoid the parenthesis in the notation below?
-- this didn't work: notation `𝒫`:max s := powerset s, nor variants
@ -150,7 +156,7 @@ by rewrite H; apply finite_image
theorem induction_finite [recursor 6] {P : set A → Prop}
(H1 : P ∅)
(H2 : ∀ ⦃a : A⦄, ∀ {s : set A} [fins : finite s], a ∉ s → P s → P (insert a s)) :
∀ (s : set A), finite s → P s :=
∀ (s : set A) [fins : finite s], P s :=
begin
intro s fins,
rewrite [-to_set_to_finset s],
@ -164,11 +170,11 @@ begin
exact ih
end
theorem induction_on_finite {P : set A → Prop} (s : set A) (fins : finite s)
theorem induction_on_finite {P : set A → Prop} (s : set A) [fins : finite s]
(H1 : P ∅)
(H2 : ∀ ⦃a : A⦄, ∀ {s : set A} [fins : finite s], a ∉ s → P s → P (insert a s)) :
P s :=
induction_finite H1 H2 s fins
induction_finite H1 H2 s
/- cardinality -/
@ -202,18 +208,19 @@ else by rewrite [card_insert_of_not_mem H]
theorem card_singleton (a : A) : card '{a} = 1 :=
by rewrite [card_insert_of_not_mem !not_mem_empty, card_empty]
/-
-- TODO: get induction working somehow.
set_option formatter.hide_full_terms false
/- Note: the induction tactic does not work well with the set induction principle with the
extra predicate "finite". -/
theorem eq_empty_of_card_eq_zero {s : set A} [fins : finite s] : card s = 0 → s = ∅ :=
induction_on_finite s
(by intro H; exact rfl)
(begin
intro a s' fins' anins IH H,
rewrite (card_insert_of_not_mem anins) at H,
apply nat.no_confusion H
end)
theorem eq_empty_of_card_eq_zero {s : set A} [fins : finite s] (H : card s = 0) : s = ∅ :=
begin
induction s with a s' fins' anins IH,
{rewrite card_empty at H},
rewrite (card_insert_of_not_mem anins) at H,
apply nat.no_confusion H,
end
-/
theorem card_upto (n : ) : card {i | i < n} = n :=
by rewrite [↑card, to_finset_upto, finset.card_upto]
theorem card_add_card (s₁ s₂ : set A) [fins₁ : finite s₁] [fins₂ : finite s₂] :
card s₁ + card s₂ = card (s₁ s₂) + card (s₁ ∩ s₂) :=
@ -223,4 +230,29 @@ begin
apply finset.card_add_card
end
theorem card_union (s₁ s₂ : set A) [fins₁ : finite s₁] [fins₂ : finite s₂] :
card (s₁ s₂) = card s₁ + card s₂ - card (s₁ ∩ s₂) :=
calc
card (s₁ s₂) = card (s₁ s₂) + card (s₁ ∩ s₂) - card (s₁ ∩ s₂) : add_sub_cancel
... = card s₁ + card s₂ - card (s₁ ∩ s₂) : card_add_card s₁ s₂
theorem card_union_of_disjoint {s₁ s₂ : set A} [fins₁ : finite s₁] [fins₂ : finite s₂] (H : s₁ ∩ s₂ = ∅) :
card (s₁ s₂) = card s₁ + card s₂ :=
by rewrite [card_union, H, card_empty]
theorem card_eq_card_add_card_diff {s₁ s₂ : set A} [fins₁ : finite s₁] [fins₂ : finite s₂] (H : s₁ ⊆ s₂) :
card s₂ = card s₁ + card (s₂ \ s₁) :=
have H1 : s₁ ∩ (s₂ \ s₁) = ∅,
from eq_empty_of_forall_not_mem (take x, assume H, (and.right (and.right H)) (and.left H)),
have s₂ = s₁ (s₂ \ s₁), from eq.symm (union_diff_cancel H),
calc
card s₂ = card (s₁ (s₂ \ s₁)) : {this}
... = card s₁ + card (s₂ \ s₁) : card_union_of_disjoint H1
theorem card_le_card_of_subset {s₁ s₂ : set A} [fins₁ : finite s₁] [fins₂ : finite s₂] (H : s₁ ⊆ s₂) :
card s₁ ≤ card s₂ :=
calc
card s₂ = card s₁ + card (s₂ \ s₁) : card_eq_card_add_card_diff H
... ≥ card s₁ : le_add_right
end set