update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
|
|
@ -1,13 +1,19 @@
|
|||
:- use_module(lambda).
|
||||
fib(N, FN) :-
|
||||
cont_fib(N, _, FN, \_^Y^_^U^(U = Y)).
|
||||
?- time(fib(0,F)).
|
||||
% 2 inferences, 0.000 CPU in 0.000 seconds (88% CPU, 161943 Lips)
|
||||
F = 0.
|
||||
|
||||
cont_fib(N, FN1, FN, Pred) :-
|
||||
( N < 2 ->
|
||||
call(Pred, 0, 1, FN1, FN)
|
||||
;
|
||||
N1 is N - 1,
|
||||
P = \X^Y^Y^U^(U is X + Y),
|
||||
cont_fib(N1, FNA, FNB, P),
|
||||
call(Pred, FNA, FNB, FN1, FN)
|
||||
).
|
||||
?- time(fib(10,F)).
|
||||
% 265 inferences, 0.000 CPU in 0.000 seconds (98% CPU, 1458135 Lips)
|
||||
F = 55.
|
||||
|
||||
?- time(fib(20,F)).
|
||||
% 32,836 inferences, 0.016 CPU in 0.016 seconds (99% CPU, 2086352 Lips)
|
||||
F = 6765.
|
||||
|
||||
?- time(fib(30,F)).
|
||||
% 4,038,805 inferences, 1.122 CPU in 1.139 seconds (98% CPU, 3599899 Lips)
|
||||
F = 832040.
|
||||
|
||||
?- time(fib(40,F)).
|
||||
% 496,740,421 inferences, 138.705 CPU in 140.206 seconds (99% CPU, 3581264 Lips)
|
||||
F = 102334155.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue