Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an FAQ about array theory in CBMC #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* [How does malloc work?](faq/malloc.md)
* [How do I write a good stub?]()
* [What do I do when CBMC won't stop?](faq/termination.md)

* [Advanced Questions](advanced-questions/README.md)
* [Does CBMC have any support for using array-theory?](advanced-questions/array-theory.md)

* [CBMC project management](management/README.md)
* [Project planning](management/Plan-your-proof.md)
Expand All @@ -37,4 +40,4 @@

* [CBMC projects](projects.md)

* [CBMC resources](resources.md)
* [CBMC resources](resources.md)
8 changes: 8 additions & 0 deletions docs/src/advanced-questions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Advanced Questions (Infrequently asked questions)

Here are answers to some questions asked by advanced CBMC users.
Please send us any questions you have by
[filing an issue with us](https://github.com/model-checking/cbmc-training/issues)
on GitHub.

* [Does CBMC have any support for using array-theory?](array-theory.md)
20 changes: 20 additions & 0 deletions docs/src/advanced-questions/array-theory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Does CBMC have any support for using array theory?
[Article Date: Aug 10, 2022]

CBMC provides support for reasoning about arrays using array theory. (Note that we are still working with a SAT back-end here, and this does not use an SMT solver)
A fixed length array uses CBMC's typical bit-vector representation of an array, but a variable length array uses CBMC's array theory.
To activate CBMC's array-theory for fixed length arrays, use the following workaround.

```
unsigned long size; // non deterministically pick the size
ArrayElement *a = malloc(size * sizeof(ArrayElement));
__CPROVER_assume(size == MAX_SIZE); // fix the size to a constant after the allocation
```
[See https://github.com/diffblue/cbmc/issues/7012 to read more about the workaround and track the fix]

## Performance impact of using CBMC's array theory feature.

CBMC’s array theory generates a number of constraints that is quadratic in the number of accesses to an array, and could be slower in cases with large number of accesses (worse for write accesses). However, unlike the bit-vector encoding, the number of constraints is not dependent on the size of the array itself.

Hence, array theory is better when you have a small number of accesses with non-constant index into a very large array. An example of this is when you want to reason about a single insertion of an element at a non-constant index in a large array.