return page history
α-wwwiki
::
history/curry/20130606-062711.txt
editor : alpha [82.255.25.228] 2013/06/06 06:27:11 _h2 derivee with curryfication _ul [[curry-cooking-up-tastier-functions|http://javascriptweblog.wordpress.com/2010/04/05/curry-cooking-up-tastier-functions/]] _ul [[top_ten|http://javascriptweblog.wordpress.com/2010/04/02/my-top-10-javascript-blogs/]] _ul [[www.svendtofte.com/code/curried_javascript|http://www.svendtofte.com/code/curried_javascript/]] _ul [[slid.es/gsklee/functional-programming-in-5-minutes|http://slid.es/gsklee/functional-programming-in-5-minutes#]] _p Grace to curryfication, the derivee of a function for a given value can be done in two "partial" steps, first creating the function, then applying it at a given value. And so, it is possible to define next derivees {u before} applying them at a given value. {pre Instead of : derivee( func, x), we use : derivee(func)(x) or in 2 steps : 1) f1 = derivee(func) -> function 2) f1(x) -> value } _h4 first derivees of cubic function {p Enter a value : {input {@ type="text" value="2" onblur="°° var derivee = function (f) { return function (x) { return (f(x+0.01)-f(x-0.01))/(2*0.01) } } var f0 = function (x) { return x*x*x; } // f0 = x^3 = 1 var f1 = derivee(f0); // f1 = 3*x^2 = 3 var f2 = derivee(f1); // f2 = 6*x = 6 var f3 = derivee(f2); // f3 = 6 var f4 = derivee(f3); // f4 = 0 var x = parseFloat( this.value ); getId('console').innerHTML = f0(x)+'\n'+f1(x)+'\n'+f2(x)+'\n'+f3(x)+'\n'+f4(x); °°"}}, then click outside the field.} {pre {@ id="console"}} _h4 code {pre °° var derivee = function (f) { return function (x) { return (f(x+0.01)-f(x-0.01))/(2*0.01) } } var f0 = function (x) { return x*x*x; } // f0 = x^3 = 1 var f1 = derivee(f0); // f1 = 3*x^2 = 3 var f2 = derivee(f1); // f2 = 6*x = 6 var f3 = derivee(f2); // f3 = 6 var f4 = derivee(f3); // f4 = 0 var x = parseFloat( this.value ); getId('console').innerHTML = f0(x)+'\n'+f1(x)+'\n'+f2(x)+'\n'+f3(x)+'\n'+f4(x); °°} _h6 The 4th derivee can be rewritten as : {pre var f4 = derivee(f3) = derivee(derivee(f2)) = derivee(derivee(derivee(f1))) = derivee(derivee(derivee(derivee(f0)))) var y = derivee(derivee(derivee(derivee(f0))))(x) = (derivee (derivee (derivee (derivee (f0)))) (x)) } _h6 a javascript code which looks like pure LISP code (see [[diff_int|../lambdaway_2.0/?view=diff_int]] in lambdaway) {pre °° function cubic at x=1 {define cubic (:x) (* :x :x :x)} -> cubic {cubic 1} -> 1 {{D cubic} 1} -> 3.0000009999997523 (≠ 3) {{D {D cubic}} 1} -> 5.999999999894978 (≠ -6) {{D {D {D cubic}}} 1} -> 6.0000000245974405 (≠ 6) {{D {D {D {D cubic}}}} 1} -> 0.00004163336342344337 (≠ 0) °°} _h3 todo _p Transpose the javascript curryfication in lambdatalk(lite).