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.
Symbolic Differentiation in Julia Now that we know how Julia expressions are built, we can design a very simple prototype system for doing symbolic differentiation in Julia. We’ll build up our system in pieces using some of the most basic rules of calculus: The Constant Rule: d/dx c = 0
This post is available as a Jupyter notebook here. Like most technical languages, Julia provides a variable constant for π. However Julia's handling is a bit special. pi π = 3.1415926535897 ... It can also be accessed via the unicode symbol (you can get it at the REPL or in a notebook via the TeX completion \pi followed by a tab)
Now, looking at http://pkg.julialang.org/ one could find more candidates to perform symbolic mathematics in julia: Julia Wrappers for SymEngine, a fast symbolic manipulation library, written in C++. a language for symbolic computations and mathematics, where, for the most part, "mathematics" means what it typically does for a scientist or engineer.
:x, the symbol denoting the variable x 1, the number 1 represented as a 64-bit integer. A typwhich stores type inference information. We’ll ignore this information as it’s not relevant to us right now. Because each expression is built out of normal components, we can construct one piecemeal: julia> Expr(:call, {:+, 1, 1}, Any) :(+(1,1))
Try:
x = Symbolics.pi * Num(5)
print(x)
Here x
should be evaluated, hence pi
should be promoted.
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