[Top][All Lists]

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

Re: [Axiom-developer] Comments are wanted on for i in 1..1 repeatprint(

From: William Sit
Subject: Re: [Axiom-developer] Comments are wanted on for i in 1..1 repeatprint(sin(i) :: Complex Float)
Date: Thu, 13 Jan 2005 09:30:26 -0500

Vladimir Bondarenko wrote:
> -> for i in 1..1 repeat print(sin(i) :: Complex Float)
>    sin(1)

Hmm, we need to understand this a bit more:

for i in 1..1 repeat print(a:=sin(i)::Complex Float)
for i in 1..1 repeat print(a:=(sin(i)::Complex Float))

all give

0.8414709848 0789650665

At least that is a work-around.


for i in 1..1 repeat print((a:=sin(i))::Complex Float)


for i in 1..1 repeat (a:=sin(i); print(a::Complex Float))


print is from PrintPackage, which calls
print from OutputForm, which calls

but the problem lies in print inside a loop (any type, not just a for-loop). The
problem seems to be an interpreter problem in parsing. This is confirmed partly
by the following transcript.  When trying to code this as a package for the
compiler, it is not easy to figure out the sequence of functions to use to
coerce  sin(i) from EXPR INT to Complex Float. I finally found one way, but it
may not be what the interpreter is doing:

)abbrev package PRINTEST Printest
Printest: T==C where
  EXPR ==> Expression
  INT  ==> Integer
  CF   ==> Complex Float
  T == with
  C == add
       import EXPR INT
         for i in 1..k repeat 
           a:=sin(i::INT::Float::CF::EXPR CF)$(EXPR CF)
           print(retract(a)$(EXPR CF)@CF::OutputForm)

Of course it makes no difference whether a:= is eliminated or not. And this
works correctly. So my tentative conclusion is that the interpreter is "lazy" in
(1) to try to figure out this rather involved coercion sequence (Hey, I got it
to EXPR INT and I have no idea how to go further to Complex Float, I think it is
good enough ...:-), but in (2), it is somehow forced to work harder (Now you
want to save the result and I have to type the variable a, ok, ...). Is it a
bug? Don't know. There are limitations to the interpreter.

Tim: Do you know if there is a system limitation on the level of coercion the
interpreter will try before quitting? Can this be reset?

This example shows why a large percent of time (my low estimate is 70% and my
high is 90%) writing compiled code is spent on coercion. 

Now, there is still the question: why does this happen only inside a loop?
Can one tell more from the way the libraries are loaded (see attached
print.out)? Notice in print.out, even after foo(3) is executed, (2) still needs
to load another bunch of libraries. Why?

Start with a fresh session:
Note that neither Float nor Complex is loaded in (1), only in (2). More
surprisingly, UniversalSegment is also not loaded in (1). (it does not matter if
the segment is 1..1 or 1..3).

                        AXIOM Computer Algebra System
              Version of Tuesday November 30, 2004 at 21:11:14
   Issue )copyright to view copyright notices.
   Issue )summary for a summary of useful system commands.
   Issue )quit to leave AXIOM and return to shell.

(1) -> for i in 1..3 repeat print(sin(i)::Complex Float)
   Loading j:/Program Files/axiom/mnt/windows/algebra/EXPR.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/KERNEL.o for
      domain Kernel
   Loading j:/Program Files/axiom/mnt/windows/algebra/BOP.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/SCACHE.o for
      package SortedCache
   Loading j:/Program Files/axiom/mnt/windows/algebra/VOID.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/UPMP.o for
      package UnivariatePolynomialMultiplicationPackage
   Loading j:/Program Files/axiom/mnt/windows/algebra/AN.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/IAN.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/ACFS-.o for
      domain AlgebraicallyClosedFunctionSpace&
   Loading j:/Program Files/axiom/mnt/windows/algebra/FS-.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/COMMONOP.o for
      package CommonOperators
   Loading j:/Program Files/axiom/mnt/windows/algebra/KDAGG-.o for
      domain KeyedDictionary&
   Loading j:/Program Files/axiom/mnt/windows/algebra/DIAGG-.o for
      domain Dictionary&
   Loading j:/Program Files/axiom/mnt/windows/algebra/BOP1.o for
      package BasicOperatorFunctions1
   Loading j:/Program Files/axiom/mnt/windows/algebra/PRINT.o for
      package PrintPackage
   Loading j:/Program Files/axiom/mnt/windows/algebra/EF.o for package
   Loading j:/Program Files/axiom/mnt/windows/algebra/ACF-.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/ES-.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/BASTYPE-.o for
      domain BasicType&
   Loading j:/Program Files/axiom/mnt/windows/algebra/FRETRCT-.o for
      domain FullyRetractableTo&
   Loading j:/Program Files/axiom/mnt/windows/algebra/EVALAB-.o for
      domain Evalable&
   Loading j:/Program Files/axiom/mnt/windows/algebra/TRANFUN-.o for
      domain TranscendentalFunctionCategory&
   Loading j:/Program Files/axiom/mnt/windows/algebra/IEVALAB-.o for
      domain InnerEvalable&
   Loading j:/Program Files/axiom/mnt/windows/algebra/TRIGCAT-.o for
      domain TrigonometricFunctionCategory&
   Loading j:/Program Files/axiom/mnt/windows/algebra/ATRIG-.o for
      domain ArcTrigonometricFunctionCategory&
   Loading j:/Program Files/axiom/mnt/windows/algebra/HYPCAT-.o for
      domain HyperbolicFunctionCategory&
   Loading j:/Program Files/axiom/mnt/windows/algebra/ELEMFUN-.o for
      domain ElementaryFunctionCategory&
   Loading j:/Program Files/axiom/mnt/windows/algebra/RADCAT-.o for
      domain RadicalCategory&
   Loading j:/Program Files/axiom/mnt/windows/algebra/AF.o for package
   Loading j:/Program Files/axiom/mnt/windows/algebra/POLYROOT.o for
      package PolynomialRoots
   Loading j:/Program Files/axiom/mnt/windows/algebra/INTFACT.o for
      package IntegerFactorizationPackage
   Loading j:/Program Files/axiom/mnt/windows/algebra/IROOT.o for
      package IntegerRoots
   Loading j:/Program Files/axiom/mnt/windows/algebra/FACTFUNC.o for
      package FactoredFunctions
   Loading j:/Program Files/axiom/mnt/windows/algebra/POLYCATQ.o for
      package PolynomialCategoryQuotientFunctions
   Loading j:/Program Files/axiom/mnt/windows/algebra/FSAGG-.o for
      domain FiniteSetAggregate&
   Loading j:/Program Files/axiom/mnt/windows/algebra/FLASORT.o for
      package FiniteLinearAggregateSort
   Loading j:/Program Files/axiom/mnt/windows/algebra/IDPOAMS.o for
      domain IndexedDirectProductOrderedAbelianMonoidSup
   Loading j:/Program Files/axiom/mnt/windows/algebra/IDPOAM.o for
      domain IndexedDirectProductOrderedAbelianMonoid
   Loading j:/Program Files/axiom/mnt/windows/algebra/PGCD.o for
      package PolynomialGcdPackage
                                                                   Type: Void
(2) -> for i in 1..3 repeat print(a:=sin(i)::Complex Float)
   Loading j:/Program Files/axiom/mnt/windows/algebra/FLOAT.o for
      domain Float
   Loading j:/Program Files/axiom/mnt/windows/algebra/COMPLEX.o for
      domain Complex
   Loading j:/Program Files/axiom/mnt/windows/algebra/COMPCAT-.o for
      domain ComplexCategory&
   Loading j:/Program Files/axiom/mnt/windows/algebra/FPS-.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/RNS-.o for domain
   Loading j:/Program Files/axiom/mnt/windows/algebra/DFLOAT.o for
      domain DoubleFloat
   Loading j:/Program Files/axiom/mnt/windows/algebra/NUMERIC.o for
      package Numeric
   Loading j:/Program Files/axiom/mnt/windows/algebra/EXPR2.o for
      package ExpressionFunctions2
   Loading j:/Program Files/axiom/mnt/windows/algebra/FS2.o for package
   Loading j:/Program Files/axiom/mnt/windows/algebra/POLYLIFT.o for
      package PolynomialCategoryLifting
   Loading j:/Program Files/axiom/mnt/windows/algebra/ES2.o for package
   Loading j:/Program Files/axiom/mnt/windows/algebra/MONOGEN-.o for
      domain MonogenicAlgebra&
   Loading j:/Program Files/axiom/mnt/windows/algebra/FRAMALG-.o for
      domain FramedAlgebra&
   Loading j:/Program Files/axiom/mnt/windows/algebra/FINRALG-.o for
      domain FiniteRankAlgebra&
   Loading j:/Program Files/axiom/mnt/windows/algebra/FEVALAB-.o for
      domain FullyEvalableOver&
   Loading j:/Program Files/axiom/mnt/windows/algebra/UNISEG.o for
      domain UniversalSegment
   0.8414709848 0789650665
   0.9092974268 256816954
   0.1411200080 598672221 + 0.3388131789 0172013563 E -20 %i
                                                                   Type: Void
(3) ->

William Sit
Department of Mathematics....Email: address@hidden
City College of New York................Tel: 212-650-5179
Convent Ave at West 138th Street........Fax: 212-862-0004
New York, NY 10031..Axiom, A Scientific Computation Sytem

reply via email to

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