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 NumberSymbol
in the same way that Pi
does it. Just copy-pasting the source code for Pi
and adding *2
should be enough. Be aware that these objects are singleton classes and not instances.
You should also read the pi manifesto ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With