bug-apl
[Top][All Lists]

Re: [Bug-apl] ⍋ on complex data

 From: Juergen Sauermann Subject: Re: [Bug-apl] ⍋ on complex data Date: Sun, 06 Mar 2016 11:45:12 +0100 User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

```Hi,

the missing *DOMAIN ERROR* is fixed in *SVN 702*.

Sorting like in J has the disadvantage that equal (within ⎕CT) numbers can
be quite far away from each other in the result. And it introduces asymmetry
```
between the real and imag direction which is mathematically unsatisfactorily.
```
You could also argue that sorting by magnitude then by angle should be used.

For all these reasons DOMAIN ERROR seems to be the cleanest approach.

If you really want to sort complex numbers then you can sort a complex B
first by *11○* and the result by *9○*

*     B←4 2J2 3 3J3 5**
**      B1[⍋9○B1←B[⍋11○B]]**
**2J2 3 3J3 4 5*

/// Jürgen

On 03/05/2016 03:50 PM, Louis de Forcrand wrote:
```
```Hmm. In J they are sorted first by real part, then by imaginary part.

Louis

```
```
```
```
Complex numbers are incomparable in mathematical sense. In Dyalog APL
this leads to DOMAIN ERROR however.

```
This is the intended behaviour in GNU APL as well. This can be seen in the function Bif_F12_SORT::sort():
```
loop(bz, len_BZ)
{
array[bz] = &B->get_ravel(bz*comp_len);
if (array[bz]->is_complex_cell())
}

```
I believe the problem is that this function returns a Token instead of directly raising DOMAIN ERROR.
```
Regards,
Elias
```
```
```
```

```