def evalf(value, n_digits=15): from mitesting.math_objects import math_object if isinstance(value,math_object): expression=value.return_expression() copy_from=value else: from sympy import sympify,SympifyError try: expression=sympify(value) except SympifyError: return value copy_from=None from mitesting.customized_commands import evalf_expression return math_object(evalf_expression(expression,n_digits), copy_parameters_from=copy_from)
def eval_to_comparison_precision(self, expression, additional_rounding=None, evaluate=None): """ If parameter round_on_compare is set, evaluate all numbers and numbersymbols (like pi) of expression to floats with either round_on_compare digits of precision (if not round_absolute) or to round_on_compare decimals (if round_absolute) It will convert floats to integers if round_absolute and round_on_compare <= 0. If additional rounding is set, round_on_compare is reduced by that amount. If round_on_compare is not set, then normalize all floats to 14 digits of precision to increase consistency of floats in presence of roundoff errors. """ modified = False round_on_compare = self._parameters.get("round_on_compare") if round_on_compare is not None: if additional_rounding: try: round_on_compare -= int(additional_rounding) except ValueError: pass round_absolute = self._parameters.get("round_absolute", False) if round_absolute: expression = round_expression(expression, round_on_compare, evaluate=evaluate) modified = True elif round_on_compare > 0: expression = evalf_expression(expression, round_on_compare, evaluate=evaluate) modified = True if not modified: expression = normalize_floats(expression, evaluate=evaluate) return expression