Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
special_number.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//special_number.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//special_number.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 special_number.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// special_number.hpp: Declares the class SpecialNumber.
23
30
31#ifndef BERTINI_FUNCTION_TREE_SPECIAL_NUMBER_HPP
32#define BERTINI_FUNCTION_TREE_SPECIAL_NUMBER_HPP
33
34
36
37#include <cmath>
38
39
40
41namespace bertini {
42namespace node{
43 using ::acos;
44 using ::exp;
45
46
47 namespace special_number{
48
54 class Pi : public Number, public NameHolder
55 {
56 public:
58
59 virtual ~Pi() = default;
60
62 template<typename... Ts>
63 static
64 std::shared_ptr<Pi> Make(Ts&& ...ts){
65 return std::static_pointer_cast<Pi>(Intern(std::shared_ptr<Node>( new Pi(ts...) )));
66 }
67
68 void print(std::ostream & target) const override
69 {
70 target << name();
71 }
72
73 // All Pi nodes are the same number: type-based structural identity, so the
74 // intern table collapses every Pi() onto one shared node (and deserialized
75 // Pi's re-intern onto it, ADR-0042).
76 std::size_t HashImpl() const override
77 {
78 return typeid(Pi).hash_code();
79 }
80 bool IsSame(Node const& other) const override
81 {
82 return dynamic_cast<Pi const*>(&other) != nullptr;
83 }
84
85
86 private:
87
88 Pi() : NameHolder("pi")
89 {}
90
91 // Return value of constant
92
93
94
95
96
97
99
100 template <typename Archive>
101 void serialize(Archive& ar, const unsigned /*version*/) {
102 ar & boost::serialization::base_object<Number>(*this);
103 ar & boost::serialization::base_object<NameHolder>(*this);
104 }
105 };
106
107
108
114 class E : public Number, public NameHolder
115 {
116 public:
118
119
120
121 virtual ~E() = default;
122
123
125 template<typename... Ts>
126 static
127 std::shared_ptr<E> Make(Ts&& ...ts){
128 return std::static_pointer_cast<E>(Intern(std::shared_ptr<Node>( new E(ts...) )));
129 }
130
131 void print(std::ostream & target) const override
132 {
133 target << name();
134 }
135
136 // All E nodes are the same number: type-based structural identity (see Pi).
137 std::size_t HashImpl() const override
138 {
139 return typeid(E).hash_code();
140 }
141 bool IsSame(Node const& other) const override
142 {
143 return dynamic_cast<E const*>(&other) != nullptr;
144 }
145
146
147 private:
148
149 E() : NameHolder("e")
150 {}
151
152
153 // Return value of constant
154
155
156
157
158
159
161
162 template <typename Archive>
163 void serialize(Archive& ar, const unsigned /*version*/) {
164 ar & boost::serialization::base_object<Number>(*this);
165 ar & boost::serialization::base_object<NameHolder>(*this);
166 }
167
168 };
169
170 } // re: special_number namespace
171
172
176 std::shared_ptr<Node> Pi();
177
181 std::shared_ptr<Node> E();
182
186 std::shared_ptr<Node> I();
187
191 std::shared_ptr<Node> Two();
192
196 std::shared_ptr<Node> One();
197
201 std::shared_ptr<Node> Zero();
202
203
204} // re: namespace node
205} // re: namespace bertini
206
207#endif
Capability class for things which have a name.
Definition symbol.hpp:78
const std::string & name() const
Definition symbol.hpp:81
Abstract Number type from which other Numbers derive.
Definition number.hpp:50
std::size_t HashImpl() const override
Compute this node's structural hash.
Definition special_number.hpp:137
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
Definition special_number.hpp:141
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
Definition special_number.hpp:131
friend class boost::serialization::access
Definition special_number.hpp:160
static std::shared_ptr< E > Make(Ts &&...ts)
Construct (and intern) a E node.
Definition special_number.hpp:127
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
Definition special_number.hpp:68
static std::shared_ptr< Pi > Make(Ts &&...ts)
Construct (and intern) a Pi node.
Definition special_number.hpp:64
std::size_t HashImpl() const override
Compute this node's structural hash.
Definition special_number.hpp:76
friend class boost::serialization::access
Definition special_number.hpp:98
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
Definition special_number.hpp:80
Definition forward_declares.hpp:74
Definition canonical.hpp:56
std::shared_ptr< Node > E()
Construct a shared pointer to .
std::shared_ptr< Node > Intern(std::shared_ptr< Node > const &candidate)
Hash-cons a freshly-built node: return an existing structurally-equal node if one is live,...
std::shared_ptr< Node > Two()
Construct a shared pointer to .
std::shared_ptr< Node > Pi()
Construct a shared pointer to .
std::shared_ptr< Node > One()
Construct a shared pointer to .
std::shared_ptr< Node > exp(const std::shared_ptr< Node > &N)
Build an exponential (e raised to the node) expression-tree node.
Definition arithmetic.hpp:1027
std::shared_ptr< Node > I()
Construct a shared pointer to .
std::shared_ptr< Node > acos(const std::shared_ptr< Node > &N)
Build a arccosine expression-tree node.
Definition trig.hpp:467
std::shared_ptr< Node > Zero()
Construct a shared pointer to .
Definition algorithm_builder.hpp:36
Provides the Number Node types, including Rational, Complex, and Integer.
#define BERTINI_DEFAULT_VISITABLE()
macro for classes which want default Accept implementation, having nothing fancy to do when accepting...
Definition visitable.hpp:121