Skip to content

Commit 77cff95

Browse files
committed
docs: reorder statements page
1 parent 219ee90 commit 77cff95

File tree

2 files changed

+98
-39
lines changed

2 files changed

+98
-39
lines changed

website/docs/heyvl/statements.md

Lines changed: 97 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,40 @@ sidebar_position: 2
88
Statements in HeyVL are instructions that are interpreted sequentially and that have side-effects.
99
They are used inside the body of [procedures](./procs.md).
1010

11-
## Semantics
11+
We can categorize HeyVL's statements into either *concrete* or *verification* statements.
12+
We have [concrete statements](#concrete-statements) and [verification statements](#verification-statements).
13+
Concrete statements include [assignments](#assignments), [Boolean choices](#boolean-choices), and [while loops](#while-loops).
14+
15+
The purpose of *verification statements* is to encode either *proof obligations* and *proof assumptions*.
16+
For example, [assert and assume statements](#assert-and-assume) are used to do this.
17+
When you are verifying programs, you ideally do not use these verification statements directly but instead use Caesar's built-in set of [proof rules](../proof-rules/).
18+
They internally use verification statements, but Caesar's proof rules guarantee correct usage so that the proofs are sound.
19+
20+
Below is an overview of HeyVL's statements with links to the respective documentation sections:
21+
22+
| [Concrete Statements](#concrete-statements) | [Verification Statements](#verification-statements) |
23+
|-----------------------|-------------------------|
24+
| [Blocks](#blocks) | [Assert and Assume](#assert-and-assume) |
25+
| [Variable Declarations](#variable-declarations) | [Havoc](#havoc) |
26+
| [Assignments and Procedure Calls](#assignments) | [Reward](#reward) |
27+
| [Boolean Choices](#boolean-choices) | [Nondeterministic Choices](#nondeterministic-choices)|
28+
| [While Loops](#while-loops) | |
29+
30+
There are also some [deprecated verification statements](#deprecated-statements).
31+
32+
33+
## Semantics: The Meaning of HeyVL Programs {#semantics}
1234

1335
Since HeyVL is an intermediate verification language, not all statements allow an operational interpretation of their effects.
1436
All HeyVL statements should be understood through their (quantitative) verification condition semantics.
1537
These are defined in reverse order, starting from an initial verification condition and proceeding from the last statement backwards to the front.
1638
We describe the *formal semantics of HeyVL statements* [in our paper on Caesar (cf. Section 3)](https://arxiv.org/pdf/2309.07781.pdf#page=10).
1739

18-
## Blocks
40+
41+
## Concrete Statements
42+
43+
44+
### Blocks
1945

2046
A block is a sequence of statements enclosed by curly braces.
2147
Statements _may_ be separated by semicolons, but those can be omitted.
@@ -30,33 +56,82 @@ x = 1
3056
y = 1 // y is not declared in this scope
3157
```
3258

33-
## Variable Declarations
3459

35-
A variable declaration `var name: Type` creates a new local variable in the current scope.
60+
### Variable Declarations
61+
62+
A variable declaration creates a new local variable of type `Type` in the current scope:
63+
```heyvl
64+
var name: Type
65+
```
66+
See the [standard library](../stdlib/) for Caesar's built-in types and [domains](./domains.md) for user-defined types.
67+
3668
A variable declaration can be combined with an assignment to initialize the variable:
3769
```heyvl
3870
var forty_two: UInt = 42
3971
```
4072

41-
## Assignments
73+
If a variable is not initialized, the program will be verified *for all* possible values of that variable.
4274

43-
An assignment `x = 39 + y` evaluates the expression on the right-hand side in the current state and assigns the result to the variable on the left-hand side.
75+
### Assignments and Procedure Calls {#assignments}
76+
77+
An assignment evaluates the expression on the right-hand side in the current state and assigns the result to the variable on the left-hand side.
78+
For example:
79+
```heyvl
80+
x = 39 + y
81+
```
82+
The right-hand side must evaluate to a value of a type that can be matches the type of `x`.
83+
84+
The right-hand side of the assignment can be a procedure call.
85+
See the [reference on procedure calls](./procs.md#calling-procedures) for more information.[^calls-concrete]
4486

4587
The left-hand side of an assignment may be a list of variables to unpack a tuple.
4688
For example, imagine a procedure `two_numbers` whose return type is `(x: UInt, y: UInt)`.
4789
The following statement assigns the result of a call to `two_numbers` to `x` and `y`:
4890
```heyvl
4991
x, y = two_numbers()
5092
```
93+
If the procedure does not have any return values, the call may be written without the equals sign and the left-hand side, i.e. simply:
94+
```heyvl
95+
fn(arg1, arg2)
96+
```
5197

52-
If the right-hand side of the assignment is a (pure) expression, then the verification condition semantics amounts to a substitution of the left-hand side by the right-hand side.
5398

54-
The right-hand side of the assignment can be a procedure call.
55-
See the [reference on procedure calls](./procs.md#calling-procedures) for more information.
99+
### Boolean Choices
100+
101+
HeyVL supports a binary choice depending on the value of a Boolean expression:
102+
```heyvl
103+
if x + 1 == 2 {
104+
...
105+
} else {
106+
...
107+
}
108+
```
109+
110+
### While Loops
111+
112+
HeyVL supports while loops that run a block of code while a condition evaluates to true.
113+
```heyvl
114+
var cont: Bool = true
115+
@invariant(...)
116+
while cont {
117+
cont = flip(0.5)
118+
}
119+
```
120+
121+
For verification, **while loops need to have [proof rule annotations](../proof-rules/)** such as the [`@invariant(...)` annotation](../proof-rules/induction.md) in the example.
122+
If a while loop does not have a proof rule annotation, Caesar cannot verify the program and will show an error.
123+
124+
The proof rule annotations also implicitly specify whether the loop has least or greatest fixpoint semantics.
125+
This choice can be made explicit with the [calculus annotations](../proof-rules/calculi.md) on procedures, which we recommend you use.
126+
127+
With the **[model checking translation](../model-checking.md), proof rule annotations are not necessary**.
128+
It allows usage of a *probabilistic model checker* such as [Storm](https://www.stormchecker.org/) for a subset of HeyVL programs.
129+
This can be helpful to e.g. get an initial estimation of expected values.
56130

57-
If the procedure does not have any return values, the call may be written without the equals sign and the left-hand side, i.e. simply `fn(arg1, arg2)`.
131+
## Verification Statements
58132

59-
## Havoc
133+
134+
### Havoc
60135

61136
A `havoc` statement can be used to "forget" previous values of variables in the following code.
62137
It also comes in a `co` variant.
@@ -67,7 +142,8 @@ cohavoc a, b, c
67142

68143
The verification condition semantics of `havoc` and `cohavoc` create an infimum respectively supremum over the specified variables.
69144

70-
## Assert and Assume
145+
146+
### Assert and Assume
71147

72148
These statements generate binary operators in the verification condition semantics.
73149
All three statements also come in `co` variants.
@@ -79,7 +155,8 @@ assert 1 + x
79155
assume 0
80156
```
81157

82-
## Reward (formerly Tick)
158+
159+
### Reward
83160

84161
The `reward` statement accepts an expression and adds it to the current verification condition.
85162
For example,
@@ -90,7 +167,8 @@ has the following semantics: `vc[reward 2 * x](f) = f + (2 * x)`.
90167

91168
`tick` is another name that Caesar accepts for `reward`.
92169

93-
## Nondeterministic Choices
170+
171+
### Nondeterministic Choices
94172

95173
HeyVL supports two kinds of binary nondeterministic choices: The "demonic" one (`if ⊓`) and the "angelic" one (`if ⊔`).
96174
```heyvl
@@ -105,30 +183,6 @@ You can also use Latex-style syntax instead of Unicode.
105183
Caesar supports `\cap` and `\cup` instead of `` and ``, respectively.
106184
(We're looking for better syntax for these statements. If you have an idea, [please start a discussion](https://github.com/moves-rwth/caesar/discussions).)
107185

108-
## Boolean Choices
109-
110-
HeyVL supports a binary choice depending on the value of a Boolean expression:
111-
```heyvl
112-
if x + 1 == 2 {
113-
...
114-
} else {
115-
...
116-
}
117-
```
118-
119-
## While Loops
120-
121-
HeyVL supports while loops that run a block of code while a condition evaluates to true.
122-
```heyvl
123-
var cont: Bool = true
124-
while cont {
125-
cont = flip(0.5)
126-
}
127-
```
128-
129-
However, for verification while loops need to be annotated with [proof rules](../proof-rules/), otherwise Caesar will show an error.
130-
These proof rule annotations also implicitly specify whether the loop has least or greatest fixpoint semantics.
131-
This choice can be made explicit with the [calculus annotations](../proof-rules/calculi.md) on procedures, which we recommend you use.
132186

133187
## Deprecated Statements
134188

@@ -162,3 +216,8 @@ If negations are used in such a way that monotonicity is broken, then (co)proced
162216
Refer to our [OOPSLA '23 paper](../publications.md#oopsla-23) for details on monotonicity and soundness of (co)procedure calls.
163217

164218
:::
219+
220+
221+
[^calls-concrete]: Note that a procedure does not necessarily need to have a body.
222+
Caesar will verify calls only based on their specification.
223+
In those cases, a procedure call is thus not concrete.

website/docs/model-checking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ In the body, statements:
254254
* [Sampling from distributions](./stdlib/distributions.md),
255255
* [If-then-else statements](./heyvl/statements.md#boolean-choices),
256256
* While loops (with least-fixed point semantics — [see below for semantics details](#loop-semantics)),
257-
* [`reward` statements](./heyvl/statements.md#reward-formerly-tick),
257+
* [`reward` statements](./heyvl/statements.md#reward),
258258
* In `proc`s:
259259
* [`assert` statements](./heyvl/statements.md#assert-and-assume),
260260
* [Binary demonic choices](./heyvl/statements.md#nondeterministic-choices),

0 commit comments

Comments
 (0)