axiom-math
[Top][All Lists]
Advanced

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

[Axiom-math] Re: [Axiom-mail] Dynamically constructed return types


From: Martin Rubey
Subject: [Axiom-math] Re: [Axiom-mail] Dynamically constructed return types
Date: Thu, 13 Jan 2005 15:50:53 +0100

Dear Marcus,

I looked a little at your code. Some comments and a "patch":

      localParam(p, n) ==
        K: CommutativeRing := Fraction Polynomial(PrimeField p)
        zero := 0::K
        var := new()$Symbol
        LS := UnivariateLaurentSeries(K, var, zero)
        x := monomial(1, -1)$LS
        for i in 1..n repeat
          a := new()$Symbol
          b := new()$Symbol
          rhs := a::K*x + b::K*x**3
--               ^^^^     ^^^^
--               ||||     ||||
-- I think that this is not what you intend: do you realy want that the
-- coefficients of rhs are polynomials?
--
          f: Stream K := coefficients taylorRep rhs

-- here you get [%a, 0, %b] ... 
-- I added the type to make things clearer

          d := degree rhs

-- here you get -3

          -- Reduce the pole to minimal possible order.
          while negative? d and zero? (d rem p) repeat

-- so this is going to be executed only if p equals 3

            eq := monomial(1,p)$SUP(K) - monomial(first f, 0)$SUP(K)
            L: CommutativeRing := SimpleAlgebraicExtension(K, SUP K, eq)
            f1 := map(#1::L, f)$StreamFunctions2(K,L)
            -- subtract w^p-w from f1
            f1.1 := 0
            j := 1 + (d quo p) - d
            f1.j := f1.j + (basis()$L).p
            while (negative? d and zero? first f1) repeat
              f1 := rest f1
              d := d+1

           K := L
           f: Stream(K) := f1 pretend Stream K
-- here's the "patch"         ^^^^^^^
-- axiom cannot believe that f1 is really of type Stream K, so I tell it...
-- maybe this screws things up completely, but it might work, too. I don't
-- know. Needs testing.

         res:Any := coerce(first(f))$ANY1(K)

         return res

Thanks for your explanations, it is clearer now!

Marcus Better writes:

 > This gives the following compiler warning:
 > ---------------------------------------------
 >     Warnings:
 >        [1] localParam: domain valued variable K has been reassigned 
 > within its scope
 > ---------------------------------------------

It's a sensible warning, of course, but I don't know its relevance.  Maybe this
is related to the following -- from aldorug.pdf, page 77:

Name constancy As a related but more fundamental concern, an expression in type
               context must only contain names which are constant over the
               scope in which the type occurs, because, without this rule, it
               would not be possible to associate well-defined types to
               expressions.

               Consider the following incorrect function, which uses a domain
               called MachineIntegerMod (see AXIOMimodnSample for a definition)
               which is parameterised by an Integer:

                    f(n: Integer): () == {
                            local a, b: MachineIntegerMod(n);
                            a := coerce((3 * n + 1) quo 2);
                            b := coerce((5 * n + 1) quo 3);
                            if n > 4 then    n := n + 1;   -- ILLEGAL!
                            c := a - b;
                            stdout << "The result is " << c << newline
                    }

               The problem is that if n is updated, the type of a and b is no
               longer valid and there is no reasonable interpretation for "-"
               or "c".  The names appearing in an expression in type context
               may be
                   · defined via "==",
                   · imported via "import", or
                   · function parameters which are nowhere updated.

Martin





reply via email to

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