Related to a previous question: I am using Julia Symbolics package and would like to represent 5*pi symbolically. I tried the following to no avail:
using Symbolics
5 * Symbolics.pi # expanded to 15.707963267948966
Num(5) * Symbolics.pi # expanded to 15.707963267948966
@variables x
Symbolics.pi * x # Gives πx, so it works with variables
Desired result, a symbolic expression using Symbolics.pi and the constant that are not numerically calculated on the spot but are kept as a product of 5 and π and show up as 5π, using Symbolics.pi.
Symbolics
supports such constructs. Any decent symbolic package should support things like π, e, and i by deferring evaluation until numeric execution. – Myrmecosin(Symbolics.pi)
isn't zero. SoSymbolics.pi
isn't π but the closest numeric approximation of it using IEEE 754 floating point. – MyrmecoSymEngine
then you the expected behaviorsin(SymEngine.PI)=0
. The same goes forsin(5*SymEngine.PI)=0
and alsosin(5000000*SymEngine.PI)=0
– MyrmecoSymbolics.pi
isBase.pi
. That is, there's not necessarily any Symbolics smarts to it at all just because you accessed it throughSymbolics.pi
. Since modules (by default) areusing Base
, non-symbolicsy things can be accessed by way ofSymbolics.name
. For example, trySymbolics.pwd()
or evenSymbolics.exit()
. You likely won't rally an answer on SO — even with a bounty — at least not yet. I'd start here. – Aircraftmanpi
itself works in Julia (without Symbolics). It'll remain irrational until you do something with it — like multiplying it by five or takin the sine — at which point it'll promote (likely to a Float64). Doingπ*x
is just stashing pi inside the term without actually doing the multiplication or a promotion (yet). – Aircraftman