users-prolog
[Top][All Lists]

## Re: Iteratively calling Prolog from C

 From: Daniel Dudley Subject: Re: Iteratively calling Prolog from C Date: Thu, 17 Jul 2003 18:35:59 +0200

```Daniele Peri wrote:
> Daniel Dudley wrote:
>
> > Using the top-level, I consulted factorial_nd.pl and then
> > ran the query:
> >
> >     | ?- factorial(14,F).
> >     F = 205203456
> >     yes
> >
> > Clearly an error will occur if N (the first argument) is
> > big. This is because, AFAIK, gprolog doesn't have a big
> > number library. Indeed,
> >
> >     | ?- factorial(15,F).
> >     F = -143173632
> >     yes
> >
> > Daniel
>
> Such little N doesn't really help testing the recursion
> optimization. As I told you before you may want to turn the
> factorial into a sum of integers (not very important) and try
> with a N large enough (important). The representation error
> you are talking about is a different subject.

Using the backtracking algorithm and ECLiPsE 5.6:

?- factorial(18795, F).
F =
3952928325081011170330983463363536161611503289391359475227321910004202
8582770124658795745092368035635105345429851003690568431580526759614623
0563527725541773086264690459212246922150651906759880977995025202235446
5579879017972481074452790669848933497157486741315449061642495203099992
5231007230222773224242994676769667945320136193354025566484206752078018
3609155255677486482762951513005056935306596671164840549047430436889905
0402367368430951456889911257277134285551307904509468299778986660590563
7260119908889815798245303633227672403084961254125390029979575462028468
5623722978243844386672911288035794469755841865128862244161821213941438
7068670920285230438684106266818008336741801739443303084642196634307928
3812812843012023955943031502529543139531401452484906677248788657623081
4056425622542036931029589033094372679033012317610476514325063604591415
8430292404097861558589324374456892086981680216475321697052403483105700
8791968650645204563638022799713158574363163353087276488553099544974153
2158053748319374674497802856877210167155192880251248393751097454812063
9661246406926031783753116408961726029049659235904955675252654311484284
6714757249164629218787520877540400694042988615533245706862853606327869
5732171149494506925474695693196247081693720273964820349905259394180430
4232749412474520621047234097469673797054099841773097132031973153651766
2554522032211661145495397535531881989726958034762527109116058131675522
9383929985515583573566545912043184179530118735264947881057575412160634
0677774238002063565520760643761209232593120141720465378393228401233527
1621832375738154976115506268927781533399027955363496235153702190994017
0402448342719613899713008925890234089872283750004271959833562994706075
4220665585061898184647952834397673419338305816731849491042235063932106
4797257608728489286553038978064688528889406792091588753396195593888033
3728549964414913298508555376483263812619952997417389490700644768249456
9883681736361785347459201825358001664998415726703351876719058380169463
446204106463973072218652022700248165...
Yes (6.47s cpu)

Big enough for you?

Daniel

```