Incorrect Values Creating Expression From Other Expressions

You do have to update all of them yourself.

If the calculations are complicated, it may be easier to have them carried out by a symbolic math library, and then wrap just the final result in an expression.

from fenics import *
import sympy

t = sympy.var("t")
exp1 = sympy.sin(t)
exp2 = sympy.cos(t)
test1_sym = exp1 * exp2
test2_sym = exp1 + exp2
test1_cpp = sympy.printing.ccode(test1_sym)
test2_cpp = sympy.printing.ccode(test2_sym)


mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh, 'CG', 6)
test1 = Expression(test1_cpp, t=0.0, degree=1)
test2 = Expression(test2_cpp, t=0.0, degree=1)
test1.t = 0.1
test2.t = 0.1
t1 = interpolate(test1, V)
t2 = interpolate(test2, V)
print('t1(0.1) = ', t1(0.0), "vs", test1_sym.subs({t: 0.1}))
print('t2(0.1) = ', t2(0.0), "vs", test2_sym.subs({t: 0.1}))

gives

t1(0.1) =  0.09933466539753065 vs 0.0993346653975306
t2(0.1) =  1.0948375819248541 vs 1.09483758192485