Larry Wall wrote:
> On Tue, Jul 15, 2008 at 03:30:24PM +0200, Moritz Lenz wrote:
> : Today bacek++ implement complex logarithms in rakudo, and one of the
> : tests failed because it assumed the result to be on a different complex
> : plane. (log(-1i) returned 0- 1.5708i, while 0 + 3/2*1i was expected).
> :
> : Should we standardize on one complex plane (for example -pi <= $c.angle
> : < pi like Complex.angle does)? Or simply fix the test to be agnostic to
> : complex planes?
>
> Standardizing on one complex plane is the normal solution, though
> this being Perl 6, there's probably a better solution using infinite
> Junctions if we can assume them to be both sufficiently lazy and
> sufficiently intelligent... :)

By the principle of least surprise, I'd recommend against this.  Most
programmers, when they see 'sqrt(1)', will expect a return value of 1,
and won't want to jump through the hurdles involved in picking '1' out
of 'any(1, -1)'.  That said, I'm not necessarily opposed to these
functions including something like an ':any' or ':all' adverb that
causes them to return a junction of all possible answers; but this
should be something that you have to explicitly ask for.

And even then, I'm concerned that it might very quickly get out of
hand.  Consider:

  pow(1, 1/pi() ) :any - 1

(I think I got that right...)

Since pi is an irrational number, there are infinitely many distinct
results to raising 1 to the power of 1/pi.  (All but one of them are
complex numbers, and all of them have a magnitude of 1, differing only
in their angles.)  Thus, pow(1, 1/pi() ) :any would have to return a
junction of an indefinitely long lazy list.  Now subtract 1 from that
junction.  Do you have to flatten the list in order to do so,
subtracting one from each item in the list?  Or is there a reasonable
way to modify the list generator to incorporate the subtraction?

Or how about:

  sqrt(1):any + sqrt(1):any

--

In any case, there's the matter of what to do when you only want one
answer, and not a junction of them.  IMHO, we should standardize the
angles on '-pi ^.. pi'.  My reasoning is as follows: if the imaginary
component is positive, the angle should be positive; if the imaginary
component is negative, the angle should be negative.  If the imaginary
component is zero and the real component is not negative, the angle
should be zero.  And the square root of -1 should be i, not -i; so if
the imaginary component is zero and the real component is negative,
the angle should be positive, not negative.

-- 
Jonathan "Dataweaver" Lang

Reply via email to