Is there a way to check if an expression contains complex expressions / imaginary numbers?
The documentation says that you can't check if an expression contains I because of how it is interpreted.
I have also tried ImaginaryQ[expr_] := expr != Conjugate[expr] and Simplify[expr] =!= Simplify[Conjugate[expr]], but it does not yield accurate results.
I have also tried to use MemberQ[expr, Complex], but that does not seem to work either.
I posted some examples into a notebook: http://www.eacousineau.com/download/complex-test.nb
How about
ImaginaryQ[expr_] := ! FreeQ[expr, _Complex]
Using it on two of your examples:
imExpr = a Sin[a + 2 I];
ImaginaryQ@imExpr
(* True *)
reExpr = a Sin[a^2 + a];
ImaginaryQ@reExpr
(* False *)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With