Skip to content

Commit

Permalink
export sympy_core, sympy_matrices; fix tests (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored May 30, 2020
1 parent 0a0ac35 commit 77b8ea0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 208 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SymPy"
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
version = "1.0.23"
version = "1.0.24"


[deps]
Expand Down
30 changes: 18 additions & 12 deletions examples/calculus.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
h5:before {content:"\2746\ ";}
h6:before {content:"\2742\ ";}
pre {display: block;}
th, td {
padding: 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
tr:hover {background-color: #f5f5f5;}
</style>

<script src="https://code.jquery.com/jquery.js"></script>
Expand Down Expand Up @@ -130,7 +136,7 @@ <h5>In <code>Julia</code></h5><p>we have</p><ul>
2⋅x⋅ℯ</pre>
<h5>In <code>Julia</code></h5><p>save for <code>**</code> becoming <code>^</code> this is the same</p><pre class="sourceCode julia">diff(cos(x), x)</pre>
<div class="well well-sm">
\begin{equation*}- \sin{\left (x \right )}\end{equation*}</div>
\begin{equation*}- \sin{\left(x \right)}\end{equation*}</div>

<pre class="sourceCode julia">diff(exp(x^2), x)</pre>
<div class="well well-sm">
Expand Down Expand Up @@ -218,7 +224,7 @@ <h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">@vars m n a b
sin(x)</pre>
<h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">integrate(cos(x), x)</pre>
<div class="well well-sm">
\begin{equation*}\sin{\left (x \right )}\end{equation*}</div>
\begin{equation*}\sin{\left(x \right)}\end{equation*}</div>

<hr /><p>Note that SymPy does not include the constant of integration. If you want it, you can add one yourself, or rephrase your problem as a differential equation and use <code>dsolve</code> to solve it, which does add the constant (see :ref:<code>tutorial-dsolve</code>).</p><blockquote>
<p>Quick Tip:</p>
Expand Down Expand Up @@ -266,11 +272,11 @@ <h5>In Julia:</h5><pre class="sourceCode julia">expr = integrate(x^x, x)
<h5>In <code>Julia</code>:</h5><p>the <code>Integral</code> class is not exported, so it must be qualified:</p><pre class="sourceCode julia">expr = sympy.Integral(log(x)^2, x)
expr</pre>
<div class="well well-sm">
\begin{equation*}\int \log{\left (x \right )}^{2}\, dx\end{equation*}</div>
\begin{equation*}\int \log{\left(x \right)}^{2}\, dx\end{equation*}</div>

<pre class="sourceCode julia">expr.doit()</pre>
<div class="well well-sm">
\begin{equation*}x \log{\left (x \right )}^{2} - 2 x \log{\left (x \right )} + 2 x\end{equation*}</div>
\begin{equation*}x \log{\left(x \right)}^{2} - 2 x \log{\left(x \right)} + 2 x\end{equation*}</div>

<hr /><p><code>integrate</code> uses powerful algorithms that are always improving to compute both definite and indefinite integrals, including heuristic pattern matching type algorithms, a partial implementation of the <code>Risch algorithm &lt;http://en.wikipedia.org/wiki/Risch_algorithm&gt;</code>, and an algorithm using <code>Meijer G-functions &lt;http://en.wikipedia.org/wiki/Meijer_g-function&gt;</code> that is useful for computing integrals in terms of special functions, especially definite integrals. Here is a sampling of some of the power of <code>integrate</code>.</p><pre class="sourceCode julia"> >>> integ = Integral((x**4 + x**2*exp(x) - x**2 - 2*x*exp(x) - 2*x -
... exp(x))*exp(x)/((x - 1)**2*(x + 1)**2*(exp(x) + 1)), x)
Expand Down Expand Up @@ -327,7 +333,7 @@ <h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">integ = sympy.Integ

<pre class="sourceCode julia">integ.doit()</pre>
<div class="well well-sm">
\begin{equation*}\log{\left (e^{x} + 1 \right )} + \frac{e^{x}}{x^{2} - 1}\end{equation*}</div>
\begin{equation*}\log{\left(e^{x} + 1 \right)} + \frac{e^{x}}{x^{2} - 1}\end{equation*}</div>

<pre class="sourceCode julia">integ = sympy.Integral(sin(x^2), x)
integ.doit()</pre>
Expand All @@ -337,7 +343,7 @@ <h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">integ = sympy.Integ
<pre class="sourceCode julia">integ = sympy.Integral(x^y*exp(-x), (x, 0, oo))
integ.doit()</pre>
<div class="well well-sm">
\begin{equation*}\begin{cases} \Gamma\left(y + 1\right) & \text{for}\: - \Re{\left(y\right)} < 1 \\\int\limits_{0}^{\infty} x^{y} e^{- x}\, dx & \text{otherwise} \end{cases}\end{equation*}</div>
\begin{equation*}\begin{cases} \Gamma\left(y + 1\right) & \text{for}\: \operatorname{re}{\left(y\right)} > -1 \\\int\limits_{0}^{\infty} x^{y} e^{- x}\, dx & \text{otherwise} \end{cases}\end{equation*}</div>

<hr /><p>This last example returned a <code>Piecewise</code> expression because the integral does not converge unless $\Re(y) > 1.$</p><h2>Limits</h2><p>SymPy can compute symbolic limits with the <code>limit</code> function. The syntax to compute</p>$$~
\lim_{x\to x_0} f(x)
Expand All @@ -360,7 +366,7 @@ <h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">limit(sin(x)/x, x,
<h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">expr = x^2/exp(x)
expr.subs(x, oo)</pre>
<div class="well well-sm">
\begin{equation*}\mathrm{NaN}\end{equation*}</div>
\begin{equation*}\text{NaN}\end{equation*}</div>

<pre class="sourceCode julia">limit(expr, x, oo)</pre>
<div class="well well-sm">
Expand All @@ -376,7 +382,7 @@ <h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">expr = x^2/exp(x)
<h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">expr = sympy.Limit((cos(x) - 1)/x, x, 0)
expr</pre>
<div class="well well-sm">
\begin{equation*}\lim_{x \to 0^+}\left(\frac{\cos{\left (x \right )} - 1}{x}\right)\end{equation*}</div>
\begin{equation*}\lim_{x \to 0^+}\left(\frac{\cos{\left(x \right)} - 1}{x}\right)\end{equation*}</div>

<pre class="sourceCode julia">expr.doit()</pre>
<div class="well well-sm">
Expand Down Expand Up @@ -449,13 +455,13 @@ <h5>In <code>Julia</code>:</h5><ul>
</ul><pre class="sourceCode julia">f, g = symbols("f g", cls=sympy.Function)
sympy.differentiate_finite(f(x)*g(x))</pre>
<div class="well well-sm">
\begin{equation*}- f{\left (x - \frac{1}{2} \right )} g{\left (x - \frac{1}{2} \right )} + f{\left (x + \frac{1}{2} \right )} g{\left (x + \frac{1}{2} \right )}\end{equation*}</div>
\begin{equation*}- f{\left(x - \frac{1}{2} \right)} g{\left(x - \frac{1}{2} \right)} + f{\left(x + \frac{1}{2} \right)} g{\left(x + \frac{1}{2} \right)}\end{equation*}</div>

<p>(The functions <code>f</code> and <code>g</code> can also be created with the command <code>@symfuns f g</code>, using the <code>@symfuns</code> macro.)</p><hr /><p>If we want to expand the intermediate derivative we may pass the flag <code>evaluate&#61;True</code>:</p><pre class="sourceCode julia"> >>> differentiate_finite(f(x)*g(x), evaluate=True)
(-f(x - 1/2) + f(x + 1/2))⋅g(x) + (-g(x - 1/2) + g(x + 1/2))⋅f(x)</pre>
<h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">sympy.differentiate_finite(f(x)*g(x), evaluate=true)</pre>
<div class="well well-sm">
\begin{equation*}\left(- f{\left (x - \frac{1}{2} \right )} + f{\left (x + \frac{1}{2} \right )}\right) g{\left (x \right )} + \left(- g{\left (x - \frac{1}{2} \right )} + g{\left (x + \frac{1}{2} \right )}\right) f{\left (x \right )}\end{equation*}</div>
\begin{equation*}\left(- f{\left(x - \frac{1}{2} \right)} + f{\left(x + \frac{1}{2} \right)}\right) g{\left(x \right)} + \left(- g{\left(x - \frac{1}{2} \right)} + g{\left(x + \frac{1}{2} \right)}\right) f{\left(x \right)}\end{equation*}</div>

<hr /><p>This form however does not respect the product rule.</p><p>If you already have a <code>Derivative</code> instance, you can use the <code>as_finite_difference</code> method to generate approximations of the derivative to arbitrary order:</p><pre class="sourceCode julia"> >>> f = Function('f')
>>> dfdx = f(x).diff(x)
Expand All @@ -465,7 +471,7 @@ <h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">f = sympy.Function(
dfdx = f(x).diff(x)
dfdx.as_finite_difference()</pre>
<div class="well well-sm">
\begin{equation*}- f{\left (x - \frac{1}{2} \right )} + f{\left (x + \frac{1}{2} \right )}\end{equation*}</div>
\begin{equation*}- f{\left(x - \frac{1}{2} \right)} + f{\left(x + \frac{1}{2} \right)}\end{equation*}</div>

<hr /><p>here the first order derivative was approximated around x using a minimum number of points (2 for 1st order derivative) evaluated equidistantly using a step-size of 1. We can use arbitrary steps (possibly containing symbolic expressions):</p><pre class="sourceCode julia"> >>> f = Function('f')
>>> d2fdx2 = f(x).diff(x, 2)
Expand All @@ -480,7 +486,7 @@ <h5>In <code>Julia</code>:</h5><pre class="sourceCode julia">f = sympy.Function(
h = sympy.Symbol("h")
d2fdx2.as_finite_difference([-3*h,-h,2*h])</pre>
<div class="well well-sm">
\begin{equation*}\frac{f{\left (- 3 h \right )}}{5 h^{2}} - \frac{f{\left (- h \right )}}{3 h^{2}} + \frac{2 f{\left (2 h \right )}}{15 h^{2}}\end{equation*}</div>
\begin{equation*}\frac{f{\left(- 3 h \right)}}{5 h^{2}} - \frac{f{\left(- h \right)}}{3 h^{2}} + \frac{2 f{\left(2 h \right)}}{15 h^{2}}\end{equation*}</div>

<hr /><p>If you are just interested in evaluating the weights, you can do so manually:</p><pre class="sourceCode julia"> >>> finite_diff_weights(2, [-3, -1, 2], 0)[-1][-1]
[1/5, -1/3, 2/15]</pre>
Expand Down
Loading

2 comments on commit 77b8ea0

@jverzani
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/15628

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.24 -m "<description of version>" 77b8ea0752fe3d5556eede993cf04be6f5b60ca8
git push origin v1.0.24

Please sign in to comment.