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