Skip to content

Commit edcaf4c

Browse files
Fix Integrate infinite recursion
1 parent 9c332ec commit edcaf4c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

mathics/builtin/numbers/calculus.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from mathics.core.atoms import (
1313
String,
1414
Integer,
15-
Integer0,
1615
Integer1,
1716
Number,
1817
Rational,
@@ -28,6 +27,7 @@
2827
)
2928

3029
from mathics.core.systemsymbols import (
30+
SymbolIndeterminate,
3131
SymbolPlus,
3232
SymbolPower,
3333
SymbolRule,
@@ -55,6 +55,8 @@
5555
IntegerZero = Integer(0)
5656
IntegerMinusOne = Integer(-1)
5757

58+
SymbolIntegrate = Symbol("Integrate")
59+
5860

5961
class D(SympyFunction):
6062
"""
@@ -594,9 +596,6 @@ def from_sympy(self, sympy_name, leaves):
594596

595597
def apply(self, f, xs, evaluation, options):
596598
"Integrate[f_, xs__, OptionsPattern[]]"
597-
self.patpow0 = Pattern.create(
598-
Expression("Power", Integer0, Expression("Blank"))
599-
)
600599
assuming = options["System`Assumptions"].evaluate(evaluation)
601600
f_sympy = f.to_sympy()
602601
if f_sympy is None or isinstance(f_sympy, SympyExpression):
@@ -688,7 +687,10 @@ def apply(self, f, xs, evaluation, options):
688687
else:
689688
result = Expression(result._head, cases, default)
690689
else:
691-
result = Expression("Simplify", result, assuming).evaluate(evaluation)
690+
if result.get_head() is SymbolIntegrate:
691+
# Sympy returned the same expression, so it can't be evaluated.
692+
return SymbolIndeterminate
693+
result = Expression("Simplify", result, assuming)
692694
return result
693695

694696

0 commit comments

Comments
 (0)