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

Commit 7368d71

Browse files
committed
chore(number_theory/arithmetic_function): Define in terms of zero_hom (#4606)
No need to write these proofs in two places
1 parent b1c1033 commit 7368d71

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/number_theory/arithmetic_function.lean

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ variable (R : Type*)
4242
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
4343
often instead defined as functions from `ℕ+`. Multiplication on `arithmetic_functions` is by
4444
Dirichlet convolution. -/
45-
structure arithmetic_function [has_zero R] :=
46-
(to_fun : ℕ → R)
47-
(map_zero' : to_fun 0 = 0)
45+
@[derive [has_coe_to_fun, has_zero, inhabited]]
46+
def arithmetic_function [has_zero R] := zero_hom ℕ R
4847

4948
variable {R}
5049

@@ -53,35 +52,24 @@ namespace arithmetic_function
5352
section has_zero
5453
variable [has_zero R]
5554

56-
instance : has_coe_to_fun (arithmetic_function R) := ⟨λ _, ℕ → R, to_fun⟩
57-
5855
@[simp] lemma to_fun_eq (f : arithmetic_function R) : f.to_fun = f := rfl
5956

6057
@[simp]
61-
lemma map_zero {f : arithmetic_function R} : f 0 = 0 := f.map_zero'
58+
lemma map_zero {f : arithmetic_function R} : f 0 = 0 :=
59+
zero_hom.map_zero' f
6260

6361
theorem coe_inj {f g : arithmetic_function R} : (f : ℕ → R) = g ↔ f = g :=
64-
begin
65-
split; intro h,
66-
{ cases f,
67-
cases g,
68-
cases h,
69-
refl },
70-
{ rw h }
71-
end
72-
73-
instance : has_zero (arithmetic_function R) := ⟨⟨λ _, 0, rfl⟩⟩
62+
⟨λ h, zero_hom.coe_inj h, λ h, h ▸ rfl⟩
7463

7564
@[simp]
76-
lemma zero_apply {x : ℕ} : (0 : arithmetic_function R) x = 0 := rfl
77-
78-
instance : inhabited (arithmetic_function R) := ⟨0
65+
lemma zero_apply {x : ℕ} : (0 : arithmetic_function R) x = 0 :=
66+
zero_hom.zero_apply x
7967

8068
@[ext] theorem ext ⦃f g : arithmetic_function R⦄ (h : ∀ x, f x = g x) : f = g :=
81-
coe_inj.1 (funext h)
69+
zero_hom.ext h
8270

8371
theorem ext_iff {f g : arithmetic_function R} : f = g ↔ ∀ x, f x = g x :=
84-
⟨λ h x, h ▸ rfl, λ h, ext h⟩
72+
zero_hom.ext_iff
8573

8674
section has_one
8775
variable [has_one R]
@@ -129,7 +117,7 @@ instance : add_monoid (arithmetic_function R) :=
129117
{ add_assoc := λ _ _ _, ext (λ _, add_assoc _ _ _),
130118
zero_add := λ _, ext (λ _, zero_add _),
131119
add_zero := λ _, ext (λ _, add_zero _),
132-
.. arithmetic_function.has_zero,
120+
.. arithmetic_function.has_zero R,
133121
.. arithmetic_function.has_add }
134122

135123
end add_monoid
@@ -224,7 +212,7 @@ instance : semiring (arithmetic_function R) :=
224212
mul_zero := λ f, by { ext, simp, },
225213
left_distrib := λ a b c, by { ext, simp [← sum_add_distrib, mul_add] },
226214
right_distrib := λ a b c, by { ext, simp [← sum_add_distrib, add_mul] },
227-
.. arithmetic_function.has_zero,
215+
.. arithmetic_function.has_zero R,
228216
.. arithmetic_function.has_mul,
229217
.. arithmetic_function.has_add,
230218
.. arithmetic_function.add_comm_monoid,

0 commit comments

Comments
 (0)