|
|
last edited 8 months ago by test1 |
1 2 | ||
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.
)abbrev package DONSIMP donSimple
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/9089532301415255797-25px001.spad using old system compiler. DONSIMP abbreviates package donSimple ------------------------------------------------------------------------ initializing NRLIB DONSIMP for donSimple compiling into NRLIB DONSIMP compiling exported simple : (Float -> Float,Segment Float) -> Float ****** comp fails at level 3 with expression: ****** error in function simple
(SEQ (|:=| (|:| |a| (|Float|)) | << | (|lo| |sf|) | >> |) (|:=| (|:| |b| (|Float|)) (|hi| |sf|)) (|exit| 1 (- (|func| |b|) (|func| |a|)))) ****** level 3 ****** $x:= (lo sf) $m:= $EmptyMode $f:= ((((|a| #) (|sf| # . #1=#) (|func| # #) (|sf| . #1#) ...)))
>> Apparent user error: NoValueMode is an unknown mode
simple(1/x,x=2..3)
There are no library operations named simple Use HyperDoc Browse or issue )what op simple to learn if there is any operation containing " simple " in its name.
Cannot find a definition or applicable library operation named simple with argument type(s) Fraction(Polynomial(Integer)) SegmentBinding(PositiveInteger)
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need.