Section Pell.
Variable (b_nat : nat) (Hb_nat : 2 <= b_nat).
Fixpoint alpha_nat n :=
match n with
| 0   => 0
| S p => match p with
| 0   => 1
| S r => b_nat * alpha_nat p - alpha_nat r
end
end.
Fact alpha_nat_fix_0 : alpha_nat 0 = 0.    Proof. auto. Qed.
Fact alpha_nat_fix_1 : alpha_nat 1 = 1.    Proof. auto. Qed.
Fact alpha_nat_fix_2 n : alpha_nat (S (S n)) = b_nat *alpha_nat (S n) - alpha_nat n.
Fact alpha_nat_inc n : alpha_nat n < alpha_nat (S n).
Fact alpha_nat_ge_n n : n <= alpha_nat n.
Fact alpha_nat_gt_0 : forall n, n <> 0 -> alpha_nat n <> 0.
Fact alpha_nat_le n : alpha_nat n <= b_nat * alpha_nat (S n).
Notation power := (mscal mult 1).
Fact alpha_nat_power n : 2 < b_nat -> power n (b_nat-1) <= alpha_nat (S n) <= power n b_nat.
Open Scope Z.
Let b := Z.of_nat b_nat.
Let Hb : 2 <= b.
Fact alpha_inc n : α n < α (S n).
Fact alpha_ge_0 n : 0 <= α (S n).
Opaque α.
Create HintDb alpha_db.
Hint Rewrite alpha_fix_0 alpha_fix_1 alpha_fix_2 alpha_fix_3 : alpha_db.
Ltac alpha := autorewrite with alpha_db.
Fact alpha_2 : b = 2 -> forall n, α n = Z.of_nat n - 1.
Notation MZ := (M22 Z).
Notation MZ_opp := (MI22 Z.opp).
Notation MZ_plus := (PL22 Zplus).
Notation MZ_mult := (MU22 Zplus Zmult).
Notation MZ_zero := (ZE_22 0).
Notation MZ_one := (ID_22 0 1).
Notation MZ_scal := (M22scal Zmult).
Notation MZ_expo := (mscal MZ_mult MZ_one).
Notation MZ_det := (Det22 Zplus Zmult Z.opp).
Local Fact MZ_plus_monoid : monoid_theory MZ_plus MZ_zero.
Hint Resolve MZ_expo_A : core.
Fact A_plus u v : A (u+v)%nat = A u ⊠ A v.
Fact A_mult u v : A (u*v)%nat = MZ_expo u (A v).
Fact A_plus_mult m n k l :
(m = n + l * k)%nat
-> A m = A n ⊠ MZ_expo l (A k).
Fact MZ_det_B : MZ_det B = 1.
Definition Pell x y := x*x -b*x*y+y*y=1.

Theorem alpha_Pell n : Pell (α (S n)) (α n).