-
Notifications
You must be signed in to change notification settings - Fork 291
"fraction" fixes #4462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
"fraction" fixes #4462
Changes from 3 commits
fe3f4ad
7710417
52ae302
8e560c1
15bd7b4
d38b5fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| #include "groebner-computations/gbring.hpp" | ||
| #include "ring-elements/ring-element.hpp" | ||
| #include "rings/polyring.hpp" | ||
| #include "rings/polyquotient.hpp" | ||
| #include "exceptions.hpp" | ||
|
|
||
| #define FRAC_VAL(f) (reinterpret_cast<frac_elem *>((f).poly_val)) | ||
|
|
@@ -99,6 +100,30 @@ ring_elem FractionField::set_non_unit_frac(ring_elem top) const | |
| return zero(); | ||
| } | ||
|
|
||
| bool FractionField::simplify_unit_denominator(frac_elem *f) const | ||
| { | ||
| if (R_->is_equal(f->denom, R_->one())) return true; | ||
|
|
||
| ring_elem denom_inverse; | ||
| if (dynamic_cast<const PolyRingQuotient *>(R_) != nullptr) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| { | ||
| denom_inverse = R_->invert(f->denom); | ||
| if (R_->is_zero(denom_inverse)) return false; | ||
| } | ||
| else | ||
| { | ||
| if (!R_->is_unit(f->denom)) return false; | ||
| denom_inverse = R_->invert(f->denom); | ||
| } | ||
|
|
||
| ring_elem numer = R_->mult(f->numer, denom_inverse); | ||
| R_->remove(f->numer); | ||
| R_->remove(f->denom); | ||
| f->numer = numer; | ||
| f->denom = R_->one(); | ||
| return true; | ||
| } | ||
|
|
||
| ring_elem FractionField::fraction(const ring_elem top, | ||
| const ring_elem bottom) const | ||
| { | ||
|
|
@@ -108,15 +133,17 @@ ring_elem FractionField::fraction(const ring_elem top, | |
| void FractionField::simplify(frac_elem *f) const | ||
| { | ||
| ring_elem x, y; | ||
| if (simplify_unit_denominator(f)) return; | ||
| if (use_gcd_simplify) | ||
| { | ||
| y = f->denom; | ||
| if (R_->is_equal(y, R_->one())) return; | ||
|
pzinn marked this conversation as resolved.
|
||
| x = f->numer; | ||
| const RingElement *a = RingElement::make_raw(R_, x); | ||
| const RingElement *b = RingElement::make_raw(R_, y); | ||
| const RingElement *c = rawGCDRingElement(a, b, nullptr, false); | ||
| if (!c) return; | ||
| if (!R_->is_equal(y, R_->one())) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| { | ||
| x = f->numer; | ||
| const RingElement *a = RingElement::make_raw(R_, x); | ||
| const RingElement *b = RingElement::make_raw(R_, y); | ||
| const RingElement *c = rawGCDRingElement(a, b, nullptr, false); | ||
| if (!c) return; | ||
|
|
||
| #if 0 | ||
| // Debugging code | ||
|
|
@@ -131,10 +158,11 @@ void FractionField::simplify(frac_elem *f) const | |
| o << newline; | ||
| emit(o.str()); | ||
| #endif | ||
| if (!R_->is_equal(c->get_value(), R_->one())) | ||
| { | ||
| f->numer = R_->divide(f->numer, c->get_value()); | ||
| f->denom = R_->divide(f->denom, c->get_value()); | ||
| if (!R_->is_equal(c->get_value(), R_->one())) | ||
| { | ||
| f->numer = R_->divide(f->numer, c->get_value()); | ||
| f->denom = R_->divide(f->denom, c->get_value()); | ||
| } | ||
| } | ||
| // Now, let's take the content of the denominator, and divide the | ||
| // numerator | ||
|
|
@@ -159,6 +187,7 @@ void FractionField::simplify(frac_elem *f) const | |
| f->numer = R_->divide_by_given_content(f->numer, ct); | ||
| f->denom = R_->divide_by_given_content(f->denom, ct); | ||
| } | ||
| simplify_unit_denominator(f); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -176,6 +205,7 @@ void FractionField::simplify(frac_elem *f) const | |
| R_->remove(f->denom); | ||
| f->numer = y; | ||
| f->denom = x; | ||
| simplify_unit_denominator(f); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -267,12 +297,11 @@ ring_elem FractionField::from_int(mpz_srcptr n) const | |
|
|
||
| bool FractionField::from_rational(mpq_srcptr n, ring_elem &result) const | ||
| { | ||
| frac_elem *f = new_frac_elem(); | ||
| f->numer = R_->from_int(mpq_numref(n)); | ||
| f->denom = R_->from_int(mpq_denref(n)); | ||
| bool ok = not R_->is_zero(f->denom); | ||
| if (ok) result = FRAC_RINGELEM(f); | ||
| return ok; | ||
| ring_elem numer = R_->from_int(mpq_numref(n)); | ||
| ring_elem denom = R_->from_int(mpq_denref(n)); | ||
| if (R_->is_zero(denom)) return false; | ||
| result = FRAC_RINGELEM(make_elem(numer, denom)); | ||
| return true; | ||
| } | ||
|
|
||
| ring_elem FractionField::var(int v) const | ||
|
|
@@ -340,6 +369,12 @@ bool FractionField::lift(const Ring *Rg, | |
| result = R_->copy(h->numer); | ||
| return true; | ||
| } | ||
| else if (R_->is_unit(h->denom)) | ||
| { | ||
| ring_elem hinv = R_->invert(h->denom); | ||
| result = R_->mult(hinv, h->numer); | ||
| return true; | ||
| } | ||
| else | ||
| { | ||
| if (R_->is_field()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -957,6 +957,15 @@ end-- | |
| gens gb Iloc | ||
| /// | ||
|
|
||
| TEST /// -- normalize ambient-unit denominators | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test never gets run because of the (While you're at it, would you mind moving up the |
||
| R = QQ[x] | ||
| RP = localRing(R, ideal x) | ||
| f = sub(1/2, RP) | ||
| assert(numerator f == 1/2_R) | ||
| assert(denominator f == 1_R) | ||
| assert(lift(f, R) == 1/2_R) | ||
| /// | ||
|
|
||
| TEST /// | ||
| -- promoting/lifting to/from fraction field | ||
| S = QQ[x] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.