<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://michaelnielsen.org/polymath/index.php?action=history&amp;feed=atom&amp;title=Matlab_script</id>
	<title>Matlab script - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://michaelnielsen.org/polymath/index.php?action=history&amp;feed=atom&amp;title=Matlab_script"/>
	<link rel="alternate" type="text/html" href="https://michaelnielsen.org/polymath/index.php?title=Matlab_script&amp;action=history"/>
	<updated>2026-05-08T02:07:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://michaelnielsen.org/polymath/index.php?title=Matlab_script&amp;diff=1681&amp;oldid=prev</id>
		<title>Teorth: New page: The script given below, written in Matlab, is intended to carry it out.  An input, DVec, is a list of 27-bit numbers.  Each number represents one case of the forbidden 2*** points.  The ou...</title>
		<link rel="alternate" type="text/html" href="https://michaelnielsen.org/polymath/index.php?title=Matlab_script&amp;diff=1681&amp;oldid=prev"/>
		<updated>2009-06-16T15:44:51Z</updated>

		<summary type="html">&lt;p&gt;New page: The script given below, written in Matlab, is intended to carry it out.  An input, DVec, is a list of 27-bit numbers.  Each number represents one case of the forbidden 2*** points.  The ou...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The script given below, written in Matlab, is intended to carry it out.  An input, DVec, is a list of 27-bit numbers.  Each number represents one case of the forbidden 2*** points.  The output is ParetoCell, which lists the Pareto statistics for each DVec value.  A more compact form of the output is ParetoInd.&lt;br /&gt;
&lt;br /&gt;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 % DATE : 6 June, 2009&lt;br /&gt;
 % AUTHOR : Michael Peake&lt;br /&gt;
 % PROJECT : Polymath1&lt;br /&gt;
 % Lookup table &lt;br /&gt;
 % There is assumed a vector of 27-bit DISALLOWED numbers in DVEC&lt;br /&gt;
 % Its output is PARETOCELL which lists the Pareto statistics &lt;br /&gt;
 % for each DISALLOWED number&lt;br /&gt;
 if ~exist(&amp;#039;eee&amp;#039;);&lt;br /&gt;
   &lt;br /&gt;
   % List of Disallowed 27-bit numbers&lt;br /&gt;
   if ~exist(&amp;#039;DVec&amp;#039;)&lt;br /&gt;
      DVec = 0;&lt;br /&gt;
   end;&lt;br /&gt;
   &lt;br /&gt;
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
   &lt;br /&gt;
   % Find the 230 line-free subsets of [3]^2&lt;br /&gt;
   [a,b,c,d,e,f,g,h,k] = ndgrid(0:1);&lt;br /&gt;
   abcd = [a(:) b(:) c(:) d(:) e(:) f(:) g(:) h(:) k(:)];&lt;br /&gt;
   All512 = abcd;&lt;br /&gt;
   % Delete those with complete lines in them&lt;br /&gt;
   for n=512:-1:1,&lt;br /&gt;
      v=abcd(n,:);&lt;br /&gt;
      if any(all(v([1 2 3;4 5 6;7 8 9;1 4 7;2 5 8;3 6 9;1 5 9;3 5 7]),2)),&lt;br /&gt;
         abcd(n,:)=[];&lt;br /&gt;
      end;&lt;br /&gt;
   end;&lt;br /&gt;
   &lt;br /&gt;
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
   % Some numbers needed repeatedly, so precalculate them&lt;br /&gt;
   TwoEight = 2.^[0:8];&lt;br /&gt;
   Eight = abcd*TwoEight&amp;#039;;&lt;br /&gt;
   TwoFourEight = 512*Eight;&lt;br /&gt;
   % Student Matlab won&amp;#039;t allow 230x230 array, but will allow cell arrays&lt;br /&gt;
   Eights = cell(1,230);&lt;br /&gt;
   % 27-bit numbers built from first layer and third layer&lt;br /&gt;
   for n=1:230,Eights{n}=Eight(n)+512*512*Eight;end;&lt;br /&gt;
   &lt;br /&gt;
   % find symmetry group of each one&lt;br /&gt;
   %for n=1:230,&lt;br /&gt;
   %v=reshape(abcd(n,:),3,3);&lt;br /&gt;
   %w=v&amp;#039;;&lt;br /&gt;
   %x=flipud(v);&lt;br /&gt;
   %y=fliplr(v);&lt;br /&gt;
   %z=flipud(fliplr(v));&lt;br /&gt;
   %a=flipud(w);&lt;br /&gt;
   %b=fliplr(w);&lt;br /&gt;
   %c=flipud(fliplr(w));&lt;br /&gt;
   %e=[v(:) w(:) x(:) y(:) z(:) a(:) b(:) c(:)];&lt;br /&gt;
   %same(n) = sum(all(e==(v(:)*ones(1,8))));&lt;br /&gt;
   %end;&lt;br /&gt;
   &lt;br /&gt;
   % calculate the statistics for each line-free square&lt;br /&gt;
   for n=1:230,&lt;br /&gt;
      v=reshape(abcd(n,:),3,3);&lt;br /&gt;
      Stats2(n,:) = [sum(v([1 3 7 9])) sum(v([2 4 6 8])) v(5)];   &lt;br /&gt;
   end;&lt;br /&gt;
   &lt;br /&gt;
   % Convert the stats to a unique index&lt;br /&gt;
   Stats2Ind = Stats2*[1;9;9*13];&lt;br /&gt;
   % The centre-slice has a different statistic&lt;br /&gt;
   Stats2Shift = Stats2*[9;9*13;9*13*7];&lt;br /&gt;
 &lt;br /&gt;
   % count the restricted patterns&lt;br /&gt;
   for n=1:512,&lt;br /&gt;
      WithinCell{n} = find(all(abcd &amp;lt;= All512(n*ones(1,230),:),2));&lt;br /&gt;
      Within(n)     = length(WithinCell{n});&lt;br /&gt;
      % Sort them so that Stats2Shift is increasing;&lt;br /&gt;
      % will make it easier to ignore repetitions later&lt;br /&gt;
      [a,b] = sort(Stats2Shift(WithinCell{n}));&lt;br /&gt;
      WithinCell{n} = WithinCell{n}(b);&lt;br /&gt;
   end;&lt;br /&gt;
   Total = 0;Count = zeros(1,48);&lt;br /&gt;
   &lt;br /&gt;
   % Compare every Statistics for the cube with every other Statistics, &lt;br /&gt;
   % to see if one dominates the other - to keep track of Pareto maxima&lt;br /&gt;
   Beaters = cell(9,13,7,2);&lt;br /&gt;
   for a=1:9,for b=1:13,for c=1:7,for d=1:2,&lt;br /&gt;
               Beaters{a,b,c,d} = zeros(9,13,7,2);&lt;br /&gt;
               for e=1:9,&lt;br /&gt;
                  for f=1:13,&lt;br /&gt;
                     for g=1:7,&lt;br /&gt;
                        for h=1:2,&lt;br /&gt;
                           if all([a b c d]&amp;gt;=[e f g h]),&lt;br /&gt;
                              Beaters{a,b,c,d}(e,f,g,h)=1;&lt;br /&gt;
                           elseif all([a b c d]&amp;lt;=[e f g h])&lt;br /&gt;
                              Beaters{a,b,c,d}(e,f,g,h)=-1;&lt;br /&gt;
                           end;&lt;br /&gt;
                        end;end;end;end;&lt;br /&gt;
               Beaters{a,b,c,d}(a,b,c,d)=-1;&lt;br /&gt;
            end;end;end;end;&lt;br /&gt;
   &lt;br /&gt;
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
   &lt;br /&gt;
   % For each Layer1 and Layer3, precalculate which cells &lt;br /&gt;
   % are forbidden in Layer2&lt;br /&gt;
   for a=1:230,  &lt;br /&gt;
      % Convert square of 01s to 9-bit number&lt;br /&gt;
      Layer1 = abcd(a,:);&lt;br /&gt;
      Num1 = TwoEight*Layer1&amp;#039;;&lt;br /&gt;
      % Some bits are needed for sloping lines&lt;br /&gt;
      X123 = bitand(Num1,7)*8;&lt;br /&gt;
      X789 = bitand(Num1,8*56)/8;&lt;br /&gt;
      X147 = bitand(Num1,73)*2;&lt;br /&gt;
      X369 = bitand(Num1,4*73)/2;&lt;br /&gt;
      &lt;br /&gt;
      for b=1:230,&lt;br /&gt;
         &lt;br /&gt;
         Layer3 = abcd(b,:);&lt;br /&gt;
         Num2 = TwoEight*Layer3&amp;#039;;&lt;br /&gt;
         &lt;br /&gt;
         % Check for vertical lines&lt;br /&gt;
         Out = bitand(Num1,Num2);         &lt;br /&gt;
         &lt;br /&gt;
         % Set up for sloping lines&lt;br /&gt;
         Y123 = bitand(Num2,7);Y123=Y123*8;&lt;br /&gt;
         Y789 = bitand(Num2,448);Y789=Y789/8;&lt;br /&gt;
         Y147 = bitand(Num2,73);Y147=Y147*2;&lt;br /&gt;
         Y369 = bitand(Num2,292);Y369=Y369/2;&lt;br /&gt;
         &lt;br /&gt;
         % Check for sloping lines&lt;br /&gt;
         Out = bitor(Out,bitand(X123,Y789));&lt;br /&gt;
         Out = bitor(Out,bitand(X789,Y123));&lt;br /&gt;
         Out = bitor(Out,bitand(X147,Y369));&lt;br /&gt;
         Out = bitor(Out,bitand(X369,Y147));&lt;br /&gt;
         &lt;br /&gt;
         % Check for major diagonals, and bit 5&lt;br /&gt;
         v = 16*any(Layer1([1 3 7 9]) &amp;amp; Layer3([9 7 3 1]));&lt;br /&gt;
         Out = bitor(Out,v);&lt;br /&gt;
         &lt;br /&gt;
         NotOut = bitcmp(Out,9);&lt;br /&gt;
         % Index&lt;br /&gt;
         In=NotOut+1;&lt;br /&gt;
         &lt;br /&gt;
         % 9-bit number shows which bits are allowed&lt;br /&gt;
         Allowed{a}(b) = In;&lt;br /&gt;
         &lt;br /&gt;
      end;end;%for a,for b&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   %%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
   eee = &amp;#039;done&amp;#039;;&lt;br /&gt;
 end;% if ~exist(&amp;#039;eee&amp;#039;);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 &lt;br /&gt;
 % Set up enough memory to keep track of Pareto sets&lt;br /&gt;
 % These are the pareto-maxima of the second slice,&lt;br /&gt;
 % will be subject to the DISALLOWED restriction &lt;br /&gt;
 &lt;br /&gt;
 % Count of Disallowed 27-bit numbers&lt;br /&gt;
 nd = length(DVec);&lt;br /&gt;
 &lt;br /&gt;
 % List of Pareto-max Layer2s&lt;br /&gt;
 ParetoInd = cell(1,nd);&lt;br /&gt;
 &lt;br /&gt;
 % Provide enough space&lt;br /&gt;
 [ParetoInd{:}] = deal(ones(1,230));&lt;br /&gt;
 &lt;br /&gt;
 % Initialize&lt;br /&gt;
 [ParetoInd{:}] = deal(ones(1));&lt;br /&gt;
 NPareto = ones(1,nd);&lt;br /&gt;
 &lt;br /&gt;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 % DATE : 6 June, 2009&lt;br /&gt;
 % AUTHOR : Michael Peake&lt;br /&gt;
 % PROJECT : Polymath1&lt;br /&gt;
 % Lookup table &lt;br /&gt;
 % There is assumed a vector of 27-bit DISALLOWED numbers in DVEC&lt;br /&gt;
 % Its output is PARETOCELL which lists the Pareto statistics &lt;br /&gt;
 % for each DISALLOWED number&lt;br /&gt;
 for a=1:230,&lt;br /&gt;
   &lt;br /&gt;
   InFirst = Allowed{a};&lt;br /&gt;
   NN0Vec = Eights{a};&lt;br /&gt;
   &lt;br /&gt;
   for b=1:230,   &lt;br /&gt;
      &lt;br /&gt;
      % Statistics of Layer1 and Layer3 put together&lt;br /&gt;
      Stats0Ind = Stats2Ind(a)+Stats2Ind(b)+1;&lt;br /&gt;
      &lt;br /&gt;
      % List of possible Layer2s&lt;br /&gt;
      Rvec0 = WithinCell{InFirst(b)};&lt;br /&gt;
      &lt;br /&gt;
      % Stats of all three Layers put together&lt;br /&gt;
      Stats3Ind0 = Stats0Ind+Stats2Shift(Rvec0);&lt;br /&gt;
      &lt;br /&gt;
      % 27-bit number of Layer1 and Layer3&lt;br /&gt;
      NN0 = NN0Vec(b);&lt;br /&gt;
      &lt;br /&gt;
      % Pick which Disallowed are dead already&lt;br /&gt;
      DOk = find(~bitand( NN0, DVec));&lt;br /&gt;
      &lt;br /&gt;
      % 27-bit number including various possible Layer2s&lt;br /&gt;
      NN = NN0+TwoFourEight(Rvec0);&lt;br /&gt;
      &lt;br /&gt;
      % Only the sequel changes for different DISALLOWEDS&lt;br /&gt;
      for di = DOk&lt;br /&gt;
         &lt;br /&gt;
         % Pick a 27-bit number of DISALLOWED bits&lt;br /&gt;
         Disallowed = DVec(di);&lt;br /&gt;
         &lt;br /&gt;
         % Which Layer2s give a cube entirely within allowed bits&lt;br /&gt;
         NOk = find(~bitand(NN,Disallowed));&lt;br /&gt;
         &lt;br /&gt;
         % Don&amp;#039;t bother if none apply&lt;br /&gt;
         if length(NOk)&lt;br /&gt;
            &lt;br /&gt;
            Stats3Ind = Stats3Ind0(NOk);&lt;br /&gt;
            &lt;br /&gt;
            % Remove repeats (values are already sorted)&lt;br /&gt;
            for c=[1; 1+find(diff(Stats3Ind))]&amp;#039;,&lt;br /&gt;
               &lt;br /&gt;
               NewStat = Stats3Ind(c);&lt;br /&gt;
               % To compare this new Statistic with current Pareto set, look up the &lt;br /&gt;
               % pre-calculated comparisons&lt;br /&gt;
               Mat = Beaters{NewStat};&lt;br /&gt;
               % Fetch the list of Pareto sets, to prevent repeated indexing&lt;br /&gt;
               PInd = ParetoInd{di};&lt;br /&gt;
               Comparison = Mat(PInd);&lt;br /&gt;
               &lt;br /&gt;
               if (all(Comparison&amp;gt;=0)),&lt;br /&gt;
                  % Then this is a new Pareto set&lt;br /&gt;
                  &lt;br /&gt;
                  % remove the dominated Pareto sets&lt;br /&gt;
                  Old = find(Comparison);&lt;br /&gt;
                  PInd(Old) = [];&lt;br /&gt;
                  % include the new Pareto set&lt;br /&gt;
                  PInd(end+1) = NewStat;&lt;br /&gt;
                  NPareto(di) = length(PInd);&lt;br /&gt;
                  % Put the updated Pareto list back in the cell array&lt;br /&gt;
                  ParetoInd{di} = PInd;&lt;br /&gt;
               end;%if Comparison&lt;br /&gt;
            end;%for c[1; 1+find(diff(Stats3Ind))]&lt;br /&gt;
         end;%if length(NOk)&lt;br /&gt;
      end;%for di&lt;br /&gt;
      %disp(num2str([floor(toc) a b Total Count(find(Count))]));&lt;br /&gt;
   end;%for b&lt;br /&gt;
   %disp(num2str([a NPareto]));&lt;br /&gt;
 end;% for a&lt;br /&gt;
 &lt;br /&gt;
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 &lt;br /&gt;
 % Convert from Pareto indexes to lists of Pareto statistics&lt;br /&gt;
 &lt;br /&gt;
 for di = 1:nd,&lt;br /&gt;
   [a,b,c,d] = ind2sub([9 13 7 2],ParetoInd{di}(1:NPareto(di)));&lt;br /&gt;
   ParetoCell{di} = [a;b;c;d]&amp;#039;-1;&lt;br /&gt;
 end;&lt;/div&gt;</summary>
		<author><name>Teorth</name></author>
	</entry>
</feed>