axiom-mail
[Top][All Lists]
Advanced

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

[Axiom-mail] Using eval() in compile spad code.


From: Donald J Bindner
Subject: [Axiom-mail] Using eval() in compile spad code.
Date: Fri, 10 Mar 2006 21:52:45 -0600
User-agent: Mutt/1.5.9i

I'm trying to learn a bit about compiling packages for Axiom, so
I chose a small task to cut my teeth on.  I want to implement for
myself a simpler simpson() function that does numerical
integration.

I've got a working package after browsing through numquad.spad.
However the prototype for my function is:

 simpson( Float->Float, Segment Float )

So I can perform calculations like:

 simpson( x +-> 1/x, 1..2 )

However I'd like to use a syntax more similar to the way
integrate() works.  I'd prefer to be able to execute

 simpson( 1/x, x=1..2 )

I've done a lot of browsing, but I can't figure out how this is
done.

I've tried to distill the core of my question into a small
example package.  It contains two simple() functions.  One works
fine, but the other won't compile.  Suggestions would be welcome.

--
-- Exports simple() function which takes 2 args,
-- Working behavior is: simple( x+->x^2, 1..2 ) = 3.0
-- Not working but intended behavior is: 
--  simple( x^2, x=1..2 ) = 3.0
--

)abbrev package DONSIMP donSimple
donSimple(): Exports == Implementation where
  F        ==> Float
  SF       ==> Segment F
  EF       ==> Expression F
  SBF      ==> SegmentBinding F

  Exports ==> with
   simple : (F->F,SF) -> F
   simple : (EF,SBF) -> EF

  Implementation ==> add
   simple(func:F->F, sf:SF ) ==
      a : F := lo(sf)
      b : F := hi(sf)
      func(b) - func(a)
  
   simple(func:EF, sbf:SBF) ==
      a : F := lo(segment(sbf))
      b : F := hi(segment(sbf))
      x : Symbol := variable(sbf)
      eval(func, x, b) - eval(func, x, a)

-- 
Don Bindner <address@hidden>




reply via email to

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