[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-developer] CAS for the masses
From: |
Ralf Hemmecke |
Subject: |
Re: [Axiom-developer] CAS for the masses |
Date: |
Fri, 30 Mar 2007 08:28:59 +0200 |
User-agent: |
Thunderbird 2.0b2 (X11/20070116) |
On 03/30/2007 06:01 AM, Bill Page wrote:
Quoting Ralf Hemmecke <address@hidden>:
Bill Page wrote:
On the other hand Python does directly support building classes
at run time while domains and categories can only be defined at
compile-time in Axiom.
Could you elaborate on this (on the python and aldor side). Can you give
a small example what you think is possible in python that cannot be done
with aldor. At first glance I have my doubts that "domains can only be
defined at compile time in aldor". Already Aldor's ability to write
domain-constructing functions is a counter example. But you probably
meant something else.
You are right that I did not state this properly. Of course we can
evaluate expressions (including functions) that return domains
and categories. What I was trying to say is that domains in Spad
and Aldor are immutable during run-time.
I would agree in principle, but not in practice. Currently categories
are immutable and that might be a good thing if one reads the article
http://portal.axiom-developer.org/refs/articles/define.pdf
For domains your statement is basically true. That is the reason why the
compiler is allowed to create only one instance of Comple2(MyInteger)
even if that piece of code appears several several times in your program.
But aldor/spad allows to modify the domain. Here some piece of code
which even uses this in the Axiom algebra library:
IntegerCombinatoricFunctions(I:IntegerNumberSystem): with
binomial: (I, I) -> I
++ \spad{binomial(n,r)} returns the binomial coefficient
++ \spad{C(n,r) = n!/(r! (n-r)!)}, where \spad{n >= r >= 0}.
++ This is the number of combinations of n objects taken r
++ at a time.
[... left out some exports ...]
== add
[... left out some code ...]
B : Record(Bn:I, Bm:I, Bv:I) := [0,0,0]
[... left out some code ...]
binomial(n, m) ==
s,b:I
n < 0 or m < 0 or m > n => 0
m = 0 => 1
n < 2*m => binomial(n, n-m)
(s,b) := (0,1)
if B.Bn = n then
B.Bm = m+1 =>
b := (B.Bv * (m+1)) quo (n-m)
B.Bn := n
B.Bm := m
return(B.Bv := b)
if m >= B.Bm then (s := B.Bm; b := B.Bv) else (s,b) := (0,1)
for k in convert(s+1)@Z .. convert(m)@Z repeat
b := (b*(n-k::I+1)) quo k::I
B.Bn := n
B.Bm := m
B.Bv := b
You could argue that B is a local variable. But then define it with ==
to be a constant and export it. Since "B.Bn := n" is a destructive
operation, one can also modify constants.
In Aldor-Combinat I even have to use this destructiveness in order to
allow recursive definitions of combinatorial species a la
B == X + B*B
internally that first defines a (dummy) constant for the value of the
exported symbol
generatingFunction
of the domain B, and immediately (at instantiation time of B) fills it
with appropriate data. So the code inside the + and * constructor looks like
generatingSeries: ExponentialGeneratingSeries == new();
set!(
generatingSeries $ %,
generatingSeries $ F(L) * generatingSeries $ G(L)
);
where F and G are equal to B for the above equation.
Again, since this set! function is destructive, I can apply it even
later, after the creation of the domain B. In that sense I would at
least modify an attribute of the domain.
However, you are right in the sense that what I just described is not
the most common usage of a domain. And I would even argue, to avoid that
option unless you have *very* good reason to use it. (I had, since
otherwise recursion were impossible.
But anyway that brings me to yet another example.
Didn't we have a running example of Even and Odd?
This here only shows a problem.
http://wiki.axiom-developer.org/MutualRecursion
But it's rather a minor problem, I guess.
>> System error:
Cannot rename the file #p"EVEN.erlib" to #p"EVEN.NRLIB".
I have also found
http://wiki.axiom-developer.org/SandBoxAldorSemantics
but maybe that is a bit too much for a contact between Aldor and Python.
Once constructed their "value" is constant and can not be changed.
Are my examples convincing, that this is not true in general.
> For example we
can not insert or remove anything in the list of exports or even
replace one exported function with another during the execution
of the program. This is possible in Python.
This is on the category level. And it is true.
I also agree that after a definition
foo(x: %): % == ... some code ...
in a domain and the instantiation of that domain, it is impossible to
make that function to use other code. It might depend on some internal
state, though, as binomial above, but the function foo always executes
the same "... some code ...".
Note: I am not talking about the post facto library extension feature
in Aldor. 'extend' is a compile-time operation.
Then certainly 'extend' is possible in Python although not at compile-time.
In Python on the other hand new classes can be created dynamically.
See for example the method '__new__' in
With a bit of work one can also achieve arbitrarily many instances of
Complex2(Integer). I think one just has to wrap the creation by a function.
Ralf
- Re: [Axiom-developer] CAS for the masses, (continued)
- Re: [Axiom-developer] CAS for the masses, Ondrej Certik, 2007/03/28
- Re: [Axiom-developer] CAS for the masses, Ralf Hemmecke, 2007/03/28
- [Axiom-developer] Re: Advantage of Types and different representations, Martin Rubey, 2007/03/28
- Re: [Axiom-developer] CAS for the masses, Gabriel Dos Reis, 2007/03/28
- Re: [Axiom-developer] CAS for the masses, Ondrej Certik, 2007/03/28
- RE: [Axiom-developer] CAS for the masses, Bill Page, 2007/03/29
- Re: [Axiom-developer] CAS for the masses, Ondrej Certik, 2007/03/29
- RE: [Axiom-developer] CAS for the masses, Bill Page, 2007/03/29
- Re: [Axiom-developer] CAS for the masses, Ralf Hemmecke, 2007/03/29
- Re: [Axiom-developer] CAS for the masses, Bill Page, 2007/03/30
- Re: [Axiom-developer] CAS for the masses,
Ralf Hemmecke <=
- Re: [Axiom-developer] CAS for the masses, Martin Rubey, 2007/03/30
- Re: [Axiom-developer] CAS for the masses, Waldek Hebisch, 2007/03/30
- Re: [Axiom-developer] CAS for the masses, Bill Page, 2007/03/30
- Re: [Axiom-developer] CAS for the masses, Waldek Hebisch, 2007/03/30
- Re: [Axiom-developer] CAS for the masses, Gabriel Dos Reis, 2007/03/30
Re: [Axiom-developer] CAS for the masses, Bill Page, 2007/03/30