Skip to content

Commit fe754e0

Browse files
committed
Add simple algebraic equations (identities) as tests.
These are expected to exercise that implements conversion of arithmetic operators for signed ints, including integers of multiple bit widths (using `long long` and `char` for now, because `stdint.h` introduces typecasts and we don't support them yet).
1 parent 0f95852 commit fe754e0

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <stdlib.h>
2+
3+
int main()
4+
{
5+
int a;
6+
__CPROVER_assume(a < 100);
7+
__CPROVER_assume(a > -100);
8+
__CPROVER_assume(a != 0);
9+
10+
// Simple algebraic identities - expected to drive the SMT backend
11+
__CPROVER_assert(a + a == a * 2, "a plus a always equals two times a");
12+
__CPROVER_assert(a - a == 0, "a minus a always equals 0");
13+
__CPROVER_assert(a + -a == 0, "a plus its additive inverse equals 0");
14+
__CPROVER_assert(
15+
a - -a == 2 * a, "a minus its additive inverse equals two times a");
16+
__CPROVER_assert((a * a) / a == a, "a squared divided by a equals a");
17+
__CPROVER_assert((2 * a) / a == 2, "two times a divided by a equals two");
18+
__CPROVER_assert(a % a == 0, "a mod itself equals 0");
19+
20+
// Same round of tests, but for a type of different size
21+
long long int b;
22+
__CPROVER_assume(b < 100ll);
23+
__CPROVER_assume(b > -100ll);
24+
__CPROVER_assume(b != 0ll);
25+
26+
__CPROVER_assert(b + b == b * 2ll, "b plus b always equals two times b");
27+
__CPROVER_assert(b - b == 0ll, "b minus b always equals 0");
28+
__CPROVER_assert(b + -b == 0ll, "b plus its additive inverse equals 0");
29+
__CPROVER_assert(
30+
b - -b == 2ll * b, "b minus its additive inverse equals two times b");
31+
__CPROVER_assert((b * b) / b == b, "b squared divided by b equals b");
32+
__CPROVER_assert((2ll * b) / b == 2ll, "two times b divided by b equals two");
33+
__CPROVER_assert(b % b == 0ll, "b mod itself equals 0");
34+
35+
char c = 0x0;
36+
__CPROVER_assume(c != 0x00);
37+
38+
__CPROVER_assert(c + c == c * 0x2, "c plus c always equals two times c");
39+
__CPROVER_assert(c - c == 0x0, "c minus c always equals 0");
40+
__CPROVER_assert(c + -c == 0x0, "c plus its additive inverse equals 0");
41+
__CPROVER_assert(
42+
c - -c == 0x2 * c, "c minus its additive inverse equals two times c");
43+
__CPROVER_assert((c * c) / c == c, "c squared divided by c equals c");
44+
__CPROVER_assert((0x2 * c) / c == 0x2, "two times c divided by c equals two");
45+
__CPROVER_assert(c % c == 0x0, "c mod itself equals 0");
46+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
CORE
2+
simple_equation.c
3+
--incremental-smt2-solver 'z3 --smt2 -in' --trace
4+
\[main\.assertion\.1\] line \d+ a plus a always equals two times a: SUCCESS
5+
\[main\.assertion\.2\] line \d+ a minus a always equals 0: SUCCESS
6+
\[main\.assertion\.3\] line \d+ a plus its additive inverse equals 0: SUCCESS
7+
\[main\.assertion\.4\] line \d+ a minus its additive inverse equals two times a: SUCCESS
8+
\[main\.assertion\.5\] line \d+ a squared divided by a equals a: SUCCESS
9+
\[main\.assertion\.6\] line \d+ two times a divided by a equals two: SUCCESS
10+
\[main\.assertion\.7\] line \d+ a mod itself equals 0: SUCCESS
11+
\[main\.assertion\.8\] line \d+ b plus b always equals two times b: SUCCESS
12+
\[main\.assertion\.9\] line \d+ b minus b always equals 0: SUCCESS
13+
\[main\.assertion\.10\] line \d+ b plus its additive inverse equals 0: SUCCESS
14+
\[main\.assertion\.11\] line \d+ b minus its additive inverse equals two times b: SUCCESS
15+
\[main\.assertion\.12\] line \d+ b squared divided by b equals b: SUCCESS
16+
\[main\.assertion\.13\] line \d+ two times b divided by b equals two: SUCCESS
17+
\[main\.assertion\.14\] line \d+ b mod itself equals 0: SUCCESS
18+
\[main\.assertion\.15\] line \d+ c plus c always equals two times c: SUCCESS
19+
\[main\.assertion\.16\] line \d+ c minus c always equals 0: SUCCESS
20+
\[main\.assertion\.17\] line \d+ c plus its additive inverse equals 0: SUCCESS
21+
\[main\.assertion\.18\] line \d+ c minus its additive inverse equals two times c: SUCCESS
22+
\[main\.assertion\.19\] line \d+ c squared divided by c equals c: SUCCESS
23+
\[main\.assertion\.20\] line \d+ two times c divided by c equals two: SUCCESS
24+
\[main\.assertion\.21\] line \d+ c mod itself equals 0: SUCCESS
25+
^VERIFICATION SUCCESSFUL$
26+
^EXIT=0$
27+
^SIGNAL=0$
28+
--
29+
--
30+
This is a simple test that's trying to verify that some simple algebraic
31+
identities hold for all values insider an integral interval. This is expected
32+
to work as an end-to-end example driving the all of the conversion function
33+
for bitvector arithmetic in the new SMT backend, getting us to the point of
34+
a full verification run producing a result.

0 commit comments

Comments
 (0)