The Animator (anm)

The Animator is a tool to demonstrate the state transitions of an Abstract Machine specification, achieved through its operations which are invoked interactively through user-provided input. The operations are displayed on screen, together with precondition and guard simplification (where appropriate) with operation output and state variables being displayed in a state window; the state invariant of the machine may also be optionally displayed (toggled in the Operation Menu).

The animator may also be driven through an ANIMATE Script (in Interactive, Execute Step or Execute Auto mode); the Scripts may be automatically created from an interactive session (so that they may be replayed against changed AMN) or may be edited from a template form. For both Execute modes, assertions on the output of operations, and on the state variables may be included in a Script  and these are evaluated and displayed during execution.

The output of all three modes of driving the animator may be saved - in interactive mode through the Utilities Menu and in either executable mode through a dialog which appears at the end of the execution. An output file is saved as  fifi.identifier.out and may subsequently be viewed through the  Browse Output File option of the Animator Menu.

Animation (anm) is invoked from the Main Environment for all currently analysed specifications, and so all library and generated machines may be animated (a good way to familiarize oneself with their functionality!).
 
In this description, fifi is assumed to be the name of the machine being animated.


The Animator Menu

The animator menu offers six options: The Animator Menu

Interactive, Execute Step and Execute Auto offer three different ways of driving the Animator.

Edit ANIMATE Script provides a way of editing an ANIMATE Scrip ; an existing script may be edited or a new one be created (with template optionally provided from an existing Script); dialog menus are automatically provided).
 
Browse Output File provides a menu of previously saved State Output files  (created from the Utilities Menu) which may be selected for browsing.

Clean Animator Files provides a menu of Script ( .anm ) and State Output files ( .out ) which may be removed when no longer needed. This option is also avaiable from the Utilities Menu.


Interactive Preliminaries

Animator Theory File

On invoking the Animator interactively for the first time, a session window appears, with, for example, the display
  No file "SRC/fifi.mch.thy" - creating template
indicating that no user-supplied theory is provided to supplement the Animator's library of re-write rules, but that a template theory file has been created in the SRC directory (see Providing More Rewrite Rules below); when theory is supplied, the display will read
  "SRC/fifi.mch.thy" loaded
provided the theory files parses, and
  "SRC/fifi.mch.thy" does not parse - not loaded
otherwise, together with information showing the cause of the error.

Animator Initialisation Files

On using the Animator interactively, if one or more previously ANIMATE Script files is found, the following prompt is displayed:
  Initialize state from ANIMATE Script?
If you reply `No', the state of the machine will be initialized according to its specification. You will be asked to instantiate any machine parameters (which must be natural numbers or enumerated sets). The Animator will then calculate the instantiated machine constraints and present them in a simplified form. If the machine (or any of its subordinates) contains sets or constants  a dialog will be presented so that they may be set, and, one set they will be represented in a simplified form.

It is recommended that all abstract sets are instantiated, otherwise realistic animation is usually not possible.

A `Yes' answer provides a menu from which the Script may be selected; subsequent selection overrides the initialization given in the Abstract Machine specification, and instead initializes the state of the Machine to that saved on file; with machine parameters and context also being set. The initial state is then displayed in the state window.
 


The Animator Operation Menu

Once animation has started, the operations of the machine are displayed in a menu together with: Animator Operation Menu See figure.

On selection of an operation, its specification is displayed together with its stated precondition. If the operation has input parameters, you will be asked to instantiate them, and the simplified precondition will be displayed:

Precondition Simplification See figure.

You will also be asked to resolve any nondeterminacy (e.g. in an ANY guard). The Animator simplifies, as far as it can, the precondition (or guards) of an operation according to the current state of the Machine. Whatever the value of the precondition or guard, the specified state change is performed, with the value of any output and the final state reported in the state window:

State Display See figure.

The `Undo' option allows you to return to the state prior to the action of the last operation.

Animator Utilities provides another menu of operations.

Display Invariant/Don't Display Invariant provides a toggle to display the current state of the INVARIANT of the machine:

Invariant Display See figure.

The `Quit' option allows you to leave the animation.


The Animator Utilities Menu

The Animator Utilities Menu is accessed from the Animator Operation Menu and offers: Animator Utilities Menu See figure

Edit theory file provides a means of adding rules to aid the animator simplification mechanism.

Restore initial state enables the animation to be restarted with the initial state.

Restart animation causes the animation to be restarted form scratch.

Set state variables enables the current values of the state variables to be overwritten.

Save output results in a prompt for a filename identifier, with the current output being recorded on that file ( SRC/fifi.identifier.out ); it is subsequently possiblt to browse output through the main Animator Menu.

Save as ANIMATE Script Initialisation enables an interactive animator session to be written to an ANIMATE Script in such a way that  it may be used to initialise (machine parameters, state variables and context) an Interactive Animator session - a menu of such Scripts is automatically provided at the start of each interactive session.

Save as ANIMATE Script Executable enables an interactive animator session to be written to an ANIMATE Script and subsequently replayed either in Step or Auto mode (although it may be used in Interactive mode - see NOTE).

Clean Animator Files provides a menu of ANIMATE Script ( .anm ) and State Output files ( .out ) which may be removed when no longer needed. This option is also avaiable from the main Animator Menu.


The  ANIMATE Script

An ANIMATE Script has filename `SRC/fif.identifier.anm'; its syntax is given in a BNF-like syntax as follows: the syntax exp1 | exp2 indicates exp1 or exp2 (choice), and  [| exp |] indicates optionality.
     ANIMATE

        machinename.identifier.anm

     [|
       PARAMETER_VALUES
         ?  |  value [| ; value |]
       SETS_VALUES
         ?  |  value [| ; value |]
       CONSTANTS_VALUES
         ?  |  value [| ; value |]
       ENUM_SETS_VALUES
         ?  |  value [| ; value |]
     |]

     OPERATIONS
       ini_operation [| ; operation |]

     END


     value          ::=    identifier = expression
     ini_operation  ::=    INI_op [| : command_list |]  |  _set_state_variables : ( eql_list )
     INI_op         ::=    INI_fifi
     operation      ::=    ANM_op [| : command_list |]  |  { predicate }
     AMN_op         ::=    [| varlist <-- |] identifier [| ( varlist ) |]
     command_list   ::=    command [| , command |]
     command        ::=    local_vars ( eql_list )  |  branch ( num )

     eql_list       ::=    equality [| , equality |]

     equality       ::=    identifier = value

Note that each of the clauses is optional (but see NOTE), and that a clause containing ? is equivalent to the clause being absent.
 

NOTE
    1. If the Script is to be used as an Interactive Initialisation the OPERATIONS clause should contain a single _set_state_variables entry, otherwise the clause will be ignored and an initialisation performed.
    2. Either the INI_  or the  _set_state_variables operation should appear as the first operation of the OPERATIONS clause.
    3. The INI_ operation may not appear other than as the first operation.
See also Animate Script example.

Creating an ANIMATION Script

A Script may be automatically created from an interactive session through the Utilities Menu . In this case assertions for all operations returning output will automatically be created (see the ANIMATION Script example below).

A new Script may be created through the  Edit ANIMATE Script option of the Animator Menu when a sub-menu will be provided offering the edit of an existing Script or the creation of a new one.

A template for a new Script may be achieved in one of two ways:

 

An example ANIMATE script

The following Script was created automatically using the Utilities Menu -> ave as ANIMATE Script Executable for DEMO9_PERSON3 following an interactive animation:
        ANIMATE
          Person3.demo.anm
        PARAMETER_VALUES
          max_person = 100
        SETS_VALUES
          SCALAR = 0..2147483646;
          STRING = STRING;
          PERSON = {p1 , p2 , p3 , p4 , p5}
        CONSTANTS_VALUES
          ?
        ENUM_SETS_VALUES
          BOOL = {FALSE , TRUE};
          CHAR = {B_SOH , B_STX , B_ETX , B_EOT , B_ENQ , B_ACK , B_BEL , B_BS , B_HT , B_LF , B_VT , B_FF , B_CR , B_SO , B_SI , B_DLE , B_DC1 , B_DC2 , B_DC3 , B_DC4 , B_NAK , B_SYN , B_ETB , B_CAN , B_EM , B_SUB , B_ESC , B_FS , B_GS , B_RS , B_US , B_SPACE , B_EXCL , B_QUOT , B_HSH , B_DOLL , B_PCT , B_AMP , B_SQUOT , B_OPAR , B_CPAR , B_MUL , B_PLUS , B_COM , B_MINUS , B_DOT , B_DIV , '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , B_COL , B_SCOL , B_LESS , B_EQL , B_GTR , B_QUERY , B_CADD , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' , B_OBRK , B_SLSH , B_CBRK , B_HAT , B_UNL , B_BSQ , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' , B_OBRC , B_BAR , B_CBRC , B_TLD , B_DEL};
          SEX = {female , male}
        OPERATIONS
          INI_Person3;
          rep , new_person <-- Add_person(rupert,91,male) :
                (
                    branch(1);
                    loc_vars( pers = p5 )
                );
              { rep = TRUE };
              { new_person = p5 };
          rep <-- Print_person_details(p5);
              { rep = TRUE };
          rep <-- Remove_person(p5);
              { rep = TRUE }
        END
 

Note that if choices/local variables are nested in the AMN, the commands following the : must sequentially reflect the route to be taken: so, for example:

        op :
            (
                branch(3);
                branch(2);
                loc_vars( (var1 = 13), (var2 = 77) )
            )

would ensure that var1 and var2 were set in:

   op =
     CHOICE ... OR ... OR CHOICE ... OR ANY var1,var2 WHERE ... END OR ... END OR ... END

Executable Animation - Step

Replaying an ANIMATE Script in Step mode results in exactly the same state output display as if the animator were driven interactively; the machine is first initialised (paremeters & context set, and initialised either through a STATE_VALUES clause or its INI_ operation) and then each operation is presented as a dialog:
 
EXECUTE - Step

At the end of animation, the user is invited to optionally save the output (as a .out file).
 


Executable Animation - Auto

The difference between Auto execution and Step execution is that the former is processed without output display; the display may be viewed after the animation is complete by responding to the option to save the output (as a .out file).

Additionally one of the following is reported after the execution is complete:
 


Providing More Rewrite Rules

Simplification of instantiated expressions (outputs, preconditions, guards) is made using a simple set of mathematical re-write rules within the Animator. If the tool is unable to simplify a particular expression, the user can provide appropriate mathematical simplification rules by using the `Edit theory file' of the Utilities Menu. The syntax for the animator theory file is:
     THEORY UserLibX IS
         rewrite_rule [ ; rewrite_rule ]
     END

     [|
       DEFINITIONS
           rewrite_rule [ ; rewrite_rule ]
       INCLUSIONS
           incl_file [ , incl_file ]
     |]
The optional DEFINITIONS clause allows macro definitions in the form of rewrite rules to be applied to the rules of UserLibX before use. If the theory file does not exist, it is created by the system with two default macros; a DEFINITIONS clause comprising `?' is equivalent to an empty clause.

The optional INCLUSIONS clause allows other animator theory files to be loaded (and, of course, the process is recursive). Each inclusion should be the name of an animator theory file enclosed in double quotes (for example "SRC/fifi.mch,thy"). An INCLUSIONS clause comprising `?' is equivalent to an empty clause.

The simplification rules of UserLibX should be expressed as B rewrite rules (see section on the B_Platform).

For example:

  1. the rule
        bident(x) 
       => 
        [l]^[x] == [l,x]
    will re-write the expression
        [aa,bb,cc]^[dd]
    to
        [aa,bb,cc,dd]
  2. the rule
        btest(n>1) 
       => 
        fac(n) == fac(n-1)*n
    will re-write the expression
        fac(7)
    to
        fac(7-1)*7

A full on-line help listing is available in the Contents Page
Also available in the form of a complete Index.
Blogo © B-Core (UK) Limited, Last updated: 22 Feb 2002