We have:
1 + 2 I + 3 + 4 I // Head
Complex
and
1 + 2 I + 3/5 + 4/5 I // Head
Complex
But we get:
1 + 2 I + 3/Sqrt[5] + 4/Sqrt[5] I // Head
Plus
1 + 2 I + 3/Surd[5, 2] + 4/Surd[5, 2] I // Head
Plus
Questions:
- Why is this happening?
- 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.
N
would helps, but not so far. See my edit to the question. $\endgroup$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 anN
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$_?NumericQ
pattern that works just fine! But to mimic the behavior of the built-inArrow
, I think the definition should beComplexArrow[l : {__?NumericQ}] := Arrow[ReIm[l]]
. $\endgroup$