Skip to content

Commit

Permalink
Merge pull request algebraic-solving#124 from mohabsafey/truncate-lif…
Browse files Browse the repository at this point in the history
…ting

Truncate lifting (grevlex GB)
  • Loading branch information
ederc authored Feb 12, 2024
2 parents 29b490f + 821e8df commit ea859ac
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ check_PROGRAMS = neogb_io \

checkdiff = test/diff/diff_cp_d_3_n_4_p_2.sh \
test/diff/diff_eco11-31.sh \
test/diff/diff_elim-31.sh \
test/diff/diff_truncate_gb.sh \
test/diff/diff_elim-31.sh \
test/diff/diff_elim-qq.sh \
test/diff/diff_F4SAT-31.sh \
test/diff/diff_F4SAT-byone-31.sh \
Expand All @@ -34,8 +35,8 @@ checkdiff = test/diff/diff_cp_d_3_n_4_p_2.sh \
test/diff/diff_radical_shape-qq.sh \
test/diff/diff_reals_dim0.sh \
test/diff/diff_reals_extract.sh \
test/diff/diff_reals_dim0-swapvar.sh \
test/diff/diff_reals_dim0-chgvar.sh \
test/diff/diff_reals_dim0-swapvar.sh \
test/diff/diff_reals_dim0-chgvar.sh \
test/diff/diff_bug_empty_tracer.sh \
test/diff/diff_bug_2nd_prime_bad.sh \
test/diff/diff_bug_68.sh \
Expand Down
5 changes: 4 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ AC_CONFIG_LINKS([
output_files/nonradical_radicalshape-no-square-qq.res:output_files/nonradical_radicalshape-no-square-qq.res
output_files/nonradical_radicalshape-no-square-qq.p3.res:output_files/nonradical_radicalshape-no-square-qq.p3.res
test/diff/diff_nonradical_radicalshape-no-square-qq.sh:test/diff/diff_nonradical_radicalshape-no-square-qq.sh
input_files/one-16.ms:input_files/one-16.ms
input_files/one-16.ms:input_files/one-16.ms
output_files/one-16.res:output_files/one-16.res
test/diff/diff_one-16.sh:test/diff/diff_one-16.sh
input_files/kat8-qq-truncate.ms:input_files/kat8-qq-truncate.ms
output_files/kat8-qq-truncate.res:output_files/kat8-qq-truncate.res
test/diff/diff_truncate_gb.sh:test/diff/diff_truncate_gb.sh
input_files/one-31.ms:input_files/one-31.ms
output_files/one-31.res:output_files/one-31.res
test/diff/diff_one-31.sh:test/diff/diff_one-31.sh
Expand Down
10 changes: 10 additions & 0 deletions input_files/kat8-qq-truncate.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x1,x2,x3,x4,x5,x6,x7,x8
0
x1+2*x2+2*x3+2*x4+2*x5+2*x6+2*x7+2*x8-1,
x1^2+2*x2^2+2*x3^2+2*x4^2+2*x5^2+2*x6^2+2*x7^2+2*x8^2-x1,
2*x1*x2+2*x2*x3+2*x3*x4+2*x4*x5+2*x5*x6+2*x6*x7+2*x7*x8-x2,
x2^2+2*x1*x3+2*x2*x4+2*x3*x5+2*x4*x6+2*x5*x7+2*x6*x8-x3,
2*x2*x3+2*x1*x4+2*x2*x5+2*x3*x6+2*x4*x7+2*x5*x8-x4,
x3^2+2*x2*x4+2*x1*x5+2*x2*x6+2*x3*x7+2*x4*x8-x5,
2*x3*x4+2*x2*x5+2*x1*x6+2*x2*x7+2*x3*x8-x6,
x4^2+2*x3*x5+2*x2*x6+2*x1*x7+2*x2*x8-x7
13 changes: 13 additions & 0 deletions output_files/kat8-qq-truncate.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Truncated reduced Groebner basis data
#---
#field characteristic: 0
#variable order: x1, x2, x3, x4, x5, x6, x7, x8
#monomial order: graded reverse lexicographical
#length of basis: 5 elements sorted by increasing leading monomials
#---
[x1+2*x2+2*x3+2*x4+2*x5+2*x6+2*x7+2*x8-1,
15*x5^2+30*x4*x6+64*x5*x6+51*x6^2+30*x3*x7+64*x4*x7+102*x5*x7+144*x6*x7+95*x7^2+30*x2*x8+64*x3*x8+102*x4*x8+144*x5*x8+190*x6*x8+240*x7*x8+147*x8^2-1*x2-4*x3-9*x4-16*x5-25*x6-36*x7-49*x8,
30*x4*x5+30*x3*x6-34*x5*x6-36*x6^2+30*x2*x7-34*x4*x7-72*x5*x7-114*x6*x7-80*x7^2-60*x2*x8-94*x3*x8-132*x4*x8-174*x5*x8-220*x6*x8-270*x7*x8-192*x8^2+x2+4*x3+9*x4+16*x5+25*x6+36*x7+64*x8,
x4^2+2*x3*x5+2*x2*x6-4*x2*x7-4*x3*x7-4*x4*x7-4*x5*x7-4*x6*x7-4*x7^2+2*x2*x8-4*x7*x8+x7,
2*x3*x4+2*x2*x5-4*x2*x6-4*x3*x6-4*x4*x6-4*x5*x6-4*x6^2+2*x2*x7-4*x6*x7+2*x3*x8-4*x6*x8+x6
]:
23 changes: 15 additions & 8 deletions src/msolve/lifting-gb.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ static int32_t * gb_modular_trace_learning(gb_modpoly_t modgbs,
const int32_t fc,
int info_level,
int print_gb,
int truncate_lifting,
int *dim,
long *dquot_ori,
int32_t start,
Expand Down Expand Up @@ -640,7 +641,6 @@ static int32_t * gb_modular_trace_learning(gb_modpoly_t modgbs,

int32_t len = bs->lml;
num_gb[0] = compute_num_gb(bexp_lm, len, bht->nv, st->nev);

int32_t *bexp_lm2 = NULL;
if(st->nev){
bexp_lm2 = calloc(num_gb[0]*(bht->nv - st->nev), sizeof(int32_t));
Expand Down Expand Up @@ -671,8 +671,12 @@ static int32_t * gb_modular_trace_learning(gb_modpoly_t modgbs,
/* int32_t *lens = array_of_lengths(bexp_lm, num_gb[0], lmb, dquot, bht->nv); */
int32_t *lens = array_of_lengths(leadmons[0], num_gb[0], lmb, dquot, bht->nv - st->nev);

gb_modpoly_init(modgbs, 2, lens, bht->nv - st->nev, num_gb[0], leadmons[0], lmb);

if(truncate_lifting != 0 && truncate_lifting < num_gb[0]){
gb_modpoly_init(modgbs, 2, lens, bht->nv - st->nev, truncate_lifting, leadmons[0], lmb);
}
else{
gb_modpoly_init(modgbs, 2, lens, bht->nv - st->nev, num_gb[0], leadmons[0], lmb);
}
modpgbs_set(modgbs, bs, bht, fc, lmb, dquot, mgb, start, st->nev);
if(bs->lml == 1){
if(info_level){
Expand Down Expand Up @@ -837,12 +841,10 @@ static inline void incremental_dlift_crt_full(gb_modpoly_t modgbs, data_lift_t d
int thrds){

uint64_t newprime = modgbs->primes[modgbs->nprimes - 1 ];

/* all primes are assumed to be good primes */
mpz_mul_ui(prod_p, mod_p, (uint32_t)newprime);
for(int32_t k = 0; k < dl->end; k++){
uint64_t c = modgbs->modpolys[k]->cf_32[coef[k]][modgbs->nprimes - 1 ];

mpz_CRT_ui(dl->crt[k], dl->crt[k], mod_p,
c, newprime, prod_p, dl->tmp, 1);
}
Expand Down Expand Up @@ -1162,6 +1164,7 @@ int msolve_gbtrace_qq(
int32_t info_level = flags->info_level;
int32_t pbm_file = flags->pbm_file;
int32_t print_gb = flags->print_gb;
int32_t truncate_lifting = flags->truncate_lifting;
files_gb *files = flags->files;

uint32_t field_char = gens->field_char;
Expand Down Expand Up @@ -1248,8 +1251,6 @@ int msolve_gbtrace_qq(
prime = next_prime(rand() % (1303905301 - (1<<30) + 1) + (1<<30));
}

/* prime = 1246973177; */

primeinit = prime;
msd->lp->p[0] = primeinit;
if(gens->field_char){
Expand Down Expand Up @@ -1288,6 +1289,7 @@ int msolve_gbtrace_qq(
msd->lp->p[0],
info_level,
print_gb,
truncate_lifting,
dim_ptr, dquot_ptr,
0,
gens, maxbitsize,
Expand Down Expand Up @@ -1534,7 +1536,12 @@ void print_msolve_gbtrace_qq(data_gens_ff_t *gens,
fprintf(ofile, "#Leading ideal data\n");
} else {
if (flags->print_gb > 1) {
fprintf(ofile, "#Reduced Groebner basis data\n");
if(flags->truncate_lifting>0){
fprintf(ofile, "#Truncated reduced Groebner basis data\n");
}
else{
fprintf(ofile, "#Reduced Groebner basis data\n");
}
}
}
fprintf(ofile, "#---\n");
Expand Down
11 changes: 8 additions & 3 deletions src/msolve/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ static void getoptions(
int32_t *update_ht,
int32_t *reduce_gb,
int32_t *print_gb,
int32_t *truncate_lifting,
int32_t *genericity_handling,
int32_t *saturate,
int32_t *colon,
Expand All @@ -161,9 +162,12 @@ static void getoptions(
char *out_fname = NULL;
char *bin_out_fname = NULL;
opterr = 1;
char options[] = "hf:F:v:l:t:e:o:O:u:iI:p:P:q:g:c:s:SCr:R:m:M:n:";
char options[] = "hf:N:F:v:l:t:e:o:O:u:iI:p:P:q:g:c:s:SCr:R:m:M:n:";
while((opt = getopt(argc, argv, options)) != -1) {
switch(opt) {
case 'N':
*truncate_lifting = strtol(optarg, NULL, 10);
break;
case 'h':
display_help(argv[0]);
exit(1);
Expand Down Expand Up @@ -322,6 +326,7 @@ int main(int argc, char **argv){
int32_t generate_pbm = 0;
int32_t reduce_gb = 1;
int32_t print_gb = 0;
int32_t truncate_lifting = 0;
int32_t genericity_handling = 2;
int32_t saturate = 0;
int32_t colon = 0;
Expand All @@ -341,7 +346,7 @@ int main(int argc, char **argv){
files->bin_out_file = NULL;
getoptions(argc, argv, &initial_hts, &nr_threads, &max_pairs,
&elim_block_len, &la_option, &use_signatures, &update_ht,
&reduce_gb, &print_gb, &genericity_handling, &saturate, &colon,
&reduce_gb, &print_gb, &truncate_lifting, &genericity_handling, &saturate, &colon,
&normal_form, &normal_form_matrix, &is_gb, &get_param,
&precision, &refine, &isolate, &generate_pbm, &info_level, files);

Expand Down Expand Up @@ -406,7 +411,7 @@ int main(int argc, char **argv){
/* main msolve functionality */
int ret = core_msolve(la_option, use_signatures, nr_threads, info_level,
initial_hts, max_pairs, elim_block_len, update_ht,
generate_pbm, reduce_gb, print_gb, get_param,
generate_pbm, reduce_gb, print_gb, truncate_lifting, get_param,
genericity_handling, saturate, colon, normal_form,
normal_form_matrix, is_gb, precision,
files, gens,
Expand Down
1 change: 1 addition & 0 deletions src/msolve/msolve-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ typedef struct{
int32_t use_signatures;
int32_t info_level;
int32_t print_gb;
int32_t truncate_lifting;
int32_t pbm_file;
files_gb *files;
} msolveflags_struct;
Expand Down
5 changes: 4 additions & 1 deletion src/msolve/msolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -3646,6 +3646,7 @@ int core_msolve(
int32_t generate_pbm,
int32_t reduce_gb,
int32_t print_gb,
int32_t truncate_lifting,
int32_t get_param,
int32_t genericity_handling,
int32_t saturate,
Expand Down Expand Up @@ -4835,6 +4836,7 @@ int core_msolve(
flags->nr_threads = nr_threads;
flags->max_nr_pairs = max_pairs;
flags->elim_block_len = elim_block_len;
flags->truncate_lifting = truncate_lifting;
flags->reset_ht = update_ht;
flags->la_option = la_option;
flags->use_signatures = use_signatures;
Expand Down Expand Up @@ -5170,7 +5172,8 @@ void msolve_julia(
/* main msolve functionality */
int ret = core_msolve(la_option, use_signatures, nr_threads, info_level,
initial_hts, max_nr_pairs, elim_block_len, reset_ht,
0 /* generate pbm */, 1 /* reduce_gb */, print_gb, get_param,
0 /* generate pbm */, 1 /* reduce_gb */,
print_gb, 0 /*truncate_lifting*/, get_param,
genericity_handling, 0 /* saturate */, 0 /* colon */,
0 /* normal_form */, 0 /* normal_form_matrix */,
0 /* is_gb */, precision, files,
Expand Down
1 change: 1 addition & 0 deletions src/msolve/msolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ int core_msolve(
int32_t generate_pbm,
int32_t reduce_gb,
int32_t print_gb,
int32_t truncate_lifting,
int32_t get_param,
int32_t genericity_handling,
int32_t saturate,
Expand Down
49 changes: 49 additions & 0 deletions test/diff/diff_truncate_gb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

file=kat8-qq-truncate

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res \
-N 5 -g 2 -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 \
-N 5 -g 2 -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 \
-N 5 -g 2 -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 \
-N 5 -g 2 -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

rm test/diff/$file.res

0 comments on commit ea859ac

Please sign in to comment.