Skip to content

Commit

Permalink
fix: apply evalf to exponents
Browse files Browse the repository at this point in the history
rational exponents with large denominators causes very long calculation times.
  • Loading branch information
mgreminger committed Jan 7, 2025
1 parent 9d69544 commit 0e447db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions public/dimensional_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,10 +1151,13 @@ def custom_integral_dims(local_expr: Expr, global_expr: Expr, dummy_integral_var
def custom_add_dims(*args: Expr):
return Add(*[Abs(arg) for arg in args])

def custom_pow(base: Expr, exponent: Expr):
return base**(exponent.evalf(PRECISION))

def custom_pow_dims(dim_values: list[Expr], base: Expr, exponent: Expr):
if custom_get_dimensional_dependencies(exponent) != {}:
raise TypeError('Exponent Not Dimensionless')
return base**dim_values[1]
return base**((dim_values[1]).evalf(PRECISION))

CP = None

Expand Down Expand Up @@ -1468,7 +1471,7 @@ def get_next_id(self):
cast(Function, Function('_range')) : {"dim_func": custom_range, "sympy_func": custom_range},
cast(Function, Function('_factorial')) : {"dim_func": factorial, "sympy_func": CustomFactorial},
cast(Function, Function('_add')) : {"dim_func": custom_add_dims, "sympy_func": Add},
cast(Function, Function('_Pow')) : {"dim_func": custom_pow_dims, "sympy_func": Pow},
cast(Function, Function('_Pow')) : {"dim_func": custom_pow_dims, "sympy_func": custom_pow},
}

global_placeholder_set = set(global_placeholder_map.keys())
Expand Down
2 changes: 1 addition & 1 deletion tests/test_symbolic_expression_error_handling.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ test('Test handling of symbolic expression error', async ({ page, browserName })

await page.locator('text=Updating...').waitFor({state: 'detached', timeout: pyodideLoadTimeout});

let content = await page.locator('#result-value-21').textContent({timeout: 240000});
let content = await page.locator('#result-value-21').textContent();
expect(parseLatexFloat(content)).toBeCloseTo(57168.5056551697, precision);
});

0 comments on commit 0e447db

Please sign in to comment.