// Optimization of initial probability distribution for squarefree Erdos-Selfridge problem. // See https://arxiv.org/abs/1901.11465 for more details. // Uses the Gurobi linear programming optimization package. // // We consider a box [Z/3]x[Z/5]x[Z/7]x[Z/11] of size 3x5x7x11, partially covered by // non-trivial hyperplanes. Each hyperplane is of the form // [a_0,a_1,a_2,a_3]={(x_0,x_1,x_2,x_3):x_i=a_i mod p_i or x_i unrestricted if a_i=*}. // Codimension 1 hyperplanes are assumed to exist and have x_i=0 as their only non-trivial // constraint. Here p_0=3, p_1=5, p_2=7, p_3=11, although the program does not assume these to be prime. // // The program loops through possibilities for the other hyperplanes, then optimizes the probability // distribution on the uncovered set so that the quantity c_a(3)-S*c_a(1) is minimized, where S=0.75 // and c_a(k) = \sum_s c(s)k^{|s|}, where c(s)= maximum weight (probability) of a hyperplane with // s as its set of fixed coordinates. This sum is over all 16 subsets of the primes, in particular // c(\emptyset)=1. // // Points in box are represented by integers mod M=3.5.7.11, but *not* via the CRT: // in order to make the code applicable to non-prime dimensions, the point (x_0,x_1,x_2,x_3) // is represented by x_0+x_1p_0+x2p_0p_1+x_3p_0p_1p_2=\sum x_iq_i, where q_i=\prod_{j=2. The following optimizations are implemented. // 1. No hyperplane is a subset of a previous hyperplane. // 2. A hyperplane [a_0,a_1,a_2,a_3] should not have an a_i more than 1 larger than the a_i's of all // previous hyperplanes. Permuting x_i=a_i and x_i=a_i-1 in all points of the box shows that this // reduces to an earlier example. // 3. The probability assigned to [x_0,x_1,x_2,x_3] can be assumed by symmetry to be the same as // that with x_i replaced by x'_i, if both x_i and x'_i > a_i for all hyperplanes [a_0,a_1,a_2,a_3]. // This reduces the number of variables in the LP problem. // // The function c_a(3)-S*c_a(1) is calculated from the distribution on the uncovered set returned by Gurobi, // not from the corresponding hyperplane variables. The distribution is normalized to a probability // distribution and checked for non-negativity. Thus any errors/inaccuracies in Gurobi will not affect the // mathematical rigor of the output, although it might make the results suboptimal. #include #include #include #include #define N 4 // number of small primes used for initial optimization of measure #define M (3*5*7*11) // product of small primes #define S 0.75 // constant in function c_a(3)-S*c_a(1) to be minimized #define LM 9.018 // threshold on c_a(3)-S*c_a(1) for reporting configurations #define OPT 4 // omit up to the last OPT hyperplanes to reduce number of configurations #define DISP 4 // display details for configs exceeding threshold with <=DISP missing hyperplanes int p[N]={3,5,7,11}; // list of small primes/dimensions of box int q[N+1]; // products of first i small primes (q[0]=1, q[1]=3, q[2]=15, ..., q[N]=M) int a[1<1e-10||lp-v>1e-10){printf("Inconsistency detected in program\n");err(0);} printf("\n"); } // Setup various arrays // void setup(){ int i,s,h; // Setup q[i]=\prod_{j=0;h--){ s=0; // s will contain fixed coordinates for(i=0;i0 then i is a fixed coordinate } // Add the hyperplane h to the begining of the list of hyperplanes with set of fixed coordinates = s nxt[h]=fst[s]; fst[s]=h; } } // Setup and solve linear programming model // mx is the point whose i-coordinate is the maximum of all a_i's occuring as a fix coordinate in a hyperplane. // d is the number of hyperplanes we omit. // double solvelp(int d,int mx){ int i,k,s,c,x,y,h; double u,v; // We first assign variables v_0,...,v_{2^N-1} , where v_s is an upper bound on the total weight // on a hyperplane with fixed set of coordinates s. vcnt=1<0 then coordinate x_i at least 2 more than any fixed value occuring in any hyperplane if(k>0)y-=k*q[i]; // point is therefore equivalent to one with smaller x_i } if(y0){ // if c=0 then the constraint is vacuous since there are no uncovered points in the hyperplane // The next line "compresses" the constraint by omitting all variables with coefficient 0 for(c=k=0;k0) or =0 (s=0) } } } // Add constraint that v_0=1. The s=0 case above then forces a probability distribution. var[0]=0;val[0]=1; if(GRBaddconstr(model,1,var,val,GRB_EQUAL,1.,NULL))err(1); // Now call Gurobi to perform optimization if(GRBoptimize(model))err(1); if(GRBgetintattr(model,"Status",&s))err(1); if(s!=GRB_OPTIMAL){printf("Not optimal\n");err(0);} // something went wrong // Now read solution into val[] if(GRBgetdblattrarray(model,"X",0,vcnt,val))err(1); if(GRBfreemodel(model))err(1); // don't need model anymore // We will now check that the solution is valid by calculating max weight of hyperplanes for(k=1<val[s])val[s]=v; // update max weight if weight of current hyperplane larger } } // Check if total weight differs significantly from 1 if(val[0]-1>1e-8||1-val[0]>1e-8){printf("Error: Large error in lp\n");err(0);} // Normalize anyway - we now have a probability distribution accurate to almost full double precision accuracy for(i=1;i<(1<=(1<=(1<1+(mx/q[i])%p[i])break; // coord > 1 more than max previous if((a[s]/q[i])%p[i]>(mx/q[i])%p[i])nmx+=q[i]; // increase max } } if(i==N)recurse(s+1,nmx); // a[s] is valid, now recursively generate next one } } main(){ int i; time(&start); // start timer if(GRBloadenv(&env,NULL))err(1); // load gurobi environment if(GRBsetintparam(env,"OutputFlag",0))err(1); // do not print Gurobi diagnostics setup(); printf("Finding configurations with c_a(3)-%fc_a(1)>%f\n\n",S,LM); recurse(1,0); for(i=4;i>=0;i--){ printf("%d / %d configurations with %d missing hyperplanes exceeded threshold\n",lpp[i],lpc[i],i); } time(&end); printf("Time taken %d seconds\n",(int)(end-start)); // print elapsed time err(0); // exit gracefully }