@@ -176,6 +176,9 @@ corresponding to the evaluation of the induced map `free_abelian_group X → A`
176
176
def lift_add_group_hom {α} (β) [add_comm_group β] (a : free_abelian_group α) : (α → β) →+ β :=
177
177
add_monoid_hom.mk' (λ f, lift f a) (lift.add' a)
178
178
179
+ lemma lift_neg' {β} [add_comm_group β] (f : α → β) : lift (-f) = -lift f :=
180
+ add_monoid_hom.ext $ λ _, (lift_add_group_hom _ _ : (α → β) →+ β).map_neg _
181
+
179
182
section monad
180
183
181
184
variables {β : Type u}
@@ -197,17 +200,17 @@ free_abelian_group.induction_on z C0 C1 Cn Cp
197
200
@[simp] lemma map_pure (f : α → β) (x : α) : f <$> (pure x : free_abelian_group α) = pure (f x) :=
198
201
rfl
199
202
200
- @[simp] lemma map_zero (f : α → β) : f <$> (0 : free_abelian_group α) = 0 :=
203
+ @[simp] protected lemma map_zero (f : α → β) : f <$> (0 : free_abelian_group α) = 0 :=
201
204
(lift (of ∘ f)).map_zero
202
205
203
- @[simp] lemma map_add (f : α → β) (x y : free_abelian_group α) :
206
+ @[simp] protected lemma map_add (f : α → β) (x y : free_abelian_group α) :
204
207
f <$> (x + y) = f <$> x + f <$> y :=
205
208
(lift _).map_add _ _
206
209
207
- @[simp] lemma map_neg (f : α → β) (x : free_abelian_group α) : f <$> (-x) = -(f <$> x) :=
210
+ @[simp] protected lemma map_neg (f : α → β) (x : free_abelian_group α) : f <$> (-x) = -(f <$> x) :=
208
211
(lift _).map_neg _
209
212
210
- @[simp] lemma map_sub (f : α → β) (x y : free_abelian_group α) :
213
+ @[simp] protected lemma map_sub (f : α → β) (x y : free_abelian_group α) :
211
214
f <$> (x - y) = f <$> x - f <$> y :=
212
215
(lift _).map_sub _ _
213
216
@@ -255,7 +258,7 @@ def seq_add_group_hom (f : free_abelian_group (α → β)) :
255
258
free_abelian_group α →+ free_abelian_group β :=
256
259
add_monoid_hom.mk' ((<*>) f)
257
260
(λ x y, show lift (<$> (x+y)) _ = _,
258
- by { simp only [map_add], exact lift.add' f _ _, })
261
+ by { simp only [free_abelian_group. map_add], exact lift.add' f _ _, })
259
262
260
263
@[simp] lemma seq_zero (f : free_abelian_group (α → β)) : f <*> 0 = 0 :=
261
264
(seq_add_group_hom f).map_zero
@@ -273,8 +276,9 @@ add_monoid_hom.mk' ((<*>) f)
273
276
(seq_add_group_hom f).map_sub x y
274
277
275
278
instance : is_lawful_monad free_abelian_group.{u} :=
276
- { id_map := λ α x, free_abelian_group.induction_on' x (map_zero id) (λ x, map_pure id x)
277
- (λ x ih, by rw [map_neg, ih]) (λ x y ihx ihy, by rw [map_add, ihx, ihy]),
279
+ { id_map := λ α x, free_abelian_group.induction_on' x (free_abelian_group.map_zero id)
280
+ (map_pure id) (λ x ih, by rw [free_abelian_group.map_neg, ih])
281
+ (λ x y ihx ihy, by rw [free_abelian_group.map_add, ihx, ihy]),
278
282
pure_bind := λ α β x f, pure_bind f x,
279
283
bind_assoc := λ α β γ x f g, free_abelian_group.induction_on' x
280
284
(by iterate 3 { rw zero_bind }) (λ x, by iterate 2 { rw pure_bind })
@@ -283,14 +287,15 @@ instance : is_lawful_monad free_abelian_group.{u} :=
283
287
284
288
instance : is_comm_applicative free_abelian_group.{u} :=
285
289
{ commutative_prod := λ α β x y, free_abelian_group.induction_on' x
286
- (by rw [map_zero, zero_seq, seq_zero])
290
+ (by rw [free_abelian_group. map_zero, zero_seq, seq_zero])
287
291
(λ p, by rw [map_pure, pure_seq]; exact free_abelian_group.induction_on' y
288
- (by rw [map_zero, map_zero, zero_seq])
292
+ (by rw [free_abelian_group. map_zero, free_abelian_group. map_zero, zero_seq])
289
293
(λ q, by rw [map_pure, map_pure, pure_seq, map_pure])
290
- (λ q ih, by rw [map_neg, map_neg, neg_seq, ih])
291
- (λ y₁ y₂ ih1 ih2, by rw [map_add, map_add, add_seq, ih1, ih2]))
292
- (λ p ih, by rw [map_neg, neg_seq, seq_neg, ih])
293
- (λ x₁ x₂ ih1 ih2, by rw [map_add, add_seq, seq_add, ih1, ih2]) }
294
+ (λ q ih, by rw [free_abelian_group.map_neg, free_abelian_group.map_neg, neg_seq, ih])
295
+ (λ y₁ y₂ ih1 ih2,
296
+ by rw [free_abelian_group.map_add, free_abelian_group.map_add, add_seq, ih1, ih2]))
297
+ (λ p ih, by rw [free_abelian_group.map_neg, neg_seq, seq_neg, ih])
298
+ (λ x₁ x₂ ih1 ih2, by rw [free_abelian_group.map_add, add_seq, seq_add, ih1, ih2]) }
294
299
295
300
296
301
end monad
@@ -332,67 +337,74 @@ lemma map_comp_apply {f : α → β} {g : β → γ} (x : free_abelian_group α)
332
337
333
338
variable (α)
334
339
335
- section monoid
336
-
337
- variables {R : Type *} [monoid α] [ring R]
340
+ section has_mul
341
+ variables [has_mul α]
338
342
339
- instance : semigroup (free_abelian_group α) :=
340
- { mul := λ x, lift $ λ x₂, lift (λ x₁, of $ x₁ * x₂) x,
341
- mul_assoc := λ x y z, begin
342
- unfold has_mul.mul,
343
- refine free_abelian_group.induction_on z (by simp) _ _ _,
344
- { intros L3, rw [lift.of, lift.of],
345
- refine free_abelian_group.induction_on y (by simp) _ _ _,
346
- { intros L2, iterate 3 { rw lift.of },
347
- refine free_abelian_group.induction_on x (by simp) _ _ _,
348
- { intros L1, iterate 3 { rw lift.of }, congr' 1 , exact mul_assoc _ _ _ },
349
- { intros L1 ih, iterate 3 { rw (lift _).map_neg }, rw ih },
350
- { intros x1 x2 ih1 ih2, iterate 3 { rw (lift _).map_add }, rw [ih1, ih2] } },
351
- { intros L2 ih, iterate 4 { rw (lift _).map_neg }, rw ih },
352
- { intros y1 y2 ih1 ih2, iterate 4 { rw (lift _).map_add }, rw [ih1, ih2] } },
353
- { intros L3 ih, iterate 3 { rw (lift _).map_neg }, rw ih },
354
- { intros z1 z2 ih1 ih2, iterate 2 { rw (lift _).map_add }, rw [ih1, ih2],
355
- exact ((lift _).map_add _ _).symm }
356
- end }
343
+ instance : has_mul (free_abelian_group α) := ⟨λ x, lift $ λ x₂, lift (λ x₁, of $ x₁ * x₂) x⟩
357
344
358
345
variable {α}
359
346
360
- lemma mul_def (x y : free_abelian_group α) :
361
- x * y = lift (λ x₂, lift (λ x₁, of (x₁ * x₂)) x) y := rfl
347
+ lemma mul_def (x y : free_abelian_group α) : x * y = lift (λ x₂, lift (λ x₁, of (x₁ * x₂)) x) y :=
348
+ rfl
362
349
363
- lemma of_mul_of (x y : α) : of x * of y = of (x * y) := rfl
350
+ @[simp] lemma of_mul_of (x y : α) : of x * of y = of (x * y) := rfl
364
351
lemma of_mul (x y : α) : of (x * y) = of x * of y := rfl
365
352
366
- variable (α)
353
+ instance : distrib (free_abelian_group α) :=
354
+ { add := (+),
355
+ left_distrib := λ x y z, (lift _).map_add _ _,
356
+ right_distrib := λ x y z, by simp only [(*), map_add, ←pi.add_def, lift.add'],
357
+ ..free_abelian_group.has_mul _ }
358
+
359
+ instance : non_unital_non_assoc_ring (free_abelian_group α) :=
360
+ { zero_mul := λ a, by { have h : 0 * a + 0 * a = 0 * a, by simp [←add_mul], simpa using h },
361
+ mul_zero := λ a, rfl,
362
+ ..free_abelian_group.distrib, ..free_abelian_group.add_comm_group _ }
363
+
364
+ end has_mul
365
+
366
+ instance [has_one α] : has_one (free_abelian_group α) := ⟨of 1 ⟩
367
+
368
+ instance [semigroup α] : non_unital_ring (free_abelian_group α) :=
369
+ { mul := (*),
370
+ mul_assoc := λ x y z, begin
371
+ refine free_abelian_group.induction_on z (by simp) (λ L3, _) (λ L3 ih, _) (λ z₁ z₂ ih₁ ih₂, _),
372
+ { refine free_abelian_group.induction_on y (by simp) (λ L2, _) (λ L2 ih, _)
373
+ (λ y₁ y₂ ih₁ ih₂, _),
374
+ { refine free_abelian_group.induction_on x (by simp) (λ L1, _) (λ L1 ih, _)
375
+ (λ x₁ x₂ ih₁ ih₂, _),
376
+ { rw [of_mul_of, of_mul_of, of_mul_of, of_mul_of, mul_assoc] },
377
+ { rw [neg_mul, neg_mul, neg_mul, ih] },
378
+ { rw [add_mul, add_mul, add_mul, ih₁, ih₂] } },
379
+ { rw [neg_mul, mul_neg, mul_neg, neg_mul, ih] },
380
+ { rw [add_mul, mul_add, mul_add, add_mul, ih₁, ih₂] } },
381
+ { rw [mul_neg, mul_neg, mul_neg, ih] },
382
+ { rw [mul_add, mul_add, mul_add, ih₁, ih₂] }
383
+ end ,
384
+ .. free_abelian_group.non_unital_non_assoc_ring }
385
+
386
+ section monoid
387
+
388
+ variables {R : Type *} [monoid α] [ring R]
367
389
368
390
instance : ring (free_abelian_group α) :=
369
- { one := free_abelian_group.of 1 ,
391
+ { mul := (*) ,
370
392
mul_one := λ x, begin
371
393
unfold has_mul.mul semigroup.mul has_one.one,
372
394
rw lift.of,
373
- refine free_abelian_group.induction_on x rfl _ _ _ ,
374
- { intros L, erw [lift.of], congr' 1 , exact mul_one L },
375
- { intros L ih, rw [(lift _). map_neg, ih] },
376
- { intros x1 x2 ih1 ih2, rw [(lift _). map_add, ih1, ih2] }
395
+ refine free_abelian_group.induction_on x rfl (λ L, _) (λ L ih, _) (λ x1 x2 ih1 ih2, _) ,
396
+ { erw [lift.of], congr' 1 , exact mul_one L },
397
+ { rw [map_neg, ih] },
398
+ { rw [map_add, ih1, ih2] }
377
399
end ,
378
400
one_mul := λ x, begin
379
401
unfold has_mul.mul semigroup.mul has_one.one,
380
402
refine free_abelian_group.induction_on x rfl _ _ _,
381
403
{ intros L, rw [lift.of, lift.of], congr' 1 , exact one_mul L },
382
- { intros L ih, rw [(lift _).map_neg, ih] },
383
- { intros x1 x2 ih1 ih2, rw [(lift _).map_add, ih1, ih2] }
384
- end ,
385
- left_distrib := λ x y z, (lift _).map_add _ _,
386
- right_distrib := λ x y z, begin
387
- unfold has_mul.mul semigroup.mul,
388
- refine free_abelian_group.induction_on z rfl _ _ _,
389
- { intros L, iterate 3 { rw lift.of }, rw (lift _).map_add, refl },
390
- { intros L ih, iterate 3 { rw (lift _).map_neg }, rw [ih, neg_add], refl },
391
- { intros z1 z2 ih1 ih2, iterate 3 { rw (lift _).map_add }, rw [ih1, ih2],
392
- rw [add_assoc, add_assoc], congr' 1 , apply add_left_comm }
404
+ { intros L ih, rw [map_neg, ih] },
405
+ { intros x1 x2 ih1 ih2, rw [map_add, ih1, ih2] }
393
406
end ,
394
- .. free_abelian_group.add_comm_group α,
395
- .. free_abelian_group.semigroup α }
407
+ .. free_abelian_group.non_unital_ring _, ..free_abelian_group.has_one _ }
396
408
397
409
variable {α}
398
410
@@ -407,23 +419,18 @@ def of_mul_hom : α →* free_abelian_group α :=
407
419
/-- If `f` preserves multiplication, then so does `lift f`. -/
408
420
def lift_monoid : (α →* R) ≃ (free_abelian_group α →+* R) :=
409
421
{ to_fun := λ f,
410
- { map_one' := (lift.of f _).trans f.map_one,
422
+ { to_fun := lift f,
423
+ map_one' := (lift.of f _).trans f.map_one,
411
424
map_mul' := λ x y,
412
425
begin
413
- simp only [add_monoid_hom.to_fun_eq_coe],
414
- refine free_abelian_group.induction_on y (mul_zero _).symm _ _ _,
415
- { intros L2,
416
- rw mul_def x,
417
- simp only [lift.of],
418
- refine free_abelian_group.induction_on x (zero_mul _).symm _ _ _,
419
- { intros L1, iterate 3 { rw lift.of },
426
+ refine free_abelian_group.induction_on y (mul_zero _).symm (λ L2, _) _ _,
427
+ { refine free_abelian_group.induction_on x (zero_mul _).symm (λ L1, _) (λ L1 ih, _) _,
428
+ { simp_rw [of_mul_of, lift.of],
420
429
exact f.map_mul _ _ },
421
- { intros L1 ih,
422
- iterate 3 { rw (lift _).map_neg },
423
- rw [ih, neg_mul_eq_neg_mul] },
430
+ { simp_rw [neg_mul, (lift f).map_neg, neg_mul],
431
+ exact congr_arg has_neg.neg ih },
424
432
{ intros x1 x2 ih1 ih2,
425
- iterate 3 { rw (lift _).map_add },
426
- rw [ih1, ih2, add_mul] } },
433
+ simp only [add_mul, map_add, ih1, ih2] } },
427
434
{ intros L2 ih,
428
435
rw [mul_neg, add_monoid_hom.map_neg, add_monoid_hom.map_neg,
429
436
mul_neg, ih] },
0 commit comments