Macaulay2 Engine
Loading...
Searching...
No Matches
frac.cpp
Go to the documentation of this file.
1// Copyright 1995 Michael E. Stillman
2
3#include "frac.hpp"
4
5#include "interface/factory.h"
6#include "text-io.hpp"
7#include "monoid.hpp"
8#include "ringmap.hpp"
9#include "gbring.hpp"
10#include "relem.hpp"
11#include "polyring.hpp"
12#include "exceptions.hpp"
13
14#define FRAC_VAL(f) (reinterpret_cast<frac_elem *>((f).poly_val))
15#define FRAC_RINGELEM(a) (ring_elem(reinterpret_cast<Nterm *>(a)))
16
18{
19 const PolynomialRing *A = R_->cast_to_PolynomialRing();
20 assert(A != 0);
21 const Ring *K = A->getCoefficientRing();
22 if (K->coefficient_type() == COEFF_ZZ) return COEFF_QQ;
23 return K->coefficient_type();
24}
25
26int FractionField::n_fraction_vars() const { return R_->n_vars(); }
28{
31
32 R_ = R;
33
34 zeroV = from_long(0);
35 oneV = from_long(1);
37
38 if (R->n_quotients() > 0 ||
40 ->cast_to_FractionField() // disallowed in x-relem.cpp
41 ||
43 0) // disallowed in x-relem.cpp
44 use_gcd_simplify = false;
45 else
46 use_gcd_simplify = true;
47#ifdef DEVELOPMENT
48#warning "frac simplify: doesn't handle towers of fracs"
49#endif
50
52 return true;
53}
54
56{
58 result->initialize_frac(R);
59 return result;
60}
61
63{
64 o << "Frac(";
65 R_->text_out(o);
66 o << ")";
67}
68
70{
71 frac_elem *g = FRAC_VAL(f);
72 return R_->copy(g->numer);
73}
74
76{
77 frac_elem *g = FRAC_VAL(f);
78 return R_->copy(g->denom);
79}
80
81unsigned int FractionField::computeHashValue(const ring_elem f) const
82{
83 frac_elem *g = FRAC_VAL(f);
84 return (16473 * R_->computeHashValue(g->numer) +
85 7698908 * R_->computeHashValue(g->denom));
86}
87
90{
91 // Sets the non unit to be top/1 (which flags an error)
92 // flags an error
93 // returns 0/1
94
96 f->numer = top;
97 f->denom = R_->one();
99 return zero();
100}
101
103 const ring_elem bottom) const
104{
105 return FRAC_RINGELEM(make_elem(R_->copy(top), R_->copy(bottom)));
106}
107
109{
110 ring_elem x, y;
112 {
113 y = f->denom;
114 if (R_->is_equal(y, R_->one())) return;
115 x = f->numer;
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}
181
183{
185 result->numer = a;
186 result->denom = b;
188 return result;
189}
190
192{
193 if (!use_gcd_simplify) return;
194 if (is_zero(c))
195 {
196 c = g;
197 return;
198 }
199
200 frac_elem *cf = FRAC_VAL(c);
201 frac_elem *gf = FRAC_VAL(g);
202 const RingElement *c1 = RingElement::make_raw(R_, cf->numer);
203 const RingElement *c2 = RingElement::make_raw(R_, cf->denom);
204 const RingElement *g1 = RingElement::make_raw(R_, gf->numer);
205 const RingElement *g2 = RingElement::make_raw(R_, gf->denom);
206
207 c1 = rawGCDRingElement(c1, g1, nullptr, false);
208
209 const RingElement *cc2 = rawGCDRingElement(c2, g2, nullptr, false);
210 const RingElement *cc3 = (*c2) * (*g2);
211 const RingElement *cc4 = (*cc3) / (*cc2);
212
214 result->numer = c1->get_value();
215 result->denom = cc4->get_value();
216
218}
219
221{
222 ring_elem a = R_->random();
223 ring_elem b = R_->random();
224 if (R_->is_zero(b))
225 {
226 R_->remove(b);
227 b = R_->from_long(1);
228 }
229 return FRAC_RINGELEM(make_elem(a, b));
230}
231
233 const ring_elem a,
234 bool p_one,
235 bool p_plus,
236 bool p_parens) const
237{
238 frac_elem *f = FRAC_VAL(a);
239 int denom_one = R_->is_equal(f->denom, R_->one());
240
241 p_one = p_one || !denom_one;
242 p_parens = p_parens || !denom_one;
243 R_->elem_text_out(o, f->numer, p_one, p_plus, p_parens);
244 if (!denom_one)
245 {
246 o << "/";
247 p_plus = false;
248 R_->elem_text_out(o, f->denom, p_one, p_plus, p_parens);
249 }
250}
251
253{
255 f->numer = R_->from_long(n);
256 f->denom = R_->from_long(1);
257 return FRAC_RINGELEM(f);
258}
259
261{
263 f->numer = R_->from_int(n);
264 f->denom = R_->from_long(1);
265 return FRAC_RINGELEM(f);
266}
267
269{
271 f->numer = R_->from_int(mpq_numref(n));
272 f->denom = R_->from_int(mpq_denref(n));
273 bool ok = not R_->is_zero(f->denom);
274 if (ok) result = FRAC_RINGELEM(f);
275 return ok;
276}
277
279{
281 f->numer = R_->var(v);
282 f->denom = R_->from_long(1);
283 return FRAC_RINGELEM(f);
284}
285
287{
288 const frac_elem *f = FRAC_VAL(a);
289 if (!R_->is_unit(f->denom))
290 // If so, a cannot be a variable, otherwise, by 'simplify', f->denom == 1.
291 return -1;
292 return R_->index_of_var(f->numer);
293}
294
296{
297 const frac_elem *f = FRAC_VAL(a);
298 M2_arrayint result1 = R_->support(f->numer);
299 M2_arrayint result2 = R_->support(f->denom);
300 M2_arrayint result = M2_makearrayint(result1->len + result2->len);
301 for (int i = 0; i < result1->len; i++) result->array[i] = result1->array[i];
302 for (int i = 0; i < result2->len; i++)
303 result->array[result1->len + i] = result2->array[i];
304
305 return result;
306}
307
309 const ring_elem f,
310 ring_elem &result) const
311{
312 // Rf = R ---> frac R
313 if (Rf == R_)
314 {
316 g->numer = R_->copy(f);
317 g->denom = R_->from_long(1);
319 return true;
320 }
321
322 return false;
323}
324
326 const ring_elem f,
327 ring_elem &result) const
328{
329 // Rg = R ---> frac R
330 // f is an element of frac R.
331
333 hdenom; // used in the case when the denominator can be a unit, but not 1
334 // e.g. when this = frac (QQ[x,y,z]). Is an element of
335 if (Rg == R_)
336 {
337 frac_elem *h = FRAC_VAL(f);
338 if (R_->is_equal(h->denom, R_->one()))
339 {
340 result = R_->copy(h->numer);
341 return true;
342 }
343 else
344 {
345 if (R_->is_field())
346 {
347 // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
348 // try to lift denominator. If can, can lift, otherwise not.
349 if (R_->lift(R_, h->denom, hdenom))
350 {
351 ring_elem hinv = R_->invert(hdenom);
352 result = R_->mult(hinv, h->numer);
353 return true;
354 }
355 }
356 }
357 }
358 return false;
359}
360
362{
363 return (!R_->is_zero(FRAC_VAL(f)->numer));
364}
365
367{
368 return (R_->is_zero(FRAC_VAL(f)->numer));
369}
370
371bool FractionField::is_equal(const ring_elem a, const ring_elem b) const
372{
373 frac_elem *f = FRAC_VAL(a);
374 frac_elem *g = FRAC_VAL(b);
375 if (R_->is_equal(f->denom, g->denom))
376 {
377 return R_->is_equal(f->numer, g->numer);
378 }
379 else
380 {
381 ring_elem h = subtract(a, b);
382 bool result = is_zero(h);
383 remove(h);
384 return result;
385 }
386}
387
389{
390 frac_elem *f = FRAC_VAL(a);
391 frac_elem *g = FRAC_VAL(b);
392 int cmp = R_->compare_elems(f->numer, g->numer);
393 if (cmp != 0) return cmp;
394 return R_->compare_elems(f->denom, g->denom);
395}
396
398{
399 frac_elem *f = FRAC_VAL(a);
401 g->numer = R_->copy(f->numer);
402 g->denom = R_->copy(f->denom);
403 return FRAC_RINGELEM(g);
404}
405
406void FractionField::remove(ring_elem &a) const { (void) a; }
408{
409 frac_elem *f = FRAC_VAL(a);
410 R_->negate_to(f->numer);
411}
412
414{
415 frac_elem *f = FRAC_VAL(a);
416 frac_elem *g = FRAC_VAL(b);
417 if (R_->is_equal(f->denom, g->denom))
418 R_->add_to(f->numer, g->numer);
419 else
420 {
421 R_->mult_to(f->numer, g->denom);
422 ring_elem tmp = R_->mult(f->denom, g->numer);
423 R_->add_to(f->numer, tmp);
424 R_->mult_to(f->denom, g->denom);
425 if (R_->is_zero(f->denom))
426 {
428 return;
429 }
430 }
431 simplify(f);
432 remove(b);
433 a = FRAC_RINGELEM(f);
434}
435
437{
438 frac_elem *f = FRAC_VAL(a);
439 frac_elem *g = FRAC_VAL(b);
440 if (R_->is_equal(f->denom, g->denom))
441 R_->subtract_to(f->numer, g->numer);
442 else
443 {
444 R_->mult_to(f->numer, g->denom);
445 ring_elem tmp = R_->mult(f->denom, g->numer);
446 R_->subtract_to(f->numer, tmp);
447 R_->mult_to(f->denom, g->denom);
448 if (R_->is_zero(f->denom))
449 {
451 return;
452 }
453 }
454 simplify(f);
455 remove(b);
456 a = FRAC_RINGELEM(f);
457}
458
460{
461 const frac_elem *f = FRAC_VAL(a);
463 result->numer = R_->negate(f->numer);
464 result->denom = R_->copy(f->denom);
465 return FRAC_RINGELEM(result);
466}
467
469{
470 const frac_elem *f = FRAC_VAL(a);
471 const frac_elem *g = FRAC_VAL(b);
472 ring_elem top, bottom;
473
474 if (R_->is_equal(f->denom, g->denom))
475 {
476 top = R_->add(f->numer, g->numer);
477 bottom = R_->copy(f->denom);
478 }
479 else
480 {
481 top = R_->mult(f->numer, g->denom);
482 ring_elem tmp = R_->mult(f->denom, g->numer);
483 R_->add_to(top, tmp);
484 bottom = R_->mult(f->denom, g->denom);
485 if (R_->is_zero(bottom)) return set_non_unit_frac(f->denom);
486 }
487 frac_elem *result = make_elem(top, bottom);
488 return FRAC_RINGELEM(result);
489}
490
492{
493 const frac_elem *f = FRAC_VAL(a);
494 const frac_elem *g = FRAC_VAL(b);
495 ring_elem top, bottom;
496
497 if (R_->is_equal(f->denom, g->denom))
498 {
499 top = R_->subtract(f->numer, g->numer);
500 bottom = R_->copy(f->denom);
501 }
502 else
503 {
504 top = R_->mult(f->numer, g->denom);
505 ring_elem tmp = R_->mult(f->denom, g->numer);
506 R_->subtract_to(top, tmp);
507 bottom = R_->mult(f->denom, g->denom);
508 if (R_->is_zero(bottom)) return set_non_unit_frac(f->denom);
509 }
510 frac_elem *result = make_elem(top, bottom);
511 return FRAC_RINGELEM(result);
512}
513
515{
516 frac_elem *f = FRAC_VAL(a);
517 frac_elem *g = FRAC_VAL(b);
518 ring_elem top = R_->mult(f->numer, g->numer);
519 ring_elem bottom = R_->mult(f->denom, g->denom);
520 if (R_->is_zero(bottom)) return set_non_unit_frac(f->denom);
521 return FRAC_RINGELEM(make_elem(top, bottom));
522}
523
525{
526 frac_elem *f = FRAC_VAL(a);
527 ring_elem top, bottom;
528 if (n >= 0)
529 {
530 top = R_->power(f->numer, n);
531 bottom = R_->power(f->denom, n);
532
533 if (R_->is_zero(bottom)) return set_non_unit_frac(f->denom);
534 }
535 else
536 {
537 if (R_->is_zero(f->numer))
538 {
540 }
541 top = R_->power(f->denom, -n);
542 bottom = R_->power(f->numer, -n);
543
544 if (R_->is_zero(bottom)) return set_non_unit_frac(f->numer);
545 }
546
547 return FRAC_RINGELEM(make_elem(top, bottom));
548}
549ring_elem FractionField::power(const ring_elem a, mpz_srcptr n) const
550{
551 frac_elem *f = FRAC_VAL(a);
552 ring_elem top, bottom;
553 if (mpz_sgn(n) >= 0)
554 {
555 top = R_->power(f->numer, n);
556 bottom = R_->power(f->denom, n);
557
558 if (R_->is_zero(bottom)) return set_non_unit_frac(f->denom);
559 }
560 else
561 {
562 if (R_->is_zero(f->numer))
563 {
565 }
566 mpz_t abs_n;
567 mpz_init(abs_n);
568 mpz_abs(abs_n, n);
569
570 top = R_->power(f->denom, abs_n);
571 bottom = R_->power(f->numer, abs_n);
572
573 mpz_clear(abs_n);
574
575 if (R_->is_zero(bottom)) return set_non_unit_frac(f->numer);
576 }
577
578 return FRAC_RINGELEM(make_elem(top, bottom));
579}
580
582{
583 frac_elem *f = FRAC_VAL(a);
584 ring_elem top = R_->copy(f->denom);
585 ring_elem bottom = R_->copy(f->numer);
586 return FRAC_RINGELEM(make_elem(top, bottom));
587}
588
590{
591 frac_elem *f = FRAC_VAL(a);
592 frac_elem *g = FRAC_VAL(b);
593 ring_elem top = R_->mult(f->numer, g->denom);
594 ring_elem bottom = R_->mult(f->denom, g->numer);
595
596 if (R_->is_zero(bottom)) return set_non_unit_frac(f->denom);
597
598 return FRAC_RINGELEM(make_elem(top, bottom));
599}
600
602 const ring_elem b,
603 ring_elem &x,
604 ring_elem &y) const
605{
607 y = FractionField::divide(a, b);
609}
610
612 const ring_elem a,
613 int first_var) const
614{
615 const Ring *S = map->get_ring();
616 const frac_elem *f = FRAC_VAL(a);
617 ring_elem top = R_->eval(map, f->numer, first_var);
618 ring_elem bottom = R_->eval(map, f->denom, first_var);
619 if (S->is_zero(bottom))
620 {
622 S->remove(bottom);
623 top = S->from_long(0);
624 bottom = S->from_long(1);
625 }
626 ring_elem result = S->divide(top, bottom);
627 S->remove(top);
628 S->remove(bottom);
629 return result;
630}
631
633{
634 if (is_zero(a)) return true;
635 const frac_elem *f = FRAC_VAL(a);
636 if (!R_->is_homogeneous(f->numer) || !R_->is_homogeneous(f->denom))
637 return false;
638 return true;
639}
640
642{
643 const frac_elem *f = FRAC_VAL(a);
644 bool tophom = R_->multi_degree(f->numer, d);
646 bool bottomhom = R_->multi_degree(f->denom, e);
647 degree_monoid()->divide(d, e, d);
648 degree_monoid()->remove(e);
649 return tophom && bottomhom;
650}
651
653 const std::vector<int> &,
654 int &lo,
655 int &hi) const
656{
657 assert(0);
658 // MES: what should this do?
659 lo = hi = 0;
660}
661
663 int v,
664 int deg,
665 const std::vector<int> &wts) const
666{
667 int d1, d2, lo1, lo2;
668 ring_elem top, bottom;
670 const frac_elem *f = FRAC_VAL(a);
671 R_->degree_weights(f->numer, wts, lo1, d1);
672 R_->degree_weights(f->denom, wts, lo2, d2);
673 if (deg >= d1 - d2)
674 {
675 top = R_->homogenize(f->numer, v, deg + d2, wts);
676 bottom = R_->homogenize(f->denom, v, d2, wts);
677 result = make_elem(top, bottom);
678 }
679 else
680 {
681 top = R_->homogenize(f->numer, v, d1, wts);
682 bottom = R_->homogenize(f->denom, v, -deg + d1, wts);
683 result = make_elem(top, bottom);
684 }
685 return FRAC_RINGELEM(result);
686}
687
689 int v,
690 const std::vector<int> &wts) const
691{
692 const frac_elem *f = FRAC_VAL(a);
693 ring_elem top = R_->homogenize(f->numer, v, wts);
694 ring_elem bottom = R_->homogenize(f->denom, v, wts);
695 frac_elem *result = make_elem(top, bottom);
696 return FRAC_RINGELEM(result);
697}
698
699int FractionField::n_terms(const ring_elem) const { return 1; }
701{
702 return copy(a);
703}
706{
707 return f;
708}
710 const ring_elem f,
711 int,
712 int) const
713{
714 (void) nvars0;
715 return f;
716}
717
718// Local Variables:
719// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
720// indent-tabs-mode: nil
721// End:
virtual void elem_text_out(buffer &o, const ring_elem f, bool p_one=true, bool p_plus=false, bool p_parens=false) const
Definition frac.cpp:232
virtual bool promote(const Ring *R, const ring_elem f, ring_elem &result) const
Definition frac.cpp:308
virtual bool lift(const Ring *R, const ring_elem f, ring_elem &result) const
Definition frac.cpp:325
virtual ring_elem subtract(const ring_elem f, const ring_elem g) const
Definition frac.cpp:491
void internal_subtract_to(ring_elem &f, ring_elem &g) const
Definition frac.cpp:436
virtual int compare_elems(const ring_elem f, const ring_elem g) const
Definition frac.cpp:388
virtual ring_elem term(const ring_elem a, const_monomial m) const
Definition frac.cpp:700
virtual bool is_zero(const ring_elem f) const
Definition frac.cpp:366
virtual void text_out(buffer &o) const
Definition frac.cpp:62
virtual int index_of_var(const ring_elem a) const
Definition frac.cpp:286
virtual ring_elem homogenize(const ring_elem f, int v, int deg, const std::vector< int > &wts) const
Definition frac.cpp:662
virtual ring_elem mult(const ring_elem f, const ring_elem g) const
Definition frac.cpp:514
virtual ring_elem random() const
Definition frac.cpp:220
virtual ring_elem get_terms(int nvars0, const ring_elem f, int lo, int hi) const
Definition frac.cpp:709
virtual bool is_homogeneous(const ring_elem f) const
Definition frac.cpp:632
static FractionField * create(const PolyRingFlat *R)
Definition frac.cpp:55
virtual unsigned int computeHashValue(const ring_elem a) const
Definition frac.cpp:81
virtual ring_elem get_coeff(const ring_elem f, const_monomial m) const
Definition frac.cpp:705
frac_elem * new_frac_elem() const
Definition frac.cpp:88
virtual ring_elem eval(const RingMap *map, const ring_elem f, int first_var) const
Definition frac.cpp:611
ring_elem set_non_unit_frac(ring_elem top) const
Definition frac.cpp:89
virtual ring_elem invert(const ring_elem f) const
Definition frac.cpp:581
ring_elem numerator(ring_elem f) const
Definition frac.cpp:69
void lower_content(ring_elem &c, const ring_elem g) const
Definition frac.cpp:191
virtual ring_elem add(const ring_elem f, const ring_elem g) const
Definition frac.cpp:468
frac_elem * make_elem(ring_elem a, ring_elem b) const
Definition frac.cpp:182
void simplify(frac_elem *f) const
Definition frac.cpp:108
virtual CoefficientType coefficient_type() const
Definition frac.cpp:17
virtual bool from_rational(mpq_srcptr n, ring_elem &result) const
Definition frac.cpp:268
bool use_gcd_simplify
Definition frac.hpp:64
const PolyRingFlat * R_
Definition frac.hpp:63
virtual ring_elem divide(const ring_elem f, const ring_elem g) const
Definition frac.cpp:589
virtual ring_elem copy(const ring_elem f) const
Definition frac.cpp:397
virtual int n_fraction_vars() const
Definition frac.cpp:26
virtual void degree_weights(const ring_elem f, const std::vector< int > &wts, int &lo, int &hi) const
Definition frac.cpp:652
virtual ring_elem power(const ring_elem f, mpz_srcptr n) const
Exponentiation. This is the default function, if a class doesn't define this.
Definition frac.cpp:549
virtual bool multi_degree(const ring_elem f, monomial d) const
Definition frac.cpp:641
virtual bool is_equal(const ring_elem f, const ring_elem g) const
Definition frac.cpp:371
virtual ring_elem negate(const ring_elem f) const
Definition frac.cpp:459
bool initialize_frac(const PolyRingFlat *R)
Definition frac.cpp:27
ring_elem denominator(ring_elem f) const
Definition frac.cpp:75
virtual int n_terms(const ring_elem f) const
Definition frac.cpp:699
ring_elem fraction(const ring_elem top, const ring_elem bottom) const
Definition frac.cpp:102
void internal_negate_to(ring_elem &f) const
Definition frac.cpp:407
virtual bool is_unit(const ring_elem f) const
Definition frac.cpp:361
virtual ring_elem from_int(mpz_srcptr n) const
Definition frac.cpp:260
virtual ring_elem lead_coeff(const ring_elem f) const
Definition frac.cpp:704
virtual ring_elem from_long(long n) const
Definition frac.cpp:252
virtual M2_arrayint support(const ring_elem a) const
Definition frac.cpp:295
void internal_add_to(ring_elem &f, ring_elem &g) const
Definition frac.cpp:413
virtual void syzygy(const ring_elem a, const ring_elem b, ring_elem &x, ring_elem &y) const
Definition frac.cpp:601
FractionField()
Definition frac.hpp:75
virtual ring_elem var(int v) const
Definition frac.cpp:278
virtual void remove(ring_elem &f) const
Definition frac.cpp:406
int numNonTermOrderVariables() const
Definition monoid.hpp:190
monomial make_one() const
Definition monoid.cpp:455
void remove(monomial d) const
Definition monoid.cpp:462
void divide(const_monomial m, const_monomial n, monomial result) const
Definition monoid.hpp:331
PolynomialRing subclass whose elements are represented as a single flat Nterm* linked list (no fracti...
Definition polyring.hpp:466
int n_quotients() const
Definition polyring.hpp:219
const Ring * getCoefficientRing() const
Definition polyring.hpp:200
virtual const Monoid * getMonoid() const
Definition polyring.hpp:282
virtual const Ring * getCoefficients() const
Definition polyring.hpp:277
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
virtual void remove(ring_elem &f) const =0
void set_non_unit(ring_elem zero_div) const
Definition ring.cpp:88
virtual ring_elem divide(const ring_elem f, const ring_elem g) const =0
ring_elem minus_oneV
Definition ring.hpp:131
ring_elem zero() const
Definition ring.hpp:359
void initialize_ring(long charac, const PolynomialRing *DR=nullptr, const std::vector< int > &heft_vec={})
Definition ring.cpp:30
virtual ring_elem from_long(long n) const =0
long characteristic() const
Definition ring.hpp:159
ring_elem oneV
Definition ring.hpp:130
bool declare_field()
Definition ring.cpp:69
CoefficientType
Definition ring.hpp:222
@ COEFF_QQ
Definition ring.hpp:222
@ COEFF_ZZ
Definition ring.hpp:222
virtual bool is_zero(const ring_elem f) const =0
const PolynomialRing * get_degree_ring() const
Definition ring.hpp:161
virtual const FractionField * cast_to_FractionField() const
Definition ring.hpp:251
virtual CoefficientType coefficient_type() const
Definition ring.hpp:223
const Monoid * degree_monoid() const
Definition ring.cpp:13
const std::vector< int > & get_heft_vector() const
Definition ring.hpp:162
ring_elem zeroV
Definition ring.hpp:129
Ring()
Definition ring.hpp:136
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
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
const Ring * get_ring() const
Definition ringmap.hpp:111
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
Definition ringmap.hpp:60
char * str()
Definition buffer.hpp:72
void reset()
Definition buffer.hpp:69
namespace exc — internal C++ exception types and the TRY / CATCH macro pair.
const RingElement * rawGCDRingElement(const RingElement *f, const RingElement *g, const RingElement *mipo, const M2_bool inExtension)
Definition factory.cpp:488
Engine-boundary C API for polynomial GCD, factorisation, and root finding.
#define FRAC_VAL(f)
Definition frac.cpp:14
#define FRAC_RINGELEM(a)
Definition frac.cpp:15
FractionField — field of fractions of an integral domain, with on-the-fly normalisation.
#define monomial
Definition gb-toric.cpp:11
GBRing and gbvector — the GB-tuned polynomial-ring view used by classical Buchberger code.
const int * const_monomial
Definition imonorder.hpp:45
VALGRIND_MAKE_MEM_DEFINED & result(result)
M2_arrayint M2_makearrayint(int n)
Definition m2-types.cpp:6
char newline[]
Definition m2-types.cpp:49
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
#define newitem(T)
Definition newdelete.hpp:86
volatile int x
PolynomialRing — abstract polynomial-ring base, the engine's most-reused class.
RingElement — tagged (Ring*, ring_elem) pair, the engine's universal element type.
RingMap — engine representation of a ring homomorphism.
ring_elem numer
Definition frac.hpp:43
ring_elem denom
Definition frac.hpp:44
void emit(const char *s)
Definition text-io.cpp:41
Text-formatting helpers layered on buffer: bignum print, line wrapping, M2_gbTrace-gated emit.