fix: sympify Littlewood-Paley sqrt/bracket inputs - #49
Open
Chessing234 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
src/estimates/littlewood_paley.py,sqrt(x)computesx ** Fraction(1, 2)directly. Whenxis a plain Python int/float (rather than an already-sympifiedExpr), this evaluates using Python's built-in numeric**, which returns an inexactfloat:bracket(x) = sqrt(1 + abs(x) ** 2)inherits the same issue. This defeats the purpose of using sympyExprobjects for exact symbolic/order-of-magnitude reasoning elsewhere in the library (e.g. comparisons withTheta/asympexpect exact sympy expressions, not floats).Fix
Wrap the input in
sympy.S(...)before exponentiation/absolute value so the arithmetic stays in exact sympy form:After the fix:
Verification
mainviauv run python -c "..."(shown above, returnsfloat).Pow).uv run pytest tests/ -k littlewood -qpasses (2 passed).uv run pytest tests/ -q): 1 pre-existing failure (test_linarith_failure_example, a z3 exception) reproduces identically on unmodifiedupstream/main, so it is unrelated to this change; all other 23 tests pass on both.