0
$\begingroup$

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:

  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.

$\endgroup$
3
  • $\begingroup$ @Bill: I thought using N would helps, but not so far. See my edit to the question. $\endgroup$
    – murray
    Commented Sep 17, 2020 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
    Commented Sep 18, 2020 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
    Commented Sep 20, 2020 at 20:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.