Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(************************************************************************) (* * The Coq Proof Assistant / The Coq Development Team *) (* v * INRIA, CNRS and contributors - Copyright 1999-2018 *) (* <O___,, * (see CREDITS file for the list of authors) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************) Require Import ZAxioms ZMulOrder ZSgnAbs NZDiv.
Euclidean Division for integers (Trunc convention)
Module Type ZQuotProp
(Import A : ZAxiomsSig')
(Import B : ZMulOrderProp A)
(Import C : ZSgnAbsProp A B).
We benefit from what already exists for NZ
Module Import Private_Div. Module Quot2Div <: NZDiv A. Definition div := quot. Definition modulo := A.rem. Definition div_wd := quot_wd. Definition mod_wd := rem_wd. Definition div_mod := quot_rem. Definition mod_bound_pos := rem_bound_pos. End Quot2Div. Module NZQuot := Nop <+ NZDivProp A Quot2Div B. End Private_Div. Ltac pos_or_neg a := let LT := fresh "LT" in let LE := fresh "LE" in destruct (le_gt_cases 0 a) as [LE|LT]; [|rewrite <- opp_pos_neg in LT].
Another formulation of the main equation
forall a b : t, b ~= 0 -> a rem b == a - b * (a ÷ b)forall a b : t, b ~= 0 -> a rem b == a - b * (a ÷ b)a, b:tH:b ~= 0a rem b == a - b * (a ÷ b)a, b:tH:b ~= 0b * (a ÷ b) + a rem b == anow apply quot_rem. Qed.a, b:tH:b ~= 0a == b * (a ÷ b) + a rem b
A few sign rules (simple ones)
forall a b : t, b ~= 0 -> - a rem - b == - (a rem b)forall a b : t, b ~= 0 -> - a rem - b == - (a rem b)now rewrite rem_opp_r, rem_opp_l. Qed.a, b:tH:b ~= 0- a rem - b == - (a rem b)forall a b : t, b ~= 0 -> - a ÷ b == - (a ÷ b)forall a b : t, b ~= 0 -> - a ÷ b == - (a ÷ b)a, b:tH:b ~= 0- a ÷ b == - (a ÷ b)a, b:tH:b ~= 0b * (- a ÷ b) == b * - (a ÷ b)now rewrite <- quot_rem, rem_opp_l, mul_opp_r, <- opp_add_distr, <- quot_rem. Qed.a, b:tH:b ~= 0b * (- a ÷ b) + - a rem b == b * - (a ÷ b) + - a rem bforall a b : t, b ~= 0 -> a ÷ - b == - (a ÷ b)forall a b : t, b ~= 0 -> a ÷ - b == - (a ÷ b)a, b:tH:b ~= 0a ÷ - b == - (a ÷ b)a, b:tH:b ~= 0H0:- b ~= 0a ÷ - b == - (a ÷ b)a, b:tH:b ~= 0H0:- b ~= 0- b * (a ÷ - b) == - b * - (a ÷ b)now rewrite <- quot_rem, rem_opp_r, mul_opp_opp, <- quot_rem. Qed.a, b:tH:b ~= 0H0:- b ~= 0- b * (a ÷ - b) + a rem - b == - b * - (a ÷ b) + a rem - bforall a b : t, b ~= 0 -> - a ÷ - b == a ÷ bforall a b : t, b ~= 0 -> - a ÷ - b == a ÷ bnow rewrite quot_opp_r, quot_opp_l, opp_involutive. Qed.a, b:tH:b ~= 0- a ÷ - b == a ÷ b
Uniqueness theorems
forall b q1 q2 r1 r2 : t, 0 <= r1 < b \/ b < r1 <= 0 -> 0 <= r2 < b \/ b < r2 <= 0 -> b * q1 + r1 == b * q2 + r2 -> q1 == q2 /\ r1 == r2forall b q1 q2 r1 r2 : t, 0 <= r1 < b \/ b < r1 <= 0 -> 0 <= r2 < b \/ b < r2 <= 0 -> b * q1 + r1 == b * q2 + r2 -> q1 == q2 /\ r1 == r2b, q1, q2, r1, r2:tHr1:0 <= r1 < b \/ b < r1 <= 0Hr2:0 <= r2 < b \/ b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r2q1 == q2 /\ r1 == r2b, q1, q2, r1, r2:tH:0 <= r1 < bH0:0 <= r2 < bEQ:b * q1 + r1 == b * q2 + r2q1 == q2 /\ r1 == r2b, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r2q1 == q2 /\ r1 == r2b, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r2q1 == q2 /\ r1 == r2b, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r2q1 == q2 /\ - r1 == - r2b, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r20 <= - r1 < - bb, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r20 <= - r2 < - bb, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r2- b * q1 + - r1 == - b * q2 + - r2b, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r20 <= - r2 < - bb, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r2- b * q1 + - r1 == - b * q2 + - r2now rewrite 2 mul_opp_l, <- 2 opp_add_distr, opp_inj_wd. Qed.b, q1, q2, r1, r2:tH:b < r1 <= 0H0:b < r2 <= 0EQ:b * q1 + r1 == b * q2 + r2- b * q1 + - r1 == - b * q2 + - r2forall a b q r : t, 0 <= a -> 0 <= r < b -> a == b * q + r -> q == a ÷ bintros; now apply NZQuot.div_unique with r. Qed.forall a b q r : t, 0 <= a -> 0 <= r < b -> a == b * q + r -> q == a ÷ bforall a b q r : t, 0 <= a -> 0 <= r < b -> a == b * q + r -> r == a rem bintros; now apply NZQuot.mod_unique with q. Qed.forall a b q r : t, 0 <= a -> 0 <= r < b -> a == b * q + r -> r == a rem b
A division by itself returns 1
forall a : t, a ~= 0 -> a ÷ a == 1forall a : t, a ~= 0 -> a ÷ a == 1a:tH:a ~= 0a ÷ a == 1a:tH:a ~= 0LE:0 <= aa ÷ a == 1a:tH:a ~= 0LT:0 < - aa ÷ a == 1a:tH:a ~= 0LT:0 < - aa ÷ a == 1now apply NZQuot.div_same. Qed.a:tH:a ~= 0LT:0 < - a- a ÷ - a == 1forall a : t, a ~= 0 -> a rem a == 0forall a : t, a ~= 0 -> a rem a == 0a:tH:a ~= 0a rem a == 0a:tH:a ~= 0a - a * 1 == 0apply sub_diag. Qed.a:tH:a ~= 0a - a == 0
A division of a small number by a bigger one yields zero.
forall a b : t, 0 <= a < b -> a ÷ b == 0exact NZQuot.div_small. Qed.forall a b : t, 0 <= a < b -> a ÷ b == 0
Same situation, in term of remulo:
forall a b : t, 0 <= a < b -> a rem b == aexact NZQuot.mod_small. Qed.forall a b : t, 0 <= a < b -> a rem b == a
forall a : t, a ~= 0 -> 0 ÷ a == 0forall a : t, a ~= 0 -> 0 ÷ a == 0a:tH:a ~= 00 ÷ a == 0a:tH:a ~= 0LE:0 <= a0 ÷ a == 0a:tH:a ~= 0LT:0 < - a0 ÷ a == 0a:tH:a ~= 0LT:0 < - a0 ÷ a == 0now apply NZQuot.div_0_l. Qed.a:tH:a ~= 0LT:0 < - a0 ÷ - a == 0forall a : t, a ~= 0 -> 0 rem a == 0intros; rewrite rem_eq, quot_0_l; now nzsimpl. Qed.forall a : t, a ~= 0 -> 0 rem a == 0forall a : t, a ÷ 1 == aforall a : t, a ÷ 1 == aa:ta ÷ 1 == aa:tLE:0 <= aa ÷ 1 == aa:tLT:0 < - aa ÷ 1 == aa:tLT:0 < - aa ÷ 1 == aa:tLT:0 < - a- (a ÷ 1) == - aa:tLT:0 < - a- a ÷ 1 == - aa:tLT:0 < - a1 ~= 0intro EQ; symmetry in EQ; revert EQ; apply lt_neq, lt_0_1. Qed.a:tLT:0 < - a1 ~= 0forall a : t, a rem 1 == 0forall a : t, a rem 1 == 0a:ta rem 1 == 0intro EQ; symmetry in EQ; revert EQ; apply lt_neq; apply lt_0_1. Qed.a:t1 ~= 0forall a : t, 1 < a -> 1 ÷ a == 0exact NZQuot.div_1_l. Qed.forall a : t, 1 < a -> 1 ÷ a == 0forall a : t, 1 < a -> 1 rem a == 1exact NZQuot.mod_1_l. Qed.forall a : t, 1 < a -> 1 rem a == 1forall a b : t, b ~= 0 -> a * b ÷ b == aforall a b : t, b ~= 0 -> a * b ÷ b == aa, b:tH:b ~= 0a * b ÷ b == aa, b:tH:b ~= 0LE:0 <= aLE0:0 <= ba * b ÷ b == aa, b:tH:b ~= 0LE:0 <= aLT:0 < - ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLE:0 <= ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba * b ÷ b == aa, b:tH:b ~= 0LE:0 <= aLT:0 < - ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLE:0 <= ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba * b ÷ b == aa, b:tH:b ~= 0LE:0 <= aLT:0 < - ba * - b ÷ - b == aa, b:tH:b ~= 0LT:0 < - aLE:0 <= ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLE:0 <= ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLE:0 <= b- a * b ÷ b == - aa, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba * b ÷ b == aa, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba * b ÷ b == aapply NZQuot.div_mul; order. Qed.a, b:tH:b ~= 0LT:0 < - aLT0:0 < - b- a * - b ÷ - b == - aforall a b : t, b ~= 0 -> (a * b) rem b == 0forall a b : t, b ~= 0 -> (a * b) rem b == 0a, b:tH:b ~= 0(a * b) rem b == 0rewrite mul_comm; apply sub_diag. Qed.a, b:tH:b ~= 0a * b - b * a == 0a, b, q:tb ~= 0 -> a == b * q -> q == a ÷ ba, b, q:tb ~= 0 -> a == b * q -> q == a ÷ ba, b, q:tHb:b ~= 0H:a == b * qq == a ÷ ba, b, q:tHb:b ~= 0H:a == b * qq == q * b ÷ bnow apply quot_mul. Qed.a, b, q:tHb:b ~= 0H:a == b * qq * b ÷ b == q
The sign of a rem b is the one of a (when it's not null)
forall a b : t, b ~= 0 -> 0 <= a -> 0 <= a rem bforall a b : t, b ~= 0 -> 0 <= a -> 0 <= a rem ba, b:tH:b ~= 0H0:0 <= a0 <= a rem ba, b:tH:b ~= 0H0:0 <= aLE:0 <= b0 <= a rem ba, b:tH:b ~= 0H0:0 <= aLT:0 < - b0 <= a rem ba, b:tH:b ~= 0H0:0 <= aLT:0 < - b0 <= a rem bdestruct (rem_bound_pos a (-b)); trivial. Qed.a, b:tH:b ~= 0H0:0 <= aLT:0 < - b0 <= a rem - bforall a b : t, b ~= 0 -> a <= 0 -> a rem b <= 0forall a b : t, b ~= 0 -> a <= 0 -> a rem b <= 0a, b:tHb:b ~= 0Ha:a <= 0a rem b <= 0a, b:tHb:b ~= 0Ha:a <= 00 <= - (a rem b)a, b:tHb:b ~= 0Ha:0 <= - a0 <= - (a rem b)now apply rem_nonneg. Qed.a, b:tHb:b ~= 0Ha:0 <= - a0 <= - a rem bforall a b : t, b ~= 0 -> 0 <= a rem b * aforall a b : t, b ~= 0 -> 0 <= a rem b * aa, b:tHb:b ~= 00 <= a rem b * aa, b:tHb:b ~= 0H:0 <= a0 <= a rem b * aa, b:tHb:b ~= 0H:a <= 00 <= a rem b * aa, b:tHb:b ~= 0H:0 <= a0 <= a rem ba, b:tHb:b ~= 0H:a <= 00 <= a rem b * aa, b:tHb:b ~= 0H:a <= 00 <= a rem b * anow apply rem_nonpos. Qed.a, b:tHb:b ~= 0H:a <= 0a rem b <= 0forall a b : t, b ~= 0 -> a rem b ~= 0 -> sgn (a rem b) == sgn aforall a b : t, b ~= 0 -> a rem b ~= 0 -> sgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0sgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:0 < asgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0EQ:0 == asgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:a < 0sgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:0 < a0 < a rem ba, b:tHb:b ~= 0H:a rem b ~= 0EQ:0 == asgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:a < 0sgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:0 < a0 <= a rem b -> 0 < a rem ba, b:tHb:b ~= 0H:a rem b ~= 0EQ:0 == asgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:a < 0sgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0EQ:0 == asgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:a < 0sgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:a < 0sgn (a rem b) == sgn aa, b:tHb:b ~= 0H:a rem b ~= 0LT:a < 0a rem b < 0order. Qed.a, b:tHb:b ~= 0H:a rem b ~= 0LT:a < 0a rem b <= 0 -> a rem b < 0forall a b : t, a ~= 0 -> b ~= 0 -> sgn (a rem b) ~= - sgn aforall a b : t, a ~= 0 -> b ~= 0 -> sgn (a rem b) ~= - sgn aa, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aFalsea, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aEQ:a rem b == 0Falsea, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0Falsea, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aEQ:a rem b == 0- sgn a == - 0a, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0Falsea, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0Falsea, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0sgn a == 0a, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0sgn a * 2 == 0a, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0sgn a + sgn a == 0a, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0sgn a == - sgn aa, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0sgn a == sgn (a rem b)now apply rem_sign_nz. Qed.a, b:tHa:a ~= 0Hb:b ~= 0H:sgn (a rem b) == - sgn aNEQ:a rem b ~= 0sgn (a rem b) == sgn a
Operations and absolute value
forall a b : t, b ~= 0 -> abs a rem b == abs (a rem b)forall a b : t, b ~= 0 -> abs a rem b == abs (a rem b)a, b:tHb:b ~= 0abs a rem b == abs (a rem b)a, b:tHb:b ~= 0LE:0 <= aabs a rem b == abs (a rem b)a, b:tHb:b ~= 0LE:a <= 0abs a rem b == abs (a rem b)a, b:tHb:b ~= 0LE:0 <= a0 <= a rem ba, b:tHb:b ~= 0LE:a <= 0abs a rem b == abs (a rem b)a, b:tHb:b ~= 0LE:a <= 0abs a rem b == abs (a rem b)now apply rem_nonpos. Qed.a, b:tHb:b ~= 0LE:a <= 0a rem b <= 0forall a b : t, b ~= 0 -> a rem abs b == a rem bforall a b : t, b ~= 0 -> a rem abs b == a rem ba, b:tHb:b ~= 0a rem abs b == a rem ba, b:tHb:b ~= 0H:0 <= ba rem abs b == a rem ba, b:tHb:b ~= 0H:b <= 0a rem abs b == a rem bnow rewrite abs_neq, ?rem_opp_r. Qed.a, b:tHb:b ~= 0H:b <= 0a rem abs b == a rem bforall a b : t, b ~= 0 -> abs a rem abs b == abs (a rem b)forall a b : t, b ~= 0 -> abs a rem abs b == abs (a rem b)now rewrite rem_abs_r, rem_abs_l. Qed.a, b:tH:b ~= 0abs a rem abs b == abs (a rem b)forall a b : t, b ~= 0 -> abs a ÷ b == sgn a * (a ÷ b)forall a b : t, b ~= 0 -> abs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0abs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0LT:0 < aabs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0EQ:0 == aabs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0LT:a < 0abs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0LT:0 < aa ÷ b == 1 * (a ÷ b)a, b:tHb:b ~= 0EQ:0 == aabs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0LT:a < 0abs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0EQ:0 == aabs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0LT:a < 0abs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0EQ:0 == a0 == sgn 0 * 0a, b:tHb:b ~= 0LT:a < 0abs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0LT:a < 0abs a ÷ b == sgn a * (a ÷ b)a, b:tHb:b ~= 0LT:a < 0- (a ÷ b) == -1 * (a ÷ b)now nzsimpl. Qed.a, b:tHb:b ~= 0LT:a < 0- (a ÷ b) == - (1 * (a ÷ b))forall a b : t, b ~= 0 -> a ÷ abs b == sgn b * (a ÷ b)forall a b : t, b ~= 0 -> a ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0a ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0LT:0 < ba ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0EQ:0 == ba ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0LT:b < 0a ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0LT:0 < ba ÷ b == 1 * (a ÷ b)a, b:tHb:b ~= 0EQ:0 == ba ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0LT:b < 0a ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0EQ:0 == ba ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0LT:b < 0a ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0LT:b < 0a ÷ abs b == sgn b * (a ÷ b)a, b:tHb:b ~= 0LT:b < 0- (a ÷ b) == -1 * (a ÷ b)now nzsimpl. Qed.a, b:tHb:b ~= 0LT:b < 0- (a ÷ b) == - (1 * (a ÷ b))forall a b : t, b ~= 0 -> abs a ÷ abs b == abs (a ÷ b)forall a b : t, b ~= 0 -> abs a ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0abs a ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0LE:0 <= aa ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - a- a ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0LE:0 <= aLE0:0 <= ba ÷ b == abs (a ÷ b)a, b:tHb:b ~= 0LE:0 <= aLT:0 < - ba ÷ - b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - a- a ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0LE:0 <= aLE0:0 <= b0 <= a ÷ ba, b:tHb:b ~= 0LE:0 <= aLT:0 < - ba ÷ - b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - a- a ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0LE:0 <= aLT:0 < - ba ÷ - b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - a- a ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0LE:0 <= aLT:0 < - b0 <= a ÷ - ba, b:tHb:b ~= 0LT:0 < - a- a ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - a- a ÷ abs b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - aLE:0 <= b- a ÷ b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - aLT0:0 < - b- a ÷ - b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - aLE:0 <= b0 <= - a ÷ ba, b:tHb:b ~= 0LT:0 < - aLT0:0 < - b- a ÷ - b == abs (a ÷ b)a, b:tHb:b ~= 0LT:0 < - aLT0:0 < - b- a ÷ - b == abs (a ÷ b)apply NZQuot.div_pos; order. Qed.a, b:tHb:b ~= 0LT:0 < - aLT0:0 < - b0 <= - a ÷ - b
We have a general bound for absolute values
forall a b : t, b ~= 0 -> abs (a rem b) < abs bforall a b : t, b ~= 0 -> abs (a rem b) < abs ba, b:tH:b ~= 0abs (a rem b) < abs ba, b:tH:b ~= 0abs a rem abs b < abs ba, b:tH:b ~= 00 <= abs aa, b:tH:b ~= 00 < abs bnow apply abs_pos. Qed.a, b:tH:b ~= 00 < abs b
A modulo cannot grow beyond its starting point.
forall a b : t, 0 <= a -> 0 < b -> a rem b <= aexact NZQuot.mod_le. Qed.forall a b : t, 0 <= a -> 0 < b -> a rem b <= aforall a b : t, 0 <= a -> 0 < b -> 0 <= a ÷ bexact NZQuot.div_pos. Qed.forall a b : t, 0 <= a -> 0 < b -> 0 <= a ÷ bforall a b : t, 0 < b <= a -> 0 < a ÷ bexact NZQuot.div_str_pos. Qed.forall a b : t, 0 < b <= a -> 0 < a ÷ bforall a b : t, b ~= 0 -> a ÷ b == 0 <-> abs a < abs bforall a b : t, b ~= 0 -> a ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0a ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LE:0 <= aLE0:0 <= ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LE:0 <= aLT:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLE:0 <= ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LE:0 <= aLE0:0 <= ba < b <-> abs a < abs ba, b:tH:b ~= 0LE:0 <= aLT:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLE:0 <= ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LE:0 <= aLT:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLE:0 <= ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LE:0 <= aLT:0 < - ba < - b <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLE:0 <= ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLE:0 <= ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLE:0 <= b- a < b <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba ÷ b == 0 <-> abs a < abs ba, b:tH:b ~= 0LT:0 < - aLT0:0 < - ba ÷ b == 0 <-> abs a < abs brewrite (abs_neq' a), (abs_neq' b); intuition; order. Qed.a, b:tH:b ~= 0LT:0 < - aLT0:0 < - b- a < - b <-> abs a < abs bforall a b : t, b ~= 0 -> a rem b == a <-> abs a < abs bforall a b : t, b ~= 0 -> a rem b == a <-> abs a < abs ba, b:tH:b ~= 0a rem b == a <-> abs a < abs ba, b:tH:b ~= 0a - b * (a ÷ b) == a <-> a ÷ b == 0a, b:tH:b ~= 0a + 0 == a + b * (a ÷ b) <-> a ÷ b == 0a, b:tH:b ~= 00 == b * (a ÷ b) <-> a ÷ b == 0tauto. Qed.a, b:tH:b ~= 0b == 0 \/ a ÷ b == 0 <-> a ÷ b == 0
As soon as the divisor is strictly greater than 1,
the division is strictly decreasing.
forall a b : t, 0 < a -> 1 < b -> a ÷ b < aexact NZQuot.div_lt. Qed.forall a b : t, 0 < a -> 1 < b -> a ÷ b < a
le is compatible with a positive division.
forall a b c : t, 0 < c -> a <= b -> a ÷ c <= b ÷ cforall a b c : t, 0 < c -> a <= b -> a ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= ba ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLE:0 <= aa ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aa ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aa ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLE:0 <= ba ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLT0:0 < - ba ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLE:0 <= ba ÷ c <= 0a, b, c:tH:0 < cH0:a <= bLT:0 < - aLE:0 <= b0 <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLT0:0 < - ba ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLE:0 <= b0 <= - a ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLE:0 <= b0 <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLT0:0 < - ba ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLE:0 <= b0 <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLT0:0 < - ba ÷ c <= b ÷ ca, b, c:tH:0 < cH0:a <= bLT:0 < - aLT0:0 < - ba ÷ c <= b ÷ ca, b, c:tH:0 < cH0:- b <= - aLT:0 < - aLT0:0 < - b- (b ÷ c) <= - (a ÷ c)apply NZQuot.div_le_mono; intuition; order. Qed.a, b, c:tH:0 < cH0:- b <= - aLT:0 < - aLT0:0 < - b- b ÷ c <= - a ÷ c
With this choice of division,
rounding of quot is always done toward zero:
forall a b : t, 0 <= a -> b ~= 0 -> 0 <= b * (a ÷ b) <= aforall a b : t, 0 <= a -> b ~= 0 -> 0 <= b * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 00 <= b * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 0LE:0 <= b0 <= b * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 0LT:0 < - b0 <= b * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 0LE:0 <= b0 <= b * (a ÷ b)a, b:tH:0 <= aH0:b ~= 0LE:0 <= bb * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 0LT:0 < - b0 <= b * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 0LE:0 <= bb * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 0LT:0 < - b0 <= b * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 0LT:0 < - b0 <= b * (a ÷ b) <= aa, b:tH:0 <= aH0:b ~= 0LT:0 < - b0 <= - b * (a ÷ - b) <= aa, b:tH:0 <= aH0:b ~= 0LT:0 < - b0 <= - b * (a ÷ - b)a, b:tH:0 <= aH0:b ~= 0LT:0 < - b- b * (a ÷ - b) <= aapply NZQuot.mul_div_le; order. Qed.a, b:tH:0 <= aH0:b ~= 0LT:0 < - b- b * (a ÷ - b) <= aforall a b : t, a <= 0 -> b ~= 0 -> a <= b * (a ÷ b) <= 0forall a b : t, a <= 0 -> b ~= 0 -> a <= b * (a ÷ b) <= 0a, b:tH:a <= 0H0:b ~= 0a <= b * (a ÷ b) <= 0a, b:tH:a <= 0H0:b ~= 0b * (- a ÷ b) <= - a /\ 0 <= b * (- a ÷ b)destruct (mul_quot_le (-a) b); tauto. Qed.a, b:tH:0 <= - aH0:b ~= 0b * (- a ÷ b) <= - a /\ 0 <= b * (- a ÷ b)
For positive numbers, considering S (a÷b) leads to an upper bound for a
forall a b : t, 0 <= a -> 0 < b -> a < b * S (a ÷ b)exact NZQuot.mul_succ_div_gt. Qed.forall a b : t, 0 <= a -> 0 < b -> a < b * S (a ÷ b)
Similar results with negative numbers
forall a b : t, a <= 0 -> 0 < b -> b * P (a ÷ b) < aforall a b : t, a <= 0 -> 0 < b -> b * P (a ÷ b) < aa, b:tH:a <= 0H0:0 < bb * P (a ÷ b) < aa, b:tH:a <= 0H0:0 < b- a < b * S (- a ÷ b)now apply mul_succ_quot_gt. Qed.a, b:tH:0 <= - aH0:0 < b- a < b * S (- a ÷ b)forall a b : t, 0 <= a -> b < 0 -> a < b * P (a ÷ b)forall a b : t, 0 <= a -> b < 0 -> a < b * P (a ÷ b)a, b:tH:0 <= aH0:b < 0a < b * P (a ÷ b)a, b:tH:0 <= aH0:b < 0a < - b * S (a ÷ - b)now apply mul_succ_quot_gt. Qed.a, b:tH:0 <= aH0:0 < - ba < - b * S (a ÷ - b)forall a b : t, a <= 0 -> b < 0 -> b * S (a ÷ b) < aforall a b : t, a <= 0 -> b < 0 -> b * S (a ÷ b) < aa, b:tH:a <= 0H0:b < 0b * S (a ÷ b) < aa, b:tH:a <= 0H0:b < 0- a < - b * S (- a ÷ - b)now apply mul_succ_quot_gt. Qed.a, b:tH:0 <= - aH0:0 < - b- a < - b * S (- a ÷ - b)
Inequality mul_quot_le is exact iff the modulo is zero.
forall a b : t, b ~= 0 -> a == b * (a ÷ b) <-> a rem b == 0forall a b : t, b ~= 0 -> a == b * (a ÷ b) <-> a rem b == 0a, b:tH:b ~= 0a == b * (a ÷ b) <-> a rem b == 0rewrite sub_move_r; nzsimpl; tauto. Qed.a, b:tH:b ~= 0a == b * (a ÷ b) <-> a - b * (a ÷ b) == 0
Some additional inequalities about quot.
forall a b q : t, 0 <= a -> 0 < b -> a < b * q -> a ÷ b < qexact NZQuot.div_lt_upper_bound. Qed.forall a b q : t, 0 <= a -> 0 < b -> a < b * q -> a ÷ b < qforall a b q : t, 0 < b -> a <= b * q -> a ÷ b <= qforall a b q : t, 0 < b -> a <= b * q -> a ÷ b <= qa, b, q:tH:0 < bH0:a <= b * qa ÷ b <= qa, b, q:tH:0 < bH0:a <= b * qa ÷ b <= q * b ÷ bnow rewrite mul_comm. Qed.a, b, q:tH:0 < bH0:a <= b * qa <= q * bforall a b q : t, 0 < b -> b * q <= a -> q <= a ÷ bforall a b q : t, 0 < b -> b * q <= a -> q <= a ÷ ba, b, q:tH:0 < bH0:b * q <= aq <= a ÷ ba, b, q:tH:0 < bH0:b * q <= aq * b ÷ b <= a ÷ bnow rewrite mul_comm. Qed.a, b, q:tH:0 < bH0:b * q <= aq * b <= a
A division respects opposite monotonicity for the divisor
forall p q r : t, 0 <= p -> 0 < q <= r -> p ÷ r <= p ÷ qexact NZQuot.div_le_compat_l. Qed.forall p q r : t, 0 <= p -> 0 < q <= r -> p ÷ r <= p ÷ q
Unlike with other division conventions, some results here aren't
always valid, and need to be restricted. For instance
(a+b×c) rem c ≠ a rem c for a=9,b=-5,c=2
forall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= a -> 0 <= a + b * c -> (a + b * c) rem c == a rem cH:forall a b c : t, c ~= 0 -> 0 <= a -> 0 <= a + b * c -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem ca, b, c:tH:c ~= 0H0:0 <= aH1:0 <= a + b * c(a + b * c) rem c == a rem cH:forall a b c : t, c ~= 0 -> 0 <= a -> 0 <= a + b * c -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem ca, b, c:tH:c ~= 0H0:0 <= aH1:0 <= a + b * cLE:0 <= c(a + b * c) rem c == a rem ca, b, c:tH:c ~= 0H0:0 <= aH1:0 <= a + b * cLT:0 < - c(a + b * c) rem c == a rem cH:forall a b c : t, c ~= 0 -> 0 <= a -> 0 <= a + b * c -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem ca, b, c:tH:c ~= 0H0:0 <= aH1:0 <= a + b * cLT:0 < - c(a + b * c) rem c == a rem cH:forall a b c : t, c ~= 0 -> 0 <= a -> 0 <= a + b * c -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem ca, b, c:tH:c ~= 0H0:0 <= aH1:0 <= a + b * cLT:0 < - c(a + b * c) rem - c == a rem - cH:forall a b c : t, c ~= 0 -> 0 <= a -> 0 <= a + b * c -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem ca, b, c:tH:c ~= 0H0:0 <= aH1:0 <= a + - b * - cLT:0 < - c(a + - b * - c) rem - c == a rem - cH:forall a b c : t, c ~= 0 -> 0 <= a -> 0 <= a + b * c -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem cH:forall a b c : t, c ~= 0 -> 0 <= a -> 0 <= a + b * c -> (a + b * c) rem c == a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) rem c == a rem cH:forall a0 b0 c0 : t, c0 ~= 0 -> 0 <= a0 -> 0 <= a0 + b0 * c0 -> (a0 + b0 * c0) rem c0 == a0 rem c0a, b, c:tHc:c ~= 0Habc:0 <= (a + b * c) * a(a + b * c) rem c == a rem cH:forall a0 b0 c0 : t, c0 ~= 0 -> 0 <= a0 -> 0 <= a0 + b0 * c0 -> (a0 + b0 * c0) rem c0 == a0 rem c0a, b, c:tHc:c ~= 0Habc:0 <= (a + b * c) * aHabc':0 <= a + b * cHa:0 <= a(a + b * c) rem c == a rem cH:forall a0 b0 c0 : t, c0 ~= 0 -> 0 <= a0 -> 0 <= a0 + b0 * c0 -> (a0 + b0 * c0) rem c0 == a0 rem c0a, b, c:tHc:c ~= 0Habc:0 <= (a + b * c) * aHabc':a + b * c <= 0Ha:a <= 0(a + b * c) rem c == a rem cH:forall a0 b0 c0 : t, c0 ~= 0 -> 0 <= a0 -> 0 <= a0 + b0 * c0 -> (a0 + b0 * c0) rem c0 == a0 rem c0a, b, c:tHc:c ~= 0Habc:0 <= (a + b * c) * aHabc':a + b * c <= 0Ha:a <= 0(a + b * c) rem c == a rem cH:forall a0 b0 c0 : t, c0 ~= 0 -> 0 <= a0 -> 0 <= a0 + b0 * c0 -> (a0 + b0 * c0) rem c0 == a0 rem c0a, b, c:tHc:c ~= 0Habc:0 <= (a + b * c) * aHabc':a + b * c <= 0Ha:a <= 0- ((a + b * c) rem c) == - (a rem c)H:forall a0 b0 c0 : t, c0 ~= 0 -> 0 <= a0 -> 0 <= a0 + b0 * c0 -> (a0 + b0 * c0) rem c0 == a0 rem c0a, b, c:tHc:c ~= 0Habc:0 <= (a + b * c) * aa <= 0 -> a + b * c <= 0 -> - ((a + b * c) rem c) == - (a rem c)H:forall a0 b0 c0 : t, c0 ~= 0 -> 0 <= a0 -> 0 <= a0 + b0 * c0 -> (a0 + b0 * c0) rem c0 == a0 rem c0a, b, c:tHc:c ~= 0Habc:0 <= (a + b * c) * a0 <= - a -> 0 <= - (a + b * c) -> - ((a + b * c) rem c) == - (a rem c)auto. Qed.H:forall a0 b0 c0 : t, c0 ~= 0 -> 0 <= a0 -> 0 <= a0 + b0 * c0 -> (a0 + b0 * c0) rem c0 == a0 rem c0a, b, c:tHc:c ~= 0Habc:0 <= (a + b * c) * a0 <= - a -> 0 <= - a + - b * c -> (- a + - b * c) rem c == - a rem cforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) ÷ c == a ÷ c + bforall a b c : t, c ~= 0 -> 0 <= (a + b * c) * a -> (a + b * c) ÷ c == a ÷ c + ba, b, c:tH:c ~= 0H0:0 <= (a + b * c) * a(a + b * c) ÷ c == a ÷ c + ba, b, c:tH:c ~= 0H0:0 <= (a + b * c) * ac * ((a + b * c) ÷ c) == c * (a ÷ c + b)a, b, c:tH:c ~= 0H0:0 <= (a + b * c) * ac * ((a + b * c) ÷ c) + (a + b * c) rem c == c * (a ÷ c + b) + (a + b * c) rem cnow rewrite mul_add_distr_l, add_shuffle0, <-quot_rem, mul_comm. Qed.a, b, c:tH:c ~= 0H0:0 <= (a + b * c) * aa + b * c == c * (a ÷ c + b) + a rem cforall a b c : t, b ~= 0 -> 0 <= (a * b + c) * c -> (a * b + c) ÷ b == a + c ÷ bforall a b c : t, b ~= 0 -> 0 <= (a * b + c) * c -> (a * b + c) ÷ b == a + c ÷ ba, b, c:tb ~= 0 -> 0 <= (a * b + c) * c -> (a * b + c) ÷ b == a + c ÷ bnow apply quot_add. Qed.a, b, c:tb ~= 0 -> 0 <= (c + a * b) * c -> (c + a * b) ÷ b == c ÷ b + a
Cancellations.
forall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ ba, b, c:tH:0 <= aH0:0 < bH1:c ~= 0a * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ ba, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LE:0 <= ca * c ÷ (b * c) == a ÷ ba, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - ca * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ ba, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - ca * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ ba, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - ca * - c ÷ (b * - c) == a ÷ ba, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - cb * c ~= 0Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ ba, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - cb * c ~= 0Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0a * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LE:0 <= ba * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - ba * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - ba * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - b- (a * c ÷ (b * c)) == - (a ÷ b)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - ba * c ÷ (- b * c) == a ÷ - bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - bb * c ~= 0Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - bb * c ~= 0Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> a * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:b ~= 0H0:c ~= 0a * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:b ~= 0H0:c ~= 0LE:0 <= aa * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - aa * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - aa * c ÷ (b * c) == a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - a- (a * c ÷ (b * c)) == - (a ÷ b)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - a- a * c ÷ (b * c) == - a ÷ bAux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - ab * c ~= 0rewrite <- neq_mul_0; intuition order. Qed.Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 * c0 ÷ (b0 * c0) == a0 ÷ b0a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - ab * c ~= 0forall a b c : t, b ~= 0 -> c ~= 0 -> c * a ÷ (c * b) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> c * a ÷ (c * b) == a ÷ brewrite !(mul_comm c); now apply quot_mul_cancel_r. Qed.a, b, c:tH:b ~= 0H0:c ~= 0c * a ÷ (c * b) == a ÷ bforall a b c : t, b ~= 0 -> c ~= 0 -> (a * c) rem (b * c) == a rem b * cforall a b c : t, b ~= 0 -> c ~= 0 -> (a * c) rem (b * c) == a rem b * ca, b, c:tH:b ~= 0H0:c ~= 0(a * c) rem (b * c) == a rem b * ca, b, c:tH:b ~= 0H0:c ~= 0H1:b * c ~= 0(a * c) rem (b * c) == a rem b * ca, b, c:tH:b ~= 0H0:c ~= 0H1:b * c ~= 0a * c - b * c * (a * c ÷ (b * c)) == (a - b * (a ÷ b)) * cnow rewrite mul_sub_distr_r, <- !mul_assoc, (mul_comm (a÷b) c). Qed.a, b, c:tH:b ~= 0H0:c ~= 0H1:b * c ~= 0a * c - b * c * (a ÷ b) == (a - b * (a ÷ b)) * cforall a b c : t, b ~= 0 -> c ~= 0 -> (c * a) rem (c * b) == c * (a rem b)intros; rewrite !(mul_comm c); now apply mul_rem_distr_r. Qed.forall a b c : t, b ~= 0 -> c ~= 0 -> (c * a) rem (c * b) == c * (a rem b)
Operations modulo.
forall a n : t, n ~= 0 -> (a rem n) rem n == a rem nforall a n : t, n ~= 0 -> (a rem n) rem n == a rem na, n:tH:n ~= 0(a rem n) rem n == a rem na, n:tH:n ~= 0LE:0 <= aLE0:0 <= n(a rem n) rem n == a rem na, n:tH:n ~= 0LE:0 <= aLT:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLE:0 <= n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLT0:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LE:0 <= aLT:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLE:0 <= n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLT0:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LE:0 <= aLT:0 < - n(a rem - n) rem - n == a rem - na, n:tH:n ~= 0LT:0 < - aLE:0 <= n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLT0:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLE:0 <= n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLT0:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLE:0 <= n- ((a rem n) rem n) == - (a rem n)a, n:tH:n ~= 0LT:0 < - aLT0:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLE:0 <= n(- a rem n) rem n == - a rem na, n:tH:n ~= 0LT:0 < - aLT0:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLT0:0 < - n(a rem n) rem n == a rem na, n:tH:n ~= 0LT:0 < - aLT0:0 < - n- ((a rem n) rem n) == - (a rem n)apply NZQuot.mod_mod; order. Qed.a, n:tH:n ~= 0LT:0 < - aLT0:0 < - n(- a rem - n) rem - n == - a rem - nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0(a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0LE:0 <= n(a rem n * b) rem n == (a * b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0LT:0 < - n(a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0LT:0 < - n(a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0LT:0 < - n(a rem - n * b) rem - n == (a * b) rem - nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, 0 <= a -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux2:forall a b n : t, 0 <= a -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tH:0 <= aH0:n ~= 0(a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux2:forall a b n : t, 0 <= a -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tH:0 <= aH0:n ~= 0LE:0 <= b(a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tH:0 <= aH0:n ~= 0LT:0 < - b(a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux2:forall a b n : t, 0 <= a -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tH:0 <= aH0:n ~= 0LT:0 < - b(a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux2:forall a b n : t, 0 <= a -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tH:0 <= aH0:n ~= 0LT:0 < - b- ((a rem n * b) rem n) == - ((a * b) rem n)Aux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux2:forall a b n : t, 0 <= a -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tH:0 <= aH0:n ~= 0LT:0 < - b(a rem n * - b) rem n == (a * - b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux2:forall a b n : t, 0 <= a -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux2:forall a b n : t, 0 <= a -> n ~= 0 -> (a rem n * b) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0Aux2:forall a0 b0 n0 : t, 0 <= a0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tHn:n ~= 0(a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0Aux2:forall a0 b0 n0 : t, 0 <= a0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tHn:n ~= 0LE:0 <= a(a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0Aux2:forall a0 b0 n0 : t, 0 <= a0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tHn:n ~= 0LT:0 < - a(a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0Aux2:forall a0 b0 n0 : t, 0 <= a0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tHn:n ~= 0LT:0 < - a(a rem n * b) rem n == (a * b) rem nAux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0Aux2:forall a0 b0 n0 : t, 0 <= a0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tHn:n ~= 0LT:0 < - a- ((a rem n * b) rem n) == - ((a * b) rem n)apply Aux2; order. Qed.Aux1:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0Aux2:forall a0 b0 n0 : t, 0 <= a0 -> n0 ~= 0 -> (a0 rem n0 * b0) rem n0 == (a0 * b0) rem n0a, b, n:tHn:n ~= 0LT:0 < - a(- a rem n * b) rem n == (- a * b) rem nforall a b n : t, n ~= 0 -> (a * (b rem n)) rem n == (a * b) rem nforall a b n : t, n ~= 0 -> (a * (b rem n)) rem n == (a * b) rem na, b, n:tH:n ~= 0(a * (b rem n)) rem n == (a * b) rem nnow apply mul_rem_idemp_l. Qed.a, b, n:tH:n ~= 0(b rem n * a) rem n == (b * a) rem nforall a b n : t, n ~= 0 -> (a * b) rem n == (a rem n * (b rem n)) rem nforall a b n : t, n ~= 0 -> (a * b) rem n == (a rem n * (b rem n)) rem nnow rewrite mul_rem_idemp_l, mul_rem_idemp_r. Qed.a, b, n:tH:n ~= 0(a * b) rem n == (a rem n * (b rem n)) rem n
addition and modulo
Generally speaking, unlike with other conventions, we don't have
(a+b) rem n = (a rem n + b rem n) rem n
for any a and b.
For instance, take (8 + (-10)) rem 3 = -2 whereas
(8 rem 3 + (-10 rem 3)) rem 3 = 1.
forall a b n : t, n ~= 0 -> 0 <= a * b -> (a rem n + b) rem n == (a + b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a rem n + b) rem n == (a + b) rem nforall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n + b) rem n == (a + b) rem nAux:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n + b) rem n == (a + b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a rem n + b) rem n == (a + b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0(a rem n + b) rem n == (a + b) rem nAux:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n + b) rem n == (a + b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a rem n + b) rem n == (a + b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0LE:0 <= n(a rem n + b) rem n == (a + b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0LT:0 < - n(a rem n + b) rem n == (a + b) rem nAux:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n + b) rem n == (a + b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a rem n + b) rem n == (a + b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0LT:0 < - n(a rem n + b) rem n == (a + b) rem nAux:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n + b) rem n == (a + b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a rem n + b) rem n == (a + b) rem na, b, n:tH:0 <= aH0:0 <= bH1:n ~= 0LT:0 < - n(a rem - n + b) rem - n == (a + b) rem - nAux:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n + b) rem n == (a + b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a rem n + b) rem n == (a + b) rem nAux:forall a b n : t, 0 <= a -> 0 <= b -> n ~= 0 -> (a rem n + b) rem n == (a + b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a rem n + b) rem n == (a + b) rem nAux:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 + b0) rem n0 == (a0 + b0) rem n0a, b, n:tHn:n ~= 0Hab:0 <= a * b(a rem n + b) rem n == (a + b) rem nAux:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 + b0) rem n0 == (a0 + b0) rem n0a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:0 <= aHb:0 <= b(a rem n + b) rem n == (a + b) rem nAux:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 + b0) rem n0 == (a0 + b0) rem n0a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0(a rem n + b) rem n == (a + b) rem nAux:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 + b0) rem n0 == (a0 + b0) rem n0a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0(a rem n + b) rem n == (a + b) rem nAux:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 + b0) rem n0 == (a0 + b0) rem n0a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0- ((a rem n + b) rem n) == - ((a + b) rem n)Aux:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 + b0) rem n0 == (a0 + b0) rem n0a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0(- a rem n + - b) rem n == (- a + - b) rem nnow apply Aux. Qed.Aux:forall a0 b0 n0 : t, 0 <= a0 -> 0 <= b0 -> n0 ~= 0 -> (a0 rem n0 + b0) rem n0 == (a0 + b0) rem n0a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:0 <= - aHb:0 <= - b(- a rem n + - b) rem n == (- a + - b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a + b rem n) rem n == (a + b) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a + b rem n) rem n == (a + b) rem na, b, n:tH:n ~= 0H0:0 <= a * b(a + b rem n) rem n == (a + b) rem na, b, n:tH:n ~= 0H0:0 <= a * b(b rem n + a) rem n == (b + a) rem nnow rewrite mul_comm. Qed.a, b, n:tH:n ~= 0H0:0 <= a * b0 <= b * aforall a b n : t, n ~= 0 -> 0 <= a * b -> (a + b) rem n == (a rem n + b rem n) rem nforall a b n : t, n ~= 0 -> 0 <= a * b -> (a + b) rem n == (a rem n + b rem n) rem na, b, n:tHn:n ~= 0Hab:0 <= a * b(a + b) rem n == (a rem n + b rem n) rem na, b, n:tHn:n ~= 0Hab:0 <= a * b(a + b) rem n == (a + b) rem na, b, n:tHn:n ~= 0Hab:0 <= a * b0 <= a * (b rem n)a, b, n:tHn:n ~= 0Hab:0 <= a * b0 <= a * (b rem n)a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:0 <= aHb:0 <= bHb':b rem n <= 0Hm:b <= 00 <= a * (b rem n)a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0Hb':0 <= b rem nHm:0 <= b0 <= a * (b rem n)a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:0 <= aHb:0 <= bHb':b rem n <= 0Hm:b <= 00 <= a * (0 rem n)a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0Hb':0 <= b rem nHm:0 <= b0 <= a * (b rem n)a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:0 <= aHb:0 <= bHb':b rem n <= 0Hm:b <= 00 <= a * 0a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0Hb':0 <= b rem nHm:0 <= b0 <= a * (b rem n)a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0Hb':0 <= b rem nHm:0 <= b0 <= a * (b rem n)a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0Hb':0 <= b rem nHm:0 <= b0 <= a * (0 rem n)nzsimpl; order. Qed.a, b, n:tHn:n ~= 0Hab:0 <= a * bHa:a <= 0Hb:b <= 0Hb':0 <= b rem nHm:0 <= b0 <= a * 0
Conversely, the following results need less restrictions here.
forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)a, b, c:tH:0 <= aH0:0 < bH1:c ~= 0a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)a, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LE:0 <= ca ÷ b ÷ c == a ÷ (b * c)a, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - ca ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)a, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - ca ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)a, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - c- (a ÷ b ÷ c) == - (a ÷ (b * c))Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)a, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - ca ÷ b ÷ - c == a ÷ (b * - c)a, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - cb * c ~= 0Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)a, b, c:tH:0 <= aH0:0 < bH1:c ~= 0LT:0 < - cb * c ~= 0Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LE:0 <= ba ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - ba ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - ba ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - b- (a ÷ b ÷ c) == - (a ÷ (b * c))Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - ba ÷ - b ÷ c == a ÷ (- b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - bb * c ~= 0Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:0 <= aH0:b ~= 0H1:c ~= 0LT:0 < - bb * c ~= 0Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a b c : t, 0 <= a -> 0 < b -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux2:forall a b c : t, 0 <= a -> b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)forall a b c : t, b ~= 0 -> c ~= 0 -> a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0a ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0LE:0 <= aa ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - aa ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - aa ÷ b ÷ c == a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - a- (a ÷ b ÷ c) == - (a ÷ (b * c))Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - a- a ÷ b ÷ c == - a ÷ (b * c)Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - ab * c ~= 0Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - ab * c ~= 0tauto. Qed.Aux1:forall a0 b0 c0 : t, 0 <= a0 -> 0 < b0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)Aux2:forall a0 b0 c0 : t, 0 <= a0 -> b0 ~= 0 -> c0 ~= 0 -> a0 ÷ b0 ÷ c0 == a0 ÷ (b0 * c0)a, b, c:tH:b ~= 0H0:c ~= 0LT:0 < - ab ~= 0 /\ c ~= 0forall a b c : t, b ~= 0 -> c ~= 0 -> a rem (b * c) == a rem b + b * ((a ÷ b) rem c)forall a b c : t, b ~= 0 -> c ~= 0 -> a rem (b * c) == a rem b + b * ((a ÷ b) rem c)a, b, c:tHb:b ~= 0Hc:c ~= 0a rem (b * c) == a rem b + b * ((a ÷ b) rem c)a, b, c:tHb:b ~= 0Hc:c ~= 0b * c * (a ÷ (b * c)) + a rem (b * c) == b * c * (a ÷ (b * c)) + (a rem b + b * ((a ÷ b) rem c))a, b, c:tHb:b ~= 0Hc:c ~= 0a == b * c * (a ÷ (b * c)) + (a rem b + b * ((a ÷ b) rem c))a, b, c:tHb:b ~= 0Hc:c ~= 0a == b * c * (a ÷ b ÷ c) + (a rem b + b * ((a ÷ b) rem c))a, b, c:tHb:b ~= 0Hc:c ~= 0a == b * (c * (a ÷ b ÷ c) + (a ÷ b) rem c) + a rem bapply quot_rem; order. Qed.a, b, c:tHb:b ~= 0Hc:c ~= 0a == b * (a ÷ b) + a rem bforall a b : t, b ~= 0 -> a rem b ÷ b == 0forall a b : t, b ~= 0 -> a rem b ÷ b == 0a, b:tHb:b ~= 0a rem b ÷ b == 0auto using rem_bound_abs. Qed.a, b:tHb:b ~= 0abs (a rem b) < abs b
A last inequality:
forall a b c : t, 0 <= a -> 0 < b -> 0 <= c -> c * (a ÷ b) <= c * a ÷ bexact NZQuot.div_mul_le. Qed. End ZQuotProp.forall a b c : t, 0 <= a -> 0 < b -> 0 <= c -> c * (a ÷ b) <= c * a ÷ b