Class Qp
Represents p-adic numbers that are rational, denoted ℚ⊂ℚₚ.
Inherited Members
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 SourceQp(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 = |
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. |
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 SourceBase
Returns the prime base of this p-adic number.
Declaration
public int Base { get; }
Property Value
Type | Description |
---|---|
int |
FirstExponent
Declaration
public int FirstExponent { get; }
Property Value
Type | Description |
---|---|
int |
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 |
NaN
Returns a NaN Qp instance.
Declaration
public static Qp NaN { get; }
Property Value
Type | Description |
---|---|
Qp |
Methods
| Edit this page View SourceCoefficients()
Declaration
public IEnumerable<int> Coefficients()
Returns
Type | Description |
---|---|
IEnumerable<int> |
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:
|
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 |
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> |
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). |
ToString()
Default string representation of the p-adic number.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
| Edit this page View SourceToStringExpanded(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 |
ToStringPeriodic()
Declaration
public string ToStringPeriodic()
Returns
Type | Description |
---|---|
string |
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. |