Sympy TypeError: cannot determine truth value of Relational when using sympy

前端 未结 1 433
[愿得一人]
[愿得一人] 2021-01-25 10:28

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)    
sy         


        
相关标签:
1条回答
  • 2021-01-25 10:57

    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.

    0 讨论(0)
提交回复
热议问题