[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-developer] axiom/aldor oddities
From: |
Ralf Hemmecke |
Subject: |
Re: [Axiom-developer] axiom/aldor oddities |
Date: |
Fri, 19 Jan 2007 17:04:04 +0100 |
User-agent: |
Thunderbird 1.5.0.9 (X11/20061206) |
Hello,
I also played a bit with your code, but I cannot quite give the same
reasoning as Martin.
On 01/19/2007 01:57 PM, Martin Rubey wrote:
Dear Franz,
I can only guess...
Franz Lehner <address@hidden> writes:
---BEGIN strange.as
#include "axiom"
FPI ==> Fraction Polynomial Integer;
tfpi1(d:Polynomial Integer,n:PositiveInteger): Fraction Polynomial Integer == {
import from Integer;
(1/factorial(n::Integer)^2)::FPI*d;
}
3B
* 1 is interpreted as an Integer (because of import from Integer)
The compiler actually has 3 choices
Polynomial Integer
Positive Integer
Fraction Polynomial Integer
since they appear in the input and output types of tfpi1. For the input
types I am pretty sure that Aldor automatically imports them. I am not
so sure with the output type, but that could be tested easily.
Unfortunately, I cannot point to the right place in the Aldor User
Guide, but (maybe) one cannot even clearly find it -- I simply don't
know by heart.
And there is a fourth choice coming from "import from Integer".
It is a bit hard now to look for a function /.
* factorial is interpreted as factorial: % -> % from Integer (again because of
the import from Integer)
* ^ ditto
* but there is no / in Integer. I have no idea which function the compiler
finds here.
Me too. Interestingly the compiler says
woodpecker:~/scratch>aldor -mno-mactext -mno-abbrev strange.as
"strange.as", line 9: (1/factorial(n::Integer)^2)::FPI*d;
...................................^
[L9 C36] #1 (Error) (After Macro Expansion) There are 2 meanings for the
operator `coerce'.
Meaning 1: Fraction(Integer) -> Fraction(Polynomial(Integer))
Meaning 2: Polynomial(Integer) -> Fraction(Polynomial(Integer))
Expanded expression was: Fraction(Polynomial(Integer))
If one additionally says "import from Fraction Integer;". That seems
like the coerce function is causing trouble.
Note that a::T should be equivalent to coerce(a)@T. But it does not tell
from which domain/package the coerce should come. I faintly remember
that I have resolved segfaults just by writing coerce(a) instead of a::T.
Unfortunately, the compiler is not saying where it finds meaning 1 and
2. So I cannot say what goes wrong. But what I dont understand is: why
is the second meaning an option for the compiler. How can it deduce the
type of 1/something to be Polynomial(Integer)???
What about
tfpi1(d:Polynomial Integer,n:PositiveInteger): Fraction Polynomial
Integer == {
import from Integer;
f: Z := factorial(n::Z);
q: Q := 1/f^2;
(q::FPI) * (d :: FPI);
}
It is never bad to add a bit of redundancy (namely the types). It's
easier for humans and it helps the compiler.
Ralf