diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt index 1a324f72c..49184468b 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt @@ -6,7 +6,6 @@ package space.kscience.kmath.functions import space.kscience.kmath.operations.* -import kotlin.jvm.JvmName import kotlin.math.max import kotlin.math.min diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledRationalFunctionUtil.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledRationalFunctionUtil.kt index 26e8ab17a..575dfed48 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledRationalFunctionUtil.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledRationalFunctionUtil.kt @@ -1,130 +1,23 @@ -package math.polynomials +/* + * Copyright 2018-2021 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ -import math.ringsAndFields.* -import space.kscience.kmath.functions.LabeledRationalFunction +package space.kscience.kmath.functions -fun > T.toLabeledRationalFunction() = LabeledRationalFunction(this.toLabeledPolynomial()) - -// region Operator extensions - -// region Field case - -fun > LabeledRationalFunction.reduced(): LabeledRationalFunction { - val greatestCommonDivider = polynomialGCD(numerator, denominator) - return LabeledRationalFunction( - numerator / greatestCommonDivider, - denominator / greatestCommonDivider - ) -} - -// endregion - -// region Constants - -operator fun > T.plus(other: LabeledRationalFunction) = other + this -operator fun > Integer.plus(other: LabeledRationalFunction) = other + this -operator fun > Int.plus(other: LabeledRationalFunction) = other + this -operator fun > Long.plus(other: LabeledRationalFunction) = other + this - -operator fun > T.minus(other: LabeledRationalFunction) = -other + this -operator fun > Integer.minus(other: LabeledRationalFunction) = -other + this -operator fun > Int.minus(other: LabeledRationalFunction) = -other + this -operator fun > Long.minus(other: LabeledRationalFunction) = -other + this - -operator fun > T.times(other: LabeledRationalFunction) = other * this -operator fun > Integer.times(other: LabeledRationalFunction) = other * this -operator fun > Int.times(other: LabeledRationalFunction) = other * this -operator fun > Long.times(other: LabeledRationalFunction) = other * this - -// endregion - -// region Polynomials - -operator fun > LabeledRationalFunction.plus(other: UnivariatePolynomial) = - LabeledRationalFunction( - numerator + denominator * other.toLabeledPolynomial(), - denominator - ) -operator fun > LabeledRationalFunction.plus(other: UnivariateRationalFunction) = - LabeledRationalFunction( - numerator * other.denominator.toLabeledPolynomial() + denominator * other.numerator.toLabeledPolynomial(), - denominator * other.denominator.toLabeledPolynomial() - ) -operator fun > LabeledRationalFunction.plus(other: Polynomial) = - LabeledRationalFunction( - numerator + denominator * other.toLabeledPolynomial(), - denominator - ) -operator fun > LabeledRationalFunction.plus(other: NumberedRationalFunction) = - LabeledRationalFunction( - numerator * other.denominator.toLabeledPolynomial() + denominator * other.numerator.toLabeledPolynomial(), - denominator * other.denominator.toLabeledPolynomial() - ) - -operator fun > LabeledRationalFunction.minus(other: UnivariatePolynomial) = - LabeledRationalFunction( - numerator - denominator * other.toLabeledPolynomial(), - denominator - ) -operator fun > LabeledRationalFunction.minus(other: UnivariateRationalFunction) = - LabeledRationalFunction( - numerator * other.denominator.toLabeledPolynomial() - denominator * other.numerator.toLabeledPolynomial(), - denominator * other.denominator.toLabeledPolynomial() - ) -operator fun > LabeledRationalFunction.minus(other: Polynomial) = - LabeledRationalFunction( - numerator - denominator * other.toLabeledPolynomial(), - denominator - ) -operator fun > LabeledRationalFunction.minus(other: NumberedRationalFunction) = - LabeledRationalFunction( - numerator * other.denominator.toLabeledPolynomial() - denominator * other.numerator.toLabeledPolynomial(), - denominator * other.denominator.toLabeledPolynomial() - ) - -operator fun > LabeledRationalFunction.times(other: UnivariatePolynomial) = - LabeledRationalFunction( - numerator * other.toLabeledPolynomial(), - denominator - ) -operator fun > LabeledRationalFunction.times(other: UnivariateRationalFunction) = - LabeledRationalFunction( - numerator * other.numerator.toLabeledPolynomial(), - denominator * other.denominator.toLabeledPolynomial() - ) -operator fun > LabeledRationalFunction.times(other: Polynomial) = - LabeledRationalFunction( - numerator * other.toLabeledPolynomial(), - denominator - ) -operator fun > LabeledRationalFunction.times(other: NumberedRationalFunction) = - LabeledRationalFunction( - numerator * other.numerator.toLabeledPolynomial(), - denominator * other.denominator.toLabeledPolynomial() - ) - -operator fun > LabeledRationalFunction.div(other: UnivariatePolynomial) = - LabeledRationalFunction( - numerator, - denominator * other.toLabeledPolynomial() - ) -operator fun > LabeledRationalFunction.div(other: UnivariateRationalFunction) = - LabeledRationalFunction( - numerator * other.denominator.toLabeledPolynomial(), - denominator * other.numerator.toLabeledPolynomial() - ) -operator fun > LabeledRationalFunction.div(other: Polynomial) = - LabeledRationalFunction( - numerator, - denominator * other.toLabeledPolynomial() - ) -operator fun > LabeledRationalFunction.div(other: NumberedRationalFunction) = - LabeledRationalFunction( - numerator * other.denominator.toLabeledPolynomial(), - denominator * other.numerator.toLabeledPolynomial() - ) - -// endregion - -// endregion \ No newline at end of file +//// region Operator extensions +// +//// region Field case +// +//fun > LabeledRationalFunction.reduced(): LabeledRationalFunction { +// val greatestCommonDivider = polynomialGCD(numerator, denominator) +// return LabeledRationalFunction( +// numerator / greatestCommonDivider, +// denominator / greatestCommonDivider +// ) +//} +// +//// endregion +// +//// endregion \ No newline at end of file