[Top][All Lists]

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

Re: [Axiom-developer] Minimal Algebra

From: Ralf Hemmecke
Subject: Re: [Axiom-developer] Minimal Algebra
Date: Mon, 27 Mar 2006 12:26:31 +0200
User-agent: Thunderbird 1.5 (X11/20051201)

On 03/26/2006 02:58 PM, Francois Maltey wrote:
"Antoine Hersen" <address@hidden> writes:

While reading the Axiom in the class room message I got this idea.

What about starting with an almost blank Axiom, and re building up
everything in a naive and minimal but instructive way ?

How should one do it ?

That's a good question. I think, at the moment you cannot have an "almost blank Axiom". I guess the reason is that the interpreter assumes quite a lot of domains to exist.

For this use of the interpreter :
1/ it must be possible to describe shortly a consistent minimal language.

Francois, Axiom is a community project. It is nice that you ask, but if it is not there and nobody on the list volunteers then you are the natural first candidate to figure out how one could write such a manual.

2/ this kernel must be (almost) bug free

If you (or your students) don't volunteer for implementing that kernel, than I hope you at least volunteer to write a testsuite.

3/ this langage must contain pretty notions, even if they are news.

Be more specific and collect your wishes in a structured document that you submit to the list or add what you mean by "pretty notions" on the AxiomWiki (

4/ the documentation must exist and be short.

What would you suggest?

---------------// 1 //
Of corse axiom kernel has very pretty concepts.
I love stream, typed object, category, etc.
I think that the first point is  possible, but might be better.

one example of what I'm waiting :
List are fine for studying cartesian product of set as E^n.

If you think so. I would take "Tuple E" instead.

In mathématics we use cartesian products of differents set.
The other cas aren't so typed, so List are fine for it.

Well, if you look at the Aldor User Guide you would find "Cross" for your purpose. (I haven't found it in Axiom, though.)

But axiom is typed and a- List of Any aren't so interressing.
b- for output result axiom seems to use record
   so it seem logical to use record for input data.
but with record we must add the name of each field, and we can't easily coerce (E x F) x G and E x (F x G) in E x F x G.
   There is no function concat for record.

All though isomorphic the three sets are not identical. If you want a function from Cross(Cross(E, F), G) -> Cross(E, F, G) then you have to write one. Not everything comes for free.

c- turple is only a syntaxic notion.

d- The product domain is a good idea but only work for 2 sets.

I don't see this problem with mupad or maple because theses CAS aren't so typed.

So I'm waiting a constructor as [|x,y,z|] for E x F x G with functions as P.1, P.2, first, rest, etc. I don't like makeRecord because list have [....] and I expect a similar syntax. and neither makeRecord nor Product have hightlevel functions.

What comes to my mind here is a domain that comes with the old axllib library.

---- Dynamic objects (OO).
---- Copyright The Numerical Algorithms Group Limited 1991, 1992, 1993, 1994.

--#include "axllib"

+++ Object implements dynamic objects, pairing data values with
+++ associated domains.
+++ Author: AXIOM-XL library
+++ Date Created: 1992-94
+++ Keywords: object

Object(C: Category): with {
        object:         (T: C, T) -> %;
        avail:          % -> (T: C, T);
== add {
        Rep == Record(T: C, val: T);
        import from Rep;

        object  (T: C, t: T) : %        == per [T, t];
        avail   (ob: %) : (T: C, T)     == explode rep ob;

If you replace "axllib" by "aldor" that works, too. I think, even "axiom" should work.

If you want to see, how this is used, then look at

I somehow have the suspicion that Objects is just another way of putting different types together.

Of course, then now you can have "Array Object SetCategory", But you have to give the types explicitly as something like,

[object(Integer, 2), object(String, "abc")]$Array(Object SetCategory)

That is probably not what you want... but some other code I tried does not yet work, since I have not yet figured out how to access a tuple.

Write a file "" with the above (where you replace axllib by aldor) in it and the following code ...

MyCross(T: Tuple OutputType): with {
        bracket: T -> %;
        apply: (%, n: MachineInteger) -> Object OutputType;
} == add {
        Rep == Array Object OutputType;
        import from Rep, Object OutputType;
        len: MachineInteger == length T;

        [t: T]: % == {
                r: Rep := new(len);
                for i:MachineInteger in 1..len repeat {
                        Ti == element(T,i);
                        ti := element(t pretend Tuple OutputType,i) pretend Ti;
                        r.i := object(Ti, ti);
                per r;
        apply(x: %, n: MachineInteger): Object OutputType == rep(x).n;

printThing(tw: TextWriter)(T: OutputType, t: T): TextWriter == tw << t;
printObject(tw: TextWriter, o: Object OutputType): TextWriter == {
        printThing(tw)(avail o);

main(): () == {
        import from TextWriter, String, Character;
        import from Integer, String;
        CIS ==> MyCross(Integer, String);
        import from CIS;
        cis: CIS := [2, "str"];
        import from MachineInteger;
        oi := cis.1;
        os := cis.2;
        printObject(stdout << "INT: ", oi) << newline;
        printObject(stdout << "STR: ", os) << newline;


... then it compiles, but for me it says...
% aldor -Mno-mactext -fx -laldor
% Cross
Looking in MyCross((AldorInteger, String)) for bracket with code 342377615
Unhandled Exception: RuntimeError()
Export not found

Since I used some dangerous "pretend"s that might have been expected. Unfortunately, I don't yet know how to do it the right way. But as you see, there is no real reason why you couldn't writ

[2, "str"]

and get an element of  "Integer x String".

Today it's possible to have more complete language in an interpretor.
axiom have not post-fixed operator. I prefer 4! to factorial 4.

For that you have to extend the language. And especially "!" is a bit dangerous as a postfix operator, since there is the convention that names of functions end in ! if they work destructively on their arguments.

It's possible to compose functions without composition operator, but
it's less interessing. mupad and maple allows cos@@100 1.0 : the result is (cos (cos (cos... 1.0)))

Come on, you can define that yourself, can't you?

#include "axiom"

FunctionIteration(T: Type): with {
  ^: (T -> T, Integer) -> (T -> T);
} == add {
  (f: T -> T) ^ (n: Integer): T -> T == {
    import from Integer;
    n < 0 => throw error("only non-negative powers allowed");
    n = 0 => return((t: T): T +-> t);
    n = 1 => f;
    (t: T): T +-> (f^(n-1)) (f t);

Put that into a file "". Then open Axiom and say

f(n:Integer): Integer == 2*n

The result is 8. Isn't that more beautiful than f@@3(1)?

I am sure you are by now able to write a package that implements a function

*: ((T -> T), (T -> T)) -> (T -> T)

that implements the composition of two functions so that you could say, for example:

myfun := cos * sin
r: Float := myfun(1.0)

and which would be the same as "cos(sin(1.0))".

maple and mupad construct this list with 100 elements.
[[i,j] $i=1..10 $j=1..10]
with axiom I can't do with ONE call :
I must? use concat and create List List List Integer before concat
concat [[[i,j] for i in 1..10] for j in 1..10].

But could you do a parallel iteration in mupad or maple? Like

[[i,j] for i in [2,3,5,7,11] for j in 4..]

BTW...have you tried to take the following...

#include "axiom"

LList(T: Type): with {
        bracket: Generator List T -> List T;
} == add {
        import from List List T;
        bracket(g: Generator List T): List T == concat [g];
Then say

[[[i,j] for i in 1..10] for j in 1..10]

Don't always give up so easily. There is more beauty in the Aldor language than you think.

Hope that helps a bit.


reply via email to

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