Okay so:
julia> using Symbolics
[ Info: Precompiling Symbolics [0c5d862f-8b57-4792-8d23-62f2024744c7]
julia> Term(sqrt, [2])
ERROR: UndefVarError: Term not defined
Stacktrace:
[1] top-level scope at REPL[1]:1
julia> Symbolics.Term(sqrt,[2])
sqrt(2)
Am I supposed to spell the using
differently to make Term
accessible (apart from just using Symbolics: Term
)?
It seems that Term
works more or less as I would expect for element:
julia> expr = Term(sqrt,[2])
sqrt(2)
julia> expr * expr
sqrt(2)^2
julia> expr * expr + 1
1 + sqrt(2)^2
julia> @syms x
(x,)
julia> expr2 = x + expr
x + sqrt(2)
However if I now substitute an exact value for x
I get a floating-point result:
julia> substitute(expr2, Dict([x => 0]))
1.4142135623730951
How can I:
- Explicitly request for an expression like
sqrt(2)
to evaluate to an approximate floating point result with some specified precision/digits - Prevent the numerical evaluation when performing an exact substitution.
- Evaluate something like
sin(pi)
exactly.
(Feel free to point to any docs that explain this but I’ve skimmed them and I don’t see these things explained or any mention of Term
.)