Skip to content Skip to sidebar Skip to footer

Sympy Typeerror: Cannot Determine Truth Value Of Relational When Using Sympy

I'm learning SymPy now. Here is the problem I got: x = symbols('x',real=True) h = symbols('h',real=True) f = symbols('f',cls=Function) sym_dexpr = f_diff.subs(f(x), x*exp(-x**2

Solution 1:

The problem is the sort you perform on patterns.

sorted(patterns, key=lambda t:t[w]) attempts to return patterns sorted by every item's value for the key w, yet these values can not be compared with each other.

Why is that? because they are "relational" values, means they depend on the values of the variable in them. Lets check:

>>> [t[w] for t in patterns]
[-h + x, -3*h + x, -2*h + x, x]

Is -h + x greater than -3*h + x or the other way around? well, that depends on what h and x are, and since SymPy can't determine the order of these values, you get an error.

Post a Comment for "Sympy Typeerror: Cannot Determine Truth Value Of Relational When Using Sympy"