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

Edit detail for SandBoxMyReduceInFriCAS revision 1 of 4

1 2 3 4
Editor: Bill Page
Time: 2008/04/08 15:39:22 GMT-7
Note: test for newGoGet

changed:
-
\begin{axiom}
)version
\end{axiom}
\begin{spad}
)abbrev package MYRED MyReduce
MyReduce(S:Type): with
    myred: ((S,S)->S,List S) -> S
 == add
   -- Waldek's local helper function
   ((f:(S,S)->S) = (g:(S,S)->S)):Boolean ==
      print(coerceMap2E(f)$Lisp::OutputForm)
      print(coerceMap2E(g)$Lisp::OutputForm)
      EQ(f,g)$Lisp
   --
   import NonNegativeInteger
   myred(f:(S,S)->S, x:List S):S ==
     if #x>1 then
       f(first x, myred(f,rest x))
     else if #x=1 then
       first x
     else
       if S has AbelianMonoid then
         -- Must force "newGoGet" by applying operations before comparison!
         -- f(0,0)=(0+0)$S and (f = _+$S) => return 0$S
         (f = _+$S) => return 0$S
       if S has Monoid then
         -- f(1,1)=(1*1)$S and (f = _*$S) => return 1$S
         (f = _*$S) => return 1$S
       error "reducing over an empty list needs the 3 argument form"
\end{spad}

\begin{axiom}
myred(+,[1,2,3,4])
myred(+,[]$List Integer)
myred(*,[1,2,3,4])
myred(*,[]$List Integer)

\end{axiom}

fricas
(1) -> )version
"FriCAS 1.3.12 compiled at Sat 7 Jun 23:54:49 CEST 2025"

spad
)abbrev package MYRED MyReduce
MyReduce(S:Type): with
    myred: ((S,S)->S,List S) -> S
 == add
   -- Waldek's local helper function
   ((f:(S,S)->S) = (g:(S,S)->S)):Boolean ==
      print(coerceMap2E(f)$Lisp::OutputForm)
      print(coerceMap2E(g)$Lisp::OutputForm)
      EQ(f,g)$Lisp
   --
   import NonNegativeInteger
   myred(f:(S,S)->S, x:List S):S ==
     if #x>1 then
       f(first x, myred(f,rest x))
     else if #x=1 then
       first x
     else
       if S has AbelianMonoid then
         -- Must force "newGoGet" by applying operations before comparison!
         -- f(0,0)=(0+0)$S and (f = _+$S) => return 0$S
         (f = _+$S) => return 0$S
       if S has Monoid then
         -- f(1,1)=(1*1)$S and (f = _*$S) => return 1$S
         (f = _*$S) => return 1$S
       error "reducing over an empty list needs the 3 argument form"
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6114676696124184375-25px002.spad
      using old system compiler.
   MYRED abbreviates package MyReduce 
------------------------------------------------------------------------
   initializing NRLIB MYRED for MyReduce 
   compiling into NRLIB MYRED 
   compiling local = : ((S,S) -> S,(S,S) -> S) -> Boolean
Time: 0 SEC.
importing NonNegativeInteger compiling exported myred : ((S,S) -> S,List S) -> S ****** Domain: S already in scope augmenting S: (AbelianMonoid) ****** Domain: S already in scope augmenting S: (Monoid) Time: 0 SEC.
(time taken in buildFunctor: 0) Time: 0 SEC.
Cumulative Statistics for Constructor MyReduce Time: 0 seconds
finalizing NRLIB MYRED Processing MyReduce for Browser database: --->-->MyReduce(constructor): Not documented!!!! --->-->MyReduce((myred (S (Mapping S S S) (List S)))): Not documented!!!! --->-->MyReduce(): Missing Description ; compiling file "/var/aw/var/LatexWiki/MYRED.NRLIB/MYRED.lsp" (written 16 SEP 2026 12:06:51 AM):
; wrote /var/aw/var/LatexWiki/MYRED.NRLIB/MYRED.fasl ; compilation finished in 0:00:00.028 ------------------------------------------------------------------------ MyReduce is now explicitly exposed in frame initial MyReduce will be automatically loaded when needed from /var/aw/var/LatexWiki/MYRED.NRLIB/MYRED

fricas
myred(+,[1,2,3,4])

\label{eq1}10(1)
Type: PositiveInteger?
fricas
myred(+,[]$List Integer)
theMap(INT;+;3%;37,145) theMap(newGoGet) theMap(INT;+;3%;37,145) theMap(newGoGet)
>> Error detected within library code: reducing over an empty list needs the 3 argument form