In [1]:
import pycalphad
from pycalphad.tests.datasets import ALFE_TDB
from pycalphad import Database, Model
import pycalphad.variables as v
from sympy import Piecewise, Function
dbf = Database(ALFE_TDB)
mod = Model(dbf, ['AL','FE', 'VA'], 'B2_BCC')
t = mod.ast.diff(v.Y('B2_BCC', 1, 'AL'), v.Y('B2_BCC', 0, 'FE'))
#print(t)
def func(x):
f = Function('f')
a = []
for t in x.args:
a.append(t[0])
#print(a)
return f(*a)
t = t.replace(lambda expr: isinstance(expr, Piecewise), func)
for _ in range(5):
t = t + t**(t+3)
from timeit import default_timer as clock
from symengine import sympify
t1 = clock()
p = str(t)
t2 = clock()
sympy_time = t2-t1
print(t2-t1)
t1 = clock()
t = sympify(t)
p = str(t)
t2 = clock()
print(t2-t1)
symengine_time = t2-t1
print(sympy_time / symengine_time)
-(4.15725*B2_BCC2VA*T*Piecewise((-1.00000000000000, 0.5*B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*Piecewise((2.22000000000000, And(T < 6000.0, T >= 298.15)), (0, True)) <= 0), (1.00000000000000, True))*Piecewise((2.22000000000000, And(T < 6000.0, T >= 298.15)), (0, True))*Piecewise((B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(2*B2_BCC0AL - B2_BCC0FE + 2*B2_BCC1AL - B2_BCC1FE)*(0.0028689064946125*T**15/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**16 + 0.00765041731896667*T**9/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**10 + 0.05737812989225*T**3/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**4 - 0.113162422843049/T)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True))*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)), T/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01) < 1), (-B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**4*(0.0401082005013337 + 0.00381982861917464*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**10/T**10 + 0.00133694001671112*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**20/T**20)*(2*B2_BCC0AL - B2_BCC0FE + 2*B2_BCC1AL - B2_BCC1FE)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True))*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True))/T**5, True))/(0.5*B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*Piecewise((-1.00000000000000, 0.5*B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*Piecewise((2.22000000000000, And(T < 6000.0, T >= 298.15)), (0, True)) <= 0), (1.00000000000000, True))*Piecewise((2.22000000000000, And(T < 6000.0, T >= 298.15)), (0, True)) + 1) + B2_BCC2VA*(0.125*(B2_BCC0AL + B2_BCC1AL)*Piecewise((2945.20000000000, And(T < 6000.0, T >= 298.15)), (0, True)) - 0.125*(B2_BCC0FE + B2_BCC1FE)*Piecewise((2945.20000000000, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.125*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((2945.20000000000, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.25*Piecewise((31.9888*T - 122960.0, And(T < 6000.0, T >= 298.15)), (0, True))) + 0.5*B2_BCC2VA*Piecewise((-14300.9572000000, And(T < 6000.0, T >= 298.15)), (0, True)) + 8.3145*T*Piecewise((B2_BCC2VA*(-0.0459025039138*B2_BCC2VA*T**15*(B2_BCC0FE + B2_BCC1FE)*(-0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0FE + B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*(2*B2_BCC0AL - B2_BCC0FE + 2*B2_BCC1AL - B2_BCC1FE)/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**17 - 0.0765041731896667*B2_BCC2VA*T**9*(B2_BCC0FE + B2_BCC1FE)*(-0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0FE + B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*(2*B2_BCC0AL - B2_BCC0FE + 2*B2_BCC1AL - B2_BCC1FE)/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**11 - 0.229512519569*B2_BCC2VA*T**3*(B2_BCC0FE + B2_BCC1FE)*(-0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0FE + B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*(2*B2_BCC0AL - B2_BCC0FE + 2*B2_BCC1AL - B2_BCC1FE)/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**5 + 0.005737812989225*T**15*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True))/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**16 + 0.0153008346379333*T**9*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True))/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**10 + 0.1147562597845*T**3*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True))/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**4 - 0.226324845686097*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True))/T)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)), T/(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01) < 1), (-B2_BCC2VA*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**3*(0.160432802005335*B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(-0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0FE + B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*(2*B2_BCC0AL - B2_BCC0FE + 2*B2_BCC1AL - B2_BCC1FE) + 0.0534776006684449*B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**10*(-0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0FE + B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*(2*B2_BCC0AL - B2_BCC0FE + 2*B2_BCC1AL - B2_BCC1FE)/T**10 + 0.0320865604010669*B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**20*(-0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0FE + B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*(2*B2_BCC0AL - B2_BCC0FE + 2*B2_BCC1AL - B2_BCC1FE)/T**20 + 0.0802164010026674*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.00763965723834927*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**11*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True))/T**10 + 0.00267388003342225*(B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True)))*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True)) + 0.01)**21*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((-1.00000000000000, B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*(0.125*(B2_BCC0AL + B2_BCC1AL)*(B2_BCC0AL - B2_BCC0FE + B2_BCC1AL - B2_BCC1FE)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True)) + 0.5*Piecewise((1043, And(T < 6000.0, T >= 298.15)), (0, True))) <= 0), (1.00000000000000, True))/T**20)*Piecewise((504, And(T < 6000.0, T >= 298.15)), (0, True))/T**5, True))*log(0.5*B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*Piecewise((-1.00000000000000, 0.5*B2_BCC2VA*(B2_BCC0FE + B2_BCC1FE)*Piecewise((2.22000000000000, And(T < 6000.0, T >= 298.15)), (0, True)) <= 0), (1.00000000000000, True))*Piecewise((2.22000000000000, And(T < 6000.0, T >= 298.15)), (0, True)) + 1))/(3.0*B2_BCC2VA - 4.0)
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-1-a6777b429aee> in <module>()
19 t = t.replace(lambda expr: isinstance(expr, Piecewise), func)
20 for _ in range(5):
---> 21 t = t + t**(t+3)
22
23 from timeit import default_timer as clock
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/decorators.py in __sympifyit_wrapper(a, b)
75 if not hasattr(b, '_op_priority'):
76 b = sympify(b, strict=True)
---> 77 return func(a, b)
78 except SympifyError:
79 return retval
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/decorators.py in binary_op_wrapper(self, other)
116 else:
117 return f(self)
--> 118 return func(self, other)
119 return binary_op_wrapper
120 return priority_decorator
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/expr.py in __pow__(self, other)
149 @call_highest_priority('__rpow__')
150 def __pow__(self, other):
--> 151 return Pow(self, other)
152
153 @_sympifyit('other', NotImplemented)
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/power.py in __new__(cls, b, e, evaluate)
192 if not e.is_Atom and b is not S.Exp1 and b.func is not exp_polar:
193 from sympy import numer, denom, log, sign, im, factor_terms
--> 194 c, ex = factor_terms(e, sign=False).as_coeff_Mul()
195 den = denom(ex)
196 if den.func is log and den.args[0] == b:
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in factor_terms(expr, radical, clear, fraction, sign)
1186 return rv
1187 expr = sympify(expr)
-> 1188 return do(expr)
1189
1190
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1155 is_iterable or not hasattr(expr, 'args_cnc'):
1156 args = expr.args
-> 1157 newargs = tuple([do(i) for i in args])
1158 if newargs == args:
1159 return expr
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1155 is_iterable or not hasattr(expr, 'args_cnc'):
1156 args = expr.args
-> 1157 newargs = tuple([do(i) for i in args])
1158 if newargs == args:
1159 return expr
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1155 is_iterable or not hasattr(expr, 'args_cnc'):
1156 args = expr.args
-> 1157 newargs = tuple([do(i) for i in args])
1158 if newargs == args:
1159 return expr
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1155 is_iterable or not hasattr(expr, 'args_cnc'):
1156 args = expr.args
-> 1157 newargs = tuple([do(i) for i in args])
1158 if newargs == args:
1159 return expr
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1155 is_iterable or not hasattr(expr, 'args_cnc'):
1156 args = expr.args
-> 1157 newargs = tuple([do(i) for i in args])
1158 if newargs == args:
1159 return expr
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1155 is_iterable or not hasattr(expr, 'args_cnc'):
1156 args = expr.args
-> 1157 newargs = tuple([do(i) for i in args])
1158 if newargs == args:
1159 return expr
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1182 elif p.args:
1183 p = p.func(
-> 1184 *[do(a) for a in p.args])
1185 rv = _keep_coeff(cont, p, clear=clear, sign=sign)
1186 return rv
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1182 elif p.args:
1183 p = p.func(
-> 1184 *[do(a) for a in p.args])
1185 rv = _keep_coeff(cont, p, clear=clear, sign=sign)
1186 return rv
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1182 elif p.args:
1183 p = p.func(
-> 1184 *[do(a) for a in p.args])
1185 rv = _keep_coeff(cont, p, clear=clear, sign=sign)
1186 return rv
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1182 elif p.args:
1183 p = p.func(
-> 1184 *[do(a) for a in p.args])
1185 rv = _keep_coeff(cont, p, clear=clear, sign=sign)
1186 return rv
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1155 is_iterable or not hasattr(expr, 'args_cnc'):
1156 args = expr.args
-> 1157 newargs = tuple([do(i) for i in args])
1158 if newargs == args:
1159 return expr
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1155 is_iterable or not hasattr(expr, 'args_cnc'):
1156 args = expr.args
-> 1157 newargs = tuple([do(i) for i in args])
1158 if newargs == args:
1159 return expr
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1182 elif p.args:
1183 p = p.func(
-> 1184 *[do(a) for a in p.args])
1185 rv = _keep_coeff(cont, p, clear=clear, sign=sign)
1186 return rv
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1182 elif p.args:
1183 p = p.func(
-> 1184 *[do(a) for a in p.args])
1185 rv = _keep_coeff(cont, p, clear=clear, sign=sign)
1186 return rv
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1162 cont, p = expr.as_content_primitive(radical=radical, clear=clear)
1163 if p.is_Add:
-> 1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1182 elif p.args:
1183 p = p.func(
-> 1184 *[do(a) for a in p.args])
1185 rv = _keep_coeff(cont, p, clear=clear, sign=sign)
1186 return rv
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <listcomp>(.0)
1182 elif p.args:
1183 p = p.func(
-> 1184 *[do(a) for a in p.args])
1185 rv = _keep_coeff(cont, p, clear=clear, sign=sign)
1186 return rv
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in do(expr)
1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
-> 1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
1167 cont = -cont
1168 list_args = [-a for a in list_args]
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/exprtools.py in <genexpr>(.0)
1164 list_args = [do(a) for a in Add.make_args(p)]
1165 # get a common negative (if there) which gcd_terms does not remove
-> 1166 if all(a.as_coeff_Mul()[0] < 0 for a in list_args):
1167 cont = -cont
1168 list_args = [-a for a in list_args]
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/numbers.py in __lt__(self, other)
1853 def __lt__(self, other):
1854 try:
-> 1855 other = _sympify(other)
1856 except SympifyError:
1857 raise TypeError("Invalid comparison %s < %s" % (self, other))
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/sympify.py in _sympify(a)
353
354 """
--> 355 return sympify(a, strict=True)
356
357
/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/sympy/core/sympify.py in sympify(a, locals, convert_xor, strict, rational, evaluate)
239 pass
240 try:
--> 241 cls = a.__class__
242 except AttributeError: # a is probably an old-style class object
243 cls = type(a)
KeyboardInterrupt:
In [3]:
import pycalphad
from pycalphad.tests.datasets import ALFE_TDB
from pycalphad import Database, Model
import pycalphad.variables as v
from sympy import Piecewise, Function
dbf = Database(ALFE_TDB)
mod = Model(dbf, ['AL','FE', 'VA'], 'B2_BCC')
t = mod.ast
def func(x):
f = Function('f')
a = []
for t in x.args:
a.append(t[0])
return f(*a)
t = t.replace(lambda expr: isinstance(expr, Piecewise), func)
from timeit import default_timer as clock
from symengine import sympify, diff
t1 = clock()
p = str(t.diff(v.Y('B2_BCC', 1, 'AL'), v.Y('B2_BCC', 0, 'FE')))
t2 = clock()
print(t2-t1)
sympy_time = t2-t1
t1 = clock()
t = sympify(t)
p = str(t.diff(v.Y('B2_BCC', 1, 'AL')).diff(v.Y('B2_BCC', 0, 'FE')))
t2 = clock()
print(t2-t1)
symengine_time = t2-t1
print(sympy_time/symengine_time)
2.1349420790002114
0.11995693399967422
17.797571243409816
In [ ]:
Content source: richardotis/pycalphad-sandbox
Similar notebooks: