Reputation: 11209
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?
Upvotes: 6
Views: 398
Reputation: 123
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.
Upvotes: 1
Reputation: 13131
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)
Upvotes: 4
Reputation: 10982
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)
Upvotes: 2