Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
pl:prolog:pllib:vectors_inner_product [2019/06/27 15:50] |
pl:prolog:pllib:vectors_inner_product [2019/06/27 15:50] (aktualna) |
| ====== Vectors inner product ====== |
| {{tag>math}} |
| ===== Description ===== |
| Computing inner products of vectors iteratively. |
| |
| **Source**: The Art of Prolog |
| ===== Download ===== |
| Program source code: {{vectors_inner_product.pl}} |
| ===== Listing ===== |
| <code prolog> |
| /* |
| 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 |
| |
| </code> |
| ===== Comments ===== |
| |