Kronecker symbols
This commit is contained in:
parent
6ea5c7b08a
commit
cb5954df40
@ -182,5 +182,20 @@ namespace MPIR.Tests.HugeIntTests
|
||||
Assert.AreEqual(-1, HugeInt.Legendre(a, p));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Kronecker()
|
||||
{
|
||||
using (var a = new HugeInt("9288562863495827364985273645298367452"))
|
||||
using (var b = new HugeInt("29927402397991286489627837734179186385188296382227"))
|
||||
{
|
||||
Assert.AreEqual(-1, HugeInt.Kronecker(a, b));
|
||||
Assert.AreEqual(0, HugeInt.Kronecker(a, 2));
|
||||
Assert.AreEqual(-1, HugeInt.Kronecker(b, 2));
|
||||
Assert.AreEqual(-1, HugeInt.Kronecker(2, b));
|
||||
Assert.AreEqual(-1, HugeInt.Kronecker(b, 2UL));
|
||||
Assert.AreEqual(-1, HugeInt.Kronecker(2UL, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2139,6 +2139,61 @@ namespace MPIR
|
||||
/// <returns>The Legendre symbol (-1, 0, or 1). Return is undefined unless <paramref name="b"/> is an odd prime.</returns>
|
||||
static int Legendre(HugeInt^ a, HugeInt^ b) { return mpz_legendre(a->_value, b->_value); }
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Jacobi symbol (<paramref name="a"/>/<paramref name="b"/>) with the Kronecker extension
|
||||
/// (<paramref name="a"/>/2) = (2/<paramref name="a"/>) when a odd, or (<paramref name="a"/>/2) = 0 when a even.
|
||||
/// <para>When <paramref name="b"/> is odd the Jacobi symbol and Kronecker symbol are identical, so the various Kronecker overloads
|
||||
/// can be used for mixed precision Jacobi symbols too.
|
||||
/// </para></summary>
|
||||
/// <param name="a">First source value for the Kronecker symbol</param>
|
||||
/// <param name="b">Second source value for the Kronecker symbol</param>
|
||||
/// <returns>The Kronecker symbol (-1, 0, or 1).</returns>
|
||||
static int Kronecker(HugeInt^ a, HugeInt^ b) { return mpz_kronecker(a->_value, b->_value); }
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Jacobi symbol (<paramref name="a"/>/<paramref name="b"/>) with the Kronecker extension
|
||||
/// (<paramref name="a"/>/2) = (2/<paramref name="a"/>) when a odd, or (<paramref name="a"/>/2) = 0 when a even.
|
||||
/// <para>When <paramref name="b"/> is odd the Jacobi symbol and Kronecker symbol are identical, so the various Kronecker overloads
|
||||
/// can be used for mixed precision Jacobi symbols too.
|
||||
/// </para></summary>
|
||||
/// <param name="a">First source value for the Kronecker symbol</param>
|
||||
/// <param name="b">Second source value for the Kronecker symbol</param>
|
||||
/// <returns>The Kronecker symbol (-1, 0, or 1).</returns>
|
||||
static int Kronecker(HugeInt^ a, mpir_ui b) { return mpz_kronecker_ui(a->_value, b); }
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Jacobi symbol (<paramref name="a"/>/<paramref name="b"/>) with the Kronecker extension
|
||||
/// (<paramref name="a"/>/2) = (2/<paramref name="a"/>) when a odd, or (<paramref name="a"/>/2) = 0 when a even.
|
||||
/// <para>When <paramref name="b"/> is odd the Jacobi symbol and Kronecker symbol are identical, so the various Kronecker overloads
|
||||
/// can be used for mixed precision Jacobi symbols too.
|
||||
/// </para></summary>
|
||||
/// <param name="a">First source value for the Kronecker symbol</param>
|
||||
/// <param name="b">Second source value for the Kronecker symbol</param>
|
||||
/// <returns>The Kronecker symbol (-1, 0, or 1).</returns>
|
||||
static int Kronecker(HugeInt^ a, mpir_si b) { return mpz_kronecker_si(a->_value, b); }
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Jacobi symbol (<paramref name="a"/>/<paramref name="b"/>) with the Kronecker extension
|
||||
/// (<paramref name="a"/>/2) = (2/<paramref name="a"/>) when a odd, or (<paramref name="a"/>/2) = 0 when a even.
|
||||
/// <para>When <paramref name="b"/> is odd the Jacobi symbol and Kronecker symbol are identical, so the various Kronecker overloads
|
||||
/// can be used for mixed precision Jacobi symbols too.
|
||||
/// </para></summary>
|
||||
/// <param name="a">First source value for the Kronecker symbol</param>
|
||||
/// <param name="b">Second source value for the Kronecker symbol</param>
|
||||
/// <returns>The Kronecker symbol (-1, 0, or 1).</returns>
|
||||
static int Kronecker(mpir_ui a, HugeInt^ b) { return mpz_ui_kronecker(a, b->_value); }
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Jacobi symbol (<paramref name="a"/>/<paramref name="b"/>) with the Kronecker extension
|
||||
/// (<paramref name="a"/>/2) = (2/<paramref name="a"/>) when a odd, or (<paramref name="a"/>/2) = 0 when a even.
|
||||
/// <para>When <paramref name="b"/> is odd the Jacobi symbol and Kronecker symbol are identical, so the various Kronecker overloads
|
||||
/// can be used for mixed precision Jacobi symbols too.
|
||||
/// </para></summary>
|
||||
/// <param name="a">First source value for the Kronecker symbol</param>
|
||||
/// <param name="b">Second source value for the Kronecker symbol</param>
|
||||
/// <returns>The Kronecker symbol (-1, 0, or 1).</returns>
|
||||
static int Kronecker(mpir_si a, HugeInt^ b) { return mpz_si_kronecker(a, b->_value); }
|
||||
|
||||
#pragma endregion
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user