This is about Symbolics.jl
I have a variableless symbolic expression wrap(Term(sqrt, [2]))
as a way to represent an irrational constant symbolically. But at some point I want to actually compute the floating point value for that symbolic expression. How do I do that? unwrap
or round
or Float64
do not seem to do it.
I don’t know if it’s the best solution, but I’ve used substitute
with an empty dictionary for similar cases:
julia> using Symbolics
julia> using BenchmarkTools
julia> @btime substitute(x,Dict()) setup=(x=Symbolics.wrap(Symbolics.Term(sqrt, [2])))
3.345 μs (26 allocations: 1.53 KiB)
1.4142135623730951
julia> @btime substitute(Symbolics.unwrap(x),Dict()) setup=(x=Symbolics.wrap(Symbolics.Term(sqrt, [2])))
3.010 μs (18 allocations: 992 bytes)
1.4142135623730951