Feature: Polynomials and rational functions #469
@ -423,7 +423,13 @@ public interface AbstractRationalFunctionalSpace<C, P: AbstractPolynomial<C>, R:
|
||||
/**
|
||||
* Checks equality of the rational functions.
|
||||
*/
|
||||
public infix fun R.equalsTo(other: R): Boolean
|
||||
public infix fun R.equalsTo(other: R): Boolean =
|
||||
when {
|
||||
this === other -> true
|
||||
numerator.isZero() != other.numerator.isZero() -> false
|
||||
numeratorDegree - denominatorDegree != with(other) { numeratorDegree - denominatorDegree } -> false
|
||||
else -> numerator * other.denominator equalsTo other.numerator * denominator
|
||||
}
|
||||
/**
|
||||
* Checks NOT equality of the polynomials.
|
||||
*/
|
||||
@ -858,3 +864,223 @@ public interface AbstractRationalFunctionalSpaceOverPolynomialSpace<
|
||||
*/
|
||||
public override fun P.asConstant(): C = polynomialRing { this@asConstant.asConstant() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstraction of field of rational functions of type [R] with respect to polynomials of type [P] and constants of type
|
||||
* [C]. It also assumes that there is provided [polynomialRing] (of type [AP]), that provides constant- and
|
||||
* polynomial-wise operations.
|
||||
*
|
||||
* @param C the type of constants. Polynomials have them as coefficients in their terms.
|
||||
* @param P the type of polynomials. Rational functions have them as numerators and denominators in them.
|
||||
* @param R the type of rational functions.
|
||||
* @param AP the type of algebraic structure (precisely, of ring) provided for polynomials.
|
||||
*/ // TODO: Add support of field
|
||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||
public abstract class AbstractPolynomialFractionsSpace<
|
||||
C,
|
||||
P: AbstractPolynomial<C>,
|
||||
R: AbstractRationalFunction<C, P>,
|
||||
> : AbstractRationalFunctionalSpace<C, P, R> {
|
||||
protected abstract fun constructRationalFunction(numerator: P, denominator: P) : R
|
||||
|
||||
/**
|
||||
* Returns sum of the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to adding [other] copies of unit polynomial to [this].
|
||||
*/
|
||||
public override operator fun R.plus(other: Int): R =
|
||||
constructRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to subtraction [other] copies of unit polynomial from [this].
|
||||
*/
|
||||
public override operator fun R.minus(other: Int): R =
|
||||
constructRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to sum of [other] copies of [this].
|
||||
*/
|
||||
public override operator fun R.times(other: Int): R =
|
||||
constructRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to adding [this] copies of unit polynomial to [other].
|
||||
*/
|
||||
public override operator fun Int.plus(other: R): R =
|
||||
constructRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to subtraction [this] copies of unit polynomial from [other].
|
||||
*/
|
||||
public override operator fun Int.minus(other: R): R =
|
||||
constructRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to sum of [this] copies of [other].
|
||||
*/
|
||||
public override operator fun Int.times(other: R): R =
|
||||
constructRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun C.plus(other: R): R =
|
||||
constructRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the constant represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun C.minus(other: R): R =
|
||||
constructRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the constant represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun C.times(other: R): R =
|
||||
constructRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun R.plus(other: C): R =
|
||||
constructRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun R.minus(other: C): R =
|
||||
constructRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun R.times(other: C): R =
|
||||
constructRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun P.plus(other: R): R =
|
||||
constructRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the polynomial represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun P.minus(other: R): R =
|
||||
constructRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the polynomial represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun P.times(other: R): R =
|
||||
constructRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun R.plus(other: P): R =
|
||||
constructRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun R.minus(other: P): R =
|
||||
constructRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun R.times(other: P): R =
|
||||
constructRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns negation of the rational function.
|
||||
*/
|
||||
public override operator fun R.unaryMinus(): R = constructRationalFunction(-numerator, denominator)
|
||||
/**
|
||||
* Returns sum of the rational functions.
|
||||
*/
|
||||
public override operator fun R.plus(other: R): R =
|
||||
constructRationalFunction(
|
||||
numerator * other.denominator + denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference of the rational functions.
|
||||
*/
|
||||
public override operator fun R.minus(other: R): R =
|
||||
constructRationalFunction(
|
||||
numerator * other.denominator - denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the rational functions.
|
||||
*/
|
||||
public override operator fun R.times(other: R): R =
|
||||
constructRationalFunction(
|
||||
numerator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Instance of zero rational function (zero of the rational functions ring).
|
||||
*/
|
||||
public override val zero: R get() = constructRationalFunction(polynomialZero, polynomialOne)
|
||||
|
||||
/**
|
||||
* Instance of unit polynomial (unit of the rational functions ring).
|
||||
*/
|
||||
public override val one: R get() = constructRationalFunction(polynomialOne, polynomialOne)
|
||||
}
|
@ -64,205 +64,25 @@ public class LabeledRationalFunction<C>(
|
||||
|
||||
public class LabeledRationalFunctionSpace<C, A: Ring<C>>(
|
||||
public val ring: A,
|
||||
) : AbstractRationalFunctionalSpaceOverPolynomialSpace<
|
||||
) :
|
||||
AbstractRationalFunctionalSpaceOverPolynomialSpace<
|
||||
C,
|
||||
LabeledPolynomial<C>,
|
||||
LabeledRationalFunction<C>,
|
||||
LabeledPolynomialSpace<C, A>,
|
||||
> {
|
||||
>,
|
||||
AbstractPolynomialFractionsSpace<
|
||||
C,
|
||||
LabeledPolynomial<C>,
|
||||
LabeledRationalFunction<C>,
|
||||
>() {
|
||||
|
||||
override val polynomialRing : LabeledPolynomialSpace<C, A> = LabeledPolynomialSpace(ring)
|
||||
|
||||
/**
|
||||
* Returns sum of the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to adding [other] copies of unit polynomial to [this].
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.plus(other: Int): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to subtraction [other] copies of unit polynomial from [this].
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.minus(other: Int): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to sum of [other] copies of [this].
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.times(other: Int): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to adding [this] copies of unit polynomial to [other].
|
||||
*/
|
||||
public override operator fun Int.plus(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to subtraction [this] copies of unit polynomial from [other].
|
||||
*/
|
||||
public override operator fun Int.minus(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to sum of [this] copies of [other].
|
||||
*/
|
||||
public override operator fun Int.times(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun C.plus(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the constant represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun C.minus(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the constant represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun C.times(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.plus(other: C): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.minus(other: C): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.times(other: C): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledPolynomial<C>.plus(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the polynomial represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledPolynomial<C>.minus(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the polynomial represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledPolynomial<C>.times(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.plus(other: LabeledPolynomial<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.minus(other: LabeledPolynomial<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.times(other: LabeledPolynomial<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns negation of the rational function.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.unaryMinus(): LabeledRationalFunction<C> = LabeledRationalFunction(-numerator, denominator)
|
||||
/**
|
||||
* Returns sum of the rational functions.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.plus(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator * other.denominator + denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference of the rational functions.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.minus(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator * other.denominator - denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the rational functions.
|
||||
*/
|
||||
public override operator fun LabeledRationalFunction<C>.times(other: LabeledRationalFunction<C>): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(
|
||||
numerator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
override fun constructRationalFunction(
|
||||
numerator: LabeledPolynomial<C>,
|
||||
denominator: LabeledPolynomial<C>
|
||||
): LabeledRationalFunction<C> =
|
||||
LabeledRationalFunction(numerator, denominator)
|
||||
|
||||
/**
|
||||
* Instance of zero rational function (zero of the rational functions ring).
|
||||
@ -279,7 +99,7 @@ public class LabeledRationalFunctionSpace<C, A: Ring<C>>(
|
||||
public override infix fun LabeledRationalFunction<C>.equalsTo(other: LabeledRationalFunction<C>): Boolean {
|
||||
if (this === other) return true
|
||||
|
||||
if ( !(numerator.isZero() xor other.numerator.isZero()) ) return false
|
||||
if (numerator.isZero() != other.numerator.isZero()) return false
|
||||
|
||||
val variables = this.variables union other.variables
|
||||
val thisNumeratorDegrees = this.numerator.degrees
|
||||
|
@ -60,205 +60,25 @@ public class NumberedRationalFunction<C> internal constructor(
|
||||
|
||||
public class NumberedRationalFunctionSpace<C, A: Ring<C>> (
|
||||
public val ring: A,
|
||||
) : AbstractRationalFunctionalSpaceOverPolynomialSpace<
|
||||
) :
|
||||
AbstractRationalFunctionalSpaceOverPolynomialSpace<
|
||||
C,
|
||||
NumberedPolynomial<C>,
|
||||
NumberedRationalFunction<C>,
|
||||
NumberedPolynomialSpace<C, A>,
|
||||
> {
|
||||
>,
|
||||
AbstractPolynomialFractionsSpace<
|
||||
C,
|
||||
NumberedPolynomial<C>,
|
||||
NumberedRationalFunction<C>,
|
||||
>() {
|
||||
|
||||
override val polynomialRing : NumberedPolynomialSpace<C, A> = NumberedPolynomialSpace(ring)
|
||||
|
||||
/**
|
||||
* Returns sum of the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to adding [other] copies of unit polynomial to [this].
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.plus(other: Int): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to subtraction [other] copies of unit polynomial from [this].
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.minus(other: Int): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to sum of [other] copies of [this].
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.times(other: Int): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to adding [this] copies of unit polynomial to [other].
|
||||
*/
|
||||
public override operator fun Int.plus(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to subtraction [this] copies of unit polynomial from [other].
|
||||
*/
|
||||
public override operator fun Int.minus(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to sum of [this] copies of [other].
|
||||
*/
|
||||
public override operator fun Int.times(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun C.plus(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the constant represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun C.minus(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the constant represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun C.times(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.plus(other: C): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.minus(other: C): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.times(other: C): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedPolynomial<C>.plus(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the polynomial represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedPolynomial<C>.minus(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the polynomial represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedPolynomial<C>.times(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.plus(other: NumberedPolynomial<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.minus(other: NumberedPolynomial<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.times(other: NumberedPolynomial<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns negation of the rational function.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.unaryMinus(): NumberedRationalFunction<C> = NumberedRationalFunction(-numerator, denominator)
|
||||
/**
|
||||
* Returns sum of the rational functions.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.plus(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator * other.denominator + denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference of the rational functions.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.minus(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator * other.denominator - denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the rational functions.
|
||||
*/
|
||||
public override operator fun NumberedRationalFunction<C>.times(other: NumberedRationalFunction<C>): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(
|
||||
numerator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
override fun constructRationalFunction(
|
||||
numerator: NumberedPolynomial<C>,
|
||||
denominator: NumberedPolynomial<C>
|
||||
): NumberedRationalFunction<C> =
|
||||
NumberedRationalFunction(numerator, denominator)
|
||||
|
||||
/**
|
||||
* Instance of zero rational function (zero of the rational functions ring).
|
||||
@ -275,7 +95,7 @@ public class NumberedRationalFunctionSpace<C, A: Ring<C>> (
|
||||
public override infix fun NumberedRationalFunction<C>.equalsTo(other: NumberedRationalFunction<C>): Boolean {
|
||||
if (this === other) return true
|
||||
|
||||
if ( !(numerator.isZero() xor other.numerator.isZero()) ) return false
|
||||
if (numerator.isZero() != other.numerator.isZero()) return false
|
||||
|
||||
val countOfVariables = max(this.lastVariable, other.lastVariable)
|
||||
val thisNumeratorDegrees = this.numerator.degrees
|
||||
|
@ -42,205 +42,22 @@ public data class RationalFunction<C> internal constructor (
|
||||
|
||||
public class RationalFunctionSpace<C, A : Ring<C>> (
|
||||
public val ring: A,
|
||||
) : AbstractRationalFunctionalSpaceOverPolynomialSpace<
|
||||
) :
|
||||
AbstractRationalFunctionalSpaceOverPolynomialSpace<
|
||||
C,
|
||||
Polynomial<C>,
|
||||
RationalFunction<C>,
|
||||
PolynomialSpace<C, A>,
|
||||
> {
|
||||
>,
|
||||
AbstractPolynomialFractionsSpace<
|
||||
C,
|
||||
Polynomial<C>,
|
||||
RationalFunction<C>,
|
||||
>() {
|
||||
|
||||
override val polynomialRing : PolynomialSpace<C, A> = PolynomialSpace(ring)
|
||||
|
||||
/**
|
||||
* Returns sum of the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to adding [other] copies of unit polynomial to [this].
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.plus(other: Int): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to subtraction [other] copies of unit polynomial from [this].
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.minus(other: Int): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the rational function and the integer represented as rational function.
|
||||
*
|
||||
* The operation is equivalent to sum of [other] copies of [this].
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.times(other: Int): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to adding [this] copies of unit polynomial to [other].
|
||||
*/
|
||||
public override operator fun Int.plus(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to subtraction [this] copies of unit polynomial from [other].
|
||||
*/
|
||||
public override operator fun Int.minus(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the integer represented as rational function and the rational function.
|
||||
*
|
||||
* The operation is equivalent to sum of [this] copies of [other].
|
||||
*/
|
||||
public override operator fun Int.times(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun C.plus(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the constant represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun C.minus(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the constant represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun C.times(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.plus(other: C): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.minus(other: C): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the constant represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.times(other: C): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun Polynomial<C>.plus(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
other.denominator * this + other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the polynomial represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun Polynomial<C>.minus(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
other.denominator * this - other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the polynomial represented as polynomial and the rational function.
|
||||
*/
|
||||
public override operator fun Polynomial<C>.times(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
this * other.numerator,
|
||||
other.denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns sum of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.plus(other: Polynomial<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator + denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference between the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.minus(other: Polynomial<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator - denominator * other,
|
||||
denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the polynomial represented as rational function and the rational function.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.times(other: Polynomial<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator * other,
|
||||
denominator
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns negation of the rational function.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.unaryMinus(): RationalFunction<C> = RationalFunction(-numerator, denominator)
|
||||
/**
|
||||
* Returns sum of the rational functions.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.plus(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator * other.denominator + denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns difference of the rational functions.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.minus(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator * other.denominator - denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
/**
|
||||
* Returns product of the rational functions.
|
||||
*/
|
||||
public override operator fun RationalFunction<C>.times(other: RationalFunction<C>): RationalFunction<C> =
|
||||
RationalFunction(
|
||||
numerator * other.numerator,
|
||||
denominator * other.denominator
|
||||
)
|
||||
override fun constructRationalFunction(numerator: Polynomial<C>, denominator: Polynomial<C>): RationalFunction<C> =
|
||||
RationalFunction(numerator, denominator)
|
||||
|
||||
/**
|
||||
* Instance of zero rational function (zero of the rational functions ring).
|
||||
@ -251,16 +68,6 @@ public class RationalFunctionSpace<C, A : Ring<C>> (
|
||||
*/
|
||||
public override val one: RationalFunction<C> = RationalFunction(polynomialOne, polynomialOne)
|
||||
|
||||
/**
|
||||
* Checks equality of the rational functions.
|
||||
*/
|
||||
public override infix fun RationalFunction<C>.equalsTo(other: RationalFunction<C>): Boolean =
|
||||
when {
|
||||
this === other -> true
|
||||
numeratorDegree - denominatorDegree != with(other) { numeratorDegree - denominatorDegree } -> false
|
||||
else -> numerator * other.denominator equalsTo other.numerator * denominator
|
||||
}
|
||||
|
||||
// TODO: Разобрать
|
||||
|
||||
public operator fun RationalFunction<C>.div(other: RationalFunction<C>): RationalFunction<C> =
|
||||
|
Loading…
Reference in New Issue
Block a user