Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 11ba687

Browse files
committed
chore(algebra/big_operators): use proper *_with_zero class in prod_eq_zero(_iff) (#3303)
Also add a missing instance `comm_semiring → comm_monoid_with_zero`.
1 parent 12c2acb commit 11ba687

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/algebra/big_operators.lean

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,11 +1111,6 @@ calc (∑ x in s, f x) / b = ∑ x in s, f x * (1 / b) : by rw [div_eq_mul_one_d
11111111
section comm_semiring
11121112
variables [comm_semiring β]
11131113

1114-
lemma prod_eq_zero (ha : a ∈ s) (h : f a = 0) : (∏ x in s, f x) = 0 :=
1115-
by haveI := classical.dec_eq α;
1116-
calc (∏ x in s, f x) = ∏ x in insert a (erase s a), f x : by rw insert_erase ha
1117-
... = 0 : by rw [prod_insert (not_mem_erase _ _), h, zero_mul]
1118-
11191114
/-- The product over a sum can be written as a sum over the product of sets, `finset.pi`.
11201115
`finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/
11211116
lemma prod_sum {δ : α → Type*} [decidable_eq α] [∀a, decidable_eq (δ a)]
@@ -1205,8 +1200,15 @@ end
12051200

12061201
end comm_semiring
12071202

1208-
section integral_domain /- add integral_semi_domain to support nat and ennreal -/
1209-
variables [integral_domain β]
1203+
section prod_eq_zero
1204+
variables [comm_monoid_with_zero β]
1205+
1206+
lemma prod_eq_zero (ha : a ∈ s) (h : f a = 0) : (∏ x in s, f x) = 0 :=
1207+
by haveI := classical.dec_eq α;
1208+
calc (∏ x in s, f x) = ∏ x in insert a (erase s a), f x : by rw insert_erase ha
1209+
... = 0 : by rw [prod_insert (not_mem_erase _ _), h, zero_mul]
1210+
1211+
variables [nontrivial β] [no_zero_divisors β]
12101212

12111213
lemma prod_eq_zero_iff : (∏ x in s, f x) = 0 ↔ (∃a∈s, f a = 0) :=
12121214
begin
@@ -1220,7 +1222,7 @@ end
12201222
theorem prod_ne_zero_iff : (∏ x in s, f x) ≠ 0 ↔ (∀ a ∈ s, f a ≠ 0) :=
12211223
by { rw [ne, prod_eq_zero_iff], push_neg }
12221224

1223-
end integral_domain
1225+
end prod_eq_zero
12241226

12251227
section ordered_add_comm_monoid
12261228
variables [ordered_add_comm_monoid β]

src/algebra/ring.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ instance comm_semiring.to_comm_monoid_with_zero [comm_semiring α] : comm_monoid
338338
section comm_semiring
339339
variables [comm_semiring α] [comm_semiring β] {a b c : α}
340340

341+
instance comm_semiring.comm_monoid_with_zero : comm_monoid_with_zero α :=
342+
{ .. (‹_› : comm_semiring α) }
343+
341344
/-- Pullback a `semiring` instance along an injective function. -/
342345
protected def function.injective.comm_semiring [has_zero γ] [has_one γ] [has_add γ] [has_mul γ]
343346
(f : γ → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)

src/data/support.lean

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ lemma nmem_support [has_zero A] {f : α → A} {x : α} :
2727
x ∉ support f ↔ f x = 0 :=
2828
classical.not_not
2929

30+
lemma mem_support [has_zero A] {f : α → A} {x : α} :
31+
x ∈ support f ↔ f x ≠ 0 :=
32+
iff.rfl
33+
3034
lemma support_binop_subset [has_zero A] (op : A → A → A) (op0 : op 0 0 = 0) (f g : α → A) :
3135
support (λ x, op (f x) (g x)) ⊆ support f ∪ support g :=
3236
λ x hx, classical.by_cases
@@ -98,10 +102,14 @@ begin
98102
exact finset.sum_eq_zero hx
99103
end
100104

101-
-- TODO: Drop `classical` once #2332 is merged
102-
lemma support_prod [integral_domain A] (s : finset α) (f : α → β → A) :
105+
lemma support_prod_subset [comm_monoid_with_zero A] (s : finset α) (f : α → β → A) :
106+
support (λ x, ∏ i in s, f i x) ⊆ ⋂ i ∈ s, support (f i) :=
107+
λ x hx, mem_bInter_iff.2 $ λ i hi H, hx $ finset.prod_eq_zero hi H
108+
109+
lemma support_prod [comm_monoid_with_zero A] [no_zero_divisors A] [nontrivial A]
110+
(s : finset α) (f : α → β → A) :
103111
support (λ x, ∏ i in s, f i x) = ⋂ i ∈ s, support (f i) :=
104-
set.ext $ λ x, by classical;
112+
set.ext $ λ x, by
105113
simp only [support, ne.def, finset.prod_eq_zero_iff, mem_set_of_eq, set.mem_Inter, not_exists]
106114

107115
lemma support_comp [has_zero A] [has_zero B] (g : A → B) (hg : g 0 = 0) (f : α → A) :

0 commit comments

Comments
 (0)