---(****************************
 * Auto-generated Maude model *
 ******************************)---
omod FACTORIAL is
    including LF-REPR .
    protecting LF-VALUE-TIME .

    op Factorial : -> ReactorId [ctor] .
    op factorial : -> ReactorId [ctor] .
    op printer : -> ReactorId [ctor] .
    op factorial.sv.N : -> RVarId [ctor] .
    op factorial.sv.result : -> RVarId [ctor] .
    op factorial.sv.lastResult : -> RVarId [ctor] .
    op printer.sv.result : -> RVarId [ctor] .
    op factorial.out.out : -> RPortId [ctor] .
    op printer.in.in : -> RPortId [ctor] .
    op factorial.t.t : -> TimerId [ctor] .
    op factorial.la.prepForNext : -> RActionId [ctor] .
    op init : -> Configuration .
    
    eq init = 
        < factorial : Reactor |
            inports : none,
            outports : 
                < factorial.out.out : Port | value : [0] >,
            state : 
                ( factorial.sv.N |-> [0] );
                ( factorial.sv.result |-> [0] );
                ( factorial.sv.lastResult |-> [0] ),
            timers : 
                < factorial.t.t : Timer | offset : 0, period : 1000000 >,
            actions : 
                < factorial.la.prepForNext : LogicalAction | minDelay : 0, minSpacing : 0, policy : defer, payload : [0] >,
            reactions : 
                (reaction when (factorial.t.t) --> (factorial.out.out ; factorial.la.prepForNext) do {
                    if ((factorial.sv.N < [2])) then ((factorial.sv.result := [1])) else ((factorial.sv.result := (factorial.sv.N * factorial.sv.lastResult))) fi ;
                    (factorial.out.out <- factorial.sv.result) ;
                    schedule(factorial.la.prepForNext, [0], [0])
                })
                (reaction when (factorial.la.prepForNext) do {
                    (factorial.sv.N := (factorial.sv.N + [1])) ;
                    (factorial.sv.lastResult := factorial.sv.result)
                })
        >
        < printer : Reactor |
            inports : 
                < printer.in.in : Port | value : [0] >,
            outports : none,
            state : 
                ( printer.sv.result |-> [0] ),
            timers : none,
            actions : none,
            reactions : 
                (reaction when (printer.in.in) do {
                    (printer.sv.result := printer.in.in) ;
                    skip
                })
        >
    (factorial : factorial.out.out --> printer : printer.in.in)
    .
endom

omod TEST-FACTORIAL is
    including FACTORIAL .
    including DYNAMICS-WITHOUT-TICK .

    ops env queue rxns : -> Oid [ctor] .

    op initSystem : -> GlobalSystem .
    eq initSystem =
        { < env : Environment |
            physicalActions : none
             > 
            addReactionIndices(init)
            < queue : EventQueue | queue : 
            addInitialTimers(init, empty) >
            < rxns : Invoked | reactions : none >} .
endom

omod ANALYSIS-FACTORIAL is
    including TEST-FACTORIAL .
    including LF-PROP-EXT .
    including SEARCH-GOAL .
endom

omod MODELCHECKER-FACTORIAL is
    including TEST-FACTORIAL .
    including LF-OUTPUT-COUNTEREXAMPLE .
    including LF-PROP-EXT .
    including MODEL-CHECKER .
endom

omod SIMULATION-FACTORIAL is
    including TEST-FACTORIAL .
    including TIMED-SIMULATION-DYNAMICS .
endom

search [1] in ANALYSIS-FACTORIAL : initSystem timeBound 10000000 =>* CS:ClockedSystem  such that CS:ClockedSystem |= (((printer . 1) invoked ) /\ (( (@ printer.sv.result in printer) ==/= @ [3628800] )) /\ remainingTime 0) .

quit
