
From:  Elias Mårtenson 
Subject:  Re: [Bugapl] Scan operator has strange behaviour 
Date:  Wed, 19 Mar 2014 23:16:32 +0800 
On 20140319 21:22:04, Elias Mårtenson wrote:But it is!
> This can't possibly be correct?
Let me just quote relevant excerpt of ISO 13751:
> Z←f\B
(...)
> If B is a vector,
> If the count of B is lessthan two, return B.
> Otherwise return Z, a vector such that the shapelist of Z is the
> shapelist of B,
> and the ravellist of Z is such that item I of the ravellist of Z
> is f/B[⍳I] for
> all I in the indexset of the ravellist of B. The type of Z is
> the sufficienttype
> of the ravellist of Z under the type mixed.
(...)
> The evaluation sequence above describes a quadratic algorithm
> for scan. If the function f
> is associative, scan may be implemented with a linear algorithm.
So for Z←f/⍳10, evaluation sequence is as follows:
Z[1]←f/1
Z[2]←f/1 2
Z[3]←f/1 2 3
Z[4]←f/1 2 3 4
and so on.
If you analyse your output, you'll find that GNU APL follows this
definition. And without additional assumptions, it is not possible
to further reduce number of calls. Even if GNU APL somehow analysed
your function and found it the be associative, you still added a side
effect of printing arguments to it so it's not possible to optimise
it out without changing the (correct) behaviour.
k
[Prev in Thread]  Current Thread  [Next in Thread] 