Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sympy.simplify(mv) blows up with Recursion #53

Closed
eric-wieser opened this issue Nov 19, 2019 · 2 comments · Fixed by #365
Closed

sympy.simplify(mv) blows up with Recursion #53

eric-wieser opened this issue Nov 19, 2019 · 2 comments · Fixed by #365
Labels

Comments

@eric-wieser
Copy link
Member

>>> ga, e1, e2, e3, ep, en = galgebra.ga.Ga.build('e_1 e_2 e_3 e_{+} e_{-}',g=[1,1,1, 1, -1])
>>> sympy.simplify(e1)
RecursionError: maximum recursion depth exceeded while calling a Python object
>>> list(e1)
RecursionError: maximum recursion depth exceeded while calling a Python object

This is because:

  • sympy.simplify and list calls iter(e1)
  • Mv.__iter__ is not defined, so it defaults to:
    def __iter__(self):
        i = 0
        while True:
            try:
                yield self[i]
            except IndexError:
                break
            i += 1
    ```
    
  • Mv.__getitem__ will return 0 forever, as it implies grade selection

Possible fixes:

  • Have Mv.__iter__ raise TypeError
  • Have Mv.__iter__ iterate only up to the highest grade present
@eric-wieser eric-wieser changed the title list(mv) blows up with Recursion sympy.simplify(mv) blows up with Recursion Nov 19, 2019
@eric-wieser
Copy link
Member Author

Using the TypeError approach doesn't improve things much:

>>> sympy.simplify(e1)*e1

image

@meuns
Copy link
Contributor

meuns commented Nov 27, 2019

sympy.simplify(e1.obj) should do the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants