-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrder.h
90 lines (77 loc) · 2.51 KB
/
Order.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <algorithm>
#include <iostream>
#include "Monomial.h"
namespace Groebner {
class Lex {
public:
static bool cmp(const Monomial& first, const Monomial& second) {
const auto& [position1, position2] = std::mismatch(first.get_degrees().begin(), first.get_degrees().end(), second.get_degrees().begin(), second.get_degrees().end());
if (position2 == second.get_degrees().end()) {
return false;
}
if (position1 == first.get_degrees().end()) {
return true;
}
return position1->first > position2->first || (position1->first == position2->first && position1->second < position2->second);
}
bool operator()(const Monomial& first, const Monomial& second) const {
return cmp(first, second);
}
};
class Deg {
public:
static bool cmp(const Monomial& first, const Monomial& second) {
auto deg1 = total_degree(first.get_degrees().begin(), first.get_degrees().end());
auto deg2 = total_degree(second.get_degrees().begin(), second.get_degrees().end());
return deg1 < deg2;
}
bool operator()(const Monomial& first, const Monomial& second) const {
return cmp(first, second);
}
private:
using Iter = std::map<Monomial::IndexType, Monomial::DegreeType>::const_iterator;
static Monomial::DegreeType total_degree(Iter it1, Iter it2) {
Monomial::DegreeType res = 0;
while (it1 != it2) {
res += it1->second;
++it1;
}
return res;
}
};
template <class... Ts>
class Sum;
template <class T>
class Sum<T> {
public:
static bool cmp(const Monomial& first, const Monomial& second) {
return T::cmp(first, second);
}
bool operator()(const Monomial& first, const Monomial& second) const {
return cmp(first, second);
}
};
template <class T1, class... Tk>
class Sum<T1, Tk...> {
public:
static bool cmp(const Monomial& first, const Monomial& second) {
if (T1::cmp(first, second)) return true;
if (T1::cmp(second, first)) return false;
return Sum<Tk...>::cmp(first, second);
}
bool operator()(const Monomial& first, const Monomial& second) const {
return cmp(first, second);
}
};
template <class T>
class Reverse {
public:
static bool cmp(const Monomial& first, const Monomial& second) {
return T::cmp(second, first);
}
bool operator()(const Monomial& first, const Monomial& second) const {
return cmp(first, second);
}
};
} // namespace Groebner