| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Some boring lemmas used by the ring solver |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- Note that these proofs use all "almost commutative ring" properties. |
| 8 |
|
| 9 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 10 |
|
| 11 |
open import Algebra using (RawRing) |
| 12 |
open import Algebra.Solver.Ring.AlmostCommutativeRing using (AlmostCommutativeRing; _-Raw-AlmostCommutative⟶_) |
| 13 |
|
| 14 |
module Algebra.Solver.Ring.Lemmas |
| 15 |
{r₁ r₂ r₃ r₄} |
| 16 |
(coeff : RawRing r₁ r₄) |
| 17 |
(r : AlmostCommutativeRing r₂ r₃) |
| 18 |
(morphism : coeff -Raw-AlmostCommutative⟶ r) |
| 19 |
where |
| 20 |
|
| 21 |
private |
| 22 |
module C = RawRing coeff |
| 23 |
open AlmostCommutativeRing r |
| 24 |
open import Algebra.Morphism |
| 25 |
open _-Raw-AlmostCommutative⟶_ morphism |
| 26 |
open import Relation.Binary.Reasoning.Setoid setoid |
| 27 |
open import Function.Base using (_⟨_⟩_; _$_) |
| 28 |
|
| 29 |
lemma₀ : ∀ a b c x → |
| 30 |
(a + b) * x + c ≈ a * x + (b * x + c) |
| 31 |
lemma₀ a b c x = begin |
| 32 |
(a + b) * x + c ≈⟨ distribʳ _ _ _ ⟨ +-cong ⟩ refl ⟩ |
| 33 |
(a * x + b * x) + c ≈⟨ +-assoc _ _ _ ⟩ |
| 34 |
a * x + (b * x + c) ∎ |
| 35 |
|
| 36 |
lemma₁ : ∀ a b c d x → |
| 37 |
(a + b) * x + (c + d) ≈ (a * x + c) + (b * x + d) |
| 38 |
lemma₁ a b c d x = begin |
| 39 |
(a + b) * x + (c + d) ≈⟨ lemma₀ _ _ _ _ ⟩ |
| 40 |
a * x + (b * x + (c + d)) ≈⟨ refl ⟨ +-cong ⟩ sym (+-assoc _ _ _) ⟩ |
| 41 |
a * x + ((b * x + c) + d) ≈⟨ refl ⟨ +-cong ⟩ (+-comm _ _ ⟨ +-cong ⟩ refl) ⟩ |
| 42 |
a * x + ((c + b * x) + d) ≈⟨ refl ⟨ +-cong ⟩ +-assoc _ _ _ ⟩ |
| 43 |
a * x + (c + (b * x + d)) ≈⟨ sym $ +-assoc _ _ _ ⟩ |
| 44 |
(a * x + c) + (b * x + d) ∎ |
| 45 |
|
| 46 |
lemma₂ : ∀ a b c x → a * c * x + b * c ≈ (a * x + b) * c |
| 47 |
lemma₂ a b c x = begin |
| 48 |
a * c * x + b * c ≈⟨ lem ⟨ +-cong ⟩ refl ⟩ |
| 49 |
a * x * c + b * c ≈⟨ sym $ distribʳ _ _ _ ⟩ |
| 50 |
(a * x + b) * c ∎ |
| 51 |
where |
| 52 |
lem = begin |
| 53 |
a * c * x ≈⟨ *-assoc _ _ _ ⟩ |
| 54 |
a * (c * x) ≈⟨ refl ⟨ *-cong ⟩ *-comm _ _ ⟩ |
| 55 |
a * (x * c) ≈⟨ sym $ *-assoc _ _ _ ⟩ |
| 56 |
a * x * c ∎ |
| 57 |
|
| 58 |
lemma₃ : ∀ a b c x → a * b * x + a * c ≈ a * (b * x + c) |
| 59 |
lemma₃ a b c x = begin |
| 60 |
a * b * x + a * c ≈⟨ *-assoc _ _ _ ⟨ +-cong ⟩ refl ⟩ |
| 61 |
a * (b * x) + a * c ≈⟨ sym $ distribˡ _ _ _ ⟩ |
| 62 |
a * (b * x + c) ∎ |
| 63 |
|
| 64 |
lemma₄ : ∀ a b c d x → |
| 65 |
(a * c * x + (a * d + b * c)) * x + b * d ≈ |
| 66 |
(a * x + b) * (c * x + d) |
| 67 |
lemma₄ a b c d x = begin |
| 68 |
(a * c * x + (a * d + b * c)) * x + b * d ≈⟨ distribʳ _ _ _ ⟨ +-cong ⟩ refl ⟩ |
| 69 |
(a * c * x * x + (a * d + b * c) * x) + b * d ≈⟨ refl ⟨ +-cong ⟩ ((refl ⟨ +-cong ⟩ refl) ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ refl ⟩ |
| 70 |
(a * c * x * x + (a * d + b * c) * x) + b * d ≈⟨ +-assoc _ _ _ ⟩ |
| 71 |
a * c * x * x + ((a * d + b * c) * x + b * d) ≈⟨ lem₁ ⟨ +-cong ⟩ (lem₂ ⟨ +-cong ⟩ refl) ⟩ |
| 72 |
a * x * (c * x) + (a * x * d + b * (c * x) + b * d) ≈⟨ refl ⟨ +-cong ⟩ +-assoc _ _ _ ⟩ |
| 73 |
a * x * (c * x) + (a * x * d + (b * (c * x) + b * d)) ≈⟨ sym $ +-assoc _ _ _ ⟩ |
| 74 |
a * x * (c * x) + a * x * d + (b * (c * x) + b * d) ≈⟨ sym $ distribˡ _ _ _ ⟨ +-cong ⟩ distribˡ _ _ _ ⟩ |
| 75 |
a * x * (c * x + d) + b * (c * x + d) ≈⟨ sym $ distribʳ _ _ _ ⟩ |
| 76 |
(a * x + b) * (c * x + d) ∎ |
| 77 |
where |
| 78 |
lem₁′ = begin |
| 79 |
a * c * x ≈⟨ *-assoc _ _ _ ⟩ |
| 80 |
a * (c * x) ≈⟨ refl ⟨ *-cong ⟩ *-comm _ _ ⟩ |
| 81 |
a * (x * c) ≈⟨ sym $ *-assoc _ _ _ ⟩ |
| 82 |
a * x * c ∎ |
| 83 |
|
| 84 |
lem₁ = begin |
| 85 |
a * c * x * x ≈⟨ lem₁′ ⟨ *-cong ⟩ refl ⟩ |
| 86 |
a * x * c * x ≈⟨ *-assoc _ _ _ ⟩ |
| 87 |
a * x * (c * x) ∎ |
| 88 |
|
| 89 |
lem₂ = begin |
| 90 |
(a * d + b * c) * x ≈⟨ distribʳ _ _ _ ⟩ |
| 91 |
a * d * x + b * c * x ≈⟨ *-assoc _ _ _ ⟨ +-cong ⟩ *-assoc _ _ _ ⟩ |
| 92 |
a * (d * x) + b * (c * x) ≈⟨ (refl ⟨ *-cong ⟩ *-comm _ _) ⟨ +-cong ⟩ refl ⟩ |
| 93 |
a * (x * d) + b * (c * x) ≈⟨ sym $ *-assoc _ _ _ ⟨ +-cong ⟩ refl ⟩ |
| 94 |
a * x * d + b * (c * x) ∎ |
| 95 |
|
| 96 |
lemma₅ : ∀ x → (0# * x + 1#) * x + 0# ≈ x |
| 97 |
lemma₅ x = begin |
| 98 |
(0# * x + 1#) * x + 0# ≈⟨ ((zeroˡ _ ⟨ +-cong ⟩ refl) ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ refl ⟩ |
| 99 |
(0# + 1#) * x + 0# ≈⟨ (+-identityˡ _ ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ refl ⟩ |
| 100 |
1# * x + 0# ≈⟨ +-identityʳ _ ⟩ |
| 101 |
1# * x ≈⟨ *-identityˡ _ ⟩ |
| 102 |
x ∎ |
| 103 |
|
| 104 |
lemma₆ : ∀ a x → 0# * x + a ≈ a |
| 105 |
lemma₆ a x = begin |
| 106 |
0# * x + a ≈⟨ zeroˡ _ ⟨ +-cong ⟩ refl ⟩ |
| 107 |
0# + a ≈⟨ +-identityˡ _ ⟩ |
| 108 |
a ∎ |
| 109 |
|
| 110 |
lemma₇ : ∀ x → - 1# * x ≈ - x |
| 111 |
lemma₇ x = begin |
| 112 |
- 1# * x ≈⟨ -‿*-distribˡ _ _ ⟩ |
| 113 |
- (1# * x) ≈⟨ -‿cong (*-identityˡ _) ⟩ |
| 114 |
- x ∎ |