I am trying to define a constant in SymPy with the same functionality as constants like pi, e, and i. When exact answers are given, they remain as their symbols, instead of evaluating to their values. For instance if I ran
2*pi
it would return 2⋅π. If I wanted an approximate answer, I could run
N(2*pi)
which returns 6.28318530717959.
What I want is to define a constant, tau, where
tau
returns τ, while
N(tau)
returns 6.28318530717959.
Basically I’m just trying to define a new symbol, τ, which is equal to 2⋅π.
You need to subclass
NumberSymbolin the same way thatPidoes it. Just copy-pasting the source code forPiand adding*2should be enough. Be aware that these objects are singleton classes and not instances.You should also read the pi manifesto 😉