Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mathics/builtin/intfns/combinatorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ class PolygonalNumber(Builtin):

See also <url>
:Binomial:
doc/reference-of-built-in-symbols/integer-functions/combinatorial-functions/binomial/</url>, and <url>
/doc/reference-of-built-in-symbols/integer-functions/combinatorial-functions/binomial/</url>, and <url>
:RegularPolygon:
doc/reference-of-built-in-symbols/drawing-graphics/regularpolygon/</url>.
/doc/reference-of-built-in-symbols/drawing-graphics/regularpolygon/</url>.
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED
Expand Down
22 changes: 15 additions & 7 deletions mathics/builtin/numbers/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,10 @@ class Integers(Builtin):

class Integrate(SympyFunction):
r"""
<url>:WMA link:
https://reference.wolfram.com/language/ref/Integrate.html</url>
<url>:Integral:https://en.wikipedia.org/wiki/Integral</url> (<url>:SymPy:
https://docs.sympy.org/latest/modules/integrals/integrals.html</url>, \
<url>:WMA:
https://reference.wolfram.com/language/ref/Integrate.html</url>)

<dl>
<dt>'Integrate[$f$, $x$]'
Expand Down Expand Up @@ -984,18 +986,20 @@ class Integrate(SympyFunction):
>> Integrate[4 Sin[x] Cos[x], x]
= 2 Sin[x] ^ 2

> Integrate[-Infinity, {x, 0, Infinity}]
>> Integrate[-Infinity, {x, 0, Infinity}]
= -Infinity

> Integrate[-Infinity, {x, Infinity, 0}]
= Infinity
Integrating something ill-defined returns the expression untouched:

Integration in TeX:
>> Integrate[1, {x, Infinity, 0}]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change from -Infinity to 1 because we pull out the -Infinity from inside the integral to outside, whereas WMA does not do this.

While this might be an interesting curiosity to ponder, and whether we should match WMA, it is not instructive and does not belong in the doc. I had also considered moving this into pytest, but felt that as long as there some motivation for doing this it is okay to leave in. Maybe even better, since this gets rendered by MathML.

= Integrate[1, {x, Infinity, 0}]

Here how is an example of converting integral equation to TeX:
>> Integrate[f[x], {x, a, b}] // TeXForm
= \int_a^b f\left[x\right] \, dx

Sometimes there is a loss of precision during integration.
You can check the precision of your result with the following sequence
You can check the precision of your result with the following sequence \
of commands.
>> Integrate[Abs[Sin[phi]], {phi, 0, 2Pi}] // N
= 4.
Expand Down Expand Up @@ -1114,6 +1118,10 @@ def eval(self, f, xs, evaluation: Evaluation, options: dict): # type: ignore[ov
# e.g. NotImplementedError: Result depends on the sign of
# -sign(_u`j)*sign(_u`w)
return
except TypeError:
# SymPy can give this. For example:
# Integrate[-Infinity, {x, 0, Infinity}]
return
if prec is not None and isinstance(sympy_result, sympy.Integral):
# TODO MaxExtraPrecision -> maxn
sympy_result = sympy_result.evalf(dps(prec))
Expand Down