-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathz3Interface.py
More file actions
101 lines (88 loc) · 2.55 KB
/
z3Interface.py
File metadata and controls
101 lines (88 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from z3 import *
class z3BaseOracle:
class AvailableFunctions:
MapMinus1 = 0
MapPlus1 = 1
MapMult2 = 2
MapMult3 = 3
MapMult4 = 4
MapMultNeg1 = 5
Reverse = 6
Sort = 7
FilterLessZero = 8
FilterGreaterZero = 9
CountLessZero = 10
CountGreaterZero = 11
ZipPlus = 12
ZipMinus = 13
ZipMin = 14
ZipMax = 15
Take = 16
Drop = 17
Access = 18
Head = 19
Last = 20
Sum = 21
Minimum = 22
Maximum = 23
ScanPlus = 24
ScanMinus = 25
ScanMin = 26
ScanMax = 27
MapDiv2 = 28
MapDiv3 = 29
MapDiv4 = 30
MapSquare = 31
FilterEven = 32
FilterOdd = 33
CountEven = 34
CountOdd = 35
ZipMult = 36
ScanMult = 37
def __init__(self):
pass
def setTimeout(self, timeoutms):
self.solver.set("timeout", timeoutms)
def bound_int(self, intvar, lw=-255, ub=255):
# Returns a constraint bounding the domain of intvar
return And(intvar <= ub, intvar >= lw)
def bound_intvector(self, intvectorvar, lw=-255, ub=255):
# Returns a constraint bounding the domain of each entry of intvectorvar
cons = []
for i in range(len(intvectorvar)):
cons.append(self.bound_int(intvectorvar[i], lw, ub))
return And(*cons)
def BitVectorVector(self, name, len, bv_len=32):
return [BitVec('{}__{}'.format(name, i), bv_len) for i in range(len)]
def getElement(self, outputItem, inputList, element):
conditions = []
for val in range(self.max_list_length):
conditions.append(Implies(element == val, outputItem == inputList[val]))
return And(*conditions)
def beginAddConstraints(self):
s = self.solver
s.push()
return self
def removeAddedConstraints(self):
s = self.solver
s.pop()
return self
def prepareDataTypesEnum(self):
self.VarTypes = self.VarTypesClass()
def checkSat(self):
if self.solver.check() == unsat:
return -1
if self.solver.check() == sat:
return 1
return 0
def evalSatAndUpdateModel(self):
s = self.solver
self.isSat = s.check()
if self.isSat == sat:
self.currModel = s.model()
return self
class VarTypesClass:
def __init__(self):
self.Int = 0
self.List = 1
self.NoneType = 2