Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Implementation of SUM operation
  3. */
  4.  
  5. /* call sum for every element of row */
  6. sumOperation(L1,L2,SUM):-!,maplist(sumRows,L1,L2,SUM).
  7.  
  8. /* sum elements */
  9. sumRows(H1,H2,H):-!,H is H1+H2.
  10.  
  11. /* main SUM function */
  12. sum(SET1,SET2,SUM):-!,
  13.     rowCount(SET1,RS1),
  14.     rowCount(SET2,RS2),
  15.     colCount(SET1,CS1),
  16.     colCount(SET2,CS2),
  17.     (RS1 == RS2 ->  /* same column and row count for sum  */
  18.         (CS1 == CS2->
  19.             maplist(sumOperation,SET1,SET2,SUM); /* map operation for every row of matrixes */
  20.             SUM=false);
  21.         SUM=false).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement