How to change commutativity of a SymPy symbol after creation?
Suppose I create a SymPy symbol x
.
import sympy as sp
x = sp.Symbol('x', commutative = False)
How can I change the commutative assumption to True
without creating a new Symbol?
I tried
with sp.assuming( sp.Q.commutative(x) ):
print( sp.ask( Q.commutative(x) ) )
But it still gives False
.
See also questions close to this topic

I want to call Python in Node.js and use SymPy module
I use Node.js and Express as server side language.
And I made a website using AWS.I need to use Python because I need complicated calculations.
However, I don't know how to call Python from Node.js.Please tell me how to use Python's SymPy module in Node.js.

TypeError: __new__() takes exactly 3 arguments (2 given) when solving high degree equation in python
I am trying to solve a quadratic complex equation using solve in sympy, but I got something wrong like this: TypeError: new() takes exactly 3 arguments (2 given) . What can I do?
Here is the code
from sympy import * import numpy as np b = 1 c = 1 d = 2.0*D*k**2.0  D*(1.0+epsilon)*fg*k**2.0 + D*fg*k**4.0/eta**2.0 \  2.0*I*D*fg*k**2.0*kx  2.0*I*fg**2.0*(fd+fg)*k**2.0*kx*st/eta**2.0 \ + fg*st*(fd*k**2.0/eta**2.0 + 2.0*I*fg*kx*theta)  2.0*I*fg**2.0*kx*st* \ (fd*k**2.0/eta**2.0+2.0*I*fg*kx*theta) e = I*D**2.0*k**4.0  I*D**2.0*(1+epsilon)*fg*k**4.0 + I*fg*kz**2.0/eta**2.0\  2.0*D*(1.0+epsilon)*fg**2.0*(fd+fg)*k**2.0*kx*st + I*D*fg*k**2.0*st* \ (fd*k**2.0/eta**2.0 + 2.0*I*fg*kx*theta) f = D*fg*k**2.0*kz**2.0/eta**2.0 + 2.0*I*fg**2.0*(fd+fg)*kx*kz**2.0*st/eta**2.0 print solve( b*x**4.0 + c*x**3.0 + d*x**2.0 + e*x + f, x)
Here is the traceback:
Traceback (most recent call last): File "solve_cubic1.py", line 65, in <module> print solve( b*x**4.0 + c*x**3.0 + d*x**2.0 + e*x + f, x) File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/solvers/solvers.py", line 1125, in solve solution = nfloat(solution, exponent=False) File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/core/function.py", line 2465, in nfloat return type(expr)([nfloat(a, n, exponent) for a in expr]) File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/core/function.py", line 2499, in nfloat lambda x: isinstance(x, Function))) File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/core/basic.py", line 1087, in xreplace value, _ = self._xreplace(rule) File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/core/basic.py", line 1095, in _xreplace return rule[self], True File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/core/rules.py", line 59, in __getitem__ return self._transform(key) File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/core/function.py", line 2498, in <lambda> lambda x: x.func(*nfloat(x.args, n, exponent)), File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/core/function.py", line 2465, in nfloat return type(expr)([nfloat(a, n, exponent) for a in expr]) File "/Users/chenkan/anaconda/lib/python2.7/sitepackages/sympy/core/function.py", line 2465, in nfloat return type(expr)([nfloat(a, n, exponent) for a in expr]) TypeError: __new__() takes exactly 3 arguments (2 given)

Why does replacing a variable in a expression by variable with same name but different symbol name not work
How do I replace a variable in a function with a new definition of the initial variable ?
import sympy as sy g, a, x = sy.symbols("g a x") g = 5*a*x
Entering g in the interpreter at this point prints:
5*a*x.Now I would like to replace the printed a with an alpha. Why does the following not work?
a = sy.symbols("alpha") g = g.subs(a,a)
I am well aware that i could use the following:
import sympy as sy g, a, x = sy.symbols("g a x") g = 5*a*x alpha = sy.symbols("alpha") g = g.subs(a,alpha)
But I would like to understand why the former approach is not working. Generally I am interested how the assigned name a= and the string in symbols("a") are connected. Must they be the same for sympy to work correctly ?