Skip to content
Draft
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
8 changes: 8 additions & 0 deletions bench-multiplication/assoc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef BW
#define BW 9
#endif
int main() {
__CPROVER_bitvector[BW] a, b, c;
__CPROVER_bitvector[BW] ab = a * b, bc = b * c;
__CPROVER_assert(ab * c == a * bc, "associativity");
}
8 changes: 8 additions & 0 deletions bench-multiplication/comm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef BW
#define BW 9
#endif
int main() {
__CPROVER_bitvector[BW] a, b;
__CPROVER_bitvector[BW] c = a * b, d = b * a;
__CPROVER_assert(c == d, "commutativity");
}
7 changes: 7 additions & 0 deletions bench-multiplication/const3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef BW
#define BW 9
#endif
int main() {
__CPROVER_bitvector[BW] a;
__CPROVER_assert(a * 3 == a + a + a, "multiply by 3");
}
8 changes: 8 additions & 0 deletions bench-multiplication/distrib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef BW
#define BW 9
#endif
int main() {
__CPROVER_bitvector[BW] a, b, c;
__CPROVER_bitvector[BW] lhs = a * (b + c), rhs = a * b + a * c;
__CPROVER_assert(lhs == rhs, "distributivity");
}
8 changes: 8 additions & 0 deletions bench-multiplication/factor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef BW
#define BW 9
#endif
int main() {
__CPROVER_bitvector[BW] p, q;
__CPROVER_assume(p > 1 && q > 1);
__CPROVER_assert(p * q != 143, "not factorable");
}
9 changes: 9 additions & 0 deletions bench-multiplication/mul_bounds.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef BW
#define BW 16
#endif
int main() {
__CPROVER_bitvector[BW/2] a, b;
__CPROVER_bitvector[BW] wide = (__CPROVER_bitvector[BW])a * (__CPROVER_bitvector[BW])b;
__CPROVER_bitvector[BW*2] wider = (__CPROVER_bitvector[BW*2])a * (__CPROVER_bitvector[BW*2])b;
__CPROVER_assert(wide == (__CPROVER_bitvector[BW])wider, "no overflow");
}
8 changes: 8 additions & 0 deletions bench-multiplication/mul_double.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef BW
#define BW 16
#endif
int main() {
__CPROVER_bitvector[BW] a, b;
__CPROVER_bitvector[BW/2] a_lo = a, b_lo = b, prod_lo = a * b;
__CPROVER_assert(prod_lo == (__CPROVER_bitvector[BW/2])(a_lo * b_lo), "low half");
}
7 changes: 7 additions & 0 deletions bench-multiplication/mul_negation.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef BW
#define BW 16
#endif
int main() {
__CPROVER_bitvector[BW] a;
__CPROVER_assert(a * (__CPROVER_bitvector[BW])(-1) == -a, "mul by -1");
}
9 changes: 9 additions & 0 deletions bench-multiplication/mul_overflow.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef BW
#define BW 16
#endif
int main() {
__CPROVER_bitvector[BW] a, b;
__CPROVER_bitvector[BW*2] wide = (__CPROVER_bitvector[BW*2])a * (__CPROVER_bitvector[BW*2])b;
__CPROVER_bitvector[BW] narrow = a * b;
__CPROVER_assert(narrow == (__CPROVER_bitvector[BW])wide, "truncated matches wide");
}
8 changes: 8 additions & 0 deletions bench-multiplication/mul_shift.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef BW
#define BW 16
#endif
int main() {
__CPROVER_bitvector[BW] a;
__CPROVER_assert(a * 4 == a << 2, "mul4 == shl2");
__CPROVER_assert(a * 8 == a << 3, "mul8 == shl3");
}
8 changes: 8 additions & 0 deletions bench-multiplication/mul_square_nonneg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef BW
#define BW 9
#endif
int main() {
__CPROVER_bitvector[BW] a;
__CPROVER_bitvector[BW*2] wide = (__CPROVER_bitvector[BW*2])a * (__CPROVER_bitvector[BW*2])a;
__CPROVER_assert(wide >= a, "square >= original");
}
11 changes: 11 additions & 0 deletions bench-multiplication/mul_zero_factor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef BW
#define BW 8
#endif
int main() {
__CPROVER_bitvector[BW] a, b, r;
r = a * b;
__CPROVER_assume(r == 0);
__CPROVER_assume(a != 0);
__CPROVER_assume(b != 0);
__CPROVER_assert(0, "found zero divisors");
}
7 changes: 7 additions & 0 deletions bench-multiplication/smt-comp/assoc_8.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(set-logic QF_BV)
(declare-fun a () (_ BitVec 8))
(declare-fun b () (_ BitVec 8))
(declare-fun c () (_ BitVec 8))
(assert (not (= (bvmul (bvmul a b) c) (bvmul a (bvmul b c)))))
(check-sat)
(exit)
6 changes: 6 additions & 0 deletions bench-multiplication/smt-comp/comm_16.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(set-logic QF_BV)
(declare-fun a () (_ BitVec 16))
(declare-fun b () (_ BitVec 16))
(assert (not (= (bvmul a b) (bvmul b a))))
(check-sat)
(exit)
6 changes: 6 additions & 0 deletions bench-multiplication/smt-comp/comm_32.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(set-logic QF_BV)
(declare-fun a () (_ BitVec 32))
(declare-fun b () (_ BitVec 32))
(assert (not (= (bvmul a b) (bvmul b a))))
(check-sat)
(exit)
6 changes: 6 additions & 0 deletions bench-multiplication/smt-comp/comm_8.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(set-logic QF_BV)
(declare-fun a () (_ BitVec 8))
(declare-fun b () (_ BitVec 8))
(assert (not (= (bvmul a b) (bvmul b a))))
(check-sat)
(exit)
7 changes: 7 additions & 0 deletions bench-multiplication/smt-comp/distrib_16.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(set-logic QF_BV)
(declare-fun a () (_ BitVec 16))
(declare-fun b () (_ BitVec 16))
(declare-fun c () (_ BitVec 16))
(assert (not (= (bvmul a (bvadd b c)) (bvadd (bvmul a b) (bvmul a c)))))
(check-sat)
(exit)
7 changes: 7 additions & 0 deletions bench-multiplication/smt-comp/distrib_8.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(set-logic QF_BV)
(declare-fun a () (_ BitVec 8))
(declare-fun b () (_ BitVec 8))
(declare-fun c () (_ BitVec 8))
(assert (not (= (bvmul a (bvadd b c)) (bvadd (bvmul a b) (bvmul a c)))))
(check-sat)
(exit)
8 changes: 8 additions & 0 deletions bench-multiplication/smt-comp/factor_12.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(set-logic QF_BV)
(declare-fun p () (_ BitVec 12))
(declare-fun q () (_ BitVec 12))
(assert (bvugt p (_ bv1 12)))
(assert (bvugt q (_ bv1 12)))
(assert (= (bvmul p q) (_ bv143 12)))
(check-sat)
(exit)
8 changes: 8 additions & 0 deletions bench-multiplication/smt-comp/factor_16.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(set-logic QF_BV)
(declare-fun p () (_ BitVec 16))
(declare-fun q () (_ BitVec 16))
(assert (bvugt p (_ bv1 16)))
(assert (bvugt q (_ bv1 16)))
(assert (= (bvmul p q) (_ bv10403 16)))
(check-sat)
(exit)
8 changes: 8 additions & 0 deletions bench-multiplication/smt-comp/factor_20.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(set-logic QF_BV)
(declare-fun p () (_ BitVec 20))
(declare-fun q () (_ BitVec 20))
(assert (bvugt p (_ bv1 20)))
(assert (bvugt q (_ bv1 20)))
(assert (= (bvmul p q) (_ bv101101 20)))
(check-sat)
(exit)
9 changes: 9 additions & 0 deletions bench-multiplication/smt-comp/mixed_arith_8.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(set-logic QF_BV)
(declare-fun a () (_ BitVec 8))
(declare-fun b () (_ BitVec 8))
(declare-fun c () (_ BitVec 8))
(declare-fun d () (_ BitVec 8))
(assert (not (= (bvadd (bvmul a b) (bvmul c d))
(bvsub (bvsub (bvmul (bvadd a c) (bvadd b d)) (bvmul a d)) (bvmul c b)))))
(check-sat)
(exit)
11 changes: 11 additions & 0 deletions bench-multiplication/smt-comp/mul_no_overflow_16.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(set-logic QF_BV)
(declare-fun a () (_ BitVec 16))
(declare-fun b () (_ BitVec 16))
(declare-fun r () (_ BitVec 16))
(assert (= r (bvmul a b)))
; Check: if a != 0 then r/a == b (no overflow case)
(assert (not (= a (_ bv0 16))))
(assert (not (= (bvudiv r a) b)))
; This is SAT when overflow occurs
(check-sat)
(exit)
9 changes: 9 additions & 0 deletions bench-multiplication/square.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef BW
#define BW 9
#endif
int main() {
__CPROVER_bitvector[BW] a, b, s = a + b;
__CPROVER_bitvector[BW] lhs = s * s;
__CPROVER_bitvector[BW] rhs = a*a + (__CPROVER_bitvector[BW])2*a*b + b*b;
__CPROVER_assert(lhs == rhs, "square identity");
}
Loading
Loading