(**************************************************************)
(*   Copyright Dominique Larchey-Wendling [*]                 *)
(*                                                            *)
(*                             [*] Affiliation LORIA -- CNRS  *)
(**************************************************************)
(*      This file is distributed under the terms of the       *)
(*         CeCILL v2 FREE SOFTWARE LICENSE AGREEMENT          *)
(**************************************************************)
(** ** Base p representation *)
Set Implicit Arguments.
Local Notation power := (mscal mult 1).
Local Notation "∑" := (msum plus 0).
Fact sum_0n_distr_in_out n a b f :
∑ n (fun i => (a i+b i) * f i)
= ∑ n (fun i => a i * f i)
+ ∑ n (fun i => b i * f i).
Section power_decomp.
Variable (p : nat) (Hp : 2 <= p).
Let power_nzero x : power x p <> 0.

(* Specifications: *)
Lemma power_decomp_is_digit n a f :
(forall i j, i < j < n -> f i < f j)
-> (forall i, i < n -> a i < p)
->  forall i, i < n -> is_digit (∑ n (fun i => a i * power (f i) p)) p (f i) (a i).
Theorem power_decomp_unique n f a b :
(forall i j, i < j < n -> f i < f j)
-> (forall i, i < n -> a i < p)
-> (forall i, i < n -> b i < p)
-> ∑ n (fun i => a i * power (f i) p)
= ∑ n (fun i => b i * power (f i) p)
-> forall i, i < n -> a i = b i.