zero #
Equations
negation (additive inverse) #
Well-definedness #
OK now here's the concrete problem. We would like to define
a negation map ℤ → ℤ
sending z
to -z
. We want to do this in
the following way: Say z ∈ ℤ
. Choose a=(i,j) ∈ ℕ²
representing z
(i.e. such that cl(i,j) = ⟦(i,j)⟧ = z
)
Now apply neg_aux
to a
, and define -z
to be the result.
The problem with this is that what if b
is a different
element of the equivalence class? Then we also want -z
to be neg_aux b
.
Indeed, in Lean this construction is called quotient.lift
, and
if you uncomment the below code
Negation on on the integers. The function sending z
to -z
.
Equations
Equations
- myint.has_neg = {neg := myint.neg}
addition #
Our final construction: we want to define addition on myint
.
Here we have the same problem. Say z₁ and z₂ are integers.
Choose elements a₁=(i,j) and a₂=(k,l) in ℕ². We want to define
z₁ + z₂ to be ⟦(i+k,j+l)⟧, the equivalence class of a₁ + a₂.
Let's make this definition now.
Addition on the integers
Equations
Equations
- myint.has_add = {add := myint.add}
Equations
- myint.add_comm_group = {add := has_add.add myint.has_add, add_assoc := myint.add_assoc, zero := 0, zero_add := myint.zero_add, add_zero := myint.add_zero, nsmul := add_group.nsmul._default 0 has_add.add myint.zero_add myint.add_zero, nsmul_zero' := myint.add_comm_group._proof_1, nsmul_succ' := myint.add_comm_group._proof_2, neg := has_neg.neg myint.has_neg, sub := add_group.sub._default has_add.add myint.add_assoc 0 myint.zero_add myint.add_zero (add_group.nsmul._default 0 has_add.add myint.zero_add myint.add_zero) myint.add_comm_group._proof_3 myint.add_comm_group._proof_4 has_neg.neg, sub_eq_add_neg := myint.add_comm_group._proof_5, zsmul := add_group.zsmul._default has_add.add myint.add_assoc 0 myint.zero_add myint.add_zero (add_group.nsmul._default 0 has_add.add myint.zero_add myint.add_zero) myint.add_comm_group._proof_6 myint.add_comm_group._proof_7 has_neg.neg, zsmul_zero' := myint.add_comm_group._proof_8, zsmul_succ' := myint.add_comm_group._proof_9, zsmul_neg' := myint.add_comm_group._proof_10, add_left_neg := myint.add_left_neg, add_comm := myint.add_comm}
multiplication #
What's left to define is 1 and multiplication (note that we don't need multiplicative inverses -- if a is a non-zero integer then a⁻¹ is typially not an integer)
Equations
Equations
- myint.has_mul = {mul := myint.mul}
Equations
- myint.has_one = {one := myint.one}
Equations
- myint.comm_ring = {add := add_comm_group.add myint.add_comm_group, add_assoc := _, zero := add_comm_group.zero myint.add_comm_group, zero_add := _, add_zero := _, nsmul := add_comm_group.nsmul myint.add_comm_group, nsmul_zero' := _, nsmul_succ' := _, neg := add_comm_group.neg myint.add_comm_group, sub := add_comm_group.sub myint.add_comm_group, sub_eq_add_neg := _, zsmul := add_comm_group.zsmul myint.add_comm_group, zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _, mul := has_mul.mul myint.has_mul, mul_assoc := myint.mul_assoc, one := 1, one_mul := myint.one_mul, mul_one := myint.mul_one, npow := ring.npow._default 1 has_mul.mul myint.one_mul myint.mul_one, npow_zero' := myint.comm_ring._proof_1, npow_succ' := myint.comm_ring._proof_2, left_distrib := myint.mul_add, right_distrib := myint.add_mul, mul_comm := myint.mul_comm}