# (-x)^(1//2) gives error in Symbolics.jl

**URL:** https://discourse.julialang.org/t/x-1-2-gives-error-in-symbolics-jl/86523
**Category:** New to Julia
**Tags:** question
**Created:** [August 30, 2022, 12:10am UTC](https://discourse.julialang.org/t/x-1-2-gives-error-in-symbolics-jl/86523 "2022-08-30T00:10:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nasser](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@Nasser](https://discourse.julialang.org/u/Nasser)
#### Post date: [August 30, 2022, 12:10am UTC](https://discourse.julialang.org/t/x-1-2-gives-error-in-symbolics-jl/86523/1 "2022-08-30T00:10:28Z")

</div>

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
>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?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 30, 2022, 2:59am UTC](https://discourse.julialang.org/t/x-1-2-gives-error-in-symbolics-jl/86523/2 "2022-08-30T02:59:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Nasser](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@Nasser](https://discourse.julialang.org/u/Nasser)
#### Post date: [August 30, 2022, 3:31am UTC](https://discourse.julialang.org/t/x-1-2-gives-error-in-symbolics-jl/86523/3 "2022-08-30T03:31:23Z")

</div>

I just noticed this is actually similar to earlier problem I saw. I did not notice the error is same until now.

I already entered a bug report on it. Here is the link.

> <https://github.com/JuliaSymbolics/Symbolics.jl/issues/719>
>
> For reference: https://stackoverflow.com/questions/73522774/how-to-translate-csc…hx21-2-to-julia-symbolic-error-domainerror-with
> 
> I am adding this as issue just in case it is new. 
> 
> \`\`\`
> \>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\> (-csch(x)^2)^(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
> 
> julia\> 
> 
> 
> \`\`\`
> 
> However this works
> 
> \`\`\`
> julia\> sqrt((-csch(x)^2))
> sqrt(-(csch(x)^2))
> 
> \`\`\`
