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) *)
(************************************************************************)
Type Z viewed modulo a particular constant corresponds to Z/nZ
as defined abstractly in CyclicAxioms.
Even if the construction provided here is not reused for building
the efficient arbitrary precision numbers, it provides a simple
implementation of CyclicAxioms, hence ensuring its coherence.
Set Implicit Arguments. Require Import Bool. Require Import ZArith. Require Import Znumtheory. Require Import Zpow_facts. Require Import DoubleType. Require Import CyclicAxioms. Local Open Scope Z_scope. Section ZModulo. Variable digits : positive. Hypothesis digits_ne_1 : digits <> 1%positive. Definition wB := base digits. Definition t := Z. Definition zdigits := Zpos digits. Definition to_Z x := x mod wB. Notation "[| x |]" := (to_Z x) (at level 0, x at level 99). Notation "[+| c |]" := (interp_carry 1 wB to_Z c) (at level 0, c at level 99). Notation "[-| c |]" := (interp_carry (-1) wB to_Z c) (at level 0, c at level 99). Notation "[|| x ||]" := (zn2z_to_Z wB to_Z x) (at level 0, x at level 99).digits:positivedigits_ne_1:digits <> 1%positive1 < Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positive1 < Z.pos digitsdestruct 1; auto. Qed. Let digits_gt_1 := spec_more_than_1_digit.digits:positivedigits_ne_1:1%positive <> 1%positive1%positive <> 1%positive -> (1 ?= 1) = Ltdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitswB > 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitswB > 0unfold wB, base; auto with zarith. Qed. Hint Resolve wB_pos : core.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits0 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, 0 <= [|x|]unfold to_Z; intros; destruct (Z_mod_lt x wB wB_pos); auto. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, 0 <= [|x|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|x|] < wBunfold to_Z; intros; destruct (Z_mod_lt x wB wB_pos); auto. Qed. Hint Resolve spec_to_Z_1 spec_to_Z_2 : core.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|x|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, 0 <= [|x|] < wBauto. Qed. Definition of_pos x := let (q,r) := Z.pos_div_eucl x wB in (N_of_Z q, r).digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, 0 <= [|x|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall p : positive, Z.pos p = Z.of_N (fst (of_pos p)) * wB + [|snd (of_pos p)|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall p : positive, Z.pos p = Z.of_N (fst (of_pos p)) * wB + [|snd (of_pos p)|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveZ.pos p = Z.of_N (fst (let (q, r) := Z.pos_div_eucl p wB in (Z.to_N q, r))) * wB + [|snd (let (q, r) := Z.pos_div_eucl p wB in (Z.to_N q, r))|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positive(let (q, r) := Z.pos_div_eucl p wB in Z.pos p = wB * q + r /\ 0 <= r < wB) -> Z.pos p = Z.of_N (fst (let (q, r) := Z.pos_div_eucl p wB in (Z.to_N q, r))) * wB + [|snd (let (q, r) := Z.pos_div_eucl p wB in (Z.to_N q, r))|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positivez, z0:ZH:Z.pos p = wB * z + z0H0:0 <= z0 < wBZ.pos p = Z.of_N (Z.to_N z) * wB + [|z0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positivez, z0:ZH:Z.pos p = wB * z + z0H0:0 <= z0 < wBZ.pos p = Z.of_N (Z.to_N z) * wB + z0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positivez, z0:ZH:Z.pos p = wB * z + z0H0:0 <= z0 < wB0 <= zdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positivez, z0:ZH:Z.pos p = wB * z + z0H0:0 <= z0 < wBH1:0 <= zZ.pos p = Z.of_N (Z.to_N z) * wB + z0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positivez, z0:ZH:Z.pos p = wB * z + z0H0:0 <= z0 < wB0 <= Z.pos p / wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positivez, z0:ZH:Z.pos p = wB * z + z0H0:0 <= z0 < wBH1:0 <= zZ.pos p = Z.of_N (Z.to_N z) * wB + z0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positivez, z0:ZH:Z.pos p = wB * z + z0H0:0 <= z0 < wBH1:0 <= zZ.pos p = Z.of_N (Z.to_N z) * wB + z0rewrite Z.mul_comm; auto. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positivez, z0:ZH:Z.pos p = wB * z + z0H0:0 <= z0 < wBH1:0 <= zZ.pos p = z * wB + z0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits[|zdigits|] = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits[|zdigits|] = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsZ.pos digits mod wB = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits0 <= Z.pos digits < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits0 <= Z.pos digits < 2 ^ Z.pos digitsapply Zpower2_lt_lin; auto with zarith. Qed. Definition zero := 0. Definition one := 1. Definition minus_one := wB - 1.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsZ.pos digits < 2 ^ Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits[|zero|] = 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits[|zero|] = 0apply Zmod_small; generalize wB_pos; auto with zarith. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits0 mod wB = 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits[|one|] = 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits[|one|] = 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits1 mod wB = 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits1 < 2 ^ Z.pos digitsapply Zpower2_lt_lin; auto with zarith. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsZ.pos digits < 2 ^ Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits[|minus_one|] = wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits[|minus_one|] = wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits(wB - 1) mod wB = wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits0 <= wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits0 <= 2 ^ Z.pos digits - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digits1 <= 2 ^ Z.pos digitsapply Zpower2_le_lin; auto with zarith. Qed. Definition compare x y := Z.compare [|x|] [|y|].digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsZ.pos digits <= 2 ^ Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, compare x y = ([|x|] ?= [|y|])reflexivity. Qed. Definition eq0 x := match [|x|] with Z0 => true | _ => false end.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, compare x y = ([|x|] ?= [|y|])digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, eq0 x = true -> [|x|] = 0unfold eq0; intros; now destruct [|x|]. Qed. Definition opp_c x := if eq0 x then C0 0 else C1 (- x). Definition opp x := - x. Definition opp_carry x := - x - 1.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, eq0 x = true -> [|x|] = 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [-|opp_c x|] = - [|x|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [-|opp_c x|] = - [|x|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zinterp_carry (-1) wB (fun x0 : Z => x0 mod wB) (if eq0 x then C0 0 else C1 (- x)) = - (x mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = true0 mod wB = - (x mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = false-1 * wB + - x mod wB = - (x mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = false-1 * wB + - x mod wB = - (x mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falsex mod wB <> 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falseH0:x mod wB <> 0-1 * wB + - x mod wB = - (x mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:match x mod wB with | 0 => true | _ => false end = falsex mod wB <> 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falseH0:x mod wB <> 0-1 * wB + - x mod wB = - (x mod wB)rewrite Z_mod_nz_opp_full; auto with zarith. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falseH0:x mod wB <> 0-1 * wB + - x mod wB = - (x mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|opp x|] = - [|x|] mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|opp x|] = - [|x|] mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z- x mod wB = - (x mod wB) mod wBrewrite Zminus_mod_idemp_r; simpl; auto. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z- x mod wB = (0 - x mod wB) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|opp_carry x|] = wB - [|x|] - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|opp_carry x|] = wB - [|x|] - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(- x - 1) mod wB = wB - x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(-1 - x) mod wB = wB - x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(-1 - x mod wB) mod wB = wB - x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(0 + (-1 - x mod wB)) mod wB = wB - x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(wB mod wB + (-1 - x mod wB)) mod wB = wB - x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(wB + (-1 - x mod wB)) mod wB = wB - x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(wB - x mod wB - 1) mod wB = wB - x mod wB - 1generalize (Z_mod_lt x wB wB_pos); omega. Qed. Definition succ_c x := let y := Z.succ x in if eq0 y then C1 0 else C0 y. Definition add_c x y := let z := [|x|] + [|y|] in if Z_lt_le_dec z wB then C0 z else C1 (z-wB). Definition add_carry_c x y := let z := [|x|]+[|y|]+1 in if Z_lt_le_dec z wB then C0 z else C1 (z-wB). Definition succ := Z.succ. Definition add := Z.add. Definition add_carry x y := x + y + 1.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z0 <= wB - x mod wB - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y z : Z, z > 0 -> (x - y) mod z = 0 -> x mod z = y mod zdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y z : Z, z > 0 -> (x - y) mod z = 0 -> x mod z = y mod zdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, z:ZH:z > 0H0:(x - y) mod z = 0x mod z = y mod zdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, z:ZH:z > 0H0:(x - y) mod z = 0x - y = z * ((x - y) / z) -> x mod z = y mod zdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, z:ZH:z > 0H0:(x - y) mod z = 0k:ZHeqk:k = (x - y) / zx - y = z * k -> x mod z = y mod zdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, z:ZH:z > 0H0:(x - y) mod z = 0k:ZHeqk:k = (x - y) / zx = y + k * z -> x mod z = y mod znow apply Z_mod_plus. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsy, z:ZH:z > 0k:ZHeqk:k = (y + k * z - y) / zH0:(y + k * z - y) mod z = 0(y + k * z) mod z = y mod zdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [+|succ_c x|] = [|x|] + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [+|succ_c x|] = [|x|] + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zinterp_carry 1 wB (fun x0 : Z => x0 mod wB) (if eq0 (x + 1) then C1 0 else C0 (x + 1)) = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = true1 * wB + 0 mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = truewB + 0 mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = truewB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = truex mod wB + 1 = wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = truex mod wB = wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = trueH0:(x + 1) mod wB = 0x mod wB = wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = trueH0:(x + 1) mod wB = 0x mod wB = (wB - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = trueH0:(x + 1) mod wB = 0x mod wB = -1 mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = false(x + 1) mod wB <> 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0x mod wB + 1 <> wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0H1:x mod wB + 1 <> wB(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:x mod wB + 1 = wB(x + 1) mod wB = 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0H1:x mod wB + 1 <> wB(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:x mod wB = wB - 1(x + 1) mod wB = 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0H1:x mod wB + 1 <> wB(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:x mod wB = wB - 1(wB - 1 + 1) mod wB = 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0H1:x mod wB + 1 <> wB(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0H1:x mod wB + 1 <> wB(x + 1) mod wB = x mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0H1:x mod wB + 1 <> wB(x mod wB + 1) mod wB = x mod wB + 1generalize (Z_mod_lt x wB wB_pos); omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 (x + 1) = falseH0:(x + 1) mod wB <> 0H1:x mod wB + 1 <> wB0 <= x mod wB + 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [+|add_c x y|] = [|x|] + [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [+|add_c x y|] = [|x|] + [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zmatch (if Z_lt_le_dec (x mod wB + y mod wB) wB then C0 (x mod wB + y mod wB) else C1 (x mod wB + y mod wB - wB)) with | C0 x0 => x0 mod wB | C1 x0 => 1 * wB + x0 mod wB end = x mod wB + y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB + y mod wB < wB(x mod wB + y mod wB) mod wB = x mod wB + y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:wB <= x mod wB + y mod wB1 * wB + (x mod wB + y mod wB - wB) mod wB = x mod wB + y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:wB <= x mod wB + y mod wB1 * wB + (x mod wB + y mod wB - wB) mod wB = x mod wB + y mod wBapply Zmod_small; generalize (Z_mod_lt x wB wB_pos) (Z_mod_lt y wB wB_pos); omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:wB <= x mod wB + y mod wB(x mod wB + y mod wB - wB) mod wB = x mod wB + y mod wB - wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [+|add_carry_c x y|] = [|x|] + [|y|] + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [+|add_carry_c x y|] = [|x|] + [|y|] + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zmatch (if Z_lt_le_dec (x mod wB + y mod wB + 1) wB then C0 (x mod wB + y mod wB + 1) else C1 (x mod wB + y mod wB + 1 - wB)) with | C0 x0 => x0 mod wB | C1 x0 => 1 * wB + x0 mod wB end = x mod wB + y mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB + y mod wB + 1 < wB(x mod wB + y mod wB + 1) mod wB = x mod wB + y mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:wB <= x mod wB + y mod wB + 11 * wB + (x mod wB + y mod wB + 1 - wB) mod wB = x mod wB + y mod wB + 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:wB <= x mod wB + y mod wB + 11 * wB + (x mod wB + y mod wB + 1 - wB) mod wB = x mod wB + y mod wB + 1apply Zmod_small; generalize (Z_mod_lt x wB wB_pos) (Z_mod_lt y wB wB_pos); omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:wB <= x mod wB + y mod wB + 1(x mod wB + y mod wB + 1 - wB) mod wB = x mod wB + y mod wB + 1 - wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|succ x|] = ([|x|] + 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|succ x|] = ([|x|] + 1) mod wBsymmetry; apply Zplus_mod_idemp_l. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(x + 1) mod wB = (x mod wB + 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|add x y|] = ([|x|] + [|y|]) mod wBintros; unfold add, to_Z; apply Zplus_mod. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|add x y|] = ([|x|] + [|y|]) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|add_carry x y|] = ([|x|] + [|y|] + 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|add_carry x y|] = ([|x|] + [|y|] + 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z(x + y + 1) mod wB = (x mod wB + y mod wB + 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z((x + y) mod wB + 1) mod wB = (x mod wB + y mod wB + 1) mod wBrewrite Zplus_mod_idemp_l; auto. Qed. Definition pred_c x := if eq0 x then C1 (wB-1) else C0 (x-1). Definition sub_c x y := let z := [|x|]-[|y|] in if Z_lt_le_dec z 0 then C1 (wB+z) else C0 z. Definition sub_carry_c x y := let z := [|x|]-[|y|]-1 in if Z_lt_le_dec z 0 then C1 (wB+z) else C0 z. Definition pred := Z.pred. Definition sub := Z.sub. Definition sub_carry x y := x - y - 1.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z((x mod wB + y mod wB) mod wB + 1) mod wB = (x mod wB + y mod wB + 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [-|pred_c x|] = [|x|] - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [-|pred_c x|] = [|x|] - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zmatch (if eq0 x then C1 (wB - 1) else C0 (x - 1)) with | C0 x0 => x0 mod wB | C1 x0 => -1 * wB + x0 mod wB end = x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = true-1 * wB + (wB - 1) mod wB = x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = false(x - 1) mod wB = x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = true-1 * wB + (wB - 1) mod wB = 0 - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = false(x - 1) mod wB = x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = truewB - 1 = (wB - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = false(x - 1) mod wB = x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = false(x - 1) mod wB = x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falsex mod wB <> 0digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falseH0:x mod wB <> 0(x - 1) mod wB = x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falseH0:x mod wB <> 0(x - 1) mod wB = x mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falseH0:x mod wB <> 0(x mod wB - 1) mod wB = x mod wB - 1generalize (Z_mod_lt x wB wB_pos); omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:eq0 x = falseH0:x mod wB <> 00 <= x mod wB - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [-|sub_c x y|] = [|x|] - [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [-|sub_c x y|] = [|x|] - [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zmatch (if Z_lt_le_dec (x mod wB - y mod wB) 0 then C1 (wB + (x mod wB - y mod wB)) else C0 (x mod wB - y mod wB)) with | C0 x0 => x0 mod wB | C1 x0 => -1 * wB + x0 mod wB end = x mod wB - y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB < 0-1 * wB + (wB + (x mod wB - y mod wB)) mod wB = x mod wB - y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB(x mod wB - y mod wB) mod wB = x mod wB - y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB < 0-1 * wB + (wB + (x mod wB - y mod wB)) = x mod wB - y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB < 0wB + (x mod wB - y mod wB) = (wB + (x mod wB - y mod wB)) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB(x mod wB - y mod wB) mod wB = x mod wB - y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB < 0wB + (x mod wB - y mod wB) = (wB + (x mod wB - y mod wB)) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB(x mod wB - y mod wB) mod wB = x mod wB - y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB < 00 <= wB + (x mod wB - y mod wB) < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB(x mod wB - y mod wB) mod wB = x mod wB - y mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB(x mod wB - y mod wB) mod wB = x mod wB - y mod wBgeneralize wB_pos (Z_mod_lt x wB wB_pos) (Z_mod_lt y wB wB_pos); omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB0 <= x mod wB - y mod wB < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [-|sub_carry_c x y|] = [|x|] - [|y|] - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [-|sub_carry_c x y|] = [|x|] - [|y|] - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zmatch (if Z_lt_le_dec (x mod wB - y mod wB - 1) 0 then C1 (wB + (x mod wB - y mod wB - 1)) else C0 (x mod wB - y mod wB - 1)) with | C0 x0 => x0 mod wB | C1 x0 => -1 * wB + x0 mod wB end = x mod wB - y mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB - 1 < 0-1 * wB + (wB + (x mod wB - y mod wB - 1)) mod wB = x mod wB - y mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB - 1(x mod wB - y mod wB - 1) mod wB = x mod wB - y mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB - 1 < 0-1 * wB + (wB + (x mod wB - y mod wB - 1)) = x mod wB - y mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB - 1 < 0wB + (x mod wB - y mod wB - 1) = (wB + (x mod wB - y mod wB - 1)) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB - 1(x mod wB - y mod wB - 1) mod wB = x mod wB - y mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB - 1 < 0wB + (x mod wB - y mod wB - 1) = (wB + (x mod wB - y mod wB - 1)) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB - 1(x mod wB - y mod wB - 1) mod wB = x mod wB - y mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:x mod wB - y mod wB - 1 < 00 <= wB + (x mod wB - y mod wB - 1) < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB - 1(x mod wB - y mod wB - 1) mod wB = x mod wB - y mod wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB - 1(x mod wB - y mod wB - 1) mod wB = x mod wB - y mod wB - 1generalize wB_pos (Z_mod_lt x wB wB_pos) (Z_mod_lt y wB wB_pos); omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zl:0 <= x mod wB - y mod wB - 10 <= x mod wB - y mod wB - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|pred x|] = ([|x|] - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|pred x|] = ([|x|] - 1) mod wBrewrite <- Zplus_mod_idemp_l; auto. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z(x + -1) mod wB = (x mod wB - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|sub x y|] = ([|x|] - [|y|]) mod wBintros; unfold sub, to_Z; apply Zminus_mod. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|sub x y|] = ([|x|] - [|y|]) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|sub_carry x y|] = ([|x|] - [|y|] - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|sub_carry x y|] = ([|x|] - [|y|] - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z(x - y - 1) mod wB = (x mod wB - y mod wB - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z((x - y) mod wB - 1) mod wB = (x mod wB - y mod wB - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z((x mod wB - y mod wB) mod wB - 1) mod wB = (x mod wB - y mod wB - 1) mod wBauto. Qed. Definition mul_c x y := let (h,l) := Z.div_eucl ([|x|]*[|y|]) wB in if eq0 h then if eq0 l then W0 else WW h l else WW h l. Definition mul := Z.mul. Definition square_c x := mul_c x x.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z(x mod wB - y mod wB - 1) mod wB = (x mod wB - y mod wB - 1) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [||mul_c x y||] = [|x|] * [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [||mul_c x y||] = [|x|] * [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Zmatch (let (h, l) := Z.div_eucl ([|x|] * [|y|]) wB in if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = [|x|] * [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZZ.div_eucl ([|x|] * [|y|]) wB = ([|x|] * [|y|] / wB, ([|x|] * [|y|]) mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:Z.div_eucl ([|x|] * [|y|]) wB = ([|x|] * [|y|] / wB, ([|x|] * [|y|]) mod wB)match (let (h, l) := Z.div_eucl ([|x|] * [|y|]) wB in if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = [|x|] * [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:Z.div_eucl ([|x|] * [|y|]) wB = ([|x|] * [|y|] / wB, ([|x|] * [|y|]) mod wB)match (let (h, l) := Z.div_eucl ([|x|] * [|y|]) wB in if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = [|x|] * [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:(h, l) = ([|x|] * [|y|] / wB, ([|x|] * [|y|]) mod wB)[|x|] * [|y|] = wB * h + l /\ 0 <= l < wB -> match (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = [|x|] * [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = [|x|] * [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wB[|l|] = ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = l[|h|] = hdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lH4:[|h|] = hmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = l0 <= h < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lH4:[|h|] = hmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, l:ZH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * ([|x|] * [|y|] / wB) + lH1:0 <= l < wBH3:[|l|] = l0 <= [|x|] * [|y|] / wB < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lH4:[|h|] = hmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, l:ZH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * ([|x|] * [|y|] / wB) + lH1:0 <= l < wBH3:[|l|] = l0 <= [|x|] * [|y|] / wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, l:ZH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * ([|x|] * [|y|] / wB) + lH1:0 <= l < wBH3:[|l|] = l[|x|] * [|y|] / wB < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lH4:[|h|] = hmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, l:ZH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * ([|x|] * [|y|] / wB) + lH1:0 <= l < wBH3:[|l|] = l[|x|] * [|y|] / wB < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lH4:[|h|] = hmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, l:ZH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * ([|x|] * [|y|] / wB) + lH1:0 <= l < wBH3:[|l|] = l[|x|] * [|y|] < wB * wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lH4:[|h|] = hmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH:h = [|x|] * [|y|] / wBH2:l = ([|x|] * [|y|]) mod wBH0:[|x|] * [|y|] = wB * h + lH1:0 <= l < wBH3:[|l|] = lH4:[|h|] = hmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hmatch (if eq0 h then if eq0 l then W0 else WW h l else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hH:eq0 h = truematch (if eq0 l then W0 else WW h l) with | W0 => 0 | WW xh xl => [|xh|] * wB + [|xl|] end = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hH:eq0 h = false[|h|] * wB + [|l|] = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hH:eq0 h = trueH0:eq0 l = true0 = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hH:eq0 h = trueH0:eq0 l = false[|h|] * wB + [|l|] = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hH:eq0 h = false[|h|] * wB + [|l|] = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hH:eq0 h = trueH0:eq0 l = false[|h|] * wB + [|l|] = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hH:eq0 h = false[|h|] * wB + [|l|] = wB * h + lrewrite H3, H4; auto with zarith. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, h, l:ZH3:[|l|] = lH4:[|h|] = hH:eq0 h = false[|h|] * wB + [|l|] = wB * h + ldigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|mul x y|] = ([|x|] * [|y|]) mod wBintros; unfold mul, to_Z; apply Zmult_mod. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, [|mul x y|] = ([|x|] * [|y|]) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [||square_c x||] = [|x|] * [|x|]intros x; exact (spec_mul_c x x). Qed. Definition div x y := Z.div_eucl [|x|] [|y|].digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [||square_c x||] = [|x|] * [|x|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, 0 < [|b|] -> let (q, r) := div a b in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, 0 < [|b|] -> let (q, r) := div a b in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]let (q, r) := Z.div_eucl [|a|] [|b|] in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0let (q, r) := Z.div_eucl [|a|] [|b|] in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0Z.div_eucl [|a|] [|b|] = ([|a|] / [|b|], [|a|] mod [|b|])digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0H1:Z.div_eucl [|a|] [|b|] = ([|a|] / [|b|], [|a|] mod [|b|])let (q, r) := Z.div_eucl [|a|] [|b|] in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0H1:Z.div_eucl [|a|] [|b|] = ([|a|] / [|b|], [|a|] mod [|b|])let (q, r) := Z.div_eucl [|a|] [|b|] in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0H1:Z.div_eucl [|a|] [|b|] = ([|a|] / [|b|], [|a|] mod [|b|])(let (q, r) := Z.div_eucl [|a|] [|b|] in [|a|] = [|b|] * q + r /\ 0 <= r < [|b|]) -> let (q, r) := Z.div_eucl [|a|] [|b|] in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:(q, r) = ([|a|] / [|b|], [|a|] mod [|b|])H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|][|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|][|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|][|r|] = rdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = r[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = r[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = r[|q|] = qdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = r0 <= q < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0r:ZH4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * ([|a|] / [|b|]) + rH3:0 <= r < [|b|]H5:[|r|] = r0 <= [|a|] / [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0r:ZH4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * ([|a|] / [|b|]) + rH3:0 <= r < [|b|]H5:[|r|] = r0 <= [|a|] / [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0r:ZH4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * ([|a|] / [|b|]) + rH3:0 <= r < [|b|]H5:[|r|] = r[|a|] / [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0r:ZH4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * ([|a|] / [|b|]) + rH3:0 <= r < [|b|]H5:[|r|] = r[|a|] / [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0r:ZH4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * ([|a|] / [|b|]) + rH3:0 <= r < [|b|]H5:[|r|] = r[|a|] < wB * [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0r:ZH4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * ([|a|] / [|b|]) + rH3:0 <= r < [|b|]H5:[|r|] = r[|a|] < wB * 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0r:ZH4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * ([|a|] / [|b|]) + rH3:0 <= r < [|b|]H5:[|r|] = rwB * 1 <= wB * [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0r:ZH4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * ([|a|] / [|b|]) + rH3:0 <= r < [|b|]H5:[|r|] = rwB * 1 <= wB * [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]rewrite H5, H6; rewrite Z.mul_comm; auto with zarith. Qed. Definition div_gt := div.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 0q, r:ZH1:q = [|a|] / [|b|]H4:r = [|a|] mod [|b|]H2:[|a|] = [|b|] * q + rH3:0 <= r < [|b|]H5:[|r|] = rH6:[|q|] = q[|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, [|a|] > [|b|] -> 0 < [|b|] -> let (q, r) := div_gt a b in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, [|a|] > [|b|] -> 0 < [|b|] -> let (q, r) := div_gt a b in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]apply spec_div; auto. Qed. Definition modulo x y := [|x|] mod [|y|]. Definition modulo_gt x y := [|x|] mod [|y|].digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:[|a|] > [|b|]H0:0 < [|b|]let (q, r) := div_gt a b in [|a|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, 0 < [|b|] -> [|modulo a b|] = [|a|] mod [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, 0 < [|b|] -> [|modulo a b|] = [|a|] mod [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|][|[|a|] mod [|b|]|] = [|a|] mod [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]0 <= [|a|] mod [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 00 <= [|a|] mod [|b|] < wBfold [|b|]; omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 < [|b|]H0:[|b|] > 00 <= [|a|] mod [|b|] < [|b|] -> 0 <= b mod wB < wB -> 0 <= [|a|] mod [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, [|a|] > [|b|] -> 0 < [|b|] -> [|modulo_gt a b|] = [|a|] mod [|b|]intros; apply spec_modulo; auto. Qed. Definition gcd x y := Z.gcd [|x|] [|y|]. Definition gcd_gt x y := Z.gcd [|x|] [|y|].digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, [|a|] > [|b|] -> 0 < [|b|] -> [|modulo_gt a b|] = [|a|] mod [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, 0 <= a -> 0 <= b -> Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, 0 <= a -> 0 <= b -> Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bZ.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bH2:(Z.gcd a b | a)H3:(Z.gcd a b | b)H4:forall x : Z, (x | a) -> (x | b) -> (x | Z.gcd a b)Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bZ.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bZ.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a b0 <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 00 <= qdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qZ.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qZ.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qe:q = 0Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsb:ZH:0 <= 0H0:0 <= bq':ZHneq:Z.gcd 0 b <> 0H4:0 <= Z.gcd 0 bH3:b = q' * Z.gcd 0 bH1:0 <= 0Z.abs b <= Z.max 0 bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0Z.gcd a b <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0Z.gcd a b <= adigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0a <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0Z.gcd a b <= q * Z.gcd a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0a <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 01 * Z.gcd a b <= q * Z.gcd a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0a <= Z.max a bgeneralize (Zmax_spec a b); omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= aH0:0 <= bq:ZH2:a = q * Z.gcd a bq':ZH3:b = q' * Z.gcd a bH4:0 <= Z.gcd a bHneq:Z.gcd a b <> 0H1:0 <= qn:q <> 0a <= Z.max a bdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, Zis_gcd [|a|] [|b|] [|gcd a b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, Zis_gcd [|a|] [|b|] [|gcd a b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZZis_gcd [|a|] [|b|] [|Z.gcd [|a|] [|b|]|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= a mod wB < wBH0:0 <= b mod wB < wBZis_gcd [|a|] [|b|] [|Z.gcd [|a|] [|b|]|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZis_gcd [|a|] [|b|] [|Z.gcd [|a|] [|b|]|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZis_gcd [|a|] [|b|] (Z.gcd [|a|] [|b|])digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZ.gcd [|a|] [|b|] = [|Z.gcd [|a|] [|b|]|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZ.gcd [|a|] [|b|] = [|Z.gcd [|a|] [|b|]|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wB0 <= Z.gcd [|a|] [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wB0 <= Z.gcd [|a|] [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZ.gcd [|a|] [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZ.gcd [|a|] [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZ.gcd [|a|] [|b|] <= Z.max [|a|] [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZ.max [|a|] [|b|] < wBgeneralize (Zmax_spec [|a|] [|b|]); omega. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:0 <= [|a|] < wBH0:0 <= [|b|] < wBZ.max [|a|] [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, [|a|] > [|b|] -> Zis_gcd [|a|] [|b|] [|gcd_gt a b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a b : Z, [|a|] > [|b|] -> Zis_gcd [|a|] [|b|] [|gcd_gt a b|]apply spec_gcd; auto. Qed. Definition div21 a1 a2 b := Z.div_eucl ([|a1|]*wB+[|a2|]) [|b|].digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa, b:ZH:[|a|] > [|b|]Zis_gcd [|a|] [|b|] [|gcd_gt a b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a1 a2 b : Z, wB / 2 <= [|b|] -> [|a1|] < [|b|] -> let (q, r) := div21 a1 a2 b in [|a1|] * wB + [|a2|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall a1 a2 b : Z, wB / 2 <= [|b|] -> [|a1|] < [|b|] -> let (q, r) := div21 a1 a2 b in [|a1|] * wB + [|a2|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]let (q, r) := Z.div_eucl ([|a1|] * wB + [|a2|]) [|b|] in [|a1|] * wB + [|a2|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBlet (q, r) := Z.div_eucl ([|a1|] * wB + [|a2|]) [|b|] in [|a1|] * wB + [|a2|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBlet (q, r) := Z.div_eucl ([|a1|] * wB + [|a2|]) [|b|] in [|a1|] * wB + [|a2|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0let (q, r) := Z.div_eucl ([|a1|] * wB + [|a2|]) [|b|] in [|a1|] * wB + [|a2|] = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]let (q, r) := Z.div_eucl a [|b|] in a = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]Z.div_eucl a [|b|] = (a / [|b|], a mod [|b|])digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]H4:Z.div_eucl a [|b|] = (a / [|b|], a mod [|b|])let (q, r) := Z.div_eucl a [|b|] in a = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]H4:Z.div_eucl a [|b|] = (a / [|b|], a mod [|b|])let (q, r) := Z.div_eucl a [|b|] in a = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]H4:Z.div_eucl a [|b|] = (a / [|b|], a mod [|b|])(let (q, r) := Z.div_eucl a [|b|] in a = [|b|] * q + r /\ 0 <= r < [|b|]) -> let (q, r) := Z.div_eucl a [|b|] in a = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:(q, r) = (a / [|b|], a mod [|b|])H5:a = [|b|] * q + rH6:0 <= r < [|b|]a = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]a = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|][|r|] = rdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = ra = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = ra = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = r[|q|] = qdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = r0 <= q < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]r:ZH7:r = a mod [|b|]H5:a = [|b|] * (a / [|b|]) + rH6:0 <= r < [|b|]H8:[|r|] = r0 <= a / [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]r:ZH7:r = a mod [|b|]H5:a = [|b|] * (a / [|b|]) + rH6:0 <= r < [|b|]H8:[|r|] = r0 <= a / [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]r:ZH7:r = a mod [|b|]H5:a = [|b|] * (a / [|b|]) + rH6:0 <= r < [|b|]H8:[|r|] = ra / [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]r:ZH7:r = a mod [|b|]H5:a = [|b|] * (a / [|b|]) + rH6:0 <= r < [|b|]H8:[|r|] = r0 <= adigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]r:ZH7:r = a mod [|b|]H5:a = [|b|] * (a / [|b|]) + rH6:0 <= r < [|b|]H8:[|r|] = ra / [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]r:ZH7:r = a mod [|b|]H5:a = [|b|] * (a / [|b|]) + rH6:0 <= r < [|b|]H8:[|r|] = ra / [|b|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]r:ZH7:r = a mod [|b|]H5:a = [|b|] * (a / [|b|]) + rH6:0 <= r < [|b|]H8:[|r|] = ra < wB * [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0r:ZH5:[|a1|] * wB + [|a2|] = [|b|] * (([|a1|] * wB + [|a2|]) / [|b|]) + rH7:r = ([|a1|] * wB + [|a2|]) mod [|b|]H6:0 <= r < [|b|]H8:[|r|] = r[|a1|] * wB + [|a2|] < wB * [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0r:ZH5:[|a1|] * wB + [|a2|] = [|b|] * (([|a1|] * wB + [|a2|]) / [|b|]) + rH7:r = ([|a1|] * wB + [|a2|]) mod [|b|]H6:0 <= r < [|b|]H8:[|r|] = r[|a1|] * wB + [|a2|] < ([|b|] - 1) * wB + wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]rewrite H8, H9; rewrite Z.mul_comm; auto with zarith. Qed. Definition add_mul_div p x y := ([|x|] * (2 ^ [|p|]) + [|y|] / (2 ^ ((Zpos digits) - [|p|]))).digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsa1, a2, b:ZH:wB / 2 <= [|b|]H0:[|a1|] < [|b|]H1:0 <= [|a1|] < wBH2:0 <= [|a2|] < wBH3:[|b|] > 0a:ZHeqa:a = [|a1|] * wB + [|a2|]q, r:ZH4:q = a / [|b|]H7:r = a mod [|b|]H5:a = [|b|] * q + rH6:0 <= r < [|b|]H8:[|r|] = rH9:[|q|] = qa = [|q|] * [|b|] + [|r|] /\ 0 <= [|r|] < [|b|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y p : Z, [|p|] <= Z.pos digits -> [|add_mul_div p x y|] = ([|x|] * 2 ^ [|p|] + [|y|] / 2 ^ (Z.pos digits - [|p|])) mod wBintros; unfold add_mul_div; auto. Qed. Definition pos_mod p w := [|w|] mod (2 ^ [|p|]).digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y p : Z, [|p|] <= Z.pos digits -> [|add_mul_div p x y|] = ([|x|] * 2 ^ [|p|] + [|y|] / 2 ^ (Z.pos digits - [|p|])) mod wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall w p : Z, [|pos_mod p w|] = [|w|] mod 2 ^ [|p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall w p : Z, [|pos_mod p w|] = [|w|] mod 2 ^ [|p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsw, p:Z[|[|w|] mod 2 ^ [|p|]|] = [|w|] mod 2 ^ [|p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsw, p:Z0 <= [|w|] mod 2 ^ [|p|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsw, p:ZH:2 ^ [|p|] > 0 -> 0 <= [|w|] mod 2 ^ [|p|] < 2 ^ [|p|]0 <= [|w|] mod 2 ^ [|p|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsw, p:ZH:2 ^ [|p|] > 0 -> 0 <= [|w|] mod 2 ^ [|p|] < 2 ^ [|p|]0 <= [|w|] mod 2 ^ [|p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsw, p:ZH:2 ^ [|p|] > 0 -> 0 <= [|w|] mod 2 ^ [|p|] < 2 ^ [|p|][|w|] mod 2 ^ [|p|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsw, p:ZH:2 ^ [|p|] > 0 -> 0 <= [|w|] mod 2 ^ [|p|] < 2 ^ [|p|][|w|] mod 2 ^ [|p|] < wBapply Zmod_le; auto with zarith. Qed. Definition is_even x := if Z.eq_dec ([|x|] mod 2) 0 then true else false.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsw, p:ZH:2 ^ [|p|] > 0 -> 0 <= [|w|] mod 2 ^ [|p|] < 2 ^ [|p|][|w|] mod 2 ^ [|p|] <= [|w|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, if is_even x then [|x|] mod 2 = 0 else [|x|] mod 2 = 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, if is_even x then [|x|] mod 2 = 0 else [|x|] mod 2 = 1generalize (Z_mod_lt [|x|] 2); omega. Qed. Definition sqrt x := Z.sqrt [|x|].digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zn:[|x|] mod 2 <> 0[|x|] mod 2 = 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|sqrt x|] ^ 2 <= [|x|] < ([|sqrt x|] + 1) ^ 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|sqrt x|] ^ 2 <= [|x|] < ([|sqrt x|] + 1) ^ 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z[|sqrt x|] ^ 2 <= [|x|] < ([|sqrt x|] + 1) ^ 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z[|Z.sqrt [|x|]|] ^ 2 <= [|x|] < ([|Z.sqrt [|x|]|] + 1) ^ 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z[|Z.sqrt [|x|]|] * [|Z.sqrt [|x|]|] <= [|x|] < ([|Z.sqrt [|x|]|] + 1) * ([|Z.sqrt [|x|]|] + 1)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZZ.sqrt [|x|] * Z.sqrt [|x|] <= [|x|] < (Z.sqrt [|x|] + 1) * (Z.sqrt [|x|] + 1)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZZ.sqrt [|x|] = [|Z.sqrt [|x|]|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZZ.sqrt [|x|] = [|Z.sqrt [|x|]|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z0 <= Z.sqrt [|x|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Z0 <= Z.sqrt [|x|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZZ.sqrt [|x|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZZ.sqrt [|x|] < wBapply Z.sqrt_le_lin; auto. Qed. Definition sqrt2 x y := let z := [|x|]*wB+[|y|] in match z with | Z0 => (0, C0 0) | Zpos p => let (s,r) := Z.sqrtrem (Zpos p) in (s, if Z_lt_le_dec r wB then C0 r else C1 (r-wB)) | Zneg _ => (0, C0 0) end.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZZ.sqrt [|x|] <= [|x|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, wB / 4 <= [|x|] -> let (s, r) := sqrt2 x y in [||WW x y||] = [|s|] ^ 2 + [+|r|] /\ [+|r|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x y : Z, wB / 4 <= [|x|] -> let (s, r) := sqrt2 x y in [||WW x y||] = [|s|] ^ 2 + [+|r|] /\ [+|r|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]let (s, r) := match [|x|] * wB + [|y|] with | Z.pos p => let (s, r) := Z.sqrtrem (Z.pos p) in (s, if Z_lt_le_dec r wB then C0 r else C1 (r - wB)) | _ => (0, C0 0) end in [||WW x y||] = [|s|] ^ 2 + [+|r|] /\ [+|r|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]let (s, r) := match [|x|] * wB + [|y|] with | Z.pos p => let (s, r) := Z.sqrtrem (Z.pos p) in (s, if Z_lt_le_dec r wB then C0 r else C1 (r - wB)) | _ => (0, C0 0) end in [|x|] * wB + [|y|] = [|s|] ^ 2 + [+|r|] /\ [+|r|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]z:ZHeqz:z = [|x|] * wB + [|y|]let (s, r) := match z with | Z.pos p => let (s, r) := Z.sqrtrem (Z.pos p) in (s, if Z_lt_le_dec r wB then C0 r else C1 (r - wB)) | _ => (0, C0 0) end in z = [|s|] ^ 2 + [+|r|] /\ [+|r|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]Heqz:0 = [|x|] * wB + [|y|]0 = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]let (s, r) := let (s, r) := Z.sqrtrem (Z.pos p) in (s, if Z_lt_le_dec r wB then C0 r else C1 (r - wB)) in Z.pos p = [|s|] ^ 2 + [+|r|] /\ [+|r|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]let (s, r) := let (s, r) := Z.sqrtrem (Z.pos p) in (s, if Z_lt_le_dec r wB then C0 r else C1 (r - wB)) in Z.pos p = [|s|] ^ 2 + [+|r|] /\ [+|r|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|](0 <= Z.pos p -> let (s, r) := Z.sqrtrem (Z.pos p) in Z.pos p = s * s + r /\ 0 <= r <= 2 * s) -> let (s, r) := let (s, r) := Z.sqrtrem (Z.pos p) in (s, if Z_lt_le_dec r wB then C0 r else C1 (r - wB)) in Z.pos p = [|s|] ^ 2 + [+|r|] /\ [+|r|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * ss < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= ss < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= swB * wB <= Z.pos pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos ps < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= swB * wB <= s * s + rdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos ps < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= swB * wB <= s * sdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos ps < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos ps < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos pZ.pos p < wB * wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos pH1:Z.pos p < wB * wBs < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos p[|x|] * wB + [|y|] < wB * wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos pH1:Z.pos p < wB * wBs < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos p[|x|] * wB + [|y|] < (wB - 1) * wB + wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos pH1:Z.pos p < wB * wBs < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos p[|x|] * wB <= (wB - 1) * wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos pH1:Z.pos p < wB * wBs < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos p[|x|] <= wB - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos p0 <= wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos pH1:Z.pos p < wB * wBs < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos p0 <= wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos pH1:Z.pos p < wB * wBs < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sl:wB <= sH0:wB * wB <= Z.pos pH1:Z.pos p < wB * wBs < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = [|s|] ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * [|s|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBZ.pos p = s ^ 2 + [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] /\ [+|(if Z_lt_le_dec r wB then C0 r else C1 (r - wB))|] <= 2 * sdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBl:r < wBZ.pos p = s ^ 2 + [|r|] /\ [|r|] <= 2 * sdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBl:wB <= rZ.pos p = s ^ 2 + (1 * wB + [|r - wB|]) /\ 1 * wB + [|r - wB|] <= 2 * sdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBl:r < wBZ.pos p = s ^ 2 + r /\ r <= 2 * sdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBl:wB <= rZ.pos p = s ^ 2 + (1 * wB + [|r - wB|]) /\ 1 * wB + [|r - wB|] <= 2 * sdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBl:wB <= rZ.pos p = s ^ 2 + (1 * wB + [|r - wB|]) /\ 1 * wB + [|r - wB|] <= 2 * sdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.pos p = [|x|] * wB + [|y|]s, r:ZU:Z.pos p = s * s + rV:0 <= r <= 2 * sH0:s < wBl:wB <= rZ.pos p = s ^ 2 + (1 * wB + (r - wB)) /\ 1 * wB + (r - wB) <= 2 * sdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]Z.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]0 <= Z.neg pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]H0:0 <= Z.neg pZ.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]compute in H0; elim H0; auto. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZH:wB / 4 <= [|x|]p:positiveHeqz:Z.neg p = [|x|] * wB + [|y|]H0:0 <= Z.neg pZ.neg p = [|0|] ^ 2 + [+|C0 0|] /\ [+|C0 0|] <= 2 * [|0|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, x >= 0 -> two_p x = 2 ^ xdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, x >= 0 -> two_p x = 2 ^ xdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:x >= 0two_p x = 2 ^ xdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:x >= 0match x with | 0 => 1 | Z.pos y => two_power_pos y | Z.neg _ => 0 end = 2 ^ xapply two_power_pos_correct. Qed. Definition head0 x := match [|x|] with | Z0 => zdigits | Zpos p => zdigits - log_inf p - 1 | _ => 0 end.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveH:Z.pos p >= 0two_power_pos p = Z.pow_pos 2 pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|x|] = 0 -> [|head0 x|] = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|x|] = 0 -> [|head0 x|] = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:[|x|] = 0[|match [|x|] with | 0 => zdigits | Z.pos p => zdigits - log_inf p - 1 | Z.neg _ => 0 end|] = Z.pos digitsapply spec_zdigits. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:[|x|] = 0[|zdigits|] = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall (x : positive) (p : Z), Z.pos x < 2 ^ p -> log_inf x < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall (x : positive) (p : Z), Z.pos x < 2 ^ p -> log_inf x < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~1 < 2 ^ pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~1 < 2 ^ pH0:0 < pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~1 < 2 ^ pH0:0 < plog_inf x < p - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~1 < 2 ^ pH0:0 < pZ.pos x < 2 ^ (p - 1)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:2 * Z.pos x + 1 < 2 ^ pH0:0 < pZ.pos x < 2 ^ (p - 1)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:2 * Z.pos x + 1 < 2 ^ Z.succ (p - 1)H0:0 < pZ.pos x < 2 ^ (p - 1)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pH0:0 < pZ.succ (log_inf x) < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pH0:0 < plog_inf x < p - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:Z.pos x~0 < 2 ^ pH0:0 < pZ.pos x < 2 ^ (p - 1)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:2 * Z.pos x < 2 ^ pH0:0 < pZ.pos x < 2 ^ (p - 1)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:positiveIHx:forall p0 : Z, Z.pos x < 2 ^ p0 -> log_inf x < p0p:ZH:2 * Z.pos x < 2 ^ Z.succ (p - 1)H0:0 < pZ.pos x < 2 ^ (p - 1)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < psimpl; intros; destruct p; compute; auto with zarith. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:ZH:1 < 2 ^ p0 < pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, 0 < [|x|] -> wB / 2 <= 2 ^ [|head0 x|] * [|x|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, 0 < [|x|] -> wB / 2 <= 2 ^ [|head0 x|] * [|x|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:0 < [|x|]wB / 2 <= 2 ^ [|match [|x|] with | 0 => zdigits | Z.pos p => zdigits - log_inf p - 1 | Z.neg _ => 0 end|] * [|x|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:0 < [|x|]0 <= [|x|] < wB -> wB / 2 <= 2 ^ [|match [|x|] with | 0 => zdigits | Z.pos p => zdigits - log_inf p - 1 | Z.neg _ => 0 end|] * [|x|] < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos p0 <= Z.pos p < wB -> wB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:two_p (log_inf p) <= Z.pos p < two_p (Z.succ (log_inf p))wB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)wB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)0 <= zdigits - log_inf p - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)0 <= zdigits - log_inf p - 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)zdigits - log_inf p - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)log_inf p < zdigitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)zdigits - log_inf p - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)log_inf p < Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)zdigits - log_inf p - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < 2 ^ Z.pos digitsH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)log_inf p < Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)zdigits - log_inf p - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)zdigits - log_inf p - 1 < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)zdigits - log_inf p - 1 < zdigitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)zdigits < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)zdigits < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ [|zdigits - log_inf p - 1|] * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ (zdigits - log_inf p - 1) * Z.pos pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB / 2 <= 2 ^ (zdigits - log_inf p - 1) * 2 ^ log_inf pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * 2 ^ log_inf p <= 2 ^ (zdigits - log_inf p - 1) * Z.pos pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB <= 2 ^ (zdigits - log_inf p - 1) * 2 ^ log_inf p * 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * 2 ^ log_inf p <= 2 ^ (zdigits - log_inf p - 1) * Z.pos pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB <= 2 ^ (zdigits - log_inf p - 1 + log_inf p) * 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * 2 ^ log_inf p <= 2 ^ (zdigits - log_inf p - 1) * Z.pos pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB <= 2 ^ Z.succ (zdigits - log_inf p - 1 + log_inf p)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * 2 ^ log_inf p <= 2 ^ (zdigits - log_inf p - 1) * Z.pos pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wBwB <= 2 ^ zdigitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * 2 ^ log_inf p <= 2 ^ (zdigits - log_inf p - 1) * Z.pos pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * 2 ^ log_inf p <= 2 ^ (zdigits - log_inf p - 1) * Z.pos pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * Z.pos p < 2 ^ (zdigits - log_inf p - 1) * 2 ^ Z.succ (log_inf p)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * 2 ^ Z.succ (log_inf p) <= wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1) * 2 ^ Z.succ (log_inf p) <= wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ (zdigits - log_inf p - 1 + Z.succ (log_inf p)) <= wBunfold wB, base, zdigits; auto with zarith. Qed. Fixpoint Ptail p := match p with | xO p => (Ptail p)+1 | _ => 0 end.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:0 <= log_inf pH2:2 ^ log_inf p <= Z.pos pH4:Z.pos p < 2 ^ Z.succ (log_inf p)H3:0 <= zdigits - log_inf p - 1 < wB2 ^ zdigits <= wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall p : positive, 0 <= Ptail pinduction p; simpl; auto with zarith. Qed. Hint Resolve Ptail_pos : core.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall p : positive, 0 <= Ptail pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall p d : positive, Z.pos p < 2 ^ Z.pos d -> Ptail p < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall p d : positive, Z.pos p < 2 ^ Z.pos d -> Ptail p < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d : positive, Z.pos p < 2 ^ Z.pos d -> Ptail p < Z.pos dforall d : positive, Z.pos p~0 < 2 ^ Z.pos d -> Ptail p~0 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dPtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dd <> 1%positivedigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positivePtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d : positive, Z.pos p < 2 ^ Z.pos d -> Ptail p < Z.pos dH:Z.pos p~0 < 2 ^ 1Falsedigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positivePtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positivePtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveZ.succ (Z.pos (Pos.pred d)) = Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dPtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positive(Pos.pred d + 1)%positive = ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dPtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positivePos.succ (Pos.pred d) = ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dPtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:d = 1%positivePos.succ (Pos.pred d) = ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dPtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dPtail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dPtail p < Z.pos (Pos.pred d)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dH2:Ptail p < Z.pos (Pos.pred d)Ptail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dZ.pos p < 2 ^ Z.pos (Pos.pred d)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dH2:Ptail p < Z.pos (Pos.pred d)Ptail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dZ.pos p * 2 < 2 ^ Z.pos (Pos.pred d) * 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dH2:Ptail p < Z.pos (Pos.pred d)Ptail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos d2 * Z.pos p < 2 ^ Z.pos (Pos.pred d) * 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dH2:Ptail p < Z.pos (Pos.pred d)Ptail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dZ.pos p~0 < 2 ^ Z.pos (Pos.pred d) * 2digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dH2:Ptail p < Z.pos (Pos.pred d)Ptail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dZ.pos p~0 < 2 * 2 ^ Z.pos (Pos.pred d)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dH2:Ptail p < Z.pos (Pos.pred d)Ptail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dZ.pos p~0 < 2 ^ Z.succ (Z.pos (Pos.pred d))digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dH2:Ptail p < Z.pos (Pos.pred d)Ptail p + 1 < Z.pos drewrite <- H1; omega. Qed. Definition tail0 x := match [|x|] with | Z0 => zdigits | Zpos p => Ptail p | Zneg _ => 0 end.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsp:positiveIHp:forall d0 : positive, Z.pos p < 2 ^ Z.pos d0 -> Ptail p < Z.pos d0d:positiveH:Z.pos p~0 < 2 ^ Z.pos dH0:d <> 1%positiveH1:Z.succ (Z.pos (Pos.pred d)) = Z.pos dH2:Ptail p < Z.pos (Pos.pred d)Ptail p + 1 < Z.pos ddigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|x|] = 0 -> [|tail0 x|] = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, [|x|] = 0 -> [|tail0 x|] = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:[|x|] = 0[|match [|x|] with | 0 => zdigits | Z.pos p => Ptail p | Z.neg _ => 0 end|] = Z.pos digitsapply spec_zdigits. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:[|x|] = 0[|zdigits|] = Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, 0 < [|x|] -> exists y : Z, 0 <= y /\ [|x|] = (2 * y + 1) * 2 ^ [|tail0 x|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsforall x : Z, 0 < [|x|] -> exists y : Z, 0 <= y /\ [|x|] = (2 * y + 1) * 2 ^ [|tail0 x|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:0 < [|x|]exists y : Z, 0 <= y /\ [|x|] = (2 * y + 1) * 2 ^ [|match [|x|] with | 0 => zdigits | Z.pos p => Ptail p | Z.neg _ => 0 end|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:ZH:0 < [|x|]0 <= [|x|] < wB -> exists y : Z, 0 <= y /\ [|x|] = (2 * y + 1) * 2 ^ [|match [|x|] with | 0 => zdigits | Z.pos p => Ptail p | Z.neg _ => 0 end|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ [|Ptail p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wB[|Ptail p|] = Ptail pdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:[|Ptail p|] = Ptail pexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ [|Ptail p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wB0 <= Ptail p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:[|Ptail p|] = Ptail pexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ [|Ptail p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBPtail p < wBdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:[|Ptail p|] = Ptail pexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ [|Ptail p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < 2 ^ Z.pos digitsPtail p < 2 ^ Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:[|Ptail p|] = Ptail pexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ [|Ptail p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < 2 ^ Z.pos digitsPtail p < Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < 2 ^ Z.pos digitsZ.pos digits < 2 ^ Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:[|Ptail p|] = Ptail pexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ [|Ptail p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < 2 ^ Z.pos digitsZ.pos digits < 2 ^ Z.pos digitsdigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:[|Ptail p|] = Ptail pexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ [|Ptail p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:[|Ptail p|] = Ptail pexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ [|Ptail p|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx:Zp:positiveH:0 < Z.pos pH0:0 <= Z.pos p < wBH1:[|Ptail p|] = Ptail pexists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ Ptail pp:positiveIHp:exists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ Ptail pexists y : Z, 0 <= y /\ Z.pos p~1 = (2 * y + 1) * 2 ^ Ptail p~1p:positiveIHp:exists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ Ptail pexists y : Z, 0 <= y /\ Z.pos p~0 = (2 * y + 1) * 2 ^ Ptail p~0exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1p:positiveIHp:exists y : Z, 0 <= y /\ Z.pos p = (2 * y + 1) * 2 ^ Ptail pexists y : Z, 0 <= y /\ Z.pos p~0 = (2 * y + 1) * 2 ^ Ptail p~0exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1p:positivey:ZYp:0 <= yYe:Z.pos p = (2 * y + 1) * 2 ^ Ptail pexists y0 : Z, 0 <= y0 /\ Z.pos p~0 = (2 * y0 + 1) * 2 ^ Ptail p~0exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1p:positivey:ZYp:0 <= yYe:Z.pos p = (2 * y + 1) * 2 ^ Ptail p0 <= y /\ Z.pos p~0 = (2 * y + 1) * 2 ^ Ptail p~0exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1p:positivey:ZYp:0 <= yYe:Z.pos p = (2 * y + 1) * 2 ^ Ptail pZ.pos p~0 = (2 * y + 1) * 2 ^ Ptail p~0exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1p:positivey:ZYp:0 <= yYe:Z.pos p = (2 * y + 1) * 2 ^ Ptail p2 * Z.pos p = (2 * y + 1) * 2 ^ Ptail p~0exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1p:positivey:ZYp:0 <= yYe:Z.pos p = (2 * y + 1) * 2 ^ Ptail p2 * ((2 * y + 1) * 2 ^ Ptail p) = (2 * y + 1) * 2 ^ Ptail p~0exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1p:positivey:ZYp:0 <= yYe:Z.pos p = (2 * y + 1) * 2 ^ Ptail p2 * ((2 * y + 1) * 2 ^ Ptail p) = (2 * y + 1) * 2 ^ Z.succ (Ptail p)exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1exists 0; simpl; auto with zarith. Qed. Definition lor := Z.lor. Definition land := Z.land. Definition lxor := Z.lxor.exists y : Z, 0 <= y /\ 1 = (2 * y + 1) * 2 ^ Ptail 1digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z[|lor x y|] = Z.lor [|x|] [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z[|lor x y|] = Z.lor [|x|] [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZZ.lor x y mod wB = Z.lor (x mod wB) (y mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.lor x y mod wB) n = Z.testbit (Z.lor (x mod wB) (y mod wB)) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.lor x y mod wB) n = Z.testbit (x mod wB) n || Z.testbit (y mod wB) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.lor x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n || Z.testbit (y mod 2 ^ Z.pos digits) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:Z.pos digits <= nZ.testbit (Z.lor x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n || Z.testbit (y mod 2 ^ Z.pos digits) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:n < Z.pos digitsZ.testbit (Z.lor x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n || Z.testbit (y mod 2 ^ Z.pos digits) nrewrite !Z.mod_pow2_bits_high; auto with zarith.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:Z.pos digits <= nZ.testbit (Z.lor x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n || Z.testbit (y mod 2 ^ Z.pos digits) nrewrite !Z.mod_pow2_bits_low, Z.lor_spec; auto with zarith. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:n < Z.pos digitsZ.testbit (Z.lor x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n || Z.testbit (y mod 2 ^ Z.pos digits) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z[|land x y|] = Z.land [|x|] [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z[|land x y|] = Z.land [|x|] [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZZ.land x y mod wB = Z.land (x mod wB) (y mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.land x y mod wB) n = Z.testbit (Z.land (x mod wB) (y mod wB)) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.land x y mod wB) n = Z.testbit (x mod wB) n && Z.testbit (y mod wB) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.land x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n && Z.testbit (y mod 2 ^ Z.pos digits) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:Z.pos digits <= nZ.testbit (Z.land x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n && Z.testbit (y mod 2 ^ Z.pos digits) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:n < Z.pos digitsZ.testbit (Z.land x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n && Z.testbit (y mod 2 ^ Z.pos digits) nrewrite !Z.mod_pow2_bits_high; auto with zarith.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:Z.pos digits <= nZ.testbit (Z.land x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n && Z.testbit (y mod 2 ^ Z.pos digits) nrewrite !Z.mod_pow2_bits_low, Z.land_spec; auto with zarith. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:n < Z.pos digitsZ.testbit (Z.land x y mod 2 ^ Z.pos digits) n = Z.testbit (x mod 2 ^ Z.pos digits) n && Z.testbit (y mod 2 ^ Z.pos digits) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z[|lxor x y|] = Z.lxor [|x|] [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:Z[|lxor x y|] = Z.lxor [|x|] [|y|]digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y:ZZ.lxor x y mod wB = Z.lxor (x mod wB) (y mod wB)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.lxor x y mod wB) n = Z.testbit (Z.lxor (x mod wB) (y mod wB)) ndigits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.lxor x y mod wB) n = xorb (Z.testbit (x mod wB) n) (Z.testbit (y mod wB) n)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nZ.testbit (Z.lxor x y mod 2 ^ Z.pos digits) n = xorb (Z.testbit (x mod 2 ^ Z.pos digits) n) (Z.testbit (y mod 2 ^ Z.pos digits) n)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:Z.pos digits <= nZ.testbit (Z.lxor x y mod 2 ^ Z.pos digits) n = xorb (Z.testbit (x mod 2 ^ Z.pos digits) n) (Z.testbit (y mod 2 ^ Z.pos digits) n)digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:n < Z.pos digitsZ.testbit (Z.lxor x y mod 2 ^ Z.pos digits) n = xorb (Z.testbit (x mod 2 ^ Z.pos digits) n) (Z.testbit (y mod 2 ^ Z.pos digits) n)rewrite !Z.mod_pow2_bits_high; auto with zarith.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:Z.pos digits <= nZ.testbit (Z.lxor x y mod 2 ^ Z.pos digits) n = xorb (Z.testbit (x mod 2 ^ Z.pos digits) n) (Z.testbit (y mod 2 ^ Z.pos digits) n)rewrite !Z.mod_pow2_bits_low, Z.lxor_spec; auto with zarith. Qed.digits:positivedigits_ne_1:digits <> 1%positivedigits_gt_1:=spec_more_than_1_digit:1 < Z.pos digitsx, y, n:ZHn:0 <= nH:n < Z.pos digitsZ.testbit (Z.lxor x y mod 2 ^ Z.pos digits) n = xorb (Z.testbit (x mod 2 ^ Z.pos digits) n) (Z.testbit (y mod 2 ^ Z.pos digits) n)
Let's now group everything in two records
Instance zmod_ops : ZnZ.Ops Z := ZnZ.MkOps (digits : positive) (zdigits: t) (to_Z : t -> Z) (of_pos : positive -> N * t) (head0 : t -> t) (tail0 : t -> t) (zero : t) (one : t) (minus_one : t) (compare : t -> t -> comparison) (eq0 : t -> bool) (opp_c : t -> carry t) (opp : t -> t) (opp_carry : t -> t) (succ_c : t -> carry t) (add_c : t -> t -> carry t) (add_carry_c : t -> t -> carry t) (succ : t -> t) (add : t -> t -> t) (add_carry : t -> t -> t) (pred_c : t -> carry t) (sub_c : t -> t -> carry t) (sub_carry_c : t -> t -> carry t) (pred : t -> t) (sub : t -> t -> t) (sub_carry : t -> t -> t) (mul_c : t -> t -> zn2z t) (mul : t -> t -> t) (square_c : t -> zn2z t) (div21 : t -> t -> t -> t*t) (div_gt : t -> t -> t * t) (div : t -> t -> t * t) (modulo_gt : t -> t -> t) (modulo : t -> t -> t) (gcd_gt : t -> t -> t) (gcd : t -> t -> t) (add_mul_div : t -> t -> t -> t) (pos_mod : t -> t -> t) (is_even : t -> bool) (sqrt2 : t -> t -> t * carry t) (sqrt : t -> t) (lor : t -> t -> t) (land : t -> t -> t) (lxor : t -> t -> t). Instance zmod_specs : ZnZ.Specs zmod_ops := ZnZ.MkSpecs spec_to_Z spec_of_pos spec_zdigits spec_more_than_1_digit spec_0 spec_1 spec_Bm1 spec_compare spec_eq0 spec_opp_c spec_opp spec_opp_carry spec_succ_c spec_add_c spec_add_carry_c spec_succ spec_add spec_add_carry spec_pred_c spec_sub_c spec_sub_carry_c spec_pred spec_sub spec_sub_carry spec_mul_c spec_mul spec_square_c spec_div21 spec_div_gt spec_div spec_modulo_gt spec_modulo spec_gcd_gt spec_gcd spec_head00 spec_head0 spec_tail00 spec_tail0 spec_add_mul_div spec_pos_mod spec_is_even spec_sqrt2 spec_sqrt spec_lor spec_land spec_lxor. End ZModulo.
A modular version of the previous construction.
Module Type PositiveNotOne. Parameter p : positive. Axiom not_one : p <> 1%positive. End PositiveNotOne. Module ZModuloCyclicType (P:PositiveNotOne) <: CyclicType. Definition t := Z. Instance ops : ZnZ.Ops t := zmod_ops P.p. Instance specs : ZnZ.Specs ops := zmod_specs P.not_one. End ZModuloCyclicType.