<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../../../unit.xsl"?>
<KIVSPEC name="AASM">
<SPECBODY>
<external/>
asm specification 
   comment: definition of an ASM for the abstract level of the Mondex
   refinement. Only parts of this ASM (ABIGNORE# and ABTRANSFER#) are used 
   in the definitions of abstract operations of the Mondex refinement. 
   Proving ASM refinement directly is future work and may require
   small corrections to the ASM definition.;
   using <a href="../../../specs/set-nat/export/unit.xml">set-nat</a> <a href="../../../specs/genname/export/unit.xml">genname</a> 
         <a href="../../../specs/AINPUT-list/export/unit.xml">AINPUT-list</a>
   declaration 
     
      <syn>initial state</syn>
      lost := λ na. 0 ; 

      <syn>final state</syn>
      ail = []      

      <syn>ASTEP#</syn>
       <syn>let</syn> value = (hd ail) .value, 
           from = (hd ail) .from, 
           to = (hd ail) .to 
       <syn>in</syn>
           ail := tl ail <syn>seq</syn>
           AOP#

      <syn>AOP#</syn>
       ABIGNORE#() ∨ ABTRANSFER#

      <syn>ABTRANSFER#</syn>
           <syn>choose</syn> fail?           
           <syn>in if</syn> value ≤ balance(from) ∧ authentic(from) ∧ authentic(to) ∧ from ≠ to
              <syn>then if</syn> ¬ fail?
                   <syn>then </syn>
                       balance(from) := balance(from) - value <syn>seq</syn>  
                       balance(to) := balance(to) + value
                   <syn>else</syn> 
                       balance(from) := balance(from) - value 
                       lost(from) := lost(from) + value
              <syn>else</syn> abort
      <syn>ABIGNORE#</syn>
       skip
end asm specification</SPECBODY>
<SPECBODY>
<internal/>asm specification 
   comment: definition of an ASM for the abstract level of the Mondex
   refinement. Only parts of this ASM (ABIGNORE# and ABTRANSFER#) are used 
   in the definitions of abstract operations of the Mondex refinement. 
   Proving ASM refinement directly is future work and may require
   small corrections to the ASM definition.;
   using <a href="../../../specs/set-nat/export/unit.xml">set-nat</a> <a href="../../../specs/genname/export/unit.xml">genname</a> 
         <a href="../../../specs/AINPUT-list/export/unit.xml">AINPUT-list</a>
    target 
         procedures 
            AASM#   : (name → nat) × (name → nat) × ainputlist nonfunctional indeterministic;
            ASTEP#   : (name → nat) × (name → nat) × ainputlist nonfunctional indeterministic;
            AOP#  nat × name × name : (name → nat) × (name → nat) nonfunctional indeterministic;
            ABTRANSFER#  nat × name × name : (name → nat) × (name → nat) nonfunctional indeterministic;
            ABIGNORE#   :  nonfunctional;
         variables 
            balance, lost : name → nat; 
            fail? : bool; 
            value : nat; 
            from, to : name; 
   declaration 
      asm : AASM# (var balance, lost, ail)
              begin 
                 lost := λ na. 0 ; while ail ≠ [] do ASTEP#(; balance, lost, ail)
              end;
      ASTEP# (var balance, lost, ail)
        begin 
           var value = (hd ail) .value, from = (hd ail) .from, to = (hd ail) .to in begin 
                                                                                       ail := tl ail ; AOP#(value, from, to; balance, lost)
                                                                                    end
        end;
      AOP# (value, from, to; var balance, lost)
        begin 
           ABIGNORE#() ∨ ABTRANSFER#(value, from, to; balance, lost)
        end;
      ABTRANSFER# (value, from, to; var balance, lost)
        begin 
           var  fail?
           with true
           in if value ≤ balance(from) ∧ authentic(from) ∧ authentic(to) ∧ from ≠ to
              then if ¬ fail?
                   then begin 
                           balance(from) := balance(from) - value ; balance(to) := balance(to) + value
                        end
                   else balance(from) := balance(from) - value, lost(from) := lost(from) + value
              else abort
        end;
      ABIGNORE# ()
        begin 
           skip
        end;
end asm specification</SPECBODY></KIVSPEC>
