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, 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 (3) 

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 the above expression once again:

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 (1) 

Cos2PiOverFermatPrime gives results for all the basic trig functions:

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

Options (2) 

The default parameter is C:

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

Use subscripts for the period values:

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

Applications (4) 

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

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

cos(2π/257):

In[13]:=
cos257 = ResourceFunction["Cos2PiOverFermatPrime"][257, Cos];

The expression contains more than 5,100 square roots:

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

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

In[15]:=
squareRoots257 = {#1, Length[#2], Union[ExpandAll[Last /@ #2]]} & @@@ Normal[GroupBy[{N[#, 20], #} & /@ Cases[cos257, Power[_, 1/2 | -1/2], {0, \[Infinity]}], First]];
In[16]:=
ListLogPlot[Tooltip[{#1, #2}, Column[#3]] & @@@ squareRoots257, PlotRange -> All, Filling -> Axis]
Out[16]=

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

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

Visualize with a graph:

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

Find the explicit numerical values of all periods:

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

Properties and Relations (2) 

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

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

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

In[24]:=
ToRadicals[Cos[2 Pi/17]]
Out[24]=
In[25]:=
 ResourceFunction["Cos2PiOverFermatPrime"][17, Cos] // Simplify
Out[25]=
In[26]:=
FullSimplify[%% - %]
Out[26]=

Possible Issues (1) 

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

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

Neat Examples (5) 

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[28]:=
rules65537 = ResourceFunction["Cos2PiOverFermatPrime"][65537, "Rules"];

The length of the rule list is p-2:

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

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

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

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

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

Plot the distribution of the 65,535 period values on a linear and on a logarithmic scale:

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

Version History

  • 1.0.0 – 18 October 2019

Related Resources

License Information