# Matrix multiply

## Description

Multiplication matixs

Source: PROLOG str. 203 Wydawnictwo PLJ Warszawa 1991 ISBN 83-85190-63-5

## Download

Program source code: matrix_multiply.pl

## Listing

```transp(A, B) :- dlug(A, N), pusta(N, T, 0), t2(A, T, B).

t1([X|Y], [G|O], [Z|U]) :- append(G, [X], Z), t1(Y, O, U), !.
t1([], [], []) :- !.
t2([L1|G1], L, V) :- t1(L1, L, K), t2(G1, K, V), !.
t2([], L, L).
dlug([G|_], N) :- d11(G, 0, N).
d11([], X, X).
d11([_|T], I, N) :- J is I + 1, d11(T, J, N).

pusta(N, [], N).
pusta(J, [[]|O], I) :- Jn is I + 1, pusta(J, O, Jn), !.

mnozm(A, B, C) :- transp(B, X), mnm(A, X, C).

mn1(_, [], []).
mn1(U, [H|T], [W|X]) :- sum(U, H, W, 0), mn1(U, T, X).

mnm([], _, []) :- !.
mnm([H|T], L, [X|Y]) :- mn1(H, L, X), mnm(T, L, Y).

sum([], [], K, K).
sum([G1|O1], [G2|O2], S, N) :- Sum is N + (G1*G2), sum(O1, O2, S, Sum).

test :- mnozm([[2, 1, 0], [1, -1, 2]], [[1, 2], [2, 3], [0, 3]], C).```

## Comments

pl/prolog/pllib/matrix_multiply.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)