From Numerical Recipes in C, 2nd edition Section 6.2 Incomplete Gamma Function http://www.library.cornell.edu/nr/bookcpdf/c6-2.pdf This Axiom interpreter function implements equation (6.2.7) axiom Gam(a:Float,x:Float):Float == if x<0.0 or a<0.0 then error "Invalid arguments" if x=0.0 then return Gamma(a) Type: Void
axiom Gam(0,1) axiom Compiling function Gam with type (Float,Float) -> Float
Type: Float
axiom Gam(1,1.1)
Type: Float
axiom Gam(5,10)
Type: Float
axiom Gam(5,11)
Type: Float
axiom Gam(7,0)
Type: Float
Let's try that again with more precision: axiom digits(100)
Type: PositiveInteger
axiom Gam(0,1)
Type: Float
axiom Gam(1,1.1)
Type: Float
axiom Gam(5,10)
Type: Float
axiom Gam(5,11)
Type: Float
axiom Gam(7,0)
Type: Float
Notice that in the case of So lets do this using machine floating point (DoubleFloat?) in Axiom's library programming language SPAD spad )abbrev package SFX SpecialFunctionsExtended SpecialFunctionsExtended: Exports == Implementation where ITMAX ==> 100.0::DoubleFloat -- Maximum allowed number of iterations FPMIN ==> 1.0e-323::DoubleFloat -- near the smallest representable number spad Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/6599990542159375921-25px004.spad using
old system compiler.
SFX abbreviates package SpecialFunctionsExtended
processing macro definition ITMAX ==> ::((elt (Float) float)(100,Zero,10),DoubleFloat)
processing macro definition FPMIN ==> ::((elt (Float) float)(One,-323,10),DoubleFloat)
processing macro definition Exports ==> -- the constructor category
processing macro definition Implementation ==> -- the constructor capsule
------------------------------------------------------------------------
initializing NRLIB SFX for SpecialFunctionsExtended
compiling into NRLIB SFX
compiling exported Gamma : (DoubleFloat,DoubleFloat) -> DoubleFloat
Time: 0.10 SEC.Apparently in SPAD we must write axiom Gamma(a,x)
Type: Expression Integer
axiom Gamma(0,1)
Type: DoubleFloat?
axiom Gamma(0,2)
Type: DoubleFloat?
axiom Gamma(1,1)
Type: DoubleFloat?
axiom Gamma(1,1.1)
Type: DoubleFloat?
axiom Gamma(5,10)
Type: DoubleFloat?
axiom Gamma(5,11)
Type: DoubleFloat?
axiom Gamma(7,0)
Type: DoubleFloat?
Exactly the same code can also be compiled using Aldor (Axiom library compiler version 2): aldor #include "axiom.as"; #pile SpecialFunctionsExtended2: Exports == Implementation where ITMAX ==> 100.0::DoubleFloat -- Maximum allowed number of iterations FPMIN ==> 1.0e-323::DoubleFloat -- near the smallest representable number aldor Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/sfx2.as using AXIOM-XL compiler and
options
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
Use the system command )set compiler args to change these
options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
"/var/zope2/var/LatexWiki/sfx2.as", line 16:
EPS := (10.0::DoubleFloat**(-digits()$DoubleFloat))$DoubleFloat -- Relative accuracy
......^............................^
[L16 C7] #3 (Error) (After Macro Expansion) No meaning for identifier `EPS'.
Expanded expression was: EPS
[L16 C36] #4 (Error) (After Macro Expansion) Argument 1 of `-' did not match any possible parameter type.
The rejected type is PositiveInteger.
Expected one of:
-- DoubleFloat
-- DoubleFloat, DoubleFloat
Expanded expression was: digits$DoubleFloat()axiom Gamma(a,x)
Type: Expression Integer
axiom Gamma(0,1)
Type: DoubleFloat?
axiom Gamma(0,2)
Type: DoubleFloat?
axiom Gamma(1,1)
Type: DoubleFloat?
axiom Gamma(1,1.1)
Type: DoubleFloat?
axiom Gamma(5,10)
Type: DoubleFloat?
axiom Gamma(5,11)
Type: DoubleFloat?
axiom Gamma(1,0)
Type: DoubleFloat?
axiom Gamma(7,0)
Type: DoubleFloat?
... --greg, Sun, 29 Jan 2006 18:12:10 -0600 reply This is false (result is 720):
Gam(7,0)
0.0
Type: Float
Sorry I forgot the limiting case. Actually the algoritm in Recipes
is a little more sophisticated. It uses the series expansion of
axiom Gam(7,0)
Type: Float
axiom Gam(7,0.1)
Type: Float
axiom Gam(7,0.2)
Type: Float
The command )set functions compile on is necessary in order to
avoid a seg fault with certain function definitions in the Axiom
interpreter. See: #196
axiom )set functions compile on axiom j:=120
Type: PositiveInteger
axiom nume(a) == cons(1 :: Float,[((a-i)*i) :: Float for i in 1..]); Type: Void
axiom dene(a,x) == [(x+2*i+1-a) :: Float for i in 0..]; Type: Void
axiom cfe(a,x) == continuedFraction(0,nume(a),dene(a,x)); Type: Void
axiom ccfe(a,x) == convergents cfe(a,x); Type: Void
axiom gamcfe(a,x) == exp(-x)*x^a*ccfe(a,x).j; Type: Void
axiom gamcfe(2,3) axiom Compiling function nume with type PositiveInteger -> Stream Float axiom Compiling function dene with type (PositiveInteger,PositiveInteger)
-> Stream Floataxiom Compiling function cfe with type (PositiveInteger,PositiveInteger)
-> ContinuedFraction Floataxiom Compiling function ccfe with type (PositiveInteger,PositiveInteger)
-> Stream Fraction Float
There are 34 exposed and 23 unexposed library operations named *
having 2 argument(s) but none was determined to be applicable.
Use HyperDoc Browse, or issue
)display op *
to learn more about the available operations. Perhaps
package-calling the operation or using coercions on the arguments
will allow you to apply the operation.
Cannot find a definition or applicable library operation named *
with argument type(s)
Expression Integer
Fraction Float
Type: Expression Float
axiom E1(x)== gamcfe(0,x) Type: Void
axiom E1(2.0) axiom Compiling function nume with type NonNegativeInteger -> Stream Float axiom Compiling function dene with type (NonNegativeInteger,Float) ->
Stream Floataxiom Compiling function cfe with type (NonNegativeInteger,Float) ->
ContinuedFraction Floataxiom Compiling function ccfe with type (NonNegativeInteger,Float) ->
Stream Fraction Float
Type: Fraction Float
There seems to be a problem with Axiom's ContinuedFraction? domain.
The type of the result is shown as Fraction Float but this is
nonesense.
axiom ff:Fraction Float Something similar happens if the argument is Fraction Integer axiom nume(a) == cons(1,[((a-i)*i) for i in 1..]); Type: Void
axiom dene(a,x) == [(x+2*i+1-a) for i in 0..]; Type: Void
axiom cfe(a,x) == continuedFraction(0,nume(a),dene(a,x)); Type: Void
axiom ccfe(a,x) == convergents cfe(a,x); Type: Void
axiom ccfe(0,2::Float) axiom Compiling function nume with type NonNegativeInteger -> Stream
Integeraxiom Compiling function dene with type (NonNegativeInteger,Float) ->
Stream Floataxiom Compiling function cfe with type (NonNegativeInteger,Float) ->
ContinuedFraction Floataxiom Compiling function ccfe with type (NonNegativeInteger,Float) ->
Stream Fraction Float
Type: Stream Fraction Float
axiom ccfe(0,2::Fraction Integer) axiom Compiling function dene with type (NonNegativeInteger,Fraction
Integer) -> Stream Fraction Integeraxiom Compiling function cfe with type (NonNegativeInteger,Fraction
Integer) -> ContinuedFraction Fraction Integeraxiom Compiling function ccfe with type (NonNegativeInteger,Fraction
Integer) -> Stream Fraction Fraction Integer
Type: Stream Fraction Fraction Integer
|
