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

# Edit detail for FunWithFunctions revision 4 of 4

 1 2 3 4 Editor: Ralf Hemmecke Time: 2011/04/05 06:34:52 GMT-7 Note:

added:
It also works with finite fields.
\begin{axiom}
P := PrimeField 17
Q := MyFun(P)
psi(f: P): P == f+1
qpsi:Q := psi::Q
apply(qpsi, 1)
qexp:=myexp(qpsi,2)
apply(qexp,1)
\end{axiom}



)abbrev package MYEXP MyExp
MyExp(F: Algebra(Fraction(Integer))): with
myexp: F -> F
myexp: (F, NonNegativeInteger) -> F
Map2 ==> ListFunctions2(NonNegativeInteger, F)
myexp(x, n) ==
a(i : NonNegativeInteger) : F == (1/(factorial i)) * x^i
reduce(_+@((F, F) -> F), map(a, [i for i in 0..n])$Map2) myexp(x: F): F == myexp(x, 32) spad  Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8403278387071313463-25px001.spad using old system compiler. MYEXP abbreviates package MyExp ------------------------------------------------------------------------ initializing NRLIB MYEXP for MyExp compiling into NRLIB MYEXP processing macro definition Map2 ==> ListFunctions2(NonNegativeInteger,F) compiling exported myexp : (F,NonNegativeInteger) -> F Time: 0.04 SEC. compiling exported myexp : F -> F Time: 0 SEC. (time taken in buildFunctor: 0) ;;; *** |MyExp| REDEFINED ;;; *** |MyExp| REDEFINED Time: 0 SEC. Cumulative Statistics for Constructor MyExp Time: 0.04 seconds finalizing NRLIB MYEXP Processing MyExp for Browser database: --->-->MyExp(constructor): Not documented!!!! --->-->MyExp((myexp (F F))): Not documented!!!! --->-->MyExp((myexp (F F (NonNegativeInteger)))): Not documented!!!! --->-->MyExp(): Missing Description ; compiling file "/var/aw/var/LatexWiki/MYEXP.NRLIB/MYEXP.lsp" (written 13 JUL 2015 02:24:20 PM): ; /var/aw/var/LatexWiki/MYEXP.NRLIB/MYEXP.fasl written ; compilation finished in 0:00:00.029 ------------------------------------------------------------------------ MyExp is now explicitly exposed in frame initial MyExp will be automatically loaded when needed from /var/aw/var/LatexWiki/MYEXP.NRLIB/MYEXP That's generic code and has to be compiled. Look at the types of the result. fricas myexp(1.0)  (1) Type: Float fricas myexp(1.0,4)  (2) Type: Float fricas myexp(1)  (3) Type: Fraction(Integer) fricas myexp(matrix[[1,0],[0,2]] :: SQMATRIX(2,FRAC(INT))) :: SQMATRIX(2,Float)  (4) Type: SquareMatrix?(2,Float) And now we create a domain of functions and let it behave like an algebra over a field of rational numbers where multiplication is concatenation of functions and addition is... well, see below. spad )abbrev domain MYFUN MyFun MyFun(F: Field): Algebra(Fraction(Integer)) with apply: (%, F) -> F coerce: (F -> F) -> % == add Rep := F -> F X ==> x pretend (F->F) Y ==> y pretend (F->F) zr(f: F): F == 0 id(f: F): F == f plus(x: %, y: %): % == (f: F): F +-> X(f) + Y(f) times(x: %, y: %): % == (f: F): F +-> X(Y f) ltimes(l: Fraction(Integer), y: %): % == (f: F): F +-> l*Y(f) 0: % == zr 1: % == id (x: %) + (y: %) == plus(x,y) (x: %) * (y: %) == times(x,y) (l: Fraction(Integer)) * (y: %) == ltimes(l,y) coerce(x: %): OutputForm == "myfun-object" apply(x: %, f: F): F == X f coerce(fun: F -> F): % == fun spad  Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1886816482829968029-25px003.spad using old system compiler. MYFUN abbreviates domain MyFun ------------------------------------------------------------------------ initializing NRLIB MYFUN for MyFun compiling into NRLIB MYFUN processing macro definition X ==> pretend(x,F -> F) processing macro definition Y ==> pretend(y,F -> F) compiling local zr : F -> F Time: 0.01 SEC. compiling local id : F -> F MYFUN;id is replaced by f Time: 0 SEC. compiling local plus : ($,$) ->$
Time: 0 SEC.
compiling local times : ($,$) -> $Time: 0 SEC. compiling local ltimes : (Fraction Integer,$) -> $Time: 0.01 SEC. compiling exported Zero : () ->$
Time: 0 SEC.
compiling exported One : () -> $Time: 0 SEC. compiling exported + : ($,$) ->$
Time: 0 SEC.
compiling exported * : ($,$) -> $Time: 0 SEC. compiling exported * : (Fraction Integer,$) -> $Time: 0 SEC. compiling exported coerce :$ -> OutputForm
MYFUN;coerce;$Of;11 is replaced by myfun-object Time: 0 SEC. compiling exported apply : ($,F) -> F
MYFUN;apply;$2F;12 is replaced by SPADCALLfx Time: 0 SEC. compiling exported coerce : F -> F ->$
MYFUN;coerce;M\$;13 is replaced by fun
Time: 0 SEC.
(time taken in buildFunctor:  0)
;;;     ***       |MyFun| REDEFINED
;;;     ***       |MyFun| REDEFINED
Time: 0 SEC.
Warnings:
[1] plus:  elt has no value
[2] times:  elt has no value
[3] apply:  elt has no value
Cumulative Statistics for Constructor MyFun
Time: 0.02 seconds
finalizing NRLIB MYFUN
Processing MyFun for Browser database:
--->-->MyFun(constructor): Not documented!!!!
--->-->MyFun((apply (F % F))): Not documented!!!!
--->-->MyFun((coerce (% (Mapping F F)))): Not documented!!!!
--->-->MyFun(): Missing Description
; compiling file "/var/aw/var/LatexWiki/MYFUN.NRLIB/MYFUN.lsp" (written 13 JUL 2015 02:24:20 PM):
; /var/aw/var/LatexWiki/MYFUN.NRLIB/MYFUN.fasl written
; compilation finished in 0:00:00.032
------------------------------------------------------------------------
MyFun is now explicitly exposed in frame initial
MyFun will be automatically loaded when needed from
/var/aw/var/LatexWiki/MYFUN.NRLIB/MYFUN

fricas
F := Fraction Integer
 (5)
Type: Type
fricas
H := MyFun(F)
 (6)
Type: Type
fricas
phi(f: F): F == f/2
Function declaration phi : Fraction(Integer) -> Fraction(Integer)
has been added to workspace.
Type: Void
fricas
hphi:H := phi::H
fricas
Compiling function phi with type Fraction(Integer) -> Fraction(
Integer)
 (7)
Type: MyFun?(Fraction(Integer))
fricas
apply(hphi, 1)
 (8)
Type: Fraction(Integer)
fricas
a==>apply
Type: Void

Computing the first 3 terms of .

fricas
1+a(hphi,1)+1/2 * a(hphi,a(hphi,1))
 (9)
Type: Fraction(Integer)

And here we first compute and then apply this function to 1.

fricas
hexp:=myexp(hphi,2)
 (10)
Type: MyFun?(Fraction(Integer))
fricas
apply(hexp,1)
 (11)
Type: Fraction(Integer)

It also works with finite fields.

fricas
P := PrimeField 17
 (12)
Type: Type
fricas
Q := MyFun(P)
 (13)
Type: Type
fricas
psi(f: P): P == f+1
Function declaration psi : PrimeField(17) -> PrimeField(17) has been
added to workspace.
Type: Void
fricas
qpsi:Q := psi::Q
fricas
Compiling function psi with type PrimeField(17) -> PrimeField(17)
 (14)
Type: MyFun?(PrimeField?(17))
fricas
apply(qpsi, 1)
 (15)
Type: PrimeField?(17)
fricas
qexp:=myexp(qpsi,2)
 (16)
Type: MyFun?(PrimeField?(17))
fricas
apply(qexp,1)
 (17)
Type: PrimeField?(17)