diff --git a/changelog b/changelog index f939891..0e5c7bd 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +20100511 tpd src/axiom-website/patches.html 20100511.05.tpd.patch +20100511 tpd src/input/Makefile add curry regression test +20100511 tpd src/input/curry.input add regression test 20100511 tpd src/axiom-website/patches.html 20100511.04.tpd.patch 20100511 tpd books/bookvolbib add Soren L. Buhl [Buh05] 20100511 tpd src/axiom-website/patches.html 20100511.03.tpd.patch diff --git a/src/axiom-website/patches.html b/src/axiom-website/patches.html index ad52779..7da83b4 100644 --- a/src/axiom-website/patches.html +++ b/src/axiom-website/patches.html @@ -2691,5 +2691,7 @@ books/bookvolbib add Assia Mahboubi [Mah05]
books/bookvol10.4 add RootsFindingPackage
20100511.04.tpd.patch books/bookvolbib add Soren L. Buhl [Buh05]
+20100511.05.tpd.patch +src/input/curry.input add regression test
diff --git a/src/input/Makefile.pamphlet b/src/input/Makefile.pamphlet index e80186e..a698023 100644 --- a/src/input/Makefile.pamphlet +++ b/src/input/Makefile.pamphlet @@ -297,7 +297,7 @@ REGRES= ackermann.regress \ coercels.regress collect.regress \ complex.regress complexfactor.regress conformal.regress \ constant.regress contfrac.regress contfrc.regress \ - curl.regress cwmmt.regress \ + curl.regress curry.regress cwmmt.regress \ cycles1.regress cycles.regress cyfactor.regress \ danzwill.regress danzwill2.regress davenport.regress \ decimal.regress defintef.regress defintrf.regress \ @@ -571,7 +571,7 @@ FILES= ${OUT}/ackermann.input \ ${OUT}/cone.input ${OUT}/conformal.input \ ${OUT}/constant.input \ ${OUT}/contfrac.input ${OUT}/contfrc.input ${OUT}/coordsys.input \ - ${OUT}/curl.input \ + ${OUT}/curl.input ${OUT}/curry.input \ ${OUT}/cycles.input ${OUT}/cycles1.input ${OUT}/cycloid.input \ ${OUT}/cycloid2.input \ ${OUT}/cycloid3.input ${OUT}/cyfactor.input ${OUT}/damped.input \ @@ -815,7 +815,8 @@ DOCFILES= \ ${DOC}/cone.input.dvi ${DOC}/conformal.input.dvi \ ${DOC}/constant.input.dvi ${DOC}/contfrac.input.dvi \ ${DOC}/contfrc.input.dvi ${DOC}/coordsys.input.dvi \ - ${DOC}/curl.input.dvi ${DOC}/cycles1.input.dvi \ + ${DOC}/curl.input.dvi ${DOC}/curry.input.dvi \ + ${DOC}/cycles1.input.dvi \ ${DOC}/cycles.input.dvi ${DOC}/cycloid2.input.dvi \ ${DOC}/cycloid3.input.dvi ${DOC}/cycloid.input.dvi \ ${DOC}/cyfactor.input.dvi ${DOC}/d01ajf.input.dvi \ diff --git a/src/input/curry.input.pamphlet b/src/input/curry.input.pamphlet new file mode 100644 index 0000000..ceedda5 --- /dev/null +++ b/src/input/curry.input.pamphlet @@ -0,0 +1,225 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/input curry.input} +\author{Ralf Hemmecke, Bill Page, Tim Daly} +\maketitle +\begin{abstract} +This shows the correct way to write a curried function. +The issue is one of correct type mappings of arguments. +\end{abstract} +\eject +\tableofcontents +\eject +\begin{chunk}{*} +)set break resume +)sys rm -rf curry.output +)spool curry.output +)set message test on +)set message auto off +)clear all + +\end{chunk} +You might think that this is the correct way to write a curried function. +This looks like it will return a function that takes a single argument $y$ +and gives the gcd of the curried valued function with the argument $y$. +\begin{chunk}{*} + +--S 1 of 14 +makeCurry := x +-> (y +-> gcd(x,y)) +--R +--R +--R (1) x +-> y +-> gcd(x,y) +--R Type: AnonymousFunction +--E 1 + +\end{chunk} +So curried is applied to 4 and we get the returned function which +appears to compute $gcd(4,y)$, which should be 2. +\begin{chunk}{*} + +--S 2 of 14 +curried:=makeCurry(4) +--R +--R +--I (2) y +-> gcd(G1392,y) +--R Type: AnonymousFunction +--E 2 + +\end{chunk} +But when we test it we get the incorrect result. This is due to the +default assigned types. +\begin{chunk}{*} + +--S 3 of 14 +curried(6) +--R +--R +--R (3) 1 +--R Type: Polynomial Integer +--E 3 + +\end{chunk} +The intermediates and results all have to remain in the correct types. +Here we fully specify the types, including the types of the inner function. +\begin{chunk}{*} + +)clear all +--S 4 of 14 +makeCurry(x:Integer):Integer->Integer == (y:Integer):Integer +-> gcd(x,y) +--R +--R Function declaration makeCurry : Integer -> (Integer -> Integer) has +--R been added to workspace. +--R Type: Void +--E 4 + +\end{chunk} +The curried function now has the correct type ``Integer$->$Integer'' +\begin{chunk}{*} + +--S 5 of 14 +curried:=makeCurry(4) +--R +--R Compiling function makeCurry with type Integer -> (Integer -> +--R Integer) +--R +--R (2) theMap(NIL,0) +--R Type: (Integer -> Integer) +--E 5 + +\end{chunk} +and now we get the correct result of the gcd(4,6) = 2. +\begin{chunk}{*} + +--S 6 of 14 +curried(6) +--R +--R +--R (3) 2 +--R Type: PositiveInteger +--E 6 + +\end{chunk} +A three argument function can be curried in a similar way. +We have two possibilities. We could curry it to a two argument function +which returns a single argument curried function or we could curry it +to a one argument function which returns a two argument curried function. +Lets look at a 3 argument gcd. Given gcd(4,6,8) we expect 2. +\begin{chunk}{*} +)clear all + +--S 7 of 14 +gcd([4,6,8]) +--R +--R +--R (1) 2 +--R Type: PositiveInteger +--E 7 + +\end{chunk} +Lets start with a three argument function to curry: +\begin{chunk}{*} + +--S 8 of 14 +fn(x:Integer,y:Integer,z:Integer):Integer == gcd([x,y,z]) +--R +--R Function declaration fn : (Integer,Integer,Integer) -> Integer has +--R been added to workspace. +--R Type: Void +--E 8 + +\end{chunk} +So first we try the case where we want to curry the two argument function +and get a new function of one argument. This would be written: +\begin{chunk}{*} + +--S 9 of 14 +makeCurry1(x:Integer,y:Integer):(Integer->Integer) == z +-> fn(x,y,z) +--R +--R Function declaration makeCurry1 : (Integer,Integer) -> (Integer -> +--R Integer) has been added to workspace. +--R Type: Void +--E 9 + +\end{chunk} +Given $x$ and $y$ this will return a function of one argument: +\begin{chunk}{*} + +--S 10 of 14 +fn1:=makeCurry1(4,6) +--R +--R Compiling function fn with type (Integer,Integer,Integer) -> Integer +--R +--R Compiling function makeCurry1 with type (Integer,Integer) -> ( +--R Integer -> Integer) +--R +--R (4) theMap(NIL,0) +--R Type: (Integer -> Integer) +--E 10 + +\end{chunk} +This function, when given a $z$ will compute the gcd: +\begin{chunk}{*} + +--S 11 of 14 +fn1(8) +--R +--R +--R (5) 2 +--R Type: PositiveInteger +--E 11 + +\end{chunk} +Now we want a two argument curried function, which would be written as: +\begin{chunk}{*} + +--S 12 of 14 +makeCurry2(x:Integer):((Integer,Integer)->Integer) == (y,z) +-> fn(x,y,z) +--R +--R Function declaration makeCurry2 : Integer -> ((Integer,Integer) -> +--R Integer) has been added to workspace. +--R Type: Void +--E 12 + +\end{chunk} +Given $x$ this will return a function of two arguments: +\begin{chunk}{*} + +--S 13 of 14 +fn2:=makeCurry2(4) +--R +--R Compiling function makeCurry2 with type Integer -> ((Integer,Integer +--R ) -> Integer) +--R +--R (7) theMap(NIL,0) +--R Type: ((Integer,Integer) -> Integer) +--E 13 + +\end{chunk} +This function, when given $y$ and $z$ will compute the gcd: +\begin{chunk}{*} + +--S 14 of 14 +fn2(6,8) +--R +--R +--R (8) 2 +--R Type: PositiveInteger +--E 14 + +\end{chunk} +For other techniques see the packages MappingPackage2 and MappingPackage3 +\begin{chunk}{*} + +)spool +)lisp (bye) + +\end{chunk} +\eject +\begin{thebibliography}{99} +\bibitem{1} +\verb|http://permalink.gmane.org/gmane.comp.mathematics.open-axiom.devel/1002| +\bibitem{2} +\verb|http://permalink.gmane.org/gmane.comp.mathematics.open-axiom.devel/1004| +\end{thebibliography} +\end{document}