(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(** exp. Exponential function on Z.  @author Olga Caprotti and Martijn Oostdijk @version $Revision$ *)
(** * Exponential function with exponent in nat. *)
Fixpoint Exp (a : Z) (n : nat) {struct n} : Z :=
match n with
| O => 1%Z
| S m => (a * Exp a m)%Z
end.

(* Specifications: *)
Lemma exp_0 : forall n : nat, Exp 0 (S n) = 0%Z.
Lemma exp_1 : forall n : nat, Exp 1 n = 1%Z.
Lemma exp_S : forall (a : Z) (n : nat), Exp a (S n) = (a * Exp a n)%Z.
Lemma exp_plus :
forall (a : Z) (n m : nat), Exp a (n + m) = (Exp a n * Exp a m)%Z.
Lemma exp_abn :
forall (a b : Z) (n : nat), Exp (a * b) n = (Exp a n * Exp b n)%Z.
Lemma exp_mult : forall (a : Z) (n m : nat), Exp a (n * m) = Exp (Exp a n) m.
Lemma exp_not0 : forall a : Z, a <> 0%Z -> forall m : nat, Exp a m <> 0%Z.
(** Convenience lemma for changing exponent. *)
Lemma exp_eq : forall (n m : nat) (a : Z), n = m -> Exp a n = Exp a m.
Lemma exp_pred_succ : forall (a : Z) (n : nat), Exp a (pred (S n)) = Exp a n.
Definition ZExp (a n : Z) : Z :=
match n with
| Z0 => 1%Z
| Zpos p => Exp a (nat_of_P p)
| Zneg p => Exp a (nat_of_P p)
end.