2015-05-16 08:42:13 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
Authors: Leonardo de Moura, Jeremy Avigad
|
|
|
|
|
|
2015-12-19 19:10:20 +00:00
|
|
|
|
Finite products on a monoid, and finite sums on an additive monoid. There are three versions:
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-12-19 19:10:20 +00:00
|
|
|
|
Prodl, Suml : products and sums over lists
|
|
|
|
|
Prod, Sum (in namespace finset) : products and sums over finsets
|
|
|
|
|
Prod, Sum (in namespace set) : products and sums over finite sets
|
2015-08-08 00:53:30 +00:00
|
|
|
|
|
2016-01-21 22:40:40 +00:00
|
|
|
|
We also define internal functions Prodl_semigroup and Prod_semigroup that can be used to define
|
|
|
|
|
operations over commutative semigroups where there is no unit. We put them into their own namespaces
|
|
|
|
|
so that they won't be very prominent. They can be used to define Min and Max in the number systems,
|
|
|
|
|
or Inter for finsets.
|
|
|
|
|
|
2015-12-19 19:10:20 +00:00
|
|
|
|
We have to be careful with dependencies. This theory imports files from finset and list, which
|
|
|
|
|
import basic files from nat.
|
2015-05-16 08:42:13 +00:00
|
|
|
|
-/
|
2015-12-19 19:10:20 +00:00
|
|
|
|
import .group .group_power data.list.basic data.list.perm data.finset.basic data.set.finite
|
2016-01-21 22:40:40 +00:00
|
|
|
|
open function binary quot subtype list
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
variables {A B : Type}
|
|
|
|
|
variable [deceqA : decidable_eq A]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2016-01-21 22:40:40 +00:00
|
|
|
|
definition mulf [sgB : semigroup B] (f : A → B) : B → A → B :=
|
|
|
|
|
λ b a, b * f a
|
|
|
|
|
|
2015-12-19 19:10:20 +00:00
|
|
|
|
/-
|
|
|
|
|
-- list versions.
|
|
|
|
|
-/
|
|
|
|
|
|
2016-01-21 22:40:40 +00:00
|
|
|
|
/- Prodl_semigroup: product indexed by a list, with a default for the empty list -/
|
|
|
|
|
|
|
|
|
|
namespace Prodl_semigroup
|
|
|
|
|
variable [semigroup B]
|
|
|
|
|
|
|
|
|
|
definition Prodl_semigroup (dflt : B) : ∀ (l : list A) (f : A → B), B
|
|
|
|
|
| [] f := dflt
|
|
|
|
|
| (a :: l) f := list.foldl (mulf f) (f a) l
|
|
|
|
|
|
|
|
|
|
theorem Prodl_semigroup_nil (dflt : B) (f : A → B) : Prodl_semigroup dflt nil f = dflt := rfl
|
|
|
|
|
|
|
|
|
|
theorem Prodl_semigroup_cons (dflt : B) (f : A → B) (a : A) (l : list A) :
|
|
|
|
|
Prodl_semigroup dflt (a::l) f = list.foldl (mulf f) (f a) l := rfl
|
|
|
|
|
|
|
|
|
|
theorem Prodl_semigroup_singleton (dflt : B) (f : A → B) (a : A) :
|
|
|
|
|
Prodl_semigroup dflt [a] f = f a := rfl
|
|
|
|
|
|
|
|
|
|
theorem Prodl_semigroup_cons_cons (dflt : B) (f : A → B) (a₁ a₂ : A) (l : list A) :
|
|
|
|
|
Prodl_semigroup dflt (a₁::a₂::l) f = f a₁ * Prodl_semigroup dflt (a₂::l) f :=
|
|
|
|
|
begin
|
|
|
|
|
rewrite [↑Prodl_semigroup, foldl_cons, ↑mulf at {2}],
|
|
|
|
|
generalize (f a₂),
|
|
|
|
|
induction l with a l ih,
|
|
|
|
|
{intro x, exact rfl},
|
|
|
|
|
intro x,
|
|
|
|
|
rewrite [*foldl_cons, ↑mulf at {2,3}, mul.assoc, ih]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
theorem Prodl_semigroup_binary (dflt : B) (f : A → B) (a₁ a₂ : A) :
|
|
|
|
|
Prodl_semigroup dflt [a₁, a₂] f = f a₁ * f a₂ := rfl
|
|
|
|
|
|
|
|
|
|
section deceqA
|
|
|
|
|
include deceqA
|
|
|
|
|
|
|
|
|
|
theorem Prodl_semigroup_insert_of_mem (dflt : B) (f : A → B) {a : A} {l : list A} : a ∈ l →
|
|
|
|
|
Prodl_semigroup dflt (insert a l) f = Prodl_semigroup dflt l f :=
|
|
|
|
|
assume ainl, by rewrite [insert_eq_of_mem ainl]
|
|
|
|
|
|
|
|
|
|
theorem Prodl_semigroup_insert_insert_of_not_mem (dflt : B) (f : A → B)
|
|
|
|
|
{a₁ a₂ : A} {l : list A} (h₁ : a₂ ∉ l) (h₂ : a₁ ∉ insert a₂ l) :
|
|
|
|
|
Prodl_semigroup dflt (insert a₁ (insert a₂ l)) f =
|
|
|
|
|
f a₁ * Prodl_semigroup dflt (insert a₂ l) f :=
|
|
|
|
|
by rewrite [insert_eq_of_not_mem h₂, insert_eq_of_not_mem h₁, Prodl_semigroup_cons_cons]
|
|
|
|
|
end deceqA
|
|
|
|
|
end Prodl_semigroup
|
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
/- Prodl: product indexed by a list -/
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
section monoid
|
2016-01-21 22:40:40 +00:00
|
|
|
|
variable [monoid B]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
definition Prodl (l : list A) (f : A → B) : B :=
|
2015-05-16 08:42:13 +00:00
|
|
|
|
list.foldl (mulf f) 1 l
|
|
|
|
|
|
|
|
|
|
-- ∏ x ← l, f x
|
2015-12-31 18:42:51 +00:00
|
|
|
|
notation `∏` binders `←` l `, ` r:(scoped f, Prodl l f) := r
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
|
|
|
|
private theorem foldl_const (f : A → B) :
|
|
|
|
|
∀ (l : list A) (b : B), foldl (mulf f) b l = b * foldl (mulf f) 1 l
|
|
|
|
|
| [] b := by rewrite [*foldl_nil, mul_one]
|
|
|
|
|
| (a::l) b := by rewrite [*foldl_cons, foldl_const, {foldl _ (mulf f 1 a) _}foldl_const, ↑mulf,
|
|
|
|
|
one_mul, mul.assoc]
|
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prodl_nil (f : A → B) : Prodl [] f = 1 := rfl
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prodl_cons (f : A → B) (a : A) (l : list A) : Prodl (a::l) f = f a * Prodl l f :=
|
|
|
|
|
by rewrite [↑Prodl, foldl_cons, foldl_const, ↑mulf, one_mul]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prodl_append :
|
|
|
|
|
∀ (l₁ l₂ : list A) (f : A → B), Prodl (l₁++l₂) f = Prodl l₁ f * Prodl l₂ f
|
|
|
|
|
| [] l₂ f := by rewrite [append_nil_left, Prodl_nil, one_mul]
|
|
|
|
|
| (a::l) l₂ f := by rewrite [append_cons, *Prodl_cons, Prodl_append, mul.assoc]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
section deceqA
|
|
|
|
|
include deceqA
|
|
|
|
|
|
|
|
|
|
theorem Prodl_insert_of_mem (f : A → B) {a : A} {l : list A} : a ∈ l →
|
|
|
|
|
Prodl (insert a l) f = Prodl l f :=
|
2015-05-16 12:26:59 +00:00
|
|
|
|
assume ainl, by rewrite [insert_eq_of_mem ainl]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prodl_insert_of_not_mem (f : A → B) {a : A} {l : list A} :
|
|
|
|
|
a ∉ l → Prodl (insert a l) f = f a * Prodl l f :=
|
|
|
|
|
assume nainl, by rewrite [insert_eq_of_not_mem nainl, Prodl_cons]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prodl_union {l₁ l₂ : list A} (f : A → B) (d : disjoint l₁ l₂) :
|
|
|
|
|
Prodl (union l₁ l₂) f = Prodl l₁ f * Prodl l₂ f :=
|
|
|
|
|
by rewrite [union_eq_append d, Prodl_append]
|
|
|
|
|
end deceqA
|
2015-05-17 07:50:32 +00:00
|
|
|
|
|
2015-05-18 22:45:23 +00:00
|
|
|
|
theorem Prodl_one : ∀(l : list A), Prodl l (λ x, 1) = (1:B)
|
2015-05-17 07:50:32 +00:00
|
|
|
|
| [] := rfl
|
|
|
|
|
| (a::l) := by rewrite [Prodl_cons, Prodl_one, mul_one]
|
2015-07-15 02:17:40 +00:00
|
|
|
|
|
2015-12-31 18:42:51 +00:00
|
|
|
|
lemma Prodl_singleton (a : A) (f : A → B) : Prodl [a] f = f a :=
|
2015-07-15 02:17:40 +00:00
|
|
|
|
!one_mul
|
|
|
|
|
|
|
|
|
|
lemma Prodl_map {f : A → B} :
|
|
|
|
|
∀ {l : list A}, Prodl l f = Prodl (map f l) id
|
|
|
|
|
| nil := by rewrite [map_nil]
|
|
|
|
|
| (a::l) := begin rewrite [map_cons, Prodl_cons f, Prodl_cons id (f a), Prodl_map] end
|
|
|
|
|
|
|
|
|
|
open nat
|
|
|
|
|
lemma Prodl_eq_pow_of_const {f : A → B} :
|
|
|
|
|
∀ {l : list A} b, (∀ a, a ∈ l → f a = b) → Prodl l f = b ^ length l
|
2015-12-06 07:27:46 +00:00
|
|
|
|
| nil := take b, assume Pconst, by rewrite [length_nil, {b^0}pow_zero]
|
2015-07-15 02:17:40 +00:00
|
|
|
|
| (a::l) := take b, assume Pconst,
|
2016-02-29 19:47:33 +00:00
|
|
|
|
have Pconstl : ∀ a', a' ∈ l → f a' = b,
|
2015-07-15 02:17:40 +00:00
|
|
|
|
from take a' Pa'in, Pconst a' (mem_cons_of_mem a Pa'in),
|
2015-12-31 18:42:51 +00:00
|
|
|
|
by rewrite [Prodl_cons f, Pconst a !mem_cons, Prodl_eq_pow_of_const b Pconstl, length_cons,
|
|
|
|
|
add_one, pow_succ b]
|
2015-05-17 05:24:37 +00:00
|
|
|
|
end monoid
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
section comm_monoid
|
2016-01-21 22:40:40 +00:00
|
|
|
|
variable [comm_monoid B]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prodl_mul (l : list A) (f g : A → B) : Prodl l (λx, f x * g x) = Prodl l f * Prodl l g :=
|
2015-05-16 08:42:13 +00:00
|
|
|
|
list.induction_on l
|
2015-05-17 05:24:37 +00:00
|
|
|
|
(by rewrite [*Prodl_nil, mul_one])
|
2015-05-16 08:42:13 +00:00
|
|
|
|
(take a l,
|
|
|
|
|
assume IH,
|
2015-05-17 05:24:37 +00:00
|
|
|
|
by rewrite [*Prodl_cons, IH, *mul.assoc, mul.left_comm (Prodl l f)])
|
|
|
|
|
end comm_monoid
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-12-19 20:45:24 +00:00
|
|
|
|
/- Suml: sum indexed by a list -/
|
|
|
|
|
|
|
|
|
|
section add_monoid
|
2016-01-21 22:40:40 +00:00
|
|
|
|
variable [add_monoid B]
|
2015-12-19 20:45:24 +00:00
|
|
|
|
local attribute add_monoid.to_monoid [trans_instance]
|
|
|
|
|
|
|
|
|
|
definition Suml (l : list A) (f : A → B) : B := Prodl l f
|
|
|
|
|
|
|
|
|
|
-- ∑ x ← l, f x
|
2015-12-31 18:42:51 +00:00
|
|
|
|
notation `∑` binders `←` l `, ` r:(scoped f, Suml l f) := r
|
2015-12-19 20:45:24 +00:00
|
|
|
|
|
|
|
|
|
theorem Suml_nil (f : A → B) : Suml [] f = 0 := Prodl_nil f
|
|
|
|
|
theorem Suml_cons (f : A → B) (a : A) (l : list A) : Suml (a::l) f = f a + Suml l f :=
|
|
|
|
|
Prodl_cons f a l
|
|
|
|
|
theorem Suml_append (l₁ l₂ : list A) (f : A → B) : Suml (l₁++l₂) f = Suml l₁ f + Suml l₂ f :=
|
|
|
|
|
Prodl_append l₁ l₂ f
|
|
|
|
|
|
|
|
|
|
section deceqA
|
|
|
|
|
include deceqA
|
|
|
|
|
theorem Suml_insert_of_mem (f : A → B) {a : A} {l : list A} (H : a ∈ l) :
|
|
|
|
|
Suml (insert a l) f = Suml l f := Prodl_insert_of_mem f H
|
|
|
|
|
theorem Suml_insert_of_not_mem (f : A → B) {a : A} {l : list A} (H : a ∉ l) :
|
|
|
|
|
Suml (insert a l) f = f a + Suml l f := Prodl_insert_of_not_mem f H
|
|
|
|
|
theorem Suml_union {l₁ l₂ : list A} (f : A → B) (d : disjoint l₁ l₂) :
|
|
|
|
|
Suml (union l₁ l₂) f = Suml l₁ f + Suml l₂ f := Prodl_union f d
|
|
|
|
|
end deceqA
|
|
|
|
|
|
|
|
|
|
theorem Suml_zero (l : list A) : Suml l (λ x, 0) = (0:B) := Prodl_one l
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Suml_singleton (a : A) (f : A → B) : Suml [a] f = f a := Prodl_singleton a f
|
2015-12-19 20:45:24 +00:00
|
|
|
|
end add_monoid
|
|
|
|
|
|
|
|
|
|
section add_comm_monoid
|
|
|
|
|
variable [acmB : add_comm_monoid B]
|
|
|
|
|
include acmB
|
|
|
|
|
local attribute add_comm_monoid.to_comm_monoid [trans_instance]
|
|
|
|
|
|
|
|
|
|
theorem Suml_add (l : list A) (f g : A → B) : Suml l (λx, f x + g x) = Suml l f + Suml l g :=
|
|
|
|
|
Prodl_mul l f g
|
|
|
|
|
end add_comm_monoid
|
|
|
|
|
|
2015-12-19 19:10:20 +00:00
|
|
|
|
/-
|
|
|
|
|
-- finset versions
|
|
|
|
|
-/
|
|
|
|
|
|
2016-01-21 22:40:40 +00:00
|
|
|
|
/- Prod_semigroup : product indexed by a finset, with a default for the empty finset -/
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-08-08 00:53:30 +00:00
|
|
|
|
namespace finset
|
2016-01-21 22:40:40 +00:00
|
|
|
|
variable [comm_semigroup B]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem mulf_rcomm (f : A → B) : right_commutative (mulf f) :=
|
2016-03-03 03:48:05 +00:00
|
|
|
|
right_commutative_comp_right (@has_mul.mul B _) f (@mul.right_comm B _)
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2016-01-21 22:40:40 +00:00
|
|
|
|
namespace Prod_semigroup
|
|
|
|
|
open Prodl_semigroup
|
|
|
|
|
|
|
|
|
|
private theorem Prodl_semigroup_eq_Prodl_semigroup_of_perm
|
|
|
|
|
(dflt : B) (f : A → B) {l₁ l₂ : list A} (p : perm l₁ l₂) :
|
|
|
|
|
Prodl_semigroup dflt l₁ f = Prodl_semigroup dflt l₂ f :=
|
|
|
|
|
perm.induction_on p
|
|
|
|
|
rfl -- nil nil
|
|
|
|
|
(take x l₁ l₂ p ih,
|
|
|
|
|
by rewrite [*Prodl_semigroup_cons, perm.foldl_eq_of_perm (mulf_rcomm f) p])
|
|
|
|
|
(take x y l,
|
|
|
|
|
begin rewrite [*Prodl_semigroup_cons, *foldl_cons, ↑mulf, mul.comm] end)
|
|
|
|
|
(take l₁ l₂ l₃ p₁ p₂ ih₁ ih₂, eq.trans ih₁ ih₂)
|
|
|
|
|
|
|
|
|
|
definition Prod_semigroup (dflt : B) (s : finset A) (f : A → B) : B :=
|
|
|
|
|
quot.lift_on s
|
|
|
|
|
(λ l, Prodl_semigroup dflt (elt_of l) f)
|
|
|
|
|
(λ l₁ l₂ p, Prodl_semigroup_eq_Prodl_semigroup_of_perm dflt f p)
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_empty (dflt : B) (f : A → B) : Prod_semigroup dflt ∅ f = dflt := rfl
|
|
|
|
|
|
|
|
|
|
section deceqA
|
|
|
|
|
include deceqA
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_singleton (dflt : B) (f : A → B) (a : A) :
|
|
|
|
|
Prod_semigroup dflt '{a} f = f a := rfl
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_insert_insert (dflt : B) (f : A → B) {a₁ a₂ : A} {s : finset A} :
|
|
|
|
|
a₂ ∉ s → a₁ ∉ insert a₂ s →
|
|
|
|
|
Prod_semigroup dflt (insert a₁ (insert a₂ s)) f =
|
|
|
|
|
f a₁ * Prod_semigroup dflt (insert a₂ s) f :=
|
|
|
|
|
quot.induction_on s
|
|
|
|
|
(take l h₁ h₂, Prodl_semigroup_insert_insert_of_not_mem dflt f h₁ h₂)
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_insert (dflt : B) (f : A → B) {a : A} {s : finset A} (anins : a ∉ s)
|
|
|
|
|
(sne : s ≠ ∅) :
|
|
|
|
|
Prod_semigroup dflt (insert a s) f = f a * Prod_semigroup dflt s f :=
|
|
|
|
|
obtain a' (a's : a' ∈ s), from exists_mem_of_ne_empty sne,
|
|
|
|
|
have H : s = insert a' (erase a' s), from eq.symm (insert_erase a's),
|
2016-02-29 21:15:48 +00:00
|
|
|
|
begin
|
2016-01-21 22:40:40 +00:00
|
|
|
|
rewrite [H, Prod_semigroup_insert_insert dflt f !not_mem_erase (eq.subst H anins)]
|
|
|
|
|
end
|
|
|
|
|
end deceqA
|
|
|
|
|
end Prod_semigroup
|
|
|
|
|
end finset
|
|
|
|
|
|
|
|
|
|
/- Prod: product indexed by a finset -/
|
|
|
|
|
|
|
|
|
|
namespace finset
|
|
|
|
|
variable [comm_monoid B]
|
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prodl_eq_Prodl_of_perm (f : A → B) {l₁ l₂ : list A} :
|
|
|
|
|
perm l₁ l₂ → Prodl l₁ f = Prodl l₂ f :=
|
|
|
|
|
λ p, perm.foldl_eq_of_perm (mulf_rcomm f) p 1
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
definition Prod (s : finset A) (f : A → B) : B :=
|
2015-05-16 08:42:13 +00:00
|
|
|
|
quot.lift_on s
|
2015-05-17 05:24:37 +00:00
|
|
|
|
(λ l, Prodl (elt_of l) f)
|
|
|
|
|
(λ l₁ l₂ p, Prodl_eq_Prodl_of_perm f p)
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
|
|
|
|
-- ∏ x ∈ s, f x
|
2015-12-31 18:42:51 +00:00
|
|
|
|
notation `∏` binders `∈` s `, ` r:(scoped f, Prod s f) := r
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prod_empty (f : A → B) : Prod ∅ f = 1 :=
|
|
|
|
|
Prodl_nil f
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 06:00:38 +00:00
|
|
|
|
theorem Prod_mul (s : finset A) (f g : A → B) : Prod s (λx, f x * g x) = Prod s f * Prod s g :=
|
|
|
|
|
quot.induction_on s (take u, !Prodl_mul)
|
|
|
|
|
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Prod_one (s : finset A) : Prod s (λ x, 1) = (1:B) :=
|
|
|
|
|
quot.induction_on s (take u, !Prodl_one)
|
|
|
|
|
|
2015-05-17 06:00:38 +00:00
|
|
|
|
section deceqA
|
|
|
|
|
include deceqA
|
2015-05-16 12:26:59 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prod_insert_of_mem (f : A → B) {a : A} {s : finset A} :
|
|
|
|
|
a ∈ s → Prod (insert a s) f = Prod s f :=
|
2015-05-16 12:26:59 +00:00
|
|
|
|
quot.induction_on s
|
2015-05-17 05:24:37 +00:00
|
|
|
|
(λ l ainl, Prodl_insert_of_mem f ainl)
|
2015-05-16 12:26:59 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prod_insert_of_not_mem (f : A → B) {a : A} {s : finset A} :
|
|
|
|
|
a ∉ s → Prod (insert a s) f = f a * Prod s f :=
|
2015-05-16 12:26:59 +00:00
|
|
|
|
quot.induction_on s
|
2015-05-17 05:24:37 +00:00
|
|
|
|
(λ l nainl, Prodl_insert_of_not_mem f nainl)
|
2015-05-16 12:26:59 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Prod_union (f : A → B) {s₁ s₂ : finset A} (disj : s₁ ∩ s₂ = ∅) :
|
|
|
|
|
Prod (s₁ ∪ s₂) f = Prod s₁ f * Prod s₂ f :=
|
|
|
|
|
have H1 : disjoint s₁ s₂ → Prod (s₁ ∪ s₂) f = Prod s₁ f * Prod s₂ f, from
|
2015-05-16 12:26:59 +00:00
|
|
|
|
quot.induction_on₂ s₁ s₂
|
2015-05-17 05:24:37 +00:00
|
|
|
|
(λ l₁ l₂ d, Prodl_union f d),
|
2015-05-17 09:06:10 +00:00
|
|
|
|
H1 (disjoint_of_inter_eq_empty disj)
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 06:00:38 +00:00
|
|
|
|
theorem Prod_ext {s : finset A} {f g : A → B} :
|
|
|
|
|
(∀{x}, x ∈ s → f x = g x) → Prod s f = Prod s g :=
|
|
|
|
|
finset.induction_on s
|
|
|
|
|
(assume H, rfl)
|
2015-05-25 08:37:07 +00:00
|
|
|
|
(take x s', assume H1 : x ∉ s',
|
2015-05-17 06:00:38 +00:00
|
|
|
|
assume IH : (∀ {x : A}, x ∈ s' → f x = g x) → Prod s' f = Prod s' g,
|
|
|
|
|
assume H2 : ∀{y}, y ∈ insert x s' → f y = g y,
|
2016-02-29 19:47:33 +00:00
|
|
|
|
have H3 : ∀y, y ∈ s' → f y = g y, from
|
2015-05-17 06:00:38 +00:00
|
|
|
|
take y, assume H', H2 (mem_insert_of_mem _ H'),
|
2016-02-29 19:47:33 +00:00
|
|
|
|
have H4 : f x = g x, from H2 !mem_insert,
|
2015-05-17 06:00:38 +00:00
|
|
|
|
by rewrite [Prod_insert_of_not_mem f H1, Prod_insert_of_not_mem g H1, IH H3, H4])
|
2015-05-17 07:50:32 +00:00
|
|
|
|
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Prod_singleton (a : A) (f : A → B) : Prod '{a} f = f a :=
|
|
|
|
|
have a ∉ ∅, from not_mem_empty a,
|
2016-02-29 21:15:48 +00:00
|
|
|
|
by rewrite [Prod_insert_of_not_mem f this, Prod_empty, mul_one]
|
2015-12-31 18:42:51 +00:00
|
|
|
|
|
|
|
|
|
theorem Prod_image {C : Type} [deceqC : decidable_eq C] {s : finset A} (f : C → B) {g : A → C}
|
|
|
|
|
(H : set.inj_on g (to_set s)) :
|
|
|
|
|
(∏ j ∈ image g s, f j) = (∏ i ∈ s, f (g i)) :=
|
|
|
|
|
begin
|
|
|
|
|
induction s with a s anins ih,
|
|
|
|
|
{rewrite [*Prod_empty]},
|
|
|
|
|
have injg : set.inj_on g (to_set s),
|
|
|
|
|
from set.inj_on_of_inj_on_of_subset H (λ x, mem_insert_of_mem a),
|
2016-01-04 00:41:01 +00:00
|
|
|
|
have g a ∉ g ' s, from
|
|
|
|
|
suppose g a ∈ g ' s,
|
2015-12-31 18:42:51 +00:00
|
|
|
|
obtain b [(bs : b ∈ s) (gbeq : g b = g a)], from exists_of_mem_image this,
|
|
|
|
|
have aias : set.mem a (to_set (insert a s)),
|
|
|
|
|
by rewrite to_set_insert; apply set.mem_insert a s,
|
|
|
|
|
have bias : set.mem b (to_set (insert a s)),
|
|
|
|
|
by rewrite to_set_insert; apply set.mem_insert_of_mem; exact bs,
|
|
|
|
|
have b = a, from H bias aias gbeq,
|
|
|
|
|
show false, from anins (eq.subst this bs),
|
|
|
|
|
rewrite [image_insert, Prod_insert_of_not_mem _ this, Prod_insert_of_not_mem _ anins, ih injg]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
theorem Prod_eq_of_bij_on {C : Type} [deceqC : decidable_eq C] {s : finset A} {t : finset C}
|
|
|
|
|
(f : C → B) {g : A → C} (H : set.bij_on g (to_set s) (to_set t)) :
|
|
|
|
|
(∏ j ∈ t, f j) = (∏ i ∈ s, f (g i)) :=
|
2016-01-04 00:41:01 +00:00
|
|
|
|
have g ' s = t,
|
2015-12-31 18:42:51 +00:00
|
|
|
|
by apply eq_of_to_set_eq_to_set; rewrite to_set_image; exact set.image_eq_of_bij_on H,
|
|
|
|
|
using this, by rewrite [-this, Prod_image f (and.left (and.right H))]
|
|
|
|
|
end deceqA
|
2015-08-08 00:53:30 +00:00
|
|
|
|
end finset
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-12-19 20:45:24 +00:00
|
|
|
|
/- Sum: sum indexed by a finset -/
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-08-08 00:53:30 +00:00
|
|
|
|
namespace finset
|
2016-01-21 22:40:40 +00:00
|
|
|
|
variable [add_comm_monoid B]
|
2015-10-09 20:21:03 +00:00
|
|
|
|
local attribute add_comm_monoid.to_comm_monoid [trans_instance]
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
definition Sum (s : finset A) (f : A → B) : B := Prod s f
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
|
|
|
|
-- ∑ x ∈ s, f x
|
2015-12-31 18:42:51 +00:00
|
|
|
|
notation `∑` binders `∈` s `, ` r:(scoped f, Sum s f) := r
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Sum_empty (f : A → B) : Sum ∅ f = 0 := Prod_empty f
|
2015-05-17 06:00:38 +00:00
|
|
|
|
theorem Sum_add (s : finset A) (f g : A → B) :
|
|
|
|
|
Sum s (λx, f x + g x) = Sum s f + Sum s g := Prod_mul s f g
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Sum_zero (s : finset A) : Sum s (λ x, 0) = (0:B) := Prod_one s
|
2015-05-16 08:42:13 +00:00
|
|
|
|
|
2015-05-17 06:00:38 +00:00
|
|
|
|
section deceqA
|
|
|
|
|
include deceqA
|
2015-05-17 05:24:37 +00:00
|
|
|
|
theorem Sum_insert_of_mem (f : A → B) {a : A} {s : finset A} (H : a ∈ s) :
|
|
|
|
|
Sum (insert a s) f = Sum s f := Prod_insert_of_mem f H
|
|
|
|
|
theorem Sum_insert_of_not_mem (f : A → B) {a : A} {s : finset A} (H : a ∉ s) :
|
|
|
|
|
Sum (insert a s) f = f a + Sum s f := Prod_insert_of_not_mem f H
|
|
|
|
|
theorem Sum_union (f : A → B) {s₁ s₂ : finset A} (disj : s₁ ∩ s₂ = ∅) :
|
|
|
|
|
Sum (s₁ ∪ s₂) f = Sum s₁ f + Sum s₂ f := Prod_union f disj
|
2015-05-17 06:00:38 +00:00
|
|
|
|
theorem Sum_ext {s : finset A} {f g : A → B} (H : ∀x, x ∈ s → f x = g x) :
|
|
|
|
|
Sum s f = Sum s g := Prod_ext H
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Sum_singleton (a : A) (f : A → B) : Sum '{a} f = f a := Prod_singleton a f
|
|
|
|
|
|
|
|
|
|
theorem Sum_image {C : Type} [deceqC : decidable_eq C] {s : finset A} (f : C → B) {g : A → C}
|
|
|
|
|
(H : set.inj_on g (to_set s)) :
|
|
|
|
|
(∑ j ∈ image g s, f j) = (∑ i ∈ s, f (g i)) := Prod_image f H
|
|
|
|
|
theorem Sum_eq_of_bij_on {C : Type} [deceqC : decidable_eq C] {s : finset A} {t : finset C}
|
|
|
|
|
(f : C → B) {g : A → C} (H : set.bij_on g (to_set s) (to_set t)) :
|
|
|
|
|
(∑ j ∈ t, f j) = (∑ i ∈ s, f (g i)) := Prod_eq_of_bij_on f H
|
2015-05-17 06:00:38 +00:00
|
|
|
|
end deceqA
|
2015-08-08 00:53:30 +00:00
|
|
|
|
end finset
|
2015-12-19 19:10:20 +00:00
|
|
|
|
|
|
|
|
|
/-
|
|
|
|
|
-- set versions
|
|
|
|
|
-/
|
|
|
|
|
|
|
|
|
|
namespace set
|
|
|
|
|
open classical
|
|
|
|
|
|
|
|
|
|
/- Prod: product indexed by a set -/
|
|
|
|
|
|
|
|
|
|
section Prod
|
2016-01-21 22:40:40 +00:00
|
|
|
|
variable [comm_monoid B]
|
2015-12-19 19:10:20 +00:00
|
|
|
|
|
|
|
|
|
noncomputable definition Prod (s : set A) (f : A → B) : B := finset.Prod (to_finset s) f
|
|
|
|
|
|
|
|
|
|
-- ∏ x ∈ s, f x
|
2015-12-31 18:42:51 +00:00
|
|
|
|
notation `∏` binders `∈` s `, ` r:(scoped f, Prod s f) := r
|
2015-12-19 19:10:20 +00:00
|
|
|
|
|
|
|
|
|
theorem Prod_empty (f : A → B) : Prod ∅ f = 1 :=
|
|
|
|
|
by rewrite [↑Prod, to_finset_empty]
|
|
|
|
|
|
|
|
|
|
theorem Prod_of_not_finite {s : set A} (nfins : ¬ finite s) (f : A → B) : Prod s f = 1 :=
|
|
|
|
|
by rewrite [↑Prod, to_finset_of_not_finite nfins]
|
|
|
|
|
|
|
|
|
|
theorem Prod_mul (s : set A) (f g : A → B) : Prod s (λx, f x * g x) = Prod s f * Prod s g :=
|
|
|
|
|
by rewrite [↑Prod, finset.Prod_mul]
|
|
|
|
|
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Prod_one (s : set A) : Prod s (λ x, 1) = (1:B) :=
|
|
|
|
|
by rewrite [↑Prod, finset.Prod_one]
|
|
|
|
|
|
2015-12-19 19:10:20 +00:00
|
|
|
|
theorem Prod_insert_of_mem (f : A → B) {a : A} {s : set A} (H : a ∈ s) :
|
|
|
|
|
Prod (insert a s) f = Prod s f :=
|
|
|
|
|
by_cases
|
|
|
|
|
(suppose finite s,
|
2016-02-29 19:47:33 +00:00
|
|
|
|
have (#finset a ∈ set.to_finset s), by rewrite mem_to_finset_eq; apply H,
|
2015-12-19 19:10:20 +00:00
|
|
|
|
by rewrite [↑Prod, to_finset_insert, finset.Prod_insert_of_mem f this])
|
|
|
|
|
(assume nfs : ¬ finite s,
|
2016-02-29 19:47:33 +00:00
|
|
|
|
have ¬ finite (insert a s), from assume H, nfs (finite_of_finite_insert H),
|
2015-12-19 19:10:20 +00:00
|
|
|
|
by rewrite [Prod_of_not_finite nfs, Prod_of_not_finite this])
|
|
|
|
|
|
|
|
|
|
theorem Prod_insert_of_not_mem (f : A → B) {a : A} {s : set A} [finite s] (H : a ∉ s) :
|
|
|
|
|
Prod (insert a s) f = f a * Prod s f :=
|
2016-02-29 19:47:33 +00:00
|
|
|
|
have (#finset a ∉ set.to_finset s), by rewrite mem_to_finset_eq; apply H,
|
2015-12-19 19:10:20 +00:00
|
|
|
|
by rewrite [↑Prod, to_finset_insert, finset.Prod_insert_of_not_mem f this]
|
|
|
|
|
|
|
|
|
|
theorem Prod_union (f : A → B) {s₁ s₂ : set A} [finite s₁] [finite s₂]
|
|
|
|
|
(disj : s₁ ∩ s₂ = ∅) :
|
|
|
|
|
Prod (s₁ ∪ s₂) f = Prod s₁ f * Prod s₂ f :=
|
|
|
|
|
begin
|
|
|
|
|
rewrite [↑Prod, to_finset_union],
|
|
|
|
|
apply finset.Prod_union,
|
|
|
|
|
apply finset.eq_of_to_set_eq_to_set,
|
|
|
|
|
rewrite [finset.to_set_inter, *to_set_to_finset, finset.to_set_empty, disj]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
theorem Prod_ext {s : set A} {f g : A → B} (H : ∀{x}, x ∈ s → f x = g x) : Prod s f = Prod s g :=
|
|
|
|
|
by_cases
|
|
|
|
|
(suppose finite s,
|
|
|
|
|
by esimp [Prod]; apply finset.Prod_ext; intro x; rewrite [mem_to_finset_eq]; apply H)
|
|
|
|
|
(assume nfs : ¬ finite s,
|
|
|
|
|
by rewrite [*Prod_of_not_finite nfs])
|
|
|
|
|
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Prod_singleton (a : A) (f : A → B) : Prod '{a} f = f a :=
|
|
|
|
|
by rewrite [↑Prod, to_finset_insert, to_finset_empty, finset.Prod_singleton]
|
|
|
|
|
|
|
|
|
|
theorem Prod_image {C : Type} {s : set A} [fins : finite s] (f : C → B) {g : A → C}
|
|
|
|
|
(H : inj_on g s) :
|
|
|
|
|
(∏ j ∈ image g s, f j) = (∏ i ∈ s, f (g i)) :=
|
|
|
|
|
begin
|
|
|
|
|
have H' : inj_on g (finset.to_set (set.to_finset s)), by rewrite to_set_to_finset; exact H,
|
|
|
|
|
rewrite [↑Prod, to_finset_image g s, finset.Prod_image f H']
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
theorem Prod_eq_of_bij_on {C : Type} {s : set A} {t : set C} (f : C → B)
|
|
|
|
|
{g : A → C} (H : bij_on g s t) :
|
|
|
|
|
(∏ j ∈ t, f j) = (∏ i ∈ s, f (g i)) :=
|
|
|
|
|
by_cases
|
|
|
|
|
(suppose finite s,
|
2016-01-04 00:41:01 +00:00
|
|
|
|
have g ' s = t, from image_eq_of_bij_on H,
|
2015-12-31 18:42:51 +00:00
|
|
|
|
using this, by rewrite [-this, Prod_image f (and.left (and.right H))])
|
|
|
|
|
(assume nfins : ¬ finite s,
|
|
|
|
|
have nfint : ¬ finite t, from
|
|
|
|
|
suppose finite t,
|
|
|
|
|
have finite s, from finite_of_bij_on' H,
|
|
|
|
|
show false, from nfins this,
|
2016-02-29 21:15:48 +00:00
|
|
|
|
by rewrite [Prod_of_not_finite nfins, Prod_of_not_finite nfint])
|
2015-12-19 19:10:20 +00:00
|
|
|
|
end Prod
|
|
|
|
|
|
2015-12-19 20:45:24 +00:00
|
|
|
|
/- Sum: sum indexed by a set -/
|
2015-12-19 19:10:20 +00:00
|
|
|
|
|
|
|
|
|
section Sum
|
2016-01-21 22:40:40 +00:00
|
|
|
|
variable [add_comm_monoid B]
|
2015-12-19 19:10:20 +00:00
|
|
|
|
local attribute add_comm_monoid.to_comm_monoid [trans_instance]
|
|
|
|
|
|
|
|
|
|
noncomputable definition Sum (s : set A) (f : A → B) : B := Prod s f
|
|
|
|
|
|
2015-12-19 20:45:24 +00:00
|
|
|
|
proposition Sum_def (s : set A) (f : A → B) : Sum s f = finset.Sum (to_finset s) f := rfl
|
|
|
|
|
|
2015-12-19 19:10:20 +00:00
|
|
|
|
-- ∑ x ∈ s, f x
|
2015-12-31 18:42:51 +00:00
|
|
|
|
notation `∑` binders `∈` s `, ` r:(scoped f, Sum s f) := r
|
2015-12-19 19:10:20 +00:00
|
|
|
|
|
|
|
|
|
theorem Sum_empty (f : A → B) : Sum ∅ f = 0 := Prod_empty f
|
|
|
|
|
theorem Sum_of_not_finite {s : set A} (nfins : ¬ finite s) (f : A → B) : Sum s f = 0 :=
|
|
|
|
|
Prod_of_not_finite nfins f
|
|
|
|
|
theorem Sum_add (s : set A) (f g : A → B) :
|
|
|
|
|
Sum s (λx, f x + g x) = Sum s f + Sum s g := Prod_mul s f g
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Sum_zero (s : set A) : Sum s (λ x, 0) = (0:B) := Prod_one s
|
2015-12-19 19:10:20 +00:00
|
|
|
|
|
|
|
|
|
theorem Sum_insert_of_mem (f : A → B) {a : A} {s : set A} (H : a ∈ s) :
|
|
|
|
|
Sum (insert a s) f = Sum s f := Prod_insert_of_mem f H
|
|
|
|
|
theorem Sum_insert_of_not_mem (f : A → B) {a : A} {s : set A} [finite s] (H : a ∉ s) :
|
|
|
|
|
Sum (insert a s) f = f a + Sum s f := Prod_insert_of_not_mem f H
|
|
|
|
|
theorem Sum_union (f : A → B) {s₁ s₂ : set A} [finite s₁] [finite s₂]
|
|
|
|
|
(disj : s₁ ∩ s₂ = ∅) :
|
|
|
|
|
Sum (s₁ ∪ s₂) f = Sum s₁ f + Sum s₂ f := Prod_union f disj
|
|
|
|
|
theorem Sum_ext {s : set A} {f g : A → B} (H : ∀x, x ∈ s → f x = g x) :
|
|
|
|
|
Sum s f = Sum s g := Prod_ext H
|
|
|
|
|
|
2015-12-31 18:42:51 +00:00
|
|
|
|
theorem Sum_singleton (a : A) (f : A → B) : Sum '{a} f = f a :=
|
|
|
|
|
Prod_singleton a f
|
|
|
|
|
|
|
|
|
|
theorem Sum_image {C : Type} {s : set A} [fins : finite s] (f : C → B) {g : A → C}
|
|
|
|
|
(H : inj_on g s) :
|
|
|
|
|
(∑ j ∈ image g s, f j) = (∑ i ∈ s, f (g i)) := Prod_image f H
|
|
|
|
|
theorem Sum_eq_of_bij_on {C : Type} {s : set A} {t : set C} (f : C → B) {g : A → C}
|
|
|
|
|
(H : bij_on g s t) :
|
|
|
|
|
(∑ j ∈ t, f j) = (∑ i ∈ s, f (g i)) := Prod_eq_of_bij_on f H
|
2015-12-19 19:10:20 +00:00
|
|
|
|
end Sum
|
|
|
|
|
|
2016-01-21 22:40:40 +00:00
|
|
|
|
/- Prod_semigroup : product indexed by a set, with a default for the empty set -/
|
|
|
|
|
|
|
|
|
|
namespace Prod_semigroup
|
|
|
|
|
variable [comm_semigroup B]
|
|
|
|
|
|
|
|
|
|
noncomputable definition Prod_semigroup (dflt : B) (s : set A) (f : A → B) : B :=
|
|
|
|
|
finset.Prod_semigroup.Prod_semigroup dflt (to_finset s) f
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_empty (dflt : B) (f : A → B) : Prod_semigroup dflt ∅ f = dflt :=
|
|
|
|
|
by rewrite [↑Prod_semigroup, to_finset_empty]
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_of_not_finite (dflt : B) {s : set A} (nfins : ¬ finite s) (f : A → B) :
|
|
|
|
|
Prod_semigroup dflt s f = dflt :=
|
|
|
|
|
by rewrite [↑Prod_semigroup, to_finset_of_not_finite nfins]
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_singleton (dflt : B) (f : A → B) (a : A) :
|
|
|
|
|
Prod_semigroup dflt ('{a}) f = f a :=
|
|
|
|
|
by rewrite [↑Prod_semigroup, to_finset_insert, to_finset_empty,
|
|
|
|
|
finset.Prod_semigroup.Prod_semigroup_singleton dflt f a]
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_insert_insert (dflt : B) (f : A → B) {a₁ a₂ : A} {s : set A}
|
|
|
|
|
[h : finite s] :
|
|
|
|
|
a₂ ∉ s → a₁ ∉ insert a₂ s →
|
|
|
|
|
Prod_semigroup dflt (insert a₁ (insert a₂ s)) f =
|
|
|
|
|
f a₁ * Prod_semigroup dflt (insert a₂ s) f :=
|
|
|
|
|
begin
|
|
|
|
|
rewrite [↑Prod_semigroup, -+mem_to_finset_eq, +to_finset_insert],
|
|
|
|
|
intro h1 h2,
|
|
|
|
|
apply finset.Prod_semigroup.Prod_semigroup_insert_insert dflt f h1 h2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
theorem Prod_semigroup_insert (dflt : B) (f : A → B) {a : A} {s : set A} [h : finite s] :
|
|
|
|
|
a ∉ s → s ≠ ∅ → Prod_semigroup dflt (insert a s) f = f a * Prod_semigroup dflt s f :=
|
|
|
|
|
begin
|
|
|
|
|
rewrite [↑Prod_semigroup, -mem_to_finset_eq, +to_finset_insert, -finset.to_set_empty],
|
|
|
|
|
intro h1 h2,
|
|
|
|
|
apply finset.Prod_semigroup.Prod_semigroup_insert dflt f h1,
|
|
|
|
|
intro h3, revert h2, rewrite [-h3, to_set_to_finset],
|
|
|
|
|
intro h4, exact (h4 rfl)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end Prod_semigroup
|
|
|
|
|
|
2015-12-19 19:10:20 +00:00
|
|
|
|
end set
|