You are looking at the HTML representation of the XML format.
HTML is good for debugging, but is unsuitable for application use.
Specify the format parameter to change the output format.
To see the non HTML representation of the XML format, set format=xml.
See the complete documentation, or API help for more information.
<?xml version="1.0"?>
<api>
  <query-continue>
    <allpages gapcontinue="Riemann-Siegel_formula" />
  </query-continue>
  <query>
    <pages>
      <page pageid="319" ns="0" title="Refined greedy computation of multiplicative sequences">
        <revisions>
          <rev contentformat="text/x-wiki" contentmodel="wikitext" xml:space="preserve">[http://michaelnielsen.org/polymath1/index.php?title=Experimental_results Back to the main experimental results page].

Here is the source of a C++ program for investigating refined greedy algorithms in the case of completely-multiplicative sequences.

The freedom lies in choosing the values at prime indices. Many methods can be devised but only a few are implemented for the moment, feel free to add many more (please indicate what you've added or modified).  The code is commented and hopefully fairly straightforward (it probably could be optimized here and there, but has been carefully checked and seems correct).  

The input file must be in the format of a sequence separated by spaces like + - + (with a space after the last sign, no carriage returns). These indicate the values at the first primes: &lt;math&gt;x_2&lt;/math&gt;, &lt;math&gt;x_3&lt;/math&gt;, &lt;math&gt;x_5&lt;/math&gt;...  In fact it is also possible not to specify any one value before the end by putting a 0. 

There are three output files: the first one will contain the sequence found, the second may contain information on the choices made for each undetermined prime (I've commented it out for now), and the third contains in columns: n, D(n), partial sum of sequence up to n, partial sum of 2-HAP up to n, ... 11-HAP up to n (you can add more if so you wish).  

Finally the constant M is the length of the sequence to be computed.  
 

&lt;pre&gt;
/*----------------------------------------------------------
author: Thomas Sauvaget
licence: public domain.
files: just this one.
------------------------------------------------------------
modification record: 
13-jan-2010: written from scratch. Really basic code...
14-jan-2010: implemented various methods to choose values 
             at prime indices.
----------------------------------------------------------*/


//---------------------------------------------------------
//-- libraries &amp; preprocessor
//---------------------------------------------------------
#include &lt;iostream&gt; //for imput-output with terminal
#include &lt;cmath&gt;    //small math library
#include &lt;algorithm&gt; //useful for permutations and the likes
#include &lt;vector&gt;
#include &lt;fstream&gt; //for imput-output with files
#include &lt;iomanip&gt; //for precision control when outputing
#include &lt;stdlib.h&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
//#include &lt;assert&gt; //for end of file command


//---------------------------------------------------------
//-- namespace (standard)
//---------------------------------------------------------
using namespace std;


//---------------------------------------------------------
//-- global variables
//--------------------------------------------------------- 


int const M=3000;


int tab[M], primes[M], prtab[M], glopartsum[M];
char filenameIN[50], filenameOUT[50], filenameOUTT[50], filenameOUTTT[50];
ofstream myfileOUT;//sequence
ofstream myfileOUTT;//other data
ofstream myfileOUTTT;//yet other data
ifstream myfileIN;


//---------------------------------------------------------
//-- useful handmade functions 
//---------------------------------------------------------

//---------
//getintval 
//converts string containing a single integer to int
//---------
int getintval(string strconv){
  int intret;

  intret=atoi(strconv.c_str());

  return(intret);
}

//---------
//mypow
//integer power: a^b
//---------
int mypow(int a, int b){
  int i, ans=1;
  for(i=1;i&lt;=b;i++){
    ans*=a;
  }
  if(b==0){
    return 1;
  }
  else{
    return ans;
  }
}


//---------
//primfact
//compute prime factors and store
//returns 2 iff n is prime
//---------
int primfact(int n){

  int a, b, c, d, ncurr;
  for(a=0;a&lt;M;a++){
    prtab[a]=0;
  }
  ncurr=n;
  for(b=0;b&lt;n;b++){//surely the n-th prime is greater than n already
    while(primes[b]!=0 &amp;&amp; ncurr&gt;1 &amp;&amp; (ncurr%primes[b])==0){
      prtab[b]+=1;
      ncurr/=primes[b];
    }

    if(primes[b]==0){
      //exit
      b+=M;
    }
  }
  d=0;
  for(c=0;c&lt;M;c++){
    if(prtab[c]!=0){
      d+=prtab[c];
    }
  }
  if(d==1){
    //cout&lt;&lt;&quot;   &quot;&lt;&lt;n&lt;&lt;&quot;  is prime&quot;&lt;&lt;endl;
    return 2;
  }
  if(d!=1){
    //cout&lt;&lt;&quot;   &quot;&lt;&lt;n&lt;&lt;&quot;  is composite&quot;&lt;&lt;endl;
    return 0;
  }
}



//---------
//disc
//computes discrepancy of sequence of +/-1 contained in tabb 
//over all HAPs up to len
//store signed partial sums up to len: 
//  glopartsum[0]=0, glopartsum[1]=sum of seq, glopartsum[2]=sum of 2-HAP...
//---------
int disc(int tabb[M], int len){

  int n, d, i;
  int signsum;
  int absum;
  int r;
  int beflocdisc;
  int aflocdisc;

  beflocdisc=0;
  aflocdisc=0;

  for(n=2;n&lt;=len;n++){
    for(d=1;d&lt;n;d++){
      signsum=0;
      absum=0;
      glopartsum[d]=0;
      r=int(floor(n/d));        
      for(i=1;i&lt;=r;i++){
	signsum+=tabb[d*i-1];
      }
      glopartsum[d]=signsum;
      absum=abs(signsum);
      aflocdisc=max(beflocdisc,absum);
      beflocdisc=aflocdisc;
    }
  }
  return aflocdisc;
}


//---------
//lplain
//just adds the entries of tabb
//---------
int lplain(int tabb[M], int len){
  int norm, a;
  norm=0;
  for(a=0;a&lt;len;a++){
    norm+=tabb[a];
  }
  return norm;
}


//---------
//l1norm
//---------
int l1norm(int tabb[M], int len){
  int a, norm;
  norm=0;
  for(a=0;a&lt;len;a++){
    norm+=abs(tabb[a]);
  }
  return norm;
}


//---------
//l2norm
//---------
double l2norm(int tabb[M], int len){
  int a, snorm;
  double norm;
  snorm=0; norm=0.0;
  for(a=0;a&lt;len;a++){
    snorm+=(tabb[a]*tabb[a]);
  }
  norm=sqrt(snorm);
  return norm;
}


//---------
//lharmw
//harmonic weighting
//---------
double lharmw(int tabb[M], int len){
  int a;
  double norm;
  norm=0;
  for(a=0;a&lt;len;a++){
    norm+=tabb[a]/(a+1);
  }
  return norm;
}


//----------------------------------------------------------
//-- main:
//
//we compute a multiplicative sequence and its discrepancy by 
//specifying its values at first p primes
//----------------------------------------------------------
int main(int argc, char *argv[]){

  int i, k, d, u, v, w, j, c, t, imax=0, maxlength, currprime, iprec;
  int datab[M];
  int mycontinue, g, loclen, h;
  double nmplus, nmminus;
  string line, buff;
  string myplus (&quot;+&quot;);
  string myminus (&quot;-&quot;);
  string myzero (&quot;0&quot;);

  //-- textlike user interface
  cout&lt;&lt;endl;
  cout&lt;&lt;&quot; give input SEQUENCE filename:&quot;&lt;&lt;endl;
  cin&gt;&gt;filenameIN;
  cout&lt;&lt;endl;


  cout&lt;&lt;endl;
  cout&lt;&lt;&quot; give output LONG MULT SEQUENCE filename:&quot;&lt;&lt;endl;
  cin&gt;&gt;filenameOUT;
  cout&lt;&lt;endl;


  cout&lt;&lt;endl;
  cout&lt;&lt;&quot; give output CHOICE filename:&quot;&lt;&lt;endl;
  cin&gt;&gt;filenameOUTT;
  cout&lt;&lt;endl;


  cout&lt;&lt;endl;
  cout&lt;&lt;&quot; give output DISC &amp; PARTSUM filename: &quot;&lt;&lt;endl;
  cin&gt;&gt;filenameOUTTT;
  cout&lt;&lt;endl;

  //-- file creation 
  myfileOUT.open(filenameOUT,ios::out);
  myfileOUT.close();

  myfileOUTT.open(filenameOUTT,ios::out);
  myfileOUTT.close();  
  
  myfileOUTTT.open(filenameOUTTT,ios::out);
  myfileOUTTT.close();


  //fill tables with zeros
  for(i=0;i&lt;M;i++){
    tab[i];
    datab[i]=0;
    primes[i]=0;
    prtab[i]=0;
  }

  
  //construct and store primes up to M
  //primes[a] = (a+1)-th prime
  iprec=2;
  for(i=2;i&lt;=M;i++){
    k=0;
    for(j=1;j&lt;=i;j++){
      if( (i%j)==0){
	k++;
      }
    }
    if(k==2){
      primes[iprec-2]=i;
      iprec+=1;
    }
  }


  //-- read the choices of values at first few primes
  myfileIN.open(filenameIN,ios::in);

  if(myfileIN.is_open()){
    
    i=0;
    getline(myfileIN,line);
    stringstream stsm(line);
    while(stsm&gt;&gt;buff){
      currprime=primes[i];
      if(buff.compare(myplus)==0){
	datab[currprime-1]=1;
      }
      if(buff.compare(myminus)==0){
	datab[currprime-1]=-1;
      }
      if(buff.compare(myzero)==0){
	datab[currprime-1]=0;
      }
      if( datab[currprime-1] !=1 &amp;&amp; datab[currprime-1] !=-1 &amp;&amp; datab[currprime-1]!=0){
      cout&lt;&lt;&quot;problem: element number &quot;&lt;&lt;i+1&lt;&lt;&quot; is neither + nor - nor 0.&quot;&lt;&lt;endl;
	abort();
      }
      i+=1;
    }
    imax=i;
    cout&lt;&lt;&quot; this initial sequence contains &quot;&lt;&lt;imax&lt;&lt;&quot; elements.&quot;&lt;&lt;endl;
    cout&lt;&lt;endl;

  }
  else{
    cout&lt;&lt;&quot;there is no file with this very name&quot;&lt;&lt;endl;
    cout&lt;&lt;&quot; (don't forget extension like .txt or .dat in particular)&quot;&lt;&lt;endl;
    abort();
  }
  myfileIN.close();



  //-- main processing:  
  //fill the rest of the sequence multiplicatively
  //and according to chosen method

  //convention: datab[i]=x_{i+1}
  //and first index is always associated to +
  datab[0]=1;

  mycontinue=0;

  while(mycontinue==0){

 
  
    for(u=2;u&lt;M;u++){
            
      if(datab[u-1]==0){	
	
	k=0;
	k=primfact(u);
	
	
	//if prime: there's freedom, choose one method to fill it
	if(k==2){

	  //choice 1:  silly uniform -1
	  //datab[u-1]=-1;


	  //choice 2: take into account of partial sums
	  loclen=u;

	  cout&lt;&lt;&quot;  adressing &quot;&lt;&lt;loclen&lt;&lt;endl;
	  
	  //values are known below loclen, not at prime loclen, 
	  //and from loclen+1 to loclen+h. we then choose loclen 
	  //(lots of flexibility)


	  //compute h 
	  h=1;
	  for(v=loclen+1;v&lt;M;v++){
	    if(datab[v]==0){
	      h=v-loclen;
	      v+=M;
	    }
	  }
	  cout&lt;&lt;&quot; values after are known up to &quot;&lt;&lt;loclen+h&lt;&lt;endl;
	  

	  
	  //now compute the effect of imposing datab[u-1]=+1 
	  //would have on partial sums up to loclen+h-1
          //you can change lplain to l2norm or whatever other idea
	  datab[u-1]=+1;
	  c=disc(datab,loclen+h-1);	    
	  nmplus=lplain(datab,loclen+h-1);

	  //compute the same with -1 instead
	  datab[u-1]=-1;
	  c=disc(datab,loclen+h-1);
	  nmminus=lplain(datab,loclen+h-1);
	  

	  //now choose
	  if(abs(nmplus)&gt;abs(nmminus)){
	    datab[u-1]=-1;
	  }
	  else{
	    datab[u-1]=+1;
	  }
	  cout&lt;&lt;&quot;  nmplus=&quot;&lt;&lt;nmplus&lt;&lt;&quot;, nmminus=&quot;&lt;&lt;nmminus&lt;&lt;endl;

	  /*------temporarily removed, could be useful to monitor	    
	  //record those numbers for further analysis
	  myfileOUTT.open(filenameOUTT,ios::app);
	  myfileOUTT&lt;&lt;u&lt;&lt;&quot;\t&quot;&lt;&lt;nmplus&lt;&lt;&quot;\t&quot;&lt;&lt;nmminus&lt;&lt;endl;
	  myfileOUTT.close();
	  ------------------------*/

	  //choice 3:
	  //more ideas to be added...



	  //in any case:  give info
	  cout&lt;&lt;&quot;    imposing: x_&quot;&lt;&lt;u&lt;&lt;&quot;=&quot;&lt;&lt;datab[u-1]&lt;&lt;endl;


          //------------ in theory there's nothing to change beyond this point, except
          //             possibily the number of HAP's partial sums printed in the third file


	}
	else{//if composite then try to compute it multiplicatively
	  
	   
	  //loop on prime factors of u to see what is known so far
	  
	  w=1;
	  for(j=0;j&lt;M;j++){
	    
	    if(prtab[j]!=0 &amp;&amp; datab[ primes[j]-1 ]!=0){
		//then this x_j is known
	      w*=1;
	    }
	    
	    if(prtab[j]!=0 &amp;&amp; datab[ primes[j]-1 ]==0){
	      //then this x_j not known, enough to discard
	      w*=0;
	    }
	  }
	  
	  
	  //if all x_j are known then compute x_u
	  if(w==1){
	    datab[u-1]=1;
	    for(j=0;j&lt;M;j++){
	      if(prtab[j]!=0){
		datab[u-1]*=mypow(datab[ primes[j]-1 ],prtab[j]);
	      }
	    }
	    cout&lt;&lt;&quot;      just computed x_&quot;&lt;&lt;u&lt;&lt;&quot;=&quot;&lt;&lt;datab[u-1]&lt;&lt;endl;    
	  }
	  else{
	    //cout&lt;&lt;&quot; cannot yet compute x_&quot;&lt;&lt;u&lt;&lt;endl;
	    //cout&lt;&lt;endl;
	  }
	  
	}//end of mult comp attempt
      }//end of this u
      else{
	//cout&lt;&lt;&quot; already known&quot;&lt;&lt;endl;
      }
    }//end of u loop
    
    //now see whether we should go on
    mycontinue=1;
    for(c=0;c&lt;M-1;c++){
      if(datab[c]!=0){
	mycontinue*=1;
      }
      else{
	mycontinue*=0;
      }
    }
    
  }//end of mycontinue


  cout&lt;&lt;&quot; ---now out, computing partial sums&quot;&lt;&lt;endl;

  myfileOUT.open(filenameOUT,ios::app);
  myfileOUTTT.open(filenameOUTTT,ios::app);
  for(u=0;u&lt;M;u++){

    if(u%50==0){
      cout&lt;&lt;&quot;  computed &quot;&lt;&lt;u&lt;&lt;&quot; data points&quot;&lt;&lt;endl;
    }

    //first output discrepancy and partial sums up to length u, and 11-th HAP
    k=disc(datab,u);
    if(u&gt;0){
      myfileOUTTT&lt;&lt;u&lt;&lt;&quot;\t&quot;&lt;&lt;k&lt;&lt;&quot;\t&quot;;
      for(d=1;d&lt;u;d++){
	if(d&lt;=11){
	  myfileOUTTT&lt;&lt;glopartsum[d]&lt;&lt;&quot;\t&quot;;
	}
      }
      myfileOUTTT&lt;&lt;&quot;\n&quot;;
    }

    //now output sequence value
    if(datab[u]==1){
      myfileOUT&lt;&lt;&quot;+ &quot;;
    }
    if(datab[u]==-1){
      myfileOUT&lt;&lt;&quot;- &quot;;
    }
  }
  myfileOUT.close();
  myfileOUTTT.close();

  cout&lt;&lt;&quot; discrepancy=&quot;&lt;&lt;disc(datab,M)&lt;&lt;endl;

  //exit normally
  return 0;	        
}
&lt;/pre&gt;</rev>
        </revisions>
      </page>
      <page pageid="374" ns="0" title="Representation of the diagonal">
        <revisions>
          <rev contentformat="text/x-wiki" contentmodel="wikitext" xml:space="preserve">The following conjecture, if true, would imply the Erdos discrepancy conjecture.

----

For all &lt;math&gt;C &gt; 0&lt;/math&gt; there exists a diagonal matrix with trace at least &lt;math&gt;C&lt;/math&gt; that can be expressed as &lt;math&gt;\sum_i \lambda_i P_i \otimes Q_i&lt;/math&gt;, where &lt;math&gt;\sum_i | \lambda_i | \leq 1&lt;/math&gt; and each &lt;math&gt;P_i&lt;/math&gt; and &lt;math&gt;Q_i&lt;/math&gt; is the characteristic function of a HAP.

----

== Proof of implication ==
Suppose &lt;math&gt;D&lt;/math&gt; is a diagonal matrix with entries &lt;math&gt;b_j&lt;/math&gt; on the diagonal, with &lt;math&gt;\sum_j b_j&lt;/math&gt; unbounded, and &lt;math&gt;D = \sum_i \lambda_i P_i \otimes Q_i&lt;/math&gt; where &lt;math&gt;\sum_i | \lambda_i | \leq 1&lt;/math&gt; and the &lt;math&gt;P_i&lt;/math&gt; and &lt;math&gt;Q_i&lt;/math&gt; are HAPs. Suppose &lt;math&gt;x&lt;/math&gt; is a &lt;math&gt;\pm 1&lt;/math&gt; sequence with finite discrepancy &lt;math&gt;C&lt;/math&gt;. Then we can write &lt;math&gt;| \langle x, Dx \rangle |&lt;/math&gt; in two ways. On the one hand, &lt;math&gt;| \langle x, Dx \rangle | = | \sum_j b_j x_j^2 | = | \sum_j b_j |&lt;/math&gt;, which is unbounded; on the other hand, &lt;math&gt;| \langle x, Dx \rangle | = | \langle x, \sum_i \lambda_i (P_i \otimes Q_i) x \rangle | = | \sum_i \lambda_i \langle x, P_i \rangle \langle x, Q_i \rangle | \leq \sum_i | \lambda_i | | \langle x, P_i \rangle | | \langle x, Q_i \rangle | \leq C^2&lt;/math&gt;, a contradiction.

== Remarks ==

Moses pointed out [http://gowers.wordpress.com/2010/03/23/edp13-quick-summary/#comment-6971 here] that we do not actually need to produce a ''diagonal'' matrix &lt;math&gt;D&lt;/math&gt; with unbounded trace. It is enough to produce a matrix &lt;math&gt;D&lt;/math&gt; such that &lt;math&gt;\sum_i d_{ii} - \sum_{i \neq j} | d_{ij} |&lt;/math&gt; is unbounded.


[[Roth's Theorem concerning discrepancy on Arithmetic Progression]] contains a representation-of-diagonal proof in detail.

[[Obtaining the correct bound in Roth's discrepancy theorem|This page]] contains the LaTeX source code for a write-up of a representation-of-diagonal proof that gives the correct bound.

== Possible proof strategies ==

== Heuristic arguments ==

== Numerical results ==
Moses has published some experimental data [http://webspace.princeton.edu/users/moses/EDP/try-lp/ here]. See [http://gowers.wordpress.com/2010/03/07/edp11-the-search-continues/#comment-6668 this comment] (and below it) for an explanation.</rev>
        </revisions>
      </page>
    </pages>
  </query>
</api>