/
addition-natural-numbers.lagda.md
194 lines (150 loc) · 5.36 KB
/
addition-natural-numbers.lagda.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Addition on the natural numbers
```agda
module elementary-number-theory.addition-natural-numbers where
```
<details><summary>Imports</summary>
```agda
open import elementary-number-theory.natural-numbers
open import foundation.action-on-identifications-binary-functions
open import foundation.action-on-identifications-functions
open import foundation.cartesian-product-types
open import foundation.dependent-pair-types
open import foundation.embeddings
open import foundation.empty-types
open import foundation.function-types
open import foundation.identity-types
open import foundation.injective-maps
open import foundation.interchange-law
open import foundation.negated-equality
```
</details>
## Definition
```agda
add-ℕ : ℕ → ℕ → ℕ
add-ℕ x 0 = x
add-ℕ x (succ-ℕ y) = succ-ℕ (add-ℕ x y)
add-ℕ' : ℕ → ℕ → ℕ
add-ℕ' m n = add-ℕ n m
infixl 35 _+ℕ_
_+ℕ_ = add-ℕ
ap-add-ℕ :
{m n m' n' : ℕ} → m = m' → n = n' → m +ℕ n = m' +ℕ n'
ap-add-ℕ p q = ap-binary add-ℕ p q
```
## Properties
### The left and right unit laws
```agda
right-unit-law-add-ℕ :
(x : ℕ) → x +ℕ zero-ℕ = x
right-unit-law-add-ℕ x = refl
left-unit-law-add-ℕ :
(x : ℕ) → zero-ℕ +ℕ x = x
left-unit-law-add-ℕ zero-ℕ = refl
left-unit-law-add-ℕ (succ-ℕ x) = ap succ-ℕ (left-unit-law-add-ℕ x)
```
### The left and right successor laws
```agda
left-successor-law-add-ℕ :
(x y : ℕ) → (succ-ℕ x) +ℕ y = succ-ℕ (x +ℕ y)
left-successor-law-add-ℕ x zero-ℕ = refl
left-successor-law-add-ℕ x (succ-ℕ y) =
ap succ-ℕ (left-successor-law-add-ℕ x y)
right-successor-law-add-ℕ :
(x y : ℕ) → x +ℕ (succ-ℕ y) = succ-ℕ (x +ℕ y)
right-successor-law-add-ℕ x y = refl
```
### Addition is associative
```agda
associative-add-ℕ :
(x y z : ℕ) → (x +ℕ y) +ℕ z = x +ℕ (y +ℕ z)
associative-add-ℕ x y zero-ℕ = refl
associative-add-ℕ x y (succ-ℕ z) = ap succ-ℕ (associative-add-ℕ x y z)
```
### Addition is commutative
```agda
commutative-add-ℕ : (x y : ℕ) → x +ℕ y = y +ℕ x
commutative-add-ℕ zero-ℕ y = left-unit-law-add-ℕ y
commutative-add-ℕ (succ-ℕ x) y =
(left-successor-law-add-ℕ x y) ∙ (ap succ-ℕ (commutative-add-ℕ x y))
```
### Addition by `1` on the left or on the right is the successor
```agda
left-one-law-add-ℕ :
(x : ℕ) → 1 +ℕ x = succ-ℕ x
left-one-law-add-ℕ x =
( left-successor-law-add-ℕ zero-ℕ x) ∙
( ap succ-ℕ (left-unit-law-add-ℕ x))
right-one-law-add-ℕ :
(x : ℕ) → x +ℕ 1 = succ-ℕ x
right-one-law-add-ℕ x = refl
```
### Addition by `1` on the left or on the right is the double successor
```agda
left-two-law-add-ℕ :
(x : ℕ) → 2 +ℕ x = succ-ℕ (succ-ℕ x)
left-two-law-add-ℕ x =
( left-successor-law-add-ℕ 1 x) ∙
( ap succ-ℕ (left-one-law-add-ℕ x))
right-two-law-add-ℕ :
(x : ℕ) → x +ℕ 2 = succ-ℕ (succ-ℕ x)
right-two-law-add-ℕ x = refl
```
### Interchange law of addition
```agda
interchange-law-add-add-ℕ : interchange-law add-ℕ add-ℕ
interchange-law-add-add-ℕ =
interchange-law-commutative-and-associative
add-ℕ
commutative-add-ℕ
associative-add-ℕ
```
### Addition by a fixed element on either side is injective
```agda
is-injective-right-add-ℕ : (k : ℕ) → is-injective (_+ℕ k)
is-injective-right-add-ℕ zero-ℕ = id
is-injective-right-add-ℕ (succ-ℕ k) p =
is-injective-right-add-ℕ k (is-injective-succ-ℕ p)
is-injective-left-add-ℕ : (k : ℕ) → is-injective (k +ℕ_)
is-injective-left-add-ℕ k {x} {y} p =
is-injective-right-add-ℕ
( k)
( commutative-add-ℕ x k ∙ (p ∙ commutative-add-ℕ k y))
```
### Addition by a fixed element on either side is an embedding
```agda
is-emb-left-add-ℕ : (x : ℕ) → is-emb (x +ℕ_)
is-emb-left-add-ℕ x = is-emb-is-injective is-set-ℕ (is-injective-left-add-ℕ x)
is-emb-right-add-ℕ : (x : ℕ) → is-emb (_+ℕ x)
is-emb-right-add-ℕ x = is-emb-is-injective is-set-ℕ (is-injective-right-add-ℕ x)
```
### `x + y = 0` if and only if both `x` and `y` are `0`
```agda
is-zero-right-is-zero-add-ℕ :
(x y : ℕ) → is-zero-ℕ (x +ℕ y) → is-zero-ℕ y
is-zero-right-is-zero-add-ℕ x zero-ℕ p = refl
is-zero-right-is-zero-add-ℕ x (succ-ℕ y) p =
ex-falso (is-nonzero-succ-ℕ (x +ℕ y) p)
is-zero-left-is-zero-add-ℕ :
(x y : ℕ) → is-zero-ℕ (x +ℕ y) → is-zero-ℕ x
is-zero-left-is-zero-add-ℕ x y p =
is-zero-right-is-zero-add-ℕ y x ((commutative-add-ℕ y x) ∙ p)
is-zero-summand-is-zero-sum-ℕ :
(x y : ℕ) → is-zero-ℕ (x +ℕ y) → (is-zero-ℕ x) × (is-zero-ℕ y)
is-zero-summand-is-zero-sum-ℕ x y p =
pair (is-zero-left-is-zero-add-ℕ x y p) (is-zero-right-is-zero-add-ℕ x y p)
is-zero-sum-is-zero-summand-ℕ :
(x y : ℕ) → (is-zero-ℕ x) × (is-zero-ℕ y) → is-zero-ℕ (x +ℕ y)
is-zero-sum-is-zero-summand-ℕ .zero-ℕ .zero-ℕ (pair refl refl) = refl
```
### `m ≠ m + n + 1`
```agda
neq-add-ℕ :
(m n : ℕ) → m ≠ m +ℕ (succ-ℕ n)
neq-add-ℕ (succ-ℕ m) n p =
neq-add-ℕ m n
( ( is-injective-succ-ℕ p) ∙
( left-successor-law-add-ℕ m n))
```
## See also
- The commutative monoid of the natural numbers with addition is defined in
[`monoid-of-natural-numbers-with-addition`](elementary-number-theory.monoid-of-natural-numbers-with-addition.md).