[Aldor-l] Collapse of function signatures

Christian Aistleitner tmgisi at gmx.at
Fri Jan 7 03:16:45 EST 2005


Hi Ralf,

>>>>> In DistributedMultivariatePolynomial1(R, V, E) there are two  
>>>>> functions
>>>>>        *: (Integer, %) -> %
>>>>>        *: (R, %) -> %
>> At present state, it is tricky (although possible) to "inherit" the   
>> desired functions.
> #include "algebra"
> extend DistributedMultivariatePolynomial1(
>    R: Ring,
>    V: VariableType,
>    E: ExponentCategory(V)
> ): with {
>    myItimes: (Integer, %) -> %;
>    myRtimes: (R, %) -> %;
> } == add {
>    myItimes(i: Integer, x: %): % == i*x;
>    myRtimes(r: R, x: %): % == r*x;
> }

Although I was thinking of something else (encapsulating the domains in  
order to be sure, that the * of r*x and the * of i*x refer to the same *),  
your version works :)
The * in i*x is bound to
   *: ( Integer, % ) -> %
, while the * in r*x is bound to
   *: ( R, % ) -> %
. I would have thought that the two functions would collapse again. For  
some reason, they do not. However, this version breaks some other things,  
as you already noted later on. If you get rid of using the exponent (which  
causes the errors), you can see, that it works. To get rid of it, replace
   x: A := monomial(exponent(1,0,0)$E)$A;
by
   import from List VARS, List Integer;
   x: A := term( 1$S, [ (variable$VARS) 1 ], [ 1$Integer ] );
.

> and later I use myItimes instead of * if I want to make sure that the  
> Integer version is used by the compiler. I wonder whether the compiler  
> behaves as I expect or whether it is smart enough to optimize myItimes  
> away so that the whole extension becomes useless.

Hopefully the compiler will never optimize myItimes away. I would not see  
a reason for optimizing it away. Although myRtimes and myItimes share the  
same signature, they have distinct names!
I would have thought that r*x and i*x would finally resolve to the same *  
function. However, they do not.

> ... but the above code would not help for the bug in xxx.as from  
> http://www.aldor.org/pipermail/aldor-l/2004-December/000001.html,  
> because there I multiply two polynomials.

Yes. But this is acutally dealing with the problem of collapsing  
functions. This, I guess, is the problem to adress in this thread.

> And it might happen during a long computation that I even don't know in  
> advance when the variable a will be equal to one. I cannot simply turn  
> a: A into a: Integer and use myItimes from above.

Yes, again I'd say this is definitely bug 1370. This bug should most  
likely be dealt with by the compiler team, since it seems to be a compiler  
issue. The only thing, that I can suggest is to extend  
DistributedMultivariatePolynomial1 with new
  *: ( %, % ) -> %
function. I will post this suggestion also as an answer to bug 1370.
Nevertheless, this is far from being convenient.
After all I would not suggest to use myRtimes or myItimes. Such issues  
should at all costs be hidden from the user. The user should always have a  
working * function. Hopefully the compiler team will fix this soon, so  
that a new algebra library can be built.

Best regards,
Christian

P.S.: The code by which i verified which function gets bound to which  
value. Note, that I changed E and V to EXP and VARS, since this cause some  
troubles. Furthermore, the multiplication functions do not do anything  
meaningfull, they just report, which function was called.


--xxx.as
--  aldor -grun -lalgebrad -laldord xxx.as

#include "algebra"

macro S == Integer;

import from TextWriter, String, Character, Symbol, MachineInteger;

extend DistributedMultivariatePolynomial1(
   R: Ring,
   V: VariableType,
   E: ExponentCategory(V)
): with {
   myItimes: (Integer, %) -> %;
   myRtimes: (R, %) -> %;
   *: ( Integer, % ) -> %;
   *: ( R, % ) -> % ;
   *: ( %, % ) -> % ;
} == add {
   (*)( a: R, b: % ): % == {
       stdout << "[R*%]";
       0;
   }
   (*)( a: Integer, b: % ): % == {
       stdout << "[Integer*%]";
       0;
   }
   (*)( a: %, b: % ): % == {
       stdout << "[%*%]";
       0;
   }
   myItimes(i: Integer, x: %): % == i*x;
   myRtimes(r: R, x: %): % == r*x;
}

main(): () == {
     import from TextWriter, String, Character, Symbol, MachineInteger;
     VARS == OrderedVariableTuple(-"x",-"y",-"z");
     EXP == MachineIntegerDegreeLexicographicalExponent(VARS);
     A == DistributedMultivariatePolynomial1(S, VARS, EXP );
     import from List VARS, List Integer;
     x: A := term( 1$S, [ (variable$VARS) 1 ], [ 1$Integer ] );
     a: A := 1;

     stdout << "myI: " << myItimes(1$Integer,x) << newline; flush! stdout;
     stdout << "myR: " << myRtimes(1$Integer,x) << newline; flush! stdout;
     stdout << "x*a: " << x*a << newline; flush! stdout;
     stdout << "a*x: " << a*x << newline; flush! stdout;
}

main();



More information about the Aldor-l mailing list