From 642322745788b6d3465e1f49615999447b115a13 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Fri, 10 Jan 2025 01:24:33 -0600 Subject: [PATCH] Revert "fix: fix error recognizing small differences in dimension exponents as being equal" This reverts commit d060821506340cd3390e56a0ac7e23e37ff00b9c. --- public/dimensional_analysis.py | 30 ++++-------------------------- tests/test_basic.spec.mjs | 22 ---------------------- 2 files changed, 4 insertions(+), 48 deletions(-) diff --git a/public/dimensional_analysis.py b/public/dimensional_analysis.py index 9e278280..b5f202b5 100644 --- a/public/dimensional_analysis.py +++ b/public/dimensional_analysis.py @@ -69,8 +69,6 @@ Integer ) -from sympy import S - class ExprWithAssumptions(Expr): is_finite: bool is_integer: bool @@ -869,22 +867,7 @@ def custom_latex(expression: Expr) -> str: _range = Function("_range") -def dimensional_dependencies_equal(input1, input2): - keys1 = set(input1.keys()) - keys2 = set(input2.keys()) - - for key in keys1 ^ keys2: # symmetric difference - if input1.get(key, S.Zero).round(EXP_NUM_DIGITS) != S.Zero or \ - input2.get(key, S.Zero).round(EXP_NUM_DIGITS) != S.Zero: - return False - - for key in keys1 & keys2: # union - if input1[key].round(EXP_NUM_DIGITS) != input2[key].round(EXP_NUM_DIGITS): - return False - - return True - -def ensure_dims_all_compatible(*args, error_message=None): +def ensure_dims_all_compatible(*args): if args[0].is_zero: if all(arg.is_zero for arg in args): first_arg = sympify('0') @@ -897,14 +880,10 @@ def ensure_dims_all_compatible(*args, error_message=None): return first_arg first_arg_dims = custom_get_dimensional_dependencies(first_arg) - - if all(dimensional_dependencies_equal(custom_get_dimensional_dependencies(arg), first_arg_dims) for arg in args[1:]): + if all(custom_get_dimensional_dependencies(arg) == first_arg_dims for arg in args[1:]): return first_arg - if error_message is None: - raise TypeError('All input arguments to function need to have compatible units') - else: - raise TypeError(error_message) + raise TypeError('All input arguments to function need to have compatible units') def ensure_dims_all_compatible_scalar_or_matrix(*args): if len(args) == 1 and is_matrix(args[0]): @@ -1182,8 +1161,7 @@ def custom_integral_dims(local_expr: Expr, global_expr: Expr, dummy_integral_var return global_expr * integral_var # type: ignore def custom_add_dims(*args: Expr): - return ensure_dims_all_compatible(*[Abs(arg) for arg in args], - error_message="Only equivalent dimensions can be added or subtracted.") + return Add(*[Abs(arg) for arg in args]) def custom_pow(base: Expr, exponent: Expr): large_rational = False diff --git a/tests/test_basic.spec.mjs b/tests/test_basic.spec.mjs index 192a1110..95ea83d8 100644 --- a/tests/test_basic.spec.mjs +++ b/tests/test_basic.spec.mjs @@ -780,28 +780,6 @@ test('Test zero canceling bug with exponent', async () => { expect(content).toBe('m'); }); -test('Test floating point exponent rounding', async () => { - - await page.setLatex(0, String.raw`1\left\lbrack m\right\rbrack+1\left\lbrack\frac{N^{\frac13}}{m^{\frac23}}\right\rbrack\cdot1\left\lbrack\frac{m^{\frac53}}{N^{\frac13}}\right\rbrack=`); - await page.click('#add-math-cell'); - await page.setLatex(1, String.raw`1\left\lbrack N\cdot s^{.0000000000001}\right\rbrack+2\left\lbrack N\right\rbrack=`); - await page.click('#add-math-cell'); - await page.setLatex(2, String.raw`1\left\lbrack N\cdot s^{.000000000001}\right\rbrack+2\left\lbrack N\right\rbrack=`); - - await page.waitForSelector('text=Updating...', {state: 'detached'}); - - let content = await page.textContent('#result-value-0'); - expect(parseLatexFloat(content)).toBeCloseTo(2, precision); - content = await page.textContent('#result-units-0'); - expect(content).toBe('m'); - - content = await page.textContent('#result-value-1'); - expect(parseLatexFloat(content)).toBeCloseTo(3, precision); - content = await page.textContent('#result-units-1'); - expect(content).toBe('N'); - - await expect(page.locator('#cell-2 >> text=Dimension Error')).toBeVisible(); -}); test('Test function notation with integrals', async () => {