axiom-math
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-math] Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re


From: Ralf Hemmecke
Subject: [Axiom-math] Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product.
Date: Tue, 23 Oct 2007 02:47:27 +0200
User-agent: Thunderbird 2.0.0.6 (X11/20070728)

On 10/22/2007 06:20 PM, Gabriel Dos Reis wrote:
On Mon, 22 Oct 2007, Bill Page wrote:

| | On 22 Oct 2007 10:16:33 -0500, wrote:
| > Bill Page writes:
| > ...
| > |
| > | I would like to consider what is?
| > |
| > |   1..9
| > |
| > | Right now in Axiom this is evaluated as a member of 'Segment
| > | PositiveInteger', i.e. the domain of all such segments. But in general
| > | I think I would prefer if '1..9' actually denoted a domain - a subset
| > | of the Positive Integers - with members 1, 2, 3 ... etc.

Bill, you don't want 1..9 to be a domain. Of course, you can have it if you really want, but that just sounds like a domain of the set (or list) of the first 9 numbers. What would be the exports of this domain?

| > Couold you elaborate on why `1..9' should denote a domain, and what
| > the benefits would be?
| >
| | Well, for one I could then write the cross-product of such domains: | | Product(1..9,1..4)

What would be its meaning?

Maybe this one....

>aldor -laldor -fx mycross.as
>mycross
1, 11
1, 12
2, 11
2, 12
3, 11
3, 12

One can certainly do with the LibAldor IntegerSegment instead of Segment(X), but I've just included it for illustration that ".." as well as "by" are just functions.

Ralf

---BEGIN mycross.as
#include "aldor"
#include "aldorio"

macro OrdMonoid == with {
    1: %;
    <=: (%, %) -> Boolean;
    +: (%, %) -> %;
}
Segment(T: OrdMonoid): with {
    ..: (T, T) -> %;
    by: (%, T) -> %;
    generator: % -> Generator T;
} == add {
    Rep == Record(lo: T, hi: T, st: T);
    import from Rep;
    (s: T) .. (t: T): % == per [s, t, 1];
    (x: %) by (t: T): % == per [rep(x).lo, rep(x).hi, t];
    generator(x: %): Generator T == generate {
        (l, h, s) := explode rep x;
        while l <= h repeat {
                yield l;
                l := l+s;
        }
    }
}

Product(A: OrdMonoid, B: OrdMonoid): with {
  *: (Segment A, Segment B) -> Generator Cross(A,B);
} == add {
  (x: Segment A) * (y: Segment B): Generator Cross(A,B) == generate {
    for a in x repeat for b in y repeat yield (a,b);
  }
}

Z ==> Integer;
main(): () == {
    import from Z, Product(Z, Z);
    s1: Segment Z := 1..3;
    s2: Segment Z := 11..12;
    for ab in s1 * s2 repeat {
        (a, b) := ab;
        stdout << a << ", " << b << newline;
    }
}

main();
---END mycross.as





reply via email to

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