Category : Miscellaneous Language Source Code
Archive   : PROLOG19.ZIP
Filename : MATRIX.PRO

 
Output of file : MATRIX.PRO contained in archive : PROLOG19.ZIP


con_num_list( [H|T] ) :- rnum( H ), con_num_list( T ).
con_num_list( [] ).


/* To multiply a row by a column: */

mat_mult( [H1|T1], [H2|T2], res ) :-
mat_mult1( [H1|T1], [H2|T2], 0, res ).

mat_mult1( [H1|T1], [H2|T2], sum, res ) :-
sum is sum + H1 * H2,
mat_mult1( T1, T2, sum, res ).

mat_mult1( [], [], sum, res ) :- res = sum.


/* To get the nth element of a list:
Let us assume a matrix in the form of a list of columns:

[ L1, L2.....]
*/


listel( N, [H|T], X ) :-
N > 0,
N is N - 1,
listel( N, T, X ).

listel( N, [H|_], X ) :- X = H.

/* Below, X, Y are the "coordinates".
L is the complex list representing the array.
element is the returned value. */

matrix_el( X, Y, L, element ) :-

/* First get the row, represented as an element "rowel" in list L */

listel( X, L, rowel ),

/* And now the value contained within the row. */
listel( Y, rowel, element ).


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : PROLOG19.ZIP
Filename : MATRIX.PRO

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/