Skip to content

Commit

Permalink
Improve algebraic number to rational
Browse files Browse the repository at this point in the history
return the true rational when is_rational is true by adding the case
P(X)=den*X-num
  • Loading branch information
bobot committed Jan 25, 2022
1 parent ff74f34 commit 9a6e2cb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/number/algebraic_number.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "polynomial/coefficient.h"
#include "polynomial/output.h"
#include "upolynomial/output.h"
#include "upolynomial/upolynomial.h"

#include "utils/debug_trace.h"

Expand Down Expand Up @@ -553,6 +554,19 @@ void lp_algebraic_number_to_rational(const lp_algebraic_number_t* a_const, lp_ra
return;
}

if (lp_upolynomial_degree(a_const->f) == 1) {
// If degree 1, we're directly rational
if(a_const->f->size==2){
mpz_neg(&q->_mp_num,&a_const->f->monomials[0].coefficient);
mpz_set(&q->_mp_den,&a_const->f->monomials[1].coefficient);
} else {
/* a_const == 0, is it possible without a_const->f==0? */
assert (a_const->f->size<=1);
mpq_set_ui(q,0,1);
}
return;
}

// We do the necessary refinement on a copy
lp_algebraic_number_t a;
lp_algebraic_number_construct_copy(&a, a_const);
Expand Down

0 comments on commit 9a6e2cb

Please sign in to comment.