login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBox Numerical Integration revision 1 of 1

1
Editor:
Time: 2007/11/18 18:30:22 GMT-8
Note: must use explicit conversions in SPAD

changed:
-
On March 10, 2006 10:53 PM Donald J Bindner wrote:

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.

\begin{spad}
)abbrev package DONSIMP donSimple

--
-- 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
--

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, kernel(x), b::EF) - eval(func, kernel(x), a::EF)
\end{spad}

\begin{axiom}
simple(1/x,x=2..3)
\end{axiom}

On March 10, 2006 10:53 PM Donald J Bindner wrote:

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.

spad
)abbrev package DONSIMP donSimple
-- 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 --
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, kernel(x), b::EF) - eval(func, kernel(x), a::EF)
spad
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/9089532301415255797-25px001.spad using 
      old system compiler.
   DONSIMP abbreviates package donSimple 
   processing macro definition F ==> Float 
   processing macro definition SF ==> Segment Float 
   processing macro definition EF ==> Expression Float 
   processing macro definition SBF ==> SegmentBinding Float 
   processing macro definition Exports ==> -- the constructor category 
   processing macro definition Implementation ==> -- the constructor capsule 
------------------------------------------------------------------------
   initializing NRLIB DONSIMP for donSimple 
   compiling into NRLIB DONSIMP 
   compiling exported simple : (Float -> Float,Segment Float) -> Float
Time: 0.05 SEC.
compiling exported simple : (Expression Float,SegmentBinding Float) -> Expression Float Time: 0.24 SEC.
(time taken in buildFunctor: 0)
;;; *** |donSimple| REDEFINED
;;; *** |donSimple| REDEFINED Time: 0 SEC.
Warnings: [1] simple: not known that (OrderedSet) is of mode (CATEGORY package (SIGNATURE simple ((Float) (Mapping (Float) (Float)) (Segment (Float)))) (SIGNATURE simple ((Expression (Float)) (Expression (Float)) (SegmentBinding (Float)))))
Cumulative Statistics for Constructor donSimple Time: 0.29 seconds
finalizing NRLIB DONSIMP Processing donSimple for Browser database: --->-->donSimple((simple (F (Mapping F F) SF))): Not documented!!!! --->-->donSimple((simple (EF EF SBF))): Not documented!!!! --->-->donSimple(constructor): Not documented!!!! --->-->donSimple(): Missing Description ------------------------------------------------------------------------ donSimple is now explicitly exposed in frame initial donSimple will be automatically loaded when needed from /var/zope2/var/LatexWiki/DONSIMP.NRLIB/code

axiom
simple(1/x,x=2..3)
LatexWiki Image(1)
Type: Expression Float