Function Repository Resource:

RamanujanC

Source Notebook

Evaluate Ramanujan's sum

Contributed by: Jan Mangaldan

ResourceFunction["RamanujanC"][q,n]

gives Ramanujan's sum cq(n).

Details

Integer mathematical function, suitable for both symbolic and numerical manipulation.
Ramanujan's sum is also known as von Sterneck's function.
Ramanujan's sum is given by , where k ranges over all positive integers coprime and less than or equal to q.
ResourceFunction["RamanujanC"] automatically threads over lists.

Examples

Basic Examples (2) 

Evaluate c10(5):

In[1]:=
ResourceFunction["RamanujanC"][10, 5]
Out[1]=

Plot RamanujanC for different indices:

In[2]:=
DiscretePlot[{ResourceFunction["RamanujanC"][3, n], ResourceFunction["RamanujanC"][7, n], ResourceFunction["RamanujanC"][12, n]}, {n, 50}, Sequence[
 Joined -> True, PlotLegends -> {
   "\!\(\*SubscriptBox[\(c\), \(3\)]\)(n)", "\!\(\*SubscriptBox[\(c\), \(7\)]\)(n)", "\!\(\*SubscriptBox[\(c\), \(12\)]\)(n)"}]]
Out[2]=

Scope (2) 

Show a table of Ramanujan sums:

In[3]:=
TableForm[Array[ResourceFunction["RamanujanC"], {7, 7}], TableHeadings -> {Range[7], Range[7]}]
Out[3]=

RamanujanC threads elementwise over lists:

In[4]:=
ResourceFunction["RamanujanC"][3, {2, 4, 6}]
Out[4]=

Applications (2) 

Verify the Brauer–Rademacher identity:

In[5]:=
With[{n = 42, k = 17}, DivisorSum[n, d |-> d/EulerPhi[d] MoebiusMu[n/d], d |-> CoprimeQ[d, k]] == MoebiusMu[n]/EulerPhi[n] ResourceFunction["RamanujanC"][n, k]]
Out[5]=

Express Cyclotomic[n,x] in terms of RamanujanC and BellY:

In[6]:=
With[{n = 105}, Cyclotomic[n, x] == 1 + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(r = 1\), \(EulerPhi[n]\)]\(
\*FractionBox[
SuperscriptBox[\(x\), \(r\)], \(r!\)] \(
\*UnderoverscriptBox[\(\[Sum]\), \(k = 1\), \(r\)]BellY[r, k, \(-Table[\(\((j - 1)\)!\) \*
InterpretationBox[
TagBox[
FrameBox[
PaneBox[GridBox[{
{
StyleBox[
StyleBox[
AdjustmentBox["\<\"[\[FilledSmallSquare]]\"\>",
BoxBaselineShift->-0.25,
BoxMargins->{{0, 0}, {-1, -1}}], "ResourceFunctionIcon",
FontColor->RGBColor[
                    0.8745098039215686, 0.2784313725490196, 0.03137254901960784]],
ShowStringCharacters->False,
FontFamily->"Source Sans Pro Black",
FontSize->0.65 Inherited,
FontWeight->"Heavy",
PrivateFontOptions->{"OperatorSubstitution"->False}], 
StyleBox[
RowBox[{
StyleBox["\<\"RamanujanC\"\>", "ResourceFunctionLabel",
FontFamily->"Source Sans Pro"], " "}],
ShowAutoStyles->False,
ShowStringCharacters->False,
FontSize->0.9 Inherited,
FontColor->GrayLevel[0.1]]}
},
GridBoxSpacings->{"Columns" -> {{0.25}}}],
Alignment->Left,
BaseStyle->{LineSpacing -> {0, 0}, LineBreakWithin -> False},
BaselinePosition->Baseline,
FrameMargins->{{3, 0}, {0, 0}}],
Background->RGBColor[0.968627, 0.976471, 0.984314],
BaselinePosition->Baseline,
DefaultBaseStyle->{},
FrameMargins->{{0, 0}, {1, 1}},
FrameStyle->RGBColor[0.831373, 0.847059, 0.85098],
RoundingRadius->4],
{"FunctionResourceBox", 
RGBColor[0.8745098039215686, 0.2784313725490196, 0.03137254901960784],
               "\"RamanujanC\""},
TagBoxNote->"FunctionResourceBox"],
ResourceFunction["RamanujanC"],
BoxID -> "RamanujanC",
Selectable->False][n, j], {j, 1, r - k + 1}]\)]\)\)\)]
Out[6]=

Properties and Relations (5) 

RamanujanC[q,1] is the same as MoebiusMu[q]:

In[7]:=
ResourceFunction["RamanujanC"][Range[20], 1] == MoebiusMu[Range[20]]
Out[7]=

RamanujanC[q,q] is the same as EulerPhi[q]:

In[8]:=
ResourceFunction["RamanujanC"][#, #] &[Range[20]] == EulerPhi[Range[20]]
Out[8]=

RamanujanC[q,n] is a multiplicative function with respect to its first argument:

In[9]:=
With[{p = 10, q = 13, n = 81}, ResourceFunction["RamanujanC"][p, n] ResourceFunction["RamanujanC"][
     q, n] == ResourceFunction["RamanujanC"][p q, n] && CoprimeQ[p, q]]
Out[9]=

Verify the definition of RamanujanC in terms of the roots of unity:

In[10]:=
With[{q = 14, n = 8}, ResourceFunction["RamanujanC"][q, n] == \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(j = 1\), \(q\)]\(Boole[
      CoprimeQ[j, q]] 
\*SuperscriptBox[\(E\), 
FractionBox[\(2  \[Pi]\ I\ n\ j\), \(q\)]]\)\) // FullSimplify]
Out[10]=

RamanujanC can be expressed as a Dirichlet convolution:

In[11]:=
With[{q = 14, n = 8}, ResourceFunction["RamanujanC"][q, n] == DirichletConvolve[K Boole[Divisible[n, K]], MoebiusMu[K], K, q]]
Out[11]=

Neat Examples (1) 

Visualize Ramanujan's sum over integer values:

In[12]:=
MatrixPlot[Array[ResourceFunction["RamanujanC"], {100, 100}]]
Out[12]=

Version History

  • 1.0.0 – 08 March 2021

Related Resources

License Information