Specification of our algorithm

This file presents the notations used by the modules develop , generation , and main .

Procedure Calls

Notations

The addition-chain algorithm uses three mutually recursive functions for generating abstract machine code. In order to use the Program tactic, we treat them at the same time. First, we define the type of procedure calls as an inductive Set:
Inductive Call:Set :=
   Call_M:nat->Call
 | Call_C:nat->nat->Call
 | Call_K:nat->nat->Call.

These strange names come from the notations of our paper .

The intention of each construction is the following:

(Call_M n)
(Call_M n) is a procedure call for generating code to raise the contents of the register X at the n-th power, letting the stack unchanged.
(Call_C n p)
(Call_C n p) is a procedure call for generating code to raise the contents of the register X at the n-th power, letting the stack unchanged, but we force the computation to have a some time
x^p in the register X
(Call_K n p)
(Call_K n p) is a procedure call for generating code to raise the contents of the register X at the n-th power, pushing x^p on the stack

Constraints on procedure calls

The procedures defined above are meaningful only if their parameters satisfy some reasonable constraints: We define a proposition conform: Call->Prop by cases, such that (conform c) means "the parameters of call c are correct".
Definition conform:Call->Prop:=
     [c:Call]
     <Prop>Case c of
      (* Call_M n *)   [n:nat]  (lt O n)
      (* Call_C n p *) [n,p:nat](and (lt (S O) p) (lt p n))
      (* Call_K n p *) [n,p:nat](and (lt O p) (lt p n))
     end.

The formal specification

Specification à la Prolog

We express the intuitive specification for our 3 types of calls by reference to the "abstract machine". That is to say, we define a proposition Spec:Call->Code->Prop, the meaning of which is "The code co is a correct implementation of the procedure call c". We express Spec as an inductive definition, each clause of which express a part of the specification in terms of code execution, register, stack and monoid operations.
Inductive Spec:Call->Code->Prop :=
     m_spec:(n:nat)(c:Code)
              ((M:Set)(MO:(monoid M))
              ((a:M)(s:(Stack M))
               (Exec M MO  c (config M a s))=
               (config M (power M MO  a n) s))) ->
            (Spec (Call_M n) c )

 |   c_spec:(p,q:nat)(c:Code)
               ((M:Set)(MO:(monoid M))
               ((a:M)(s:(Stack M))
                 (Exec M MO c (config M a s))=
                 (config M (power M MO a p) s))) ->
             (Spec (Call_C p q) c)

 |   k_spec:(p,q:nat)(c:Code)
                ((M:Set)(MO:(monoid M))
                ((a:M)(s:(Stack M))
                  (Exec M MO c (config M a s))=
                  (config M (power M MO a p) 
                            (push M (power M MO a q) s)))) ->
              (Spec (Call_K p q) c).

Code generation

It is classical, in Coq, to transform some specification à la Prolog into a Set:
Inductive gencode[c:Call]:Set :=
   gencode_intro:(co:Code)(Spec c co)->(gencode c).
Typically, the proofs of lemmas of the form (gencode c) will be done by a command of the form "Realizer <Fw-term:Code>.", followed by a proof of a logical goal of the form (Spec c co) .

This is done in the module develop .

Specification of the powering algorithm

Finally, we declare Call_M as an entry point :
Inductive  addchain_spec[n:nat]:Set :=
  addchain_spec_intro:(gencode (Call_M n))->
                      (addchain_spec n).
Click here to look at the source .