@@ -13,55 +13,66 @@ open import Relation.Binary.Definitions
13
13
14
14
module Algebra.Consequences.Setoid {a ℓ} (S : Setoid a ℓ) where
15
15
16
- open Setoid S renaming (Carrier to A)
16
+ import Algebra.Consequences.Base as Base
17
17
open import Algebra.Core
18
- open import Algebra.Definitions _≈_
19
18
open import Data.Sum.Base using (inj₁; inj₂)
20
19
open import Data.Product.Base using (_,_)
21
20
open import Function.Base using (_$_; id; _∘_)
22
21
open import Function.Definitions
23
22
import Relation.Binary.Consequences as Bin
24
23
open import Relation.Binary.Core using (Rel)
25
- open import Relation.Binary.Reasoning.Setoid S
26
24
open import Relation.Unary using (Pred)
27
25
26
+ open Setoid S renaming (Carrier to A)
27
+ open import Algebra.Definitions _≈_
28
+ open import Relation.Binary.Reasoning.Setoid S
29
+
28
30
------------------------------------------------------------------------
29
31
-- Re-exports
30
32
31
33
-- Export base lemmas that don't require the setoid
32
34
33
- open import Algebra.Consequences.Base public
35
+ open Base public
36
+ hiding (module Congruence )
37
+
38
+ -- Export congruence lemmas using reflexivity
39
+
40
+ module Congruence {_∙_ : Op₂ A} (cong : Congruent₂ _∙_) where
41
+
42
+ open Base.Congruence _≈_ cong refl public
34
43
35
44
------------------------------------------------------------------------
36
45
-- MiddleFourExchange
37
46
38
47
module _ {_∙_ : Op₂ A} (cong : Congruent₂ _∙_) where
39
48
49
+ open Congruence cong
50
+
40
51
comm∧assoc⇒middleFour : Commutative _∙_ → Associative _∙_ →
41
52
_∙_ MiddleFourExchange _∙_
42
53
comm∧assoc⇒middleFour comm assoc w x y z = begin
43
54
(w ∙ x) ∙ (y ∙ z) ≈⟨ assoc w x (y ∙ z) ⟩
44
- w ∙ (x ∙ (y ∙ z)) ≈⟨ cong refl (sym ( assoc x y z)) ⟩
45
- w ∙ ((x ∙ y) ∙ z) ≈⟨ cong refl (cong (comm x y) refl ) ⟩
46
- w ∙ ((y ∙ x) ∙ z) ≈⟨ cong refl (assoc y x z) ⟩
47
- w ∙ (y ∙ (x ∙ z)) ≈⟨ sym ( assoc w y (x ∙ z)) ⟩
55
+ w ∙ (x ∙ (y ∙ z)) ≈⟨ ∙-congˡ ( assoc x y z) ⟨
56
+ w ∙ ((x ∙ y) ∙ z) ≈⟨ ∙-congˡ (∙-congʳ (comm x y)) ⟩
57
+ w ∙ ((y ∙ x) ∙ z) ≈⟨ ∙-congˡ (assoc y x z) ⟩
58
+ w ∙ (y ∙ (x ∙ z)) ≈⟨ assoc w y (x ∙ z) ⟨
48
59
(w ∙ y) ∙ (x ∙ z) ∎
49
60
50
61
identity∧middleFour⇒assoc : {e : A} → Identity e _∙_ →
51
62
_∙_ MiddleFourExchange _∙_ →
52
63
Associative _∙_
53
64
identity∧middleFour⇒assoc {e} (identityˡ , identityʳ) middleFour x y z = begin
54
- (x ∙ y) ∙ z ≈⟨ cong refl (sym ( identityˡ z)) ⟩
65
+ (x ∙ y) ∙ z ≈⟨ ∙-congˡ ( identityˡ z) ⟨
55
66
(x ∙ y) ∙ (e ∙ z) ≈⟨ middleFour x y e z ⟩
56
- (x ∙ e) ∙ (y ∙ z) ≈⟨ cong (identityʳ x) refl ⟩
67
+ (x ∙ e) ∙ (y ∙ z) ≈⟨ ∙-congʳ (identityʳ x) ⟩
57
68
x ∙ (y ∙ z) ∎
58
69
59
70
identity∧middleFour⇒comm : {_+_ : Op₂ A} {e : A} → Identity e _+_ →
60
71
_∙_ MiddleFourExchange _+_ →
61
72
Commutative _∙_
62
73
identity∧middleFour⇒comm {_+_} {e} (identityˡ , identityʳ) middleFour x y
63
74
= begin
64
- x ∙ y ≈⟨ sym ( cong (identityˡ x) (identityʳ y)) ⟩
75
+ x ∙ y ≈⟨ cong (identityˡ x) (identityʳ y) ⟨
65
76
(e + x) ∙ (y + e) ≈⟨ middleFour e x y e ⟩
66
77
(e + y) ∙ (x + e) ≈⟨ cong (identityˡ y) (identityʳ x) ⟩
67
78
y ∙ x ∎
@@ -198,25 +209,27 @@ module _ {_∙_ : Op₂ A} {_⁻¹ : Op₁ A} {e} (comm : Commutative _∙_) whe
198
209
199
210
module _ {_∙_ : Op₂ A} {_⁻¹ : Op₁ A} {e} (cong : Congruent₂ _∙_) where
200
211
212
+ open Congruence cong
213
+
201
214
assoc∧id∧invʳ⇒invˡ-unique : Associative _∙_ →
202
215
Identity e _∙_ → RightInverse e _⁻¹ _∙_ →
203
216
∀ x y → (x ∙ y) ≈ e → x ≈ (y ⁻¹)
204
217
assoc∧id∧invʳ⇒invˡ-unique assoc (idˡ , idʳ) invʳ x y eq = begin
205
- x ≈⟨ sym ( idʳ x) ⟩
206
- x ∙ e ≈⟨ cong refl (sym ( invʳ y)) ⟩
207
- x ∙ (y ∙ (y ⁻¹)) ≈⟨ sym ( assoc x y (y ⁻¹)) ⟩
208
- (x ∙ y) ∙ (y ⁻¹) ≈⟨ cong eq refl ⟩
218
+ x ≈⟨ idʳ x ⟨
219
+ x ∙ e ≈⟨ ∙-congˡ ( invʳ y) ⟨
220
+ x ∙ (y ∙ (y ⁻¹)) ≈⟨ assoc x y (y ⁻¹) ⟨
221
+ (x ∙ y) ∙ (y ⁻¹) ≈⟨ ∙-congʳ eq ⟩
209
222
e ∙ (y ⁻¹) ≈⟨ idˡ (y ⁻¹) ⟩
210
223
y ⁻¹ ∎
211
224
212
225
assoc∧id∧invˡ⇒invʳ-unique : Associative _∙_ →
213
226
Identity e _∙_ → LeftInverse e _⁻¹ _∙_ →
214
227
∀ x y → (x ∙ y) ≈ e → y ≈ (x ⁻¹)
215
228
assoc∧id∧invˡ⇒invʳ-unique assoc (idˡ , idʳ) invˡ x y eq = begin
216
- y ≈⟨ sym ( idˡ y) ⟩
217
- e ∙ y ≈⟨ cong (sym ( invˡ x)) refl ⟩
229
+ y ≈⟨ idˡ y ⟨
230
+ e ∙ y ≈⟨ ∙-congʳ ( invˡ x) ⟨
218
231
((x ⁻¹) ∙ x) ∙ y ≈⟨ assoc (x ⁻¹) x y ⟩
219
- (x ⁻¹) ∙ (x ∙ y) ≈⟨ cong refl eq ⟩
232
+ (x ⁻¹) ∙ (x ∙ y) ≈⟨ ∙-congˡ eq ⟩
220
233
(x ⁻¹) ∙ e ≈⟨ idʳ (x ⁻¹) ⟩
221
234
x ⁻¹ ∎
222
235
@@ -228,6 +241,8 @@ module _ {_∙_ _◦_ : Op₂ A}
228
241
(∙-comm : Commutative _∙_)
229
242
where
230
243
244
+ open Congruence ◦-cong renaming (∙-congˡ to ◦-congˡ)
245
+
231
246
comm∧distrˡ⇒distrʳ : _∙_ DistributesOverˡ _◦_ → _∙_ DistributesOverʳ _◦_
232
247
comm∧distrˡ⇒distrʳ distrˡ x y z = begin
233
248
(y ◦ z) ∙ x ≈⟨ ∙-comm (y ◦ z) x ⟩
@@ -250,7 +265,7 @@ module _ {_∙_ _◦_ : Op₂ A}
250
265
251
266
comm⇒sym[distribˡ] : ∀ x → Symmetric (λ y z → (x ◦ (y ∙ z)) ≈ ((x ◦ y) ∙ (x ◦ z)))
252
267
comm⇒sym[distribˡ] x {y} {z} prf = begin
253
- x ◦ (z ∙ y) ≈⟨ ◦-cong refl (∙-comm z y) ⟩
268
+ x ◦ (z ∙ y) ≈⟨ ◦-congˡ (∙-comm z y) ⟩
254
269
x ◦ (y ∙ z) ≈⟨ prf ⟩
255
270
(x ◦ y) ∙ (x ◦ z) ≈⟨ ∙-comm (x ◦ y) (x ◦ z) ⟩
256
271
(x ◦ z) ∙ (x ◦ y) ∎
@@ -262,16 +277,18 @@ module _ {_∙_ _◦_ : Op₂ A}
262
277
(◦-comm : Commutative _◦_)
263
278
where
264
279
280
+ open Congruence ∙-cong
281
+
265
282
distrib∧absorbs⇒distribˡ : _∙_ Absorbs _◦_ →
266
283
_◦_ Absorbs _∙_ →
267
284
_◦_ DistributesOver _∙_ →
268
285
_∙_ DistributesOverˡ _◦_
269
286
distrib∧absorbs⇒distribˡ ∙-absorbs-◦ ◦-absorbs-∙ (◦-distribˡ-∙ , ◦-distribʳ-∙) x y z = begin
270
- x ∙ (y ◦ z) ≈⟨ ∙-cong (∙-absorbs-◦ _ _) refl ⟨
271
- (x ∙ (x ◦ y)) ∙ (y ◦ z) ≈⟨ ∙-cong (∙-cong refl (◦-comm _ _)) refl ⟩
287
+ x ∙ (y ◦ z) ≈⟨ ∙-congʳ (∙-absorbs-◦ _ _) ⟨
288
+ (x ∙ (x ◦ y)) ∙ (y ◦ z) ≈⟨ ∙-congʳ (∙-congˡ (◦-comm _ _)) ⟩
272
289
(x ∙ (y ◦ x)) ∙ (y ◦ z) ≈⟨ ∙-assoc _ _ _ ⟩
273
- x ∙ ((y ◦ x) ∙ (y ◦ z)) ≈⟨ ∙-cong refl (◦-distribˡ-∙ _ _ _) ⟨
274
- x ∙ (y ◦ (x ∙ z)) ≈⟨ ∙-cong (◦-absorbs-∙ _ _) refl ⟨
290
+ x ∙ ((y ◦ x) ∙ (y ◦ z)) ≈⟨ ∙-congˡ (◦-distribˡ-∙ _ _ _) ⟨
291
+ x ∙ (y ◦ (x ∙ z)) ≈⟨ ∙-congʳ (◦-absorbs-∙ _ _) ⟨
275
292
(x ◦ (x ∙ z)) ∙ (y ◦ (x ∙ z)) ≈⟨ ◦-distribʳ-∙ _ _ _ ⟨
276
293
(x ∙ y) ◦ (x ∙ z) ∎
277
294
@@ -284,27 +301,31 @@ module _ {_+_ _*_ : Op₂ A}
284
301
(*-cong : Congruent₂ _*_)
285
302
where
286
303
304
+ open Congruence +-cong renaming (∙-congˡ to +-congˡ; ∙-congʳ to +-congʳ)
305
+
306
+ open Congruence *-cong renaming (∙-congˡ to *-congˡ; ∙-congʳ to *-congʳ)
307
+
287
308
assoc∧distribʳ∧idʳ∧invʳ⇒zeˡ : Associative _+_ → _*_ DistributesOverʳ _+_ →
288
309
RightIdentity 0# _+_ → RightInverse 0# _⁻¹ _+_ →
289
310
LeftZero 0# _*_
290
311
assoc∧distribʳ∧idʳ∧invʳ⇒zeˡ +-assoc distribʳ idʳ invʳ x = begin
291
- 0# * x ≈⟨ sym ( idʳ _) ⟩
292
- (0# * x) + 0# ≈⟨ +-cong refl (sym ( invʳ _)) ⟩
293
- (0# * x) + ((0# * x) + ((0# * x)⁻¹)) ≈⟨ sym ( +-assoc _ _ _) ⟩
294
- ((0# * x) + (0# * x)) + ((0# * x)⁻¹) ≈⟨ +-cong (sym ( distribʳ _ _ _)) refl ⟩
295
- ((0# + 0#) * x) + ((0# * x)⁻¹) ≈⟨ +-cong (*-cong (idʳ _) refl) refl ⟩
312
+ 0# * x ≈⟨ idʳ _ ⟨
313
+ (0# * x) + 0# ≈⟨ +-congˡ ( invʳ _) ⟨
314
+ (0# * x) + ((0# * x) + ((0# * x)⁻¹)) ≈⟨ +-assoc _ _ _ ⟨
315
+ ((0# * x) + (0# * x)) + ((0# * x)⁻¹) ≈⟨ +-congʳ ( distribʳ _ _ _) ⟨
316
+ ((0# + 0#) * x) + ((0# * x)⁻¹) ≈⟨ +-congʳ (*-congʳ (idʳ _)) ⟩
296
317
(0# * x) + ((0# * x)⁻¹) ≈⟨ invʳ _ ⟩
297
318
0# ∎
298
319
299
320
assoc∧distribˡ∧idʳ∧invʳ⇒zeʳ : Associative _+_ → _*_ DistributesOverˡ _+_ →
300
321
RightIdentity 0# _+_ → RightInverse 0# _⁻¹ _+_ →
301
322
RightZero 0# _*_
302
323
assoc∧distribˡ∧idʳ∧invʳ⇒zeʳ +-assoc distribˡ idʳ invʳ x = begin
303
- x * 0# ≈⟨ sym ( idʳ _) ⟩
304
- (x * 0#) + 0# ≈⟨ +-cong refl (sym ( invʳ _)) ⟩
305
- (x * 0#) + ((x * 0#) + ((x * 0#)⁻¹)) ≈⟨ sym ( +-assoc _ _ _) ⟩
306
- ((x * 0#) + (x * 0#)) + ((x * 0#)⁻¹) ≈⟨ +-cong (sym ( distribˡ _ _ _)) refl ⟩
307
- (x * (0# + 0#)) + ((x * 0#)⁻¹) ≈⟨ +-cong (*-cong refl (idʳ _)) refl ⟩
324
+ x * 0# ≈⟨ idʳ _ ⟨
325
+ (x * 0#) + 0# ≈⟨ +-congˡ ( invʳ _) ⟨
326
+ (x * 0#) + ((x * 0#) + ((x * 0#)⁻¹)) ≈⟨ +-assoc _ _ _ ⟨
327
+ ((x * 0#) + (x * 0#)) + ((x * 0#)⁻¹) ≈⟨ +-congʳ ( distribˡ _ _ _) ⟨
328
+ (x * (0# + 0#)) + ((x * 0#)⁻¹) ≈⟨ +-congʳ (*-congˡ (idʳ _)) ⟩
308
329
((x * 0#) + ((x * 0#)⁻¹)) ≈⟨ invʳ _ ⟩
309
330
0# ∎
310
331
0 commit comments