[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## [Axiom-math] Re: [Axiom-developer] Summing over a list

**From**: |
Martin Rubey |

**Subject**: |
[Axiom-math] Re: [Axiom-developer] Summing over a list |

**Date**: |
23 May 2007 15:50:39 +0200 |

**User-agent**: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |

Dear Alasdair,
(redirecting to axiom-math, where usage questions belong)
"Alasdair McAndrew" <address@hidden> writes:
>* Given two lists,for example:*
>* *
>* z:=[1,2,3,4,5,6]*
>* w:=[1,0,0,1,1,1]*
>* *
>* it seems that the sum of the pairwise product is obtained by*
>* *
>* reduce(+,[z.i*w.i for i in 1..6])3B*
yes. Or, if you prefer
reduce(+, [ez*ew for ez in z for ew in w])
or, if you are really thinking of the standard inner product
dot(z, w)
>* which is all very well. But why doesn't*
>* *
>* sum(z.i*w.i,i=1..6)*
>* *
>* work? I mean, sum(i^2,i=1..6) is fine.*
For a (very long) explanation see
http://wiki.axiom-developer.org/IndexedVariables
Short explanation: unlike Mma or Maple, in axiom evaluation is extremely
simple: first the arguments are evaluated, then the function. So, in your
case, first axiom tries to evaluate
z.i*w.i
and
i=1..6
but there is no operation elt (which the dot is syntactig sugar for) that takes
a list and a symbol -- try to type z.i into the interpreter! To make things
clearer, note that there *is* an operation "=" that takes a symbol and a
segment.
Hope that helps,
Martin

**[Axiom-math] Re: [Axiom-developer] Summing over a list**,
*Martin Rubey* **<=**