I was going to enter an issue for this, but thought to ask first here in case I am not using Julia symbolic correctly as I am still learning it.
>julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.8.0 (2022-08-17)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> using Symbolics
julia> @syms x
(x,)
julia> (-x)^(1//2)
ERROR: DomainError with -1.0:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.
Stacktrace:
[1] throw_exp_domainerror(x::Float64)
@ Base.Math ./math.jl:37
[2] ^(x::Float64, y::Float64)
@ Base.Math ./math.jl:1003
[3] ^
@ ./promotion.jl:422 [inlined]
[4] ^
@ ./rational.jl:481 [inlined]
[5] unstable_pow
@ ~/.julia/packages/SymbolicUtils/qulQp/src/types.jl:801 [inlined]
[6] ^(a::SymbolicUtils.Mul{Number, Int64, Dict{Any, Number}, Nothing}, b::Rational{Int64})
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/qulQp/src/types.jl:1047
[7] top-level scope
@ REPL[3]:1
So how does one write (-x)^(1/2) in Julia, given that x is symbolic?
Note that sqrt(-x) gives no error. But the exponent can be any ratio of two integers and not just 1/2 as in this example. I know I need to use 1//2 and not 1/2 in Julia to make sure it does not convert to 0.5. Any thing I should have done?
btw this is not a Julia bug, this is a Symbolics bug, Julia has no built-in symbolic capability; I have changed the title to reflect you’re talking about Symbolics.jl