Skip to content

Commit 5489873

Browse files
committed
feat: another version of the cardinality of the difference (leanprover-community#37541)
In mathlib there is `Set.ncard_diff` which states that `(t \ s).ncard = t.ncard - s.ncard` when `s ⊆ t` and `s` is finite. But one way to prove that `s` is finite is by showing that `t` is finite and using the `s ⊆ t` hypothesis, so this PR adds `Set.ncard_diff'` which assumes that `t` is finite instead of `s`.
1 parent 5c04ef2 commit 5489873

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Mathlib/Data/Set/Card.lean

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,10 +995,16 @@ theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t) (ht : t.Finite := by toFini
995995
rw [ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq, ht.diff.cast_ncard_eq,
996996
encard_diff_add_encard_of_subset h]
997997

998+
/-- This is the same as `ncard_diff` but we require `t` to be finite instead. -/
999+
theorem ncard_diff' (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
1000+
(t \ s).ncard = t.ncard - s.ncard := by
1001+
rw [← ncard_diff_add_ncard_of_subset hst ht, add_tsub_cancel_right]
1002+
1003+
/-- This is the same as `ncard_diff'` but we require `s` to be finite instead. -/
9981004
theorem ncard_diff (hst : s ⊆ t) (hs : s.Finite := by toFinite_tac) :
9991005
(t \ s).ncard = t.ncard - s.ncard := by
10001006
obtain ht | ht := t.finite_or_infinite
1001-
· rw [← ncard_diff_add_ncard_of_subset hst ht, add_tsub_cancel_right]
1007+
· exact ncard_diff' hst ht
10021008
· rw [ht.ncard, Nat.zero_sub, (ht.diff hs).ncard]
10031009

10041010
lemma cast_ncard_sdiff {R : Type*} [AddGroupWithOne R] (hst : s ⊆ t) (ht : t.Finite) :

0 commit comments

Comments
 (0)