learning_tla/lamport_video/docs/lecture07.md
2025-02-12 18:19:37 +01:00

39 lines
873 B
Markdown

# 7. Paxos
## CHOOSE
`CHOOSE x \in S: P` selects one particular value
in S such that P holds.
Example: how to write a maximum function:
```tla+ code fragment
Maximum(S) ==
IF S = {}
THEN -1
ELSE CHOOSE n \in S: \A m \in S: n >= m
```
![maximum.png](lecture07_maximum.png)
Elements of a `SYMMETRY` set can not appear in a `CHOOSE`
expression.
## Set constructors
- `{ v \in S: P }` the set of all `v` in `S` for which `P` holds
- `{e: v \in S}` the set of `e` for all `v` in `S`
- Example: `{ n^2: n \in Nat }`: the set of squares of all natural numbers
## `EXCEPT` drilling
```tla+ code fragment
[aState EXCEPT ![m.ins][acc].mbal = m.bal]
\* means
[aState EXCEPT ![m.ins] =
[aState[m.int] EXCEPT ![acc] =
[aState[m.ins][acc] EXCEPT !.mbal = m.bal]
]
]
\* just like this programming statement:
\* aState[m.ins][acc].mbal = mbal
```