exercise2.smt2 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ; declare constants as 64-bit vectors
  2. (declare-const l (_ BitVec 64))
  3. (declare-const h (_ BitVec 64))
  4. (declare-const m (_ BitVec 64))
  5. ;(echo "does (m = (l + h) / 2) and (0 <= l <= h) imply (l <= m <= h)?")
  6. ; declare our conjecture we want to check
  7. (define-fun conjecture () Bool
  8. (=> (and (bvsle #x0000000000000000 l) (bvsle l h))
  9. (and (bvsle l m) (bvsle m h))))
  10. ; constrain the values of m
  11. ; (l + h) / 2 = (l + h) >> 2
  12. (assert (= m (bvsdiv (bvadd l h) #x0000000000000002)))
  13. ; we assert the negation of our conjecture
  14. ; if the result is sat, then a model that is a counterexample will be yielded
  15. (assert (not conjecture))
  16. ;(echo "counterexample in the theory of 64-bitvectors: sat")
  17. ; we expect satisfiability
  18. (check-sat)
  19. ;(get-model)
  20. (reset)
  21. ; declaring integers this time
  22. (declare-const l Int)
  23. (declare-const h Int)
  24. (declare-const m Int)
  25. ; same as above
  26. (define-fun conjecture () Bool
  27. (=> (and (<= 0 l) (<= l h))
  28. (and (<= l m) (<= m h))))
  29. ; constrain the values of m
  30. (assert (= m (div (+ l h) 2)))
  31. ; again we assert the negation
  32. (assert (not conjecture))
  33. ; this time we expect *unsatisfiability*
  34. (check-sat)
  35. (reset)
  36. ; repeat of 1 but with different premise
  37. (declare-const l (_ BitVec 64))
  38. (declare-const h (_ BitVec 64))
  39. (declare-const m (_ BitVec 64))
  40. (define-fun conjecture () Bool
  41. (=> (and (bvsle #x0000000000000000 l) (bvsle l h))
  42. (and (bvsle l m) (bvsle m h))))
  43. ; constrain the values of m
  44. ; l + ((h - l) / 2) = l + ((h - l) >> 2)
  45. (assert (= m (bvadd l (bvsdiv (bvsub h l) #x0000000000000002))))
  46. (assert (not conjecture))
  47. ; we expect *unsatisfiability*
  48. (check-sat)