Wolfram Research

Function Repository Resource:

Excess01Ruler

Source Notebook

Find a near-minimal set of integer marks so that all integers up to a given length are represented as differences

Contributed by: Ed Pegg Jr

ResourceFunction["Excess01Ruler"][length]

finds a set of integers representing all differences up to length using a compact form for the result.

ResourceFunction["Excess01Ruler"][length,"Full"]

finds a set of integers representing all differences up to length.

Details and Options

The "Full" calculation requires significant memory for large length values.
An integer length ruler with marks so that all integer differences up to the length are represented is called a complete ruler.
The excess of a complete ruler with length L and M marks is .
For any positive integer length, a complete ruler with excess 0 or 1 can be made, hence these are called excess-01 rulers.
There are no known complete rulers with an excess of -1.

Examples

Basic Examples

Find the marks for a sparse ruler of length 9:

In[1]:=
ResourceFunction["Excess01Ruler"][9, "Full"]
Out[1]=

Check that all differences are covered:

In[2]:=
Union[Last[#] - First[#] & /@ Subsets[ResourceFunction["Excess01Ruler"][9, "Full"], {2}]]
Out[2]=

Find the marks for a sparse ruler of length 57:

In[3]:=
ResourceFunction["Excess01Ruler"][57, "Full"]
Out[3]=

Check that the ruler is complete (i.e. all differences are covered):

In[4]:=
Complement[
 Range[57], #[[2]] - #[[1]] & /@ Subsets[ResourceFunction["Excess01Ruler"][57, "Full"], {2}]]
Out[4]=

Show the intervals between marks in the full form of a length-396 ruler:

In[5]:=
Differences[ResourceFunction["Excess01Ruler"][396, "Full"]]
Out[5]=

Split the differences:

In[6]:=
Split[%]
Out[6]=

Make a series of lists from the compact form of a length-396 ruler:

In[7]:=
Table[#[[1]], {#[[2]]}] & /@ Transpose[ResourceFunction["Excess01Ruler"][396]]
Out[7]=

Show the compact form:

In[8]:=
ResourceFunction["Excess01Ruler"][396]
Out[8]=

Verify that the compact form from the previous result has length 396:

In[9]:=
Dot @@ %
Out[9]=

Show the full form for a length-396 ruler:

In[10]:=
ResourceFunction["Excess01Ruler"][396, "Full"]
Out[10]=

Scope

Show the marks for the first 51 rulers:

In[11]:=
Table[ResourceFunction["Excess01Ruler"][n, "Full"], {n, 1, 51}]
Out[11]=

Show the excess values for the first 51 rulers:

In[12]:=
Length[#] - Round[Sqrt[3 Last[#] + 9/4]] & /@ %
Out[12]=

Count the number of marks for a length-58 ruler in full form or compact form:

In[13]:=
{Length[ResourceFunction["Excess01Ruler"][58, "Full"]], Total[ResourceFunction["Excess01Ruler"][58][[2]]] + 1}
Out[13]=

The excess of a ruler with length L and M marks is :

In[14]:=
(Total[ResourceFunction["Excess01Ruler"][58][[2]]] + 1) - Round[Sqrt[3 58 + 9/4]]
Out[14]=

An excess-01 ruler has an excess of 0 or 1:

In[15]:=
length = 999;
ruler = ResourceFunction["Excess01Ruler"][length];
marks = Total[Last[ruler]] + 1;
excess = marks - Round[Sqrt[3 length + 9/4]];
Column[{{excess, marks, length}, Grid[ruler, Frame -> All]}, Alignment -> Center]
Out[15]=

A list of some rulers with a single mark less than those generated by this function:

Show the length-999 ruler with one less mark:

In[16]:=
ruler = betterRulers[[208]];
length = Dot @@ ruler;
marks = Total[Last[ruler]] + 1;
excess = marks - Round[Sqrt[3 length + 9/4]];
Column[{{excess, marks, length}, Grid[ruler, Frame -> All]}, Alignment -> Center]
Out[16]=

Show how the Leech upper bound for the number of marks in a complete ruler compares to the number of marks in function-generated rulers:

In[17]:=
ListPlot[Table[
  Sqrt[3.348 n] - (Total[
      Last[ResourceFunction["Excess01Ruler"][n]]] + 1), {n, 214, 2019}]]
Out[17]=

Generate rulers of length n! and plot the number of marks:

In[18]:=
ListLogPlot[
 Table[(Total[Last[ResourceFunction["Excess01Ruler"][n!]]] + 1), {n, 1, 30}]]
Out[18]=

Possible Issues

Show the default shortened form for a length-googol ruler:

In[19]:=
ResourceFunction["Excess01Ruler"][10^100]
Out[19]=

Show the number of marks in a length-googol ruler:

In[20]:=
Total[Last[%]] + 1
Out[20]=

Showing the full form of a googol-length ruler is not recommended.

Neat Examples

Generate reasonable rulers for various integer powers and calculate their excess:

In[21]:=
Text@Grid[Flatten[Table[Transpose[Prepend[
      Table[{base^ToString[n], Total[ResourceFunction["Excess01Ruler"][base^n][[2]]] + 1 - Round[Sqrt[3 base^n + 9/4]]}, {n, 3, 15}], {"length", "excess"}]],
    {base, 2, 11}], 1], Dividers -> {True, {{True, False}}}]
Out[21]=

All rulers to length 213 are minimal. Show a pixel representation of these sparse rulers:

In[22]:=
ArrayPlot[Table[PadRight[ReplacePart[Table[0, {n + 1}],
    ({# + 1} & /@ ResourceFunction["Excess01Ruler"][n, "Full"]) -> 1],
    215], {n, 1, 213}], PixelConstrained -> 2, Frame -> False]
Out[22]=

The maximal length for a given number of marks is usually a Wichmann value:

In[23]:=
WichmannValues = Table[(n^2 - (Mod[n, 6] - 3)^2)/3 + n, {n, 1, 30}]
Out[23]=

Arrange lengths in columns ending in Wichmann values and bold the lengths with excess 1:

In[24]:=
Grid[Append[
  Transpose[
   Table[PadLeft[
     Take[Style[
         If[Length[ResourceFunction["Excess01Ruler"][#, "Full"]] - Round[Sqrt[3 # + 9/4]] == 1, Style[#, Black, Bold, 16], Style[#, Gray, 14]]] & /@ Range[213],
      {WichmannValues[[n]] + 1, WichmannValues[[n + 1]]}], 15, ""], {n, 24 - 1}]], Range[3, 25]], Spacings -> {.2, .2}, Dividers -> {False, -2 -> Blue}]
Out[24]=

Resource History

See Also

AuthorNotes

No sparse ruler is known with an excess less than 0.

This function has not been extensively tested for values past 20 million.

License Information