# Revision history [back]

### Sympy Sagemath integration bug?

The following piece of code (never mind what it does) that uses sympy runs fine:

# some code...
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt

phi_1_NN, phi_2_NN = sp.symbols('general_NN test', cls=sp.Function)
A11,A21,b,C11,C12,d = sp.symbols('A11 A21 b C11  C12 d')
U11,U21,v,W11,W12,r = sp.symbols('U11 U21 v W11 W12 r')
mylambda = sp.symbols('lambda')
x = sp.symbols('x')
phi_1_NN =(C11*A11**3+C12*A21**3)*x**3 + (3*b*C11*A11**2+3*b*C12*A21**2)*x**2 + (3*b**2*C11*A11+3*b**2*C12*A21)*x+b**3*C11+b**3*C12+d
sp.poly(phi_1_NN,x)
phi_2_NN =(W11*U11**3+W12*U21**3)*x**3 + (3*v*W11*U11**2+3*v*W12*U21**2)*x**2 + (3*v**2*W11*U11+3*v**2*W12*U21)*x+v**3*W11+v**3*W12+r
sp.poly(phi_2_NN,x)
final_expr = mylambda *phi_1_NN+ (mylambda -1)*phi_2_NN
sp.poly(final_expr,x)
arr_linspace = []
for i in range(6):
arr_linspace.append(np.linspace(int(-2.), int(2.), int(4.)))
mesh = np.meshgrid(*arr_linspace, indexing='ij')

arr_flat = []
for m in mesh:
arr_flat.append(m.flatten('C'))
mat_high_dim = np.stack((np.array(arr_flat)),axis = -1)


But when I run in the next cell this code, Sagemath throws a sympy error. But when I run the piece of code at home, it runs fine.

# UNTIL HERE EVERYTHING RUNS FINE
# BUT IF I RUN THE CODE BELOW IN MY MACHINE AT HOME IT WORKS, BUT IF I RUN IT IN SAGE, A SYMPY ERROR IS RETURNED (EVEN THOUGH AT HOME IT RUNS FINE)
l = sp.symbols('l')
rhs_arr = []
for vals in mat_high_dim:
vals = list(map(sp.sympify,vals))
rhs_arr.append(final_expr.subs({A11:1, U11:vals[0], A21:0, U21:vals[1],b:1, v:vals[2], C11:1, W11:vals[3], C12:-2, W12:vals[4],d:3,r:vals[5], mylambda:l}))


Is this some kind of bug that Sagemath has, not having integrated sympy properly? (I tried everything to get Sagemath to work, changed the software environment to different versions of Ubuntu, bought a licence; nothing worked)

### Sympy Sagemath integration bug?

The following piece of code (never mind what it does) that uses sympy runs fine:

# some code...
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt

phi_1_NN, phi_2_NN = sp.symbols('general_NN test', cls=sp.Function)
A11,A21,b,C11,C12,d = sp.symbols('A11 A21 b C11  C12 d')
U11,U21,v,W11,W12,r = sp.symbols('U11 U21 v W11 W12 r')
mylambda = sp.symbols('lambda')
x = sp.symbols('x')
phi_1_NN =(C11*A11**3+C12*A21**3)*x**3 + (3*b*C11*A11**2+3*b*C12*A21**2)*x**2 + (3*b**2*C11*A11+3*b**2*C12*A21)*x+b**3*C11+b**3*C12+d
sp.poly(phi_1_NN,x)
phi_2_NN =(W11*U11**3+W12*U21**3)*x**3 + (3*v*W11*U11**2+3*v*W12*U21**2)*x**2 + (3*v**2*W11*U11+3*v**2*W12*U21)*x+v**3*W11+v**3*W12+r
sp.poly(phi_2_NN,x)
final_expr = mylambda *phi_1_NN+ (mylambda -1)*phi_2_NN
sp.poly(final_expr,x)
arr_linspace = []
for i in range(6):
arr_linspace.append(np.linspace(int(-2.), int(2.), int(4.)))
mesh = np.meshgrid(*arr_linspace, indexing='ij')

arr_flat = []
for m in mesh:
arr_flat.append(m.flatten('C'))
mat_high_dim = np.stack((np.array(arr_flat)),axis = -1)


But when I run in the next cell this code, Sagemath throws a sympy error. But when I run the piece of code at home, offline, instead of the CoCalc Server, it runs fine.

# UNTIL HERE EVERYTHING RUNS FINE
# BUT IF I RUN THE CODE BELOW IN MY MACHINE AT HOME IT WORKS, BUT IF I RUN IT IN SAGE, A SYMPY ERROR IS RETURNED (EVEN THOUGH AT HOME IT RUNS FINE)
l = sp.symbols('l')
rhs_arr = []
for vals in mat_high_dim:
vals = list(map(sp.sympify,vals))
rhs_arr.append(final_expr.subs({A11:1, U11:vals[0], A21:0, U21:vals[1],b:1, v:vals[2], C11:1, W11:vals[3], C12:-2, W12:vals[4],d:3,r:vals[5], mylambda:l}))


Is this some kind of bug that Sagemath has, not having integrated sympy properly? (I tried everything to get Sagemath to work, changed the software environment to different versions of Ubuntu, bought a CoCalc licence; nothing worked)