A little challenge...
Robert Jacques
sandford at jhu.edu
Fri Feb 26 17:53:28 PST 2010
On Fri, 26 Feb 2010 03:58:59 -0500, Norbert Nemec
<Norbert at nemec-online.de> wrote:
> Robert Jacques wrote:
>> Well there is std.algorithm's map and reduce. Somehow, I feel slicing,
>> ranges/generators and array expressions should be able to handle this.
>> For example: \sum_i i*a_i*b_i-1 => sum(iota * a * b[1..$]) But then
>> again I'm having trouble thinking of real examples off the top of my
>> head.
>
> In fact, that is the way you would do it in e.g. Python/NumPy. It works
> fine for many common cases but does not scale up to more complex
> situations. The mathematical sum notation scales up arbitrarily and
> remains clear.
>
> I would want to offer both options and leave it to the user to choose
> the more appropriate notation.
That sounds sensible. However, extensive experience in Matlab has taught
me that resorting to custom for-loop indicates you've failed to
sufficiently think in arrays. :)
Take, for example, your composition example from the other thread:
sum(i)( a[i] * sum(j)(b[i,j]*c[j]) ) => sum(a.*(b'*c)) or
a.*sum(b.*(c*ones(1,length(c)))) ,1)
or something like that. (As an aside, having a more efficient syntax for
broadcasts, instead of having to use the outer product all the time, would
be nice)
Is there some example of a complex case you can post? I think we'll all
think of better solutions with a goal in sight.
More information about the Digitalmars-d
mailing list