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.
This file is part of the Flocq formalization of floating-point
arithmetic in Coq: http://flocq.gforge.inria.fr/
Copyright (C) 2011-2018 Sylvie Boldo
Copyright (C) 2011-2018 Guillaume Melquiond
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
COPYING file for more details.
Copyright (C) 2011-2018 Guillaume Melquiond
From Coq Require Import ZArith Lia Zquot. Require Import SpecFloatCompat. Notation cond_Zopp := cond_Zopp (only parsing). Notation iter_pos := iter_pos (only parsing). Section Zmissing.
About Z
forall x y : Z, (- y <= - x)%Z -> (x <= y)%Zforall x y : Z, (- y <= - x)%Z -> (x <= y)%Zx, y:ZHxy:(- y <= - x)%Z(x <= y)%Znow ring_simplify. Qed.x, y:ZHxy:(- y <= - x)%Z(x + (- x - y) <= y + (- x - y))%Zforall x y : Z, (y < x)%Z -> x <> yforall x y : Z, (y < x)%Z -> x <> yx, y:ZH:(y < x)%ZHn:x = yFalsenow rewrite Hn at 1. Qed. End Zmissing. Section Proof_Irrelevance. Scheme eq_dep_elim := Induction for eq Sort Type. Definition eqbool_dep P (h1 : P true) b := match b return P b -> Prop with | true => fun (h2 : P true) => h1 = h2 | false => fun (h2 : P false) => False end.x, y:ZH:(y < x)%ZHn:x = y(x < x)%Zforall (b : bool) (h1 h2 : b = true), h1 = h2forall (b : bool) (h1 h2 : b = true), h1 = h2forall h : true = true, eq_refl = hH:forall h : true = true, eq_refl = hforall (b : bool) (h1 h2 : b = true), h1 = h2H:forall h : true = true, eq_refl = hforall (b : bool) (h1 h2 : b = true), h1 = h2H:forall h : true = true, eq_refl = hb:boolforall h1 h2 : b = true, h1 = h2H:forall h : true = true, eq_refl = hb:boolforall h1 h2 : true = true, h1 = h2H:forall h : true = true, eq_refl = hb:boolforall h1 h2 : false = true, h1 = h2H:forall h : true = true, eq_refl = hb:boolh1, h2:true = trueh1 = h2H:forall h : true = true, eq_refl = hb:boolforall h1 h2 : false = true, h1 = h2H:forall h : true = true, eq_refl = hb:boolforall h1 h2 : false = true, h1 = h2discriminate h. Qed. End Proof_Irrelevance. Section Even_Odd.H:forall h0 : true = true, eq_refl = h0b:boolh:false = trueforall h2 : false = true, h = h2forall x : Z, exists p : Z, x = (2 * p + (if Z.even x then 0 else 1))%Zforall x : Z, exists p : Z, x = (2 * p + (if Z.even x then 0 else 1))%Zexists p : Z, 0%Z = (2 * p + (if Z.even 0 then 0 else 1))%Zn:positiveexists p : Z, Z.pos n~1 = (2 * p + (if Z.even (Z.pos n~1) then 0 else 1))%Zn:positiveexists p : Z, Z.pos n~0 = (2 * p + (if Z.even (Z.pos n~0) then 0 else 1))%Zexists p : Z, 1%Z = (2 * p + (if Z.even 1 then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~1 = (2 * p + (if Z.even (Z.neg n~1) then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~0 = (2 * p + (if Z.even (Z.neg n~0) then 0 else 1))%Zexists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Zn:positiveexists p : Z, Z.pos n~1 = (2 * p + (if Z.even (Z.pos n~1) then 0 else 1))%Zn:positiveexists p : Z, Z.pos n~0 = (2 * p + (if Z.even (Z.pos n~0) then 0 else 1))%Zexists p : Z, 1%Z = (2 * p + (if Z.even 1 then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~1 = (2 * p + (if Z.even (Z.neg n~1) then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~0 = (2 * p + (if Z.even (Z.neg n~0) then 0 else 1))%Zexists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Zn:positiveexists p : Z, Z.pos n~0 = (2 * p + (if Z.even (Z.pos n~0) then 0 else 1))%Zexists p : Z, 1%Z = (2 * p + (if Z.even 1 then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~1 = (2 * p + (if Z.even (Z.neg n~1) then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~0 = (2 * p + (if Z.even (Z.neg n~0) then 0 else 1))%Zexists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Zexists p : Z, 1%Z = (2 * p + (if Z.even 1 then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~1 = (2 * p + (if Z.even (Z.neg n~1) then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~0 = (2 * p + (if Z.even (Z.neg n~0) then 0 else 1))%Zexists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~1 = (2 * p + (if Z.even (Z.neg n~1) then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~0 = (2 * p + (if Z.even (Z.neg n~0) then 0 else 1))%Zexists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Zn:positiveZ.neg n~1 = (2 * (Z.neg n - 1) + (if Z.even (Z.neg n~1) then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~0 = (2 * p + (if Z.even (Z.neg n~0) then 0 else 1))%Zexists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Zn:positive(2 * Z.neg n - 1)%Z = (2 * (Z.neg n - 1) + 1)%Zn:positiveexists p : Z, Z.neg n~0 = (2 * p + (if Z.even (Z.neg n~0) then 0 else 1))%Zexists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Zn:positiveexists p : Z, Z.neg n~0 = (2 * p + (if Z.even (Z.neg n~0) then 0 else 1))%Zexists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Znow exists (-1)%Z. Qed. End Even_Odd. Section Zpower.exists p : Z, (-1)%Z = (2 * p + (if Z.even (-1) then 0 else 1))%Zforall n k1 k2 : Z, (0 <= k1)%Z -> (0 <= k2)%Z -> (n ^ (k1 + k2))%Z = (n ^ k1 * n ^ k2)%Zforall n k1 k2 : Z, (0 <= k1)%Z -> (0 <= k2)%Z -> (n ^ (k1 + k2))%Z = (n ^ k1 * n ^ k2)%Znow apply Zpower_exp ; apply Z.le_ge. Qed.n, k1, k2:ZH1:(0 <= k1)%ZH2:(0 <= k2)%Z(n ^ (k1 + k2))%Z = (n ^ k1 * n ^ k2)%Zforall b e : Z, (0 <= e)%Z -> (b ^ e)%Z = Zpower_nat b (Z.abs_nat e)forall b e : Z, (0 <= e)%Z -> (b ^ e)%Z = Zpower_nat b (Z.abs_nat e)b:ZHe:(0 <= 0)%Z(b ^ 0)%Z = Zpower_nat b (Z.abs_nat 0)b:Ze:positiveHe:(0 <= Z.pos e)%Z(b ^ Z.pos e)%Z = Zpower_nat b (Z.abs_nat (Z.pos e))b:Ze:positiveHe:(0 <= Z.neg e)%Z(b ^ Z.neg e)%Z = Zpower_nat b (Z.abs_nat (Z.neg e))b:Ze:positiveHe:(0 <= Z.pos e)%Z(b ^ Z.pos e)%Z = Zpower_nat b (Z.abs_nat (Z.pos e))b:Ze:positiveHe:(0 <= Z.neg e)%Z(b ^ Z.neg e)%Z = Zpower_nat b (Z.abs_nat (Z.neg e))b:Ze:positiveHe:(0 <= Z.neg e)%Z(b ^ Z.neg e)%Z = Zpower_nat b (Z.abs_nat (Z.neg e))apply refl_equal. Qed.b:Ze:positiveHe:(0 <= Z.neg e)%Z(0 ?= Z.neg e)%Z = Gtforall (b : Z) (e : nat), Zpower_nat b (S e) = (b * Zpower_nat b e)%Zforall (b : Z) (e : nat), Zpower_nat b (S e) = (b * Zpower_nat b e)%Zb:Ze:natZpower_nat b (S e) = (b * Zpower_nat b e)%Zb:Ze:nat(Zpower_nat b 1 * Zpower_nat b e)%Z = (b * Zpower_nat b e)%Zapply Zmult_1_r. Qed.b:Ze:natZpower_nat b 1 = bforall (b : Z) (p : positive), (0 < b)%Z -> (0 < Z.pow_pos b p)%Zforall (b : Z) (p : positive), (0 < b)%Z -> (0 < Z.pow_pos b p)%Zb:Zp:positiveHb:(0 < b)%Z(0 < Z.pow_pos b p)%Zb:Zp:positiveHb:(0 < b)%Z(0 < Zpower_nat b (Pos.to_nat p))%Zb:Zp:positiveHb:(0 < b)%Z(0 < Zpower_nat b 0)%Zb:Zp:positiveHb:(0 < b)%Zn:natIHn:(0 < Zpower_nat b n)%Z(0 < Zpower_nat b (S n))%Zb:Zp:positiveHb:(0 < b)%Zn:natIHn:(0 < Zpower_nat b n)%Z(0 < Zpower_nat b (S n))%Znow apply Zmult_lt_0_compat. Qed.b:Zp:positiveHb:(0 < b)%Zn:natIHn:(0 < Zpower_nat b n)%Z(0 < b * Zpower_nat b n)%Zforall b e : Z, (0 <= e)%Z -> Z.even b = false -> Z.even (b ^ e) = falseforall b e : Z, (0 <= e)%Z -> Z.even b = false -> Z.even (b ^ e) = falseb, e:ZHe:(0 <= e)%ZHb:Z.even b = falseZ.even (b ^ e) = falseb, e:ZHe:(0 <= e)%ZHb:Z.even b = falseHe':(0 < e)%ZZ.even (b ^ e) = falseb, e:ZHe:(0 <= e)%ZHb:Z.even b = falseHe':0%Z = eZ.even (b ^ e) = falseb, e:ZHe:(0 <= e)%ZHb:Z.even b = falseHe':(0 < e)%ZZ.even (b ^ e) = Z.even bb, e:ZHe:(0 <= e)%ZHb:Z.even b = falseHe':0%Z = eZ.even (b ^ e) = falsenow rewrite <- He'. Qed.b, e:ZHe:(0 <= e)%ZHb:Z.even b = falseHe':0%Z = eZ.even (b ^ e) = false
The radix must be greater than 1
Record radix := { radix_val :> Z ; radix_prop : Zle_bool 2 radix_val = true }.forall r1 r2 : radix, r1 = r2 -> r1 = r2forall r1 r2 : radix, r1 = r2 -> r1 = r2r1:ZH1:(2 <=? r1)%Z = truer2:ZH2:(2 <=? r2)%Z = trueH:{| radix_val := r1; radix_prop := H1 |} = {| radix_val := r2; radix_prop := H2 |}{| radix_val := r1; radix_prop := H1 |} = {| radix_val := r2; radix_prop := H2 |}r1:ZH1:(2 <=? r1)%Z = truer2:ZH2:(2 <=? r2)%Z = trueH:r1 = r2{| radix_val := r1; radix_prop := H1 |} = {| radix_val := r2; radix_prop := H2 |}r1, r2:ZH2:(2 <=? r2)%Z = trueH:r1 = r2forall H1 : (2 <=? r1)%Z = true, {| radix_val := r1; radix_prop := H1 |} = {| radix_val := r2; radix_prop := H2 |}r1, r2:ZH2:(2 <=? r2)%Z = trueH:r1 = r2forall H1 : (2 <=? r2)%Z = true, {| radix_val := r2; radix_prop := H1 |} = {| radix_val := r2; radix_prop := H2 |}r1, r2:ZH2:(2 <=? r2)%Z = trueH:r1 = r2H1:(2 <=? r2)%Z = true{| radix_val := r2; radix_prop := H1 |} = {| radix_val := r2; radix_prop := H2 |}apply eqbool_irrelevance. Qed. Definition radix2 := Build_radix 2 (refl_equal _). Variable r : radix.r1, r2:ZH2:(2 <=? r2)%Z = trueH:r1 = r2H1:(2 <=? r2)%Z = trueH1 = H2r:radix(0 < r)%Zr:radix(0 < r)%Zr:radix(0 < 2)%Zr:radix(2 <= r)%Zr:radix(2 <= r)%Zapply r. Qed.r:radix(2 <=? r)%Z = truer:radix(1 < r)%Zr:radix(1 < r)%Zr:radixv:ZHr:(2 <=? v)%Z = true(1 < {| radix_val := v; radix_prop := Hr |})%Zr:radixv:ZHr:(2 <=? v)%Z = true(1 < v)%Zr:radixv:ZHr:(2 <=? v)%Z = true(1 < 2)%Zr:radixv:ZHr:(2 <=? v)%Z = true(2 <= v)%Znow apply Zle_bool_imp_le. Qed.r:radixv:ZHr:(2 <=? v)%Z = true(2 <= v)%Zr:radixforall p : Z, (0 < p)%Z -> (1 < r ^ p)%Zr:radixforall p : Z, (0 < p)%Z -> (1 < r ^ p)%Zr:radixp:positiveHp:(0 < Z.pos p)%Z(1 < r ^ Z.pos p)%Zr:radixp:positiveHp:(0 < Z.pos p)%Z(1 < Z.pow_pos r p)%Zr:radixp:positiveHp:(0 < Z.pos p)%Z(1 < Zpower_nat r (Pos.to_nat p))%Zr:radixp:positiveHp:(0 < Z.pos p)%Z0 < Pos.to_nat p -> (1 < Zpower_nat r (Pos.to_nat p))%Zr:radixp:positiveHp:(0 < Z.pos p)%Z0 < 0 -> (1 < Zpower_nat r 0)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%Z0 < S n -> (1 < Zpower_nat r (S n))%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%Z0 < S n -> (1 < Zpower_nat r (S n))%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%Z(1 < Zpower_nat r (S n))%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%Z(1 < r * Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%Z(0 < Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 < r * Zpower_nat r n)%Zr:radixn:nat(0 < Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 < r * Zpower_nat r n)%Zr:radix(0 < Zpower_nat r 0)%Zr:radixn:natIHn:(0 < Zpower_nat r n)%Z(0 < Zpower_nat r (S n))%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 < r * Zpower_nat r n)%Zr:radixn:natIHn:(0 < Zpower_nat r n)%Z(0 < Zpower_nat r (S n))%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 < r * Zpower_nat r n)%Zr:radixn:natIHn:(0 < Zpower_nat r n)%Z(0 < r * Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 < r * Zpower_nat r n)%Zr:radixn:natIHn:(0 < Zpower_nat r n)%Z(0 < r)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 < r * Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 < r * Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 <= 1 * Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 * Zpower_nat r n < r * Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 <= Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 * Zpower_nat r n < r * Zpower_nat r n)%Zr:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 * Zpower_nat r n < r * Zpower_nat r n)%Zapply radix_gt_1. Qed.r:radixp:positiveHp:(0 < Z.pos p)%Zn:natIHn:0 < n -> (1 < Zpower_nat r n)%ZH:(0 < Zpower_nat r n)%Z(1 < r)%Zr:radixforall p : Z, (0 <= p)%Z -> (0 < r ^ p)%Zr:radixforall p : Z, (0 <= p)%Z -> (0 < r ^ p)%Zr:radixp:ZHp:(0 <= p)%Z(0 < r ^ p)%Zr:radixp:ZHp:(0 <= p)%Z(0 < Zpower_nat r (Z.abs_nat p))%Zr:radixp:ZHp:(0 <= p)%Z(0 < Zpower_nat r 0)%Zr:radixp:ZHp:(0 <= p)%Zn:natIHn:(0 < Zpower_nat r n)%Z(0 < Zpower_nat r (S n))%Zr:radixp:ZHp:(0 <= p)%Zn:natIHn:(0 < Zpower_nat r n)%Z(0 < Zpower_nat r (S n))%Zr:radixp:ZHp:(0 <= p)%Zn:natIHn:(0 < Zpower_nat r n)%Z(0 < r * Zpower_nat r n)%Zapply radix_gt_0. Qed.r:radixp:ZHp:(0 <= p)%Zn:natIHn:(0 < Zpower_nat r n)%Z(0 < r)%Zr:radixforall e : Z, (0 <= r ^ e)%Zr:radixforall e : Z, (0 <= r ^ e)%Zr:radixe:positive(0 <= r ^ Z.pos e)%Znow apply Zpower_gt_0. Qed.r:radixe:positive(0 < r ^ Z.pos e)%Zr:radixforall e1 e2 : Z, (e1 <= e2)%Z -> (r ^ e1 <= r ^ e2)%Zr:radixforall e1 e2 : Z, (e1 <= e2)%Z -> (r ^ e1 <= r ^ e2)%Zr:radixe1, e2:ZHe:(e1 <= e2)%Z(r ^ e1 <= r ^ e2)%Zr:radixe1, e2:ZHe:(e1 <= e2)%ZH1:(0 <= e1)%Z(r ^ e1 <= r ^ e2)%Zr:radixe1, e2:ZHe:(e1 <= e2)%ZH1:(e1 < 0)%Z(r ^ e1 <= r ^ e2)%Zr:radixe1, e2:ZHe:(e1 <= e2)%ZH1:(0 <= e1)%Z(r ^ e1 <= r ^ (e2 - e1 + e1))%Zr:radixe1, e2:ZHe:(e1 <= e2)%ZH1:(e1 < 0)%Z(r ^ e1 <= r ^ e2)%Zr:radixe1, e2:ZHe:(e1 <= e2)%ZH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e2)%Z(Z.neg p < 0)%Z -> (r ^ Z.neg p < r ^ e2)%Znow apply Zpower_gt_0. Qed.r:radixp:positivee2:ZHe2:(0 <= e2)%Z(r ^ Z.neg p < r ^ e2)%Zr:radixforall e1 e2 : Z, (r ^ (e1 - 1) < r ^ e2)%Z -> (e1 <= e2)%Zr:radixforall e1 e2 : Z, (r ^ (e1 - 1) < r ^ e2)%Z -> (e1 <= e2)%Zr:radixe1, e2:ZHe:(r ^ (e1 - 1) < r ^ e2)%Z(e1 <= e2)%Zr:radixe1, e2:ZHe:(r ^ (e1 - 1) < r ^ e2)%Z~ (e1 > e2)%Zr:radixe1, e2:ZHe:(r ^ (e1 - 1) < r ^ e2)%ZH:(e1 > e2)%ZFalser:radixe1, e2:ZHe:(r ^ (e1 - 1) < r ^ e2)%ZH:(e1 > e2)%Z(r ^ e2 <= r ^ (e1 - 1))%Zclear -H ; omega. Qed.r:radixe1, e2:ZHe:(r ^ (e1 - 1) < r ^ e2)%ZH:(e1 > e2)%Z(e2 <= e1 - 1)%Zr:radixforall n : Z, (n < r ^ n)%Zr:radixforall n : Z, (n < r ^ n)%Zr:radixn:positive(Z.pos n < r ^ Z.pos n)%Zr:radixn:positive(Z.pos n < Z.pow_pos r n)%Zr:radixn:positive(Z.pos n < Zpower_nat r (Pos.to_nat n))%Zr:radixn:positive(Z.of_nat (Pos.to_nat n) < Zpower_nat r (Pos.to_nat n))%Zr:radixn:positive(Z.of_nat 0 < Zpower_nat r 0)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(Z.of_nat (S n0) < Zpower_nat r (S n0))%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(Z.of_nat (S n0) < Zpower_nat r (S n0))%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(Z.succ (Z.of_nat n0) < Zpower_nat r (S n0))%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(Z.succ (Z.of_nat n0) < r * Zpower_nat r n0)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(Z.of_nat n0 + 1 < r * Zpower_nat r n0)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(Z.of_nat n0 + 1 < r * (Z.of_nat n0 + 1))%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(Z.of_nat n0 + 1 < r * (Z.of_nat n0 + 1))%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(0 < r * (Z.of_nat n0 + 1) - (Z.of_nat n0 + 1))%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(0 < (r - 1) * (Z.of_nat n0 + 1))%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(0 < r - 1)%Zr:radixn0:nat(0 < Z.of_nat n0 + 1)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(2 <= r)%Z -> (0 < r - 1)%Zr:radixn0:nat(2 <= r)%Zr:radixn0:nat(0 < Z.of_nat n0 + 1)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(2 <= r)%Zr:radixn0:nat(0 < Z.of_nat n0 + 1)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(2 <=? r)%Z = truer:radixn0:nat(0 < Z.of_nat n0 + 1)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(0 < Z.of_nat n0 + 1)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn0:nat(0 <= Z.of_nat n0)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(r * (Z.of_nat n0 + 1) <= r * Zpower_nat r n0)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(Z.of_nat n0 + 1 <= Zpower_nat r n0)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(0 <= r)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(0 <= r)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(0 <= 2)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(2 <= r)%Zr:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(2 <= r)%Zapply r. Qed. End Zpower. Section Div_Mod.r:radixn:positiven0:natIHn0:(Z.of_nat n0 < Zpower_nat r n0)%Z(2 <=? r)%Z = trueforall n a b : Z, (0 < a)%Z -> (0 <= b)%Z -> ((n mod (a * b)) mod b)%Z = (n mod b)%Zforall n a b : Z, (0 < a)%Z -> (0 <= b)%Z -> ((n mod (a * b)) mod b)%Z = (n mod b)%Zn, a:ZHa:(0 < a)%ZHb:(0 <= 0)%Z((n mod (a * 0)) mod 0)%Z = (n mod 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z((n mod (a * Z.pos b)) mod Z.pos b)%Z = (n mod Z.pos b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z((n mod (a * Z.pos b)) mod Z.pos b)%Z = (n mod Z.pos b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z((n - n / (a * Z.pos b) * (a * Z.pos b)) mod Z.pos b)%Z = (n mod Z.pos b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(a * Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z((n - n / (a * Z.pos b) * a * Z.pos b) mod Z.pos b)%Z = (n mod Z.pos b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(a * Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z((n + - (n / (a * Z.pos b) * a * Z.pos b)) mod Z.pos b)%Z = (n mod Z.pos b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(a * Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z((n + - (n / (a * Z.pos b) * a) * Z.pos b) mod Z.pos b)%Z = (n mod Z.pos b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(a * Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(a * Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(a * Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(a > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.pos b)%Z(Z.pos b > 0)%Zn, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Znow elim Hb. Qed.n, a:Zb:positiveHa:(0 < a)%ZHb:(0 <= Z.neg b)%Z((n mod (a * Z.neg b)) mod Z.neg b)%Z = (n mod Z.neg b)%Zforall a b : Z, Z.rem a b = (a - a ÷ b * b)%Zforall a b : Z, Z.rem a b = (a - a ÷ b * b)%Za, b:ZZ.rem a b = (a - a ÷ b * b)%Zring. Qed.a, b:ZZ.rem a b = (b * (a ÷ b) + Z.rem a b - a ÷ b * b)%Zforall n a b : Z, Z.rem (Z.rem n (a * b)) b = Z.rem n bforall n a b : Z, Z.rem (Z.rem n (a * b)) b = Z.rem n bn, a, b:ZZ.rem (Z.rem n (a * b)) b = Z.rem n bn, a, b:ZZ.rem n (a * b) = (n + - (n ÷ (a * b) * a) * b)%Zn, a, b:ZH:Z.rem n (a * b) = (n + - (n ÷ (a * b) * a) * b)%ZZ.rem (Z.rem n (a * b)) b = Z.rem n bn, a, b:ZZ.rem n (a * b) = (n + - (n ÷ (a * b) * a * b))%Zn, a, b:ZH:Z.rem n (a * b) = (n + - (n ÷ (a * b) * a) * b)%ZZ.rem (Z.rem n (a * b)) b = Z.rem n bn, a, b:ZZ.rem n (a * b) = (n + - (n ÷ (a * b) * (a * b)))%Zn, a, b:ZH:Z.rem n (a * b) = (n + - (n ÷ (a * b) * a) * b)%ZZ.rem (Z.rem n (a * b)) b = Z.rem n bn, a, b:ZH:Z.rem n (a * b) = (n + - (n ÷ (a * b) * a) * b)%ZZ.rem (Z.rem n (a * b)) b = Z.rem n bn, a, b:ZH:Z.rem n (a * b) = (n + - (n ÷ (a * b) * a) * b)%ZZ.rem (n + - (n ÷ (a * b) * a) * b) b = Z.rem n bn, a, b:ZH:Z.rem n (a * b) = (n + - (n ÷ (a * b) * a) * b)%Z(0 <= (n + - (n ÷ (a * b) * a) * b) * n)%Zapply Zrem_sgn2. Qed.n, a, b:ZH:Z.rem n (a * b) = (n + - (n ÷ (a * b) * a) * b)%Z(0 <= Z.rem n (a * b) * n)%Zforall n a b : Z, (0 <= a)%Z -> (0 <= b)%Z -> (n mod (a * b) / a)%Z = ((n / a) mod b)%Zforall n a b : Z, (0 <= a)%Z -> (0 <= b)%Z -> (n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%Z(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%Z(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z((n - n / (a * b) * (a * b)) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z((n - n / (a * b) * (b * a)) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z((n - n / (a * b) * b * a) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z((n + - (n / (a * b) * b * a)) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z((n + - (n / (a * b) * b) * a) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(n / a + - (n / (a * b) * b))%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(n / a + - (n / a / b * b))%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z((n / a) mod b)%Z = (n / a + - (n / a / b * b))%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':(0 < b)%Z(a * b > 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(n mod (a * 0) / a)%Z = ((n / a) mod 0)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':(0 < a)%ZHb':0%Z = b(0 / a)%Z = 0%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Zn, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (a * b) / a)%Z = ((n / a) mod b)%Znow rewrite 2!Zdiv_0_r, Zmod_0_l. Qed.n, a, b:ZHa:(0 <= a)%ZHb:(0 <= b)%ZHa':0%Z = a(n mod (0 * b) / 0)%Z = ((n / 0) mod b)%Zforall n a b : Z, (Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bforall n a b : Z, (Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a = 0%Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a = 0%Z(Z.rem n (0 * b) ÷ 0)%Z = Z.rem (n ÷ 0) bn, a, b:ZZa:a <> 0%Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%ZZ.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Zn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%Z(n - n ÷ (a * b) * (a * b))%Z = (n + - (n ÷ a ÷ b * b) * a)%Zn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%Z(n - n ÷ (a * b) * (a * b))%Z = (n + - (n ÷ (a * b) * b) * a)%Zn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(Z.rem n (a * b) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z((n + - (n ÷ a ÷ b * b) * a) ÷ a)%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(n ÷ a + - (n ÷ a ÷ b * b))%Z = Z.rem (n ÷ a) bn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(0 <= (n + - (n ÷ a ÷ b * b) * a) * n)%Zn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%ZZ.rem (n ÷ a) b = (n ÷ a + - (n ÷ a ÷ b * b))%Zn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(0 <= (n + - (n ÷ a ÷ b * b) * a) * n)%Zn, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(0 <= (n + - (n ÷ a ÷ b * b) * a) * n)%Zapply Zrem_sgn2. Qed.n, a, b:ZZa:a <> 0%ZH:Z.rem n (a * b) = (n + - (n ÷ a ÷ b * b) * a)%Z(0 <= Z.rem n (a * b) * n)%Zforall a b : Z, (Z.abs a < b)%Z -> (a ÷ b)%Z = 0%Zforall a b : Z, (Z.abs a < b)%Z -> (a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%Z(a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(0 <= a < b)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(0 <= a)%Za, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(a < b)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(a < b)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(- (a ÷ b))%Z = (- 0)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(- a ÷ b)%Z = 0%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(0 <= - a < b)%Zomega. Qed.a, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z((a <= 0)%Z -> Z.abs a = (- a)%Z) -> (0 <= - a < b)%Zforall a b : Z, (Z.abs a < b)%Z -> Z.rem a b = aforall a b : Z, (Z.abs a < b)%Z -> Z.rem a b = aa, b:ZHa:(Z.abs a < b)%ZZ.rem a b = aa, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%ZZ.rem a b = aa, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%ZZ.rem a b = aa, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(0 <= a < b)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%ZZ.rem a b = aa, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(0 <= a)%Za, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(a < b)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%ZZ.rem a b = aa, b:ZHa:(Z.abs a < b)%ZH:(0 <= a)%Z(a < b)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%ZZ.rem a b = aa, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%ZZ.rem a b = aa, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(- Z.rem a b)%Z = (- a)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%ZZ.rem (- a) b = (- a)%Za, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z(0 <= - a < b)%Zomega. Qed.a, b:ZHa:(Z.abs a < b)%ZH:(a < 0)%Z((a <= 0)%Z -> Z.abs a = (- a)%Z) -> (0 <= - a < b)%Zforall a b c : Z, (0 <= a * b)%Z -> ((a + b) ÷ c)%Z = (a ÷ c + b ÷ c + (Z.rem a c + Z.rem b c) ÷ c)%Zforall a b c : Z, (0 <= a * b)%Z -> ((a + b) ÷ c)%Z = (a ÷ c + b ÷ c + (Z.rem a c + Z.rem b c) ÷ c)%Za, b, c:ZHab:(0 <= a * b)%Z((a + b) ÷ c)%Z = (a ÷ c + b ÷ c + (Z.rem a c + Z.rem b c) ÷ c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c = 0%Z((a + b) ÷ c)%Z = (a ÷ c + b ÷ c + (Z.rem a c + Z.rem b c) ÷ c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%Z((a + b) ÷ c)%Z = (a ÷ c + b ÷ c + (Z.rem a c + Z.rem b c) ÷ c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%Z((a + b) ÷ c)%Z = (a ÷ c + b ÷ c + (Z.rem a c + Z.rem b c) ÷ c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%Z((a + b) ÷ c * c)%Z = ((a ÷ c + b ÷ c + (Z.rem a c + Z.rem b c) ÷ c) * c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%Z((a + b) ÷ c * c)%Z = (a ÷ c * c + b ÷ c * c + (Z.rem a c + Z.rem b c) ÷ c * c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%Zforall d : Z, (d ÷ c * c)%Z = (d - Z.rem d c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%ZH:forall d : Z, (d ÷ c * c)%Z = (d - Z.rem d c)%Z((a + b) ÷ c * c)%Z = (a ÷ c * c + b ÷ c * c + (Z.rem a c + Z.rem b c) ÷ c * c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%Zd:Z(d ÷ c * c)%Z = (d - Z.rem d c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%ZH:forall d : Z, (d ÷ c * c)%Z = (d - Z.rem d c)%Z((a + b) ÷ c * c)%Z = (a ÷ c * c + b ÷ c * c + (Z.rem a c + Z.rem b c) ÷ c * c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%Zd:Z(d ÷ c * c)%Z = (d - (d - d ÷ c * c))%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%ZH:forall d : Z, (d ÷ c * c)%Z = (d - Z.rem d c)%Z((a + b) ÷ c * c)%Z = (a ÷ c * c + b ÷ c * c + (Z.rem a c + Z.rem b c) ÷ c * c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%ZH:forall d : Z, (d ÷ c * c)%Z = (d - Z.rem d c)%Z((a + b) ÷ c * c)%Z = (a ÷ c * c + b ÷ c * c + (Z.rem a c + Z.rem b c) ÷ c * c)%Za, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%ZH:forall d : Z, (d ÷ c * c)%Z = (d - Z.rem d c)%Z(a + b - Z.rem (a + b) c)%Z = (a - Z.rem a c + (b - Z.rem b c) + (Z.rem a c + Z.rem b c - Z.rem (Z.rem a c + Z.rem b c) c))%Zring. Qed. End Div_Mod. Section Same_sign.a, b, c:ZHab:(0 <= a * b)%ZZc:c <> 0%ZH:forall d : Z, (d ÷ c * c)%Z = (d - Z.rem d c)%Z(a + b - Z.rem (a + b) c)%Z = (a - Z.rem a c + (b - Z.rem b c) + (Z.rem a c + Z.rem b c - Z.rem (a + b) c))%Zforall v u w : Z, v <> 0%Z -> (0 <= u * v)%Z -> (0 <= v * w)%Z -> (0 <= u * w)%Zintros [|v|v] [|u|u] [|w|w] Zv Huv Hvw ; try easy ; now elim Zv. Qed.forall v u w : Z, v <> 0%Z -> (0 <= u * v)%Z -> (0 <= v * w)%Z -> (0 <= u * w)%Zforall v u w : Z, (v = 0%Z -> w = 0%Z) -> (0 <= u * v)%Z -> (0 <= v * w)%Z -> (0 <= u * w)%Zintros [|v|v] [|u|u] [|w|w] Zv Huv Hvw ; try easy ; now discriminate Zv. Qed.forall v u w : Z, (v = 0%Z -> w = 0%Z) -> (0 <= u * v)%Z -> (0 <= v * w)%Z -> (0 <= u * w)%Zforall u v : Z, ((0 < u)%Z -> (0 <= v)%Z) -> ((0 < - u)%Z -> (0 <= - v)%Z) -> (0 <= u * v)%Zforall u v : Z, ((0 < u)%Z -> (0 <= v)%Z) -> ((0 < - u)%Z -> (0 <= - v)%Z) -> (0 <= u * v)%Zv:ZHp:(0 < 0)%Z -> (0 <= v)%ZHn:(0 < - 0)%Z -> (0 <= - v)%Z(0 <= 0 * v)%Zu:positivev:ZHp:(0 < Z.pos u)%Z -> (0 <= v)%ZHn:(0 < - Z.pos u)%Z -> (0 <= - v)%Z(0 <= Z.pos u * v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= Z.neg u * v)%Zu:positivev:ZHp:(0 < Z.pos u)%Z -> (0 <= v)%ZHn:(0 < - Z.pos u)%Z -> (0 <= - v)%Z(0 <= Z.pos u * v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= Z.neg u * v)%Zu:positivev:ZHp:(0 < Z.pos u)%Z -> (0 <= v)%ZHn:(0 < - Z.pos u)%Z -> (0 <= - v)%Z(0 <= Z.pos u)%Zu:positivev:ZHp:(0 < Z.pos u)%Z -> (0 <= v)%ZHn:(0 < - Z.pos u)%Z -> (0 <= - v)%Z(0 <= v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= Z.neg u * v)%Zu:positivev:ZHp:(0 < Z.pos u)%Z -> (0 <= v)%ZHn:(0 < - Z.pos u)%Z -> (0 <= - v)%Z(0 <= v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= Z.neg u * v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= Z.neg u * v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= Z.pos u * - v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(Z.pos u * - v)%Z = (Z.neg u * v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= Z.pos u)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= - v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(Z.pos u * - v)%Z = (Z.neg u * v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(0 <= - v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(Z.pos u * - v)%Z = (Z.neg u * v)%Zu:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(Z.pos u * - v)%Z = (Z.neg u * v)%Zapply Zopp_mult_distr_l. Qed.u:positivev:ZHp:(0 < Z.neg u)%Z -> (0 <= v)%ZHn:(0 < - Z.neg u)%Z -> (0 <= - v)%Z(- (Z.pos u * v))%Z = (Z.neg u * v)%Zforall u v : Z, (0 <= v)%Z -> (0 <= u * (u ÷ v))%Zforall u v : Z, (0 <= v)%Z -> (0 <= u * (u ÷ v))%Zu, v:ZHv:(0 <= v)%Z(0 <= u * (u ÷ v))%Zu, v:ZHv:(0 <= v)%ZHu:(0 < u)%Z(0 <= u ÷ v)%Zu, v:ZHv:(0 <= v)%ZHu:(0 < - u)%Z(0 <= - (u ÷ v))%Zu, v:ZHv:(0 <= v)%ZHu:(0 < u)%Z(0 <= u)%Zu, v:ZHv:(0 <= v)%ZHu:(0 < - u)%Z(0 <= - (u ÷ v))%Zu, v:ZHv:(0 <= v)%ZHu:(0 < - u)%Z(0 <= - (u ÷ v))%Zu, v:ZHv:(0 <= v)%ZHu:(0 < - u)%Z(0 <= - u ÷ v)%Znow apply Zlt_le_weak. Qed. End Same_sign.u, v:ZHv:(0 <= v)%ZHu:(0 < - u)%Z(0 <= - u)%Z
Boolean comparisons
Section Zeq_bool. Inductive Zeq_bool_prop (x y : Z) : bool -> Prop := | Zeq_bool_true_ : x = y -> Zeq_bool_prop x y true | Zeq_bool_false_ : x <> y -> Zeq_bool_prop x y false.forall x y : Z, Zeq_bool_prop x y (Zeq_bool x y)forall x y : Z, Zeq_bool_prop x y (Zeq_bool x y)x, y:ZZeq_bool_prop x y (Zeq_bool x y)x, y:Zx = y <-> Zeq_bool x y = true -> Zeq_bool_prop x y (Zeq_bool x y)x, y:ZH1:x = y -> true = trueH2:true = true -> x = yx = yx, y:ZH1:x = y -> false = trueH2:false = true -> x = yx <> yx, y:ZH1:x = y -> false = trueH2:false = true -> x = yx <> yx, y:ZH1:x = y -> false = trueH2:false = true -> x = yH:x = yFalsediscriminate H1. Qed.x, y:ZH1:false = trueH2:false = true -> x = yH:x = yFalseforall x y : Z, x = y -> Zeq_bool x y = trueforall x y : Z, x = y -> Zeq_bool x y = trueapply -> Zeq_is_eq_bool. Qed.x, y:Zx = y -> Zeq_bool x y = trueforall x y : Z, x <> y -> Zeq_bool x y = falseforall x y : Z, x <> y -> Zeq_bool x y = falsex, y:Zx <> y -> Zeq_bool x y = falsex, y:Z(Zeq_bool x y = true -> x = y) -> x <> y -> Zeq_bool x y = falsex, y:Z(true = true -> x = y) -> x <> y -> true = falsex, y:Z(false = true -> x = y) -> x <> y -> false = falsex, y:ZHe:true = true -> x = yHn:x <> ytrue = falsex, y:Z(false = true -> x = y) -> x <> y -> false = falsex, y:ZHe:true = true -> x = yHn:x <> yx = yx, y:Z(false = true -> x = y) -> x <> y -> false = falsenow intros _ _. Qed. End Zeq_bool. Section Zle_bool. Inductive Zle_bool_prop (x y : Z) : bool -> Prop := | Zle_bool_true_ : (x <= y)%Z -> Zle_bool_prop x y true | Zle_bool_false_ : (y < x)%Z -> Zle_bool_prop x y false.x, y:Z(false = true -> x = y) -> x <> y -> false = falseforall x y : Z, Zle_bool_prop x y (x <=? y)%Zforall x y : Z, Zle_bool_prop x y (x <=? y)%Zx, y:ZZle_bool_prop x y (x <=? y)%Zx, y:Z(x <= y)%Z <-> (x <=? y)%Z = true -> Zle_bool_prop x y (x <=? y)%Zx, y:ZH1:(x <= y)%Z -> true = trueH2:true = true -> (x <= y)%Z(x <= y)%Zx, y:ZH1:(x <= y)%Z -> false = trueH2:false = true -> (x <= y)%Z(y < x)%Zx, y:ZH1:(x <= y)%Z -> false = trueH2:false = true -> (x <= y)%Z(y < x)%Zx, y:ZH1:(x <= y)%Z -> false = trueH2:false = true -> (x <= y)%ZH:(x <= y)%Z(y < x)%Zx, y:ZH1:(x <= y)%Z -> false = trueH2:false = true -> (x <= y)%ZH:(y < x)%Z(y < x)%Zexact H. Qed.x, y:ZH1:(x <= y)%Z -> false = trueH2:false = true -> (x <= y)%ZH:(y < x)%Z(y < x)%Zforall x y : Z, (x <= y)%Z -> (x <=? y)%Z = trueforall x y : Z, (x <= y)%Z -> (x <=? y)%Z = trueapply (proj1 (Zle_is_le_bool x y)). Qed.x, y:Z(x <= y)%Z -> (x <=? y)%Z = trueforall x y : Z, (y < x)%Z -> (x <=? y)%Z = falseforall x y : Z, (y < x)%Z -> (x <=? y)%Z = falsex, y:ZHxy:(y < x)%Z(x <=? y)%Z = falsex, y:ZHxy:(y < x)%Z(if (x <=? y)%Z then (x <= y)%Z else (x > y)%Z) -> (x <=? y)%Z = falsex, y:ZHxy:(y < x)%ZH:(x <= y)%Ztrue = falsex, y:ZHxy:(y < x)%ZH:(x > y)%Zfalse = falsex, y:ZHxy:(y < x)%ZH:(x <= y)%Z(x < x)%Zx, y:ZHxy:(y < x)%ZH:(x > y)%Zfalse = falseapply refl_equal. Qed. End Zle_bool. Section Zlt_bool. Inductive Zlt_bool_prop (x y : Z) : bool -> Prop := | Zlt_bool_true_ : (x < y)%Z -> Zlt_bool_prop x y true | Zlt_bool_false_ : (y <= x)%Z -> Zlt_bool_prop x y false.x, y:ZHxy:(y < x)%ZH:(x > y)%Zfalse = falseforall x y : Z, Zlt_bool_prop x y (x <? y)%Zforall x y : Z, Zlt_bool_prop x y (x <? y)%Zx, y:ZZlt_bool_prop x y (x <? y)%Zx, y:Z(x < y)%Z <-> (x <? y)%Z = true -> Zlt_bool_prop x y (x <? y)%Zx, y:ZH1:(x < y)%Z -> true = trueH2:true = true -> (x < y)%Z(x < y)%Zx, y:ZH1:(x < y)%Z -> false = trueH2:false = true -> (x < y)%Z(y <= x)%Zx, y:ZH1:(x < y)%Z -> false = trueH2:false = true -> (x < y)%Z(y <= x)%Zx, y:ZH1:(x < y)%Z -> false = trueH2:false = true -> (x < y)%ZH:(y <= x)%Z(y <= x)%Zx, y:ZH1:(x < y)%Z -> false = trueH2:false = true -> (x < y)%ZH:(x < y)%Z(y <= x)%Znow specialize (H1 H). Qed.x, y:ZH1:(x < y)%Z -> false = trueH2:false = true -> (x < y)%ZH:(x < y)%Z(y <= x)%Zforall x y : Z, (x < y)%Z -> (x <? y)%Z = trueforall x y : Z, (x < y)%Z -> (x <? y)%Z = trueapply (proj1 (Zlt_is_lt_bool x y)). Qed.x, y:Z(x < y)%Z -> (x <? y)%Z = trueforall x y : Z, (y <= x)%Z -> (x <? y)%Z = falseforall x y : Z, (y <= x)%Z -> (x <? y)%Z = falsex, y:ZHxy:(y <= x)%Z(x <? y)%Z = falsex, y:ZHxy:(y <= x)%Z(if (x <? y)%Z then (x < y)%Z else (x >= y)%Z) -> (x <? y)%Z = falsex, y:ZHxy:(y <= x)%ZH:(x < y)%Ztrue = falsex, y:ZHxy:(y <= x)%ZH:(x >= y)%Zfalse = falsex, y:ZHxy:(y <= x)%ZH:(x < y)%Z(x < x)%Zx, y:ZHxy:(y <= x)%ZH:(x >= y)%Zfalse = falseapply refl_equal. Qed.x, y:ZHxy:(y <= x)%ZH:(x >= y)%Zfalse = falseforall x y : Z, negb (x <=? y)%Z = (y <? x)%Zforall x y : Z, negb (x <=? y)%Z = (y <? x)%Zx, y:Znegb (x <=? y)%Z = (y <? x)%Zx, y:ZH:(x <= y)%Znegb true = (y <? x)%Zx, y:ZH:(y < x)%Znegb false = (y <? x)%Znow rewrite Zlt_bool_true. Qed.x, y:ZH:(y < x)%Znegb false = (y <? x)%Zforall x y : Z, negb (x <? y)%Z = (y <=? x)%Zforall x y : Z, negb (x <? y)%Z = (y <=? x)%Zx, y:Znegb (x <? y)%Z = (y <=? x)%Zx, y:ZH:(x < y)%Znegb true = (y <=? x)%Zx, y:ZH:(y <= x)%Znegb false = (y <=? x)%Znow rewrite Zle_bool_true. Qed. End Zlt_bool. Section Zcompare. Inductive Zcompare_prop (x y : Z) : comparison -> Prop := | Zcompare_Lt_ : (x < y)%Z -> Zcompare_prop x y Lt | Zcompare_Eq_ : x = y -> Zcompare_prop x y Eq | Zcompare_Gt_ : (y < x)%Z -> Zcompare_prop x y Gt.x, y:ZH:(y <= x)%Znegb false = (y <=? x)%Zforall x y : Z, Zcompare_prop x y (x ?= y)%Zforall x y : Z, Zcompare_prop x y (x ?= y)%Zx, y:ZZcompare_prop x y (x ?= y)%Zx, y:ZH:(x < y)%ZZcompare_prop x y (x ?= y)%Zx, y:ZH:(x > y)%ZZcompare_prop x y (x ?= y)%Zx, y:ZH:x = yZcompare_prop x y (x ?= y)%Zx, y:ZH:(x < y)%Zmatch (x ?= y)%Z with | Lt => True | _ => False end -> Zcompare_prop x y (x ?= y)%Zx, y:ZH:(x > y)%ZZcompare_prop x y (x ?= y)%Zx, y:ZH:x = yZcompare_prop x y (x ?= y)%Zx, y:ZH:(x < y)%ZTrue -> Zcompare_prop x y Ltx, y:ZH:(x > y)%ZZcompare_prop x y (x ?= y)%Zx, y:ZH:x = yZcompare_prop x y (x ?= y)%Zx, y:ZH:(x > y)%ZZcompare_prop x y (x ?= y)%Zx, y:ZH:x = yZcompare_prop x y (x ?= y)%Zx, y:ZH:(x > y)%Zmatch (x ?= y)%Z with | Gt => True | _ => False end -> Zcompare_prop x y (x ?= y)%Zx, y:ZH:x = yZcompare_prop x y (x ?= y)%Zx, y:ZH:(x > y)%ZTrue -> Zcompare_prop x y Gtx, y:ZH:x = yZcompare_prop x y (x ?= y)%Zx, y:ZH:(x > y)%ZH0:True(y < x)%Zx, y:ZH:x = yZcompare_prop x y (x ?= y)%Zx, y:ZH:x = yZcompare_prop x y (x ?= y)%Zx, y:ZH:x = y(x ?= y)%Z = Eq -> Zcompare_prop x y (x ?= y)%Znow constructor. Qed.x, y:ZH:x = yEq = Eq -> Zcompare_prop x y Eqforall x y : Z, (x < y)%Z -> (x ?= y)%Z = Lteasy. Qed.forall x y : Z, (x < y)%Z -> (x ?= y)%Z = Ltforall x y : Z, x = y -> (x ?= y)%Z = Eqforall x y : Z, x = y -> (x ?= y)%Z = Eqapply <- Zcompare_Eq_iff_eq. Qed.x, y:Zx = y -> (x ?= y)%Z = Eqforall x y : Z, (y < x)%Z -> (x ?= y)%Z = Gtforall x y : Z, (y < x)%Z -> (x ?= y)%Z = Gtapply Z.lt_gt. Qed. End Zcompare. Section cond_Zopp.x, y:Z(y < x)%Z -> (x ?= y)%Z = Gtforall (x : bool) (y : Z), SpecFloatCopy.cond_Zopp (negb x) y = (- SpecFloatCopy.cond_Zopp x y)%Zforall (x : bool) (y : Z), SpecFloatCopy.cond_Zopp (negb x) y = (- SpecFloatCopy.cond_Zopp x y)%Zy:ZSpecFloatCopy.cond_Zopp (negb true) y = (- SpecFloatCopy.cond_Zopp true y)%Zy:ZSpecFloatCopy.cond_Zopp (negb false) y = (- SpecFloatCopy.cond_Zopp false y)%Zeasy. Qed.y:ZSpecFloatCopy.cond_Zopp (negb false) y = (- SpecFloatCopy.cond_Zopp false y)%Zforall (b : bool) (m : Z), Z.abs (SpecFloatCopy.cond_Zopp b m) = Z.abs mforall (b : bool) (m : Z), Z.abs (SpecFloatCopy.cond_Zopp b m) = Z.abs mm:ZZ.abs (SpecFloatCopy.cond_Zopp true m) = Z.abs mm:ZZ.abs (SpecFloatCopy.cond_Zopp false m) = Z.abs mapply refl_equal. Qed.m:ZZ.abs (SpecFloatCopy.cond_Zopp false m) = Z.abs mforall m : Z, SpecFloatCopy.cond_Zopp (m <? 0)%Z m = Z.abs mforall m : Z, SpecFloatCopy.cond_Zopp (m <? 0)%Z m = Z.abs mm:ZSpecFloatCopy.cond_Zopp (m <? 0)%Z m = Z.abs mm:ZZ.abs m = SpecFloatCopy.cond_Zopp (m <? 0)%Z mm:ZHm:(m < 0)%ZZ.abs m = SpecFloatCopy.cond_Zopp true mm:ZHm:(0 <= m)%ZZ.abs m = SpecFloatCopy.cond_Zopp false mm:ZHm:(m < 0)%Z(m <= 0)%Zm:ZHm:(0 <= m)%ZZ.abs m = SpecFloatCopy.cond_Zopp false mnow apply Z.abs_eq. Qed. End cond_Zopp. Section fast_pow_pos. Fixpoint Zfast_pow_pos (v : Z) (e : positive) : Z := match e with | xH => v | xO e' => Z.square (Zfast_pow_pos v e') | xI e' => Zmult v (Z.square (Zfast_pow_pos v e')) end.m:ZHm:(0 <= m)%ZZ.abs m = SpecFloatCopy.cond_Zopp false mforall (v : Z) (e : positive), Zfast_pow_pos v e = Z.pow_pos v eforall (v : Z) (e : positive), Zfast_pow_pos v e = Z.pow_pos v ev:Ze:positiveZfast_pow_pos v e = Z.pow_pos v ev:Ze:positive(Zfast_pow_pos v e * 1)%Z = Z.pow_pos v ev:Ze:positive(Zfast_pow_pos v e * 1)%Z = Pos.iter (Z.mul v) 1%Z ev:Ze:positiveforall z : Z, (Zfast_pow_pos v e * z)%Z = Pos.iter (Z.mul v) z ee:positiveforall v z : Z, (Zfast_pow_pos v e * z)%Z = Pos.iter (Z.mul v) z ee:positiveIHe:forall v0 z : Z, (Zfast_pow_pos v0 e * z)%Z = Pos.iter (Z.mul v0) z ev, f:Z(v * Z.square (Zfast_pow_pos v e) * f)%Z = (v * Pos.iter (Z.mul v) (Pos.iter (Z.mul v) f e) e)%Ze:positiveIHe:forall v0 z : Z, (Zfast_pow_pos v0 e * z)%Z = Pos.iter (Z.mul v0) z ev, f:Z(Z.square (Zfast_pow_pos v e) * f)%Z = Pos.iter (Z.mul v) (Pos.iter (Z.mul v) f e) ev, f:Z(v * f)%Z = (v * f)%Ze:positiveIHe:forall v0 z : Z, (Zfast_pow_pos v0 e * z)%Z = Pos.iter (Z.mul v0) z ev, f:Z(v * Z.square (Zfast_pow_pos v e) * f)%Z = (v * Pos.iter (Z.mul v) (Pos.iter (Z.mul v) f e) e)%Ze:positiveIHe:forall v0 z : Z, (Zfast_pow_pos v0 e * z)%Z = Pos.iter (Z.mul v0) z ev, f:Z(v * Z.square (Zfast_pow_pos v e) * f)%Z = (v * (Zfast_pow_pos v e * (Zfast_pow_pos v e * f)))%Zring.e:positiveIHe:forall v0 z : Z, (Zfast_pow_pos v0 e * z)%Z = Pos.iter (Z.mul v0) z ev, f:Z(v * (Zfast_pow_pos v e * Zfast_pow_pos v e) * f)%Z = (v * (Zfast_pow_pos v e * (Zfast_pow_pos v e * f)))%Ze:positiveIHe:forall v0 z : Z, (Zfast_pow_pos v0 e * z)%Z = Pos.iter (Z.mul v0) z ev, f:Z(Z.square (Zfast_pow_pos v e) * f)%Z = Pos.iter (Z.mul v) (Pos.iter (Z.mul v) f e) ee:positiveIHe:forall v0 z : Z, (Zfast_pow_pos v0 e * z)%Z = Pos.iter (Z.mul v0) z ev, f:Z(Z.square (Zfast_pow_pos v e) * f)%Z = (Zfast_pow_pos v e * (Zfast_pow_pos v e * f))%Zapply eq_sym, Zmult_assoc.e:positiveIHe:forall v0 z : Z, (Zfast_pow_pos v0 e * z)%Z = Pos.iter (Z.mul v0) z ev, f:Z(Zfast_pow_pos v e * Zfast_pow_pos v e * f)%Z = (Zfast_pow_pos v e * (Zfast_pow_pos v e * f))%Zapply eq_refl. Qed. End fast_pow_pos. Section faster_div.v, f:Z(v * f)%Z = (v * f)%Zforall a b : Z, Z.div_eucl a b = ((a / b)%Z, (a mod b)%Z)forall a b : Z, Z.div_eucl a b = ((a / b)%Z, (a mod b)%Z)a, b:ZZ.div_eucl a b = ((a / b)%Z, (a mod b)%Z)now case Z.div_eucl. Qed. Fixpoint Zpos_div_eucl_aux1 (a b : positive) {struct b} := match b with | xO b' => match a with | xO a' => let (q, r) := Zpos_div_eucl_aux1 a' b' in (q, 2 * r)%Z | xI a' => let (q, r) := Zpos_div_eucl_aux1 a' b' in (q, 2 * r + 1)%Z | xH => (Z0, Zpos a) end | xH => (Zpos a, Z0) | xI _ => Z.pos_div_eucl a (Zpos b) end.a, b:ZZ.div_eucl a b = (let (q, _) := Z.div_eucl a b in q, let (_, r) := Z.div_eucl a b in r)forall a b : positive, Zpos_div_eucl_aux1 a b = Z.pos_div_eucl a (Z.pos b)forall a b : positive, Zpos_div_eucl_aux1 a b = Z.pos_div_eucl a (Z.pos b)a, b:positiveZpos_div_eucl_aux1 a b = Z.pos_div_eucl a (Z.pos b)b:positiveforall a : positive, Zpos_div_eucl_aux1 a b = Z.pos_div_eucl a (Z.pos b)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~1 = Z.pos_div_eucl a (Z.pos b~1)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~0 = Z.pos_div_eucl a (Z.pos b~0)a:positiveZpos_div_eucl_aux1 a 1 = Z.pos_div_eucl a 1easy.b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~1 = Z.pos_div_eucl a (Z.pos b~1)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~0 = Z.pos_div_eucl a (Z.pos b~0)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~0 = Z.div_eucl (Z.pos a) (Z.pos b~0)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~0 = ((Z.pos a / Z.pos b~0)%Z, (Z.pos a mod Z.pos b~0)%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~0 = ((Z.pos a / (2 * Z.pos b))%Z, (Z.pos a mod (2 * Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~0 = ((Z.pos a / (2 * Z.pos b))%Z, (Z.pos a mod 2 + 2 * ((Z.pos a / 2) mod Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a b~0 = ((Z.pos a / 2 / Z.pos b)%Z, (Z.pos a mod 2 + 2 * ((Z.pos a / 2) mod Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a~1 b~0 = ((Z.pos a~1 / 2 / Z.pos b)%Z, (Z.pos a~1 mod 2 + 2 * ((Z.pos a~1 / 2) mod Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a~0 b~0 = ((Z.pos a~0 / 2 / Z.pos b)%Z, (Z.pos a~0 mod 2 + 2 * ((Z.pos a~0 / 2) mod Z.pos b))%Z)b:positiveIHb:forall a : positive, Zpos_div_eucl_aux1 a b = Z.pos_div_eucl a (Z.pos b)Zpos_div_eucl_aux1 1 b~0 = ((1 / 2 / Z.pos b)%Z, (1 mod 2 + 2 * ((1 / 2) mod Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a~1 b~0 = ((Z.pos a~1 / 2 / Z.pos b)%Z, (Z.pos a~1 mod 2 + 2 * ((Z.pos a~1 / 2) mod Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positive(let (q, r) := Zpos_div_eucl_aux1 a b in (q, (2 * r + 1)%Z)) = ((Z.pos a~1 / 2 / Z.pos b)%Z, (Z.pos a~1 mod 2 + 2 * ((Z.pos a~1 / 2) mod Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positive(let (q, r) := Z.pos_div_eucl a (Z.pos b) in (q, (2 * r + 1)%Z)) = ((Z.pos a~1 / 2 / Z.pos b)%Z, (Z.pos a~1 mod 2 + 2 * ((Z.pos a~1 / 2) mod Z.pos b))%Z)b, a:positive(let (q, r) := Z.pos_div_eucl a (Z.pos b) in (q, (2 * r + 1)%Z)) = ((Z.pos a~1 / 2 / Z.pos b)%Z, (Z.pos a~1 mod 2 + 2 * ((Z.pos a~1 / 2) mod Z.pos b))%Z)b, a:positive(let (q, r) := Z.div_eucl (Z.pos a) (Z.pos b) in (q, (2 * r + 1)%Z)) = ((Z.pos a~1 / 2 / Z.pos b)%Z, (Z.pos a~1 mod 2 + 2 * ((Z.pos a~1 / 2) mod Z.pos b))%Z)b, a:positive((Z.pos a / Z.pos b)%Z, (2 * (Z.pos a mod Z.pos b) + 1)%Z) = ((Z.pos a~1 / 2 / Z.pos b)%Z, (Z.pos a~1 mod 2 + 2 * ((Z.pos a~1 / 2) mod Z.pos b))%Z)b, a:positive((Z.pos a / Z.pos b)%Z, (2 * (Z.pos a mod Z.pos b) + 1)%Z) = (((1 + 2 * Z.pos a) / 2 / Z.pos b)%Z, ((1 + 2 * Z.pos a) mod 2 + 2 * (((1 + 2 * Z.pos a) / 2) mod Z.pos b))%Z)b, a:positive((Z.pos a / Z.pos b)%Z, (2 * (Z.pos a mod Z.pos b) + 1)%Z) = (((1 + Z.pos a * 2) / 2 / Z.pos b)%Z, ((1 + Z.pos a * 2) mod 2 + 2 * (((1 + Z.pos a * 2) / 2) mod Z.pos b))%Z)b, a:positive((Z.pos a / Z.pos b)%Z, (2 * (Z.pos a mod Z.pos b) + 1)%Z) = (((1 / 2 + Z.pos a) / Z.pos b)%Z, ((1 + Z.pos a * 2) mod 2 + 2 * ((1 / 2 + Z.pos a) mod Z.pos b))%Z)b, a:positive(2 * (Z.pos a mod Z.pos b) + 1)%Z = ((1 + Z.pos a * 2) mod 2 + 2 * ((1 / 2 + Z.pos a) mod Z.pos b))%Zapply Zplus_comm.b, a:positive(2 * (Z.pos a mod Z.pos b) + 1)%Z = (1 mod 2 + 2 * ((1 / 2 + Z.pos a) mod Z.pos b))%Zb:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positiveZpos_div_eucl_aux1 a~0 b~0 = ((Z.pos a~0 / 2 / Z.pos b)%Z, (Z.pos a~0 mod 2 + 2 * ((Z.pos a~0 / 2) mod Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positive(let (q, r) := Zpos_div_eucl_aux1 a b in (q, (2 * r)%Z)) = ((Z.pos a~0 / 2 / Z.pos b)%Z, (Z.pos a~0 mod 2 + 2 * ((Z.pos a~0 / 2) mod Z.pos b))%Z)b:positiveIHb:forall a0 : positive, Zpos_div_eucl_aux1 a0 b = Z.pos_div_eucl a0 (Z.pos b)a:positive(let (q, r) := Z.pos_div_eucl a (Z.pos b) in (q, (2 * r)%Z)) = ((Z.pos a~0 / 2 / Z.pos b)%Z, (Z.pos a~0 mod 2 + 2 * ((Z.pos a~0 / 2) mod Z.pos b))%Z)b, a:positive(let (q, r) := Z.pos_div_eucl a (Z.pos b) in (q, (2 * r)%Z)) = ((Z.pos a~0 / 2 / Z.pos b)%Z, (Z.pos a~0 mod 2 + 2 * ((Z.pos a~0 / 2) mod Z.pos b))%Z)b, a:positive(let (q, r) := Z.div_eucl (Z.pos a) (Z.pos b) in (q, (2 * r)%Z)) = ((Z.pos a~0 / 2 / Z.pos b)%Z, (Z.pos a~0 mod 2 + 2 * ((Z.pos a~0 / 2) mod Z.pos b))%Z)b, a:positive((Z.pos a / Z.pos b)%Z, (2 * (Z.pos a mod Z.pos b))%Z) = ((Z.pos a~0 / 2 / Z.pos b)%Z, (Z.pos a~0 mod 2 + 2 * ((Z.pos a~0 / 2) mod Z.pos b))%Z)b, a:positive((Z.pos a / Z.pos b)%Z, (2 * (Z.pos a mod Z.pos b))%Z) = ((2 * Z.pos a / 2 / Z.pos b)%Z, ((2 * Z.pos a) mod 2 + 2 * ((2 * Z.pos a / 2) mod Z.pos b))%Z)b, a:positive((Z.pos a / Z.pos b)%Z, (2 * (Z.pos a mod Z.pos b))%Z) = ((Z.pos a * 2 / 2 / Z.pos b)%Z, ((Z.pos a * 2) mod 2 + 2 * ((Z.pos a * 2 / 2) mod Z.pos b))%Z)b, a:positive((Z.pos a / Z.pos b)%Z, (2 * (Z.pos a mod Z.pos b))%Z) = ((Z.pos a / Z.pos b)%Z, ((Z.pos a * 2) mod 2 + 2 * (Z.pos a mod Z.pos b))%Z)now rewrite Z_mod_mult.b, a:positive(2 * (Z.pos a mod Z.pos b))%Z = ((Z.pos a * 2) mod 2 + 2 * (Z.pos a mod Z.pos b))%Zeasy.b:positiveIHb:forall a : positive, Zpos_div_eucl_aux1 a b = Z.pos_div_eucl a (Z.pos b)Zpos_div_eucl_aux1 1 b~0 = ((1 / 2 / Z.pos b)%Z, (1 mod 2 + 2 * ((1 / 2) mod Z.pos b))%Z)a:positiveZpos_div_eucl_aux1 a 1 = Z.pos_div_eucl a 1a:positiveZpos_div_eucl_aux1 a 1 = Z.div_eucl (Z.pos a) 1now rewrite Zdiv_1_r, Zmod_1_r. Qed. Definition Zpos_div_eucl_aux (a b : positive) := match Pos.compare a b with | Lt => (Z0, Zpos a) | Eq => (1%Z, Z0) | Gt => Zpos_div_eucl_aux1 a b end.a:positiveZpos_div_eucl_aux1 a 1 = ((Z.pos a / 1)%Z, (Z.pos a mod 1)%Z)forall a b : positive, Zpos_div_eucl_aux a b = Z.pos_div_eucl a (Z.pos b)forall a b : positive, Zpos_div_eucl_aux a b = Z.pos_div_eucl a (Z.pos b)a, b:positiveZpos_div_eucl_aux a b = Z.pos_div_eucl a (Z.pos b)a, b:positivematch (a ?= b)%positive with | Eq => (1%Z, 0%Z) | Lt => (0%Z, Z.pos a) | Gt => Zpos_div_eucl_aux1 a b end = Z.pos_div_eucl a (Z.pos b)a, b:positivematch (a ?= b)%positive with | Eq => (1%Z, 0%Z) | Lt => (0%Z, Z.pos a) | Gt => Zpos_div_eucl_aux1 a b end = Z.div_eucl (Z.pos a) (Z.pos b)a, b:positivematch (a ?= b)%positive with | Eq => (1%Z, 0%Z) | Lt => (0%Z, Z.pos a) | Gt => Zpos_div_eucl_aux1 a b end = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)a, b:positiveH:a = b(1%Z, 0%Z) = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)a, b:positiveH:(a < b)%positive(0%Z, Z.pos a) = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)a, b:positiveH:(b < a)%positiveZpos_div_eucl_aux1 a b = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)a, b:positiveH:(a < b)%positive(0%Z, Z.pos a) = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)a, b:positiveH:(b < a)%positiveZpos_div_eucl_aux1 a b = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)a, b:positiveH:(b < a)%positiveZpos_div_eucl_aux1 a b = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)a, b:positiveH:(b < a)%positiveZ.pos_div_eucl a (Z.pos b) = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)apply Zdiv_eucl_unique. Qed. Definition Zfast_div_eucl (a b : Z) := match a with | Z0 => (0, 0)%Z | Zpos a' => match b with | Z0 => (0, 0)%Z | Zpos b' => Zpos_div_eucl_aux a' b' | Zneg b' => let (q, r) := Zpos_div_eucl_aux a' b' in match r with | Z0 => (-q, 0)%Z | Zpos _ => (-(q + 1), (b + r))%Z | Zneg _ => (-(q + 1), (b + r))%Z end end | Zneg a' => match b with | Z0 => (0, 0)%Z | Zpos b' => let (q, r) := Zpos_div_eucl_aux a' b' in match r with | Z0 => (-q, 0)%Z | Zpos _ => (-(q + 1), (b - r))%Z | Zneg _ => (-(q + 1), (b - r))%Z end | Zneg b' => let (q, r) := Zpos_div_eucl_aux a' b' in (q, (-r)%Z) end end.a, b:positiveH:(b < a)%positiveZ.div_eucl (Z.pos a) (Z.pos b) = ((Z.pos a / Z.pos b)%Z, (Z.pos a mod Z.pos b)%Z)forall a b : Z, Zfast_div_eucl a b = Z.div_eucl a bforall a b : Z, Zfast_div_eucl a b = Z.div_eucl a bintros [|a|a] [|b|b] ; try rewrite Zpos_div_eucl_aux_correct ; easy. Qed. End faster_div. Section Iter. Context {A : Type}. Variable (f : A -> A). Fixpoint iter_nat (n : nat) (x : A) {struct n} : A := match n with | S n' => iter_nat n' (f x) | O => x end.forall a b : Z, match a with | 0%Z => (0%Z, 0%Z) | Z.pos a' => match b with | 0%Z => (0%Z, 0%Z) | Z.pos b' => Zpos_div_eucl_aux a' b' | Z.neg b' => let (q, r) := Zpos_div_eucl_aux a' b' in match r with | 0%Z => ((- q)%Z, 0%Z) | _ => ((- (q + 1))%Z, (b + r)%Z) end end | Z.neg a' => match b with | 0%Z => (0%Z, 0%Z) | Z.pos b' => let (q, r) := Zpos_div_eucl_aux a' b' in match r with | 0%Z => ((- q)%Z, 0%Z) | _ => ((- (q + 1))%Z, (b - r)%Z) end | Z.neg b' => let (q, r) := Zpos_div_eucl_aux a' b' in (q, (- r)%Z) end end = Z.div_eucl a bA:Typef:A -> Aforall (p q : nat) (x : A), iter_nat (p + q) x = iter_nat p (iter_nat q x)A:Typef:A -> Aforall (p q : nat) (x : A), iter_nat (p + q) x = iter_nat p (iter_nat q x)A:Typef:A -> Ap:natforall x : A, iter_nat (p + 0) x = iter_nat p (iter_nat 0 x)A:Typef:A -> Ap, q:natIHq:forall x : A, iter_nat (p + q) x = iter_nat p (iter_nat q x)forall x : A, iter_nat (p + S q) x = iter_nat p (iter_nat (S q) x)A:Typef:A -> Ap, q:natIHq:forall x : A, iter_nat (p + q) x = iter_nat p (iter_nat q x)forall x : A, iter_nat (p + S q) x = iter_nat p (iter_nat (S q) x)A:Typef:A -> Ap, q:natIHq:forall x0 : A, iter_nat (p + q) x0 = iter_nat p (iter_nat q x0)x:Aiter_nat (p + S q) x = iter_nat p (iter_nat (S q) x)apply IHq. Qed.A:Typef:A -> Ap, q:natIHq:forall x0 : A, iter_nat (p + q) x0 = iter_nat p (iter_nat q x0)x:Aiter_nat (S (p + q)) x = iter_nat p (iter_nat (S q) x)A:Typef:A -> Aforall (p : nat) (x : A), iter_nat (S p) x = f (iter_nat p x)A:Typef:A -> Aforall (p : nat) (x : A), iter_nat (S p) x = f (iter_nat p x)A:Typef:A -> Aforall x : A, iter_nat 1 x = f (iter_nat 0 x)A:Typef:A -> Ap:natIHp:forall x : A, iter_nat (S p) x = f (iter_nat p x)forall x : A, iter_nat (S (S p)) x = f (iter_nat (S p) x)A:Typef:A -> Ap:natIHp:forall x : A, iter_nat (S p) x = f (iter_nat p x)forall x : A, iter_nat (S (S p)) x = f (iter_nat (S p) x)A:Typef:A -> Ap:natIHp:forall x : A, iter_nat (S p) x = f (iter_nat p x)forall x : A, iter_nat p (f (f x)) = f (iter_nat p (f x))apply IHp. Qed.A:Typef:A -> Ap:natIHp:forall x0 : A, iter_nat (S p) x0 = f (iter_nat p x0)x:Aiter_nat p (f (f x)) = f (iter_nat p (f x))A:Typef:A -> Aforall (p : positive) (x : A), SpecFloatCopy.iter_pos f p x = iter_nat (Pos.to_nat p) xA:Typef:A -> Aforall (p : positive) (x : A), SpecFloatCopy.iter_pos f p x = iter_nat (Pos.to_nat p) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~1 x = iter_nat (Pos.to_nat p~1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~0 x = iter_nat (Pos.to_nat p~0) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~1 x = iter_nat (S (2 * Pos.to_nat p)) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~0 x = iter_nat (Pos.to_nat p~0) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p (SpecFloatCopy.iter_pos f p (f x)) = iter_nat (Pos.to_nat p + (Pos.to_nat p + 0)) (f x)A:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~0 x = iter_nat (Pos.to_nat p~0) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p (SpecFloatCopy.iter_pos f p (f x)) = iter_nat (Pos.to_nat p + Pos.to_nat p) (f x)A:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~0 x = iter_nat (Pos.to_nat p~0) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p (SpecFloatCopy.iter_pos f p (f x)) = iter_nat (Pos.to_nat p) (iter_nat (Pos.to_nat p) (f x))A:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~0 x = iter_nat (Pos.to_nat p~0) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p (iter_nat (Pos.to_nat p) (f x)) = iter_nat (Pos.to_nat p) (iter_nat (Pos.to_nat p) (f x))A:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~0 x = iter_nat (Pos.to_nat p~0) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~0 x = iter_nat (Pos.to_nat p~0) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p~0 x = iter_nat (2 * Pos.to_nat p) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p (SpecFloatCopy.iter_pos f p x) = iter_nat (Pos.to_nat p + (Pos.to_nat p + 0)) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p (SpecFloatCopy.iter_pos f p x) = iter_nat (Pos.to_nat p + Pos.to_nat p) xA:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p (SpecFloatCopy.iter_pos f p x) = iter_nat (Pos.to_nat p) (iter_nat (Pos.to_nat p) x)A:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xA:Typef:A -> Ap:positiveIHp:forall x0 : A, SpecFloatCopy.iter_pos f p x0 = iter_nat (Pos.to_nat p) x0x:ASpecFloatCopy.iter_pos f p (iter_nat (Pos.to_nat p) x) = iter_nat (Pos.to_nat p) (iter_nat (Pos.to_nat p) x)A:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) xeasy. Qed. End Iter.A:Typef:A -> Ax:ASpecFloatCopy.iter_pos f 1 x = iter_nat (Pos.to_nat 1) x