[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-math] Problem in compiling a function
From: |
Martin Rubey |
Subject: |
Re: [Axiom-math] Problem in compiling a function |
Date: |
17 Nov 2005 17:22:55 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Dear Fabio,
"Fabio S." <address@hidden> writes:
> I am having a problem in compiling a function and I would like to know how
> to fix it. My function takes two arguments which are supposed to be a
> nonnegative integer n and a prime p. I want the number to be considered
> modulo p. So, to make a very short (even if meaningless) example of the
> error, define
>
> f: (NNI,NNI) -> NNI
> f(n,p) ==
> x := n :: PF p
> x*x
> 2
>
> This works, but only in interpreted mode. Is there a way to modify it in
> order to have it compiled?
The interpreter message is
(14) -> f(3,7)
Cannot compile the declaration for x because its (possible partial)
type contains a local variable.
AXIOM will attempt to step through and interpret the code.
Compiling function f with type (NonNegativeInteger,
NonNegativeInteger) -> NonNegativeInteger
(14) 2
So apparantly, the code is compiled... (see the third message). Are you sure
that it's not (is it too slow?)
The spad compiler has no problem:
)abbrev package TEST Test
Test(): Exports == Implementation where
NNI ==> NonNegativeInteger
Exports == with
f: (NNI,NNI) -> NNI
Implementation == add
f(n,p)==
x := n :: PrimeField p
x*x
2
compiles without warning and works, too. So, to your original question I have
no answer, only a workaround. Sorry.
> What about if I want the result to be in PF p? For example, to have x*x as
> result (after deleting the last line, of course), changing
>
> f: (NNI,NNI) -> NNI
>
> into
>
> f: (NNI,NNI) -> PF
>
> works, but yelds another warning when loading.
This cannot work, and the interpreter says so, too:
Although PrimeField is the name of a constructor, a full type must
be specified in the context you have used it. Issue )show
PrimeField for more information.
In fact, this is (in my opinion) the main deficience of Axiom with respect to
Aldor. Dependent types are not supported, i.e., signutures like
f(p:NNI,n:NNI): PF p == something
are not allowed. In Aldor, they are. William Sit wrote a very long argument how
you can simulate dependent signatures in Axiom, but it will work only in the
interpreter. So maybe it is of use to you. See
http://page.axiom-developer.org/zope/mathaction/18AxiomDomainsAndAldorReturnTypes
The easy workoround is: don't declare your function...
Sorry about that,
Martin
PS: If you find somebody (maybe yourself) who would like to fix the
interpreter, some money would be available.