<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-2022-jp">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7036.0">
<TITLE>RE: [racket] Math - factorial.rkt, binomial.rkt and memoization</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><SPAN LANG="es"><FONT SIZE=2 FACE="Arial"> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">Thanks for your interesting replies. It was just my first thought.</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">Jos</FONT></SPAN>
</P>
<P><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> -----Original Message-----</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> From: users-bounces@racket-lang.org </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> [</FONT></SPAN><A HREF="mailto:users-bounces@racket-lang.org"><SPAN LANG="es"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">mailto:users-bounces@racket-lang.org</FONT></U></SPAN></A><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">] On Behalf Of Neil Toronto</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> Sent: martes, 09 de abril de 2013 22:00</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> To: users@racket-lang.org</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> Subject: Re: [racket] Math - factorial.rkt, binomial.rkt and </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> memoization</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> On 04/09/2013 11:41 AM, Hendrik Boom wrote:</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> > On Tue, Apr 09, 2013 at 08:26:31PM +0200, Jos Koot wrote:</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> >> Would it be possible to use</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> >> <</FONT></SPAN><A HREF="http://en.wikipedia.org/wiki/Stirling%27s_approximation"><SPAN LANG="es"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://en.wikipedia.org/wiki/Stirling%27s_approximation</FONT></U></SPAN></A><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> Stirling's</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> >> approximation for a fast inexact first approximation for </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> factorials of very</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> >> big numbers and from there quickly get to an exact </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> factorial? (if exactness</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> >> is required) I don't know for I haven't thought thoroughly </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> about this.</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> >> Jos.</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> ></FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> > I don't know of a way take an approximation and by applying some</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> > operation to it to get a better one.</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> ></FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> > There are ways to do thie for other functions, like squate </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> root, but I</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> > don't know one for factorial.</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> For Newton's method, you'd need a differentiable inverse, but </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> computing </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> the gamma function's inverse is hard in the first place.</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> > But there might be a bound on the error in Stirling's </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> approximation that</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> > you cna use teo determine whether that's good enough for your</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> > application (if you have one).</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> Use the first omitted series term as the signed relative </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> error bound. If </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> this is e, then exp(|e|)-1 (which is nearly |e| for small e) is the </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> relative error bound after exponentiating.</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> Stirling's series isn't convergent for any particular n; i.e. </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> for any n </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> there's a point at which adding more terms makes the error </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> worse. On the </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> other hand, for any fixed number of terms, error decreases as *n* </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> increases. So the thing I'd try first is finding the n for which the </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> error of the non-polynomial part n * log(n) - n + 1/2 * </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> log(2*pi*n) is </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> acceptable, and use its exponential</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> n^((2*n+1)/2) * exp(-n) * sqrt(2*pi)</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> for all greater n. The tricky part would be computing exp(-n) with </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> acceptable precision. (In fact, this is where I'd go looking </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> for other </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> solutions.)</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="MS PGothic">> Neil $B"](J</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> ____________________</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> Racket Users list:</FONT></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN><A HREF="http://lists.racket-lang.org/users"><SPAN LANG="es"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://lists.racket-lang.org/users</FONT></U></SPAN></A><SPAN LANG="es"></SPAN>
<BR><SPAN LANG="es"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
</P>
</BODY>
</HTML>