In sympy, I want to create a constant e.g. to represent the speed of light.
Thus I initialize c
with the keyword constant=True
.
Later I want to check, if a symbol is a constant or a variable.
Unexpectedly the command c.is_constant()
outputs False.
c = Symbol( 'c' , constant=True, real=True )
c.is_real # outputs True as expected.
c.is_constant() # outputs False. This is unexpected !
How can I check, if a symbol is a constant or a variable ?
is_constant
I see that it does not check theassumptions
. So setting that assumption as you do does not make a difference. From the docs it looks likeis_constant
makes more sense when applied to an expression than to a single symbol. Assumptions keywords are not constrained.foobar=True
is allowed, but only means something if I add some sort of test. – Smallagef( const*x ) = const*f( x )
, but I don't want to put something outside the brackets, if I face the product of two variables (NOT:f(yx)=y*f(x))
. Thus I want to check, ifx
,y
orconst
are constants or variables. – Lamaseryf
commutes with multiplication by some symbols but not others. – Mallissa