Jon Lang wrote:
> 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 that's what they get unless they write it as sqrt(1 + 0i).

> and won't want to jump through the hurdles involved in picking '1' out
> of 'any(1, -1)'. 

1 and -1 aren't just separated by a complex plain, they are really
distinct numbers

> 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...)

Not quite. Afaict the only functions that might return a junction are
Complex.angle and Complex.log.

But having
   $compl.angle > pi
always yield True would be quite weird ;-)

> Since pi is an irrational number, there are infinitely many distinct
> results to raising 1 to the power of 1/pi.

No. exp($x) is a single, well-defined value.

>  (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?  

Obviously we'd have to avoid that if there's any infinite list/junction
involved somewhere ;-)

But you do have a point that we can't really use infinite junctions
unless we can ensure that we can do all sorts of arithmetics with it
without loosing lazyness. And I don't think we can prove that (but I
might give it it shot if I have some spare time)

> 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.

Moritz Lenz |

Reply via email to