MCPcopy Create free account
hub / github.com/LeapLabTHU/Absolute-Zero-Reasoner / is_expr_equal

Function is_expr_equal

evaluation/math_eval/eval/math_utils.py:133–179  ·  view source on GitHub ↗
(ans_p, ans_l, is_strict=False)

Source from the content-addressed store, hash-verified

131
132
133def is_expr_equal(ans_p, ans_l, is_strict=False):
134 def is_equ_num_equal(equation, number):
135 if (
136 isinstance(equation, sp.Eq)
137 # and isinstance(equation.lhs, sp.Symbol)
138 and equation.rhs.is_number
139 and number.is_number
140 ):
141 try:
142 ret = my_equals(equation.rhs, number)
143 return bool(ret)
144 except:
145 return equation.rhs == number
146
147 if ans_p is None or ans_l is None:
148 return False
149 if isinstance(ans_l, str):
150 return ans_p == ans_l
151
152 if (
153 not is_strict
154 and is_equ_num_equal(ans_l, ans_p)
155 or is_equ_num_equal(ans_p, ans_l)
156 ):
157 return True
158
159 if ans_p.free_symbols != ans_l.free_symbols:
160 return False
161
162 if ans_p == ans_l:
163 return True
164
165 if isinstance(ans_l, sp.core.relational.Relational):
166 try:
167 if (
168 type(ans_l) == type(ans_p)
169 and my_equals(ans_p.lhs, ans_l.lhs)
170 and my_equals(ans_p.rhs, ans_l.rhs)
171 ):
172 return True
173 except Exception as e:
174 print(ans_p, ans_l, e)
175 try:
176 ret = my_equals(ans_p, ans_l)
177 return bool(ret)
178 except:
179 return False
180
181
182# @timeout_decorator.timeout(5)

Callers 1

compare_ansFunction · 0.85

Calls 2

is_equ_num_equalFunction · 0.85
my_equalsFunction · 0.85

Tested by

no test coverage detected