-
Notifications
You must be signed in to change notification settings - Fork 18
Closed
Description
When p has degree 1, discriminant(p) returns a polynomial built in the default context rather than in p's context:
libpoly/src/polyxx/polynomial.cpp
Lines 369 to 374 in fc54e31
| Polynomial discriminant(const Polynomial& p) { | |
| if (degree(p) == 1) { | |
| // Derivative is constant, making the resultant trivial (and resultant() | |
| // does not cope with that) | |
| return Polynomial(Integer(1)); | |
| } |
This can cause an assertion failure when the returned polynomial is combined with polynomials from the original context:
#include <poly/polyxx.h>
#include <iostream>
int main()
{
poly::Context ctx;
poly::Variable x(ctx, "x");
poly::Polynomial p1(ctx, x);
poly::Polynomial d = poly::discriminant(p1); // d built in the default context
poly::Polynomial p2 = p1 + d; // assertion failure!
std::cout << p2 << std::endl;
return 0;
}A possible fix is to add a constructor that takes a C context and an integer:
Polynomial::Polynomial(const lp_polynomial_context_t* c, Integer i)
: mPoly(lp_polynomial_new(c), polynomial_deleter) {
lp_polynomial_construct_simple(get_internal(), c,
i.get_internal(), lp_variable_null, 0);
}Then, construct the polynomial in the desired context:
return Polynomial(detail::context(p), Integer(1));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels