diff options
| author | emakarov | 2007-10-02 19:54:25 +0000 |
|---|---|---|
| committer | emakarov | 2007-10-02 19:54:25 +0000 |
| commit | 865b038b8552b57686ba01a2630455b53673f084 (patch) | |
| tree | af86e7dc5bcf6eabbb1c067ff9dff1f797a07db3 /theories/Numbers/Integer | |
| parent | e17dd18ea716f157112fec03ccd03b038464ed06 (diff) | |
The following now compiles: abstract integers with plus, minus and times, binary implementation and integers as pairs of natural numbers
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@10167 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'theories/Numbers/Integer')
| -rw-r--r-- | theories/Numbers/Integer/Binary/ZBinary.v | 206 | ||||
| -rw-r--r-- | theories/Numbers/Integer/NatPairs/ZNatPairs.v | 303 | ||||
| -rw-r--r-- | theories/Numbers/Integer/NatPairs/ZPairsAxioms.v | 142 |
3 files changed, 394 insertions, 257 deletions
diff --git a/theories/Numbers/Integer/Binary/ZBinary.v b/theories/Numbers/Integer/Binary/ZBinary.v index 0fd1be7a9f..cb8ac3b5b1 100644 --- a/theories/Numbers/Integer/Binary/ZBinary.v +++ b/theories/Numbers/Integer/Binary/ZBinary.v @@ -2,198 +2,174 @@ Require Import ZTimesOrder. Require Import ZArith. Open Local Scope Z_scope. -Module Export ZBinDomain <: ZDomainSignature. -Delimit Scope IntScope with Int. -(* Is this really necessary? Without it, applying ZDomainProperties -functor to this module produces an error since the functor opens the -scope. *) -Definition Z := Z. -Definition E := (@eq Z). -Definition e := Zeq_bool. +Module ZBinAxiomsMod <: ZAxiomsSig. +Module Export NZOrdAxiomsMod <: NZOrdAxiomsSig. +Module Export NZAxiomsMod <: NZAxiomsSig. -Theorem E_equiv_e : forall x y : Z, E x y <-> e x y. -Proof. -intros x y; unfold E, e, Zeq_bool; split; intro H. -rewrite H; now rewrite Zcompare_refl. -rewrite eq_true_unfold_pos in H. -assert (H1 : (x ?= y) = Eq). -case_eq (x ?= y); intro H1; rewrite H1 in H; simpl in H; -[reflexivity | discriminate H | discriminate H]. -now apply Zcompare_Eq_eq. -Qed. +Definition NZ := Z. +Definition NZE := (@eq Z). +Definition NZ0 := 0. +Definition NZsucc := Zsucc'. +Definition NZpred := Zpred'. +Definition NZplus := Zplus. +Definition NZminus := Zminus. +Definition NZtimes := Zmult. -Theorem E_equiv : equiv Z E. +Theorem NZE_equiv : equiv Z NZE. Proof. -apply eq_equiv with (A := Z). (* It does not work without "with (A := Z)" though it looks like it should *) +exact (@eq_equiv Z). Qed. -Add Relation Z E - reflexivity proved by (proj1 E_equiv) - symmetry proved by (proj2 (proj2 E_equiv)) - transitivity proved by (proj1 (proj2 E_equiv)) -as E_rel. - -End ZBinDomain. +Add Relation Z NZE + reflexivity proved by (proj1 NZE_equiv) + symmetry proved by (proj2 (proj2 NZE_equiv)) + transitivity proved by (proj1 (proj2 NZE_equiv)) +as NZE_rel. -Module Export ZBinInt <: IntSignature. -Module Export ZDomainModule := ZBinDomain. - -Definition O := 0. -Definition S := Zsucc'. -Definition P := Zpred'. - -Add Morphism S with signature E ==> E as S_wd. +Add Morphism NZsucc with signature NZE ==> NZE as NZsucc_wd. Proof. -intros; unfold E; congruence. -Qed. - -Add Morphism P with signature E ==> E as P_wd. -Proof. -intros; unfold E; congruence. +congruence. Qed. -Theorem S_inj : forall x y : Z, S x = S y -> x = y. +Add Morphism NZpred with signature NZE ==> NZE as NZpred_wd. Proof. -exact Zsucc'_inj. +congruence. Qed. -Theorem S_P : forall x : Z, S (P x) = x. +Add Morphism NZplus with signature NZE ==> NZE ==> NZE as NZplus_wd. Proof. -exact Zsucc'_pred'. +congruence. Qed. -Theorem induction : - forall Q : Z -> Prop, - pred_wd E Q -> Q 0 -> - (forall x, Q x -> Q (S x)) -> - (forall x, Q x -> Q (P x)) -> forall x, Q x. +Add Morphism NZminus with signature NZE ==> NZE ==> NZE as NZminus_wd. Proof. -intros; now apply Zind. +congruence. Qed. -End ZBinInt. - -Module Export ZBinPlus <: ZPlusSignature. -Module Export IntModule := ZBinInt. - -Definition plus := Zplus. -Definition minus := Zminus. -Definition uminus := Zopp. - -Add Morphism plus with signature E ==> E ==> E as plus_wd. +Add Morphism NZtimes with signature NZE ==> NZE ==> NZE as NZtimes_wd. Proof. -intros; congruence. +congruence. Qed. -Add Morphism minus with signature E ==> E ==> E as minus_wd. +Theorem NZpred_succ : forall n : Z, NZpred (NZsucc n) = n. Proof. -intros; congruence. +exact Zpred'_succ'. Qed. -Add Morphism uminus with signature E ==> E as uminus_wd. +Theorem NZinduction : + forall A : Z -> Prop, predicate_wd NZE A -> + A 0 -> (forall n : Z, A n <-> A (NZsucc n)) -> forall n : Z, A n. Proof. -intros; congruence. +intros A A_wd A0 AS n; apply Zind; clear n. +assumption. +intros; now apply -> AS. +intros n H. rewrite <- (Zsucc'_pred' n) in H. now apply <- AS. Qed. -Theorem plus_0 : forall n, 0 + n = n. +Theorem NZplus_0_l : forall n : Z, 0 + n = n. Proof. exact Zplus_0_l. Qed. -Theorem plus_S : forall n m, (S n) + m = S (n + m). +Theorem NZplus_succ_l : forall n m : Z, (NZsucc n) + m = NZsucc (n + m). Proof. intros; do 2 rewrite <- Zsucc_succ'; apply Zplus_succ_l. Qed. -Theorem minus_0 : forall n, n - 0 = n. +Theorem NZminus_0_r : forall n : Z, n - 0 = n. Proof. exact Zminus_0_r. Qed. -Theorem minus_S : forall n m, n - (S m) = P (n - m). +Theorem NZminus_succ_r : forall n m : Z, n - (NZsucc m) = NZpred (n - m). Proof. intros; rewrite <- Zsucc_succ'; rewrite <- Zpred_pred'; apply Zminus_succ_r. Qed. -Theorem uminus_0 : - 0 = 0. +Theorem NZtimes_0_r : forall n : Z, n * 0 = 0. Proof. -reflexivity. +exact Zmult_0_r. Qed. -Theorem uminus_S : forall n, - (S n) = P (- n). -Admitted. +Theorem NZtimes_succ_r : forall n m : Z, n * (NZsucc m) = n * m + n. +Proof. +intros; rewrite <- Zsucc_succ'; apply Zmult_succ_r. +Qed. -End ZBinPlus. +End NZAxiomsMod. -Module Export ZBinTimes <: ZTimesSignature. -Module Export ZPlusModule := ZBinPlus. +Definition NZlt := Zlt. +Definition NZle := Zle. -Definition times := Zmult. +Add Morphism NZlt with signature NZE ==> NZE ==> iff as NZlt_wd. +Proof. +unfold NZE. intros n1 n2 H1 m1 m2 H2; rewrite H1; now rewrite H2. +Qed. -Add Morphism times with signature E ==> E ==> E as times_wd. +Add Morphism NZle with signature NZE ==> NZE ==> iff as NZle_wd. Proof. -congruence. +unfold NZE. intros n1 n2 H1 m1 m2 H2; rewrite H1; now rewrite H2. Qed. -Theorem times_0 : forall n, n * 0 = 0. +Theorem NZle_lt_or_eq : forall n m : Z, n <= m <-> n < m \/ n = m. Proof. -exact Zmult_0_r. +intros n m; split. apply Zle_lt_or_eq. +intro H; destruct H as [H | H]. now apply Zlt_le_weak. rewrite H; apply Zle_refl. Qed. -Theorem times_S : forall n m, n * (S m) = n * m + n. +Theorem NZlt_irrefl : forall n : Z, ~ n < n. Proof. -intros; rewrite <- Zsucc_succ'; apply Zmult_succ_r. +exact Zlt_irrefl. Qed. -End ZBinTimes. +Theorem NZlt_succ_le : forall n m : Z, n < (NZsucc m) <-> n <= m. +Proof. +intros; unfold NZsucc; rewrite <- Zsucc_succ'; split; +[apply Zlt_succ_le | apply Zle_lt_succ]. +Qed. -Module Export ZBinOrder <: ZOrderSignature. -Module Export IntModule := ZBinInt. +End NZOrdAxiomsMod. -Definition lt := Zlt_bool. -Definition le := Zle_bool. +Definition Zopp := Zopp. -Add Morphism lt with signature E ==> E ==> eq_bool as lt_wd. +Add Morphism Zopp with signature NZE ==> NZE as Zopp_wd. Proof. congruence. Qed. -Add Morphism le with signature E ==> E ==> eq_bool as le_wd. +Theorem Zsucc_pred : forall n : Z, NZsucc (NZpred n) = n. Proof. -congruence. +exact Zsucc'_pred'. Qed. -Theorem le_lt : forall n m, le n m <-> lt n m \/ n = m. +Theorem Zopp_0 : - 0 = 0. Proof. -intros; unfold lt, le, Zlt_bool, Zle_bool. -case_eq (n ?= m); intro H. -apply Zcompare_Eq_eq in H; rewrite H; now split; intro; [right |]. -now split; intro; [left |]. -split; intro H1. now idtac. -destruct H1 as [H1 | H1]. -assumption. unfold E in H1; rewrite H1 in H. now rewrite Zcompare_refl in H. +reflexivity. Qed. -Theorem lt_irr : forall n, ~ (lt n n). +Theorem Zopp_succ : forall n : Z, - (NZsucc n) = NZpred (- n). Proof. -intro n; rewrite eq_true_unfold_pos; intro H. -assert (H1 : (Zlt n n)). -change (if true then (Zlt n n) else (Zge n n)). rewrite <- H. -unfold lt. apply Zlt_cases. -false_hyp H1 Zlt_irrefl. +intro; rewrite <- Zsucc_succ'; rewrite <- Zpred_pred'. apply Zopp_succ. Qed. -Theorem lt_S : forall n m, lt n (S m) <-> le n m. -Proof. -intros; unfold lt, le, S; do 2 rewrite eq_true_unfold_pos. -rewrite <- Zsucc_succ'; rewrite <- Zlt_is_lt_bool; rewrite <- Zle_is_le_bool. -split; intro; [now apply Zlt_succ_le | now apply Zle_lt_succ]. -Qed. +End ZBinAxiomsMod. + +Module Export ZBinTimesOrderPropMod := ZTimesOrderPropFunct ZBinAxiomsMod. -End ZBinOrder. -Module Export ZTimesOrderPropertiesModule := - ZTimesOrderProperties ZBinTimes ZBinOrder. + +(* +Theorem E_equiv_e : forall x y : Z, E x y <-> e x y. +Proof. +intros x y; unfold E, e, Zeq_bool; split; intro H. +rewrite H; now rewrite Zcompare_refl. +rewrite eq_true_unfold_pos in H. +assert (H1 : (x ?= y) = Eq). +case_eq (x ?= y); intro H1; rewrite H1 in H; simpl in H; +[reflexivity | discriminate H | discriminate H]. +now apply Zcompare_Eq_eq. +Qed. +*)
\ No newline at end of file diff --git a/theories/Numbers/Integer/NatPairs/ZNatPairs.v b/theories/Numbers/Integer/NatPairs/ZNatPairs.v new file mode 100644 index 0000000000..41fc7e75ee --- /dev/null +++ b/theories/Numbers/Integer/NatPairs/ZNatPairs.v @@ -0,0 +1,303 @@ +Require Import NMinus. (* The most complete file for natural numbers *) +Require Import ZTimesOrder. (* The most complete file for integers *) + +Module ZPairsAxiomsMod (Import NAxiomsMod : NAxiomsSig) <: ZAxiomsSig. +Module Import NPropMod := NMinusPropFunct NAxiomsMod. (* Get all properties of natural numbers *) +Notation Local N := NZ. (* To remember N without having to use a long qualifying name *) +Notation Local NE := NZE (only parsing). +Notation Local plus_wd := NZplus_wd (only parsing). +Open Local Scope NatIntScope. + +Module Export NZOrdAxiomsMod <: NZOrdAxiomsSig. +Module Export NZAxiomsMod <: NZAxiomsSig. + +Definition NZ : Set := (NZ * NZ)%type. +Definition NZE (p1 p2 : NZ) := ((fst p1) + (snd p2) == (fst p2) + (snd p1)). +Notation Z := NZ (only parsing). +Notation E := NZE (only parsing). +Definition NZ0 := (0, 0). +Definition NZsucc (n : Z) := (S (fst n), snd n). +Definition NZpred (n : Z) := (fst n, S (snd n)). +(* We do not have P (S n) = n but only P (S n) == n. It could be possible +to consider as canonical only pairs where one of the elements is 0, and +make all operations convert canonical values into other canonical values. +In that case, we could get rid of setoids as well as arrive at integers as +signed natural numbers. *) +Definition NZplus (n m : Z) := ((fst n) + (fst m), (snd n) + (snd m)). +Definition NZminus (n m : Z) := ((fst n) + (snd m), (snd n) + (fst m)). +Definition NZuminus (n : Z) := (snd n, fst n). +(* Unfortunately, the elements of the pair keep increasing, even during +subtraction *) +Definition NZtimes (n m : Z) := + ((fst n) * (fst m) + (snd n) * (snd m), (fst n) * (snd m) + (snd n) * (fst m)). + +Theorem ZE_refl : reflexive Z E. +Proof. +unfold reflexive, E; reflexivity. +Qed. + +Theorem ZE_symm : symmetric Z E. +Proof. +unfold symmetric, E; now symmetry. +Qed. + +Theorem ZE_trans : transitive Z E. +Proof. +unfold transitive, E. intros n m p H1 H2. +assert (H3 : (fst n + snd m) + (fst m + snd p) == (fst m + snd n) + (fst p + snd m)) +by now apply plus_wd. +stepl ((fst n + snd p) + (fst m + snd m)) in H3 by ring. +stepr ((fst p + snd n) + (fst m + snd m)) in H3 by ring. +now apply -> plus_cancel_r in H3. +Qed. + +Theorem NZE_equiv : equiv Z E. +Proof. +unfold equiv; repeat split; [apply ZE_refl | apply ZE_trans | apply ZE_symm]. +Qed. + +Add Relation Z E + reflexivity proved by (proj1 NZE_equiv) + symmetry proved by (proj2 (proj2 NZE_equiv)) + transitivity proved by (proj1 (proj2 NZE_equiv)) +as NZE_rel. + +Add Morphism (@pair N N) with signature NE ==> NE ==> E as Zpair_wd. +Proof. +intros n1 n2 H1 m1 m2 H2; unfold E; simpl; rewrite H1; now rewrite H2. +Qed. + +Add Morphism NZsucc with signature E ==> E as NZsucc_wd. +Proof. +unfold NZsucc, E; intros n m H; simpl. +do 2 rewrite plus_succ_l; now rewrite H. +Qed. + +Add Morphism NZpred with signature E ==> E as NZpred_wd. +Proof. +unfold NZpred, E; intros n m H; simpl. +do 2 rewrite plus_succ_r; now rewrite H. +Qed. + +Add Morphism NZplus with signature E ==> E ==> E as NZplus_wd. +Proof. +unfold E, NZplus; intros n1 m1 H1 n2 m2 H2; simpl. +assert (H3 : (fst n1 + snd m1) + (fst n2 + snd m2) == (fst m1 + snd n1) + (fst m2 + snd n2)) +by now apply plus_wd. +stepl (fst n1 + snd m1 + (fst n2 + snd m2)) by ring. +now stepr (fst m1 + snd n1 + (fst m2 + snd n2)) by ring. +Qed. + +Add Morphism NZminus with signature E ==> E ==> E as NZminus_wd. +Proof. +unfold E, NZminus; intros n1 m1 H1 n2 m2 H2; simpl. +symmetry in H2. +assert (H3 : (fst n1 + snd m1) + (fst m2 + snd n2) == (fst m1 + snd n1) + (fst n2 + snd m2)) +by now apply plus_wd. +stepl (fst n1 + snd m1 + (fst m2 + snd n2)) by ring. +now stepr (fst m1 + snd n1 + (fst n2 + snd m2)) by ring. +Qed. + +Add Morphism NZtimes with signature E ==> E ==> E as NZtimes_wd. +Proof. +unfold NZtimes, E; intros n1 m1 H1 n2 m2 H2; simpl. +stepl (fst n1 * fst n2 + (snd n1 * snd n2 + fst m1 * snd m2 + snd m1 * fst m2)) by ring. +stepr (fst n1 * snd n2 + (fst m1 * fst m2 + snd m1 * snd m2 + snd n1 * fst n2)) by ring. +apply plus_times_repl_pair with (n := fst m2) (m := snd m2); [| now idtac]. +stepl (snd n1 * snd n2 + (fst n1 * fst m2 + fst m1 * snd m2 + snd m1 * fst m2)) by ring. +stepr (snd n1 * fst n2 + (fst n1 * snd m2 + fst m1 * fst m2 + snd m1 * snd m2)) by ring. +apply plus_times_repl_pair with (n := snd m2) (m := fst m2); +[| (stepl (fst n2 + snd m2) by ring); now stepr (fst m2 + snd n2) by ring]. +stepl (snd m2 * snd n1 + (fst n1 * fst m2 + fst m1 * snd m2 + snd m1 * fst m2)) by ring. +stepr (snd m2 * fst n1 + (snd n1 * fst m2 + fst m1 * fst m2 + snd m1 * snd m2)) by ring. +apply plus_times_repl_pair with (n := snd m1) (m := fst m1); +[ | (stepl (fst n1 + snd m1) by ring); now stepr (fst m1 + snd n1) by ring]. +stepl (fst m2 * fst n1 + (snd m2 * snd m1 + fst m1 * snd m2 + snd m1 * fst m2)) by ring. +stepr (fst m2 * snd n1 + (snd m2 * fst m1 + fst m1 * fst m2 + snd m1 * snd m2)) by ring. +apply plus_times_repl_pair with (n := fst m1) (m := snd m1); [| now idtac]. +ring. +Qed. + +Delimit Scope IntScope with Int. +Bind Scope IntScope with NZ. +Open Local Scope IntScope. +Notation "x == y" := (NZE x y) (at level 70) : IntScope. +Notation "x ~= y" := (~ NZE x y) (at level 70) : IntScope. +Notation "0" := NZ0 : IntScope. +Notation "'S'" := NZsucc : IntScope. +Notation "'P'" := NZpred : IntScope. +Notation "1" := (S 0) : IntScope. +Notation "x + y" := (NZplus x y) : IntScope. +Notation "x - y" := (NZminus x y) : IntScope. +Notation "x * y" := (NZtimes x y) : IntScope. + +Theorem NZpred_succ : forall n : Z, P (S n) == n. +Proof. +unfold NZpred, NZsucc, E; intro n; simpl. +rewrite plus_succ_l; now rewrite plus_succ_r. +Qed. + +Section Induction. +Open Scope NatIntScope. (* automatically closes at the end of the section *) +Variable A : Z -> Prop. +Hypothesis A_wd : predicate_wd E A. + +Add Morphism A with signature E ==> iff as A_morph. +Proof. +exact A_wd. +Qed. + +Theorem NZinduction : + A 0 -> (forall n : Z, A n <-> A (S n)) -> forall n : Z, A n. (* 0 is interpreted as in Z due to "Bind" directive *) +Proof. +intros A0 AS n; unfold NZ0, NZsucc, predicate_wd, fun_wd, E in *. +destruct n as [n m]. +cut (forall p : N, A (p, 0)); [intro H1 |]. +cut (forall p : N, A (0, p)); [intro H2 |]. +destruct (plus_dichotomy n m) as [[p H] | [p H]]. +rewrite (A_wd (n, m) (0, p)); simpl. rewrite plus_0_l; now rewrite plus_comm. apply H2. +rewrite (A_wd (n, m) (p, 0)); simpl. now rewrite plus_0_r. apply H1. +induct p. assumption. intros p IH. +apply -> (A_wd (0, p) (1, S p)) in IH; [| now rewrite plus_0_l, plus_1_l]. +now apply <- AS. +induct p. assumption. intros p IH. +replace 0 with (snd (p, 0)); [| reflexivity]. +replace (S p) with (S (fst (p, 0))); [| reflexivity]. now apply -> AS. +Qed. + +End Induction. + +Theorem NZplus_0_l : forall n : Z, 0 + n == n. +Proof. +intro n; unfold NZplus, E; simpl. now do 2 rewrite plus_0_l. +Qed. + +Theorem NZplus_succ_l : forall n m : Z, (S n) + m == S (n + m). +Proof. +intros n m; unfold NZplus, E; simpl. now do 2 rewrite plus_succ_l. +Qed. + +Theorem NZminus_0_r : forall n : Z, n - 0 == n. +Proof. +intro n; unfold NZminus, E; simpl. now do 2 rewrite plus_0_r. +Qed. + +Theorem NZminus_succ_r : forall n m : Z, n - (S m) == P (n - m). +Proof. +intros n m; unfold NZminus, E; simpl. symmetry; now rewrite plus_succ_r. +Qed. + +Theorem NZtimes_0_r : forall n : Z, n * 0 == 0. +Proof. +intro n; unfold NZtimes, E; simpl. +repeat rewrite times_0_r. now rewrite plus_assoc. +Qed. + +Theorem NZtimes_succ_r : forall n m : Z, n * (S m) == n * m + n. +Proof. +intros n m; unfold NZtimes, NZsucc, E; simpl. +do 2 rewrite times_succ_r. ring. +Qed. + +End NZAxiomsMod. + +Definition NZlt (n m : Z) := (fst n) + (snd m) < (fst m) + (snd n). +Definition NZle (n m : Z) := (fst n) + (snd m) <= (fst m) + (snd n). + +Notation "x < y" := (NZlt x y) : IntScope. +Notation "x <= y" := (NZle x y) : IntScope. +Notation "x > y" := (NZlt y x) (only parsing) : IntScope. +Notation "x >= y" := (NZle y x) (only parsing) : IntScope. + +Add Morphism NZlt with signature E ==> E ==> iff as NZlt_wd. +Proof. +unfold NZlt, E; intros n1 m1 H1 n2 m2 H2; simpl. split; intro H. +stepr (snd m1 + fst m2) by apply plus_comm. +apply (plus_lt_repl_pair (fst n1) (snd n1)); [| assumption]. +stepl (snd m2 + fst n1) by apply plus_comm. +stepr (fst m2 + snd n1) by apply plus_comm. +apply (plus_lt_repl_pair (snd n2) (fst n2)). +now stepl (fst n1 + snd n2) by apply plus_comm. +stepl (fst m2 + snd n2) by apply plus_comm. now stepr (fst n2 + snd m2) by apply plus_comm. +stepr (snd n1 + fst n2) by apply plus_comm. +apply (plus_lt_repl_pair (fst m1) (snd m1)); [| now symmetry]. +stepl (snd n2 + fst m1) by apply plus_comm. +stepr (fst n2 + snd m1) by apply plus_comm. +apply (plus_lt_repl_pair (snd m2) (fst m2)). +now stepl (fst m1 + snd m2) by apply plus_comm. +stepl (fst n2 + snd m2) by apply plus_comm. now stepr (fst m2 + snd n2) by apply plus_comm. +Qed. + +Open Local Scope IntScope. + +Add Morphism NZle with signature E ==> E ==> iff as NZle_wd. +Proof. +unfold NZle, E; intros n1 m1 H1 n2 m2 H2; simpl. +do 2 rewrite le_lt_or_eq. rewrite (NZlt_wd n1 m1 H1 n2 m2 H2). fold (m1 < m2). +fold (n1 == n2) (m1 == m2); fold (n1 == m1) in H1; fold (n2 == m2) in H2. +now rewrite H1, H2. +Qed. + +Theorem NZle_lt_or_eq : forall n m : Z, n <= m <-> n < m \/ n == m. +Proof. +intros n m; unfold NZlt, NZle, E; simpl. apply le_lt_or_eq. +Qed. + +Theorem NZlt_irrefl : forall n : Z, ~ (n < n). +Proof. +intros n; unfold NZlt, E; simpl. apply lt_irrefl. +Qed. + +Theorem NZlt_succ_le : forall n m : Z, n < (S m) <-> n <= m. +Proof. +intros n m; unfold NZlt, NZle, E; simpl. rewrite plus_succ_l; apply lt_succ_le. +Qed. + +End NZOrdAxiomsMod. + +Definition Zopp (n : Z) := (snd n, fst n). + +Notation "- x" := (Zopp x) (at level 35, right associativity) : IntScope. + +Add Morphism Zopp with signature E ==> E as Zopp_wd. +Proof. +unfold E; intros n m H; simpl. symmetry. +stepl (fst n + snd m) by apply plus_comm. +now stepr (fst m + snd n) by apply plus_comm. +Qed. + +Open Local Scope IntScope. + +Theorem Zsucc_pred : forall n : Z, S (P n) == n. +Proof. +intro n; unfold NZsucc, NZpred, E; simpl. +rewrite plus_succ_l; now rewrite plus_succ_r. +Qed. + +Theorem Zopp_0 : - 0 == 0. +Proof. +unfold Zopp, E; simpl. now rewrite plus_0_l. +Qed. + +Theorem Zopp_succ : forall n, - (S n) == P (- n). +Proof. +reflexivity. +Qed. + +End ZPairsAxiomsMod. + +(* For example, let's build integers out of pairs of Peano natural numbers +and get their properties *) + +(* The following lines increase the compilation time at least twice *) +(* +Require Import NPeano. + +Module Export ZPairsPeanoAxiomsMod := ZPairsAxiomsMod NPeanoAxiomsMod. +Module Export ZPairsTimesOrderPropMod := ZTimesOrderPropFunct ZPairsPeanoAxiomsMod. + +Open Local Scope IntScope. + +Eval compute in (3, 5) * (4, 6). +*) + diff --git a/theories/Numbers/Integer/NatPairs/ZPairsAxioms.v b/theories/Numbers/Integer/NatPairs/ZPairsAxioms.v deleted file mode 100644 index 2a9b4f3866..0000000000 --- a/theories/Numbers/Integer/NatPairs/ZPairsAxioms.v +++ /dev/null @@ -1,142 +0,0 @@ -Require Import NPlus. -Require Export ZAxioms. - -Module NatPairsDomain (Import NPlusMod : NPlusSig) <: ZDomainSignature. -(* with Definition Z := - (NPM.NBaseMod.DomainModule.N * NPM.NBaseMod.DomainModule.N)%type - with Definition E := - fun p1 p2 => - NPM.NBaseMod.DomainModule.E (NPM.plus (fst p1) (snd p2)) (NPM.plus (fst p2) (snd p1)) - with Definition e := - fun p1 p2 => - NPM.NBaseMod.DomainModule.e (NPM.plus (fst p1) (snd p2)) (NPM.plus (fst p2) (snd p1)).*) - -Module Export NPlusPropMod := NPlusPropFunct NBaseMod NPlusMod. -Open Local Scope NatScope. - -Definition Z : Set := (N * N)%type. -Definition E (p1 p2 : Z) := ((fst p1) + (snd p2) == (fst p2) + (snd p1)). -Definition e (p1 p2 : Z) := e ((fst p1) + (snd p2)) ((fst p2) + (snd p1)). - -Delimit Scope IntScope with Int. -Bind Scope IntScope with Z. -Notation "x == y" := (E x y) (at level 70) : IntScope. -Notation "x # y" := (~ E x y) (at level 70) : IntScope. - -Theorem E_equiv_e : forall x y : Z, E x y <-> e x y. -Proof. -intros x y; unfold E, e; apply E_equiv_e. -Qed. - -Theorem ZE_refl : reflexive Z E. -Proof. -unfold reflexive, E; reflexivity. -Qed. - -Theorem ZE_symm : symmetric Z E. -Proof. -unfold symmetric, E; now symmetry. -Qed. - -Theorem ZE_trans : transitive Z E. -Proof. -unfold transitive, E. intros x y z H1 H2. -apply plus_cancel_l with (p := fst y + snd y). -rewrite (plus_shuffle2 (fst y) (snd y) (fst x) (snd z)). -rewrite (plus_shuffle2 (fst y) (snd y) (fst z) (snd x)). -rewrite plus_comm. rewrite (plus_comm (snd y) (fst x)). -rewrite (plus_comm (snd y) (fst z)). now apply plus_wd. -Qed. - -Theorem E_equiv : equiv Z E. -Proof. -unfold equiv; split; [apply ZE_refl | split; [apply ZE_trans | apply ZE_symm]]. -Qed. - -Add Relation Z E - reflexivity proved by (proj1 E_equiv) - symmetry proved by (proj2 (proj2 E_equiv)) - transitivity proved by (proj1 (proj2 E_equiv)) -as E_rel. - -Add Morphism (@pair N N) - with signature NDomainModule.E ==> NDomainModule.E ==> E - as pair_wd. -Proof. -intros x1 x2 H1 y1 y2 H2; unfold E; simpl; rewrite H1; now rewrite H2. -Qed. - -End NatPairsDomain. - -Module NatPairsInt (Import NPlusMod : NPlusSig) <: ZBaseSig. -Module Export ZDomainModule := NatPairsDomain NPlusMod. -Module Export ZDomainModuleProperties := ZDomainProperties ZDomainModule. -Open Local Scope IntScope. - -Definition O : Z := (0, 0)%Nat. -Definition S (n : Z) := (NBaseMod.S (fst n), snd n). -Definition P (n : Z) := (fst n, NBaseMod.S (snd n)). -(* Unfortunately, we do not have P (S n) = n but only P (S n) == n. -It could be possible to consider as "canonical" only pairs where one of -the elements is 0, and make all operations convert canonical values into -other canonical values. We do not do this because this is more complex -and because we do not have the predecessor function on N at this point. *) - -Notation "0" := O : IntScope. - -Add Morphism S with signature E ==> E as succ_wd. -Proof. -unfold S, E; intros n m H; simpl. -do 2 rewrite plus_succ_l; now rewrite H. -Qed. - -Add Morphism P with signature E ==> E as pred_wd. -Proof. -unfold P, E; intros n m H; simpl. -do 2 rewrite plus_succ_r; now rewrite H. -Qed. - -Theorem succ_inj : forall x y : Z, S x == S y -> x == y. -Proof. -unfold S, E; simpl; intros x y H. -do 2 rewrite plus_succ_l in H. now apply succ_inj in H. -Qed. - -Theorem succ_pred : forall x : Z, S (P x) == x. -Proof. -intro x; unfold S, P, E; simpl. -rewrite plus_succ_l; now rewrite plus_succ_r. -Qed. - -Section Induction. -Open Scope NatScope. (* automatically closes at the end of the section *) -Variable A : Z -> Prop. -Hypothesis Q_wd : predicate_wd E A. - -Add Morphism A with signature E ==> iff as Q_morph. -Proof. -exact Q_wd. -Qed. - -Theorem induction : - A 0 -> (forall x, A x -> A (S x)) -> (forall x, A x -> A (P x)) -> forall x, A x. -Proof. -intros Q0 QS QP x; unfold O, S, P, predicate_wd, E in *. -destruct x as [n m]. -cut (forall p : N, A (p, 0)); [intro H1 |]. -cut (forall p : N, A (0, p)); [intro H2 |]. -destruct (plus_dichotomy n m) as [[p H] | [p H]]. -rewrite (Q_wd (n, m) (0, p)); simpl. rewrite plus_0_l; now rewrite plus_comm. apply H2. -rewrite (Q_wd (n, m) (p, 0)); simpl. now rewrite plus_0_r. apply H1. -induct p. assumption. intros p IH. -replace 0 with (fst (0, p)); [| reflexivity]. -replace p with (snd (0, p)); [| reflexivity]. now apply QP. -induct p. assumption. intros p IH. -replace 0 with (snd (p, 0)); [| reflexivity]. -replace p with (fst (p, 0)); [| reflexivity]. now apply QS. -Qed. - -End Induction. - -End NatPairsInt. - |
