Finish ch05 practical.

This commit is contained in:
Kyle Isom 2018-01-18 18:01:08 -08:00
parent 5f9633349c
commit 9bf32e3aa5
1 changed files with 9 additions and 5 deletions

View File

@ -34,10 +34,9 @@ min([H|T], N) :-
%% should yield
%% Result = [6,21,12]
scalarMult(_, [], []).
scalarMult(K, [H|T], R) :-
V is K * H,
scalarMult(K, T, [R|V]).
scalarMult(K, [H|T], [V|R]) :-
V is K * H,
scalarMult(K, T, R).
%% 3. Another fundamental operation on vectors is the dot product. This
%% operation combines two vectors of the same dimension and yields a
@ -51,4 +50,9 @@ scalarMult(K, [H|T], R) :-
%% the query
%% ?- dot([2,5,6],[3,4,1],Result).
%% should yield
%% Result = 32
%% Result = 32
dot([], [], 0).
dot([X|TX], [Y|TY], R) :-
dot(TX, TY, R2),
V is X * Y,
R is R2 + V.