This repository was archived by the owner on Jun 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathring_bigops.lean
More file actions
183 lines (155 loc) · 5.91 KB
/
Copy pathring_bigops.lean
File metadata and controls
183 lines (155 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Properties of finite sums and products in various structures, including ordered rings and fields.
There are two versions of every theorem: one for finsets, and one for finite sets.
-/
import .group_bigops .ordered_field
variables {A B : Type}
variable [deceqA : decidable_eq A]
/-
-- finset versions
-/
namespace finset
section comm_semiring
variable [csB : comm_semiring B]
include deceqA csB
proposition mul_Sum (f : A → B) {s : finset A} (b : B) :
b * (∑ x ∈ s, f x) = ∑ x ∈ s, b * f x :=
begin
induction s with a s ans ih,
{rewrite [+Sum_empty, mul_zero]},
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem (λ x, b * f x) ans],
rewrite [-ih, left_distrib]
end
proposition Sum_mul (f : A → B) {s : finset A} (b : B) :
(∑ x ∈ s, f x) * b = ∑ x ∈ s, f x * b :=
by rewrite [mul.comm _ b, mul_Sum]; apply Sum_ext; intros; apply mul.comm
proposition Prod_eq_zero (f : A → B) {s : finset A} {a : A} (H : a ∈ s) (fa0 : f a = 0) :
(∏ x ∈ s, f x) = 0 :=
begin
induction s with b s bns ih,
{exact absurd H !not_mem_empty},
rewrite [Prod_insert_of_not_mem f bns],
have a = b ∨ a ∈ s, from eq_or_mem_of_mem_insert H,
cases this with aeqb ains,
{rewrite [-aeqb, fa0, zero_mul]},
rewrite [ih ains, mul_zero]
end
end comm_semiring
section ordered_comm_group
variable [ocgB : ordered_comm_group B]
include deceqA ocgB
proposition Sum_le_Sum (f g : A → B) {s : finset A} (H: ∀ x, x ∈ s → f x ≤ g x) :
(∑ x ∈ s, f x) ≤ (∑ x ∈ s, g x) :=
begin
induction s with a s ans ih,
{exact le.refl _},
have H1 : f a ≤ g a, from H _ !mem_insert,
have H2 : (∑ x ∈ s, f x) ≤ (∑ x ∈ s, g x), from ih (forall_of_forall_insert H),
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem g ans],
apply add_le_add H1 H2
end
proposition Sum_nonneg (f : A → B) {s : finset A} (H : ∀x, x ∈ s → f x ≥ 0) :
(∑ x ∈ s, f x) ≥ 0 :=
calc
0 = (∑ x ∈ s, 0) : Sum_zero
... ≤ (∑ x ∈ s, f x) : Sum_le_Sum (λ x, 0) f H
proposition Sum_nonpos (f : A → B) {s : finset A} (H : ∀x, x ∈ s → f x ≤ 0) :
(∑ x ∈ s, f x) ≤ 0 :=
calc
0 = (∑ x ∈ s, 0) : Sum_zero
... ≥ (∑ x ∈ s, f x) : Sum_le_Sum f (λ x, 0) H
end ordered_comm_group
section decidable_linear_ordered_comm_group
variable [dloocgB : decidable_linear_ordered_comm_group B]
include deceqA dloocgB
proposition abs_Sum_le (f : A → B) (s : finset A) : abs (∑ x ∈ s, f x) ≤ (∑ x ∈ s, abs (f x)) :=
begin
induction s with a s ans ih,
{rewrite [+Sum_empty, abs_zero]},
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem _ ans],
apply le.trans,
apply abs_add_le_abs_add_abs,
apply add_le_add_left ih
end
end decidable_linear_ordered_comm_group
end finset
/-
-- set versions
-/
namespace set
open classical
section comm_semiring
variable [csB : comm_semiring B]
include csB
proposition mul_Sum (f : A → B) {s : set A} (b : B) :
b * (∑ x ∈ s, f x) = ∑ x ∈ s, b * f x :=
begin
cases (em (finite s)) with fins nfins,
rotate 1,
{rewrite [+Sum_of_not_finite nfins, mul_zero]},
induction fins with a s fins ans ih,
{rewrite [+Sum_empty, mul_zero]},
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem (λ x, b * f x) ans],
rewrite [-ih, left_distrib]
end
proposition Sum_mul (f : A → B) {s : set A} (b : B) :
(∑ x ∈ s, f x) * b = ∑ x ∈ s, f x * b :=
by rewrite [mul.comm _ b, mul_Sum]; apply Sum_ext; intros; apply mul.comm
proposition Prod_eq_zero (f : A → B) {s : set A} [fins : finite s] {a : A} (H : a ∈ s) (fa0 : f a = 0) :
(∏ x ∈ s, f x) = 0 :=
begin
induction fins with b s fins bns ih,
{exact absurd H !not_mem_empty},
rewrite [Prod_insert_of_not_mem f bns],
have a = b ∨ a ∈ s, from eq_or_mem_of_mem_insert H,
cases this with aeqb ains,
{rewrite [-aeqb, fa0, zero_mul]},
rewrite [ih ains, mul_zero]
end
end comm_semiring
section ordered_comm_group
variable [ocgB : ordered_comm_group B]
include ocgB
proposition Sum_le_Sum (f g : A → B) {s : set A} (H: ∀₀ x ∈ s, f x ≤ g x) :
(∑ x ∈ s, f x) ≤ (∑ x ∈ s, g x) :=
begin
cases (em (finite s)) with fins nfins,
{induction fins with a s fins ans ih,
{rewrite +Sum_empty},
{rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem g ans],
have H1 : f a ≤ g a, from H !mem_insert,
have H2 : (∑ x ∈ s, f x) ≤ (∑ x ∈ s, g x), from ih (forall_of_forall_insert H),
apply add_le_add H1 H2}},
rewrite [+Sum_of_not_finite nfins]
end
proposition Sum_nonneg (f : A → B) {s : set A} (H : ∀₀ x ∈ s, f x ≥ 0) :
(∑ x ∈ s, f x) ≥ 0 :=
calc
0 = (∑ x ∈ s, 0) : Sum_zero
... ≤ (∑ x ∈ s, f x) : Sum_le_Sum (λ x, 0) f H
proposition Sum_nonpos (f : A → B) {s : set A} (H : ∀₀ x ∈ s, f x ≤ 0) :
(∑ x ∈ s, f x) ≤ 0 :=
calc
0 = (∑ x ∈ s, 0) : Sum_zero
... ≥ (∑ x ∈ s, f x) : Sum_le_Sum f (λ x, 0) H
end ordered_comm_group
section decidable_linear_ordered_comm_group
variable [dloocgB : decidable_linear_ordered_comm_group B]
include deceqA dloocgB
proposition abs_Sum_le (f : A → B) (s : set A) : abs (∑ x ∈ s, f x) ≤ (∑ x ∈ s, abs (f x)) :=
begin
cases (em (finite s)) with fins nfins,
rotate 1,
{rewrite [+Sum_of_not_finite nfins, abs_zero]},
induction fins with a s fins ans ih,
{rewrite [+Sum_empty, abs_zero]},
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem _ ans],
apply le.trans,
apply abs_add_le_abs_add_abs,
apply add_le_add_left ih
end
end decidable_linear_ordered_comm_group
end set