question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

substitute not working with SymPy

See original GitHub issue

Calling sorted( ) in https://github.com/HPAC/matchpy/blob/5cae3f275e3a1f725518516bf3c700dc3be03a56/matchpy/functions.py#L87 fails with SymPy, as SymPy objects are not comparable with operators (<, <=, >, >=). Operators are overloaded in SymPy to create instances of inequality objects.

SymPy has a function called default_sort_key meant to deal with this problem:

from sympy import symbols
x, y, z = symbols("x y z")
from sympy.core.compatibility import default_sort_key
sorted([z, x, y], key=default_sort_key)

The question is, is it possible to modify MatchPy to specify a custom sorting key so that SymPy can specify the way its objects should be sorted?

Or is it an issue with Multiset?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Upabjojrcommented, Dec 30, 2020

I guess it would also make sense to add tests for the SymPy compatibility before the next release. Are you working on those tests?

We have these tests in SymPy. I have merged some extensions to sympy.utilities.matchpy_connector 15 days ago. We may need to wait for a new release of SymPy before we can add tests to MatchPy.

0reactions
hbarthelscommented, Dec 30, 2020

Is it important to you that we create a new release of MatchPy as soon as possible? If not, I would prefer to wait a bit in case more problems show up. I guess it would also make sense to add tests for the SymPy compatibility before the next release. Are you working on those tests?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sympy's subs limitations - python - Stack Overflow
The first line gives the expected result (ie. a+1 ) while in the second one there is no substitution. Problem 2: factorized expressions....
Read more >
subs() not working properly · Issue #12302 · sympy ... - GitHub
I tried executing the following code : In [1]: import sympy In [2]: from sympy.abc import x,y In [3]: expr1=x + x**y/x In...
Read more >
SymPy - Substitution - Tutorialspoint
One of the most basic operations to be performed on a mathematical expression is substitution. The subs() function in SymPy replaces all occurrences...
Read more >
Python | sympy.subs() method - GeeksforGeeks
With the help of sympy.subs() method, we can substitute all instances of a variable or expression in a mathematical expression with some other ......
Read more >
Basic Operations - SymPy 1.11 documentation
Substitution replaces all instances of something in an expression with something else. ... That means that subs does not modify it in-place.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found