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

Edit detail for SandBoxMyReduce revision 2 of 14

1 2 3 4 5 6 7 8 9 10 11 12 13 14
Editor: Bill Page
Time: 2008/04/07 14:29:08 GMT-7
Note: Waldek's function

removed:
-)abbrev package MYRED1 MyReduce1
-MyReduce1(S:AbelianMonoid): with
-    plus: (S,S)->S
- == add
-    plus(a,b) == a + b
-

added:
     getfun(f:(S,S)->S):(S,S)-> S == f

changed:
-         f=plus(#1,#2) => 0$S
         f=getfun(_+$S) => 0$S

spad
)abbrev package MYRED MyReduce MyReduce(S:Type): with reduce: ((S,S)->S,List S) -> S == add import MyReduce1(S) reduce(f:(S,S)->S, x:List S):S == getfun(f:(S,S)->S):(S,S)-> S == f if empty? x then if S has AbelianMonoid then f=getfun(_+$S) => 0$S error "reducing over an empty list needs the 3 argument form" reduce(f, rest x, first x)
spad
   Compiling OpenAxiom source code from file 
      /var/zope2/var/LatexWiki/5622284915943523155-25px001.spad using 
      old system compiler.
   MYRED abbreviates package MyReduce 
------------------------------------------------------------------------
   initializing NRLIB MYRED for MyReduce 
   compiling into NRLIB MYRED 
   importing MyReduce1 S
   compiling exported reduce : ((S,S) -> S,List S) -> S
   Semantic Errors: 
      [1]  MyReduce1 is not a known type
****** comp fails at level 1 with expression: ******
error in function reduce 
((SEQ (DEF (|getfun| |f|) ((|Mapping| S S S) (|Mapping| S S S))
           (NIL NIL) |f|)
      (SEQ (LET #0=#:G1386 (|empty?| |x|))
           (|exit| 1
                   (IF #0#
                       (SEQ (IF (|has| S (|AbelianMonoid|))
                                (SEQ (LET #1=#:G1385
                                       (= |f| (|getfun| (|elt| S +))))
                                     (|exit| 1
                                      (IF #1# (|exit| 2 (|elt| S 0))
                                       |%noBranch|)))
                                |%noBranch|)
                            (|exit| 1
                                    (|error|
                                     "reducing over an empty list needs the 3 argument form")))
                       |%noBranch|)))
      (|exit| 1 (|reduce| |f| (|rest| |x|) (|first| |x|)))))
****** level 1  ******
$x:= (SEQ (DEF (getfun f) ((Mapping S S S) (Mapping S S S)) (NIL NIL) f) (SEQ (LET G1386 (empty? x)) (exit 1 (IF G1386 (SEQ (IF (has S (AbelianMonoid)) (SEQ (LET G1385 (= f (getfun (elt S +)))) (exit 1 (IF G1385 (exit 2 (elt S (Zero))) %noBranch))) %noBranch) (exit 1 (error reducing over an empty list needs the 3 argument form))) %noBranch))) (exit 1 (reduce f (rest x) (first x))))
$m:= S
$f:=
((((|x| # . #1=(#)) (|f| # #) (|x| . #1#) (|#| # #) ...)))
   >> Apparent user error:
   Wrong number of arguments: 
   (getfun f)