You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR add support for quantifiers. Especially, we inline function
calls in quantified expressions so that the result statement-expression
can be accepted by the CBMC backend.
RFC: [RFC
0010-quantifiers](https://github.com/model-checking/kani/blob/main/rfc/src/rfcs/0010-quantifiers.md).
Resolves#2546 and
#836.
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
---------
Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
Co-authored-by: Felipe R. Monteiro <felisous@amazon.com>
Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
Quantifiers are a powerful feature in formal verification that allow you to express properties over a range of values. Kani provides experimental support for quantifiers, enabling users to write concise and expressive specifications for their programs.
4
+
5
+
## Supported Quantifiers
6
+
7
+
Kani currently supports the following quantifiers:
8
+
9
+
1.**Universal Quantifier**:
10
+
- Ensures that a property holds for all values in a given range.
11
+
- Syntax: `kani::forall!(|variable in range| condition)`
12
+
- Example:
13
+
14
+
```rust
15
+
#[kani::proof]
16
+
fntest_forall() {
17
+
letv=vec![10; 10];
18
+
kani::assert(kani::forall!(|iin0..10|v[i] ==10));
19
+
}
20
+
```
21
+
22
+
2.**Existential Quantifier**:
23
+
- Ensures that there exists at least one value in a given range for which a property holds.
24
+
- Syntax: `kani::exists!(|variable in range| condition)`
The performance of quantifiers can be affected by the depth of call stacks in the quantified expressions. If the call stack is too deep, Kani may not be able to evaluate the quantifier effectively, leading to potential timeouts or running out of memory. Actually, array indexing in Rust leads to a deep call stack, which can cause issues with quantifiers. To mitigate this, consider using *unsafe* pointer dereferencing instead of array indexing when working with quantifiers. For example:
We now assume that all quantified variables are of type `usize`. This means that the range specified in the quantifier must be compatible with `usize`.
56
+
We plan to support other types in the future, but for now, ensure that your quantifiers use `usize` ranges.
0 commit comments