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

RecursionError for unevluated expression in latex #22788

Open
proy87 opened this issue Jan 3, 2022 · 6 comments · May be fixed by #24810
Open

RecursionError for unevluated expression in latex #22788

proy87 opened this issue Jan 3, 2022 · 6 comments · May be fixed by #24810

Comments

@proy87
Copy link

proy87 commented Jan 3, 2022

latex(Mul(Pow(Integer(2), Integer(-1), evaluate=False), Add(Integer(1), i, evaluate=False), Add(Integer(1), Pow(i, Integer(-8), evaluate=False), evaluate=False), evaluate=False))

@oscarbenjamin
Copy link
Contributor

I presume that i here is sympy.I

@proy87
Copy link
Author

proy87 commented Jan 3, 2022

@oscarbenjamin, yes.

@KuldeepBorkar
Copy link
Contributor

@oscarbenjamin, @proy87
Specifically we can say error comes here
z = Pow(I, Integer(-8), evaluate=False)

@KuldeepBorkar
Copy link
Contributor

KuldeepBorkar commented Jan 3, 2022

Yeah it's getting error trying to do this -1**(-8) when evaluate=False.
Say, for any negative number except -1

@oscarbenjamin
Copy link
Contributor

The error is here:

numer, denom = fraction(expr, exact=True)
if denom is S.One and Pow(1, -1, evaluate=False) not in expr.args:
# use the original expression here, since fraction() may have
# altered it when producing numer and denom
tex += convert(expr)

The problem is that in this case:

In [5]: z
Out[5]: 
1 
──
 8
 

In [6]: fraction(z, exact=True)
Out[6]: (1, 1)

When we call convert with expr we get right back here again. The problem with fraction can be fixed with:

diff --git a/sympy/simplify/radsimp.py b/sympy/simplify/radsimp.py
index 91078be..6d18499 100644
--- a/sympy/simplify/radsimp.py
+++ b/sympy/simplify/radsimp.py
@@ -1089,11 +1089,11 @@ def fraction(expr, exact=False):
                     denom.append(b)
                 elif exact:
                     if ex.is_constant():
-                        denom.append(Pow(b, -ex))
+                        denom.append(Pow(b, -ex, evaluate=not exact))
                     else:
                         numer.append(term)
                 else:
-                    denom.append(Pow(b, -ex))
+                    denom.append(Pow(b, -ex, evaluate=not exact))
             elif ex.is_positive:
                 numer.append(term)
             elif not exact and ex.is_Mul:

@KuldeepBorkar
Copy link
Contributor

Thanks @oscarbenjamin I will make the changes quick.

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