@@ -961,10 +961,11 @@ def visit_Operation(self, expression, *operands):
961961
962962 @property
963963 def result (self ):
964- return self .apply_bindings (self ._stack [- 1 ])
964+ return f" { self .apply_bindings (self ._stack [- 1 ])} "
965965
966966 def apply_bindings (self , main_smtlib_str ):
967967 # Python program to print topological sorting of a DAG
968+ # Well-sortedness requirements
968969 from toposort import toposort_flatten as toposort
969970
970971 G = {}
@@ -977,25 +978,22 @@ def apply_bindings(self, main_smtlib_str):
977978 if not variables :
978979 G [name ] = set ()
979980
980- output = ""
981981 # Build let statement
982+ output = main_smtlib_str
982983 for name in reversed (toposort (G )):
983984 if name not in self ._bindings :
984985 continue
985986 expr , smtlib = self ._bindings [name ]
986987
988+
987989 # FIXME: too much string manipulation. Search occurrences in the Expression realm
988- if main_smtlib_str . count ( name ) + output .count (name ) = = 1 :
989- main_smtlib_str = main_smtlib_str . replace ( name , smtlib )
990+ if output .count (name ) < = 1 :
991+ #output = f"let (({ name} { smtlib})) ({output})"
990992 output = output .replace (name , smtlib )
991993 else :
992- output = f"({ name } { smtlib } ) { output } "
994+ output = f"(let (( { name } { smtlib } )) { output } ) "
993995
994- if output :
995- output = f"(let ({ output } ) { main_smtlib_str } )"
996- else :
997- output = main_smtlib_str
998- return output
996+ return f"{ output } "
999997
1000998 def declarations (self ):
1001999 result = ""
0 commit comments