Wolfram Research

Function Repository Resource:

Cos2PiOverFermatPrime

Source Notebook

Closed form of cos(2π/p) where p is a Fermat prime (3, 5, 17, 257, 65537) a la Gauss

Contributed by: Michael Trott

ResourceFunction["Cos2PiOverFermatPrime"][p,"Rules"]

returns a list {cos,rules} where cos represents cos(2π/p) and rules is a list of replacements to be applied to cos. The value p can be one of the five Fermat primes 3, 5, 17, 257, 65537.

ResourceFunction["Cos2PiOverFermatPrime"][p,trig]

returns trig(2π/p) where trig can be any of the trigonometric function Cos,Sin,Tan,Cot,Sec, or Csc.

Details and Options

ResourceFunction["Cos2PiOverFermatPrime"] is a faithful implementation of Gauss’ algorithm discovered on March 29 in 1796.
The original result realized a ruler and compass construction of a regular 17‐gon.
The resulting expressions contain only square roots, no cube roots or higher roots.
The option GeneratedParameters can be used to specify the variable used to express the rules.

Examples

Basic Examples

The classic Gauss result for cos(2π/17):

In[1]:=
ResourceFunction["Cos2PiOverFermatPrime"][17, Cos]
Out[1]=

Using the "Rules" argument shows the recursive nature of the period values:

In[2]:=
ResourceFunction["Cos2PiOverFermatPrime"][17, "Rules"]
Out[2]=

Applying the rules gives again the above expression:

In[3]:=
First[%] //. Last[%]
Out[3]=

The cosine values for the two smallest Fermat primes:

In[4]:=
ResourceFunction["Cos2PiOverFermatPrime"][3, Cos]
Out[4]=
In[5]:=
ResourceFunction["Cos2PiOverFermatPrime"][5, Cos]
Out[5]=

Scope

Cos2PiOverFermatPrime gives results for all the basic trig functions:

In[6]:=
{LeafCount[tan257], ByteCount[tan257]}
Out[6]=
In[7]:=
{N[tan257, 20], N[Tan[2 Pi/257], 20]}
Out[7]=

Options

The default parameter is C:

In[8]:=
ResourceFunction["Cos2PiOverFermatPrime"][17, "Rules"]
Out[8]=

Use subscripts for the period values:

In[9]:=
ResourceFunction["Cos2PiOverFermatPrime"][17, "Rules", GeneratedParameters -> (Subscript[\[Lambda], ##] &)]
Out[9]=

Applications

The case p=257 was manually computed by Richelot in 1832:

In[10]:=
rules257 = ResourceFunction["Cos2PiOverFermatPrime"][257, "Rules"];
Short[rules257, 6]
Out[10]=
In[11]:=
Length[Last[rules257]]
Out[11]=

cos(2π/257):

The expression contains more than 5,100 square roots:

In[12]:=
Count[cos257, Power[_, 1/2 | -1/2], {0, \[Infinity]}]
Out[12]=

Plot the frequency of occurrences of different square roots (mouseover points to see square roots):

In[13]:=
ListLogPlot[Tooltip[{#1, #2}, Column[#3]] & @@@ squareRoots257, PlotRange -> All, Filling -> Axis]
Out[13]=

The network of the period values of cos(2π/257):

In[14]:=
rules257 = ResourceFunction["Cos2PiOverFermatPrime"][257, "Rules"];

Visualize with a graph:

In[15]:=
makeEdges[a_ -> b_, C_] := Tooltip[a -> #, a \[DirectedEdge] b] & /@ Cases[b, _C, {0, \[Infinity]}]
In[16]:=
g257 = Graph[Flatten[makeEdges[#, C] & /@ rules257[[2]]], VertexLabels -> Placed["Name", Tooltip]]
Out[16]=
In[17]:=
Graph3D[g257]
Out[17]=

Find the explicit numerical values of all periods:

In[18]:=
cos17 = ResourceFunction["Cos2PiOverFermatPrime"][17, "Rules"]
Out[18]=
In[19]:=
(Rule @@@ Transpose[{(First /@ Last[cos17]), (Last /@ Last[cos17]) //. Last[cos17]}] // FullSimplify[#, ComplexityFunction -> (1000 Count[#, _Root, {0, \[Infinity]}] \
&)] &) // Column
Out[19]=

Properties and Relations

The function ToRadicals does express cos(2π/257) in radicals, but not in square roots:

In[20]:=
Cos[2 Pi/257] // ToRadicals
Out[20]=

ToRadicals of cos(2π/17) in returns an expression quite similar to Cos2PiOverFermatPrime:

In[21]:=
ToRadicals[Cos[2 Pi/17]]
Out[21]=
In[22]:=
 ResourceFunction["Cos2PiOverFermatPrime"][17, Cos] // Simplify
Out[22]=
In[23]:=
FullSimplify[%% - %]
Out[23]=

Possible Issues

The computation for the Fermat prime 65537 will take about 10 to 15 min on a modern laptop:

In[24]:=
ResourceFunction["Cos2PiOverFermatPrime"][65537, "Rules"]; // Timing
Out[24]=

Neat Examples

The value of cos(2π/65537) was first computed by Johann Gustav Hermes and took him 10 years. The computation are still preserved in the famous “suitcase of Göttingen”:

In[25]:=
rules65537 = ResourceFunction["Cos2PiOverFermatPrime"][65537, "Rules"];

The length of the rule list is p-2:

In[26]:=
Length[rules65537[[2]]]
Out[26]=

To compute the period values, we change the rules to assignments and let the 65535 assignments autoevaluate after numericalization of numbers:

In[27]:=
SetAttributes[c, NHoldAll]
num65537 = Set @@@ N[rules65537[[2]] /. C -> c, 50];

The last value is just cos(2π/65537) :

In[28]:=
{N[num65537[[-1]]/2, 20],
 N[Cos[2 Pi/65537], 20]}
Out[28]=

Plot the distribution of the 65535 period values on a linear and on a logarithmic scale:

In[29]:=
Histogram[N[num65537], {0.1}]
Out[29]=
In[30]:=
Histogram[Abs @ N[num65537], {"Log", 100}, PlotRange -> All]
Out[30]=

Resource History

Related Resources

License Information