Skip to content

Commit 8b148ae

Browse files
authored
Implement variable-eliminating simplifications under a flag (metalift#65)
1 parent b3f9634 commit 8b148ae

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

actors/synthesis.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def __call__(
171171
uid: int = 0,
172172
noVerify: bool = False,
173173
unboundedInts: bool = False,
174-
listBound: int = 1,
174+
optimize_vc_equality: bool = False,
175+
listBound: int = 2,
175176
) -> typing.List[Expr]:
176177
...
177178

synthesize_cvc5.py

+22
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,35 @@ def synthesize(
210210
uid: int = 0,
211211
noVerify: bool = False, # currently ignored
212212
unboundedInts: bool = False, # currently ignored
213+
optimize_vc_equality: bool = False,
213214
listBound: int = 2, # currently ignored
214215
) -> typing.List[Expr]:
215216
synthDir = "./synthesisLogs/"
216217
if not os.path.exists(synthDir):
217218
os.mkdir(synthDir)
218219
sygusFile = synthDir + basename + f"_{uid}" + ".sl"
219220

221+
if optimize_vc_equality:
222+
prev_vc = vc.toSMT()
223+
new_vars: typing.Set[Expr] = set()
224+
while True:
225+
expr_count: Dict[str, int] = {}
226+
vc.countVariableUses(expr_count)
227+
228+
vc = vc.optimizeUselessEquality(expr_count, new_vars)
229+
230+
if vc.toSMT() == prev_vc:
231+
break # run to fixpoint
232+
else:
233+
prev_vc = vc.toSMT()
234+
235+
vars = vars.union(new_vars)
236+
for var in list(vars):
237+
if var.args[0] not in expr_count:
238+
vars.remove(var)
239+
else:
240+
vc = vc.simplify()
241+
220242
# Generate sygus file for synthesis
221243
toSMT(
222244
targetLang,

synthesize_rosette.py

+22-17
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def synthesize(
303303
uid: int = 0,
304304
noVerify: bool = False,
305305
unboundedInts: bool = False,
306+
optimize_vc_equality: bool = False,
306307
listBound: int = 2,
307308
) -> typing.List[Expr]:
308309
invGuess: typing.List[Any] = []
@@ -312,23 +313,27 @@ def synthesize(
312313

313314
while True:
314315
synthFile = synthDir + basename + f"_{uid}" + ".rkt"
315-
# prev_vc = vc.toSMT()
316-
# new_vars: typing.Set[Expr] = set()
317-
# while True:
318-
# expr_count: Dict[str, int] = {}
319-
# vc.countVariableUses(expr_count)
320-
321-
# vc = vc.optimizeUselessEquality(expr_count, new_vars)
322-
323-
# if vc.toSMT() == prev_vc:
324-
# break # run to fixpoint
325-
# else:
326-
# prev_vc = vc.toSMT()
327-
328-
# vars = vars.union(new_vars)
329-
# for var in list(vars):
330-
# if var.args[0] not in expr_count:
331-
# vars.remove(var)
316+
317+
if optimize_vc_equality:
318+
prev_vc = vc.toSMT()
319+
new_vars: typing.Set[Expr] = set()
320+
while True:
321+
expr_count: Dict[str, int] = {}
322+
vc.countVariableUses(expr_count)
323+
324+
vc = vc.optimizeUselessEquality(expr_count, new_vars)
325+
326+
if vc.toSMT() == prev_vc:
327+
break # run to fixpoint
328+
else:
329+
prev_vc = vc.toSMT()
330+
331+
vars = vars.union(new_vars)
332+
for var in list(vars):
333+
if var.args[0] not in expr_count:
334+
vars.remove(var)
335+
else:
336+
vc = vc.simplify()
332337

333338
##### synthesis procedure #####
334339
choices: Dict[str, Dict[str, Expr]] = {}

0 commit comments

Comments
 (0)