Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
witness_set.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/nag_datatypes/witness_set.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/nag_datatypes/witness_set.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/nag_datatypes/witness_set.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22
28
29
30#pragma once
31
32#include <deque>
33#include <boost/serialization/deque.hpp>
34#include <boost/serialization/split_member.hpp>
39
40
41namespace bertini {
42
43 namespace nag_datatype {
44
46 template <typename T>
47 using PointCont = std::deque<T>;
48
50
76 template<typename NumT, typename SystemT = System, template<typename> class ObjManagementP = policy::Copy >
78 {
79 using PointP = ObjManagementP<Vec<NumT>>;
80 using SliceP = ObjManagementP<Slice>;
81 using SystemP = ObjManagementP<SystemT>;
82
83 using PointContT = PointCont<typename PointP::HeldT>;
84
85 PointContT points_;
86 typename SliceP::HeldT slice_;
87 typename SystemP::HeldT system_;
88
89
90public:
97
103 WitnessSet(PointContT const& pts, typename SliceP::HeldT const& slc, typename SystemP::HeldT const& sys) :
104 points_(pts),
105 slice_(slc),
106 system_(sys)
107 {}
108
109
115 inline
116 auto Degree() const
117 {
118 return GetPoints().size();
119 }
120
121
125 inline
126 auto Dimension() const
127 {
128 return GetSlice().Dimension();
129 }
130
131
135 inline
136 void AddPoint(typename PointP::HeldT const& p)
137 {
138 points_.push_back(p);
139 }
140
141
145 void SetPoints(PointContT const& pts)
146 {
147 points_ = pts;
148 }
149
150
154 inline
155 const PointContT& GetPoints() const
156 {
157 return points_;
158 }
159
163 const Vec<NumT>& GetPoint(IndexT ind) const
164 {
165 if (ind > Degree())
166 {
167 std::stringstream ss;
168 ss << "asking for point of index " << ind << ", outside range [0,"<<Degree()-1 << "].";
169 throw std::runtime_error(ss.str());
170 }
171
172 return PointP::AtGet(points_[ind]);
173 }
174
175
179 const Vec<NumT>& operator[](IndexT ind) const
180 {
181 return PointP::AtGet(points_[ind]);
182 }
183
184
185
186
187
193 void SetSystem(typename SystemP::HeldT const& sys)
194 {
195 system_ = sys;
196 }
197
198
202 inline
203 const SystemT& GetSystem() const
204 {
205 return SystemP::AtGet(system_);
206 }
207
208
214 void SetSlice(typename SliceP::HeldT const& s)
215 {
216 slice_ = s;
217 }
218
222 const Slice & GetSlice() const
223 {
224 return SliceP::AtGet(slice_);
225 }
226
230 bool IsConsistent() const
231 {
232 return (GetSystem().NumVariables() - GetSystem().NumNaturalFunctions()) == GetSlice().Dimension();
233 }
234
235
236 private:
237
238 friend class boost::serialization::access;
239
245 template <typename Archive>
246 void save(Archive& ar, const unsigned /*version*/) const
247 {
248 ar & points_;
249 ar & slice_;
250 ar & system_;
251 }
252
253 template <typename Archive>
254 void load(Archive& ar, const unsigned /*version*/)
255 {
256 ar & points_;
257 ar & slice_;
258 ar & system_;
259 // GetSystem() is const and returns a const System&; Differentiate()/precision() are
260 // const (they mutate only the system's mutable evaluation state), so this restores
261 // the held system in place regardless of object-management policy.
262 GetSystem().Differentiate();
263 // the precision self-assignment that used to sit here (a re-materialize at the
264 // value already held) is unnecessary: the first evaluation after load
265 // materializes the system at the precision of the point it is given (#377)
266 }
267
268 BOOST_SERIALIZATION_SPLIT_MEMBER()
269
270 };
271 }
272}
A linear slice of affine or projective space: a stack of linear forms, M [x ; 1].
Definition slice.hpp:68
unsigned Dimension() const
The dimension of the slice – the number of linear forms.
Definition slice.hpp:372
const Slice & GetSlice() const
Gets (a const reference to) the slice for the witness set.
Definition witness_set.hpp:222
const SystemT & GetSystem() const
Gets a (const reference to) the system for the witness set.
Definition witness_set.hpp:203
const Vec< NumT > & operator[](IndexT ind) const
Non-range-checked accessor to get points from witness set.
Definition witness_set.hpp:179
void SetSlice(typename SliceP::HeldT const &s)
Sets the slice for the witness set.
Definition witness_set.hpp:214
WitnessSet(PointContT const &pts, typename SliceP::HeldT const &slc, typename SystemP::HeldT const &sys)
Construct a witness set from points, slice, and system.
Definition witness_set.hpp:103
const PointContT & GetPoints() const
Get (a const reference to) the set of points for the witness set.
Definition witness_set.hpp:155
WitnessSet()
The default constructor.
Definition witness_set.hpp:96
bool IsConsistent() const
Check whether the witness set makes sense, in terms of system size, number of variables,...
Definition witness_set.hpp:230
auto Degree() const
Get the degree of the witness set.
Definition witness_set.hpp:116
void SetSystem(typename SystemP::HeldT const &sys)
Sets the system for the witness set.
Definition witness_set.hpp:193
void SetPoints(PointContT const &pts)
Sets the set of points for the witness set.
Definition witness_set.hpp:145
const Vec< NumT > & GetPoint(IndexT ind) const
Range-checked version of point getter for witness set.
Definition witness_set.hpp:163
auto Dimension() const
Query the dimension of the witness set.
Definition witness_set.hpp:126
void AddPoint(typename PointP::HeldT const &p)
Adds a point to the witness set.
Definition witness_set.hpp:136
Bertini extensions of the Eigen linear algebra library.
Definition policies.hpp:9
typename PointCont< int >::size_type IndexT
The index type for point containers.
Definition witness_set.hpp:49
std::deque< T > PointCont
The container type used to hold points (a deque).
Definition witness_set.hpp:47
Definition algorithm_builder.hpp:36
Eigen::Matrix< NumT, Eigen::Dynamic, 1 > Vec
A dynamically-sized column vector of NumT.
Definition eigen_extensions.hpp:296
Provides the bertini::Slice class – a linear slice of affine or projective space.
Storage policy that holds objects by value (a copy).
Definition policies.hpp:16
Provides the bertini::System class.