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

fricas
(1) -> )version
"FriCAS 1.3.10 compiled at Wed 10 Jan 02:19:45 CET 2024"

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.01 SEC.
(time taken in buildFunctor: 0)
;;; *** |MyReduce| REDEFINED
;;; *** |MyReduce| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor MyReduce Time: 0.01 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 FEB 2025 09:21:57 AM):
; wrote /var/aw/var/LatexWiki/MYRED.NRLIB/MYRED.fasl ; compilation finished in 0:00:00.032 ------------------------------------------------------------------------ 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,655) theMap(newGoGet) theMap(INT;+;3%;37,655) theMap(newGoGet)
>> Error detected within library code: reducing over an empty list needs the 3 argument form

Here is another version of the same thing using the = from the Mapping domain.

spad
)abbrev package MYRED2 MyReduce2
MyReduce2(S:Type): with
    myred2: ((S,S)->S,List S) -> S
 == add
   import NonNegativeInteger
   myred2(f:(S,S)->S, x:List S):S ==
     if #x>1 then
       f(first x, myred2(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)$Mapping(S,S,S) => return 0$S
       if S has Monoid then
         -- f(1,1)=(1*1)$S and (f = _*$S) => return 1$S
         (f = _*$S)$Mapping(S,S,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/7640641182681721660-25px004.spad
      using old system compiler.
   MYRED2 abbreviates package MyReduce2 
------------------------------------------------------------------------
   initializing NRLIB MYRED2 for MyReduce2 
   compiling into NRLIB MYRED2 
   importing NonNegativeInteger
   compiling exported myred2 : ((S,S) -> S,List S) -> S
****** Domain: S already in scope
augmenting S: (AbelianMonoid)
****** Domain: S already in scope
augmenting S: (Monoid)
****** Domain: (Mapping S S S) already in scope
Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |MyReduce2| REDEFINED
;;; *** |MyReduce2| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor MyReduce2 Time: 0 seconds
finalizing NRLIB MYRED2 Processing MyReduce2 for Browser database: --->-->MyReduce2(constructor): Not documented!!!! --->-->MyReduce2((myred2 (S (Mapping S S S) (List S)))): Not documented!!!! --->-->MyReduce2(): Missing Description ; compiling file "/var/aw/var/LatexWiki/MYRED2.NRLIB/MYRED2.lsp" (written 16 FEB 2025 09:21:57 AM):
; wrote /var/aw/var/LatexWiki/MYRED2.NRLIB/MYRED2.fasl ; compilation finished in 0:00:00.008 ------------------------------------------------------------------------ MyReduce2 is now explicitly exposed in frame initial MyReduce2 will be automatically loaded when needed from /var/aw/var/LatexWiki/MYRED2.NRLIB/MYRED2

Notice that it fails in the same way as above:

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

\label{eq2}10(2)
Type: PositiveInteger?
fricas
myred2(+,[]$List Integer)
>> Error detected within library code: reducing over an empty list needs the 3 argument form

But it works if we used the original trick of applying the function to get rid of newGoGet before comparing the functions.

spad
)abbrev package MYRED3 MyReduce3
MyReduce3(S:Type): with
    myred3: ((S,S)->S,List S) -> S
 == add
   import NonNegativeInteger
   myred3(f:(S,S)->S, x:List S):S ==
     if #x>1 then
       f(first x, myred3(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)$Mapping(S,S,S) => return 0$S
       if S has Monoid then
         f(1,1)=(1*1)$S and (f = _*$S)$Mapping(S,S,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/1899462816039391804-25px006.spad
      using old system compiler.
   MYRED3 abbreviates package MyReduce3 
------------------------------------------------------------------------
   initializing NRLIB MYRED3 for MyReduce3 
   compiling into NRLIB MYRED3 
   importing NonNegativeInteger
   compiling exported myred3 : ((S,S) -> S,List S) -> S
****** Domain: S already in scope
augmenting S: (AbelianMonoid)
****** Domain: S already in scope
augmenting S: (Monoid)
****** Domain: (Mapping S S S) already in scope
Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |MyReduce3| REDEFINED
;;; *** |MyReduce3| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor MyReduce3 Time: 0 seconds
finalizing NRLIB MYRED3 Processing MyReduce3 for Browser database: --->-->MyReduce3(constructor): Not documented!!!! --->-->MyReduce3((myred3 (S (Mapping S S S) (List S)))): Not documented!!!! --->-->MyReduce3(): Missing Description ; compiling file "/var/aw/var/LatexWiki/MYRED3.NRLIB/MYRED3.lsp" (written 16 FEB 2025 09:21:57 AM):
; wrote /var/aw/var/LatexWiki/MYRED3.NRLIB/MYRED3.fasl ; compilation finished in 0:00:00.008 ------------------------------------------------------------------------ MyReduce3 is now explicitly exposed in frame initial MyReduce3 will be automatically loaded when needed from /var/aw/var/LatexWiki/MYRED3.NRLIB/MYRED3

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

\label{eq3}10(3)
Type: PositiveInteger?
fricas
myred3(+,[]$List Integer)

\label{eq4}0(4)
Type: NonNegativeInteger?
fricas
myred3(*,[1,2,3,4])

\label{eq5}24(5)
Type: PositiveInteger?
fricas
myred3(*,[]$List Integer)

\label{eq6}1(6)
Type: PositiveInteger?




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