forked from LLNL/polycube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvec_oper.pl
29 lines (23 loc) · 793 Bytes
/
vec_oper.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
:- module(vec_oper,[vec_vec_sum/3,vec_mat_sum/3,scal_vec_sum/3,scal_vec_prod/3]).
:- use_module(library(clpfd)).
% Copyright 2019 Lawrence Livermore National Security, LLC.
% See the top-level LICENSE file for details.
%
% SPDX-License-Identifier: MIT
% Define clpfd addition and multiplication
add(A,B,C) :-
C #= A+B.
multiply(A,B,C) :-
C #= A*B.
% Define vector addition/subtraction
vec_vec_sum(Alist,Blist,Clist) :-
maplist(add(),Alist,Blist,Clist).
% Define vector addition like scalar addition for matrices
vec_mat_sum(Alist,Bmat,Cmat) :-
maplist(vec_vec_sum(Alist),Bmat,Cmat).
% Define scalar-vector addition
scal_vec_sum(A,Blist,Clist) :-
maplist(add(A),Blist,Clist).
% Define scalar-vector multiplication
scal_vec_prod(A,Blist,Clist) :-
maplist(multiply(A),Blist,Clist).