@@ -42,9 +42,8 @@ variable (R : Type*)
42
42
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
43
43
often instead defined as functions from `ℕ+`. Multiplication on `arithmetic_functions` is by
44
44
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
48
47
49
48
variable {R}
50
49
@@ -53,35 +52,24 @@ namespace arithmetic_function
53
52
section has_zero
54
53
variable [has_zero R]
55
54
56
- instance : has_coe_to_fun (arithmetic_function R) := ⟨λ _, ℕ → R, to_fun⟩
57
-
58
55
@[simp] lemma to_fun_eq (f : arithmetic_function R) : f.to_fun = f := rfl
59
56
60
57
@[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
62
60
63
61
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⟩
74
63
75
64
@[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
79
67
80
68
@[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
82
70
83
71
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
85
73
86
74
section has_one
87
75
variable [has_one R]
@@ -129,7 +117,7 @@ instance : add_monoid (arithmetic_function R) :=
129
117
{ add_assoc := λ _ _ _, ext (λ _, add_assoc _ _ _),
130
118
zero_add := λ _, ext (λ _, zero_add _),
131
119
add_zero := λ _, ext (λ _, add_zero _),
132
- .. arithmetic_function.has_zero,
120
+ .. arithmetic_function.has_zero R ,
133
121
.. arithmetic_function.has_add }
134
122
135
123
end add_monoid
@@ -224,7 +212,7 @@ instance : semiring (arithmetic_function R) :=
224
212
mul_zero := λ f, by { ext, simp, },
225
213
left_distrib := λ a b c, by { ext, simp [← sum_add_distrib, mul_add] },
226
214
right_distrib := λ a b c, by { ext, simp [← sum_add_distrib, add_mul] },
227
- .. arithmetic_function.has_zero,
215
+ .. arithmetic_function.has_zero R ,
228
216
.. arithmetic_function.has_mul,
229
217
.. arithmetic_function.has_add,
230
218
.. arithmetic_function.add_comm_monoid,
0 commit comments