(**************************************************************)
(*   Copyright Dominique Larchey-Wendling [*]                 *)
(*                                                            *)
(*                             [*] Affiliation LORIA -- CNRS  *)
(**************************************************************)
(*      This file is distributed under the terms of the       *)
(*         CeCILL v2 FREE SOFTWARE LICENSE AGREEMENT          *)
(**************************************************************)
(** ** Exponentiation is Diophantine *)
Set Implicit Arguments.
Local Notation expo := (mscal mult 1).
Section expo_diophantine.
Variables (p q r : nat).
Definition expo_conditions :=
r = 0 /\ p = 1
\/ q = 0 /\ 0 < r /\ p = 0
\/ (0 < r /\ q <> 0) /\ exists b m a1 a2 a3,
(3 < q+4 /\ a1 = alpha_nat (q+4) (1+r))
/\ (3 < b   /\ a2 = alpha_nat b r)
/\ (3 < b   /\ a3 = alpha_nat b (1+r))
/\ b = a1+q*q+2
/\ m + q*q + 1 = b*q
/\ p < m
/\ rem (p+b*a2) m = rem (q*a2+a3) m.
Let H_q3_q : 0 < q -> q*q+2 <= q*q*q+2*q.

(* Specifications: *)
Lemma expo_sufficiency : p = expo r q -> expo_conditions.
Infix "⊕" := (Zp_plus _) (at level 50, left associativity).