-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprofiling_programs.py
More file actions
276 lines (253 loc) · 7.88 KB
/
profiling_programs.py
File metadata and controls
276 lines (253 loc) · 7.88 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
from constants import BV_LENGTH
from z3 import *
from program import Program
from program_synthesis import ProgramSynthesis
import bit_vector_tests as BVT
def P15():
p = Program(num_prog_inputs=2)
p.create_add_component()
p.create_and_component()
p.create_xor_component()
p.create_bitshiftright_component(1)
return ProgramSynthesis(p, BVT.P15, 'P15')
def P16():
p = Program(num_prog_inputs=2)
p.create_xor_component()
p.create_xor_component()
p.create_negate_component()
p.create_and_component()
p.create_ule_component()
return ProgramSynthesis(p, BVT.P16, 'P16')
def P6():
p = Program()
p.create_increment_component()
p.create_and_component()
p.create_or_component()
p.create_not_component()
p.create_add_component()
p.create_xor_component()
return ProgramSynthesis(p, BVT.P6, 'P6')
def P7():
p = Program()
p.create_increment_component()
p.create_and_component()
p.create_or_component()
p.create_not_component()
p.create_add_component()
p.create_xor_component()
return ProgramSynthesis(p, BVT.P7, 'P7')
def P8_divide():
p = Program()
p.create_decrement_component()
p.create_not_component()
p.create_and_component()
p.create_divide_component()
p.create_divide_component()
p.create_divide_component()
return ProgramSynthesis(p, BVT.P8, 'P8 Divide')
def P8_increment():
p = Program()
p.create_decrement_component()
p.create_not_component()
p.create_and_component()
p.create_increment_component()
p.create_increment_component()
p.create_increment_component()
return ProgramSynthesis(p, BVT.P8, 'P8 Increment')
def P8_xor():
p = Program()
p.create_decrement_component()
p.create_not_component()
p.create_and_component()
p.create_xor_component()
p.create_xor_component()
p.create_xor_component()
return ProgramSynthesis(p, BVT.P8, 'P8 Xor')
def P8_decrement():
p = Program()
p.create_decrement_component()
p.create_not_component()
p.create_and_component()
p.create_decrement_component()
p.create_decrement_component()
p.create_decrement_component()
return ProgramSynthesis(p, BVT.P8, 'P8 Dec')
def P8_bitshiftleft1():
p = Program()
p.create_decrement_component()
p.create_not_component()
p.create_and_component()
p.create_bitshiftleft_component(1)
p.create_bitshiftleft_component(1)
p.create_bitshiftleft_component(1)
return ProgramSynthesis(p, BVT.P8, 'P8 BitShiftL1')
def first8_program():
p = Program()
p.create_increment_component()
p.create_decrement_component()
p.create_and_component()
# p.create_negate_component()
p.create_xor_component()
p.create_or_component()
p.create_not_component()
return p
def P1through8():
ps = []
for p in [BVT.P1, BVT.P2, BVT.P3, BVT.P4, BVT.P5, BVT.P6, BVT.P7, BVT.P8]:
ps.append(ProgramSynthesis(first8_program(), p, p.__name__))
return ps
def P1through8except3():
ps = []
for p in [BVT.P1, BVT.P2, BVT.P4, BVT.P5, BVT.P6, BVT.P7, BVT.P8]:
ps.append(ProgramSynthesis(first8_program(), p, p.__name__))
return ps
def first8_program_no_xor():
p = Program()
p.create_increment_component()
p.create_decrement_component()
p.create_and_component()
# p.create_negate_component()
# p.create_xor_component()
p.create_or_component()
p.create_not_component()
return p
def P1_2_5_8():
ps = []
for p in [BVT.P1, BVT.P2, BVT.P5, BVT.P6, BVT.P7, BVT.P8]:
ps.append(ProgramSynthesis(first8_program_no_xor(), p, p.__name__))
return ps
def inc_dec_and_or_with(comp, number):
p = Program()
p.create_increment_component()
p.create_decrement_component()
p.create_and_component()
p.create_or_component()
for _ in range(number):
comp(p)
return p
def Pinc_dec_and_or(comp, number):
ps = []
for p in [BVT.Psimple_inc, BVT.Psimple_dec, BVT.P1, BVT.P2, BVT.P5, BVT.P6]:
ps.append(ProgramSynthesis(inc_dec_and_or_with(comp, number), p, p.__name__))
return ps
def shortestComparison_P1():
ps = []
p = Program()
p.create_decrement_component()
p.create_and_component()
p.create_xor_component()
p.create_xor_component()
p.create_decrement_component()
p.create_add_component()
oracle = BVT.P1
ps_short = ProgramSynthesis(p, oracle, 'Shortest')
ps_short.find_shortest_program = True
ps.append(ps_short)
ps_no_short = ProgramSynthesis(p, oracle, 'No Shortest')
ps_no_short.find_shortest_program = False
ps.append(ps_no_short)
return ps
def shortestComparison_P14():
ps = []
p = Program(num_prog_inputs=2)
p.create_bitshiftleft_component(-1)
p.create_increment_component()
p.create_subtract_component()
p.create_and_component()
p.create_divide_component()
p.create_xor_component()
oracle = BVT.P14
ps_short = ProgramSynthesis(p, oracle, 'Shortest')
ps_short.find_shortest_program = True
ps.append(ps_short)
ps_no_short = ProgramSynthesis(p, oracle, 'No Shortest')
ps_no_short.find_shortest_program = False
ps.append(ps_no_short)
return ps
def shortestComparison_P16():
ps = []
p = Program(num_prog_inputs=2)
p.create_xor_component()
p.create_xor_component()
p.create_and_component()
p.create_negate_component()
p.create_ule_component()
p.create_and_component()
p.create_add_component()
oracle = BVT.P16
ps_short = ProgramSynthesis(p, oracle, 'Find Shortest')
ps_short.find_shortest_program = True
ps.append(ps_short)
ps_no_short = ProgramSynthesis(p, oracle, 'No Find Shortest')
ps_no_short.find_shortest_program = False
ps.append(ps_no_short)
return ps
def shortestComparison_P20():
ps = []
p = Program(num_prog_inputs=1)
p.create_decrement_component()
p.create_bitshiftright_component(BV_LENGTH - 1)
p.create_and_component()
p.create_bvredor_component()
p.create_or_component()
p.create_and_component()
p.create_add_component()
oracle = BVT.P20
ps_short = ProgramSynthesis(p, oracle, 'Shortest')
ps_short.find_shortest_program = True
ps.append(ps_short)
ps_no_short = ProgramSynthesis(p, oracle, 'No Shortest')
ps_no_short.find_shortest_program = False
ps.append(ps_no_short)
return ps
def shortestComparison_P7():
ps = []
p = Program(num_prog_inputs=1)
p.create_not_component()
p.create_increment_component()
p.create_and_component()
p.create_or_component()
p.create_decrement_component()
p.create_and_component()
oracle = BVT.P7
ps_short = ProgramSynthesis(p, oracle, 'Shortest')
ps_short.find_shortest_program = True
ps.append(ps_short)
ps_no_short = ProgramSynthesis(p, oracle, 'No Shortest')
ps_no_short.find_shortest_program = False
ps.append(ps_no_short)
return ps
def shortestComparison_P21():
ps = []
p = Program(num_prog_inputs=1)
p.create_negate_component()
p.create_and_component()
p.create_add_component()
p.create_xor_component()
p.create_add_component()
p.create_bitshiftright_component(2)
p.create_or_component()
oracle = BVT.P21
ps_short = ProgramSynthesis(p, oracle, 'Shortest')
ps_short.find_shortest_program = True
ps.append(ps_short)
ps_no_short = ProgramSynthesis(p, oracle, 'No Shortest')
ps_no_short.find_shortest_program = False
ps.append(ps_no_short)
return ps
def alternative_increment():
ps = []
p = Program(num_prog_inputs=1)
# p.create_increment_component()
p.create_bitshiftleft_component(1)
p.create_bitshiftright_component(1)
p.create_ule_component()
p.create_ult_component()
p.create_bvredor_component()
p.create_and_component()
p.create_add_component()
oracle = BVT.Psimple_inc
ps_short = ProgramSynthesis(p, oracle, 'P Simple')
ps_short.find_shortest_program = True
ps.append(ps_short)
return ps