axiom-developer
[Top][All Lists]
Advanced

[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 13:36:15 +0100
User-agent: Thunderbird 1.5.0.9 (X11/20061206)

I read the excellent aldor user's guide and neglected the fact, that
it is written for the standalone version of aldor rather than the axiom version. Is there a similar manual for axiom+aldor other than
http://www.aldor.org/docs/HTML/chap18.html ?
Is this the right mailing list anyways?

Since you want to work with Axiom, I guess you are right here.

[snip]

Now to the real questions.
I was aware of reduce but did not use it because I actually wanted to write a "generic" sum function for "all" possible structures, including finite streams etc. on which reduce does not work.
The only way I found in axiom was

  last complete scan(0,+,somestream)

which looks rather insatisfactory.

I currently rather rely on what is provided in LibAldor+LibAlgebra and don't take things from LibAxiom, but that is personal taste.

It seems that you want

---BEGIN sum.as
#include "axiom"
macro {
        MyAdditiveMonoid == with {
                0: %;
                +: (%, %) -> %;
        }
}
SumPackage(M: MyAdditiveMonoid): with {
    sum: Generator M -> M;
} == add {
     sum(g: Generator M): M == {
         m: M := 0;
         for x in g repeat m := m+x;
         return m;
     }
}
---END sum.as

You would call that via

l: List Integer := [2,3,4]
sum generator l

You have probably read that "Generator" abstracts from the actual underlying datastructure and only relies on the fact that the elements are delivered in a linear fashion. The bad thing is: "Generator" is not available in an Axiom Session. And even worse, no Axiom domain provides a "generator" function for its elements. You always have to hide it inside an Aldor program. So your problem is probably not easily solvable. But that would be my Aldor approach.

What could be axiom equivalents of AdditiveType and BoundedFiniteDataStructureType?

I don't know of any "Bounded..." category in Axiom.

Then SumPackage(L:BoundedFiniteDataStructureType,R:AdditiveType)
with essentially the same code would do just any possible case.

Yep. But sorry to say: Axiom is weak in that respect (at least to my knowledge).

Ralf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]