# Notation: Converter Symbolic


```python
import mechkit
import numpy as np
import sympy as sp
import itertools
```


```python
np.set_printoptions(
    linewidth=140,
    precision=3,
    # suppress=False,
)
```

### Symbolic with numbers


```python
converter = mechkit.notation.ConverterSymbolic()
ones_tensor = np.ones((3, 3, 3, 3), dtype=sp.Symbol)
print(ones_tensor)
```

    [[[[1 1 1]
       [1 1 1]
       [1 1 1]]
    
      [[1 1 1]
       [1 1 1]
       [1 1 1]]
    
      [[1 1 1]
       [1 1 1]
       [1 1 1]]]
    
    
     [[[1 1 1]
       [1 1 1]
       [1 1 1]]
    
      [[1 1 1]
       [1 1 1]
       [1 1 1]]
    
      [[1 1 1]
       [1 1 1]
       [1 1 1]]]
    
    
     [[[1 1 1]
       [1 1 1]
       [1 1 1]]
    
      [[1 1 1]
       [1 1 1]
       [1 1 1]]
    
      [[1 1 1]
       [1 1 1]
       [1 1 1]]]]



```python
ones_mandel6 = converter.to_mandel6(ones_tensor)
print(ones_mandel6)
```

    [[1 1 1 sqrt(2) sqrt(2) sqrt(2)]
     [1 1 1 sqrt(2) sqrt(2) sqrt(2)]
     [1 1 1 sqrt(2) sqrt(2) sqrt(2)]
     [sqrt(2) sqrt(2) sqrt(2) 2 2 2]
     [sqrt(2) sqrt(2) sqrt(2) 2 2 2]
     [sqrt(2) sqrt(2) sqrt(2) 2 2 2]]



```python
ones_mandel9 = converter.to_mandel9(ones_tensor)
print(ones_mandel9)
```

    [[1 1 1 sqrt(2) sqrt(2) sqrt(2) 0 0 0]
     [1 1 1 sqrt(2) sqrt(2) sqrt(2) 0 0 0]
     [1 1 1 sqrt(2) sqrt(2) sqrt(2) 0 0 0]
     [sqrt(2) sqrt(2) sqrt(2) 2 2 2 0 0 0]
     [sqrt(2) sqrt(2) sqrt(2) 2 2 2 0 0 0]
     [sqrt(2) sqrt(2) sqrt(2) 2 2 2 0 0 0]
     [0 0 0 0 0 0 0 0 0]
     [0 0 0 0 0 0 0 0 0]
     [0 0 0 0 0 0 0 0 0]]


### Symbolic with letters


```python
def tensor(
    order=2, symbol="A", dim=3, latex_index=False, kwargs_symbol={}, indice_offset=0
):
    A = np.zeros((dim,) * order, dtype=sp.Symbol)
    for x in itertools.product(range(dim), repeat=order):
        index = "".join(map(str, map(lambda x: x + indice_offset, x)))
        if latex_index:
            index = "_{" + index + "}"
        A[x] = sp.Symbol(symbol + index, **kwargs_symbol)
    return A
```


```python
def make_it_hooke_symmetric(A, dim=3):
    for i in range(dim):
        for j in range(dim):
            for k in range(dim):
                for m in range(dim):
                    A[i, j, m, k] = A[i, j, k, m]
                    A[j, i, m, k] = A[i, j, k, m]
                    A[k, m, i, j] = A[i, j, k, m]
    return A
```


```python
def make_it_left_symmetric(A, dim=3):
    for i in range(dim):
        for j in range(dim):
            for k in range(dim):
                for m in range(dim):
                    A[j, i, k, m] = A[i, j, k, m]
    return A
```


```python
def make_it_right_symmetric(A, dim=3):
    for i in range(dim):
        for j in range(dim):
            for k in range(dim):
                for m in range(dim):
                    A[i, j, m, k] = A[i, j, k, m]
    return A
```


```python
def make_it_minor_symmetric(A, dim=3):
    tmp = make_it_left_symmetric(A)
    tmp = make_it_right_symmetric(A)
    return tmp
```


```python
tensor = make_it_minor_symmetric(tensor(order=4, indice_offset=1))
print(tensor)
```

    [[[[A1111 A1112 A1113]
       [A1112 A1122 A1123]
       [A1113 A1123 A1133]]
    
      [[A1211 A1212 A1213]
       [A1212 A1222 A1223]
       [A1213 A1223 A1233]]
    
      [[A1311 A1312 A1313]
       [A1312 A1322 A1323]
       [A1313 A1323 A1333]]]
    
    
     [[[A1211 A1212 A1213]
       [A1212 A1222 A1223]
       [A1213 A1223 A1233]]
    
      [[A2211 A2212 A2213]
       [A2212 A2222 A2223]
       [A2213 A2223 A2233]]
    
      [[A2311 A2312 A2313]
       [A2312 A2322 A2323]
       [A2313 A2323 A2333]]]
    
    
     [[[A1311 A1312 A1313]
       [A1312 A1322 A1323]
       [A1313 A1323 A1333]]
    
      [[A2311 A2312 A2313]
       [A2312 A2322 A2323]
       [A2313 A2323 A2333]]
    
      [[A3311 A3312 A3313]
       [A3312 A3322 A3323]
       [A3313 A3323 A3333]]]]



```python
tensor_mandel6 = converter.to_mandel6(tensor)
print(tensor_mandel6)
```

    [[A1111 A1122 A1133 sqrt(2)*A1123 sqrt(2)*A1113 sqrt(2)*A1112]
     [A2211 A2222 A2233 sqrt(2)*A2223 sqrt(2)*A2213 sqrt(2)*A2212]
     [A3311 A3322 A3333 sqrt(2)*A3323 sqrt(2)*A3313 sqrt(2)*A3312]
     [sqrt(2)*A2311 sqrt(2)*A2322 sqrt(2)*A2333 2*A2323 2*A2313 2*A2312]
     [sqrt(2)*A1311 sqrt(2)*A1322 sqrt(2)*A1333 2*A1323 2*A1313 2*A1312]
     [sqrt(2)*A1211 sqrt(2)*A1222 sqrt(2)*A1233 2*A1223 2*A1213 2*A1212]]



```python
tensor_mandel9 = converter.to_mandel9(tensor)
print(tensor_mandel9)
```

    [[A1111 A1122 A1133 sqrt(2)*A1123 sqrt(2)*A1113 sqrt(2)*A1112 0 0 0]
     [A2211 A2222 A2233 sqrt(2)*A2223 sqrt(2)*A2213 sqrt(2)*A2212 0 0 0]
     [A3311 A3322 A3333 sqrt(2)*A3323 sqrt(2)*A3313 sqrt(2)*A3312 0 0 0]
     [sqrt(2)*A2311 sqrt(2)*A2322 sqrt(2)*A2333 2*A2323 2*A2313 2*A2312 0 0 0]
     [sqrt(2)*A1311 sqrt(2)*A1322 sqrt(2)*A1333 2*A1323 2*A1313 2*A1312 0 0 0]
     [sqrt(2)*A1211 sqrt(2)*A1222 sqrt(2)*A1233 2*A1223 2*A1213 2*A1212 0 0 0]
     [0 0 0 0 0 0 0 0 0]
     [0 0 0 0 0 0 0 0 0]
     [0 0 0 0 0 0 0 0 0]]


ipynb
a06baec3090f5c9d57e3d95bd6a7e87072c557fa
Jupyter Notebook
2022-03-16T08:16:20.000Z
2021-10-01T08:50:07.000Z
b6851366b7dcd6094753426a2bc598404c306201
MIT
jonashund/mechkit
docs/source/notebooks/02.ipynb
b6851366b7dcd6094753426a2bc598404c306201
2022-03-16T09:22:30.000Z
2020-09-11T06:53:33.000Z
MIT
jonashund/mechkit
docs/source/notebooks/02.ipynb
b6851366b7dcd6094753426a2bc598404c306201
MIT
jonashund/mechkit
docs/source/notebooks/02.ipynb
2022-02-25T19:36:44.000Z
2020-07-24T21:59:04.000Z