Macaulay2 Engine
Loading...
Searching...
No Matches

◆ simplify()

void LocalRing::simplify ( local_elem * f) const
private

Definition at line 73 of file localring.cpp.

74{
75 ring_elem x, y;
77 {
78 y = f->denom;
79 if (mRing->is_equal(y, mRing->one())) return;
80 x = f->numer;
81 const RingElement *a = RingElement::make_raw(mRing, x);
82 const RingElement *b = RingElement::make_raw(mRing, y);
83 const RingElement *c = rawGCDRingElement(a, b, nullptr, false);
84
85#if 0
86 // Debugging code
87 buffer o;
88 o << newline;
89 o << "a = ";
90 a->text_out(o);
91 o << " b = ";
92 b->text_out(o);
93 o << " gcd = ";
94 c->text_out(o);
95 o << newline;
96 emit(o.str());
97#endif
98 if (!mRing->is_equal(c->get_value(), mRing->one()))
99 {
100 f->numer = mRing->divide(f->numer, c->get_value());
101 f->denom = mRing->divide(f->denom, c->get_value());
102 }
103 // Now, let's take the content of the denominator, and divide the
104 // numerator
105 // and denominator by this value.
106 ring_elem ct = mRing->content(
107 f->denom, f->numer); // result is in mRing->getCoefficients()
108
109#if 0
110 o.reset();
111 o << "f->numer = ";
112 mRing->elem_text_out(o,f->numer);
113 o << " f->denom = ";
114 mRing->elem_text_out(o,f->denom);
115 o << " ass= ";
116 mRing->getCoefficients()->elem_text_out(o,ct);
117 o << newline;
118 emit(o.str());
119#endif
120
121 if (!mRing->getCoefficients()->is_equal(ct,
122 mRing->getCoefficients()->one()))
123 {
124 f->numer = mRing->divide_by_given_content(f->numer, ct);
125 f->denom = mRing->divide_by_given_content(f->denom, ct);
126 }
127 }
128 else
129 {
130 mRing->syzygy(f->numer, f->denom, x, y);
131 if (mRing->is_zero(x))
132 {
133 mRing->remove(x);
135 f->numer = mRing->zero();
136 f->denom = mRing->one();
137 return;
138 }
139 mRing->negate_to(y);
140 mRing->remove(f->numer);
141 mRing->remove(f->denom);
142 f->numer = y;
143 f->denom = x;
144 }
145}
ring_elem set_non_unit_frac(ring_elem top) const
const PolyRing * mRing
Definition localring.hpp:69
bool use_gcd_simplify
Definition localring.hpp:83
void text_out(buffer &o) const
Definition relem.cpp:142
ring_elem get_value() const
Definition relem.hpp:79
static RingElement * make_raw(const Ring *R, ring_elem f)
Definition relem.cpp:20
char * str()
Definition buffer.hpp:72
void reset()
Definition buffer.hpp:69
const RingElement * rawGCDRingElement(const RingElement *f, const RingElement *g, const RingElement *mipo, const M2_bool inExtension)
Definition factory.cpp:488
char newline[]
Definition m2-types.cpp:49
volatile int x
ring_elem numer
Definition localring.hpp:48
ring_elem denom
Definition localring.hpp:49
void emit(const char *s)
Definition text-io.cpp:41

References local_elem::denom, emit(), RingElement::get_value(), RingElement::make_raw(), mRing, newline, local_elem::numer, rawGCDRingElement(), buffer::reset(), set_non_unit_frac(), buffer::str(), RingElement::text_out(), use_gcd_simplify, and x.

Referenced by make_elem().