MathLib Docs MathLib Docs
MathLib Docs MathLib Docs

Search Results for

    Edit this page

    Class Qb

    Represents a rational number with a base-dependent expansion, denoted ℚb.

    Inheritance
    object
    Q
    Qb
    Implements
    IEquatable<Q>
    IComparable<Q>
    IEquatable<Qb>
    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 Qb : Q, IEquatable<Q>, IComparable<Q>, IEquatable<Qb>
    Remarks

    The class Qb extends Q by adopting a base, and thus defining a base-specific coefficient expansion of the rational number, with a preperiodic and a periodic part. These types of expansions are commonly used in numeral systems like p-ary expansions (e.g. decimal or binary) or in p-adic systems.

    Each number is expressed in terms of a base, denoted by Base, with a preperiodic part (initial terminating sequence) and a periodic part (repeating sequence).

    Each coefficient is indexed according to the exponent of the base Base. The index i corresponds to the coefficient c_i associated with the term c_i · Base^i, where the value of i decreases as we move from left to right in the expansion.

    The first (leftmost) coefficient has index FirstExponent, which corresponds to the largest exponent. The index decreases through the expansion, reflecting the successive exponents of the base, including negative exponents for terms after the radix point (radix point occurs between c_0 and c_-1).

    This consistent indexing system aligns with the mathematical representation of the number as a series in base Base: q = Σ (c_i · Base^i) where the index i decreases from FirstExponent to negative values as the expansion proceeds.

    Overview of concepts and properties, for a full (ultimately periodic) expansion:
                             |--------------------------------------------------------|
        Indexes (example):   |-- 7   6   5   4   3   2   1   0  -1  -2  -3  -4  -5  --|  
        Numeric parts:       |-- IntegralPart    --|-- FractionalPart               --|
        Length properties:   |-- IntegralLength  --|-- FractionalLength             --|
        Numeric parts:       |-- PreperiodicPart               --|-- PeriodicPart   --|         
        Length properties:   |-- PreperiodicLength             --|-- Period         --|                  
                             |-- Length                                             --|
        Indexes (Exponents): • (FirstExponent=8)                     • (FirstPeriodicExponent=-2)
                                                               • (Radix point, after c_0)

    The class methods must never throw exceptions for arithmetic operations. Instead, they return NaN for undefined results (such as from divide by zero).

    Constructors

    | Edit this page View Source

    Qb(Q, int)

    Extends a rational number to a Qb extension with the specific base base_.

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

    A rational number of type Q

    int base_

    The base of the rational number extension.

    | Edit this page View Source

    Qb(bool, BaseInt, BaseInt, int)

    Constructor that creates a Qb from the defining parts of a base-specific expansion.

    Declaration
    public Qb(bool negative, BaseInt prePeriodicPart, BaseInt periodicPart, int firstExponent = -1)
    Parameters
    Type Name Description
    bool negative

    A boolean indicating if the number is negative.

    BaseInt prePeriodicPart

    The preperiodic part as a BaseInt.

    BaseInt periodicPart

    The periodic part as a BaseInt>.

    int firstExponent

    The exponent index of the first coefficient of the number.

    Remarks

    This constructor will derive the Numerator and Denominator from the parts.

    | Edit this page View Source

    Qb(BigInteger, BigInteger, int)

    Constructor for a Qb that takes a numerator, denominator and a base. The rational number is automatically normalized to its simplest form.

    Declaration
    public Qb(BigInteger numerator, BigInteger denominator, int base_)
    Parameters
    Type Name Description
    BigInteger numerator

    The numerator of the rational number.

    BigInteger denominator

    The denominator of the rational number. Must be non-zero.

    int base_

    The base of the rational number extension.

    Remarks

    If you already have an object of type Q, then the constructor Qb(Q, int) will be faster.

    Or alternatively, you can simply call InBase(int) on the Q instance

    Properties

    | Edit this page View Source

    Base

    Gets the base of the rational number extension.

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

    FirstExponent

    Index (= exponent value) of the first coefficient (of the base Base expansion)

    Declaration
    public int FirstExponent { get; }
    Property Value
    Type Description
    int
    Remarks

    This value is simply the length of IntegralPart - 1:

    The range of possible values is [-1..∞[, since a number either starts before the radix point, or directly after it.

    The coefficient at index FirstExponent is the true first coefficient in the expansion, which can be zero iffFirstExponent is -1.

    Formula:

    FirstExponent = IntegralPart.Length(Base) - 1

    | Edit this page View Source

    FirstPeriodicExponent

    Index (= exponent value) of the first coefficient of the periodic part (of the base B expansion).

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

    FractionalLength

    Length of the fractional part (of the base B expansion).

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

    FullInteger

    Numeric concatenation of the preperiodic and periodic parts.

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

    IntegralLength

    Length of the integer part (of the base B expansion).

    Declaration
    public int IntegralLength { get; }
    Property Value
    Type Description
    int
    Remarks

    This value is simply the base-specific length of IntegralPart.

    Formula:

    IntegralLength = IntegralPart.Length(Base)

    | Edit this page View Source

    Length

    Total length of the preperiodic and periodic parts (of the base B expansion).

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

    NaN

    Returns a NaN Qb instance.

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

    Period

    Length of the periodic part (of the base B expansion).

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

    PeriodicPart

    The periodic part.

    Declaration
    public BaseInt PeriodicPart { get; }
    Property Value
    Type Description
    BaseInt
    Remarks

    Contains the periodic coefficients (including zero-padding), and the period (=length of the periodic part).

    | Edit this page View Source

    PreperiodicLength

    Length of the preperiodic part (of the base B expansion).

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

    PreperiodicPart

    The preperiodic part.

    Declaration
    public BaseInt PreperiodicPart { get; }
    Property Value
    Type Description
    BaseInt
    Remarks

    Contains the preperiodic coefficients (including zero-padding), and the length of the preperiodic part.

    Methods

    | Edit this page View Source

    Coefficients()

    Returns the coefficient (or digit) expansion of a rational number in the specified base, expressed as a sequence of integers (modulo b).

    Declaration
    public IEnumerable<int> Coefficients()
    Returns
    Type Description
    IEnumerable<int>

    An enumerable sequence of integers representing the coefficients in base Base.

    Remarks

    The coefficients are obtained from the fractional expansions generated by recursively shifting the radix point of the rational number in base Base.

    Specifically, the coefficients are derived by taking the ShiftedFractions() and scaling them to the range [0..Base-1].

    Thus, each coefficient is a number modulo Base.

    | Edit this page View Source

    Equals(Qb?)

    Indicates whether the current object is equal to another object of the same type.

    Declaration
    public bool Equals(Qb? other)
    Parameters
    Type Name Description
    Qb other

    An object to compare with this object.

    Returns
    Type Description
    bool

    true if the current object is equal to the other parameter; otherwise, false.

    | Edit this page View Source

    RepetendShiftLeft()

    Returns a new Q with a repetend (interpreted as an integer) that is base shifted 1 step to the left compared to the original repetend (interpreted as an integer).

    Declaration
    public Q RepetendShiftLeft()
    Returns
    Type Description
    Q

    A new Q instance with the base-shifted repetend.

    | Edit this page View Source

    RepetendShiftRight()

    Returns a new Q with a repetend (interpreted as an integer) that is base shifted 1 step to the right compared to the original repetend (interpreted as an integer).

    Declaration
    public Q RepetendShiftRight()
    Returns
    Type Description
    Q

    A new Q instance with the base-shifted repetend.

    | Edit this page View Source

    ShiftedFractions()

    Returns the left-to-right expansion of the rational number in the specified base as an infinite sequence of fractions. Each fraction corresponds to the fractional part remaining after successive base-specific left shifts.

    Declaration
    public IEnumerable<(BigInteger Integer, Q Fraction)> ShiftedFractions()
    Returns
    Type Description
    IEnumerable<(BigInteger Integer, Q Fraction)>

    An enumerable sequence of rational numbers representing the shifted fractional parts in base Base.

    Remarks

    This method first applies a normalization step to the rational number, effectively shifting the radix point to the right (in base Base),
    such that the integer part is zero, leaving only the fractional part. The first element of the sequence is this fractional remainder.

    Subsequently, at each step, the fractional part is shifted left by the base (* Base), and the next fractional part is extracted by removing the integer part.

    This process generates an infinite sequence of fractional remainders, which represent the underlying structure of the rational number in the given base. These fractions can be used to derive coefficients or compute the period of the expansion.

    | Edit this page View Source

    ToString()

    Returns the default string representation of the rational number

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

    ToStringExpanded(int)

    Converts the current instance of Qb to its expanded string representation in the given base.

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

    The number of coefficients to include, starting from the leftmost. (default=16)

    Returns
    Type Description
    string

    The expanded string representation of the current instance of Qb.

    Remarks

    The sign of a number is not encoded by (contained in) the expanded representation, since some Q and -Q can have the same string representation. However, negative numbers, completes the generation, by enabling us to generate all ultimately periodic expansions, including those that are not covered by the positive rational numbers.

    Examples
    Q ExpansionMode
    0.0000000000000000FEO=FIO, in any base
    1₂1.000000000000000FEO
    -1₂.1111111111111111FIO
    103/16₂110.0111000000000FEO
    -103/16₂110.0110111111111FIO
    5/24₂.0011010101010101FEO=FIO
    -5/24₂.0011010101010101FEO=FIO
    3/45₅.3333333333333333FEO=FIO
    -3/45₅.3333333333333333FEO=FIO
    537/11₃1210.211002110021FEO=FIO
    -537/11₃1210.211002110021FEO=FIO
    | Edit this page View Source

    ToStringExpandedSigned(int)

    Declaration
    public string ToStringExpandedSigned(int coefficientCount = 16)
    Parameters
    Type Name Description
    int coefficientCount
    Returns
    Type Description
    string
    | Edit this page View Source

    ToStringPeriodic()

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

    ToStringRepetend()

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

    ToStringRotations()

    Declaration
    public string ToStringRotations()
    Returns
    Type Description
    string

    Implements

    IEquatable<T>
    IComparable<T>
    IEquatable<T>