4

Fyi, Just in case this is a bug in Julia symbolic, added new issue at https://github.com/JuliaSymbolics/Symbolics.jl/issues/719


I am trying to translate the following. In Mathematica

enter image description here

In Maple:

enter image description here

To Julia symbolics. Where csch is hyperbolic cosecant function and x is syms. But Julia gives an error on (-csch(x)^2)^(1//2) but no error on (csch(x)^2)^(1//2)

Here is the code

>julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.3 (2022-05-06)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |

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] ^
   @ ./math.jl:909 [inlined]
 [3] ^
   @ ./promotion.jl:413 [inlined]
 [4] ^
   @ ./rational.jl:479 [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

I noticed however that this works

julia> sqrt(-csch(x)^2)
sqrt(-(csch(x)^2))

But in my case, the exponents are not always 1/2 and so this is not a workaround for me. For example, I could have (-csch(x)^2)^(1//3) and so on. But it is strange that it accepts sqrt and not ^(1//2) in this example.

What exactly is the issue and is there a workaround?

Nasser
  • 12,849
  • 6
  • 52
  • 104
  • 1
    I assume it's trying to evaluate`(-1)^(1//2) * (csch(x)^2)^(1//2)`. `((-1+0im)*csch(x)^2)^(1//2)` works (not a very elegant solution though...) – August Aug 31 '22 at 01:32

0 Answers0