Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat(data/nat/choose/sum): alternating binomial coefficient sums #4997

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/data/finset/powerset.lean
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@ by cases s; simp [powerset_len, val_le_iff.symm]; refl
card (powerset_len n s) = nat.choose (card s) n :=
(card_pmap _ _ _).trans (card_powerset_len n s.1)

theorem powerset_len_eq_filter {n} {s : finset α} :
powerset_len n s = (powerset s).filter (λ x, x.card = n) :=
by { ext, simp [mem_powerset_len] }

end powerset_len
end finset
40 changes: 40 additions & 0 deletions src/data/nat/choose/sum.lean
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,43 @@ begin
end

end nat

theorem int.alternating_sum_range_choose {n : ℕ} :
awainverse marked this conversation as resolved.
Show resolved Hide resolved
∑ m in range (n + 1), ((-1) ^ m * ↑(choose n m) : ℤ) = if n = 0 then 1 else 0 :=
begin
cases n, { simp },
have h := add_pow (-1 : ℤ) 1 n.succ,
simp only [one_pow, mul_one, add_left_neg, int.nat_cast_eq_coe_nat] at h,
rw [← h, zero_pow (nat.succ_pos n), if_neg (nat.succ_ne_zero n)],
end

namespace finset

theorem sum_powerset_apply_card {α β : Type*} [add_comm_monoid α] (f : ℕ → α) {x : finset β} :
∑ m in x.powerset, f m.card = ∑ m in range (x.card + 1), (x.card.choose m) •ℕ f m :=
begin
transitivity ∑ m in range (x.card + 1), ∑ j in x.powerset.filter (λ z, z.card = m), f j.card,
rw sum_fiberwise_of_maps_to,
{ intros y hy,
rw [mem_range, nat.lt_succ_iff],
rw mem_powerset at hy,
exact card_le_of_subset hy },
apply sum_congr rfl,
intros y hy,
rw [← card_powerset_len, ← sum_const],
apply sum_congr powerset_len_eq_filter.symm,
intros z hz,
rw (mem_powerset_len.1 hz).2,
end

theorem sum_powerset_neg_one_pow_card {α : Type*} [decidable_eq α] (x : finset α) :
∑ m in x.powerset, (-1 : ℤ) ^ m.card = if x = ∅ then 1 else 0 :=
awainverse marked this conversation as resolved.
Show resolved Hide resolved
begin
rw sum_powerset_apply_card,
simp only [nsmul_eq_mul', ← card_eq_zero],
convert int.alternating_sum_range_choose,
ext,
simp,
end

end finset