Gröbner basis project
Codebase for research into Gröbner basis computation
betti.cpp
1 #ifndef __BETTI_CPP_
2 #define __BETTI_CPP_
3 
4 /*****************************************************************************\
5 * This file is part of DynGB. *
6 * *
7 * DynGB is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Foobar is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
19 \*****************************************************************************/
20 
21 #include <set>
22 using std::set;
23 #include <utility>
24 using std::pair;
25 #include <algorithm>
26 using std::any_of;
27 
28 #include "betti.hpp"
29 
30 map<DEG_TYPE, unsigned long> incremental_betti(
31  const list<Monomial> & T, const WT_TYPE * grading
32 ) {
33  map<DEG_TYPE, unsigned long> result;
34  const Monomial & u = T.back();
35  auto Tstop = T.end();
36  --Tstop;
37  list<pair<Monomial, Monomial>> S;
38  for (auto ti = T.begin(); ti != Tstop; ++ti) {
39  S.emplace_back(*ti, u);
40  S.back().first.set_monomial_ordering(u.monomial_ordering());
41  for (auto ui = T.begin(); ui != ti; ++ui) {
42  S.emplace_back(*ti, *ui);
43  S.back().first.set_monomial_ordering(u.monomial_ordering());
44  }
45  }
46  list<pair<Monomial, Monomial>> S2;
47  for (auto p : S) {
48  bool found = false;
49  if (
50  not found and u | p.first.lcm(p.second) and
51  any_of(S2.begin(), S2.end(), [p,u](pair<Monomial, Monomial> q){return (q.first == u or q.second == u) and (q.first == p.first or q.second==p.first);}) and
52  any_of(S2.begin(), S2.end(), [p,u](pair<Monomial, Monomial> q){return (q.first == u or q.second == u) and (q.first == p.second or q.second==p.second);})
53  ) {
54  found = true;
55  }
56  for (auto t : T) {
57  if (found) break;
58  if (
59  t | p.first.lcm(p.second) and
60  any_of(S2.begin(), S2.end(), [p,t](pair<Monomial, Monomial> q){return (q.first == t or q.second == t) and (q.first == p.second or q.second==p.second);}) and
61  any_of(S2.begin(), S2.end(), [p,t](pair<Monomial, Monomial> q){return (q.first == t or q.second == t) and (q.first == p.second or q.second==p.second);})
62  ) {
63  found = true;
64  }
65  }
66  if (not found) S2.emplace_back(p);
67  }
68  for (auto p : S2) {
69  DEG_TYPE d = (grading == nullptr)
70  ? p.first.lcm(p.second).total_degree()
71  : p.first.lcm(p.second).weighted_degree(grading);
72  if (result.find(d) != result.end())
73  ++result[d];
74  else
75  result[d] = 1;
76  }
77  return result;
78 }
79 
80 #endif
void set_monomial_ordering(const Monomial_Ordering *mord)
sets the Monomial_Ordering associated with this Monomial
Definition: monomial.cpp:211
map< DEG_TYPE, unsigned long > incremental_betti(const list< Monomial > &T, const WT_TYPE *grading)
Incremental Betti numbers for monomial ideals.
Definition: betti.cpp:30
Implementation of monomials.
Definition: monomial.hpp:69
Monomial lcm(const Monomial &u) const
Least common multiple: largest exponents.
Definition: monomial.cpp:365
const Monomial_Ordering * monomial_ordering() const
the Monomial_Ordering associated with this Monomial
Definition: monomial.hpp:165