[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-developer] How to do generic sum using aldor?
From: |
Ralf Hemmecke |
Subject: |
Re: [Axiom-developer] How to do generic sum using aldor? |
Date: |
Thu, 04 Jan 2007 09:42:15 +0100 |
User-agent: |
Thunderbird 1.5.0.9 (X11/20061206) |
On 01/04/2007 08:34 AM, Gernot Hueber wrote:
You also can use reduce. E.g. reduce(+, [1,2,3])
Gernot
Yes, but be careful. The documentation in Collection(S) (aggcat.spad) says:
reduce: ((S,S)->S,%) -> S
++ reduce(f,u) reduces the binary operation f across u. For example,
++ if u is \axiom{[x,y,...,z]} then \axiom{reduce(f,u)} returns
++ \axiom{f(..f(f(x,y),...),z)}.
++ Note: if u has one element x, \axiom{reduce(f,u)} returns x.
++ Error: if u is empty.
Franz has a bit more information on S. He knows that it is at least a
Ring, so "sumlist []" will return 0. Otherwise one would have to use
reduce: ((S,S)->S,%,S) -> S
++ reduce(f,u,x) reduces the binary operation f across u, where x is
++ the identity operation of f.
++ Same as \axiom{reduce(f,u)} if u has 2 or more elements.
++ Returns \axiom{f(x,y)} if u has one element y,
++ x if u is empty.
++ For example, \axiom{reduce(+,u,0)} returns the
++ sum of the elements of u.
Ralf