Click here to get back home

bignum 0.22

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
bignum 0.22 gamo 07-04-2007
`--> Re: bignum 0.22 José Luis Pérez...07-05-2007
Posted by gamo on July 4, 2007, 9:43 am
Please log in for more thread options



Hello

I found a problem related with calculating Catalan's numbers

#!/usr/local/bin/perl -w

use bignum;

while (1){
$n++;
# $Cat = (fact(2*$n))/((n+1)!n!)
$Cat = (fact(2*$n))/(($n+1)*fact($n)**2);
print "$Cat\n";
last if length $Cat > 78;
}

sub fact {
my $i = shift;
my $f = 1;
while ($i>1){
        $f *= $i;
        $i--;
}
return $f;
}

__END__

TIA

--
http://www.telecable.es/personales/gamo/
perl -e 'print 111_111_111**2,"\n";'

Posted by Sisyphus on July 5, 2007, 4:47 am
Please log in for more thread options



>
> Hello
>
> I found a problem related with calculating Catalan's numbers
>

What is the problem ? (I don't see it.)

Cheers,
Rob


Posted by gamo on July 5, 2007, 5:36 am
Please log in for more thread options


On Thu, 5 Jul 2007, Sisyphus wrote:

>
> >
> > Hello
> >
> > I found a problem related with calculating Catalan's numbers
> >
>
> What is the problem ? (I don't see it.)
>
> Cheers,
> Rob
>

The problem is that this output lacks precision aparently

216489185503133990863274261791925599831200000000000000000000
853702637172735926234421145556838686126800000000000000000000
3366939372774715522158184331074634818182000000000000000000000
13280705303722489004068393750349948449500000000000000000000000
52391773216519910749994580850004383791590000000000000000000000
206709359781542193322705891717290023323200000000000000000000000
815663960219058384462569194343901173113100000000000000000000000
3218959557293069695825496284821467129607000000000000000000000000
12704920022590345879098861442746675573490000000000000000000000000
50151000089172417943811295168736877263790000000000000000000000000
197987426438993719534698504405274280676200000000000000000000000000
781708976802233823680102715669100177152500000000000000000000000000
3086748267372923303762456877257472494397000000000000000000000000000
12190039767760866606383939871203238833810000000000000000000000000000
48145535217206784075634048230802707999060000000000000000000000000000
190174864107966797098754490511670696596300000000000000000000000000000
751269297881058917464501210451062751843200000000000000000000000000000
2968129521136642608343357241290264314659000000000000000000000000000000
11727731278637465915893265197293239487190000000000000000000000000000000
46343454246228695957965322150594252812290000000000000000000000000000000
183149331181095806425878953139148487114200000000000000000000000000000000
723875928001473901587997767169015449070200000000000000000000000000000000
2861304849265668492891140780463352404986000000000000000000000000000000000
11311095732253345760960290897769189975960000000000000000000000000000000000
44718285453094622775889522153971216184030000000000000000000000000000000000
176809220945312585436978572208778500912300000000000000000000000000000000000
699138751524213124094312216825551629561400000000000000000000000000000000000
2764775971936660990736598311991954171447000000000000000000000000000000000000
10934377152170553993439479038404269881060000000000000000000000000000000000000
43247909631719355347185999181748231619130000000000000000000000000000000000000
171069509209912116706646841207804116182300000000000000000000000000000000000000
676730852609799402854235298307342753721300000000000000000000000000000000000000

Cheers,

--
http://www.telecable.es/personales/gamo/
perl -e 'print 111_111_111**2,"\n";'

Posted by gamo on July 5, 2007, 6:55 am
Please log in for more thread options


On Thu, 5 Jul 2007, gamo wrote:

> On Thu, 5 Jul 2007, Sisyphus wrote:
>
> >
> > >
> > > Hello
> > >
> > > I found a problem related with calculating Catalan's numbers
> > >
> >
> > What is the problem ? (I don't see it.)
> >
> > Cheers,
> > Rob
> >
>
> The problem is that this output lacks precision aparently
>
> 216489185503133990863274261791925599831200000000000000000000
> 853702637172735926234421145556838686126800000000000000000000
> 3366939372774715522158184331074634818182000000000000000000000
> 13280705303722489004068393750349948449500000000000000000000000
> 52391773216519910749994580850004383791590000000000000000000000
> 206709359781542193322705891717290023323200000000000000000000000
> 815663960219058384462569194343901173113100000000000000000000000
> 3218959557293069695825496284821467129607000000000000000000000000
> 12704920022590345879098861442746675573490000000000000000000000000
> 50151000089172417943811295168736877263790000000000000000000000000
> 197987426438993719534698504405274280676200000000000000000000000000
> 781708976802233823680102715669100177152500000000000000000000000000
> 3086748267372923303762456877257472494397000000000000000000000000000
> 12190039767760866606383939871203238833810000000000000000000000000000
> 48145535217206784075634048230802707999060000000000000000000000000000
> 190174864107966797098754490511670696596300000000000000000000000000000
> 751269297881058917464501210451062751843200000000000000000000000000000
> 2968129521136642608343357241290264314659000000000000000000000000000000
> 11727731278637465915893265197293239487190000000000000000000000000000000
> 46343454246228695957965322150594252812290000000000000000000000000000000
> 183149331181095806425878953139148487114200000000000000000000000000000000
> 723875928001473901587997767169015449070200000000000000000000000000000000
> 2861304849265668492891140780463352404986000000000000000000000000000000000
> 11311095732253345760960290897769189975960000000000000000000000000000000000
> 44718285453094622775889522153971216184030000000000000000000000000000000000
> 176809220945312585436978572208778500912300000000000000000000000000000000000
> 699138751524213124094312216825551629561400000000000000000000000000000000000
> 2764775971936660990736598311991954171447000000000000000000000000000000000000
> 10934377152170553993439479038404269881060000000000000000000000000000000000000
> 43247909631719355347185999181748231619130000000000000000000000000000000000000
> 171069509209912116706646841207804116182300000000000000000000000000000000000000
> 676730852609799402854235298307342753721300000000000000000000000000000000000000
>
> Cheers,
>
> --
> http://www.telecable.es/personales/gamo/
> perl -e 'print 111_111_111**2,"\n";'
>

The real Catalan numbers are of this form

50151000089172417943811295168736877263790538026356457136124707000
197987426438993719534698504405274280676181776208398535128701017200
781708976802233823680102715669100177152510806064194216284009188600
3086748267372923303762456877257472494397093952150920751480446539600
12190039767760866606383939871203238833805472726290924323643119385200
48145535217206784075634048230802707999063631776107012034556858076000
190174864107966797098754490511670696596301345515622697536499589400200
751269297881058917464501210451062751843240026086509499359064493663600
2968129521136642608343357241290264314659358135849980153205484311031600
11727731278637465915893265197293239487190634585553580117543620936271200
46343454246228695957965322150594252812285572152590760141906244022362000
183149331181095806425878953139148487114152581147038684080813476376374624
723875928001473901587997767169015449070222106438295751367024692344718752
2861304849265668492891140780463352404986232263244287143198790516197234752
11311095732253345760960290897769189975961199415637572612957718759342193629
44718285453094622775889522153971216184032648852520635911693306722980765510
176809220945312585436978572208778500912252165463043129681618151197016257478
699138751524213124094312216825551629561424593205010237977696200916445964684
2764775971936660990736598311991954171447451800401631395639071339987763587614
10934377152170553993439479038404269881062854488806451985760537780703486068308
43247909631719355347185999181748231619129200590055369794426007640095877732860
171069509209912116706646841207804116182333282333996796075729541331934805254424
676730852609799402854235298307342753721289013938899090358400685563095038432942
2677285562879644352897777603522480091364515660984549685943453807118230006063172

--
http://www.telecable.es/personales/gamo/
perl -e 'print 111_111_111**2,"\n";'

Posted by Mumia W. on July 5, 2007, 10:41 am
Please log in for more thread options


On 07/05/2007 04:36 AM, gamo wrote:
> On Thu, 5 Jul 2007, Sisyphus wrote:
>
>>> Hello
>>>
>>> I found a problem related with calculating Catalan's numbers
>>>
>> What is the problem ? (I don't see it.)
>>
>> Cheers,
>> Rob
>>
>
> The problem is that this output lacks precision aparently
>
> 216489185503133990863274261791925599831200000000000000000000
> 853702637172735926234421145556838686126800000000000000000000
> 3366939372774715522158184331074634818182000000000000000000000
> [...]

You can set the "accuracy" of the bignum module. Read "perldoc bignum"

BTW, if you make fact() recursive and use the Memoize module, you can
get a speed improvement--a /substantial/ speed improvement :-)



Similar ThreadsPosted
Problem around bignum March 28, 2006, 6:04 am
bignum incompatible with loos_like_number ??? June 26, 2007, 10:05 pm
bignum incompatible with looks_like_number() ??? June 26, 2007, 10:17 pm
Error in perl module "bignum"... May 14, 2006, 4:31 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap