MathLib Docs MathLib Docs
MathLib Docs MathLib Docs

Search Results for

    Edit this page

    Class Qp

    Represents p-adic numbers that are rational, denoted ℚ⊂ℚₚ.

    Inheritance
    object
    Q
    Qp
    Implements
    IEquatable<Q>
    IComparable<Q>
    Inherited Members
    Q.IsNaN
    Q.IsZero
    Q.IsOne
    Q.IsPositive
    Q.IsNegative
    Q.IsInteger
    Q.IsNonZeroInteger
    Q.IsPositiveInteger
    Q.IsNegativeInteger
    Q.IsUnitFraction
    Q.Equals(Q)
    Q.CompareTo(Q)
    Q.CompareTo(BigInteger)
    Q.CompareTo(int)
    Q.Equals(object)
    Q.GetHashCode()
    Q.Numerator
    Q.Denominator
    Q.IntegralPart
    Q.FractionalPart
    Q.Zero
    Q.One
    Q.PAryInterpretation(bool, BaseInt, BaseInt, int)
    Q.PAdicInterpretation(BaseInt, BaseInt, int)
    Q.PAryPreperiodic(bool, BaseInt, int)
    Q.PAdicPreperiodic(BaseInt, int)
    Q.PAryPeriodic(bool, BaseInt, int)
    Q.PAdicPeriodic(BaseInt, int)
    Q.GetPAdicPreperiodic(Q, BaseInt, int)
    Q.InBase(int)
    Q.ShiftedFractions(int)
    Q.Coefficients(int)
    Q.Coeff(int)
    Q.Backward(int)
    Q.Forward(int)
    Q.Sign
    Q.Reciprocal
    Q.Negation(bool)
    Q.Square()
    Q.Abs
    Q.Pow(Q)
    Q.Pow(int)
    Q.TryCastToInt32(out int)
    Q.IntegralPartAlwaysFEO
    Q.IntegralPartSelective(bool)
    Q.ToStringCanonical()
    Q.ToStringFactorization()
    Q.ToStringFinite(int)
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: MathLib
    Assembly: MathLib.dll
    Syntax
    public class Qp : Q, IEquatable<Q>, IComparable<Q>
    Remarks

    In mathematics, the set of p-adic numbers ℚₚ is the completion of the rational numbers ℚ with respect to the p-adic norm. This completion includes both rational numbers and p-adic irrationals (limits of infinite p-adic expansions).

    However, in this library, the Qp class is restricted to representing only the rational numbers within ℚₚ (which can be finitely represented in a computer). Consequently, it handles p-adic numbers whose expansions are finite or ultimately periodic, corresponding exactly to elements of ℚ

    This means that while ℚₚ is uncountable and includes numbers that cannot be expressed as ratios of integers (p-adic irrationals), our Qp class cannot represent these elements. It focuses on rational numbers and their representations in p-adic form.

    Examples

    A 5-adic expansion for the rational number -4/3 is:

    -4/3 = …2222222212₅

    Constructors

    | Edit this page View Source

    Qp(BaseInt, BaseInt, int)

    Constructor for a p-adic number for the specified preperiodic and periodic parts, and an optional first exponent.

    Declaration
    public Qp(BaseInt pAdicPreperiodic, BaseInt pAdicPeriodic, int firstExponent = 0)
    Parameters
    Type Name Description
    BaseInt pAdicPreperiodic

    The p-adic preperiodic part of the number.

    BaseInt pAdicPeriodic

    The p-adic periodic part of the number.

    int firstExponent

    The first exponent of the number (Default value = 0).

    | Edit this page View Source

    Qp(Q, int)

    Constructor for a p-adic number.

    Declaration
    public Qp(Q q, int base_)
    Parameters
    Type Name Description
    Q q

    The rational number to represent as a p-adic number.

    int base_

    The prime base of the p-adic number.

    | Edit this page View Source

    Qp(BigInteger, BigInteger, int)

    Declaration
    public Qp(BigInteger Numerator, BigInteger Denominator, int base_)
    Parameters
    Type Name Description
    BigInteger Numerator
    BigInteger Denominator
    int base_

    Properties

    | Edit this page View Source

    Base

    Returns the prime base of this p-adic number.

    Declaration
    public int Base { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    FirstExponent

    Declaration
    public int FirstExponent { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    Generator

    A reverse generator that can be used to generate the coefficients of the p-adic number, in reverse order (least significant digit first).

    Declaration
    public Qb Generator { get; }
    Property Value
    Type Description
    Qb
    | Edit this page View Source

    NaN

    Returns a NaN Qp instance.

    Declaration
    public static Qp NaN { get; }
    Property Value
    Type Description
    Qp

    Methods

    | Edit this page View Source

    Coefficients()

    Declaration
    public IEnumerable<int> Coefficients()
    Returns
    Type Description
    IEnumerable<int>
    | Edit this page View Source

    FindKQ(Q, int)

    Decomposes a rational number q into an integer part k and a fractional remainder based on the specified modulus.

    Declaration
    public static (int k, Q q) FindKQ(Q q, int modulus)
    Parameters
    Type Name Description
    Q q

    The rational number to decompose, represented as an instance of Q.

    int modulus

    The modulus (or base) for the decomposition, which must be a positive integer greater than 1.

    Returns
    Type Description
    (int k, Q q)

    A tuple containing:

    • k: An integer representing the integer component of the decomposition, in the range [0, modulus).
    • q: The remaining fractional part of the decomposition, represented as a rational number Q.
    Remarks

    This method computes the first coefficient k in the p-adic expansion of the rational number q with respect to the specified modulus modulus (which serves as the base of the p-adic expansion). The remainder is the fractional part of the number after subtracting the integer part k and dividing by modulus.

    Mathematically, this method solves the equation:

    q = k + modulus × remainder

    where k is an integer in the range [0, modulus) and remainder is the fractional part of q after division by modulus.

    The method uses modular arithmetic to compute k efficiently by solving the congruence:

    k ≡ q.Numerator × (q.Denominator)⁻¹ (mod modulus)

    where q.Denominator⁻¹ is the modular inverse of q.Denominator with respect to modulus.

    Examples

    This example demonstrates decomposing a rational number with respect to a modulus:

    Q q = new Q(1, 17);
    (int k, Q remainder) = FindKQ(q, 5);
    Console.WriteLine($"k = {k}, remainder = {remainder}");
    // Output: k = 3, remainder = -10 / 17
    Exceptions
    Type Condition
    ArgumentException

    Thrown if q's denominator and modulus are not coprime (i.e., their greatest common divisor is not 1).

    | Edit this page View Source

    PadicCoeffs(Q, int, bool)

    Declaration
    public static IEnumerable<int> PadicCoeffs(Q q, int base_, bool yieldDelimiters = false)
    Parameters
    Type Name Description
    Q q
    int base_
    bool yieldDelimiters
    Returns
    Type Description
    IEnumerable<int>
    | Edit this page View Source

    ReciprocalCoefficients(BigInteger, int)

    Generates the p-adic coefficients of the reciprocal of n in the base base_. Also returns a remainder with each coefficient.

    Declaration
    public static IEnumerable<(int coefficient, BigInteger remainder)> ReciprocalCoefficients(BigInteger n, int base_)
    Parameters
    Type Name Description
    BigInteger n

    The number whose reciprocal's p-adic expansion is computed.

    int base_

    The prime base of the p-adic expansion.

    Returns
    Type Description
    IEnumerable<(int coefficient, BigInteger remainder)>

    An enumerable tuple sequence (coefficient, remainder).

    | Edit this page View Source

    ToString()

    Default string representation of the p-adic number.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    Q.ToString()
    | Edit this page View Source

    ToStringExpanded(int)

    Returns a string for the p-adic number in expanded form.

    Declaration
    public string ToStringExpanded(int coefficientCount = 16)
    Parameters
    Type Name Description
    int coefficientCount

    The number of coefficients to include

    Returns
    Type Description
    string
    | Edit this page View Source

    ToStringPeriodic()

    Declaration
    public string ToStringPeriodic()
    Returns
    Type Description
    string
    | Edit this page View Source

    Valuation()

    p-adic valuation of the current p-adic number.

    Declaration
    public int Valuation()
    Returns
    Type Description
    int

    Valuation of the number relative to Base.

    Implements

    IEquatable<T>
    IComparable<T>