Closed aravindh-krishnamoorthy closed 2 days ago
For the kinds of problems this fixes, please let's add a test that gets run for this. This way we can ensure no regressions to the code.
Since MatchQ[]
is currently in mathics.core.testing_expressions
a test case could be added to test/builtin/test_testing_expressions.py
Or if you want a more isolated kind of unit test, a new file test/core/test_patterns.py
would be created. Thanks.
For the kinds of problems this fixes, please let's add a test that gets run for this. This way we can ensure no regressions to the code.
Fully agree! I will definitely add them before I finalise this PR.
Pattern x_Integer + y_Integer z_.
for 1 + 2 x
(Not directly relevant for Rubi)
Possibly due to this optimization? https://github.com/Mathics3/mathics-core/blob/0d8a8f6e7cd17348870e501f4ce99103772be5df/mathics/core/pattern.py#L783-L796
We need to get it right before we "optimize". So please fix. Thanks.
We need to get it right before we "optimize". So please fix. Thanks.
Sorry, @rocky, what do you mean? The mentioned optimization is not in the PR but in the mathics-core
code.
We need to get it right before we "optimize". So please fix. Thanks.
Sorry, @rocky, what do you mean? The mentioned optimization is not in the PR but in the
mathics-core
code.
I mean please put in PR to fix add to this PR a fix for the mathics-core code. Thanks.
Pattern
x_Integer + y_Integer z_.
for1 + 2 x
(Not directly relevant for Rubi)Possibly due to this optimization?
If you want to deactivate the optimization, just set leading_blanks=False
before the loop.
Up to here, the changes look reasonable, but it would be nice to see some tests that pass after these changes.
Up to here, the changes look reasonable, but it would be nice to see some tests that pass after these changes.
Let me go further and explain. From my side, it is better to have many smaller fixes and PRS of specific independent bugs than wait until everything is done in several weeks/months and have one huge PR.
It is also useful to add tests after each bug fix is done rather than view this as some sort of separate and independent bullet item or task.
Indeed, it makes sense to have smaller PRs. I will finalise these with tests soon.
Pattern
x_Integer + y_Integer z_.
for1 + 2 x
(Not directly relevant for Rubi) Possibly due to this optimization? https://github.com/Mathics3/mathics-core/blob/0d8a8f6e7cd17348870e501f4ce99103772be5df/mathics/core/pattern.py#L783-L796If you want to deactivate the optimization, just set
leading_blanks=False
before the loop.
Perhaps the removal of optionals in this PR can be reverted after we undo the leading_blanks
optimization. I'll double-check that in the next PR.
Great - thanks!
Overview
In this PR, fixes for pattern matching, esp. those that concern
Rubi`
, are collected.Related issues
1172
1173
Failing patterns
a_. + b_. x_
does not match1 + 2 x
x_.^m_.
does not matchx
a_. + b_.
does not matchx
mathics/core/pattern.py
->assert new_pattern is not None
Pattern(Not directly relevant for Rubi)x_Integer + y_Integer z_.
for1 + 2 x
With
:g[x_] := With[{}, x /; False] /; True
matches forg[2]
~(Fixes for items struck out above are moved to the next PR.)
Final review
Tests
Documentation
N/A