Vectors inner product

Description

Computing inner products of vectors iteratively.

Source: The Art of Prolog

Download

Program source code: vectors_inner_product.pl

Listing

/*
   inner_product(Xs,Ys,Value) :- 
	Value is the inner product of the vectors
	represented by the lists of integers Xs and Ys.
*/
     inner_product(Xs,Ys,IP) :- inner_product(Xs,Ys,0,IP).
 
     inner_product([X|Xs],[Y|Ys],Temp,IP) :-
         Temp1 is X*Y+Temp, inner_product(Xs,Ys,Temp1,IP).
     inner_product([],[],IP,IP).
 
%  Program 8.7b   Computing inner products of vectors iteratively

Comments

pl/prolog/pllib/vectors_inner_product.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0