Symbolics.jl icon indicating copy to clipboard operation
Symbolics.jl copied to clipboard

TypeError: non-boolean (Num) used in boolean context with symbolic Julia

Open nasser1 opened this issue 2 years ago • 1 comments

I asked about this at https://stackoverflow.com/questions/73519459/typeerror-non-boolean-num-used-in-boolean-context-with-symbolic-julia-how-to and was suggested to open an issue. Getting an error on sqrt(-im+x) where x is variable using Symbolics.

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> @variables x
1-element Vector{Num}:
 x

julia> sqrt(-im+x)
ERROR: TypeError: non-boolean (Num) used in boolean context
Stacktrace:
 [1] sqrt(z::Complex{Num})
   @ Base ./complex.jl:501
 [2] top-level scope
   @ REPL[3]:1
variables x
julia> 

As was suggested in the link above, using @syms x instead of @variables x then the error goes away.

nasser1 avatar Aug 28 '22 21:08 nasser1

I got curious from the SO question. I've yet to find a single function that works for Complex[Num}, apart from abs

@variables z::Complex[Num}
abs(z)  # :) 
exp(z)  # :( 
sin(z)  # :( 
sqrt(z) # :( 

nor could i manage to register any function, even custom ones, that would work for Conplex[Num}

Micket avatar Sep 01 '22 00:09 Micket

Any news on this?:) I also just bumped into the same issue.

nmheim avatar Oct 10 '22 16:10 nmheim