When the semantics of a block of code are different
depending on runtime conditions, we use a *compound intended function*. This is
basically an if-then-else structure on top of a set of
simple intended functions.

Formally:

- simple intended function
A list of state changes that happen simultaneously. Each state change is an ordered pair

*(v*where_{i}, e_{i})*v*is some state item that changes in the prime, and_{i}*e*is a description of the new value._{i}- compound intended function
A compound intended function is a set of simple intended functions

*S*, and a set of one or more conditions_{0}, S_{1}, …*C*that select one of the intended functions._{0}, C_{1}, …

Conceptually, the execution of a prime with a compound intended function proceeds in two steps:

The conditions are examined to see which simple intended function applies in this case.

The state changes for the selected simple intended function occur simultaneously.

Here is the general form as it might appear in the code:

# [ if-> #`C`

_{0}# else if`S`

_{0}-> #`C`

_{1}# else if ... # ... # else -> #`S`

_{1}]`S`

_{n}

Each

is a description of some
condition, and each `C`

_{i}

is a simple
intended function.
`S`

_{i}

The relationship between the conditions and the simple intended functions can be expressed as a truth table. Here is an abstract example:

# [ if C0 -> # S0 # else if C1 -> # S1 # else -> # S2 ]

Here is a presentation of that case structure as a truth table.

`C0` | `C1` | Case |
---|---|---|

`T` | `T` | `S0` |

`T` | `F` | `S0` |

`F` | `T` | `S1` |

`F` | `F` | `S2` |

Note that two lines of the above truth table have the
same simple intended function. Using the convention from
digital logic that “`X`

” means
“don't care”, the above truth table can be
reduced to three rows:

`C0` | `C1` | Case |
---|---|---|

`T` | `X` | `S0` |

`F` | `T` | `S1` |

`F` | `F` | `S2` |

Here is a concrete example: an intended function for a call to
Python's `str.isdigit()`

method.

# [ if (s has at least one character) and # (all of s's characters are digits) -> # digitCheck := True # else -> # digitCheck := False ] digitCheck = s.isdigit()

In more complex cases, if you prefer, you may nest
“`if`

” and “`else`

” clauses. However, be sure that you
have covered all possible cases. Any case that is not
covered is undefined, but this is not good practice;
better practice is to use preconditions to insure that
all cases are covered. A truth table is a good way to be
sure you have considered all the edge cases.