S2_Legality_STACK Module Interface Specification

(0) CHARACTERISTICS

-type specified: s2_stack

-features: deterministic, non-parameterized

-foreign types:

(1) SYNTAX

ACCESS-PROGRAMS

Program Name
Arg#1Arg#2Result Type
DIVCOUNTs2_stack:Vint:Vint
PUSHs2_stack:VOint:V 
POPs2_stack:VO   
TOPs2_stack:V  int

(2) CANONICAL TRACES

canonical(T) n:<int>; a[1]..a[n]:<int> [T = [PUSH(*, a[i])]i=1..n ]

AUXILIARY FUNCTIONS

divcount: <s2_stack> × <int> <int>

divcount(T, n) (n 0) =

ConditionValue
T = _ 0
T1:<s2_stack>; x:<int> [T = T1.PUSH(*, x) ]
ConditionValue
x mod n 0divcount(T1, n)
x mod n = 0 1 + divcount(T1, n)

(3) SEMANTICS

ACCESS-PROGRAMS

Legality(DIVCOUNT(T, n)) =

ConditionValue
n = 0 %fatal%
n 0%legal%

DIVCOUNT(T, n) = divcount(T, n)

Legality(PUSH((n, T), a)) = %legal%

PUSH((n, T) , a) = T.PUSH(*, a)

Legality(POP((n, T))) =

ConditionValue
T = _ %empty%
T _%legal%

POP((n, T) ) = T1 where T1:<s2_stack>; a:<int> [T = T1.PUSH(*, a) ]

Legality(TOP(T)) =

ConditionValue
T = _ %empty%
T _%legal%

TOP(T) = a where T1:<s2_stack>; a:<int> [T = T1.PUSH(*, a) ]