Hey Guys, i have written the following program, that describes a lagged fibbonacci sequence, with
fib = 1, for 0<=n<2000 and
fib = fib(n-2000)+fib(n-1999), for n>=2000.
The problem:
When i call the programm (below) for a large "n", for example, for
n= 100000000000000 (in the code its X), prolog always returns "out of local stack". With a view in my code, is there a way to prevent that error? The modolu op is used, cause i want my solution modolued. Please do not make bad comments about the runtime of my program =D .
code:
:- dynamic fib/2.
fib(X,1) :- X>=0, X<2000,!.
fib(X,Y) :- X>=2000,!,
X1 is (X-2000),
fib(X1,Y1),
Y1 is Y1 mod 200000,
X2 is (X-1999),
fib(X2,Y2),
Y2 is Y2 mod 200000,
Y is ((Y1+Y2) mod 200000),
asserta( fib(X,Y) :- ! ).
user:
?- fib(10000000000000,Y).
Thank you helping !
fib = 1, for 0<=n<2000 and
fib = fib(n-2000)+fib(n-1999), for n>=2000.
The problem:
When i call the programm (below) for a large "n", for example, for
n= 100000000000000 (in the code its X), prolog always returns "out of local stack". With a view in my code, is there a way to prevent that error? The modolu op is used, cause i want my solution modolued. Please do not make bad comments about the runtime of my program =D .
code:
:- dynamic fib/2.
fib(X,1) :- X>=0, X<2000,!.
fib(X,Y) :- X>=2000,!,
X1 is (X-2000),
fib(X1,Y1),
Y1 is Y1 mod 200000,
X2 is (X-1999),
fib(X2,Y2),
Y2 is Y2 mod 200000,
Y is ((Y1+Y2) mod 200000),
asserta( fib(X,Y) :- ! ).
user:
?- fib(10000000000000,Y).
Thank you helping !