(* Copyright 2012-2015 by Adam Petcher.				* * Use of this source code is governed by the license described	* * in the LICENSE file at the root of the source tree.		*)
(* Definitions and theory of natural numbers that is useful in cryptographi proofs. *)
Set Implicit Arguments.
Require Export Arith.
Require Export Omega.
Require Export Arith.Div2.
Require Export Coq.Numbers.Natural.Peano.NPeano.
induction n1; destruct n2; intuition; simpl in *.
remember (n2 * n3) as x.
omega.
remember (n1 * n3) as x.
omega.
f_equal.
eapply IHn1; eauto.
eapply plus_reg_l. eauto.
Qed.
intuition.
eapply mult_same_r; eauto.
rewrite mult_comm.
rewrite (mult_comm n2 n3).
trivial.
Qed.
destruct n1; intuition; simpl in *.
remember (n1 * n2) as x.
omega.
Qed.
intuition.
Qed.
intuition.
Qed.
intuition.
Qed.
intuition.
Qed.
intuition.
Qed.
Class nz (a : nat) := {
agz : a > 0
}.
Instance nz_nat : forall (n : nat), nz (S n).
intuition.
econstructor.
omega.
Defined.
Definition posnat := {n : nat | n > 0}.
Definition posnatToNat(p : posnat) :=
match p with
| exist _ n _ => n
end.
Inductive posnatEq : posnat -> posnat -> Prop :=
| posnatEq_intro :
forall (n1 n2 : nat) pf1 pf2,
n1 = n2 ->
posnatEq (exist _ n1 pf1) (exist _ n2 pf2).
Definition posnatMult(p1 p2 : posnat) : posnat :=
match (p1, p2) with
| (exist _ n1 pf1, exist _ n2 pf2) =>
(exist (fun n => n > 0) (n1 * n2) (mult_gt_0 pf1 pf2))
end.
intuition.
unfold posnatMult.
destruct p1; destruct p2.
econstructor.
apply mult_comm.
Qed.
Coercion posnatToNat : posnat >-> nat.
intuition.
destruct p.
unfold posnatToNat.
trivial.
Qed.
Instance nz_posnat : forall (p : posnat),
nz p.
intuition.
econstructor.
eapply posnat_pos.
Qed.
Definition natToPosnat(n : nat)(pf : nz n) :=
(exist (fun x => x > 0) n agz).
Notation "'pos' x" := (@natToPosnat x _) (at level 40).
Fixpoint expnat n1 n2 :=
match n2 with
| 0 => 1
| S n2' =>
n1 * (expnat n1 n2')
end.

Theorem expnat_pos : forall x n,
x > 0 ->
expnat x n > 0.