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

fricas
(1) -> <spad>
fricas
)abbrev package MYEXP MyExp
MyExp(F: Algebra(Fraction(Integer))): with myexp: F -> F myexp: (F, NonNegativeInteger) -> F == add 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>
fricas
Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8403278387071313463-25px001.spad
      using 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.02 SEC.
compiling exported myexp : F -> F Time: 0 SEC.
(time taken in buildFunctor: 0) Time: 0 SEC.
Cumulative Statistics for Constructor MyExp Time: 0.02 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 28 NOV 2026 06:27:52 AM):
; wrote /var/aw/var/LatexWiki/MYEXP.NRLIB/MYEXP.fasl ; compilation finished in 0:00:00.044 ------------------------------------------------------------------------ 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)

\label{eq1}2.7182818284 \<u> 590452354(1)
Type: Float
fricas
myexp(1.0,4)

\label{eq2}2.7083333333 \<u> 333333333(2)
Type: Float
fricas
myexp(1)

\label{eq3}\frac{28610550901763172837819811744646057}{105252334773477412
06688720486400000}(3)
Type: Fraction(Integer)
fricas
myexp(matrix[[1,0],[0,2]] :: SQMATRIX(2,FRAC(INT))) :: SQMATRIX(2,Float)

\label{eq4}\left[ 
\begin{array}{cc}
{2.7182818284 \<u> 590452354}&{0.0}
\
{0.0}&{7.3890560989 \</u> 306502273}
(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 == message("myfun-object")$OutputForm 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/4752705461069213214-25px003.spad
      using 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 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,%) -> % ****** comp fails at level 4 with expression: ****** error in function ltimes
(+-> (|:| (|:| |f| F) F) (* |l| ((|pretend| |y| (|Mapping| F F)) |f|))) ****** level 4 ****** x:= l m:= F f:= ((((|f| #) (|y| # #) (|l| # #) (|ltimes| #) ...) ((|times| #) (|plus| #)) ((|plus| #) (|id| #)) ((|id| #) (|zr| #)) ...))
>> Apparent user error: Cannot coerce l of mode (Fraction (Integer)) to mode ##1

fricas
F := Fraction Integer

\label{eq5}\hbox{\axiomType{Fraction}\ } \left({\hbox{\axiomType{Integer}\ }}\right)(5)
Type: Type
fricas
H := MyFun(F)
MyFun is an unknown constructor and so is unavailable. Did you mean to use -> but type something different instead?

Computing the first 3 terms of 1+\varphi(1)+\frac{1}{2}\varphi(\varphi(1)).

fricas
1+a(hphi,1)+1/2 * a(hphi,a(hphi,1))
There are no library operations named a Use HyperDoc Browse or issue )what op a to learn if there is any operation containing " a " in its name.
Cannot find a definition or applicable library operation named a with argument type(s) Variable(hphi) PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

And here we first compute 1+\varphi+\frac{1}{2}\varphi^2 and then apply this function to 1.

fricas
hexp:=myexp(hphi,2)

\label{eq6}{{\frac{1}{2}}\ {{hphi}^{2}}}+ hphi + 1(6)
Type: Polynomial(Fraction(Integer))
fricas
apply(hexp,1)
There are 2 exposed and 2 unexposed library operations named apply having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op apply 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 apply with argument type(s) Polynomial(Fraction(Integer)) PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

It also works with finite fields.

fricas
P := PrimeField 17

\label{eq7}\hbox{\axiomType{PrimeField}\ } \left({17}\right)(7)
Type: Type
fricas
Q := MyFun(P)
MyFun is an unknown constructor and so is unavailable. Did you mean to use -> but type something different instead?




  Subject:   Be Bold !!
  ( 15 subscribers )  
Please rate this page: