Macaulay2 Engine
Loading...
Searching...
No Matches
triple.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright (C) 2006-2011 by Mikhail V. Zinin *
3 * mzinin@gmail.com *
4 * *
5 * You may redistribute this file under the terms of the GNU General *
6 * Public License as published by the Free Software Foundation, either *
7 * version 2 of the License, or any later version. *
8 *****************************************************************************/
9
10#ifndef BIBASIS_TRIPLE_HPP
11#define BIBASIS_TRIPLE_HPP
12
45
46#include <set>
47#include <string>
48#include "allocator.hpp"
49#include "polynom.hpp"
50#include "error.h"
51
52namespace BIBasis
53{
54 template <typename MonomType>
55 class Triple
56 {
57 private:
58 const MonomType* Lm;
62 std::set<typename MonomType::Integer> Nmp;
63 const typename MonomType::Integer Variable;
64
65 public:
66 Triple(Polynom<MonomType>* initialPolynom);
67
68 Triple(Polynom<MonomType>* initialPolynom
69 , const Triple* initialAncestor
70 , const std::set<typename MonomType::Integer>& initialNmp
71 , const Triple* weakAncestor
72 , typename MonomType::Integer nmVar);
73
74 ~Triple();
75
76 const Polynom<MonomType>* GetPolynom() const;
77 const MonomType& GetPolynomLm() const;
78 const Triple* GetAncestor() const;
79 const Triple* GetWeakAncestor() const;
80 typename MonomType::Integer GetVariable() const;
81 const std::set<typename MonomType::Integer>& GetNmp() const;
82
83 void SetNmp(const std::set<typename MonomType::Integer>& newNmp);
84 void SetNmp(typename MonomType::Integer variable);
85 bool TestNmp(typename MonomType::Integer variable) const;
86
87 static bool Compare(const Triple* tripleA, const Triple* tripleB);
88 };
89
90 template <typename MonomType>
92 : Lm(0)
93 , Polynomial(initialPolynom)
94 , Ancestor(0)
95 , WeakAncestor(0)
96 , Nmp()
97 , Variable(-1)
98 {
99 if (Polynomial)
100 {
101 Lm = &Polynomial->Lm();
102 Ancestor = this;
103 Nmp = std::set<typename MonomType::Integer>();
104 }
105 }
106
107 template <typename MonomType>
109 , const Triple<MonomType>* initialAncestor
110 , const std::set<typename MonomType::Integer>& initialNmp
111 , const Triple<MonomType>* weakAncestor
112 , typename MonomType::Integer nmVar)
113 : Lm(0)
114 , Polynomial(0)
115 , Ancestor(0)
116 , WeakAncestor(0)
117 , Nmp()
118 , Variable(nmVar)
119 {
120 if (initialPolynom)
121 {
122 if (Variable == -1)
123 {
124 Polynomial = initialPolynom;
125 if (initialAncestor)
126 {
127 Ancestor = initialAncestor;
128 }
129 else
130 {
131 Ancestor = this;
132 }
133 }
134 else
135 {
137 (*Polynomial) += initialPolynom->Lm();
138
139 Ancestor = initialAncestor;
140 WeakAncestor = weakAncestor;
141 }
142
143 Lm = &Polynomial->Lm();
144 Nmp = initialNmp;
145 }
146 }
147
148 template <typename MonomType>
150 {
151 delete Polynomial;
152 }
153
154 template <typename MonomType>
156 {
157 return Polynomial;
158 }
159
160 template <typename MonomType>
161 const MonomType& Triple<MonomType>::GetPolynomLm() const
162 {
163 return *Lm;
164 }
165
166 template <typename MonomType>
168 {
169 return Ancestor;
170 }
171
172 template <typename MonomType>
177
178 template <typename MonomType>
179 typename MonomType::Integer Triple<MonomType>::GetVariable() const
180 {
181 return Variable;
182 }
183
184 template <typename MonomType>
185 const std::set<typename MonomType::Integer>& Triple<MonomType>::GetNmp() const
186 {
187 return Nmp;
188 }
189
190 template <typename MonomType>
191 void Triple<MonomType>::SetNmp(const std::set<typename MonomType::Integer>& newNmp)
192 {
193 Nmp = newNmp;
194 }
195
196 template <typename MonomType>
197 void Triple<MonomType>::SetNmp(typename MonomType::Integer var)
198 {
199 Nmp.insert(var);
200 }
201
202 template <typename MonomType>
203 bool Triple<MonomType>::TestNmp(typename MonomType::Integer var) const
204 {
205 return Nmp.count(var);
206 }
207
208 template <typename MonomType>
210 {
211 if (!tripleA || !tripleB)
212 {
213 throw std::string("BIBasis::Triple::Compare(): at least one argument is NULL.");
214 }
215 return *tripleA->Lm > *tripleB->Lm;
216 }
217}
218
219#endif // BIBASIS_TRIPLE_HPP
BIBasis::FastAllocator — per-size-class slab allocator for BIBasis's small objects.
const MonomType & Lm() const
Definition polynom.hpp:189
const Triple * GetWeakAncestor() const
Definition triple.hpp:173
const Polynom< MonomType > * GetPolynom() const
Definition triple.hpp:155
bool TestNmp(typename MonomType::Integer variable) const
Definition triple.hpp:203
Triple(Polynom< MonomType > *initialPolynom)
Definition triple.hpp:91
const Triple * Ancestor
Definition triple.hpp:60
std::set< typename MonomType::Integer > Nmp
Definition triple.hpp:62
void SetNmp(const std::set< typename MonomType::Integer > &newNmp)
Definition triple.hpp:191
const MonomType::Integer Variable
Definition triple.hpp:63
const Triple * WeakAncestor
Definition triple.hpp:61
const std::set< typename MonomType::Integer > & GetNmp() const
Definition triple.hpp:185
MonomType::Integer GetVariable() const
Definition triple.hpp:179
const Triple * GetAncestor() const
Definition triple.hpp:167
const MonomType * Lm
Definition triple.hpp:58
Polynom< MonomType > * Polynomial
Definition triple.hpp:59
static bool Compare(const Triple *tripleA, const Triple *tripleB)
Definition triple.hpp:209
const MonomType & GetPolynomLm() const
Definition triple.hpp:161
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
BIBasis::Polynom<MonomType> — linked-list F_2[x] polynomial with symmetric-difference arithmetic.