From 3c9d8a4eee586962ba59a3790c3d7ddb18572637 Mon Sep 17 00:00:00 2001 From: Gleb Minaev <43728100+lounres@users.noreply.github.com> Date: Wed, 16 Mar 2022 22:44:55 +0300 Subject: [PATCH] Deleted all region marks --- .../kmath/functions/AbstractPolynomial.kt | 27 ------- .../functions/AbstractRationalFunction.kt | 79 ------------------- .../kmath/functions/LabeledPolynomial.kt | 40 +--------- .../functions/LabeledRationalFunction.kt | 27 +------ .../kmath/functions/NumberedPolynomial.kt | 29 +------ .../functions/NumberedRationalFunction.kt | 27 +------ .../kscience/kmath/functions/Polynomial.kt | 1 - .../kmath/functions/RationalFunction.kt | 24 +----- .../kmath/functions/labeledPolynomialUtil.kt | 37 +-------- .../functions/labeledRationalFunctionUtil.kt | 10 +-- .../kmath/functions/numberedPolynomialUtil.kt | 42 +--------- .../functions/numberedRationalFunctionUtil.kt | 10 +-- .../kmath/functions/polynomialUtil.kt | 14 +--- .../kmath/functions/rationalFunctionUtil.kt | 12 +-- 14 files changed, 11 insertions(+), 368 deletions(-) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/AbstractPolynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/AbstractPolynomial.kt index 2d2d22fd3..aacf055fa 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/AbstractPolynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/AbstractPolynomial.kt @@ -23,7 +23,6 @@ public interface AbstractPolynomial */ @Suppress("INAPPLICABLE_JVM_NAME", "PARAMETER_NAME_CHANGED_ON_OVERRIDE") public interface AbstractPolynomialSpace> : Ring

{ - // region Constant-integer relation /** * Returns sum of the constant and the integer represented as constant (member of underlying ring). * @@ -42,9 +41,7 @@ public interface AbstractPolynomialSpace> : Ring

* The operation is equivalent to sum of [other] copies of [this]. */ public operator fun C.times(other: Int): C - // endregion - // region Integer-constant relation /** * Returns sum of the integer represented as constant (member of underlying ring) and the constant. * @@ -63,9 +60,7 @@ public interface AbstractPolynomialSpace> : Ring

* The operation is equivalent to sum of [this] copies of [other]. */ public operator fun Int.times(other: C): C - // endregion - // region Polynomial-integer relation /** * Returns sum of the polynomial and the integer represented as polynomial. * @@ -84,9 +79,7 @@ public interface AbstractPolynomialSpace> : Ring

* The operation is equivalent to sum of [other] copies of [this]. */ public operator fun P.times(other: Int): P = multiplyBySquaring(this, other) - // endregion - // region Integer-polynomial relation /** * Returns sum of the integer represented as polynomial and the polynomial. * @@ -105,9 +98,7 @@ public interface AbstractPolynomialSpace> : Ring

* The operation is equivalent to sum of [this] copies of [other]. */ public operator fun Int.times(other: P): P = multiplyBySquaring(other, this) - // endregion - // region Constant-constant relation /** * Returns the same constant. */ @@ -178,9 +169,7 @@ public interface AbstractPolynomialSpace> : Ring

* Instance of unit constant (unit of the underlying ring). */ public val constantOne: C - // endregion - // region Constant-polynomial relation /** * Returns sum of the constant represented as polynomial and the polynomial. */ @@ -193,9 +182,7 @@ public interface AbstractPolynomialSpace> : Ring

* Returns product of the constant represented as polynomial and the polynomial. */ public operator fun C.times(other: P): P - // endregion - // region Polynomial-constant relation /** * Returns sum of the constant represented as polynomial and the polynomial. */ @@ -208,9 +195,7 @@ public interface AbstractPolynomialSpace> : Ring

* Returns product of the constant represented as polynomial and the polynomial. */ public operator fun P.times(other: C): P - // endregion - // region Polynomial-polynomial relation /** * Returns the same polynomial. */ @@ -278,10 +263,7 @@ public interface AbstractPolynomialSpace> : Ring

* Checks NOT equality of the polynomials. */ public infix fun P.notEqualsTo(other: P): Boolean = !(this equalsTo other) - // endregion - // Not sure is it necessary... - // region Polynomial properties /** * Degree of the polynomial, [see also](https://en.wikipedia.org/wiki/Degree_of_a_polynomial). If the polynomial is * zero, degree is -1. @@ -314,12 +296,9 @@ public interface AbstractPolynomialSpace> : Ring

* Otherwise, (when the polynomial is not constant polynomial) raises corresponding exception. */ public fun P.asConstant(): C = asConstantOrNull() ?: error("Can not represent non-constant polynomial as a constant") - // endregion - // region Legacy of Ring interface override fun add(left: P, right: P): P = left + right override fun multiply(left: P, right: P): P = left * right - // endregion } /** @@ -335,7 +314,6 @@ public interface AbstractPolynomialSpaceOverRing, A: public val ring: A - // region Constant-integer relation /** * Returns sum of the constant and the integer represented as constant (member of underlying ring). * @@ -354,9 +332,7 @@ public interface AbstractPolynomialSpaceOverRing, A: * The operation is equivalent to sum of [other] copies of [this]. */ public override operator fun C.times(other: Int): C = ring { multiplyBySquaring(this@times, other) } - // endregion - // region Integer-constant relation /** * Returns sum of the integer represented as constant (member of underlying ring) and the constant. * @@ -375,9 +351,7 @@ public interface AbstractPolynomialSpaceOverRing, A: * The operation is equivalent to sum of [this] copies of [other]. */ public override operator fun Int.times(other: C): C = ring { multiplyBySquaring(other, this@times) } - // endregion - // region Constant-constant relation /** * Returns negation of the constant. */ @@ -412,5 +386,4 @@ public interface AbstractPolynomialSpaceOverRing, A: * Instance of unit constant (unit of the underlying ring). */ public override val constantOne: C get() = ring.one - // endregion } \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/AbstractRationalFunction.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/AbstractRationalFunction.kt index c6f1d7a7a..b9ca01da4 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/AbstractRationalFunction.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/AbstractRationalFunction.kt @@ -30,7 +30,6 @@ public interface AbstractRationalFunction> { */ // TODO: Add support of field @Suppress("INAPPLICABLE_JVM_NAME", "PARAMETER_NAME_CHANGED_ON_OVERRIDE") public interface AbstractRationalFunctionalSpace, R: AbstractRationalFunction> : Ring { - // region Constant-integer relation /** * Returns sum of the constant and the integer represented as constant (member of underlying ring). * @@ -49,9 +48,7 @@ public interface AbstractRationalFunctionalSpace, R: * The operation is equivalent to sum of [other] copies of [this]. */ public operator fun C.times(other: Int): C - // endregion - // region Integer-constant relation /** * Returns sum of the integer represented as constant (member of underlying ring) and the constant. * @@ -70,9 +67,7 @@ public interface AbstractRationalFunctionalSpace, R: * The operation is equivalent to sum of [this] copies of [other]. */ public operator fun Int.times(other: C): C - // endregion - // region Polynomial-integer relation /** * Returns sum of the constant and the integer represented as polynomial. * @@ -91,9 +86,7 @@ public interface AbstractRationalFunctionalSpace, R: * The operation is equivalent to sum of [other] copies of [this]. */ public operator fun P.times(other: Int): P - // endregion - // region Integer-polynomial relation /** * Returns sum of the integer represented as polynomial and the constant. * @@ -112,9 +105,7 @@ public interface AbstractRationalFunctionalSpace, R: * The operation is equivalent to sum of [this] copies of [other]. */ public operator fun Int.times(other: P): P - // endregion - // region Rational-integer relation /** * Returns sum of the rational function and the integer represented as rational function. * @@ -133,9 +124,7 @@ public interface AbstractRationalFunctionalSpace, R: * The operation is equivalent to sum of [other] copies of [this]. */ public operator fun R.times(other: Int): R = multiplyBySquaring(this, other) - // endregion - // region Integer-Rational relation /** * Returns sum of the integer represented as rational function and the rational function. * @@ -154,9 +143,7 @@ public interface AbstractRationalFunctionalSpace, R: * The operation is equivalent to sum of [this] copies of [other]. */ public operator fun Int.times(other: R): R = multiplyBySquaring(other, this) - // endregion - // region Constant-constant relation /** * Returns the same constant. */ @@ -227,9 +214,7 @@ public interface AbstractRationalFunctionalSpace, R: * Instance of unit constant (unit of the underlying ring). */ public val constantOne: C - // endregion - // region Constant-polynomial relation /** * Returns sum of the constant represented as polynomial and the polynomial. */ @@ -242,9 +227,7 @@ public interface AbstractRationalFunctionalSpace, R: * Returns product of the constant represented as polynomial and the polynomial. */ public operator fun C.times(other: P): P - // endregion - // region Polynomial-constant relation /** * Returns sum of the constant represented as polynomial and the polynomial. */ @@ -257,9 +240,7 @@ public interface AbstractRationalFunctionalSpace, R: * Returns product of the constant represented as polynomial and the polynomial. */ public operator fun P.times(other: C): P - // endregion - // region Polynomial-polynomial relation /** * Returns the same polynomial. */ @@ -327,9 +308,7 @@ public interface AbstractRationalFunctionalSpace, R: * Checks NOT equality of the polynomials. */ public infix fun P.notEqualsTo(other: P): Boolean = !(this equalsTo other) - // endregion - // region Constant-rational relation /** * Returns sum of the constant represented as rational function and the rational function. */ @@ -342,9 +321,7 @@ public interface AbstractRationalFunctionalSpace, R: * Returns product of the constant represented as polynomial and the rational function. */ public operator fun C.times(other: R): R - // endregion - // region Rational-constant relation /** * Returns sum of the constant represented as rational function and the rational function. */ @@ -357,9 +334,7 @@ public interface AbstractRationalFunctionalSpace, R: * Returns product of the constant represented as rational function and the rational function. */ public operator fun R.times(other: C): R - // endregion - // region Polynomial-rational relation /** * Returns sum of the polynomial represented as rational function and the rational function. */ @@ -372,9 +347,7 @@ public interface AbstractRationalFunctionalSpace, R: * Returns product of the polynomial represented as polynomial and the rational function. */ public operator fun P.times(other: R): R - // endregion - // region Rational-polynomial relation /** * Returns sum of the polynomial represented as rational function and the rational function. */ @@ -387,9 +360,7 @@ public interface AbstractRationalFunctionalSpace, R: * Returns product of the polynomial represented as rational function and the rational function. */ public operator fun R.times(other: P): R - // endregion - // region Rational-rational relation /** * Returns the same rational function. */ @@ -457,10 +428,7 @@ public interface AbstractRationalFunctionalSpace, R: * Checks NOT equality of the polynomials. */ public infix fun R.notEqualsTo(other: R): Boolean = !(this equalsTo other) - // endregion - // Not sure is it necessary... - // region Polynomial properties /** * Degree of the polynomial, [see also](https://en.wikipedia.org/wiki/Degree_of_a_polynomial). If the polynomial is * zero, degree is -1. @@ -494,10 +462,6 @@ public interface AbstractRationalFunctionalSpace, R: */ public fun P.asConstant(): C = asConstantOrNull() ?: error("Can not represent non-constant polynomial as a constant") - // endregion - - // Not sure is it necessary... - // region Rational properties /** * Degree of the polynomial, [see also](https://en.wikipedia.org/wiki/Degree_of_a_polynomial). If the polynomial is * zero, degree is -1. @@ -509,25 +473,8 @@ public interface AbstractRationalFunctionalSpace, R: */ public val R.denominatorDegree: Int get() = denominator.degree - // TODO: Перенести в реализацию -// fun R.substitute(argument: C): C -// fun R.substitute(argument: P): R -// fun R.substitute(argument: R): R -// -// fun R.asFunction(): (C) -> C = /*this::substitute*/ { this.substitute(it) } -// fun R.asFunctionOnConstants(): (C) -> C = /*this::substitute*/ { this.substitute(it) } -// fun P.asFunctionOnPolynomials(): (P) -> R = /*this::substitute*/ { this.substitute(it) } -// fun R.asFunctionOnRationalFunctions(): (R) -> R = /*this::substitute*/ { this.substitute(it) } -// -// operator fun R.invoke(argument: C): C = this.substitute(argument) -// operator fun R.invoke(argument: P): R = this.substitute(argument) -// operator fun R.invoke(argument: R): R = this.substitute(argument) - // endregion - - // region Legacy override fun add(left: R, right: R): R = left + right override fun multiply(left: R, right: R): R = left * right - // endregion } /** @@ -544,7 +491,6 @@ public interface AbstractRationalFunctionalSpaceOverRing.cleanUp() = filterValues { it > 0U } -// endregion - -// region Constructors and converters - //context(LabeledPolynomialSpace>) //@Suppress("FunctionName") //internal fun LabeledPolynomial(coefs: Map, C>, toCheckInput: Boolean = false) : LabeledPolynomial { @@ -128,8 +122,6 @@ internal fun Map.cleanUp() = filterValues { it > 0U } public fun C.asLabeledPolynomial() : LabeledPolynomial = LabeledPolynomial(mapOf(emptyMap() to this)) -// endregion - /** * Space of polynomials. * @@ -140,8 +132,6 @@ public fun C.asLabeledPolynomial() : LabeledPolynomial = LabeledPolynomia public class LabeledPolynomialSpace>( public override val ring: A, ) : AbstractPolynomialSpaceOverRing, A> { - - // region Symbol-integer relation public operator fun Symbol.plus(other: Int): LabeledPolynomial = if (other == 0) LabeledPolynomial(mapOf( mapOf(this@plus to 1U) to constantOne, @@ -163,9 +153,7 @@ public class LabeledPolynomialSpace>( else LabeledPolynomial(mapOf( mapOf(this to 1U) to constantOne * other, )) - // endregion - // region Integer-variable relation public operator fun Int.plus(other: Symbol): LabeledPolynomial = if (this == 0) LabeledPolynomial(mapOf( mapOf(other to 1U) to constantOne, @@ -187,9 +175,7 @@ public class LabeledPolynomialSpace>( else LabeledPolynomial(mapOf( mapOf(other to 1U) to constantOne * this@times, )) - // endregion - // region Polynomial-integer relation /** * Returns sum of the polynomial and the integer represented as polynomial. * @@ -243,9 +229,7 @@ public class LabeledPolynomialSpace>( mapValues { (_, c) -> c * other } } ) - // endregion - // region Integer-polynomial relation /** * Returns sum of the integer represented as polynomial and the polynomial. * @@ -299,9 +283,7 @@ public class LabeledPolynomialSpace>( mapValues { (_, c) -> this@times * c } } ) - // endregion - // region Constant-variable relation public operator fun C.plus(other: Symbol): LabeledPolynomial = if (isZero()) LabeledPolynomial(mapOf( mapOf(other to 1U) to constantOne, @@ -323,9 +305,7 @@ public class LabeledPolynomialSpace>( else LabeledPolynomial(mapOf( mapOf(other to 1U) to this@times, )) - // endregion - // region Symbol-constant relation public operator fun Symbol.plus(other: C): LabeledPolynomial = if (other.isZero()) LabeledPolynomial(mapOf( mapOf(this@plus to 1U) to constantOne, @@ -347,9 +327,7 @@ public class LabeledPolynomialSpace>( else LabeledPolynomial(mapOf( mapOf(this@times to 1U) to other, )) - // endregion - // region Constant-polynomial relation /** * Returns sum of the constant represented as polynomial and the polynomial. */ @@ -401,9 +379,7 @@ public class LabeledPolynomialSpace>( mapValues { (_, c) -> this@times * c } } ) - // endregion - // region Polynomial-constant relation /** * Returns sum of the constant represented as polynomial and the polynomial. */ @@ -455,9 +431,7 @@ public class LabeledPolynomialSpace>( mapValues { (_, c) -> c * other } } ) - // endregion - // region Symbol-variable relation public operator fun Symbol.plus(other: Symbol): LabeledPolynomial = if (this == other) LabeledPolynomial(mapOf( mapOf(this to 1U) to constantOne * 2 @@ -479,9 +453,7 @@ public class LabeledPolynomialSpace>( else LabeledPolynomial(mapOf( mapOf(this to 1U, other to 1U) to constantOne, )) - // endregion - // region Symbol-polynomial relation public operator fun Symbol.plus(other: LabeledPolynomial): LabeledPolynomial = with(other.coefficients) { if (isEmpty()) LabeledPolynomial(mapOf(mapOf(this@plus to 1u) to constantOne)) @@ -519,9 +491,7 @@ public class LabeledPolynomialSpace>( other.coefficients .mapKeys { (degs, _) -> degs.toMutableMap().also{ it[this] = if (this in it) it[this]!! + 1U else 1U } } ) - // endregion - // region Polynomial-variable relation public operator fun LabeledPolynomial.plus(other: Symbol): LabeledPolynomial = with(coefficients) { if (isEmpty()) LabeledPolynomial(mapOf(mapOf(other to 1u) to constantOne)) @@ -557,9 +527,7 @@ public class LabeledPolynomialSpace>( coefficients .mapKeys { (degs, _) -> degs.toMutableMap().also{ it[other] = if (other in it) it[other]!! + 1U else 1U } } ) - // endregion - // region Polynomial-polynomial relation /** * Returns negation of the polynomial. */ @@ -626,10 +594,7 @@ public class LabeledPolynomialSpace>( else -> coefficients.size == other.coefficients.size && coefficients.all { (key, value) -> with(other.coefficients) { key in this && this[key] == value } } } - // endregion - // Not sure is it necessary... - // region Polynomial properties /** * Degree of the polynomial, [see also](https://en.wikipedia.org/wiki/Degree_of_a_polynomial). If the polynomial is * zero, degree is -1. @@ -713,10 +678,8 @@ public class LabeledPolynomialSpace>( // @Suppress("NOTHING_TO_INLINE") // @JvmName("invokePolynomial") // public inline operator fun LabeledPolynomial.invoke(argument: Map>): LabeledPolynomial = this.substitute(ring, argument) - // endregion - // region Utilities - // TODO: Move to region internal utilities with context receiver + // TODO: Move to other internal utilities with context receiver @JvmName("applyAndRemoveZerosInternal") internal fun MutableMap, C>.applyAndRemoveZeros(block: MutableMap, C>.() -> Unit) : MutableMap, C> { contract { @@ -744,5 +707,4 @@ public class LabeledPolynomialSpace>( for ((degs, c) in this) if (c.isZero()) this.remove(degs) } } - // endregion } \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/LabeledRationalFunction.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/LabeledRationalFunction.kt index 3077a2b82..3908933e6 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/LabeledRationalFunction.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/LabeledRationalFunction.kt @@ -17,8 +17,6 @@ public class LabeledRationalFunction( override fun toString(): String = "LabeledRationalFunction${numerator.coefficients}/${denominator.coefficients}" } -// region Internal utilities - /** * Represents internal [LabeledRationalFunction] errors. */ @@ -34,9 +32,6 @@ internal class LabeledRationalFunctionError : Error { */ internal fun labeledRationalFunctionError(message: Any): Nothing = throw LabeledRationalFunctionError(message.toString()) -// endregion - -// region Constructors and converters // Waiting for context receivers :( TODO: Replace with context receivers when they will be available //context(RationalFunctionSpace) @@ -82,8 +77,6 @@ internal fun labeledRationalFunctionError(message: Any): Nothing = throw Labeled //LabeledPolynomial(numeratorCoefficients) //) -// endregion - public class LabeledRationalFunctionSpace>( public val ring: A, ) : AbstractRationalFunctionalSpaceOverPolynomialSpace< @@ -95,7 +88,6 @@ public class LabeledRationalFunctionSpace>( override val polynomialRing : LabeledPolynomialSpace = LabeledPolynomialSpace(ring) - // region Rational-integer relation /** * Returns sum of the rational function and the integer represented as rational function. * @@ -126,9 +118,7 @@ public class LabeledRationalFunctionSpace>( numerator * other, denominator ) - // endregion - // region Integer-Rational relation /** * Returns sum of the integer represented as rational function and the rational function. * @@ -159,9 +149,7 @@ public class LabeledRationalFunctionSpace>( this * other.numerator, other.denominator ) - // endregion - // region Constant-rational relation /** * Returns sum of the constant represented as rational function and the rational function. */ @@ -186,9 +174,7 @@ public class LabeledRationalFunctionSpace>( this * other.numerator, other.denominator ) - // endregion - // region Rational-constant relation /** * Returns sum of the constant represented as rational function and the rational function. */ @@ -213,9 +199,7 @@ public class LabeledRationalFunctionSpace>( numerator * other, denominator ) - // endregion - // region Polynomial-rational relation /** * Returns sum of the polynomial represented as rational function and the rational function. */ @@ -240,9 +224,7 @@ public class LabeledRationalFunctionSpace>( this * other.numerator, other.denominator ) - // endregion - // region Rational-polynomial relation /** * Returns sum of the polynomial represented as rational function and the rational function. */ @@ -267,9 +249,7 @@ public class LabeledRationalFunctionSpace>( numerator * other, denominator ) - // endregion - // region Rational-rational relation /** * Returns negation of the rational function. */ @@ -329,9 +309,7 @@ public class LabeledRationalFunctionSpace>( return numerator * other.denominator equalsTo other.numerator * denominator } - // endregion - // region Polynomial properties /** * Map that associates variables (that appear in the polynomial in positive exponents) with their most exponents * in which they are appeared in the polynomial. @@ -348,9 +326,7 @@ public class LabeledRationalFunctionSpace>( * Count of all variables that appear in the polynomial in positive exponents. */ public val LabeledPolynomial.countOfVariables: Int get() = polynomialRing { countOfVariables } - // endregion - // region Rational properties /** * Count of all variables that appear in the polynomial in positive exponents. */ @@ -360,9 +336,8 @@ public class LabeledRationalFunctionSpace>( * Count of all variables that appear in the polynomial in positive exponents. */ public val LabeledRationalFunction.countOfVariables: Int get() = variables.size - // endregion - // region REST TODO: Разобрать + // TODO: Разобрать public operator fun LabeledRationalFunction.div(other: LabeledRationalFunction): LabeledRationalFunction = LabeledRationalFunction( diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/NumberedPolynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/NumberedPolynomial.kt index a1033fcc4..fe6bb597d 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/NumberedPolynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/NumberedPolynomial.kt @@ -47,8 +47,6 @@ internal constructor( override fun toString(): String = "NumberedPolynomial$coefficients" } -// region Internal utilities - /** * Represents internal [Polynomial] errors. */ @@ -69,10 +67,6 @@ internal fun numberedPolynomialError(message: Any): Nothing = throw PolynomialEr */ internal fun List.cleanUp() = subList(0, indexOfLast { it != 0U } + 1) -// endregion - -// region Constructors and converters - //context(NumberedPolynomialSpace>) //@Suppress("FunctionName") //internal fun NumberedPolynomial(coefs: Map, C>, toCheckInput: Boolean = false) : NumberedPolynomial { @@ -124,8 +118,6 @@ internal fun List.cleanUp() = subList(0, indexOfLast { it != 0U } + 1) public fun C.asNumberedPolynomial() : NumberedPolynomial = NumberedPolynomial(mapOf(emptyList() to this)) -// endregion - /** * Space of polynomials. * @@ -136,7 +128,6 @@ public fun C.asNumberedPolynomial() : NumberedPolynomial = NumberedPolyno public open class NumberedPolynomialSpace>( public final override val ring: A, ) : AbstractPolynomialSpaceOverRing, A> { - // region Polynomial-integer relation /** * Returns sum of the polynomial and the integer represented as polynomial. * @@ -190,9 +181,7 @@ public open class NumberedPolynomialSpace>( mapValues { (_, c) -> c * other } } ) - // endregion - // region Integer-polynomial relation /** * Returns sum of the integer represented as polynomial and the polynomial. * @@ -246,9 +235,7 @@ public open class NumberedPolynomialSpace>( mapValues { (_, c) -> this@times * c } } ) - // endregion - // region Constant-polynomial relation /** * Returns sum of the constant represented as polynomial and the polynomial. */ @@ -300,9 +287,7 @@ public open class NumberedPolynomialSpace>( mapValues { (_, c) -> this@times * c } } ) - // endregion - // region Polynomial-constant relation /** * Returns sum of the constant represented as polynomial and the polynomial. */ @@ -352,9 +337,7 @@ public open class NumberedPolynomialSpace>( mapValues { (_, c) -> c * other } } ) - // endregion - // region Polynomial-polynomial relation /** * Returns negation of the polynomial. */ @@ -463,10 +446,7 @@ public open class NumberedPolynomialSpace>( else -> coefficients.size == other.coefficients.size && coefficients.all { (key, value) -> with(other.coefficients) { key in this && this[key] == value } } } - // endregion - // Not sure is it necessary... - // region Polynomial properties // TODO: Replace `countOfVariables` with `lastVariable` and create new `countOfVariables` /** * Count of all variables that appear in the polynomial in positive exponents. @@ -545,10 +525,8 @@ public open class NumberedPolynomialSpace>( @Suppress("NOTHING_TO_INLINE") @JvmName("invokePolynomial") public inline operator fun NumberedPolynomial.invoke(argument: Map>): NumberedPolynomial = this.substitute(ring, argument) - // endregion - // region Utilities - // TODO: Move to region internal utilities with context receiver + // TODO: Move to other internal utilities with context receiver @JvmName("applyAndRemoveZerosInternal") internal fun MutableMap, C>.applyAndRemoveZeros(block: MutableMap, C>.() -> Unit) : MutableMap, C> { contract { @@ -576,9 +554,6 @@ public open class NumberedPolynomialSpace>( for ((degs, c) in this) if (c.isZero()) this.remove(degs) } } - // endregion - - // region Constructors and converters @Suppress("FunctionName") internal fun NumberedPolynomial(coefs: Map, C>, toCheckInput: Boolean = false) : NumberedPolynomial { @@ -622,6 +597,4 @@ public open class NumberedPolynomialSpace>( @Suppress("FunctionName") public fun NumberedPolynomial(vararg pairs: Pair, C>) : NumberedPolynomial = NumberedPolynomial(pairs.toList(), toCheckInput = true) - - // endregion } \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/NumberedRationalFunction.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/NumberedRationalFunction.kt index a81795c81..745df10e8 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/NumberedRationalFunction.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/NumberedRationalFunction.kt @@ -16,8 +16,6 @@ public class NumberedRationalFunction internal constructor( override fun toString(): String = "NumberedRationalFunction${numerator.coefficients}/${denominator.coefficients}" } -// region Internal utilities - /** * Represents internal [NumberedRationalFunction] errors. */ @@ -33,9 +31,6 @@ internal class NumberedRationalFunctionError : Error { */ internal fun numberedRationalFunctionError(message: Any): Nothing = throw NumberedRationalFunctionError(message.toString()) -// endregion - -// region Constructors and converters // Waiting for context receivers :( TODO: Replace with context receivers when they will be available //context(RationalFunctionSpace) @@ -78,8 +73,6 @@ internal fun numberedRationalFunctionError(message: Any): Nothing = throw Number //Polynomial(numeratorCoefficients) //) -// endregion - public class NumberedRationalFunctionSpace> ( public val ring: A, ) : AbstractRationalFunctionalSpaceOverPolynomialSpace< @@ -91,7 +84,6 @@ public class NumberedRationalFunctionSpace> ( override val polynomialRing : NumberedPolynomialSpace = NumberedPolynomialSpace(ring) - // region Rational-integer relation /** * Returns sum of the rational function and the integer represented as rational function. * @@ -122,9 +114,7 @@ public class NumberedRationalFunctionSpace> ( numerator * other, denominator ) - // endregion - // region Integer-Rational relation /** * Returns sum of the integer represented as rational function and the rational function. * @@ -155,9 +145,7 @@ public class NumberedRationalFunctionSpace> ( this * other.numerator, other.denominator ) - // endregion - // region Constant-rational relation /** * Returns sum of the constant represented as rational function and the rational function. */ @@ -182,9 +170,7 @@ public class NumberedRationalFunctionSpace> ( this * other.numerator, other.denominator ) - // endregion - // region Rational-constant relation /** * Returns sum of the constant represented as rational function and the rational function. */ @@ -209,9 +195,7 @@ public class NumberedRationalFunctionSpace> ( numerator * other, denominator ) - // endregion - // region Polynomial-rational relation /** * Returns sum of the polynomial represented as rational function and the rational function. */ @@ -236,9 +220,7 @@ public class NumberedRationalFunctionSpace> ( this * other.numerator, other.denominator ) - // endregion - // region Rational-polynomial relation /** * Returns sum of the polynomial represented as rational function and the rational function. */ @@ -263,9 +245,7 @@ public class NumberedRationalFunctionSpace> ( numerator * other, denominator ) - // endregion - // region Rational-rational relation /** * Returns negation of the rational function. */ @@ -325,9 +305,7 @@ public class NumberedRationalFunctionSpace> ( return numerator * other.denominator equalsTo other.numerator * denominator } - // endregion - // region Polynomial properties /** * Count of all variables that appear in the polynomial in positive exponents. */ @@ -340,17 +318,14 @@ public class NumberedRationalFunctionSpace> ( * And size of the list is [countOfVariables]. */ public val NumberedPolynomial.degrees: List get() = polynomialRing { degrees } - // endregion - // region Rational properties /** * Count of all variables that appear in the polynomial in positive exponents. */ public val NumberedRationalFunction.countOfVariables: Int get() = polynomialRing { max(numerator.countOfVariables, denominator.countOfVariables) } - // endregion - // region REST TODO: Разобрать + // TODO: Разобрать public operator fun NumberedRationalFunction.div(other: NumberedRationalFunction): NumberedRationalFunction = NumberedRationalFunction( 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 2f7976da6..3f3838f53 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 @@ -91,7 +91,6 @@ public fun C.asPolynomial() : Polynomial = Polynomial(listOf(this)) * @param A type of underlying ring of constants. It's [Ring] of [C]. * @param ring underlying ring of constants of type [A]. */ -//@Suppress("INAPPLICABLE_JVM_NAME") // TODO: KT-31420 public open class PolynomialSpace>( public override val ring: A, ) : AbstractPolynomialSpaceOverRing, A> { diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/RationalFunction.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/RationalFunction.kt index 441136a64..5ff3edd2e 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/RationalFunction.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/RationalFunction.kt @@ -18,8 +18,6 @@ public data class RationalFunction internal constructor ( override fun toString(): String = "RationalFunction${numerator.coefficients}/${denominator.coefficients}" } -// region Internal utilities - /** * Represents internal [RationalFunction] errors. */ @@ -35,9 +33,6 @@ internal class RationalFunctionError : Error { */ internal fun rationalFunctionError(message: Any): Nothing = throw RationalFunctionError(message.toString()) -// endregion - -// region Constructors and converters // Waiting for context receivers :( TODO: Replace with context receivers when they will be available //context(RationalFunctionSpace) @@ -63,8 +58,6 @@ internal fun rationalFunctionError(message: Any): Nothing = throw RationalFuncti // Polynomial( with(numeratorCoefficients) { if (reverse) reversed() else this } ) // ) -// endregion - public class RationalFunctionSpace> ( public val ring: A, ) : AbstractRationalFunctionalSpaceOverPolynomialSpace< @@ -76,7 +69,6 @@ public class RationalFunctionSpace> ( override val polynomialRing : PolynomialSpace = PolynomialSpace(ring) - // region Rational-integer relation /** * Returns sum of the rational function and the integer represented as rational function. * @@ -107,9 +99,7 @@ public class RationalFunctionSpace> ( numerator * other, denominator ) - // endregion - // region Integer-Rational relation /** * Returns sum of the integer represented as rational function and the rational function. * @@ -140,9 +130,7 @@ public class RationalFunctionSpace> ( this * other.numerator, other.denominator ) - // endregion - // region Constant-rational relation /** * Returns sum of the constant represented as rational function and the rational function. */ @@ -167,9 +155,7 @@ public class RationalFunctionSpace> ( this * other.numerator, other.denominator ) - // endregion - // region Rational-constant relation /** * Returns sum of the constant represented as rational function and the rational function. */ @@ -194,9 +180,7 @@ public class RationalFunctionSpace> ( numerator * other, denominator ) - // endregion - // region Polynomial-rational relation /** * Returns sum of the polynomial represented as rational function and the rational function. */ @@ -221,9 +205,7 @@ public class RationalFunctionSpace> ( this * other.numerator, other.denominator ) - // endregion - // region Rational-polynomial relation /** * Returns sum of the polynomial represented as rational function and the rational function. */ @@ -248,9 +230,7 @@ public class RationalFunctionSpace> ( numerator * other, denominator ) - // endregion - // region Rational-rational relation /** * Returns negation of the rational function. */ @@ -298,9 +278,8 @@ public class RationalFunctionSpace> ( numeratorDegree - denominatorDegree != with(other) { numeratorDegree - denominatorDegree } -> false else -> numerator * other.denominator equalsTo other.numerator * denominator } - // endregion - // region REST TODO: Разобрать + // TODO: Разобрать public operator fun RationalFunction.div(other: RationalFunction): RationalFunction = RationalFunction( @@ -383,5 +362,4 @@ public class RationalFunctionSpace> ( // numerator.removeZeros(), // denominator.removeZeros() // ) - // endregion } \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledPolynomialUtil.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledPolynomialUtil.kt index 516e76b8f..19417d767 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledPolynomialUtil.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledPolynomialUtil.kt @@ -17,10 +17,6 @@ import kotlin.contracts.contract // TODO: Docs -// region Sort of legacy - -//// region Constants -// //// TODO: Reuse underlying ring extensions // //context(LabeledPolynomialSpace) @@ -33,9 +29,7 @@ import kotlin.contracts.contract //context(LabeledPolynomialSpace) //fun > multiplyWithPower(base: C, arg: C, pow: UInt): C = ring { multiplyWithPower(base, arg, pow) } // -//// endregion -//// region Symbols // //context(LabeledPolynomialSpace) //fun > power(arg: Symbol, pow: UInt): LabeledPolynomial = @@ -44,9 +38,7 @@ import kotlin.contracts.contract // mapOf(arg to pow) to constantOne // )) // -//// endregion -//// region Polynomials // //context(LabeledPolynomialSpace) //fun > number(value: Int): LabeledPolynomial = ring { LabeledPolynomial(mapOf(emptyMap() to number(value))) } @@ -71,11 +63,6 @@ import kotlin.contracts.contract // else -> error("Error in raising ring instant by unsigned integer: got reminder by division by 2 different from 0 and 1") // } // -//// endregion - -// endregion - -// region Utilities /** * Crates a [LabeledPolynomialSpace] over received ring. @@ -92,10 +79,6 @@ public inline fun , R> A.labeledPolynomial(block: LabeledPolynomi return LabeledPolynomialSpace(this).block() } -// endregion - -//// region String representations -// ///** // * Represents the polynomial as a [String] with names of variables substituted with names from [names]. // * Consider that monomials are sorted in lexicographic order. @@ -261,13 +244,7 @@ public inline fun , R> A.labeledPolynomial(block: LabeledPolynomi //context(LabeledPolynomialSpace) //fun > LabeledPolynomial.representReversedWithBrackets(namer: (Symbol) -> String): String = // with(representReversed(namer)) { if (coefficients.count() == 1) this else "($this)" } -// -//// endregion -// region Operator extensions - -//// region Field case -// //operator fun > Polynomial.div(other: T): Polynomial = // if (other.isZero()) throw ArithmeticException("/ by zero") // else @@ -276,13 +253,7 @@ public inline fun , R> A.labeledPolynomial(block: LabeledPolynomi // .mapValues { it.value / other }, // toCheckInput = false // ) -// -//// endregion -// endregion - -//// region Polynomial substitution and functional representation -// //public fun LabeledPolynomial.substitute(ring: Ring, args: Map): LabeledPolynomial = ring { // if (coefficients.isEmpty()) return this@substitute // LabeledPolynomial( @@ -324,10 +295,6 @@ public inline fun , R> A.labeledPolynomial(block: LabeledPolynomi // //fun > LabeledPolynomial.asPolynomialFunctionOver(ring: A): (Map>) -> LabeledPolynomial = // { substitute(ring, it) } -// -//// endregion - -// region Algebraic derivative and antiderivative /** * Returns algebraic derivative of received polynomial. @@ -572,6 +539,4 @@ public fun > LabeledPolynomial.nthAntiderivativeWithRespectTo } } ) -} - -// endregion \ No newline at end of file +} \ No newline at end of file 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 575dfed48..61f443871 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 @@ -6,18 +6,10 @@ package space.kscience.kmath.functions -//// 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 +//} \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedPolynomialUtil.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedPolynomialUtil.kt index ac411fc28..b2778343d 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedPolynomialUtil.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedPolynomialUtil.kt @@ -9,10 +9,6 @@ import kotlin.math.max // TODO: Docs -// region Sort of legacy - -//// region Constants -// //// TODO: Reuse underlying ring extensions // //context(NumberedPolynomialSpace) @@ -21,11 +17,7 @@ import kotlin.math.max // //context(NumberedPolynomialSpace) //public fun > multiplyWithPower(base: C, arg: C, pow: UInt): C = ring { multiplyWithPower(base, arg, pow) } -// -//// endregion -//// region Polynomials -// //context(NumberedPolynomialSpace) //public fun > number(value: Int): NumberedPolynomial = ring { NumberedPolynomial(mapOf(emptyList() to number(value))) } // @@ -48,12 +40,6 @@ import kotlin.math.max // exponent % 2U == 1U -> multiplyWithPowerInternalLogic(base * arg, arg * arg, exponent / 2U) // else -> error("Error in raising ring instant by unsigned integer: got reminder by division by 2 different from 0 and 1") // } -// -//// endregion - -// endregion - -// region Utilities /** * Crates a [NumberedPolynomialSpace] over received ring. @@ -70,10 +56,6 @@ public inline fun , R> A.numberedPolynomial(block: NumberedPolyno return NumberedPolynomialSpace(this).block() } -// endregion - -//// region String representations -// ///** // * Represents the polynomial as a [String] where name of variable with index `i` is [withVariableName] + `"_${i+1}"`. // * Consider that monomials are sorted in lexicographic order. @@ -237,11 +219,7 @@ public inline fun , R> A.numberedPolynomial(block: NumberedPolyno //context(NumberedPolynomialSpace) //public fun > NumberedPolynomial.representReversedWithBrackets(namer: (Int) -> String): String = // with(representReversed(namer)) { if (coefficients.count() == 1) this else "($this)" } -// -//// endregion -//// region Polynomial substitution and functional representation -// //public fun NumberedPolynomial.substitute(ring: Ring, args: Map): NumberedPolynomial = ring { // if (coefficients.isEmpty()) return this@substitute // NumberedPolynomial( @@ -283,13 +261,7 @@ public inline fun , R> A.numberedPolynomial(block: NumberedPolyno // //public fun > NumberedPolynomial.asPolynomialFunctionOver(ring: A): (Map>) -> NumberedPolynomial = // { substitute(ring, it) } -// -//// endregion -// region Operator extensions - -//// region Field case -// //operator fun > Polynomial.div(other: T): Polynomial = // if (other.isZero()) throw ArithmeticException("/ by zero") // else @@ -298,12 +270,6 @@ public inline fun , R> A.numberedPolynomial(block: NumberedPolyno // .mapValues { it.value / other }, // toCheckInput = false // ) -// -//// endregion - -// endregion - -// region Polynomial substitution and functional representation // TODO: May be apply Horner's method too? /** @@ -368,10 +334,6 @@ public fun > NumberedPolynomial.asFunction(ring: A): (Map> NumberedPolynomial.asPolynomialFunctionOver(ring: A): (Map>) -> NumberedPolynomial = { substitute(ring, it) } -// endregion - -// region Algebraic derivative and antiderivative - /** * Returns algebraic derivative of received polynomial. */ @@ -596,6 +558,4 @@ public fun > NumberedPolynomial.nthAntiderivativeWithRespectT } } ) -} - -// endregion \ No newline at end of file +} \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedRationalFunctionUtil.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedRationalFunctionUtil.kt index 7c8120c68..035e201f7 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedRationalFunctionUtil.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedRationalFunctionUtil.kt @@ -6,18 +6,10 @@ package space.kscience.kmath.functions -//// region Operator extensions -// -//// region Field case -// //fun > NumberedRationalFunction.reduced(): NumberedRationalFunction { // val greatestCommonDivider = polynomialGCD(numerator, denominator) // return NumberedRationalFunction( // numerator / greatestCommonDivider, // denominator / greatestCommonDivider // ) -//} -// -//// endregion -// -//// endregion \ No newline at end of file +//} \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialUtil.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialUtil.kt index 2d0377d2c..e6d6b1ae6 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialUtil.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialUtil.kt @@ -14,8 +14,6 @@ import kotlin.math.min import kotlin.math.pow -// region Utilities - /** * Removes zeros on the end of the coefficient list of polynomial. */ @@ -51,10 +49,6 @@ public inline fun A.scalablePolynomial(block: ScalablePolynomialSpace< return ScalablePolynomialSpace(this).block() } -// endregion - -// region Polynomial substitution and functional representation - // TODO: May be apply Horner's method too? /** * Evaluates the value of the given double polynomial for given double argument. @@ -116,10 +110,6 @@ public fun > Polynomial.asFunction(ring: A): (C) -> C = { subs */ public fun > Polynomial.asPolynomialFunctionOver(ring: A): (Polynomial) -> Polynomial = { substitute(ring, it) } -// endregion - -// region Algebraic derivative and antiderivative - /** * Returns algebraic derivative of received polynomial. */ @@ -180,6 +170,4 @@ public fun > Polynomial.integrate( ): C = algebra { val integral = antiderivative(algebra) integral.substitute(algebra, range.endInclusive) - integral.substitute(algebra, range.start) -} - -// endregion \ No newline at end of file +} \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/rationalFunctionUtil.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/rationalFunctionUtil.kt index d5bbc3b82..359c781b5 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/rationalFunctionUtil.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/rationalFunctionUtil.kt @@ -6,10 +6,6 @@ package space.kscience.kmath.functions -// region Operator extensions - -// region Field case - //operator fun > RationalFunction.invoke(arg: T): T = numerator(arg) / denominator(arg) // //fun > RationalFunction.reduced(): RationalFunction = @@ -20,11 +16,6 @@ package space.kscience.kmath.functions // ) // } -// endregion - -// endregion - -// region Derivatives ///** // * Returns result of applying formal derivative to the polynomial. // * @@ -35,5 +26,4 @@ package space.kscience.kmath.functions // RationalFunction( // numerator.derivative() * denominator - denominator.derivative() * numerator, // denominator * denominator -// ) -// endregion \ No newline at end of file +// ) \ No newline at end of file