Anonymous user
Horner's rule for polynomial evaluation: Difference between revisions
Horner's rule for polynomial evaluation (view source)
Revision as of 19:57, 3 May 2011
, 13 years ago→{{header|Prolog}}
(K version added) |
|||
Line 629:
<lang Prolog> ?- horner([-19, 7, -4, 6], 3, V).
V = 128.</lang>
===Functionnal approach===
Works with SWI-Prolog and module lambda, written by <b>Ulrich Neumerkel</b> found there http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/lambda.pl
<lang Prolog>:- use_module(library(lambda)).
% foldr(Pred, Init, List, R).
%
foldr(_Pred, Val, [], Val).
foldr(Pred, Val, [H | T], Res) :-
foldr(Pred, Val, T, Res1),
call(Pred, Res1, H, Res).
f_horner(L, V, R) :-
foldr(\X^Y^Z^(Z is X * V + Y), 0, L, R).
</lang>
=={{header|PureBasic}}==
|