PGA - ProGram Algebra

# Combining Programs and State Machines

## Basic instruction set

A basic instruction sets that supports interactions with state machines is FMN (Focus Method Notation).

### Instructions

`f.a(x)`
Here, `f` is the focus of the instruction, and `a(x)` its co-instruction part (or co-action). The bracket pair can be empty. A focus is loaded the first time it is used.
It returns the value replied by the co-instruction.
`f.p:a(x)`
Here, `p` is the prefix of the action that will be performed, indicating a particular copy of the state machine. A copy of the state machines is created the first time the prefix is used.
It returns the value replied by the co-instruction.
Alternative versions of the above instructions:
`f.a:x`
`f:i.a:x`
Here, `i` is the instance of the method.

## Available state machines

• Console
Co-actions: `println(s)` in which `s` is a string of characters.
The action `println` prints its argument.
• smbr - boolean register
Co-actions: `set(true)`, `set(false)`, `eq(true)`, `eq(false)`
The co-actions `set(true)` and `set(false)` reply `true`. The co-actions `eq(true)` and `eq(false)` reply `false` until the register is set, after which `eq(b)` replies `true` whenever `b` is the current value of the register, and `false` otherwise.
• smnnr - natural number register
Co-actions: `set(i)`, `eq(i)` in which `i` is a natural number
The replies of the co-actions are simular to that of smbr.
• smnnc - natural number counter
Co-actions: `succ()`, `pred()`, `isZero()`
The counter always starts with value zero, and the action `pred()` leaves the counter at zero if it is zero.
• smnns - natural number stack
Co-action: `push(i)`, `pop()`, `topEq(i)` in which `i` is a natural number.
The stack always starts empty, and the action `pop()` leaves the empty stack empty.

## Examples

• Consider the following PGLEc program.
```smbr.x:set(true);
smbr.y:set(false);
+ smbr.x:eq(true) {;
Console.println(x is true);
}{;
Console.println(x is false);
};
+ smbr.y:eq(true) {;
Console.println(y is true);
}{;
Console.println(y is false);
}
```

Upon execution the result will be:

```x is true
y is false
```

• Fibonacci numbers