Skip to content Skip to sidebar Skip to footer

How To Assign Properties To Symbols In SymPy And Have Them In The Same Domain?

I want to extend the Symbols class in SymPy so that I can add a Boolean attribute. I’m able to accomplish this for a single symbol (see my question here, and also someone else�

Solution 1:

In your first example you put symbols in a list so you didn't zip x and y with the values 1, 4:

>>> Poly(x+y).evalf(subs=dict(zip(sympy.symbols('x, y'),[1,4])))
5.00000000000000

You will get the desired result if you use the same State symbols that you defined

>>> x=State('x', boolean_attr=True)
... y=State('y', boolean_attr=False)
... states_poly = Poly(x+y)
... states_poly.evalf(subs=dict(zip((x,y),[1,1])))
2.00000000000000

(In your proposed syntax you used States which was undefined. Even if it did work, such a routine wouldn't have put True for one boolean_attr and False for the other and since Symbols match on attributes, the substitution would have failed.)


Post a Comment for "How To Assign Properties To Symbols In SymPy And Have Them In The Same Domain?"