Skip to content

Commit

Permalink
Merge pull request #181 from mohabsafey/issue-178
Browse files Browse the repository at this point in the history
Resolves Issue 178
  • Loading branch information
vneiger authored Sep 20, 2024
2 parents 105cca6 + 2a8163d commit a87c873
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 17 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ checkdiff = test/diff/diff_cp_d_3_n_4_p_2.sh \
test/diff/diff_one-qq.sh \
test/diff/diff_radical_shape-31.sh \
test/diff/diff_radical_shape-qq.sh \
test/diff/diff_realroot-extraction-exact-root.sh \
test/diff/diff_reals_dim0.sh \
test/diff/diff_reals_dim0-chgvar.sh \
test/diff/diff_reals_dim0-extract.sh \
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ AC_CONFIG_LINKS([
input_files/reals_dim0.ms:input_files/reals_dim0.ms
output_files/reals_dim0.res:output_files/reals_dim0.res
output_files/reals_dim0.p256.res:output_files/reals_dim0.p256.res
test/diff/diff_realroot-extraction-exact-root.sh:test/diff/diff_realroot-extraction-exact-root.sh
input_files/realroot-extraction-exact-root.ms:input_files/realroot-extraction-exact-root.ms
output_files/realroot-extraction-exact-root.res:output_files/realroot-extraction-exact-root.res
output_files/realroot-extraction-exact-root.p256.res:output_files/realroot-extraction-exact-root.p256.res
test/diff/diff_reals_dim0.sh:test/diff/diff_reals_dim0.sh
input_files/reals_dim0-extract.ms:input_files/reals_dim0-extract.ms
output_files/reals_dim0-extract.res:output_files/reals_dim0-extract.res
Expand Down
5 changes: 5 additions & 0 deletions input_files/realroot-extraction-exact-root.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
x,y
0
x^2 - 140*x*y - y^3 + 4900*y^2,
1427247692705959881058285969449495136382746624*y-1

3 changes: 3 additions & 0 deletions output_files/realroot-extraction-exact-root.p256.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[0, [1,
[[[2644525230407001319669759 / 2^225, 2644525230407001319669759 / 2^225], [1 / 2^150, 1 / 2^150]], [[2644525230407001319669761 / 2^225, 2644525230407001319669761 / 2^225], [1 / 2^150, 1 / 2^150]]]
]]:
3 changes: 3 additions & 0 deletions output_files/realroot-extraction-exact-root.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[0, [1,
[[[2644525230407001319669759 / 2^225, 2644525230407001319669759 / 2^225], [1 / 2^150, 1 / 2^150]], [[2644525230407001319669761 / 2^225, 2644525230407001319669761 / 2^225], [1 / 2^150, 1 / 2^150]]]
]]:
30 changes: 23 additions & 7 deletions src/msolve/msolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -2924,7 +2924,7 @@ int newvalue_denom(mpz_t *denom, long deg, mpz_t r, long k, mpz_t *xdo,
mpz_fdiv_q_2exp(den_do, den_do, k * deg);
mpz_cdiv_q_2exp(den_up, den_up, k * deg);

return boo;
return (boo || (mpz_sgn(den_do)==0) || (mpz_sgn(den_up)==0));
}

void lazy_single_real_root_param(mpz_param_t param, mpz_t *polelim,
Expand All @@ -2938,18 +2938,19 @@ void lazy_single_real_root_param(mpz_param_t param, mpz_t *polelim,
/* root is exact */
if (rt->isexact == 1) {
single_exact_real_root_param(param, rt, nb, xdo, xup, den_up, den_do, c,
tmp, val_do, val_up, tab, pt, prec,
tmp, val_do, val_up, tab, pt, MAX(rt->k, prec),
info_level);
return;
}

long b = 16;
long corr = 2 * (ns + rt->k);
int64_t b = 16;
int64_t corr = 2 * (ns + rt->k);

/* checks whether the abs. value of the root is greater than 1 */

generate_table_values_full(rt, c, ns, b, corr, xdo, xup);
while (newvalue_denom(param->denom->coeffs, param->denom->length - 1,
while (rt->isexact == 0 &&
newvalue_denom(param->denom->coeffs, param->denom->length - 1,
rt->numer, rt->k, xdo, xup, tmp, den_do, den_up, corr,
s)) {

Expand All @@ -2958,7 +2959,7 @@ void lazy_single_real_root_param(mpz_param_t param, mpz_t *polelim,
get_values_at_bounds(param->elim->coeffs, ns, rt, tab);
refine_QIR_positive_root(polelim, &ns, rt, tab, 2 * (rt->k), info_level);
} else {
/* root is positive */
/* root is negative */
mpz_add_ui(pos_root->numer, rt->numer, 1);
mpz_neg(pos_root->numer, pos_root->numer);
pos_root->k = rt->k;
Expand Down Expand Up @@ -3002,13 +3003,28 @@ void lazy_single_real_root_param(mpz_param_t param, mpz_t *polelim,
corr *= 2;
b *= 2;

if(rt->isexact){
mpz_poly_eval_2exp_naive(param->denom->coeffs, param->denom->length - 1,
&rt->numer, rt->k, xdo, xup);
mpz_set(den_up, xdo[0]);
mpz_set(den_do, xdo[0]);
corr = (param->denom->length - 1) * rt->k;
}
generate_table_values_full(rt, c, ns, b, corr, xdo, xup);

if (info_level) {
fprintf(stderr, "<%ld>", rt->k);
}
}


if (rt->isexact == 1) {
single_exact_real_root_param(param, rt, nb, xdo, xup, den_up, den_do, c,
tmp, val_do, val_up, tab, pt, MAX(prec, rt->k),
info_level);
return;
}

mpz_t v1, v2;
mpz_init(v1);
mpz_init(v2);
Expand All @@ -3027,7 +3043,7 @@ void lazy_single_real_root_param(mpz_param_t param, mpz_t *polelim,
mpz_mul_2exp(val_up, val_up, dec);
mpz_mul_2exp(val_do, val_do, dec);

if (mpz_cmp(val_do, val_up) > 0) {
if (rt->isexact==0 && mpz_cmp(val_do, val_up) > 0) {
fprintf(stderr, "BUG in real root extractor(2)\n");
exit(1);
}
Expand Down
17 changes: 9 additions & 8 deletions src/usolve/refine.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ static int left_interval(mpz_t *upoly, unsigned long int *deg_ptr,

static void refine_root_by_N_positive_k(mpz_t *upol, unsigned long int *deg_ptr,
interval *rt,
mpz_t *tab, long long int Nlog,
mpz_t *tab, int64_t Nlog,
int *success, int verbose){
long k = (rt-> k);
long newk = k+Nlog;
int64_t k = (rt-> k);
int64_t newk = k+Nlog;
int sgna, sgnb, sgnx;
long long int index;
int64_t index;

mpz_t *vala = (tab);
mpz_t *valb = (tab+1);
Expand All @@ -287,7 +287,7 @@ static void refine_root_by_N_positive_k(mpz_t *upol, unsigned long int *deg_ptr,

mpz_set(*vala, *tmpvala);
mpz_set(*valb, *tmpvalb);
unsigned long long maxindex = (1<<(Nlog));
int64_t maxindex = (1L<<(Nlog));

if(index == -2 || index == 0 || (LOG2(index) > Nlog && index > 0) ){
if(Nlog == 2) index = 2;
Expand Down Expand Up @@ -408,7 +408,7 @@ static void refine_root_by_N_positive_k(mpz_t *upol, unsigned long int *deg_ptr,
//tab[0] et tab[1] contiennent f(a) et f(b) respectivement
//tab[2] contient b
static void refine_root_by_N_negative_k(mpz_t *upol, unsigned long int *deg_ptr,
interval *rt, mpz_t *tab, long long int Nlog,
interval *rt, mpz_t *tab, int64_t Nlog,
int *success, int verbose){
long newk;
/* one takes the opposite */
Expand Down Expand Up @@ -595,7 +595,7 @@ static void refine_root_by_N_negative_k(mpz_t *upol, unsigned long int *deg_ptr,
*/
static void refine_positive_root_by_N(mpz_t *upol, unsigned long int *deg_ptr,
interval *rt, mpz_t *tab,
unsigned long long int Nlog, int *success,
int64_t Nlog, int *success,
int verbose){
*success = 1;

Expand All @@ -622,7 +622,7 @@ static void refine_positive_root_by_N(mpz_t *upol, unsigned long int *deg_ptr,
void refine_QIR_positive_root(mpz_t *upol, unsigned long int *deg_ptr,
interval *rt, mpz_t *tab, int prec, int verbose){
if(rt->isexact==1) return;
long long int Nlog = 2;
int64_t Nlog = 2;
int success = 1;
while(rt->isexact != 1 && rt->k < prec){

Expand Down Expand Up @@ -882,6 +882,7 @@ void refine_QIR_roots(mpz_t *upol, unsigned long int *deg, interval *roots,
void refine_QIR_roots_adaptative(mpz_t *upol, unsigned long int *deg, interval *roots,
int nbneg, int nbpos,
int prec, int verbose, double step, int nthreads){

unsigned long int i;
/* table for intermediate values */
mpz_t *tab = (mpz_t *)(malloc(sizeof(mpz_t) * 8));
Expand Down
2 changes: 0 additions & 2 deletions src/usolve/usolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,6 @@ interval *real_roots(mpz_t *upoly, unsigned long deg,
}
}

/* display_roots_system(stderr, roots, nbroots); */
/* fprintf(stderr, "First root \n"); */
/* display_root(stderr, roots); */

e_time = realtime ( ) - e_time;
Expand Down
93 changes: 93 additions & 0 deletions test/diff/diff_realroot-extraction-exact-root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

file=realroot-extraction-exact-root

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-l 2 -t 1
if [ $? -gt 0 ]; then
exit 1
fi

diff test/diff/$file.res output_files/$file.res
if [ $? -gt 0 ]; then
exit 2
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-p 256 -l 2 -t 1
if [ $? -gt 0 ]; then
exit 3
fi

diff test/diff/$file.res output_files/$file.p256.res
if [ $? -gt 0 ]; then
exit 4
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-l 2 -t 2
if [ $? -gt 0 ]; then
exit 21
fi

diff test/diff/$file.res output_files/$file.res
if [ $? -gt 0 ]; then
exit 22
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-p 256 -l 2 -t 2
if [ $? -gt 0 ]; then
exit 23
fi

diff test/diff/$file.res output_files/$file.p256.res
if [ $? -gt 0 ]; then
exit 24
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-l 44 -t 1
if [ $? -gt 0 ]; then
exit 41
fi

diff test/diff/$file.res output_files/$file.res
if [ $? -gt 0 ]; then
exit 42
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-p 256 -l 44 -t 1
if [ $? -gt 0 ]; then
exit 43
fi

diff test/diff/$file.res output_files/$file.p256.res
if [ $? -gt 0 ]; then
exit 44
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-l 44 -t 2
if [ $? -gt 0 ]; then
exit 61
fi

diff test/diff/$file.res output_files/$file.res
if [ $? -gt 0 ]; then
exit 62
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-p 256 -l 44 -t 2
if [ $? -gt 0 ]; then
exit 63
fi

diff test/diff/$file.res output_files/$file.p256.res
if [ $? -gt 0 ]; then
exit 64
fi

rm test/diff/$file.res

0 comments on commit a87c873

Please sign in to comment.