axiom-developer
[Top][All Lists]
Advanced

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

Re: [Axiom-developer] Conditional for inner functions in a package.


From: Ralf Hemmecke
Subject: Re: [Axiom-developer] Conditional for inner functions in a package.
Date: Wed, 03 Jan 2007 00:31:21 +0100
User-agent: Thunderbird 1.5.0.9 (X11/20061206)

Hello Francois and Happy New Year to everyone.

I am not a SPAD-expert, but let me try on your little code chunk.

-------------------------------------------------------------------
)abbrev package TRYCOND TryConditions

TryConditions (R, F): Exports == Implementation where
  R : Join (OrderedSet, GcdDomain)
  F : Join (FunctionSpace R, TranscendentalFunctionCategory)

  Exports ==> with
    result    : F -> F
    expResult : F -> F

  Implementation ==> add
    iResult : F -> F
    iResult x == cos x
expResult x == cos x if R is Integer then
      iResult x == sin x
expResult x == sin x result x == iResult x
----------------------------------------------------------------------
test result (sin x) -- sin : right result (sin %i) -- sin, I wait a cos expResult (sin x) -- sin : right
expResult (sin %i)                 -- cos : right

First, to me that is bad code in the sense that "==" should define a constant. What you do is you define the constan iResult and if "R is Integer" you re-define the "constant". Looks ugly, better would be

if R is Integer
 then expResult x == sin
 else expResult x == cos

Aldor has a "local" keyword, but I have not tried to actually conditionalize the definition of a local constant.

My construction above for exported functions is certainly treated in a special way by the compiler.

What you want is

result(x: F): F == if R has IntegerNumberSystem then sin x else cos x;

right? So why don't you write it?

Ok, now everytime "result" is called the expression

  R has IntegerNumberSystem

will be evaluated. Since that is a waste of time, you could say

RhasINS: Boolean == R has IntegerNumberSystem;
result(x: F): F == if RhasINS then sin x else cos x;

which is only a bit test. But probably still one test too much.

If I look at elemntry.spad, it seems that all the functions starting with ii... should be defined in a separate package. Let's name it MyTrigFuns(R, F). MyTrigFuns should export all these ii... functions. and define them as in ElementaryFunction(R,F). ElementaryFunctions in turn should have all the i... and ii... stuff moved to MyTrigFuns and at the end always say something like

   evaluate(opexp, iiexp$MyTrigFuns(R, F))

My problem would be how to avoid the exports of MyTrigFuns to be visible in an Axiom session. But maybe

)unexpose MyTrigFuns

works.

Otherwise you could define MyTrigFuns locally inside the "add" of ElementaryFunctions. So no exports of i... functions would be seen in an Axiom session since they are hidden inside the "add". Aldor would allow such a local domain construction. I have however no idea whether SPAD can do this.

I hope I could help a little.

Ralf




reply via email to

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