1 /* Scalar_Products class implementation (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 #ifndef PPL_Scalar_Products_inlines_hh
25 #define PPL_Scalar_Products_inlines_hh 1
26 
27 #include "Linear_Expression_defs.hh"
28 #include "Constraint_defs.hh"
29 #include "Generator_defs.hh"
30 #include "Congruence_defs.hh"
31 #include "Grid_Generator_defs.hh"
32 
33 namespace Parma_Polyhedra_Library {
34 
35 inline int
sign(const Linear_Expression & x,const Linear_Expression & y)36 Scalar_Products::sign(const Linear_Expression& x, const Linear_Expression& y) {
37   PPL_DIRTY_TEMP_COEFFICIENT(z);
38   assign(z, x, y);
39   return sgn(z);
40 }
41 
42 inline int
reduced_sign(const Linear_Expression & x,const Linear_Expression & y)43 Scalar_Products::reduced_sign(const Linear_Expression& x,
44                               const Linear_Expression& y) {
45   PPL_DIRTY_TEMP_COEFFICIENT(z);
46   reduced_assign(z, x, y);
47   return sgn(z);
48 }
49 
50 inline int
homogeneous_sign(const Linear_Expression & x,const Linear_Expression & y)51 Scalar_Products::homogeneous_sign(const Linear_Expression& x,
52                                   const Linear_Expression& y) {
53   PPL_DIRTY_TEMP_COEFFICIENT(z);
54   homogeneous_assign(z, x, y);
55   return sgn(z);
56 }
57 
58 inline int
sign(const Constraint & c,const Generator & g)59 Scalar_Products::sign(const Constraint& c, const Generator& g) {
60   return sign(c.expr, g.expr);
61 }
62 
63 inline int
sign(const Generator & g,const Constraint & c)64 Scalar_Products::sign(const Generator& g, const Constraint& c) {
65   return sign(g.expr, c.expr);
66 }
67 
68 inline int
sign(const Constraint & c,const Grid_Generator & g)69 Scalar_Products::sign(const Constraint& c, const Grid_Generator& g) {
70   PPL_DIRTY_TEMP_COEFFICIENT(z);
71   assign(z, c, g);
72   return sgn(z);
73 }
74 
75 inline int
reduced_sign(const Constraint & c,const Generator & g)76 Scalar_Products::reduced_sign(const Constraint& c, const Generator& g) {
77   // The reduced scalar product is only defined if the topology of `c' is
78   // NNC.
79   PPL_ASSERT(!c.is_necessarily_closed());
80   return reduced_sign(c.expr, g.expr);
81 }
82 
83 inline int
reduced_sign(const Generator & g,const Constraint & c)84 Scalar_Products::reduced_sign(const Generator& g, const Constraint& c) {
85   // The reduced scalar product is only defined if the topology of `g' is
86   // NNC.
87   PPL_ASSERT(!c.is_necessarily_closed());
88   return reduced_sign(g.expr, c.expr);
89 }
90 
91 inline void
homogeneous_assign(Coefficient & z,const Linear_Expression & e,const Generator & g)92 Scalar_Products::homogeneous_assign(Coefficient& z,
93                                     const Linear_Expression& e,
94                                     const Generator& g) {
95   homogeneous_assign(z, e, g.expr);
96 }
97 
98 inline void
homogeneous_assign(Coefficient & z,const Linear_Expression & e,const Grid_Generator & g)99 Scalar_Products::homogeneous_assign(Coefficient& z,
100                                     const Linear_Expression& e,
101                                     const Grid_Generator& g) {
102   homogeneous_assign(z, e, g.expr);
103 }
104 
105 inline int
homogeneous_sign(const Linear_Expression & e,const Generator & g)106 Scalar_Products::homogeneous_sign(const Linear_Expression& e,
107                                   const Generator& g) {
108   return homogeneous_sign(e, g.expr);
109 }
110 
111 inline int
homogeneous_sign(const Linear_Expression & e,const Grid_Generator & g)112 Scalar_Products::homogeneous_sign(const Linear_Expression& e,
113                                   const Grid_Generator& g) {
114   return homogeneous_sign(e, g.expr);
115 }
116 
117 inline int
homogeneous_sign(const Grid_Generator & g,const Constraint & c)118 Scalar_Products::homogeneous_sign(const Grid_Generator& g,
119                                   const Constraint& c) {
120   PPL_DIRTY_TEMP_COEFFICIENT(z);
121   homogeneous_assign(z, g, c);
122   return sgn(z);
123 }
124 
125 inline
126 Topology_Adjusted_Scalar_Product_Sign
Topology_Adjusted_Scalar_Product_Sign(const Constraint & c)127 ::Topology_Adjusted_Scalar_Product_Sign(const Constraint& c)
128   : sps_fp(c.is_necessarily_closed()
129            ? static_cast<SPS_type>(&Scalar_Products::sign)
130            : static_cast<SPS_type>(&Scalar_Products::reduced_sign)) {
131 }
132 
133 inline
134 Topology_Adjusted_Scalar_Product_Sign
Topology_Adjusted_Scalar_Product_Sign(const Generator & g)135 ::Topology_Adjusted_Scalar_Product_Sign(const Generator& g)
136   : sps_fp(g.is_necessarily_closed()
137            ? static_cast<SPS_type>(&Scalar_Products::sign)
138            : static_cast<SPS_type>(&Scalar_Products::reduced_sign)) {
139 }
140 
141 inline int
operator ()(const Constraint & c,const Generator & g) const142 Topology_Adjusted_Scalar_Product_Sign::operator()(const Constraint& c,
143                                                   const Generator& g) const {
144   PPL_ASSERT(c.space_dimension() <= g.space_dimension());
145   PPL_ASSERT(sps_fp == (c.is_necessarily_closed()
146                     ? static_cast<SPS_type>(&Scalar_Products::sign)
147                     : static_cast<SPS_type>(&Scalar_Products::reduced_sign)));
148   return sps_fp(c.expr, g.expr);
149 }
150 
151 inline int
operator ()(const Generator & g,const Constraint & c) const152 Topology_Adjusted_Scalar_Product_Sign::operator()(const Generator& g,
153                                                   const Constraint& c) const {
154   PPL_ASSERT(g.space_dimension() <= c.space_dimension());
155   PPL_ASSERT(sps_fp == (g.is_necessarily_closed()
156                     ? static_cast<SPS_type>(&Scalar_Products::sign)
157                     : static_cast<SPS_type>(&Scalar_Products::reduced_sign)));
158   return sps_fp(g.expr, c.expr);
159 }
160 
161 } // namespace Parma_Polyhedra_Library
162 
163 #endif // !defined(PPL_Scalar_Products_inlines_hh)
164