Ramanujan Sum

Return the exact integer c_q(k), the sum of exp(2πiak/q) over residues a coprime to q, using the Möbius–totient formula and q≤10¹².

Description

Ramanujan sums add roots of unity over residues coprime to a modulus.

Ramanujan sums add roots of unity over residues coprime to a modulus. Although the defining expression uses complex numbers, the sum is an integer computable from arithmetic functions.1

The tool returns value. The indexing and output conventions below determine how to read these values.

When to use Ramanujan Sum

Use this for the following task: Return the exact integer c_q(k), the sum of exp(2πiak/q) over residues a coprime to q, using the Möbius–totient formula and q≤10¹². Use the input and output conventions below to reproduce the intended mathematical quantity.

How to use Ramanujan Sum and understand its results

  1. Choose the required indexes, integers or sequence entries. Preserve decimal-string encodings where the field table specifies strings.
  2. Enter modulus, frequency according to the field table, then run the tool.
  3. Read value. Preserve exact decimal strings and the stated indexing or coefficient order.
  4. Keep exact decimal strings for subsequent integer arithmetic; distinguish them from any explicitly approximate numeric result.
Input fieldMeaningValue type and boundsRequirement
modulusPositive modulus q (trial-division resource limit 10^12)integer; minimum 1; maximum 1000000000000Required
frequencySigned integer frequency kstring (integer/arbitrary); maximum text length 200; pattern ^-?(0|[1-9][0-9]*)$Required

Read the signed frequency as BigInt, compute the gcd, factor the reduced modulus and return zero if it has a repeated prime factor. Otherwise apply the Möbius sign and totient ratio.

c_q(k)=μ(q/gcd(q,k))×φ(q)/φ(q/gcd(q,k))

The symbols and boundary conditions refer to the supplied fields and the implementation described above.

Output fieldMeaningValue type
valueExact Ramanujan sumstring (integer/arbitrary)
json
{
  "input": {
    "modulus": 12,
    "frequency": "4"
  },
  "output": {
    "value": "-2"
  }
}

Limitations and assumptions

The modulus is positive and at most 10¹². Signed frequencies are supported, but no complex terms or residue list is returned.

Use the declared integer bounds and string formats. Large exact outputs remain decimal strings; numerical approximations use ordinary floating-point arithmetic. A rejected input is different from a valid zero count or false membership flag.

Alternative or Complementary methods

Choose Möbius Inversion of Divisor Sums when you need its operation: Recover f(1)…f(N) from F(n)=Σ(d|n)f(d) by exact triangular divisor-sum inversion; prefixes start at one and are capped at 1,000 entries. Choose Liouville Lambda Function for the complementary operation: Return λ(n)=(−1)^Ω(n), counting prime factors with multiplicity and using λ(1)=1; trial division is limited to n≤10¹².

Background reference: Digital Library of Mathematical Functions, §27.10.

References

  1. Digital Library of Mathematical Functions, §27.10 — National Institute of Standards and Technology

Similar or alternative tools

  • Möbius Inversion of Divisor Sums

    Recover f(1)…f(N) from F(n)=Σ(d|n)f(d) by exact triangular divisor-sum inversion; prefixes start at one and are capped at 1,000 entries.

  • Liouville Lambda Function

    Return λ(n)=(−1)^Ω(n), counting prime factors with multiplicity and using λ(1)=1; trial division is limited to n≤10¹².

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies