Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
describe.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//describe.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//describe.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 describe.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17
27
28#pragma once
29
30#include <ostream>
31#include <string>
32
35
36namespace bertini {
37namespace blocks {
38namespace describe_detail {
39
43inline constexpr size_t kTerseRowCap = 10;
44
47template <typename R>
48inline std::string FmtReal(R const& r, int sig)
49{
50 return (sig > 0) ? r.str(sig) : r.str();
51}
52
56inline void PrintCoeff(std::ostream& out, complex_mp const& c, int sig = 0)
57{
58 const bool re0 = (c.real() == 0), im0 = (c.imag() == 0);
59 if (im0) out << FmtReal(c.real(), sig);
60 else if (re0) out << FmtReal(c.imag(), sig) << "*i";
61 else out << "(" << FmtReal(c.real(), sig) << "+" << FmtReal(c.imag(), sig) << "*i)";
62}
63
68inline int CoeffSig(bool verbose) { return verbose ? static_cast<int>(DefaultPrecision()) : 4; }
69
71inline void PrintRowLabel(std::ostream& out, size_t row, size_t n)
72{
73 out << "f_" << row;
74 if (n > 1)
75 out << "..f_" << (row + n - 1);
76}
77
79inline void PrintAugmentedVars(std::ostream& out, VariableGroup const& vars, size_t num_vars, bool homogeneous)
80{
81 out << "[";
82 for (size_t c = 0; c < num_vars && c < vars.size(); ++c)
83 out << (c ? ", " : "") << *vars[c];
84 if (!homogeneous)
85 out << ", 1";
86 out << "]";
87}
88
92inline void PrintLinearFormVerbose(std::ostream& out, Mat<complex_mp> const& M, Eigen::Index r,
93 VariableGroup const& vars, size_t num_vars, bool homogeneous)
94{
95 bool first = true;
96 const size_t ncol = homogeneous ? num_vars : num_vars + 1;
97 for (size_t c = 0; c < ncol; ++c)
98 {
99 complex_mp const& coeff = M(r, static_cast<Eigen::Index>(c));
100 if (coeff.real() == 0 && coeff.imag() == 0)
101 continue;
102 if (!first) out << " + ";
103 first = false;
104 out << "(";
105 PrintCoeff(out, coeff);
106 out << ")";
107 if (c < num_vars && c < vars.size()) // a variable column (the last affine column is the constant)
108 out << "*" << *vars[c];
109 }
110 if (first)
111 out << "0";
112}
113
114} // namespace describe_detail
115} // namespace blocks
116} // namespace bertini
Collects the various header files which define the Bertini2 function tree node types.
Definition describe.hpp:38
std::string FmtReal(R const &r, int sig)
Format one multiprecision real part.
Definition describe.hpp:48
void PrintCoeff(std::ostream &out, complex_mp const &c, int sig=0)
Print one (complex_mp) coefficient compactly: a real prints as its real part, a pure imaginary as b*i...
Definition describe.hpp:56
void PrintAugmentedVars(std::ostream &out, VariableGroup const &vars, size_t num_vars, bool homogeneous)
The augmenting variable list [x, y, 1] (affine) or [h, x, y] (homogeneous: no trailing 1).
Definition describe.hpp:79
int CoeffSig(bool verbose)
The significant-digit count for coefficient printing: 4 for terse (short and legible),...
Definition describe.hpp:68
void PrintLinearFormVerbose(std::ostream &out, Mat< complex_mp > const &M, Eigen::Index r, VariableGroup const &vars, size_t num_vars, bool homogeneous)
One affine linear form, row r of an augmented coefficient matrix M (num_vars+1 cols affine,...
Definition describe.hpp:92
constexpr size_t kTerseRowCap
How many function rows a block lists in terse (non-verbose) describe before truncating with a ....
Definition describe.hpp:43
void PrintRowLabel(std::ostream &out, size_t row, size_t n)
f_k for a single row, or f_a..f_b for a contiguous range of n rows starting at row.
Definition describe.hpp:71
Definition blend_block.hpp:75
Definition algorithm_builder.hpp:36
std::vector< std::shared_ptr< node::Variable > > VariableGroup
An ordered group of variables (the unit of homogenization / variable grouping).
Definition node.hpp:69
Eigen::Matrix< NumT, Eigen::Dynamic, Eigen::Dynamic > Mat
A dynamically-sized matrix of NumT.
Definition eigen_extensions.hpp:298
bmp::number< mpc_complex_backend< 0 >, bmp::et_on > complex_mp
The arbitrary-precision complex number type.
Definition mpfr_complex.hpp:58
auto DefaultPrecision()
Get the global default precision (digits) for multiprecision numbers.
Definition mpfr_complex.hpp:135
Provides an Eigen-like NumTraits struct for querying traits of a number type.