Commit 7b4c3f2d authored by Martin Bauer's avatar Martin Bauer
Browse files

Refactoring of plotting and stencil plotting

- stencil plotting & transformation now in ps.stencil
- additional documentation & notebooks
parent 0998f2e1
[flake8] [flake8]
max-line-length=120 max-line-length=120
exclude=pystencils/jupytersetup.py, exclude=pystencils/jupyter.py,
pystencils/plot2d.py pystencils/plot.py
pystencils/session.py pystencils/session.py
ignore = W293 W503 W291 ignore = W293 W503 W291
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from pystencils.session import * from pystencils.session import *
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Tutorial 01: Getting Started # Tutorial 01: Getting Started
## Overview ## Overview
*pystencils* is a package that can speed up computations on *numpy* arrays. All computations are carried out fully parallel on CPUs (single node with OpenMP, multiple nodes with MPI) or on GPUs. *pystencils* is a package that can speed up computations on *numpy* arrays. All computations are carried out fully parallel on CPUs (single node with OpenMP, multiple nodes with MPI) or on GPUs.
It is suited for applications that run the same operation on *numpy* arrays multiple times. It can be used to accelerate computations on images or voxel fields. Its main application, however, are numerical simulations using finite differences, finite volumes, or lattice Boltzmann methods. It is suited for applications that run the same operation on *numpy* arrays multiple times. It can be used to accelerate computations on images or voxel fields. Its main application, however, are numerical simulations using finite differences, finite volumes, or lattice Boltzmann methods.
There already exist a variety of packages to speed up numeric Python code. One could use pure numpy or solutions that compile your code, like *Cython* and *numba*. See [this page](demo_benchmark.ipynb) for a comparison of these tools. There already exist a variety of packages to speed up numeric Python code. One could use pure numpy or solutions that compile your code, like *Cython* and *numba*. See [this page](demo_benchmark.ipynb) for a comparison of these tools.
![Stencil](../img/pystencils_stencil_four_points_with_arrows.svg) ![Stencil](../img/pystencils_stencil_four_points_with_arrows.svg)
As the name suggests, *pystencils* was developed for **stencil codes**, i.e. operations that update array elements using only a local neighborhood. As the name suggests, *pystencils* was developed for **stencil codes**, i.e. operations that update array elements using only a local neighborhood.
It generates C code, compiles it behind the scenes, and lets you call the compiled C function as if it was a native Python function. It generates C code, compiles it behind the scenes, and lets you call the compiled C function as if it was a native Python function.
But lets not dive too deep into the concepts of *pystencils* here, they are covered in detail in the following tutorials. Let's instead look at a simple example, that computes the average neighbor values of a *numpy* array. Therefor we first create two rather large arrays for input and output: But lets not dive too deep into the concepts of *pystencils* here, they are covered in detail in the following tutorials. Let's instead look at a simple example, that computes the average neighbor values of a *numpy* array. Therefor we first create two rather large arrays for input and output:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
input_arr = np.random.rand(1024, 1024) input_arr = np.random.rand(1024, 1024)
output_arr = np.zeros_like(input_arr) output_arr = np.zeros_like(input_arr)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We first implement a version of this algorithm using pure numpy and benchmark it. We first implement a version of this algorithm using pure numpy and benchmark it.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def numpy_kernel(): def numpy_kernel():
output_arr[1:-1, 1:-1] = input_arr[2:, 1:-1] + input_arr[:-2, 1:-1] + \ output_arr[1:-1, 1:-1] = input_arr[2:, 1:-1] + input_arr[:-2, 1:-1] + \
input_arr[1:-1, 2:] + input_arr[1:-1, :-2] input_arr[1:-1, 2:] + input_arr[1:-1, :-2]
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%%timeit %%timeit
numpy_kernel() numpy_kernel()
``` ```
%%%% Output: stream %%%% Output: stream
3.84 ms ± 36.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) 3.93 ms ± 40 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now lets see how to run the same algorithm with *pystencils*. Now lets see how to run the same algorithm with *pystencils*.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
src, dst = ps.fields(src=input_arr, dst=output_arr) src, dst = ps.fields(src=input_arr, dst=output_arr)
symbolic_description = ps.Assignment(dst[0,0], symbolic_description = ps.Assignment(dst[0,0],
(src[1, 0] + src[-1, 0] + src[0, 1] + src[0, -1]) / 4) (src[1, 0] + src[-1, 0] + src[0, 1] + src[0, -1]) / 4)
symbolic_description symbolic_description
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdkAAAAoCAYAAACy/oAKAAAACXBIWXMAAA7EAAAOxAGVKw4bAAANAUlEQVR4Ae2di3HdNhaGJY0L0Ho78HagdTpwOnA2FSTuwBlXkHE68KaC2OnA7mAdd+B0kFgdeP8PAigQF3w/gEsdzOASjwPg8P8BHgIgeS+/fv16Ya4+BC4vL19Lq7+8Zrc6fhRXn4gr75kON/LfyP8g/9THdbi4kNwvLhD9JPWR8yHUF4lZcCYCCb6L+ErqQiPjaiYvuWIJvou4ov6kPpKML1DIuASrRdgnddFanbhjZM3XhYE6yx/yN4EXhd/Lv4nirwn7dGSfR/EvQc6nPVH+5yATyf0Ry4Ww5J6EcA1H6dPgUIM+OR2k4yp8gb28cbXhNWktrugHNfElXWycaBx2jM/NrmljcDcDu+GAzhE+lOYHrsTuDT9Eyl+T5sPBqHJBfhdkFXYz3BD38sg4oxzSKSPv6ghpXrYlF+dNCatu9H0/toxkX8ozc3fHuJzSnss/i9NqCks3DKNUWs6X6pnNlcp2YhjrtkZYbWX5VfqD4Qoc5Xbny7BfhrvnLdt/u8aGMO8cW8ob7PNmZKOLYxfIe6aLtGt5etIX+TfyLQOjeDC2Qa6VH+vqy1OXKxPnpWHJYHgX3fGpPJ0XnfGf0zZyccn9KN8Yd4XptM2NA2XkqG+Rbrm210iTXoGHRXz5c5zFlcoOYrjSuQ7y68/j0FxFfXI3voSrYX9/LZiL+yCG6TgZM7aG+rwZ2cqMrB/AzEhZIqYz4U9mhUrDGEn8fgaVhpXPhf+kbEaOztcYujR/alx1of9YI8tsoHWjoHhrECmOIWsZ3qk6bSmP/vKL+FL52Vyp7CCGa56/P98sv8o7PFdgKVeEr4eO/RLcwxjowzDIhKNkB8eWZHr7/JUEzFWCgDbyn8iz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+uoyTcpzUgH0RI+shZ9baGMtAA0YzhNOj8tib/YeAaz3p21cmqoO/29vln2aiNs8+KKxZcbiVt6X2ytk0ruojyDgpx0kt2JdaLuYjFRjTyUZPwGFgux6EyjLqy9hfpWXRGUx8Ia4OuXc5eObnJ2Bc1ceZcVKOkyqwL2ZkPe51/BVRuU5Qdcu6OeH1K7s5qZqlO+WMq/pIMk7KcVIT9kWNrGZIPL32twBhSXKUmzGrwlDY6zej0L0XEifsf7MnbsvE97BUGTKu6qPFOCnHSW3Yl9yTdSzoIp5+xGJVdlR/5x7vqg0dr7JXws5uTs6DV+OqPp6Mk3KcVIV90ZlsOQ6s5T4EdCfIvjffejZXOQLGVX0EGSflOKkRezOy5fpDlS2rk7JMzLeqJz1cVuXJHFwp46o+go2TcpzUiv2lLqblULGWq0NAHZVZ7PfyfJUrduxt8yrPW/nPtgwfQ1MmbFyVwb2vVeOkD51t82rF3ozstrwfpnZ14C86mQ8yrvHHQQ5zfkc6EeOqPjaNk3KclMbelovLcX+OLbOUbO48EDCu6uPJOCnHSTHszciWI/0sWtZdIO8y81eHdNJnCr+Td39feBYn8ICUNK7qI9s4KcdJLdjbcnG5PmAtGwKGgCFgCBwcgf8DpsUufKsWZaMAAAAASUVORK5CYII=)
$\displaystyle {{dst}_{(0,0)}} \leftarrow \frac{{{src}_{(-1,0)}}}{4} + \frac{{{src}_{(0,-1)}}}{4} + \frac{{{src}_{(0,1)}}}{4} + \frac{{{src}_{(1,0)}}}{4}$ $\displaystyle {{dst}_{(0,0)}} \leftarrow \frac{{{src}_{(-1,0)}}}{4} + \frac{{{src}_{(0,-1)}}}{4} + \frac{{{src}_{(0,1)}}}{4} + \frac{{{src}_{(1,0)}}}{4}$
src_W src_S src_N src_E src_W src_S src_N src_E
dst_C := ───── + ───── + ───── + ───── dst_C := ───── + ───── + ───── + ─────
4 4 4 4 4 4 4 4
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
plt.figure(figsize=(3,3)) plt.figure(figsize=(3,3))
ps.visualize_stencil_expression(symbolic_description.rhs) ps.stencil.plot_expression(symbolic_description.rhs)
``` ```
%%%% Output: display_data %%%% Output: display_data
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANoAAADTCAYAAADnEg0TAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAClpJREFUeJzt3W9sVWcdwPHv0z+X0tLC4I7hUGZchluiiTFxMdmcm7qRS7Y5/JNg3AvFxAjTSDRzJMZk0akkRoPGzMRIfLGgkTmXbHEdL/ybEaPGF1OjYwwWUNDJZUBLKbDePr5o6coKtL1rf4eefj9v6D33nPVHeb65596de5tyzkiaXS1FDyDNB4YmBWgregDNjNRbvw24DVgKpIvsloGjwK9zrfq7qNkEyedoc1/qrX8R+PQ0D3s416rfnY15NJGhzXGpt94N/AFon+ahZ4B351r11MxPpdfyOdrcdwPTjwxgAXD9DM+iizC0uW9BQcdqGgytjPqPtXDfratYt+o6Xni2UvQ4MrRy6uga5ms/O8SNd/QXPYpGGFoZtVdg6VWNosfQqwxNCmBoUgBDkwJ4CVZZbVm3kgPPdXB4f4U19x7nzg19RY80nxlaWW19/FDRI+hVnjpKAQxNCuCpYxmtvXL1Re976sjzgZNolKGV0bmYdu3oZvuDy9m5d1/BE817njqW1XADdj/ZzbIVQ0WPIkMrr107erjprn7Sxd5srUiGVkaNIXjmiW5uX+9FxZcJQyujpx/p4ea7+2lpLXoSjTK0Mjq4p8KvH+3h/ruu478HF7Bt8/KiR5rvfNWxjDZurTM40MnL/72ahz6R+Mw3PIUsmI9oZXXy+BXk3MKXfzzytQplaGXUGGrl7OnOsdtnBrtoDPlvXSB/+HPfxM8LPHli8YRtA30Tt8HwLMyjCzC0ue/YebdyhoG+K8g5jduWOHniCiZ+hufLsz+ewNDK4B/Af8ZunT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JDk0J46igFMDQpwP8BiJCQfoddbocAAAAASUVORK5CYII=)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Here we first have created a symbolic notation of the stencil itself. This representation is built on top of *sympy* and is explained in detail in the next section. Here we first have created a symbolic notation of the stencil itself. This representation is built on top of *sympy* and is explained in detail in the next section.
This description is then compiled and loaded as a Python function. This description is then compiled and loaded as a Python function.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
kernel = ps.create_kernel(symbolic_description).compile() kernel = ps.create_kernel(symbolic_description).compile()
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
This whole process might seem overly complicated. We have already spent more lines of code than we needed for the *numpy* implementation and don't have anything running yet! However, this multi-stage process of formulating the algorithm symbolically, and just in the end actually running it, is what makes *pystencils* faster and more flexible than other approaches. This whole process might seem overly complicated. We have already spent more lines of code than we needed for the *numpy* implementation and don't have anything running yet! However, this multi-stage process of formulating the algorithm symbolically, and just in the end actually running it, is what makes *pystencils* faster and more flexible than other approaches.
Now finally lets benchmark the *pystencils* kernel. Now finally lets benchmark the *pystencils* kernel.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def pystencils_kernel(): def pystencils_kernel():
kernel(src=input_arr, dst=output_arr) kernel(src=input_arr, dst=output_arr)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%%timeit %%timeit
pystencils_kernel() pystencils_kernel()
``` ```
%%%% Output: stream %%%% Output: stream
639 µs ± 35 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) 643 µs ± 8.66 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
This benchmark shows that *pystencils* is a lot faster than pure *numpy*, especially for large arrays. This benchmark shows that *pystencils* is a lot faster than pure *numpy*, especially for large arrays.
If you are interested in performance details and comparison to other packages like Cython, have a look at [this page](demo_benchmark.ipynb). If you are interested in performance details and comparison to other packages like Cython, have a look at [this page](demo_benchmark.ipynb).
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Short *sympy* introduction ## Short *sympy* introduction
In this tutorial we continue with a short *sympy* introduction, since the symbolic kernel definition is built on top of this package. If you already know *sympy* you can skip this section. In this tutorial we continue with a short *sympy* introduction, since the symbolic kernel definition is built on top of this package. If you already know *sympy* you can skip this section.
You can also read the full [sympy documentation here](http://docs.sympy.org/latest/index.html). You can also read the full [sympy documentation here](http://docs.sympy.org/latest/index.html).
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import sympy as sp import sympy as sp
sp.init_printing() # enable nice LaTeX output sp.init_printing() # enable nice LaTeX output
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
*sympy* is a package for symbolic calculation. So first we need some symbols: *sympy* is a package for symbolic calculation. So first we need some symbols:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
x = sp.Symbol("x") x = sp.Symbol("x")
y = sp.Symbol("y") y = sp.Symbol("y")
type(x) type(x)
``` ```
%%%% Output: execute_result %%%% Output: execute_result
sympy.core.symbol.Symbol sympy.core.symbol.Symbol
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
The usual mathematical operations are defined for symbols: The usual mathematical operations are defined for symbols:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
expr = x**2 * ( y + x + 5) + x**2 expr = x**2 * ( y + x + 5) + x**2
expr expr
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKoAAAAZCAYAAAChKLVZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFdklEQVR4Ae2bgVHcMBBFOYYCSFJBoAMgHUAHUEKgA5hUwEAHJB2EdABUEKADSAWE64D8p0ge2ZaNvfb57sCaMbJW0mr3a7Urycfk5eVlxZImk8mZ+q3r2dDzqOdEvKbKxzQiYEagyq4mFkP1zC7UFwNdUflS2YbK22YJx47vHoE6u1o1orNf6Heq8pYGwruOaUTAikClXV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L6Ci21anvOV3TUIQLPsfxayauXFD40APCPSF72HD6p9glMbk5oD2zIWVoKz/3yT88NvQNJ+vBJ1/zwAk/GCteEifCdqruLndH9V/1DJ16ndNOP0qxaC6guZPdA3RL/7Z9NB6HAf5NJnk6N/Bjoe2IXykyNOHVtzx1Y2ostnMcvsLiqmuerBtS3qQAnjgPQyVUtf7FVZ0SdXV+sogKrfdp6suWKPtfMM+LmwsWmsmjdpGnTs9UncbiNuBJspoX6ZDypnQItMENlYGlPFuAIwE4iFcNyrbNJSfen69Tbuvj5eZ3n+aJbyuDtb03sKX8mV9K53kZKiFp4X84rcnm0MQ9JInwWfdN3TValD9+US28M2iK11wMFeEEJAcBLqj7Oqg11fnNtxO2bK+uFz1itZmIf3yMaza5icDpAAAAAElFTkSuQmCC)
$\displaystyle x^{2} \left(x + y + 5\right) + x^{2}$ $\displaystyle x^{2} \left(x + y + 5\right) + x^{2}$
2 2 2 2
x ⋅(x + y + 5) + x x ⋅(x + y + 5) + x
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now we can do all sorts of operations on these expressions: expand them, factor them, substitute variables: Now we can do all sorts of operations on these expressions: expand them, factor them, substitute variables:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
expr.expand() expr.expand()
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIYAAAAYCAYAAAA/FYWiAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEqElEQVRoBeWagVUUMRCGOZ4FoFYgdIBagdIBagVoB/isgIcdoBUodqBWINABdIBcB/h9YbMvt+zevd3N3cXHvDdkk1xm/kwmmckuk9vb240hNJlMjhl3De/AT+ADZE0pi6cK+xZAt+Er+OP/gj23cTttoWP0ZcCdwO/juKr+M9ZLLsGqQ29HjDyfwuex/pDKebbYpHMoeVJEOufhdawUXu438B1R32XneHo8NOq0xaMhlmBXfWiMe079V6Ot5GoMIWKM4S9tKxl7bmzpvGtbDHKM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:
``` python ``` python
expr.factor() expr.factor()
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHoAAAAZCAYAAAD+OToQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAE6klEQVRoBe2ai3EUORBAvS4C8HERHM7AHBlABvZdBEAGpojABRkAEVxBBvgiADsDTASAMzDvaaUtjXZm16OZXW/BdJWsX3er1a1utcY7u7m52auB2Wz2CroDygPKFeUFvK6pJ9hBDcxqDB2N/AZaDbxH/z3VA/oPd3CPk0hoYL9SC8cF3Rn9Iwyud0+wgxqoNbRbyY2aQnY+toPb/X1FulezdUL0YUF3FPufi/GpuyMaGOLR+RZMzHolY4Z5yrOcydQeRwPo9bi8RquSsVwcGIbsGy9/no+vakNjtv4emier8Ka5bg1EvX+LGH9S/4c+LxMF8ybIOl9ImPdoVBcY6ZFm3714QHNBMUvvRTfhh6ewTqL+Hid90H7jWOpbAwEvjVWHbk7MY5gdwih4sn1KuqtdqBXA8XB8hm5+0lqxxhtkPcPY6Xgch3EaQR49Vf2dZ5KYBH/P+jqQCfJ52ntVMgaxBjVknyl4XECDn8T2quoFk1PIXqWhjjl0rXMFB8tRMGqXPn32fqW8rjI0hP9Twj1LvYB4ihb9soGg4fkF3la8uVz/F+jrJNe31Z/2QOdXHpCFoelouJQFP6ItUw2j93rZf4PwNbVh4Q/rCtD785DTYNFHhgbhhjqZPD4nv6T9uxxz6sa78i8V6tgWQG++ZG1t8i/FZEzZTGy79Or4SUiGaGjkVyCnvgb/Qjl1LLYbl33C7VPD5yPlWRsN4xuRAb4errCPtnVXjUEXdEKtgn/kuPKkMNQvoYSmSh7o1I/G8HA1dEhfWx23ySIu5SJ59Es6xvMEnhJP7Ns44P07RriVZyNpiPyttiVDtmR3M3rsp4hh7lHu33uxy4u6GQ+fOcKgyS6Jm3K8Q+Zz5sroor4PwjsahIMcgb6e53HtuuSd7g3w/QHRCXyXFDRUBuhNDvW8EvSE+5TSUOJdI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Ah+dL4P8DBxDYA8Oug/lKfzkaW/6vt8xh8R31FShmlGZ8z3wjeV9w4qszyHe0NUkt/Gy2RiYzKwpnei39Vbk6Z1m4iKzPWj7EE/8GwcgnW8nB8qT+QR/pFE+5qiI5ootl4jrKcNnw7+7xVMegELm1CYHfZWUq+FIvIYis3XhZ/Z7d/IvxSZcryu9tjydK3jOGvpQCZvh3dhaL3hIYv7Nt84xM0alTz9vQBar7TFb+EiL18OS8+Y2zIeIs9t10h4rKXnz79oooBez4Mx8Fnc+23n/02JjEafxZMlyj36s3MMnZY8kDV5c7Dv1j0aAVJI2fkfHuARJl2+QwXvZvOL1rswYOzQH2TXmZ4jb7gi78TQ6gNBTCL8eDJKoifPCeYaQLdej34OXeRBPwGnY432F5GebwAAAABJRU5ErkJggg==)
$\displaystyle x^{2} \left(x + y + 6\right)$ $\displaystyle x^{2} \left(x + y + 6\right)$
2 2
x ⋅(x + y + 6) x ⋅(x + y + 6)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
expr.subs(y, sp.cos(x)) expr.subs(y, sp.cos(x))
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANoAAAAZCAYAAABXYTDBAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGi0lEQVR4Ae2bjXHVOBSF8zIUwEIH0AGwFSx0EJYKCB2EoQImdAB0AHRAqGCTdEC2grDpIHs+ja7jH8nPT5btZ2zNaKzfq6Mj3asrvWRze3t7kBI2m82p+t1XfKR4pfhWsm70XcPKwGIZiOnFJkXRvLCP6ouCHSj/VZ9Hyj9dLMPrxBfPQJteHCayc1Tr9175JxqI020NKwNLZSCqF6mKBpFlpTKXsVy2VLLXeS+bgbIOFHpxL4UTuYiPa/2e+Px5rXzNrgwshoE2vehzopUJ5GFkp8cQ3EzF47KQNR1noC9f6n+EjPgI+1UzN7wR9u70Qlp40CdqAITxMNJZjtrzWvl9lz5LbpuLL8mxR6vOazUE78Jxo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displaystyle x^{2} \left(x + \cos{\left(x \right)} + 5\right) + x^{2}$
2 2 2 2
x ⋅(x + cos(x) + 5) + x x ⋅(x + cos(x) + 5) + x
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We can also built equations and solve them We can also built equations and solve them
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
eq = sp.Eq(expr, 1) eq = sp.Eq(expr, 1)
eq eq
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANAAAAAZCAYAAABAQ6AIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGKUlEQVR4Ae2cj3HUOBSHswwFwF0FQAeB6yB0ACUAHcBQQSZ0AHQAdEBSwRE6SKjgIB3kvs+RPbbX9tqyrfUmqxkhS5aefnp/9J7kDavr6+uDmLRarU4Y94D8mHxJfgetK8p92nMgmgO7plerGAMKi/zIWA3ngPpXisfUn0Zzbj/wznNgF/XqXqTUXtTGHVM/hAF6o33acyCWAzunV7EGJIPKxpKHbuW2WCbux91tDpR1aPF6dT9GVoRqT2rjDkP9R619X91zoDcHdlGvxnigMmO8UBh0iWC4R35dJrJ/noYD8PXFLQmnB+vVNBzsTyXqEqFMHkFlt3HsHm/K7V3PjPH27itjnnf1279b5wC8O6f1I/kL/LuirveX99+pf6PMEu1e7LipZRc9oXlnCvAP1qttLG6UB2KRepAHCKm38YRFnlEOHbMN/ixxTs8IGtAf+O83CA3qqmw81E2vyBrRzqURejXrWsGlZ5fvOoAsRZ2BHAmRI4onufGE+m/qPzPKLf/QT6P7Qb8kOyPzebPjFfuHFkhJmyfAI99OXRP5X/K3Jl7Spnc6Jb8ds/YJ8AKxf2K+KL3qP8OwnuDRWD6T5bs8L4yH54MoA4KoYYMu9jgwWFp6lJc+bEjveL8P3TYwqeP1JQYhD/ukYzr9Ii9i89gEeKRebSIf9d6NiIGZXoPPzb9y1R5lQBAxBNMSKyFCmIzm5gQALfiAfkm8TzOKu9OqPOD5Jf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TqIF8EW3KRyJ3NGm+s7H/1r7EFI6MzEfpfwm0VlZx9Kp29/5jM8ney3cIGZz8C/5kn7YJoaT9eczOWO6aVDbvRd3RvfpcTbCGDhjdswIEOOpwi1KZafnF1BifSig88BjDW0Lf6vh0DLm8S2j5Yb8Y/Bs5F4rQNzebAufkFSe92rmhJvL0AL65TcgFw/QjGUe4NSJ/FCsTwHp97yBJxZCBtw+3c3jd9+YueZY1xQ/DOwRnnKOTDdRprbMiBDi8X/QR1KaMx7GARvGNT1m7PQbRlFMPbFb1LL4FY8iq0YkHARsAdgP/xNdUERz4VbNhLeGib7WWLRHv42sP1//R3DyYnQa4YAAAAASUVORK5CYII=)
$\displaystyle x^{2} \left(x + y + 5\right) + x^{2} = 1$ $\displaystyle x^{2} \left(x + y + 5\right) + x^{2} = 1$
2 2 2 2
x ⋅(x + y + 5) + x = 1 x ⋅(x + y + 5) + x = 1
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
sp.solve(sp.Eq(expr, 1), y) sp.solve(sp.Eq(expr, 1), y)
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAH8AAAAyCAYAAAB1ewShAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAE60lEQVR4Ae2di1EbMRCGbYYCHNKB6YCQCkI6gKQCoAMYKmBIB4QKMqQDoAOgg9AB4A6c/zskj7g522efdEa+3RlFOj1X+0ur1QOn3+v1XuUGciH9Go/Hp2GEhfOVQL/fvxD3J6UejPqKAPxDuccg8UXgj4JvC2YsAYHP5N4KurCj8NWmi3gS2E9BogXXSAJuIk8msxsMvY016uPad0Wg7cu9evCadtjP/Kb1WPlEEnBAX6l6NPNQrmyfLd2ygb+06Nop6FT2Aa1pIBzJ24/Vsqn9WJLMsB4DP0PQYrFs4MeSZIb1GPgZghaLZQM/liQzrMfAzxC0WCwb+LEkmWE9Bn6GoMVi2cCPJcl26ol2uge7dsLXDmiNWtHJ3qUq4FZu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 6 + ──⎥ ⎢-x - 6 + ──⎥
⎢ 2⎥ ⎢ 2⎥
⎣ x ⎦ ⎣ x ⎦
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
A *sympy* expression is represented by an abstract syntax tree (AST), which can be inspected and modified. A *sympy* expression is represented by an abstract syntax tree (AST), which can be inspected and modified.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
expr expr
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKoAAAAZCAYAAAChKLVZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFdklEQVR4Ae2bgVHcMBBFOYYCSFJBoAMgHUAHUEKgA5hUwEAHJB2EdABUEKADSAWE64D8p0ge2ZaNvfb57sCaMbJW0mr3a7Urycfk5eVlxZImk8mZ+q3r2dDzqOdEvKbKxzQiYEagyq4mFkP1zC7UFwNdUflS2YbK22YJx47vHoE6u1o1orNf6Heq8pYGwruOaUTAikClXVkNFUFiowwhP6ZZhR37vW8EYhvK7GrNgolC/Gah35Yv3xboY3FEoDECdXbVxaPGAnCwanWYYpug5zBmMr73g4Bw3X8j27DMrkyHqRhOAeJO/1oNRzG97l19uC24VJ+9unZjXRkBYXcn6oWen8JvqjLRDOyvVP6l3CXROeDiPNyB15OXJpP8ObvqZKhihkfcFhiNjRSk1A+wD5YVRHSYVxJ2zxqbhR6nc2F5EhPUjjY3oi/dTUzKrsyhX8x2BcRmMFLKesJeNcYs9+6FuB3KSDUeYfA4J8QcCz3Ig4c814P3xDiZg5yRirYiGgeR66669yAv4jROGi9pV6bDlJhhkLjmUxTxUuBVD/x7XQaoY8ivQ6i+7jFlmBVdTkX/owfDXvhUZ1cmQ5XGN3rcPjPW3q/imJR7lyDu6kHtlnLflFNmCQrMhzB/1LOr9+slELnSrjJDlTIYXjiFf9E7ng/Dwnt+0vMkZd3KVP5BZUvC+1YC1kYGy+Bt+0TycB33EPSHj+rAhr32Z9EJs4MljR3miTlDNr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hpKhOG6y7D3mb1+JRyrqzz57cC8lI8zt71UmtCMHV1bFDzEiObwxmHmk3ubUXU/hnqXwNGiiMquW1ZkDJdRbc/HlaoVrqdIEd5VB/Tnc4fmKiUn6qKdoaLTjYIIRllIsj5f7VG2zQ4loeDHuKTNazKRveWLexXeNhZHiObkByOmpOrZueNRJsV9cnoW84tmfXUmBVLhgEkzhMsUv0MQTQ02GqNAm5GrXiwziYw5dyIK8XpY43DL5VG4FeZvm6mOWR325xC+FcdFYpMhTwlY0J2tT+Yrt1N8sb4KXeU5XJUgu+RUIreT1cg1tBcL+q2FoxjK0lRyPey/Qs4ijMsY7Fa3qANN2jKbtUxGDvgHT1G8tqqJJ0zF7add1Tp2higmX4kFZB0Y8Cao7juq7CE5YArhSGlCG0tivENhX58KpynPZn2pcPpumvjQxZ8XFJJJLyB8vMk+efdbnnK6KGUoSUsJqze1LVe8ULXgUq5Z4oBLQA8vQVvackXpZwcrt49sy69j+TOOzH82SyuxNWfzJvbbo4D2L6Ci21anvOV3TUIQLPsfxayauXFD40APCPSF72HD6p9glMbk5oD2zIWVoKz/3yT88NvQNJ+vBJ1/zwAk/GCteEifCdqruLndH9V/1DJ16ndNOP0qxaC6guZPdA3RL/7Z9NB6HAf5NJnk6N/Bjoe2IXykyNOHVtzx1Y2ostnMcvsLiqmuerBtS3qQAnjgPQyVUtf7FVZ0SdXV+sogKrfdp6suWKPtfMM+LmwsWmsmjdpGnTs9UncbiNuBJspoX6ZDypnQItMENlYGlPFuAIwE4iFcNyrbNJSfen69Tbuvj5eZ3n+aJbyuDtb03sKX8mV9K53kZKiFp4X84rcnm0MQ9JInwWfdN3TValD9+US28M2iK11wMFeEEJAcBLqj7Oqg11fnNtxO2bK+uFz1itZmIf3yMaza5icDpAAAAAElFTkSuQmCC)
$\displaystyle x^{2} \left(x + y + 5\right) + x^{2}$ $\displaystyle x^{2} \left(x + y + 5\right) + x^{2}$
2 2 2 2
x ⋅(x + y + 5) + x x ⋅(x + y + 5) + x
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
ps.to_dot(expr, graph_style={'size': "9.5,12.5"} ) ps.to_dot(expr, graph_style={'size': "9.5,12.5"} )
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/svg+xml;utf8,<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN""http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><!-- Generated by graphviz version 2.40.1 (20161225.0304)--><!-- Title: %3 Pages: 1 --><svg width="422pt" height="260pt"viewBox="0.00 0.00 422.00 260.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 256)"><title>%3</title><polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-256 418,-256 418,4 -4,4"/><!-- Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_() --><g id="node1" class="node"><title>Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()</title><ellipse fill="none" stroke="#000000" cx="135" cy="-234" rx="27" ry="18"/><text text-anchor="middle" x="135" y="-230.3" font-family="Times,serif" font-size="14.00" fill="#000000">Add</text></g><!-- Pow(Symbol(x), Integer(2))_(0,) --><g id="node2" class="node"><title>Pow(Symbol(x), Integer(2))_(0,)</title><ellipse fill="none" stroke="#000000" cx="99" cy="-162" rx="27" ry="18"/><text text-anchor="middle" x="99" y="-158.3" font-family="Times,serif" font-size="14.00" fill="#000000">Pow</text></g><!-- Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()&#45;&gt;Pow(Symbol(x), Integer(2))_(0,) --><g id="edge1" class="edge"><title>Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()&#45;&gt;Pow(Symbol(x), Integer(2))_(0,)</title><path fill="none" stroke="#000000" d="M126.2854,-216.5708C122.0403,-208.0807 116.8464,-197.6929 112.1337,-188.2674"/><polygon fill="#000000" stroke="#000000" points="115.237,-186.6477 107.6343,-179.2687 108.976,-189.7782 115.237,-186.6477"/></g><!-- Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,) --><g id="node5" class="node"><title>Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)</title><ellipse fill="none" stroke="#000000" cx="171" cy="-162" rx="27" ry="18"/><text text-anchor="middle" x="171" y="-158.3" font-family="Times,serif" font-size="14.00" fill="#000000">Mul</text></g><!-- Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()&#45;&gt;Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,) --><g id="edge2" class="edge"><title>Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()&#45;&gt;Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)</title><path fill="none" stroke="#000000" d="M143.7146,-216.5708C147.9597,-208.0807 153.1536,-197.6929 157.8663,-188.2674"/><polygon fill="#000000" stroke="#000000" points="161.024,-189.7782 162.3657,-179.2687 154.763,-186.6477 161.024,-189.7782"/></g><!-- Symbol(x)_(0, 0) --><g id="node3" class="node"><title>Symbol(x)_(0, 0)</title><ellipse fill="none" stroke="#000000" cx="27" cy="-90" rx="27" ry="18"/><text text-anchor="middle" x="27" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">x</text></g><!-- Pow(Symbol(x), Integer(2))_(0,)&#45;&gt;Symbol(x)_(0, 0) --><g id="edge3" class="edge"><title>Pow(Symbol(x), Integer(2))_(0,)&#45;&gt;Symbol(x)_(0, 0)</title><path fill="none" stroke="#000000" d="M83.7307,-146.7307C73.803,-136.803 60.6847,-123.6847 49.5637,-112.5637"/><polygon fill="#000000" stroke="#000000" points="51.7933,-109.8436 42.2473,-105.2473 46.8436,-114.7933 51.7933,-109.8436"/></g><!-- Integer(2)_(0, 1) --><g id="node4" class="node"><title>Integer(2)_(0, 1)</title><ellipse fill="none" stroke="#000000" cx="99" cy="-90" rx="27" ry="18"/><text text-anchor="middle" x="99" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">2</text></g><!-- Pow(Symbol(x), Integer(2))_(0,)&#45;&gt;Integer(2)_(0, 1) --><g id="edge4" class="edge"><title>Pow(Symbol(x), Integer(2))_(0,)&#45;&gt;Integer(2)_(0, 1)</title><path fill="none" stroke="#000000" d="M99,-143.8314C99,-136.131 99,-126.9743 99,-118.4166"/><polygon fill="#000000" stroke="#000000" points="102.5001,-118.4132 99,-108.4133 95.5001,-118.4133 102.5001,-118.4132"/></g><!-- Pow(Symbol(x), Integer(2))_(1, 0) --><g id="node6" class="node"><title>Pow(Symbol(x), Integer(2))_(1, 0)</title><ellipse fill="none" stroke="#000000" cx="171" cy="-90" rx="27" ry="18"/><text text-anchor="middle" x="171" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">Pow</text></g><!-- Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)&#45;&gt;Pow(Symbol(x), Integer(2))_(1, 0) --><g id="edge5" class="edge"><title>Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)&#45;&gt;Pow(Symbol(x), Integer(2))_(1, 0)</title><path fill="none" stroke="#000000" d="M171,-143.8314C171,-136.131 171,-126.9743 171,-118.4166"/><polygon fill="#000000" stroke="#000000" points="174.5001,-118.4132 171,-108.4133 167.5001,-118.4133 174.5001,-118.4132"/></g><!-- Add(Integer(5), Symbol(x), Symbol(y))_(1, 1) --><g id="node9" class="node"><title>Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)</title><ellipse fill="none" stroke="#000000" cx="279" cy="-90" rx="27" ry="18"/><text text-anchor="middle" x="279" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">Add</text></g><!-- Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)&#45;&gt;Add(Integer(5), Symbol(x), Symbol(y))_(1, 1) --><g id="edge6" class="edge"><title>Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)&#45;&gt;Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)</title><path fill="none" stroke="#000000" d="M190.3082,-149.1278C207.3555,-137.763 232.4019,-121.0654 251.5344,-108.3104"/><polygon fill="#000000" stroke="#000000" points="253.4799,-111.2199 259.8589,-102.7607 249.5969,-105.3956 253.4799,-111.2199"/></g><!-- Symbol(x)_(1, 0, 0) --><g id="node7" class="node"><title>Symbol(x)_(1, 0, 0)</title><ellipse fill="none" stroke="#000000" cx="99" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="99" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">x</text></g><!-- Pow(Symbol(x), Integer(2))_(1, 0)&#45;&gt;Symbol(x)_(1, 0, 0) --><g id="edge7" class="edge"><title>Pow(Symbol(x), Integer(2))_(1, 0)&#45;&gt;Symbol(x)_(1, 0, 0)</title><path fill="none" stroke="#000000" d="M155.7307,-74.7307C145.803,-64.803 132.6847,-51.6847 121.5637,-40.5637"/><polygon fill="#000000" stroke="#000000" points="123.7933,-37.8436 114.2473,-33.2473 118.8436,-42.7933 123.7933,-37.8436"/></g><!-- Integer(2)_(1, 0, 1) --><g id="node8" class="node"><title>Integer(2)_(1, 0, 1)</title><ellipse fill="none" stroke="#000000" cx="171" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="171" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">2</text></g><!-- Pow(Symbol(x), Integer(2))_(1, 0)&#45;&gt;Integer(2)_(1, 0, 1) --><g id="edge8" class="edge"><title>Pow(Symbol(x), Integer(2))_(1, 0)&#45;&gt;Integer(2)_(1, 0, 1)</title><path fill="none" stroke="#000000" d="M171,-71.8314C171,-64.131 171,-54.9743 171,-46.4166"/><polygon fill="#000000" stroke="#000000" points="174.5001,-46.4132 171,-36.4133 167.5001,-46.4133 174.5001,-46.4132"/></g><!-- Integer(5)_(1, 1, 0) --><g id="node10" class="node"><title>Integer(5)_(1, 1, 0)</title><ellipse fill="none" stroke="#000000" cx="243" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="243" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">5</text></g><!-- Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Integer(5)_(1, 1, 0) --><g id="edge9" class="edge"><title>Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Integer(5)_(1, 1, 0)</title><path fill="none" stroke="#000000" d="M270.2854,-72.5708C266.0403,-64.0807 260.8464,-53.6929 256.1337,-44.2674"/><polygon fill="#000000" stroke="#000000" points="259.237,-42.6477 251.6343,-35.2687 252.976,-45.7782 259.237,-42.6477"/></g><!-- Symbol(x)_(1, 1, 1) --><g id="node11" class="node"><title>Symbol(x)_(1, 1, 1)</title><ellipse fill="none" stroke="#000000" cx="315" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="315" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">x</text></g><!-- Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Symbol(x)_(1, 1, 1) --><g id="edge10" class="edge"><title>Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Symbol(x)_(1, 1, 1)</title><path fill="none" stroke="#000000" d="M287.7146,-72.5708C291.9597,-64.0807 297.1536,-53.6929 301.8663,-44.2674"/><polygon fill="#000000" stroke="#000000" points="305.024,-45.7782 306.3657,-35.2687 298.763,-42.6477 305.024,-45.7782"/></g><!-- Symbol(y)_(1, 1, 2) --><g id="node12" class="node"><title>Symbol(y)_(1, 1, 2)</title><ellipse fill="none" stroke="#000000" cx="387" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="387" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">y</text></g><!-- Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Symbol(y)_(1, 1, 2) --><g id="edge11" class="edge"><title>Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Symbol(y)_(1, 1, 2)</title><path fill="none" stroke="#000000" d="M298.3082,-77.1278C315.3555,-65.763 340.4019,-49.0654 359.5344,-36.3104"/><polygon fill="#000000" stroke="#000000" points="361.4799,-39.2199 367.8589,-30.7607 357.5969,-33.3956 361.4799,-39.2199"/></g></g></svg>) ![](data:image/svg+xml;utf8,<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN""http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><!-- Generated by graphviz version 2.40.1 (20161225.0304)--><!-- Title: %3 Pages: 1 --><svg width="422pt" height="260pt"viewBox="0.00 0.00 422.00 260.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 256)"><title>%3</title><polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-256 418,-256 418,4 -4,4"/><!-- Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_() --><g id="node1" class="node"><title>Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()</title><ellipse fill="none" stroke="#000000" cx="135" cy="-234" rx="27" ry="18"/><text text-anchor="middle" x="135" y="-230.3" font-family="Times,serif" font-size="14.00" fill="#000000">Add</text></g><!-- Pow(Symbol(x), Integer(2))_(0,) --><g id="node2" class="node"><title>Pow(Symbol(x), Integer(2))_(0,)</title><ellipse fill="none" stroke="#000000" cx="99" cy="-162" rx="27" ry="18"/><text text-anchor="middle" x="99" y="-158.3" font-family="Times,serif" font-size="14.00" fill="#000000">Pow</text></g><!-- Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()&#45;&gt;Pow(Symbol(x), Integer(2))_(0,) --><g id="edge1" class="edge"><title>Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()&#45;&gt;Pow(Symbol(x), Integer(2))_(0,)</title><path fill="none" stroke="#000000" d="M126.2854,-216.5708C122.0403,-208.0807 116.8464,-197.6929 112.1337,-188.2674"/><polygon fill="#000000" stroke="#000000" points="115.237,-186.6477 107.6343,-179.2687 108.976,-189.7782 115.237,-186.6477"/></g><!-- Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,) --><g id="node5" class="node"><title>Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)</title><ellipse fill="none" stroke="#000000" cx="171" cy="-162" rx="27" ry="18"/><text text-anchor="middle" x="171" y="-158.3" font-family="Times,serif" font-size="14.00" fill="#000000">Mul</text></g><!-- Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()&#45;&gt;Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,) --><g id="edge2" class="edge"><title>Add(Pow(Symbol(x), Integer(2)), Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y))))_()&#45;&gt;Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)</title><path fill="none" stroke="#000000" d="M143.7146,-216.5708C147.9597,-208.0807 153.1536,-197.6929 157.8663,-188.2674"/><polygon fill="#000000" stroke="#000000" points="161.024,-189.7782 162.3657,-179.2687 154.763,-186.6477 161.024,-189.7782"/></g><!-- Symbol(x)_(0, 0) --><g id="node3" class="node"><title>Symbol(x)_(0, 0)</title><ellipse fill="none" stroke="#000000" cx="27" cy="-90" rx="27" ry="18"/><text text-anchor="middle" x="27" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">x</text></g><!-- Pow(Symbol(x), Integer(2))_(0,)&#45;&gt;Symbol(x)_(0, 0) --><g id="edge3" class="edge"><title>Pow(Symbol(x), Integer(2))_(0,)&#45;&gt;Symbol(x)_(0, 0)</title><path fill="none" stroke="#000000" d="M83.7307,-146.7307C73.803,-136.803 60.6847,-123.6847 49.5637,-112.5637"/><polygon fill="#000000" stroke="#000000" points="51.7933,-109.8436 42.2473,-105.2473 46.8436,-114.7933 51.7933,-109.8436"/></g><!-- Integer(2)_(0, 1) --><g id="node4" class="node"><title>Integer(2)_(0, 1)</title><ellipse fill="none" stroke="#000000" cx="99" cy="-90" rx="27" ry="18"/><text text-anchor="middle" x="99" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">2</text></g><!-- Pow(Symbol(x), Integer(2))_(0,)&#45;&gt;Integer(2)_(0, 1) --><g id="edge4" class="edge"><title>Pow(Symbol(x), Integer(2))_(0,)&#45;&gt;Integer(2)_(0, 1)</title><path fill="none" stroke="#000000" d="M99,-143.8314C99,-136.131 99,-126.9743 99,-118.4166"/><polygon fill="#000000" stroke="#000000" points="102.5001,-118.4132 99,-108.4133 95.5001,-118.4133 102.5001,-118.4132"/></g><!-- Pow(Symbol(x), Integer(2))_(1, 0) --><g id="node6" class="node"><title>Pow(Symbol(x), Integer(2))_(1, 0)</title><ellipse fill="none" stroke="#000000" cx="171" cy="-90" rx="27" ry="18"/><text text-anchor="middle" x="171" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">Pow</text></g><!-- Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)&#45;&gt;Pow(Symbol(x), Integer(2))_(1, 0) --><g id="edge5" class="edge"><title>Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)&#45;&gt;Pow(Symbol(x), Integer(2))_(1, 0)</title><path fill="none" stroke="#000000" d="M171,-143.8314C171,-136.131 171,-126.9743 171,-118.4166"/><polygon fill="#000000" stroke="#000000" points="174.5001,-118.4132 171,-108.4133 167.5001,-118.4133 174.5001,-118.4132"/></g><!-- Add(Integer(5), Symbol(x), Symbol(y))_(1, 1) --><g id="node9" class="node"><title>Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)</title><ellipse fill="none" stroke="#000000" cx="279" cy="-90" rx="27" ry="18"/><text text-anchor="middle" x="279" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">Add</text></g><!-- Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)&#45;&gt;Add(Integer(5), Symbol(x), Symbol(y))_(1, 1) --><g id="edge6" class="edge"><title>Mul(Pow(Symbol(x), Integer(2)), Add(Integer(5), Symbol(x), Symbol(y)))_(1,)&#45;&gt;Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)</title><path fill="none" stroke="#000000" d="M190.3082,-149.1278C207.3555,-137.763 232.4019,-121.0654 251.5344,-108.3104"/><polygon fill="#000000" stroke="#000000" points="253.4799,-111.2199 259.8589,-102.7607 249.5969,-105.3956 253.4799,-111.2199"/></g><!-- Symbol(x)_(1, 0, 0) --><g id="node7" class="node"><title>Symbol(x)_(1, 0, 0)</title><ellipse fill="none" stroke="#000000" cx="99" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="99" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">x</text></g><!-- Pow(Symbol(x), Integer(2))_(1, 0)&#45;&gt;Symbol(x)_(1, 0, 0) --><g id="edge7" class="edge"><title>Pow(Symbol(x), Integer(2))_(1, 0)&#45;&gt;Symbol(x)_(1, 0, 0)</title><path fill="none" stroke="#000000" d="M155.7307,-74.7307C145.803,-64.803 132.6847,-51.6847 121.5637,-40.5637"/><polygon fill="#000000" stroke="#000000" points="123.7933,-37.8436 114.2473,-33.2473 118.8436,-42.7933 123.7933,-37.8436"/></g><!-- Integer(2)_(1, 0, 1) --><g id="node8" class="node"><title>Integer(2)_(1, 0, 1)</title><ellipse fill="none" stroke="#000000" cx="171" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="171" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">2</text></g><!-- Pow(Symbol(x), Integer(2))_(1, 0)&#45;&gt;Integer(2)_(1, 0, 1) --><g id="edge8" class="edge"><title>Pow(Symbol(x), Integer(2))_(1, 0)&#45;&gt;Integer(2)_(1, 0, 1)</title><path fill="none" stroke="#000000" d="M171,-71.8314C171,-64.131 171,-54.9743 171,-46.4166"/><polygon fill="#000000" stroke="#000000" points="174.5001,-46.4132 171,-36.4133 167.5001,-46.4133 174.5001,-46.4132"/></g><!-- Integer(5)_(1, 1, 0) --><g id="node10" class="node"><title>Integer(5)_(1, 1, 0)</title><ellipse fill="none" stroke="#000000" cx="243" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="243" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">5</text></g><!-- Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Integer(5)_(1, 1, 0) --><g id="edge9" class="edge"><title>Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Integer(5)_(1, 1, 0)</title><path fill="none" stroke="#000000" d="M270.2854,-72.5708C266.0403,-64.0807 260.8464,-53.6929 256.1337,-44.2674"/><polygon fill="#000000" stroke="#000000" points="259.237,-42.6477 251.6343,-35.2687 252.976,-45.7782 259.237,-42.6477"/></g><!-- Symbol(x)_(1, 1, 1) --><g id="node11" class="node"><title>Symbol(x)_(1, 1, 1)</title><ellipse fill="none" stroke="#000000" cx="315" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="315" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">x</text></g><!-- Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Symbol(x)_(1, 1, 1) --><g id="edge10" class="edge"><title>Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Symbol(x)_(1, 1, 1)</title><path fill="none" stroke="#000000" d="M287.7146,-72.5708C291.9597,-64.0807 297.1536,-53.6929 301.8663,-44.2674"/><polygon fill="#000000" stroke="#000000" points="305.024,-45.7782 306.3657,-35.2687 298.763,-42.6477 305.024,-45.7782"/></g><!-- Symbol(y)_(1, 1, 2) --><g id="node12" class="node"><title>Symbol(y)_(1, 1, 2)</title><ellipse fill="none" stroke="#000000" cx="387" cy="-18" rx="27" ry="18"/><text text-anchor="middle" x="387" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">y</text></g><!-- Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Symbol(y)_(1, 1, 2) --><g id="edge11" class="edge"><title>Add(Integer(5), Symbol(x), Symbol(y))_(1, 1)&#45;&gt;Symbol(y)_(1, 1, 2)</title><path fill="none" stroke="#000000" d="M298.3082,-77.1278C315.3555,-65.763 340.4019,-49.0654 359.5344,-36.3104"/><polygon fill="#000000" stroke="#000000" points="361.4799,-39.2199 367.8589,-30.7607 357.5969,-33.3956 361.4799,-39.2199"/></g></g></svg>)
<graphviz.files.Source at 0x7fc7dc51b2e8> <graphviz.files.Source at 0x7ff8a018e7f0>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Programatically the children node type is acessible as ``expr.func`` and its children as ``expr.args``. Programatically the children node type is acessible as ``expr.func`` and its children as ``expr.args``.
With these members a tree can be traversed and modified. With these members a tree can be traversed and modified.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
expr.func expr.func
``` ```
%%%% Output: execute_result %%%% Output: execute_result
sympy.core.add.Add sympy.core.add.Add
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
expr.args expr.args
``` ```
%%%% Output: execute_result %%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALAAAAAcCAYAAADBaTXLAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAG2klEQVR4Ae2bj3HVOBDG85gUELgKLnQQoIIjHYTr4KCDZKggEzrgqIAjHQAVHKQDchUE0kHu+ymSkfRk2ZZl+5G8nVFs/dv9tFqtVvLL6ubmZqc2rVarM/HcU9pXulQ6kZxrPRejTcS0mDLukOBVbQO2hvJWfDHcHeU/6LGv/JOl9LaJmJbSxV2T+yAekCb7QOl5XD4gfxS1PVUennjjpWgTMS2li19SruznOAU8MGCMV41ey1t+SjUeUOYbqwsd/LIBrKo19eVvCqZqg7sHjC5kn+zmAe0GuZ2dd8r/EZUNysr4H0cdWBTQl9vH/H83EdP8Wvi1JeJUZcCHSi/1/rcbTeOBVfFWhe9V6byTazP2yYFu8UNcNIhBmKSbfRQX8dhmK2lAuj1Cx13sZJsnanOitntNWxXyTmde9sjXSuKHoXCgq8ZzLK+hmNCJ0sexcu9rf+nuqxKL39iWnuzIOMsjXyfKu8N+1lbUjli4sSnTWAXVDU08Ad0I8sEu9V6CSX2YAG5Rsord1qf1I939UMI5+uks1pfqcRRf4/I4rzbG2bpyF0JgbB+VqpBcPLcYjyXkFQzJK7lYuIqMoUxKMKkPevmicZgrwaEyS9pLJttp8sRdwm9snwp40N0bpXMlQgDsgmdAKiN0Jc7Njt3OxSW4YLCrFywa6x978wA/jBVDxaOfOiF6x5BfKC1CIzCh6MNFQN8doZcpg20ZHleu/ylh8DnCVrGpc24h8JbXdgXodTR9FgcWRHDlUZF/CcDBmOzCJmyYzfuWDOwu9cFGpHe863O95xzqN437T8aOAfOFLDtJYohBsp1Cz5TwTHhuvO1vSlcSaFaNng+Vn5xmwMQWlVMiu01vvUyuEAnw8HCV+c3NCbJVx3wRz/+u8mvK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AZCyvcnTeGuqoDmrsblcZJsrcqSUMERfPJ0B+jcU1DEJfWlDG+NSnibVU14uQIx4ouk1ujs8kmBICmfBA+V6buTB4Inu/Elu/s/NFJ3fS7zKK3gL6NtQ8c+PgjBiviuERmuXuonGmfynlCCNnDkzwzoMTXfJeTiDW7upqlUkmB5bmjrAW31p8hI0bmll/yGN1UnQPnBq3+LEIs/eqqX6urDYexzf1lCxCVT7AZG2O8SgZHZn/ibMelSA/eTJW40mI1Tm3zCEDET62uyfCmLxiHMKrb1vJNOcNyeyKA9dYqm9w6re8zHWT+BV54DF41gB2FEgWV4tXwtp6A+ON6SE6IgaG3L3cbW6GvxbI1QyiikVIQYRHhE9sfbMQk0IqFHagfn7Yg0Fz91tkvGAYiQcWvcjaA1FAq/FaRvwG4tzpqPmvZDFgsO9VQcw7OUle8K8hkwssFGAV+0F6CQ6whewm7SasHNYwYqjrNwe3rTbkr7Bz5nglPQeH0Bie2hHW8YHJXAn6BszW9VkVyZN3zOg+5aU0PDDeYfCB9T7pqXSs0i+hGl+Du4zXfb1rQt3GgBEuRhyqDsVotpgPuVvaaqBLA9aJ8Cu2YCcMDBgm1oiJw4rjpi4w2/qtBoZqQHZJbL/2z8FrBjyU8bb9VgNLauB//cXFCFN3t9QAAAAASUVORK5CYII=)
$\displaystyle \left( x^{2}, \ x^{2} \left(x + y + 5\right)\right)$ $\displaystyle \left( x^{2}, \ x^{2} \left(x + y + 5\right)\right)$
⎛ 2 2 ⎞ ⎛ 2 2 ⎞
⎝x , x ⋅(x + y + 5)⎠ ⎝x , x ⋅(x + y + 5)⎠
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Using *pystencils* ## Using *pystencils*