1 /* Scalar_Products class implementation (non-inline functions).
2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4
5 This file is part of the Parma Polyhedra Library (PPL).
6
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23
24 #include "ppl-config.h"
25 #include "Scalar_Products_defs.hh"
26 #include "Scalar_Products_inlines.hh"
27 #include "Coefficient_defs.hh"
28
29 namespace PPL = Parma_Polyhedra_Library;
30
31 void
assign(Coefficient & z,const Linear_Expression & x,const Linear_Expression & y)32 PPL::Scalar_Products::assign(Coefficient& z,
33 const Linear_Expression& x,
34 const Linear_Expression& y) {
35 x.scalar_product_assign(z, y);
36 }
37
38 void
assign(Coefficient & z,const Constraint & c,const Generator & g)39 PPL::Scalar_Products::assign(Coefficient& z,
40 const Constraint& c, const Generator& g) {
41 assign(z, c.expr, g.expr);
42 }
43
44 void
assign(Coefficient & z,const Generator & g,const Constraint & c)45 PPL::Scalar_Products::assign(Coefficient& z,
46 const Generator& g, const Constraint& c) {
47 assign(z, g.expr, c.expr);
48 }
49
50 void
assign(Coefficient & z,const Grid_Generator & gg,const Congruence & cg)51 PPL::Scalar_Products::assign(Coefficient& z,
52 const Grid_Generator& gg, const Congruence& cg) {
53 gg.expr.scalar_product_assign(z, cg.expr, 0, gg.space_dimension() + 1);
54 }
55
56 void
assign(Coefficient & z,const Constraint & c,const Grid_Generator & gg)57 PPL::Scalar_Products::assign(Coefficient& z,
58 const Constraint& c,
59 const Grid_Generator& gg) {
60 assign(z, c.expr, gg.expr);
61 }
62
63 void
assign(Coefficient & z,const Congruence & cg,const Grid_Generator & gg)64 PPL::Scalar_Products::assign(Coefficient& z,
65 const Congruence& cg, const Grid_Generator& gg) {
66 // Scalar product is only defined if `cg' and `gg' are
67 // dimension-compatible.
68 PPL_ASSERT(cg.space_dimension() <= gg.space_dimension());
69 cg.expr.scalar_product_assign(z, gg.expr);
70 }
71
72 void
reduced_assign(Coefficient & z,const Linear_Expression & x,const Linear_Expression & y)73 PPL::Scalar_Products::reduced_assign(Coefficient& z,
74 const Linear_Expression& x,
75 const Linear_Expression& y) {
76 // The reduced scalar product is only defined
77 // if `y' has enough coefficients.
78 PPL_ASSERT(x.space_dimension() - 1 <= y.space_dimension());
79 x.scalar_product_assign(z, y, 0, x.space_dimension());
80 }
81
82 void
reduced_assign(Coefficient & z,const Grid_Generator & gg,const Congruence & cg)83 PPL::Scalar_Products::reduced_assign(Coefficient& z,
84 const Grid_Generator& gg,
85 const Congruence& cg) {
86 // The reduced scalar product is only defined
87 // if `cg' has enough coefficients.
88 PPL_ASSERT(gg.space_dimension() <= cg.space_dimension());
89 gg.expr.scalar_product_assign(z, cg.expr, 0, gg.space_dimension());
90 }
91
92 void
homogeneous_assign(Coefficient & z,const Linear_Expression & x,const Linear_Expression & y)93 PPL::Scalar_Products::homogeneous_assign(Coefficient& z,
94 const Linear_Expression& x,
95 const Linear_Expression& y) {
96 // Scalar product is only defined if `x' and `y' are
97 // dimension-compatible.
98 PPL_ASSERT(x.space_dimension() <= y.space_dimension());
99 x.scalar_product_assign(z, y, 1, x.space_dimension() + 1);
100 }
101
102 void
homogeneous_assign(Coefficient & z,const Grid_Generator & gg,const Congruence & cg)103 PPL::Scalar_Products::homogeneous_assign(Coefficient& z,
104 const Grid_Generator& gg,
105 const Congruence& cg) {
106 // Scalar product is only defined if `gg' and `cg' are
107 // dimension-compatible.
108 PPL_ASSERT(gg.space_dimension() <= cg.space_dimension());
109 gg.expr.scalar_product_assign(z, cg.expr, 1, gg.space_dimension() + 1);
110 }
111
112 void
homogeneous_assign(Coefficient & z,const Grid_Generator & gg,const Constraint & c)113 PPL::Scalar_Products::homogeneous_assign(Coefficient& z,
114 const Grid_Generator& gg,
115 const Constraint& c) {
116 // Scalar product is only defined if `gg' and `c' are
117 // dimension-compatible.
118 PPL_ASSERT(gg.space_dimension() <= c.space_dimension());
119 gg.expr.scalar_product_assign(z, c.expr, 1, gg.space_dimension() + 1);
120 }
121