# Advanced Expression Manipulation


```python
from sympy import *
x, y, z = symbols('x y z')
```

For each exercise, fill in the function according to its docstring. 

## Creating expressions from classes

Create the following objects without using any mathematical operators like `+`, `-`, `*`, `/`, or `**` by explicitly using the classes `Add`, `Mul`, and `Pow`.  You may use `x` instead of `Symbol('x')` and `4` instead of `Integer(4)`.

$$x^2 + 4xyz$$
$$x^{(x^y)}$$
$$x - \frac{y}{z}$$



```python
def explicit_classes1():
    """
    Returns the expression x**2 + 4*x*y*z, built using SymPy classes explicitly.

    >>> explicit_classes1()
    x**2 + 4*x*y*z
    """

```


```python
explicit_classes1()
```


```python
def explicit_classes2():
    """
    Returns the expression x**(x**y), built using SymPy classes explicitly.

    >>> explicit_classes2()
    x**(x**y)
    """

```


```python
explicit_classes2()
```


```python
def explicit_classes3():
    """
    Returns the expression x - y/z, built using SymPy classes explicitly.

    >>> explicit_classes3()
    x - y/z
    """

```


```python
explicit_classes3()
```

## Nested args


```python
expr = x**2 - y*(2**(x + 3) + z)
```

Use nested `.args` calls to get the 3 in expr.


```python
def nested_args():
    """
    Get the 3 in the above expression.

    >>> nested_args()
    3
    """

```


```python
nested_args()
```

## Traversal 

Write a post-order traversal function that prints each node.


```python
def post(expr):
    """
    Post-order traversal

    >>> expr = x**2 - y*(2**(x + 3) + z)
    >>> post(expr)
    -1
    y
    2
    3
    x
    x + 3
    2**(x + 3)
    z
    2**(x + 3) + z
    -y*(2**(x + 3) + z)
    x
    2
    x**2
    x**2 - y*(2**(x + 3) + z)
    """

```


```python
post(expr)
```


```python
for i in postorder_traversal(expr):
    print(i)
```

7559d6e82e90191767670894b7cce2226b3e7ab5
ipynb
Jupyter Notebook
tutorial_exercises/Advanced-Expression Manipulation.ipynb
gvvynplaine/scipy-2016-tutorial
aa417427a1de2dcab2a9640b631b809d525d7929
BSD-3-Clause
2016-06-21T21:11:02.000Z
2021-02-04T07:51:03.000Z
tutorial_exercises/Advanced-Expression Manipulation.ipynb
gvvynplaine/scipy-2016-tutorial
aa417427a1de2dcab2a9640b631b809d525d7929
BSD-3-Clause
2016-07-02T20:24:06.000Z
2016-07-11T11:31:44.000Z
tutorial_exercises/Advanced-Expression Manipulation.ipynb
gvvynplaine/scipy-2016-tutorial
aa417427a1de2dcab2a9640b631b809d525d7929
BSD-3-Clause
2016-06-25T09:04:24.000Z
2021-08-09T06:46:01.000Z
Qwen/Qwen-72B
1. YES
2. YES