Library Stdlib.Zmod.ZmodBase
Unsigned conversions to Z
Lemma unsigned_add [
m] (
x y :
Zmod m) :
to_Z (
x + y)
= (to_Z x + to_Z y) mod m.
Notation to_Z_add :=
unsigned_add (
only parsing).
Lemma eqb_spec [
m] (
x y :
Zmod m) :
BoolSpec (
x = y) (
x <> y) (
eqb x y).
Lemma eqb_eq [
m] (
x y :
Zmod m) :
eqb x y = true <-> x = y.
Lemma eqb_refl [
m] (
x :
Zmod m) :
eqb x x = true.
Lemma signed_add [
m]
x y :
signed (@
add m x y)
= Z.smodulo (
signed x+signed y)
m.
Lemma of_Z_add [
m] (
x y :
Z) :
of_Z m (
Z.add x y)
= add (
of_Z m x) (
of_Z m y).
Lemma unsigned_sub [
m] (
x y :
Zmod m) :
to_Z (
x - y)
= (to_Z x - to_Z y) mod m.
Notation to_Z_sub :=
unsigned_sub (
only parsing).
Lemma signed_sub [
m]
x y :
signed (@
sub m x y)
= Z.smodulo (
signed x-signed y)
m.
Lemma of_Z_sub [
m] (
x y :
Z) :
of_Z m (
Z.sub x y)
= sub (
of_Z m x) (
of_Z m y).
Lemma unsigned_opp [
m] (
x :
Zmod m) :
to_Z (
opp x)
= (- to_Z x) mod m.
Notation to_Z_opp :=
unsigned_opp (
only parsing).
Lemma signed_opp [
m]
x :
signed (@
opp m x)
= Z.smodulo (
-signed x)
m.
Lemma unsigned_m1 m : @
to_Z m (
opp one)
= -1
mod m.
Lemma unsigned_m1_pos [
m :
Z] (
H : 2
<= m) : @
to_Z m (
opp one)
= m-1.
Notation to_Z_m1_pos :=
unsigned_m1_pos (
only parsing).
Lemma unsigned_m1_1 : @
to_Z 1 (
opp one)
= 0.
Notation to_Z_m1_1 :=
unsigned_m1_1 (
only parsing).
Lemma unsigned_m1_m1 : @
to_Z (-1) (
opp one)
= 0.
Notation to_Z_m1_m1 :=
unsigned_m1_m1 (
only parsing).
Lemma unsigned_m1_neg [
m :
Z] (
H :
m <= -2) : @
to_Z m (
opp one)
= -1.
Notation to_Z_m1_neg :=
unsigned_m1_neg (
only parsing).
Lemma unsigned_m1_cases m : @
to_Z m (
opp one)
=
if (m <=? -2
) || (m =? 0
) then -1
else if Z.abs m =? 1
then 0
else m-1.
Notation to_Z_m1_cases :=
unsigned_m1_cases (
only parsing).
Lemma of_Z_m1 m : @
of_Z m (-1)
= opp one.
Lemma signed_m1 [
m] (
Hm : 2
<= m) : @
signed m (
opp one)
= -1.
Lemma of_Z_opp [
m] (
x :
Z) :
of_Z m (
Z.opp x)
= opp (
of_Z m x).
Lemma opp_zero m : @
opp m zero = zero.
Lemma opp_overflow [
m] (
Hm :
m mod 2
= 0)
(
x :
Zmod m) (
Hx :
signed x = -m/2) :
opp x = x.
Lemma signed_opp_odd [
m] (
x :
Zmod m) (
H :
m mod 2
= 1) :
signed (
opp x)
= Z.opp (
signed x).
Lemma signed_opp_small [
m] (
x :
Zmod m) (
H :
signed x = -m/2
-> m mod 2
= 1) :
signed (
- x)
= Z.opp (
signed x).
Lemma unsigned_mul [
m] (
x y :
Zmod m) :
to_Z (
x * y)
= (to_Z x * to_Z y) mod m.
Notation to_Z_mul :=
unsigned_mul (
only parsing).
Lemma signed_mul [
m]
x y :
signed (@
mul m x y)
= Z.smodulo (
signed x*signed y)
m.
Lemma of_Z_mul [
m] (
x y :
Z) :
of_Z m (
Z.mul x y)
= mul (
of_Z m x) (
of_Z m y).
Local Ltac r :=
try apply to_Z_inj;
cbv [
one];
repeat rewrite ?
to_Z_of_Z, ?
to_Z_add, ?
to_Z_mul, ?
to_Z_sub, ?
to_Z_opp,
?
mod_to_Z, ?
Zmod_0_l, ?
Z.mul_1_l, ?
Z.add_0_l, ?
Zplus_mod_idemp_l,
?
Zplus_mod_idemp_r, ?
Zmult_mod_idemp_l, ?
Zmult_mod_idemp_r,
?
Z.add_opp_diag_r, ?
to_Z_0;
try (
f_equal;
lia).
Lemma add_0_l [
m]
a : @
add m zero a = a.
Lemma add_comm [
m]
a b : @
add m a b = add b a.
Lemma mul_comm [
m]
a b : @
mul m a b = mul b a.
Lemma add_assoc [
m]
a b c : @
add m a (
add b c)
= add (
add a b)
c.
Lemma mul_assoc [
m]
a b c : @
mul m a (
mul b c)
= mul (
mul a b)
c.
Lemma mul_add_l [
m]
a b c : @
mul m (
add a b)
c = add (
mul a c) (
mul b c).
Lemma mul_1_l [
m]
a : @
mul m one a = a.
Lemma add_opp_r [
m]
a b : @
add m a (
opp b)
= sub a b.
Lemma add_opp_same_r [
m]
a : @
add m a (
opp a)
= zero.
Lemma sub_same [
m]
a : @
sub m a a = zero.
Lemma ring_theory m : @
ring_theory (
Zmod m)
zero one add mul sub opp eq.
Section WithRing.
Context [
m :
Z].
Add Ring __Private__Zmod_base_ring : (
ring_theory m).
Implicit Types a b c :
Zmod m.
Lemma opp_0 :
opp zero = zero :> Zmod m.
Lemma add_0_r a :
add a zero = a.
Lemma sub_0_l a :
sub zero a = opp a.
Lemma sub_0_r a :
sub a zero = a.
Lemma mul_1_r a :
mul a one = a.
Lemma mul_m1_l a :
mul (
opp one)
a = opp a.
Lemma mul_m1_r a :
mul a (
opp one)
= opp a.
Lemma mul_0_l a :
mul zero a = zero.
Lemma mul_0_r a :
mul a zero = zero.
Lemma opp_opp a :
opp (
opp a)
= a.
Lemma opp_inj a b :
opp a = opp b -> a = b.
Lemma opp_inj_iff a b :
opp a = opp b <-> a = b.
Lemma add_opp_l a b :
add (
opp a)
b = sub b a.
Lemma sub_opp_r a b :
sub a (
opp b)
= add a b.
Lemma sub_opp_l a b :
sub (
opp a)
b = opp (
add a b).
Lemma add_sub_r a b c :
add a (
sub b c)
= sub (
add a b)
c.
Lemma add_sub_l a b c :
add (
sub a b)
c = sub (
add a c)
b.
Lemma sub_sub_r a b c :
sub a (
sub b c)
= sub (
add a c)
b.
Lemma sub_sub_l a b c :
sub (
sub a b)
c = sub a (
add b c).
Lemma mul_add_r a b c :
mul a (
add b c)
= add (
mul a b) (
mul a c).
Lemma add_opp_same_l a : @
add m (
opp a)
a = zero.
Lemma mul_sub_l a b c :
mul (
sub a b)
c = sub (
mul a c) (
mul b c).
Lemma mul_sub_r a b c :
mul a (
sub b c)
= sub (
mul a b) (
mul a c).
Lemma mul_opp_l a b :
mul (
opp a)
b = opp (
mul a b).
Lemma mul_opp_r a b :
mul a (
opp b)
= opp (
mul a b).
Lemma mul_opp_opp a b :
mul (
opp a) (
opp b)
= mul a b.
Local Lemma square_roots_opp_prime_subproof a b :
sub (
mul a a) (
mul b b)
= mul (
sub a (
opp b)) (
sub a b).
End WithRing.
Properties of division operators
Lemmas for equalities with different moduli
Elements