We have:

     1 + 2 I + 3 + 4 I // Head


     1 + 2 I + 3/5 + 4/5 I // Head

But we get:

     1 + 2 I + 3/Sqrt[5] + 4/Sqrt[5] I // Head

     1 + 2 I + 3/Surd[5, 2] + 4/Surd[5, 2] I // Head


  1. Why is this happening?
  2. What can be done so that the latter two complex expressions in fact result in a Complex head?

Purpose: I'm trying to use functions defined in the form

func[{a_Complex, b_Complex}]:= ...

where they are to be used with arguments built up from complex numbers, e.g.,

func[{1+2I, 1 + 2 I + 3/Sqrt[5] + 4/Sqrt[5] I}]

Edit: Start, for example, with:

complexArrow[{a_Complex, b_Complex}] := Arrow[ReIm[{a, b}]]

which will not work for the kind of argument shown above, built up from complex numbers. Even if this is modified to...

complexArrow[{a_Complex, b_Complex}] := Arrow[ReIm[{N[a], N[b]}]]

...still the following does not work:

complexArrow[{2 + 2 I, 2 + 2 I + 1/Sqrt[2] + 1/Sqrt[2] I}]

Note: I'm trying to define a function for complex arrows analogous to those suggested in https://mathematica.stackexchange.com/a/230280/148. The same problem already arises with complexLine, among the other functions, proffered there.

  • $\begingroup$ If you look at FullForm[1 + 2 I + 3 + 4 I] you will see Complex[4,6] showing that the automatic shallow simplification of input has performed the addition making all that into a single complex number. If you look at FullForm[1+2 I+3/Sqrt[5]+4/Sqrt[5] I] you will see that the automatic shallow simplification of input has not turned that into a single complex number. Does this help: N[1 + 2 I + 3/Sqrt[5] + 4/Sqrt[5] I]] $\endgroup$ – Bill Sep 17 at 20:00
  • $\begingroup$ @Bill: I thought using N would helps, but not so far. See my edit to the question. $\endgroup$ – murray Sep 17 at 20:41
  • $\begingroup$ @Bill: Yes, N works there. But I'd like a robust function even an inexperienced user could apply, without the fuss of knowing you have to insert an N wrapper sometimes in the actual argument; I'm hoping, somehow, that this can be taken care of in the function definition, by the way it handles the formal argument. $\endgroup$ – murray Sep 18 at 19:43
  • $\begingroup$ @Bill: Yes, using the _?NumericQ pattern that works just fine! But to mimic the behavior of the built-in Arrow, I think the definition should be ComplexArrow[l : {__?NumericQ}] := Arrow[ReIm[l]]. $\endgroup$ – murray Sep 20 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.