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

◆ simplify()

void FractionField::simplify ( frac_elem * f) const
private

Definition at line 108 of file frac.cpp.

109{
110 ring_elem x, y;
112 {
113 y = f->denom;
114 if (R_->is_equal(y, R_->one())) return;
115 x = f->numer;
116 const RingElement *a = RingElement::make_raw(R_, x);
117 const RingElement *b = RingElement::make_raw(R_, y);
118 const RingElement *c = rawGCDRingElement(a, b, nullptr, false);
119 if (!c) return;
120
121#if 0
122 // Debugging code
123 buffer o;
124 o << newline;
125 o << "a = ";
126 a->text_out(o);
127 o << " b = ";
128 b->text_out(o);
129 o << " gcd = ";
130 c->text_out(o);
131 o << newline;
132 emit(o.str());
133#endif
134 if (!R_->is_equal(c->get_value(), R_->one()))
135 {
136 f->numer = R_->divide(f->numer, c->get_value());
137 f->denom = R_->divide(f->denom, c->get_value());
138 }
139 // Now, let's take the content of the denominator, and divide the
140 // numerator
141 // and denominator by this value.
142 ring_elem ct = R_->content(
143 f->denom, f->numer); // result is in R_->getCoefficients()
144
145#if 0
146 o.reset();
147 o << "f->numer = ";
148 R_->elem_text_out(o,f->numer);
149 o << " f->denom = ";
150 R_->elem_text_out(o,f->denom);
151 o << " ass= ";
152 R_->getCoefficients()->elem_text_out(o,ct);
153 o << newline;
154 emit(o.str());
155#endif
156
157 if (!R_->getCoefficients()->is_equal(ct, R_->getCoefficients()->one()))
158 {
159 f->numer = R_->divide_by_given_content(f->numer, ct);
160 f->denom = R_->divide_by_given_content(f->denom, ct);
161 }
162 }
163 else
164 {
165 R_->syzygy(f->numer, f->denom, x, y);
166 if (R_->is_zero(x))
167 {
168 R_->remove(x);
170 f->numer = R_->zero();
171 f->denom = R_->one();
172 return;
173 }
174 R_->negate_to(y);
175 R_->remove(f->numer);
176 R_->remove(f->denom);
177 f->numer = y;
178 f->denom = x;
179 }
180}
ring_elem set_non_unit_frac(ring_elem top) const
Definition frac.cpp:89
bool use_gcd_simplify
Definition frac.hpp:64
const PolyRingFlat * R_
Definition frac.hpp:63
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 frac.hpp:43
ring_elem denom
Definition frac.hpp:44
void emit(const char *s)
Definition text-io.cpp:41

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

Referenced by internal_add_to(), internal_subtract_to(), and make_elem().