1 // -*- c++ -*-
2 //*****************************************************************************
3 /** @file DegLexOrder.cc
4 *
5 * @author Alexander Dreyer
6 * @date 2006-05-18
7 *
8 * Defining Degree-lexicographical ordering.
9 *
10 * @par Copyright:
11 * (c) 2006 by The PolyBoRi Team
12 **/
13 //*****************************************************************************
14
15 // include definitions
16
17
18 #include <polybori/DegLexOrder.h>
19
20 #include <polybori/routines/pbori_algo.h>
21 #include <polybori/iterators/PBoRiOutIter.h>
22
23
24 // get internal routines
25 #include <polybori/routines/pbori_routines.h>
26
27
28 #include <polybori/cache/CDegreeCache.h>
29
30 #include <polybori/BooleSet.h>
31
32 BEGIN_NAMESPACE_PBORI
33
34 // Comparison of monomials
35 DegLexOrder::comp_type
compare(const monom_type & lhs,const monom_type & rhs) const36 DegLexOrder::compare(const monom_type& lhs, const monom_type& rhs) const {
37
38 PBORI_TRACE_FUNC(
39 "DegLexOrder::compare(const monom_type&, const monom_type&) const)" );
40
41 return deg_lex_compare(lhs, rhs, idx_comparer_type());
42 }
43
44 // Comparison of monomials
45 DegLexOrder::comp_type
compare(const exp_type & lhs,const exp_type & rhs) const46 DegLexOrder::compare(const exp_type& lhs, const exp_type& rhs) const {
47
48 PBORI_TRACE_FUNC(
49 "DegLexOrder::compare(const exp_type&, const exp_type&) const)" );
50
51 return deg_lex_compare(lhs, rhs, idx_comparer_type());
52
53 }
54
55 // Comparison of monomials
56 DegLexOrder::comp_type
compare(idx_type lhs,idx_type rhs) const57 DegLexOrder::compare(idx_type lhs, idx_type rhs) const {
58
59 PBORI_TRACE_FUNC(
60 "DegLexOrder::compare(monom_type, monom_type) const)" );
61
62 return generic_compare_3way(lhs, rhs, idx_comparer_type());
63 }
64
65 // Extraction of leading term
66 DegLexOrder::monom_type
lead(const poly_type & poly) const67 DegLexOrder::lead(const poly_type& poly) const {
68
69 PBORI_TRACE_FUNC( "DegLexOrder::lead(const poly_type&) const)" );
70 return self::lead(poly, poly.deg());
71 }
72
73 // Extraction of leading term
74 ///@todo: more accurate explanation (comments)
75 DegLexOrder::monom_type
lead(const poly_type & poly,deg_type bound) const76 DegLexOrder::lead(const poly_type& poly, deg_type bound) const {
77
78 PBORI_TRACE_FUNC( "DegLexOrder::lead(const poly_type&, deg_type) const)" );
79
80 CacheManager<CCacheTypes::dlex_lead> cache_mgr(poly.ring());
81 CBoundedDegreeCache<set_type> deg_mgr(poly.ring());
82
83 poly_type::navigator navi(poly.navigation());
84 deg_type deg(dd_cached_degree(deg_mgr, navi, bound));
85
86 return monom( dd_recursive_degree_lead(cache_mgr, deg_mgr, navi, set_type(poly.ring()), deg,
87 descending_property()) );
88 }
89
90
91 // maybe common template here
92 // Extraction of leading exponent
93 DegLexOrder::exp_type
leadExp(const poly_type & poly) const94 DegLexOrder::leadExp(const poly_type& poly) const {
95
96 PBORI_TRACE_FUNC( "DegLexOrder::leadexp(const poly_type&) const)" );
97 return self::leadExp(poly, poly.deg());
98 }
99
100 // maybe common template here
101 // Extraction of leading exponent
102 DegLexOrder::exp_type
leadExp(const poly_type & poly,deg_type bound) const103 DegLexOrder::leadExp(const poly_type& poly, deg_type bound) const {
104
105 PBORI_TRACE_FUNC( "DegLexOrder::leadexp(const poly_type&, deg_type) const)");
106
107 CacheManager<CCacheTypes::dlex_lead> cache_mgr(poly.ring());
108 CBoundedDegreeCache<set_type> deg_mgr(poly.ring());
109
110 poly_type::navigator navi(poly.navigation());
111 deg_type deg(dd_cached_degree(deg_mgr, navi, bound));
112
113 exp_type result;
114 result.reserve(std::max(deg, 0));
115
116 return dd_recursive_degree_leadexp(cache_mgr, deg_mgr, navi, result, deg,
117 descending_property());
118 }
119
120 END_NAMESPACE_PBORI
121