<h1>The SymPy tutorial (1.3) in <code>Julia</code></h1>

<h2>Table of contents</h2>

<ul>
<li><p><a href="intro.html">Introduction</a></p>
</li>
<li><p><a href="gotchas.html">Gotchas</a></p>
</li>
<li><p><a href="basic_operations.html">Basic Operations</a></p>
</li>
<li><p><a href="simplification.html">Simplification</a></p>
</li>
<li><p><a href="calculus.html">Calculus</a></p>
</li>
<li><p><a href="solvers.html">Solvers</a></p>
</li>
<li><p><a href="matrices.html">Matrices</a></p>
</li>
<li><p><a href="manipulation.html">Advanced Expression Manipulation</a></p>
</li>
</ul>

<h2>About <code>SymPy.jl</code></h2>

<p>The <code>SymPy</code> package for <code>Julia</code> allows <code>Julia</code> users to interact with  python's SymPy module in a mostly seamless manner, thanks to the power of the <code>PyCall</code> package for <code>Julia</code>. The following pages reexpress the SymPy tutorial illustrating the associated <code>Julia</code> commands. There are some changes, but mostly modest ones.</p>

<p>The <code>SymPy</code> package for <code>Julia</code> essentially does:</p>

<ul>
<li><p>it provides a type for symbolic objects, a simple wrapper around the underlying <code>PyCall</code> objects.</p>
</li>
</ul>

<p>Such objects may be created using the SymPy syntax:</p>


```julia
using SymPy
x, y = symbols("x, y")
```




    (x, y)



<p>Alternatively, the <code>@vars</code> macro may be used:</p>


```julia
@vars a b real=true
```




    (a, b)



<ul>
<li><p>Symbolic objects are subtypes of numbers, <code>SymPy</code> provides methods for the generic interface for Julia numbers. For example, elementary operations <code>&#43;</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>^</code> are defined as well as more <code>Julia</code>-specific methodssuch as <code>ones</code>, <code>zeros</code>, <code>eps</code>, etc.</p>
</li>
<li><p>SymPy is organized around various modules, from which functions are imported for use. A common SymPy command would be:</p>
</li>
</ul>


```julia
from sympy import *
```

<p>This imports all functions <em>and</em> modules from the base sympy module into the user's namespace. By default, <code>SymPy</code> imports all functions from <code>sympy</code> – but <em>no</em> modules, as there would be several conflicts with fundamental <code>Julia</code> objects (e.g., <code>Matrix</code>). As such, modules must be qualified, as in <code>sympy.Matrix</code>. (<code>SymPy</code> exports the underlying <code>sympy</code> object.) For other modules, <code>SymPy</code> provides the function <code>import_from</code> to load functions from a given module.</p>

<p>The functions imported by <code>SymPy</code> are specialized so that their first argument is of symbolic type. This is not always appropriate, as some SymPy functions naturally take integer values for the first entry. An example is <code>ones</code>. Either the integer can be made symbolic (as with <code>Sym&#40;1&#41;</code>) or the function can be qualified, as in <code>sympy.ones</code>.</p>

<ul>
<li><p>SymPy and <code>Julia</code> have matrix (and vector) objects. These may be expressed as elements of type <code>Matrix&#123;Sym&#125;</code> (using <code>Julia</code>'s generic matrix type to store symbolic objects. SymPy methods for matrices are available using the <code>getproperty</code> notation (the dot), whereas, <code>Julia</code> methods would just use the fact that <code>Matrix&#123;Sym&#125;</code> will have many generic methods already defined for it.</p>
</li>
</ul>

<p>A quick example:</p>


```julia

@vars x
A = [1 x; x x^3]  # Matrix{Sym}
using LinearAlgebra
A.shape, size(A)
```




    ((2, 2), (2, 2))



8a8cc69137ec284805217f816b691b4faa7e524d
ipynb
Jupyter Notebook
examples/index.ipynb
UnofficialJuliaMirrorSnapshots/SymPy.jl-24249f21-da20-56a4-8eb1-6a02cf4ae2e6
a6e5a24b3d1ad069a413d0c28f01052c5fa4c6cc
MIT
examples/index.ipynb
UnofficialJuliaMirrorSnapshots/SymPy.jl-24249f21-da20-56a4-8eb1-6a02cf4ae2e6
a6e5a24b3d1ad069a413d0c28f01052c5fa4c6cc
MIT
examples/index.ipynb
UnofficialJuliaMirrorSnapshots/SymPy.jl-24249f21-da20-56a4-8eb1-6a02cf4ae2e6
a6e5a24b3d1ad069a413d0c28f01052c5fa4c6cc
MIT
Qwen/Qwen-72B
1. YES
2. YES