axiom-math
[Top][All Lists]
Advanced

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

Re: [Axiom-math] Problem in compiling a function


From: Fabio S.
Subject: Re: [Axiom-math] Problem in compiling a function
Date: Mon, 21 Nov 2005 09:54:04 +0100 (CET)

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?)

Well, no, I am not sure, since I didn't test it with something more difficult. In any casy, I need this only for teaching purpose, so speed is not an issue, in this case: I just wanted to know if there was something trivial hidden somewhere in the over 1000 axiom manual pages which I was missing...

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.

If I were able to do it...  :-((

Thanks for your attention

Fabio




reply via email to

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