I am looking for a way to represent a symbolic expression such as sqrt(3)*x
so as to avoid sqrt(3)
being calculated upfront.
Sample code:
using Symbolics
@variables x
y = sqrt(3)*x
Showing y, we can see that sqrt(3) has become a floating point.
Is there a mechanism to keep the sqrt in symbolic form?
The sqrt () is an inbuilt function in julia which is used to return the square root of the specified number and throws DomainError for negative Real parameter. It also accept complex negative parameter. x: Specified values. Returns: It returns the square root of the specified number and throws DomainError for negative Real parameter.
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
JuliaSymbolics is the Julia organization dedicated to building a fully-featured and high performance Computer Algebra System (CAS) for the Julia programming language. It is currently home to a layered architecture of packages: Layer 3: Symbolics.jl – A fast symbolic system designed for everyday symbolic computing needs. It features:
Like Lisp, the Julia interpreter represents Julian expressions using normal data structures: every Julian expression is represented using an object of type Expr.
is there a mechanism to keep the sqrt in symbolic form?
julia> using Symbolics
julia> @variables x
(x,)
julia> y = Symbolics.Term(sqrt,[3])*x
x*sqrt(3)
I cannot reproduce:
julia> using Symbolics
julia> @variables x
(x,)
julia> y = 1//3*x
(1//3)*x
julia> y
(1//3)*x
My config:
[0c5d862f] Symbolics v0.1.21
and
julia> versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Funny, y = 1//3 * x works, but not y = sqrt(3) * x as according to the orignal question. So, the answer from user Nasser is really helpful thanks.
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