Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[Prolog] Matrix Multiplication

Status
Not open for further replies.

lipiec

Programmer
Mar 25, 2010
1
PL
Hi,

I found some code for Matrix Multiplication in Prolog but I can't figure out what is wrong with it.

mmultiply([],_,[]).
mmultiply([V0|Rest], V1, [Result|Others]):-
mmultiply(Rest, V1, Others),
multiply(V1,V0,Result).

multiply([],_,[]).
multiply([V0|Rest], V1, [Result|Others]):-
multiply(Rest, V1, Others),
vmul(V0,V1,Result).

vmul([],[],0).
vmul([H1|T1], [H2|T2], Result):-
vmul(T1,T2, Newresult),
Result is H1*H2+Newresult.

When I call mmultiply([[1,2],[1,2]],X,[[1,2],[1,2]]). Prolog throws an error:
ERROR: is/2: Arguments are not sufficiently instantiated.

I'm new in Prolog and I don't know what is wrong.
Thanks for any suggestions.
 
You can't use mmultiply this way.
arg 1 and 2 must be bound :
mmultiply([[1,2],[1,2]],[[1,2],[1,2]], X).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top