Thanks, so i will do.<div>I just wanted to be sure before.</div><div>;)<br><br>El jueves, 17 de septiembre de 2020, Alexandre Torres Porres <<a href="mailto:porres@gmail.com">porres@gmail.com</a>> escribió:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">hopefully you can open an issue on github please <a href="https://github.com/pure-data/pure-data/issues" target="_blank">https://github.com/<wbr>pure-data/pure-data/issues</a></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em qui., 17 de set. de 2020 às 18:12, oscar pablo di liscia <<a href="mailto:odiliscia@gmail.com" target="_blank">odiliscia@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:"arial narrow",sans-serif">Hello Albert:<br></div><div class="gmail_default" style="font-family:"arial narrow",sans-serif">Many thanks for your kind response and your advice. I want factorial to work on some combinatorial stuff.<br></div><div class="gmail_default" style="font-family:"arial narrow",sans-serif">I just wanted to check if I was doing something wrong with the use of "expr".  IMHO, the advantage</div><div class="gmail_default" style="font-family:"arial narrow",sans-serif">of  "expr" is that I can have "packed" in just one object a complete formula including</div><div class="gmail_default" style="font-family:"arial narrow",sans-serif">operator precedences. <br></div><div class="gmail_default" style="font-family:"arial narrow",sans-serif">Best<br></div><div class="gmail_default" style="font-family:"arial narrow",sans-serif"><br></div><div class="gmail_default" style="font-family:"arial narrow",sans-serif"><br clear="all"></div><div><div dir="ltr">Oscar Pablo Di Liscia</div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El jue., 17 sept. 2020 a las 4:24, Albert Rafetseder (<<a href="mailto:albert.rafetseder%2Bpd@univie.ac.at" target="_blank">albert.rafetseder+pd@univie.<wbr>ac.at</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Oscar,<br>
<br>
> the "fact" (factorial) function does not seem to work properly in the<br>
> "expr" external when called with an argument greater than 12.<br>
<br>
the problem in [expr fact(...)] looks like an integer overflow. See [1]<br>
for conceptual details, TL;DR: Factorials produce huge numbers very<br>
quickly, but the implementation of `fact` reserves too little space to<br>
store the result's digits [2], and thus truncates the result, producing<br>
garbage:<br>
<br>
[expr fact(12)] is 4.79002e+08, just about right<br>
[expr fact(13)] is 1.93205e+09, clearly *not* the above times 13<br>
[expr fact(14)] is 1.27895e+09, even smaller than the previous result<br>
(...)<br>
[expr fact(17)] is a negative number altogether<br>
<br>
I can't comment on the efficiency your implementation as I'm not too<br>
well versed in Pd. I'd speculate it won't suffer [expr fact]'s numerical<br>
problems since AFAIK, patches use floats as the default number format,<br>
basically allowing for larger numbers to be stored.<br>
<br>
The usual suggestion for avoiding numerical problems with factorials is<br>
to re-think what the numbers are used for -- Taylor series?<br>
combinatorials of n-choose-k kind? something else? -- and use an<br>
appropriate alternative such as:<br>
<br>
* Stirling's approximation [3]<br>
* the Gamma function [4]<br>
* binomial coefficient without factorials [5]<br>
<br>
Cheers,<br>
  Albert.<br>
<br>
[1] <a href="https://en.wikipedia.org/wiki/Integer_overflow" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/<wbr>Integer_overflow</a><br>
[2]<br>
<a href="https://github.com/pure-data/pure-data/blob/2af4b5d/src/x_vexp_fun.c#L913-L928" rel="noreferrer" target="_blank">https://github.com/pure-data/<wbr>pure-data/blob/2af4b5d/src/x_<wbr>vexp_fun.c#L913-L928</a><br>
[3] <a href="https://en.wikipedia.org/wiki/Stirling%27s_approximation" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/<wbr>Stirling%27s_approximation</a><br>
[4] <a href="https://en.wikipedia.org/wiki/Gamma_function" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/<wbr>Gamma_function</a><br>
[5]<br>
<a href="https://en.wikipedia.org/wiki/Binomial_coefficient#Binomial_coefficient_in_programming_languages" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/<wbr>Binomial_coefficient#Binomial_<wbr>coefficient_in_programming_<wbr>languages</a><br>
</blockquote></div>
______________________________<wbr>_________________<br>
<a href="mailto:Pd-list@lists.iem.at" target="_blank">Pd-list@lists.iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">https://lists.puredata.info/<wbr>listinfo/pd-list</a><br>
</blockquote></div>
</blockquote></div><br><br>-- <br>Oscar Pablo Di Liscia<br>