fix: symbolic sign, Max/Min, and numeric copysign in the SymPy backend#721
Draft
henryiii wants to merge 2 commits into
Draft
fix: symbolic sign, Max/Min, and numeric copysign in the SymPy backend#721henryiii wants to merge 2 commits into
henryiii wants to merge 2 commits into
Conversation
43 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #721 +/- ##
=======================================
Coverage 87.16% 87.17%
=======================================
Files 96 96
Lines 11199 11205 +6
=======================================
+ Hits 9762 9768 +6
Misses 1437 1437 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…y backend The _lib shim's sign() delegated to numpy.sign, which raises on symbolic input (breaking scale() with a symbolic factor on rho/phi vectors), and maximum/minimum returned the first symbolic argument unconditionally, silently dropping domain clamps (acos inputs, Mt2/t2 floors). They now use sympy.Max/sympy.Min/sympy.sign for symbolic input and fall back to the numpy equivalents for plain numbers so that nan propagates instead of raising inside sympy. copysign keeps the assume-non-negative-carrier shortcut for symbolic input (a faithful Abs(x)*sign(y) translation makes sympy's simplifier choke on the nested Piecewise expressions produced by tau/t round trips), but now documents the assumption and handles plain numbers correctly. Affected exact-expression test assertions were updated to the new honest Max/Min forms; numeric expectations are unchanged. Also adds the missing BSD-3 headers to sympy.py and _pytree.py and fixes an operator-precedence bug in two _wrap_result branch conditions (latent; the guards bound to only one arm of the or). Assisted-by: ClaudeCode:claude-fable-5
9a9ef8f to
6c232cc
Compare
Assisted-by: ClaudeCode:claude-opus-4.8
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.
🤖 AI text below 🤖
Part of #711.
Fixes the SymPy backend's
_libshim and related issues:signraised on symbolic input_lib.signdelegated tonumpy.sign, which cannot evaluate a symbolic relational. Repro (before):Now uses
sympy.signfor symbolic input (numpy for plain numbers).maximum/minimumreturned the first symbolic argument unconditionallyThe two methods were byte-identical, so symbolic clamps were silently dropped — e.g.
deltaangle'sacosdomain clamp and thet2/Mt2floors. They now returnsympy.Max/sympy.Minfor symbolic input, and fall back tonumpy.maximum/numpy.minimumfor plain numbers (sonanfrom mixed sympy/object operations propagates instead of raising insidesympy.Max).The exact-expression assertions in the sympy mirror tests were updated to the new honest forms (e.g.
acos(Min(1, ...)),sqrt(Max(0, tau**2 + ...))). No numeric.subs(...).evalf()expectation changed.copysign— documented, deliberately not fully fixedcopysign(val1, val2)returningval1assumes the sign carrier is non-negative (true for timelike vectors). I attempted the faithfulAbs(val1) * sign(val2)(and aPiecewisevariant matching numpy'scopysign(x, 0) == +x): both are mathematically right, but tau/t round-trips then produce nestedPiecewiseexpressions that crash sympy'spiecewise_fold/simplify_logicwithValueError: The argument 'nan' is not comparable, and degrade every tau-coordinate expression with unsimplifiablesign(...)factors. The shortcut is now explicitly commented (with a pointer to #711), and the numeric path (copysign(3.0, -2.0)) is handled correctly vianumpy.copysign. A proper symbolic encoding of signedtauis left as a follow-up decision.Other
src/vector/backends/sympy.pyandsrc/vector/_pytree.py._wrap_resultbranch conditions (theisinstance/issubclassguards bound to only one arm of theor; latent today, aligned with the correct parenthesization innumpy.py).scale, symbolicMax/Min, numericcopysign.Tests: full suite 814 passed, 3 skipped (unrelated optional deps);
prek -aclean.🤖 Generated with Claude Code