Legendre Symbol Calculator

.legendre-container { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; max-width: 600px; margin: 20px auto; padding: 25px; border: 1px solid #ddd; border-radius: 12px; background-color: #f9f9f9; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } .legendre-container h2 { color: #2c3e50; text-align: center; margin-top: 0; } .input-group { margin-bottom: 20px; } .input-group label { display: block; font-weight: bold; margin-bottom: 8px; color: #34495e; } .input-group input { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 6px; box-sizing: border-box; font-size: 16px; } .calc-button { width: 100%; padding: 15px; background-color: #3498db; color: white; border: none; border-radius: 6px; font-size: 18px; cursor: pointer; transition: background-color 0.3s; } .calc-button:hover { background-color: #2980b9; } .result-area { margin-top: 25px; padding: 15px; border-radius: 6px; background-color: #fff; border-left: 5px solid #3498db; display: none; } .result-value { font-size: 24px; font-weight: bold; color: #2c3e50; text-align: center; } .error-msg { color: #e74c3c; font-size: 14px; margin-top: 5px; display: none; }

Legendre Symbol Calculator

Please enter an odd prime number greater than 2.
function isPrime(n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 === 0 || n % 3 === 0) return false; for (var i = 5; i * i 0n) { if (exp % 2n === 1n) res = (res * base) % m; base = (base * base) % m; exp = exp / 2n; } return res; } function calculateLegendre() { var aInput = document.getElementById("integerA").value; var pInput = document.getElementById("primeP").value; var errorDiv = document.getElementById("primeError"); var resultBox = document.getElementById("resultBox"); var resultText = document.getElementById("legendreResult"); var interpretation = document.getElementById("interpretation"); errorDiv.style.display = "none"; resultBox.style.display = "none"; if (aInput === "" || pInput === "") { alert("Please fill in both fields."); return; } var a = parseInt(aInput); var p = parseInt(pInput); if (p <= 2 || p % 2 === 0 || !isPrime(p)) { errorDiv.style.display = "block"; return; } var result; var aModP = ((a % p) + p) % p; if (aModP === 0) { result = 0; } else { var exponent = (p – 1) / 2; var res = power(aModP, exponent, p); if (res === 1n) { result = 1; } else { result = -1; } } resultText.innerHTML = "(" + a + " / " + p + ") = " + result; var text = ""; if (result === 1) { text = a + " is a quadratic residue modulo " + p; } else if (result === -1) { text = a + " is a quadratic non-residue modulo " + p; } else { text = a + " is a multiple of " + p; } interpretation.innerHTML = text; resultBox.style.display = "block"; }

Understanding the Legendre Symbol

In number theory, the Legendre symbol is a function that indicates whether a given integer a is a quadratic residue modulo an odd prime p. This mathematical tool is fundamental in modular arithmetic and is a precursor to the Jacobi symbol and the Kronecker symbol.

What is a Quadratic Residue?

An integer a is called a quadratic residue modulo p if there exists some integer x such that:

x² ≡ a (mod p)

If no such x exists, and a is not divisible by p, then a is called a quadratic non-residue modulo p.

Mathematical Values of the Legendre Symbol (a/p)

  • (a/p) = 1: If a is a quadratic residue modulo p (and a is not 0 mod p).
  • (a/p) = -1: If a is a quadratic non-residue modulo p.
  • (a/p) = 0: If a is a multiple of p (i.e., a ≡ 0 mod p).

Calculation Method: Euler's Criterion

This calculator utilizes Euler's Criterion to determine the value. The formula states:

(a/p) ≡ a(p-1)/2 (mod p)

This means we raise the integer a to the power of half the prime minus one, then find the remainder when divided by p. If the result is 1, the symbol is 1. If the result is p-1 (which is -1 mod p), the symbol is -1.

Properties of the Legendre Symbol

The Legendre symbol follows several useful algebraic properties:

  1. Completely Multiplicative: (ab/p) = (a/p)(b/p).
  2. Periodicity: If a ≡ b (mod p), then (a/p) = (b/p).
  3. Quadratic Reciprocity: For two distinct odd primes p and q, (p/q)(q/p) = (-1)((p-1)/2)((q-1)/2).

Practical Example

Let's calculate (3 / 7):

  • Identify a = 3 and p = 7.
  • Apply Euler's Criterion: 3(7-1)/2 = 3³ = 27.
  • Find 27 mod 7: 27 = (3 × 7) + 6. So 27 ≡ 6 mod 7.
  • Since 6 ≡ -1 mod 7, the result is -1.
  • Conclusion: 3 is a quadratic non-residue modulo 7 (there is no integer x where x² ≡ 3 mod 7).

Leave a Reply

Your email address will not be published. Required fields are marked *