Skip to content

Commit

Permalink
feat(algebra/big_operators/basic): prod_subsingleton (#8423)
Browse files Browse the repository at this point in the history
  • Loading branch information
pechersky committed Aug 16, 2021
1 parent e195347 commit f8241b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/algebra/big_operators/basic.lean
Expand Up @@ -1286,6 +1286,18 @@ end

end comm_group_with_zero

@[to_additive]
lemma prod_unique_nonempty {α β : Type*} [comm_monoid β] [unique α]
(s : finset α) (f : α → β) (h : s.nonempty) :
(∏ x in s, f x) = f (default α) :=
begin
obtain ⟨a, ha⟩ := h,
have : s = {a},
{ ext b,
simpa [subsingleton.elim a b] using ha },
rw [this, finset.prod_singleton, subsingleton.elim a (default α)]
end

end finset

namespace fintype
Expand Down Expand Up @@ -1329,6 +1341,19 @@ lemma prod_finset_coe [comm_monoid β] :
∏ (i : (s : set α)), f i = ∏ i in s, f i :=
(finset.prod_subtype s (λ _, iff.rfl) f).symm

@[to_additive]
lemma prod_unique {α β : Type*} [comm_monoid β] [unique α] (f : α → β) :
(∏ x : α, f x) = f (default α) :=
by rw [univ_unique, prod_singleton]

@[to_additive]
lemma prod_subsingleton {α β : Type*} [comm_monoid β] [subsingleton α] (f : α → β) (a : α) :
(∏ x : α, f x) = f a :=
begin
haveI : unique α := unique_of_subsingleton a,
convert prod_unique f
end

end fintype

namespace list
Expand Down
8 changes: 8 additions & 0 deletions src/algebra/group/units.lean
Expand Up @@ -33,6 +33,14 @@ structure add_units (α : Type u) [add_monoid α] :=

attribute [to_additive add_units] units

section has_elem

@[to_additive] lemma unique_has_one {α : Type*} [unique α] [has_one α] :
default α = 1 :=
unique.default_eq 1

end has_elem

namespace units

variables [monoid α]
Expand Down
5 changes: 0 additions & 5 deletions src/data/fintype/card.lean
Expand Up @@ -71,11 +71,6 @@ begin
exact λ hc, (hc (finset.mem_univ _)).elim
end

@[to_additive]
lemma prod_unique [unique β] (f : β → M) :
(∏ x, f x) = f (default β) :=
by simp only [finset.prod_singleton, univ_unique]

/-- If a product of a `finset` of a subsingleton type has a given
value, so do the terms in that product. -/
@[to_additive "If a sum of a `finset` of a subsingleton type has a given
Expand Down

0 comments on commit f8241b7

Please sign in to comment.