I have to assert that value val1 >= val2. That is in terms of Model checking, the witness(counterexample) has to assert that the val1 >= val2.
I can do it easily in C (cbmc) by:
C1 = True;
C1 = (C1 && (val1 >= val2));
__CPROVER_assert(!C1 ,"constraint sat");
Is there a way to do that in Python?
Update:
C1 = True
C1 = C1 && (val1 >= val2)
assert not C1
causing
File "python_version.py", line 123, in main
assert not C1
AssertionError
But if I do
C1 = True
C1 = C1 && (val1 >= val2)
assert C1
The result is the reverse of what I want (I want val2 >= val1). Edit:
import math
from random import randint
def main():
C1 = True
z = randint(1,10)
r = randint(1,10)
x = z + 2
y = r + 2
C1 = C1 and (x >= y)
assert C1
print(x)
print(y)
Depending upon the value of z and r chosen, this will break or goes through and prints x , y. So this not working as __CPROVER_assert does, which finds a witness / interpretation that is valid / satisfied !
For example, my three different runs of same code resulted as:
>mokambo 11:16 PM ~/cost-allocation/Constraint_solving python checkPython.py
Traceback (most recent call last):
File "checkPython.py", line 23, in <module>
main()
File "checkPython.py", line 15, in main
assert C1
AssertionError
>mokambo 11:16 PM ~/cost-allocation/Constraint_solving python checkPython.py
7
4
>mokambo 11:16 PM ~/cost-allocation/Constraint_solving python checkPython.py
12
11
Is there any way to check satisfiability of a constraint in Python.