carl  24.04
Computer ARithmetic Library
GBUpdateProcedures.h
Go to the documentation of this file.
1 /**
2  * @file GBUpdateProcedures.h
3  * @ingroup gb
4  * @author Sebastian Junges
5  */
6 
7 #pragma once
8 
9 #include "../poly/umvpoly/functions/SeparablePart.h"
10 
11 namespace carl
12 {
13 
14 struct UpdateFnc {
15  virtual void operator()(std::size_t index) = 0;
16  virtual ~UpdateFnc() = default;
17 };
18 
19 
20 template<typename Polynomial>
21 struct StdAdding
22 {
23 public:
24  virtual ~StdAdding() = default;
25 
26  bool addToGb(const Polynomial& p, std::shared_ptr<Ideal<Polynomial>> gb, UpdateFnc* update)
27  {
28  if(p.is_constant())
29  {
30  gb->clear();
31  Polynomial q(1);
32  q.setReasons(p.getReasons());
33  gb->addGenerator(q);
34  return true;
35  }
36  else
37  {
38  size_t index = gb->addGenerator(p);
39  (*update)(index);
40  }
41  return false;
42  }
43 };
44 
45 template<typename Polynomial>
47 {
48 
49 };
50 
51 template<typename Polynomial>
53 {
54 private:
55 
56 public:
58  {
59 
60  }
61 
62  bool addToGb(const Polynomial& p, std::shared_ptr<Ideal<Polynomial>> gb, UpdateFnc* update)
63  {
64  if(p.is_constant())
65  {
66  gb->clear();
67  Polynomial q(1);
68  q.setReasons(p.getReasons());
69  gb->addGenerator(q);
70  return true;
71  }
72  else if(p.nr_terms() == 1)
73  {
74  assert(!p.is_constant());
75  Polynomial q(carl::separable_part(*p.lmon()));
76 #ifdef BUCHBERGER_STATISTICS
77  if(q.lterm().tdeg() != p.lterm().tdeg()) mStats->SingleTermSFP();
78 #endif
79  q.setReasons(p.getReasons());
80  size_t index = gb->addGenerator(q);
81  (*update)(index);
82  }
83  else if(p.is_tsos())
84  {
85  if(p.has_constant_term())
86  {
87 #ifdef BUCHBERGER_STATISTICS
88  if(p.nrOfTerms() > 1) mStats->TSQWithConstant();
89 #endif
90  gb->clear();
91  Polynomial q(1);
92  q.setReasons(p.getReasons());
93  gb->addGenerator(q);
94  return true;
95  }
96  else
97  {
98 #ifdef BUCHBERGER_STATISTICS
99  mStats->TSQWithoutConstant();
100 #endif
101  Polynomial remainder(p);
102  while(!carl::is_zero(remainder))
103  {
104  Polynomial r1(carl::separable_part(*remainder.lmon()));
105 #ifdef BUCHBERGER_STATISTICS
106  if(remainder.lterm().tdeg() != r1.lterm().tdeg()) mStats->SingleTermSFP();
107 #endif
108  r1.setReasons(p.getReasons());
109  remainder.strip_lterm();
110  size_t index = gb->addGenerator(r1);
111  (*update)(index);
112  }
113  }
114  }
115  else if(p.is_reducible_identity())
116  {
117 #ifdef BUCHBERGER_STATISTICS
118  mStats->ReducibleIdentity();
119 #endif
120  Polynomial r;
122  //Polynomial r(p.getReducibleIdentity());
123  //r.setOrigins(p.getOrigins());
124  size_t index = gb->addGenerator(p);
125  (*update)(index);
126  }
127  else
128  {
129  size_t index = gb->addGenerator(p);
130  (*update)(index);
131  }
132  return false;
133  }
134 };
135 }
#define CARL_LOG_NOTIMPLEMENTED()
Definition: carl-logging.h:48
carl is the main namespace for the library.
Monomial::Arg separable_part(const Monomial &m)
Calculates the separable part of this monomial.
Definition: SeparablePart.h:12
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
cln::cl_I remainder(const cln::cl_I &a, const cln::cl_I &b)
Calculate the remainder of the integer division.
Definition: operations.h:526
virtual void operator()(std::size_t index)=0
virtual ~UpdateFnc()=default
bool addToGb(const Polynomial &p, std::shared_ptr< Ideal< Polynomial >> gb, UpdateFnc *update)
virtual ~StdAdding()=default
bool addToGb(const Polynomial &p, std::shared_ptr< Ideal< Polynomial >> gb, UpdateFnc *update)