1+SqrtI-Complex[1,Sqrt] should be zero. In fact,
ComplexExpand cannot reduce this to
What is going on here?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.Sign up to join this community
Many what's-going-on questions really just turn out to be people wanting a fix for their code. They just don't understand why it doesn't work. Given the simple code, maybe an explanation of how
Complex works is actually being sought.
There's pretty much the same problem with
1/Sqrt - Rational[1, Sqrt] and
1/2 - Rational[1., 2].
Complex[x, y] is not a valid expression unless
y are numbers, which is reflected in how
Complex[1, Sqrt] is typeset in the Front End. (
Sqrt is not a number either. It's a numeric expression. Compare
NumericQ[Sqrt].) Generally, you should construct a complex number with
Complex, somewhat like your first two terms. However,
1 + Sqrt I cannot be represented by a
Complex number in Mathematica. It can only be represented by a composite, complex-numeric expression.
Complex[x, y] to be valid,
y can be any numbers,
Rational or even
Complex parts will be automatically simplified:
Complex[Complex[1, 2], 1] (* 1 + 3 I *)
Another undocumented quirk is that if one part is
MachinePrecision, then both parts will be made
MachinePrecision (the docs show only numbers with both parts entered with machine precision):
Complex[1., 2] Complex[1., 2`500] Complex[1.`6, 2] (* may have mixed-precision non-MachinePrecision parts *) (* 1. + 2. I 1. + 2. I 1.00000 + 2 I *)
Under the everything-is-an-expression philosophy,
Complex[1, Sqrt] is treated as an expression, but not one with internally defined semantics apparently. So it is not combined with other numeric expressions as though it represented a complex number.
A valid number passes the
NumberQ test (as well as
Complex[1, Sqrt] // NumberQ Complex[1, 2] // NumberQ (* False True *)
Rational[x, y] to be valid,
y each have to be an
y nonzero, though
Rational[1, 0] will evaluate to