From 970dea3f89bdf17a19300b6722a845ec9ef13c28 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sun, 9 Jul 2023 21:31:12 -0500 Subject: [PATCH] refactor: bind placeholder functions after substituting implicit parameters Will make functions that are challenging to compute symbolically faster (inv, det, etc.) --- public/dimensional_analysis.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/public/dimensional_analysis.py b/public/dimensional_analysis.py index 7be6dbc6..8da14d90 100644 --- a/public/dimensional_analysis.py +++ b/public/dimensional_analysis.py @@ -1162,8 +1162,8 @@ def get_result(exponents: list[Exponent | ExponentName], else: dim, dim_latex = dimensional_analysis(dimensional_analysis_subs, expression) - expression = replace_placeholder_funcs(expression) expression = cast(Expr, expression.xreplace(parameter_subs)) + expression = replace_placeholder_funcs(expression) evaluated_expression = cast(ExprWithAssumptions, expression.evalf(PRECISION)) symbolic_expression = custom_latex(cancel(expression)) if evaluated_expression.is_number: @@ -1297,9 +1297,11 @@ def evaluate_statements(statements: list[InputAndSystemStatement]) -> tuple[list exponent_dimensionless[exponent_name+current_function_name] = True else: exponent_dimensionless[exponent_name+current_function_name] = False - final_expression: Expr = replace_placeholder_funcs(final_expression) + + final_expression = cast(Expr, cast(Expr, final_expression).xreplace(parameter_subs)) + final_expression = replace_placeholder_funcs(final_expression) - exponent_subs[symbols(exponent_name+current_function_name)] = cast(Expr, final_expression.xreplace(parameter_subs)) + exponent_subs[symbols(exponent_name+current_function_name)] = final_expression elif is_function: while(True):