# About
This notebook was created to follow the sympy code generation tutorial at [this link](http://www.sympy.org/scipy-2017-codegen-tutorial/)


```python
import sympy as sym
sym.init_printing()
x, y = sym.symbols('x y')
expr = 3*x**2 + sym.log(x**2 + y**2 + 1)
expr
```


```python
expr.subs({x: 17, y: 42}).evalf()
% timeit expr.subs({x: 17, y: 42}).evalf()
```

    221 µs ± 948 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)



```python
import math
f = lambda x, y:  3*x**2 + math.log(x**2 + y**2 + 1)
%timeit f(17, 42)
```

    917 ns ± 2.67 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)



```python
g = sym.lambdify([x, y], expr, modules=['math'])
g(17, 42)
```


```python
%timeit g(17, 42)
```

    906 ns ± 1.64 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)



```python
import numpy as np
xarr = np.linspace(17,18,5)
h = sym.lambdify([x, y], expr)
out = h(xarr, 42)
out
```




    array([ 874.62754439,  900.31920442,  926.38590757,  952.82765322,
            979.64444076])



lambdify constructs string representation of python code and uses python eval to compile


```python
z = z1, z2, z3 = sym.symbols('z:3')
```


```python
expr2 = x*y*(z1+z2+z3)
func2 = sym.lambdify([x, y, z], expr2)
func2(1,2, (3,4,5))
# Vector arguments can be done as tuples when using odeint... (see video/example)
```


```python
# How to efficiently deal with matrices without preconverting?
# Or just save as M, C, etc... What about pars? Third argument. Can it be dict or must it be tuple?
# How to efficiently save, 

```

# Chemistry...

In example, dict is converted to tuple, both for the constants used to define the lambda, and for the tuple for evaluation. So they are in the same order

215be5fcdc63f973080f496d7705a349c7bd2e69
ipynb
Jupyter Notebook
sympytest/Tutorial part 2.ipynb
laurensvalk/devbots
dd7285774c0ec1a02fb30aaaaa9d396d6a680b3e
MIT
2020-05-19T11:06:46.000Z
2020-05-19T11:06:46.000Z
sympytest/Tutorial part 2.ipynb
laurensvalk/devbots
dd7285774c0ec1a02fb30aaaaa9d396d6a680b3e
MIT
sympytest/Tutorial part 2.ipynb
laurensvalk/devbots
dd7285774c0ec1a02fb30aaaaa9d396d6a680b3e
MIT
Qwen/Qwen-72B
1. YES
2. YES