/* Matrix multiplication in Picat. Port of the B-Prolog program http://www.probp.com/examples/tabling/matrix.pl """ Taken from "Simplifying Dynamic Programming via Mode-directed Tabling" Software Practice and Experience, 38(1): 75-94, 2008, by Hai-Feng Guo, Gopal Gupta """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go => statistics(_, _), sc([50, 10, 400, 30, 30, 20, 10, 5, 30, 20, 6, 20, 20, 30, 9, 30, 20, 500, 20, 40, 30, 8, 3, 5, 9, 200, 10, 400, 20, 30, 56, 14, 430, 60, 35, 25, 15, 5, 35, 25, 50, 10, 400, 30, 30, 20, 10, 5, 30, 20, 35, 18, 32, 54, 94, 250, 70, 200, 50, 70, 6, 20, 20, 30, 9, 30, 20, 500, 20, 40, 80, 26, 405, 20, 70, 40, 90, 15, 20, 30, 6, 20, 20, 30, 9, 30, 20, 500, 20, 40, 30, 8, 3, 5, 9, 200, 10, 400, 20, 30], V, 50, 30), statistics(_, [_, B]), printf("Scalar Multiplication is %w\n",V), printf("execution time = %wms\n",B), nl. % This tabling yielded output_mode_error (as it does in B-Prolog) % table(+,min,-,-) % This works table(+,min,+,+) sc(P1P2, V, P1, P2) ?=> P1P2=[P1, P2], V=0. sc(PP, V, P1, Pn) => PP=[P1, P2, P3 | Pr], break([P1, P2, P3 | Pr], PL1, PL2, Pk), sc(PL1, V1, P1, Pk), sc(PL2, V2, Pk, Pn), V = V1 + V2 + P1 * Pk * Pn. break(A, B, C, P2) ?=> A=[P1, P2, P3], B=[P1, P2], C=[P2, P3]. break(A, B, C, P2) ?=> A=[P1, P2, P3, P4 | Pr], B=[P1, P2], C=[P2, P3, P4 | Pr]. break(A, B, L2, Pk) ?=> A=[P1, P2, P3, P4 | Pr], B=[P1 | L1], break([P2, P3, P4 | Pr], L1, L2, Pk).