Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent 5*π symbolically in Julia

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.

like image 448
Tarik Avatar asked Apr 18 '21 18:04

Tarik


People also ask

How do you do symbolic differentiation in Julia?

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

How do I find the value of Pi in Julia?

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)

What is the best programming language for symbolic mathematics in Julia?

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.

What does the symbol x1 mean in Julia?

: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))


1 Answers

Try:

x = Symbolics.pi * Num(5)
print(x)

Here x should be evaluated, hence pi should be promoted.

like image 75
Szabó Áron Avatar answered Nov 09 '22 05:11

Szabó Áron