Timings for NZCyclic.v
- /home/gitlab-runner/builds/gGKko-aj/0/coq/coq/_bench/opam.OLD/ocaml-OLD/.opam-switch/build/coq-stdlib.dev/_build/default/theories//./Numbers/Cyclic/Abstract/NZCyclic.timing
- /home/gitlab-runner/builds/gGKko-aj/0/coq/coq/_bench/opam.NEW/ocaml-NEW/.opam-switch/build/coq-stdlib.dev/_build/default/theories//./Numbers/Cyclic/Abstract/NZCyclic.timing
(************************************************************************)
(* * The Coq Proof Assistant / The Coq Development Team *)
(* v * Copyright INRIA, CNRS and contributors *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(* \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) *)
(************************************************************************)
(* Evgeny Makarov, INRIA, 2007 *)
(************************************************************************)
Require Import Zpow_facts.
Require Import DoubleType.
Require Import CyclicAxioms.
(** * From [CyclicType] to [NZAxiomsSig] *)
(** A [Z/nZ] representation given by a module type [CyclicType]
implements [NZAxiomsSig], e.g. the common properties between
N and Z with no ordering. Notice that the [n] in [Z/nZ] is
a power of 2.
*)
Module NZCyclicAxiomsMod (Import Cyclic : CyclicType) <: NZAxiomsSig.
Local Open Scope Z_scope.
Local Notation wB := (base ZnZ.digits).
Local Notation "[| x |]" := (ZnZ.to_Z x) (at level 0, x at level 99).
Definition eq (n m : t) := [| n |] = [| m |].
Definition zero := ZnZ.zero.
Definition one := ZnZ.one.
Definition two := ZnZ.succ ZnZ.one.
Definition succ := ZnZ.succ.
Definition pred := ZnZ.pred.
Definition add := ZnZ.add.
Definition sub := ZnZ.sub.
Definition mul := ZnZ.mul.
Local Infix "==" := eq (at level 70).
Local Notation "0" := zero.
Local Notation S := succ.
Local Notation P := pred.
Global Hint Rewrite ZnZ.spec_0 ZnZ.spec_1 ZnZ.spec_succ ZnZ.spec_pred
ZnZ.spec_add ZnZ.spec_mul ZnZ.spec_sub : cyclic.
Ltac zify :=
unfold eq, zero, one, two, succ, pred, add, sub, mul in *;
autorewrite with cyclic.
Ltac zcongruence := repeat red; intros; zify; congruence.
#[global]
Instance eq_equiv : Equivalence eq.
1-2: firstorder auto with crelations.
intros x y z; apply eq_trans.
Local Obligation Tactic := zcongruence.
#[global]
Program Instance succ_wd : Proper (eq ==> eq) succ.
#[global]
Program Instance pred_wd : Proper (eq ==> eq) pred.
#[global]
Program Instance add_wd : Proper (eq ==> eq ==> eq) add.
#[global]
Program Instance sub_wd : Proper (eq ==> eq ==> eq) sub.
#[global]
Program Instance mul_wd : Proper (eq ==> eq ==> eq) mul.
Theorem gt_wB_1 : 1 < wB.
apply Zpower_gt_1; unfold Z.lt; auto with zarith.
Theorem gt_wB_0 : 0 < wB.
Lemma one_mod_wB : 1 mod wB = 1.
Lemma succ_mod_wB : forall n : Z, (n + 1) mod wB = ((n mod wB) + 1) mod wB.
rewrite <- one_mod_wB at 2.
now rewrite <- Zplus_mod.
Lemma pred_mod_wB : forall n : Z, (n - 1) mod wB = ((n mod wB) - 1) mod wB.
rewrite <- one_mod_wB at 2.
Lemma NZ_to_Z_mod : forall n, [| n |] mod wB = [| n |].
intro n; rewrite Zmod_small.
Theorem pred_succ : forall n, P (S n) == n.
replace ([| n |] + 1 - 1)%Z with [| n |] by ring.
Theorem one_succ : one == succ zero.
Theorem two_succ : two == succ one.
Hypothesis A_wd : Proper (eq ==> iff) A.
Hypothesis AS : forall n, A n <-> A (S n).
(* Below, we use only -> direction *)
Let B (n : Z) := A (ZnZ.of_Z n).
Lemma BS : forall n : Z, 0 <= n -> n < wB - 1 -> B n -> B (n + 1).
setoid_replace (ZnZ.of_Z (n + 1)) with (S (ZnZ.of_Z n)).
rewrite 2 ZnZ.of_Z_correct.
symmetry; apply Zmod_small; lia.
Theorem Zbounded_induction :
(forall Q : Z -> Prop, forall b : Z,
Q 0 ->
(forall n, 0 <= n -> n < b - 1 -> Q n -> Q (n + 1)) ->
forall n, 0 <= n -> n < b -> Q n)%Z.
set (Q' := fun n => (n < b /\ Q n) \/ (b <= n)).
assert (H : forall n, 0 <= n -> Q' n).
apply natlike_rec2; unfold Q'.
destruct (Z.le_gt_cases b 0) as [H | H].
destruct IH as [[IH1 IH2] | IH].
destruct (Z.le_gt_cases (b - 1) n) as [H1 | H1].
split; [ lia | now apply (QS n)].
unfold Q' in *; intros n H1 H2.
destruct (H n H1) as [[H3 H4] | H3].
now apply Z.le_ngt in H3.
Lemma B_holds : forall n : Z, 0 <= n < wB -> B n.
apply Zbounded_induction with wB.
Theorem bi_induction : forall n, A n.
setoid_replace n with (ZnZ.of_Z (ZnZ.to_Z n)).
Theorem add_0_l : forall n, 0 + n == n.
Theorem add_succ_l : forall n m, (S n) + m == S (n + m).
repeat rewrite Zplus_mod_idemp_l; try apply gt_wB_0.
rewrite <- (Z.add_assoc ([| n |] mod wB) 1 [| m |]).
rewrite Zplus_mod_idemp_l.
rewrite (Z.add_comm 1 [| m |]); now rewrite Z.add_assoc.
Theorem sub_0_r : forall n, n - 0 == n.
Theorem sub_succ_r : forall n m, n - (S m) == P (n - m).
rewrite Zminus_mod_idemp_r, Zminus_mod_idemp_l.
now replace ([|n|] - ([|m|] + 1))%Z with ([|n|] - [|m|] - 1)%Z
by ring.
Theorem mul_0_l : forall n, 0 * n == 0.
Theorem mul_succ_l : forall n m, (S n) * m == n * m + m.
rewrite Zplus_mod_idemp_l, Zmult_mod_idemp_l.
now rewrite Z.mul_add_distr_r, Z.mul_1_l.