In this section, we will explain assertions and invariants in Cyclone so that you can use them wisely for specifying the conditions you want.
An assertion in Cyclone specifies a content condition. A content condition is different from a path condition (covered in Chapter 1). A path condition specifies how Cyclone searches for ideal solution based on specific path constraints while a content condition tells how Cyclone explores search space based on specific computation instructions (code). Both path and content conditions can be used together in the goal section. Combining both path and content conditions can be particularly useful in many scenarios.
For example, the following code tells Cyclone to search for a path (upto length=10) such that when it reaches either node (state) S or T, x must be greater or equal to y. In the meanwhile, this path must contain node (state) S exactly twice.
assert x>=y;
check upto 10 condition (S^{2}) reach (S,T)
S^{2} is a path condition and x>=y is a content condition. In this case, Cyclone must find a path that satisfies both conditions.
An assertion has four forms in Cyclone and users can choose any one of them to use.
Let φ be our property or condition to be checked, we can have following four forms of assertion in Cyclone.
This type of assertions can help you to discover whether your model has a path that leads to the condition φ.
Note that you may specify a list of states with in clause. When there are multiple states specified, then φ only needs to satisfied in any one of them. This type of assertions is particularly useful when you only want to restrict your property for a subset of states.
φ may be satisfied in any of the states along the path. Note this is different from our first form of assertion. In the first form of assertion, φ only needs to be satisfied in the last state of a path. Here with modifier some, φ could be satisfied in any of the states in the path and this may include the last state in path. Thus, this form of assertion is useful for checking whether your model can satisfy your property φ in some paths.
This form of assertion is useful for finding whether your model contains a path that can make a property (φ) always hold.
An invariant in Cyclone specifies something that should always hold. For example, a loop invariant can be specified using an invariant in Cyclone. If a Cyclone specification contains an invariant, then Cyclone will try to find a counter-example that can break the invariant. This is useful for proving validity of your model by finding no counter-examples.
In order to use invariant correctly, there a few rules we need to mention here. First, an invariant in Cyclone only requires to be hold before entering and leaving a state. Consider the following example,
normal state S {
x=-1;
x=y+a;
}
invariant A { x>=0;}
invariant A requires variable x to be greater or equal to 0 in every state. Obviously, in state S our invariant A seems to be broken because x is first assigned to -1, then gets reassigned y+a. However, an invariant in Cyclone is allowed to be violated in a state as long as it holds before and leaving this state. Thus, as long as our invariant A here holds before entering state S and after executing x=y+a, Cyclone will not consider this invariant is violated.
However, the following example will break our invariant A.
normal state S {
x=y+a;
x=-1;
}
invariant A { x>=0;}
Second, Cyclone also allows an invariant to be violated before entering the starting state. However, an invariant must be established when leaving the starting state. Consider the following example,
int x=-1;
normal start state S {
x=0;
}
invariant A { x>=0;}
int x=0;
normal start state S {
x=-1;
}
invariant A { x>=0;}
There are two forms of invariants a user can use in Cyclone. Let φ again be our property or condition to be met.
@2020-2022 Hao Wu. All rights reserved. Last update: August 17, 2022