diff --git a/examples/src/main/kotlin/space/kscience/kmath/functions/polynomials.kt b/examples/src/main/kotlin/space/kscience/kmath/functions/polynomials.kt index 273fe5cb9..7843a0210 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/functions/polynomials.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/functions/polynomials.kt @@ -8,6 +8,7 @@ package space.kscience.kmath.functions import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.symbol import space.kscience.kmath.operations.algebra +import space.kscience.kmath.operations.invoke /** @@ -102,7 +103,7 @@ fun numberedPolynomialsExample() { numberedPolynomialSpace { // Also there is DSL for constructing NumberedPolynomials: - val polynomial5: NumberedPolynomial = NumberedPolynomial { + val polynomial5: NumberedPolynomial = NumberedPolynomialDSL1 { 3 {} 5 { 2 inPowerOf 1u } -7 with { 1 pow 2u; 3 pow 1u } @@ -116,7 +117,7 @@ fun numberedPolynomialsExample() { } } - val polynomial6: NumberedPolynomial = with(Int.algebra) { + val polynomial6: NumberedPolynomial = Int.algebra { NumberedPolynomial( listOf() to 7, listOf(0u, 1u) to -5, @@ -127,28 +128,28 @@ fun numberedPolynomialsExample() { // For every ring there can be provided a polynomial ring: Int.algebra.numberedPolynomialSpace { println( - -polynomial6 == NumberedPolynomial { - (-7) {} - 5 { 2 pow 1u } - 0 { 1 pow 2u; 3 pow 1u } - (-4) { 4 pow 4u } - } + -polynomial6 == NumberedPolynomial( + listOf() to -7, + listOf(0u, 1u) to 5, + listOf(2u, 0u, 1u) to 0, + listOf(0u, 0u, 0u, 4u) to (-4), + ) ) // true println( - polynomial1 + polynomial6 == NumberedPolynomial { - 10 {} - 0 { 2 pow 1u } - (-7) { 1 pow 2u; 3 pow 1u } - 4 { 4 pow 4u } - } + polynomial1 + polynomial6 == NumberedPolynomial( + listOf() to 10, + listOf(0u, 1u) to 0, + listOf(2u, 0u, 1u) to -7, + listOf(0u, 0u, 0u, 4u) to 4, + ) ) // true println( - polynomial1 - polynomial6 == NumberedPolynomial { - (-4) {} - 10 { 2 pow 1u } - (-7) { 1 pow 2u; 3 pow 1u } - (-4) { 4 pow 4u } - } + polynomial1 - polynomial6 == NumberedPolynomial( + listOf() to -4, + listOf(0u, 1u) to 10, + listOf(2u, 0u, 1u) to -7, + listOf(0u, 0u, 0u, 4u) to -4, + ) ) // true polynomial1 * polynomial6 // Multiplication works too @@ -156,14 +157,14 @@ fun numberedPolynomialsExample() { Double.algebra.numberedPolynomialSpace { // You can even write - val x_1: NumberedPolynomial = NumberedPolynomial { 1.0 { 1 pow 1u } } - val x_2: NumberedPolynomial = NumberedPolynomial { 1.0 { 2 pow 1u } } - val x_3: NumberedPolynomial = NumberedPolynomial { 1.0 { 3 pow 1u } } - val polynomial7: NumberedPolynomial = NumberedPolynomial { - 3.0 {} - 5.0 { 2 pow 1u } - (-7.0) { 1 pow 2u; 3 pow 1u } - } + val x_1: NumberedPolynomial = NumberedPolynomial(listOf(1u) to 1.0) + val x_2: NumberedPolynomial = NumberedPolynomial(listOf(0u, 1u) to 1.0) + val x_3: NumberedPolynomial = NumberedPolynomial(listOf(0u, 0u, 1u) to 1.0) + val polynomial7: NumberedPolynomial = NumberedPolynomial( + listOf() to 3.0, + listOf(0u, 1u) to 5.0, + listOf(2u, 0u, 1u) to -7.0, + ) Double.algebra.listPolynomialSpace { println(3 + 5 * x_2 - 7 * x_1 * x_1 * x_3 == polynomial7) println(3.0 + 5.0 * x_2 - 7.0 * x_1 * x_1 * x_3 == polynomial7) @@ -171,49 +172,49 @@ fun numberedPolynomialsExample() { } Int.algebra.numberedPolynomialSpace { - val x_4: NumberedPolynomial = NumberedPolynomial { 1 { 4 pow 1u } } + val x_4: NumberedPolynomial = NumberedPolynomial(listOf(0u, 0u, 0u, 4u) to 1) // Also there are some utilities for polynomials: println(polynomial1.substitute(mapOf(0 to 1, 1 to -2, 2 to -1)) == 0.asNumberedPolynomial()) // true, // because it's substitution x_1 -> 1, x_2 -> -2, x_3 -> -1, // so 3 + 5 x_2 - 7 x_1^2 x_3 = 3 + 5 * (-2) - 7 * 1^2 * (-1) = 3 - 10 + 7 = 0 println( - polynomial1.substitute(mapOf(1 to x_4)) == NumberedPolynomial { - 3 {} - 5 { 4 pow 1u } - (-7) { 1 pow 2u; 3 pow 1u } - } + polynomial1.substitute(mapOf(1 to x_4)) == NumberedPolynomial( + listOf() to 3, + listOf(0u, 1u) to 5, + listOf(2u, 0u, 1u) to -7, + ) ) // true, because it's substitution x_2 -> x_4, so result is 3 + 5 x_4 - 7 x_1^2 x_3 println( polynomial1.derivativeWithRespectTo(Int.algebra, 1) == - NumberedPolynomial { 5 {} } + NumberedPolynomial(listOf() to 5) ) // true, d/dx_2 (3 + 5 x_2 - 7 x_1^2 x_3) = 5 } // Lastly, there are rational functions and some other utilities: Double.algebra.numberedRationalFunctionSpace { val rationalFunction1: NumberedRationalFunction = NumberedRationalFunction( - NumberedPolynomial { - 2.0 {} - (-3.0) { 1 pow 1u } - 1.0 { 1 pow 2u } - }, - NumberedPolynomial { - 3.0 {} - (-1.0) { 1 pow 1u } - } + NumberedPolynomial( + listOf() to 2.0, + listOf(1u) to -3.0, + listOf(2u) to 1.0, + ), + NumberedPolynomial( + listOf() to 3.0, + listOf(1u) to -1.0, + ) ) // It's just (2 - 3x + x^2)/(3 - x) where x = x_1 val rationalFunction2: NumberedRationalFunction = NumberedRationalFunction( - NumberedPolynomial { - 5.0 {} - (-4.0) { 1 pow 1u } - 1.0 { 1 pow 2u } - }, - NumberedPolynomial { - 3.0 {} - (-1.0) { 1 pow 1u } - } + NumberedPolynomial( + listOf() to 5.0, + listOf(1u) to -4.0, + listOf(2u) to 1.0, + ), + NumberedPolynomial( + listOf() to 3.0, + listOf(1u) to -1.0, + ) ) // It's just (5 - 4x + x^2)/(3 - x) where x = x_1 @@ -267,7 +268,7 @@ fun labeledPolynomialsExample() { labeledPolynomialSpace { // Also there is DSL for constructing NumberedPolynomials: - val polynomial5: LabeledPolynomial = LabeledPolynomial { + val polynomial5: LabeledPolynomial = LabeledPolynomialDSL1 { 3 {} 5 { y inPowerOf 1u } -7 with { x pow 2u; z pow 1u } @@ -281,7 +282,7 @@ fun labeledPolynomialsExample() { } } - val polynomial6: LabeledPolynomial = with(Int.algebra) { + val polynomial6: LabeledPolynomial = Int.algebra { LabeledPolynomial( mapOf() to 7, mapOf(y to 1u) to -5, @@ -292,28 +293,28 @@ fun labeledPolynomialsExample() { // For every ring there can be provided a polynomial ring: Int.algebra.labeledPolynomialSpace { println( - -polynomial6 == LabeledPolynomial { - (-7) {} - 5 { y pow 1u } - 0 { x pow 2u; z pow 1u } - (-4) { t pow 4u } - } + -polynomial6 == LabeledPolynomial( + mapOf() to -7, + mapOf(y to 1u) to 5, + mapOf(x to 2u, z to 1u) to 0, + mapOf(t to 4u) to -4, + ) ) // true println( - polynomial1 + polynomial6 == LabeledPolynomial { - 10 {} - 0 { y pow 1u } - (-7) { x pow 2u; z pow 1u } - 4 { t pow 4u } - } + polynomial1 + polynomial6 == LabeledPolynomial( + mapOf() to 10, + mapOf(y to 1u) to 0, + mapOf(x to 2u, z to 1u) to -7, + mapOf(t to 4u) to 4, + ) ) // true println( - polynomial1 - polynomial6 == LabeledPolynomial { - (-4) {} - 10 { y pow 1u } - (-7) { x pow 2u; z pow 1u } - (-4) { t pow 4u } - } + polynomial1 - polynomial6 == LabeledPolynomial( + mapOf() to -4, + mapOf(y to 1u) to 10, + mapOf(x to 2u, z to 1u) to -7, + mapOf(t to 4u) to -4, + ) ) // true polynomial1 * polynomial6 // Multiplication works too @@ -321,11 +322,11 @@ fun labeledPolynomialsExample() { Double.algebra.labeledPolynomialSpace { // You can even write - val polynomial7: LabeledPolynomial = LabeledPolynomial { - 3.0 {} - 5.0 { y pow 1u } - (-7.0) { x pow 2u; z pow 1u } - } + val polynomial7: LabeledPolynomial = LabeledPolynomial( + mapOf() to 3.0, + mapOf(y to 1u) to 5.0, + mapOf(x to 2u, z to 1u) to -7.0, + ) Double.algebra.listPolynomialSpace { println(3 + 5 * y - 7 * x * x * z == polynomial7) println(3.0 + 5.0 * y - 7.0 * x * x * z == polynomial7) @@ -338,42 +339,42 @@ fun labeledPolynomialsExample() { // because it's substitution x -> 1, y -> -2, z -> -1, // so 3 + 5 y - 7 x^2 z = 3 + 5 * (-2) - 7 * 1^2 * (-1) = 3 - 10 + 7 = 0 println( - polynomial1.substitute(mapOf(y to t.asPolynomial())) == LabeledPolynomial { - 3 {} - 5 { t pow 1u } - (-7) { x pow 2u; z pow 1u } - } + polynomial1.substitute(mapOf(y to t.asPolynomial())) == LabeledPolynomial( + mapOf() to 3, + mapOf(t to 1u) to 5, + mapOf(x to 2u, z to 1u) to -7, + ) ) // true, because it's substitution y -> t, so result is 3 + 5 t - 7 x^2 z println( - polynomial1.derivativeWithRespectTo(Int.algebra, y) == LabeledPolynomial { 5 {} } + polynomial1.derivativeWithRespectTo(Int.algebra, y) == LabeledPolynomial(mapOf() to 5) ) // true, d/dy (3 + 5 y - 7 x^2 z) = 5 } // Lastly, there are rational functions and some other utilities: Double.algebra.labeledRationalFunctionSpace { val rationalFunction1: LabeledRationalFunction = LabeledRationalFunction( - LabeledPolynomial { - 2.0 {} - (-3.0) { x pow 1u } - 1.0 { x pow 2u } - }, - LabeledPolynomial { - 3.0 {} - (-1.0) { x pow 1u } - } + LabeledPolynomial( + mapOf() to 2.0, + mapOf(x to 1u) to -3.0, + mapOf(x to 2u) to 1.0, + ), + LabeledPolynomial( + mapOf() to 3.0, + mapOf(x to 1u) to -1.0, + ) ) // It's just (2 - 3x + x^2)/(3 - x) val rationalFunction2: LabeledRationalFunction = LabeledRationalFunction( - LabeledPolynomial { - 5.0 {} - (-4.0) { x pow 1u } - 1.0 { x pow 2u } - }, - LabeledPolynomial { - 3.0 {} - (-1.0) { x pow 1u } - } + LabeledPolynomial( + mapOf() to 5.0, + mapOf(x to 1u) to -4.0, + mapOf(x to 2u) to 1.0, + ), + LabeledPolynomial( + mapOf() to 3.0, + mapOf(x to 1u) to -1.0, + ) ) // It's just (5 - 4x + x^2)/(3 - x) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledConstructors.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledConstructors.kt index 7a8d961c0..8442d3f91 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledConstructors.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/labeledConstructors.kt @@ -274,14 +274,14 @@ public inline fun C.asLabeledPolynomial() : LabeledPolynomial = LabeledPo */ @DslMarker @UnstableKMathAPI -internal annotation class LabeledPolynomialConstructorDSL +internal annotation class LabeledPolynomialConstructorDSL1 /** * Builder of [LabeledPolynomial] signature. It should be used as an implicit context for lambdas that describe term signature. */ @UnstableKMathAPI -@LabeledPolynomialConstructorDSL -public class LabeledPolynomialTermSignatureBuilder { +@LabeledPolynomialConstructorDSL1 +public class DSL1LabeledPolynomialTermSignatureBuilder { /** * Signature storage. Any declaration of any variable's power updates the storage by increasing corresponding value. * Afterward the storage will be used as a resulting signature. @@ -302,7 +302,7 @@ public class LabeledPolynomialTermSignatureBuilder { * Declaring another power of the same variable will increase its degree by received degree. */ public infix fun Symbol.inPowerOf(deg: UInt) { - signature[this] = deg + signature[this] = signature.getOrElse(this) { 0u } + deg } /** * Declares power of [this] variable of degree [deg]. @@ -328,7 +328,8 @@ public class LabeledPolynomialTermSignatureBuilder { * Builder of [LabeledPolynomial]. It should be used as an implicit context for lambdas that describe [LabeledPolynomial]. */ @UnstableKMathAPI -public class LabeledPolynomialBuilder( +@LabeledPolynomialConstructorDSL1 +public class DSL1LabeledPolynomialBuilder( /** * Summation operation that will be used to sum coefficients of monomials of same signatures. */ @@ -367,15 +368,15 @@ public class LabeledPolynomialBuilder( * Declaring another monomial with the same signature will add [this] coefficient to existing one. If the sum of such * coefficients is zero at any moment the monomial won't be removed but will be left as it is. */ - public inline infix fun C.with(noinline block: LabeledPolynomialTermSignatureBuilder.() -> Unit): Unit = this.invoke(block) + public inline infix fun C.with(noinline block: DSL1LabeledPolynomialTermSignatureBuilder.() -> Unit): Unit = this.invoke(block) /** * Declares monomial with [this] coefficient and signature constructed by [block]. * * Declaring another monomial with the same signature will add [this] coefficient to existing one. If the sum of such * coefficients is zero at any moment the monomial won't be removed but will be left as it is. */ - public inline operator fun C.invoke(block: LabeledPolynomialTermSignatureBuilder.() -> Unit): Unit = - this with LabeledPolynomialTermSignatureBuilder().apply(block).build() + public inline operator fun C.invoke(block: DSL1LabeledPolynomialTermSignatureBuilder.() -> Unit): Unit = + this with DSL1LabeledPolynomialTermSignatureBuilder().apply(block).build() } // Waiting for context receivers :( FIXME: Replace with context receivers when they will be available @@ -398,7 +399,7 @@ public class LabeledPolynomialBuilder( // 2. Union types are implemented. Then all three functions should be rewritten // as one with single union type as a (context) receiver. //@UnstableKMathAPI -//public inline fun > A.LabeledPolynomial(initialCapacity: Int = 0, block: LabeledPolynomialBuilder.() -> Unit) : LabeledPolynomial = LabeledPolynomialBuilder(::add, initialCapacity).apply(block).build() +//public inline fun > A.LabeledPolynomialDSL1(initialCapacity: Int = 0, block: LabeledPolynomialBuilder.() -> Unit) : LabeledPolynomial = LabeledPolynomialBuilder(::add, initialCapacity).apply(block).build() /** * Creates [LabeledPolynomial] with lambda [block] in context of [this] ring of [LabeledPolynomial]s. * @@ -413,7 +414,7 @@ public class LabeledPolynomialBuilder( * ``` */ @UnstableKMathAPI -public inline fun > LabeledPolynomialSpace.LabeledPolynomial(initialCapacity: Int = 0, block: LabeledPolynomialBuilder.() -> Unit) : LabeledPolynomial = LabeledPolynomialBuilder({ left: C, right: C -> left + right }, initialCapacity).apply(block).build() +public inline fun > LabeledPolynomialSpace.LabeledPolynomialDSL1(initialCapacity: Int = 0, block: DSL1LabeledPolynomialBuilder.() -> Unit) : LabeledPolynomial = DSL1LabeledPolynomialBuilder({ left: C, right: C -> left + right }, initialCapacity).apply(block).build() /** * Creates [LabeledPolynomial] with lambda [block] in context of [this] field of [LabeledRationalFunction]s. * @@ -428,7 +429,7 @@ public inline fun > LabeledPolynomialSpace.LabeledPolynomial * ``` */ @UnstableKMathAPI -public inline fun > LabeledRationalFunctionSpace.LabeledPolynomial(initialCapacity: Int = 0, block: LabeledPolynomialBuilder.() -> Unit) : LabeledPolynomial = LabeledPolynomialBuilder({ left: C, right: C -> left + right }, initialCapacity).apply(block).build() +public inline fun > LabeledRationalFunctionSpace.LabeledPolynomialDSL1(initialCapacity: Int = 0, block: DSL1LabeledPolynomialBuilder.() -> Unit) : LabeledPolynomial = DSL1LabeledPolynomialBuilder({ left: C, right: C -> left + right }, initialCapacity).apply(block).build() // Waiting for context receivers :( FIXME: Replace with context receivers when they will be available diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedConstructors.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedConstructors.kt index 7f02ff1e3..8d2c9e617 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedConstructors.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/numberedConstructors.kt @@ -255,14 +255,14 @@ public inline fun C.asNumberedPolynomial() : NumberedPolynomial = Numbere */ @DslMarker @UnstableKMathAPI -internal annotation class NumberedPolynomialConstructorDSL +internal annotation class NumberedPolynomialConstructorDSL1 /** * Builder of [NumberedPolynomial] signature. It should be used as an implicit context for lambdas that describe term signature. */ @UnstableKMathAPI -@NumberedPolynomialConstructorDSL -public class NumberedPolynomialTermSignatureBuilder { +@NumberedPolynomialConstructorDSL1 +public class DSL1NumberedPolynomialTermSignatureBuilder { /** * Signature storage. Any declaration of any variable's power updates the storage by increasing corresponding value. * Afterward the storage will be used as a resulting signature. @@ -316,8 +316,8 @@ public class NumberedPolynomialTermSignatureBuilder { * Builder of [NumberedPolynomial]. It should be used as an implicit context for lambdas that describe [NumberedPolynomial]. */ @UnstableKMathAPI -@NumberedPolynomialConstructorDSL -public class NumberedPolynomialBuilder( +@NumberedPolynomialConstructorDSL1 +public class DSL1NumberedPolynomialBuilder( /** * Summation operation that will be used to sum coefficients of monomials of same signatures. */ @@ -356,15 +356,15 @@ public class NumberedPolynomialBuilder( * Declaring another monomial with the same signature will add [this] coefficient to existing one. If the sum of such * coefficients is zero at any moment the monomial won't be removed but will be left as it is. */ - public inline infix fun C.with(noinline block: NumberedPolynomialTermSignatureBuilder.() -> Unit): Unit = this.invoke(block) + public inline infix fun C.with(noinline block: DSL1NumberedPolynomialTermSignatureBuilder.() -> Unit): Unit = this.invoke(block) /** * Declares monomial with [this] coefficient and signature constructed by [block]. * * Declaring another monomial with the same signature will add [this] coefficient to existing one. If the sum of such * coefficients is zero at any moment the monomial won't be removed but will be left as it is. */ - public inline operator fun C.invoke(block: NumberedPolynomialTermSignatureBuilder.() -> Unit): Unit = - this with NumberedPolynomialTermSignatureBuilder().apply(block).build() + public inline operator fun C.invoke(block: DSL1NumberedPolynomialTermSignatureBuilder.() -> Unit): Unit = + this with DSL1NumberedPolynomialTermSignatureBuilder().apply(block).build() } // Waiting for context receivers :( FIXME: Replace with context receivers when they will be available @@ -387,7 +387,7 @@ public class NumberedPolynomialBuilder( // 2. Union types are implemented. Then all three functions should be rewritten // as one with single union type as a (context) receiver. //@UnstableKMathAPI -//public inline fun > A.NumberedPolynomial(initialCapacity: Int = 0, block: NumberedPolynomialBuilder.() -> Unit) : NumberedPolynomial = NumberedPolynomialBuilder(::add, initialCapacity).apply(block).build() +//public inline fun > A.NumberedPolynomialDSL1(initialCapacity: Int = 0, block: NumberedPolynomialBuilder.() -> Unit) : NumberedPolynomial = NumberedPolynomialBuilder(::add, initialCapacity).apply(block).build() /** * Creates [NumberedPolynomial] with lambda [block] in context of [this] ring of [NumberedPolynomial]s. * @@ -402,7 +402,7 @@ public class NumberedPolynomialBuilder( * ``` */ @UnstableKMathAPI -public inline fun > NumberedPolynomialSpace.NumberedPolynomial(initialCapacity: Int = 0, block: NumberedPolynomialBuilder.() -> Unit) : NumberedPolynomial = NumberedPolynomialBuilder({ left: C, right: C -> left + right }, initialCapacity).apply(block).build() +public inline fun > NumberedPolynomialSpace.NumberedPolynomialDSL1(initialCapacity: Int = 0, block: DSL1NumberedPolynomialBuilder.() -> Unit) : NumberedPolynomial = DSL1NumberedPolynomialBuilder({ left: C, right: C -> left + right }, initialCapacity).apply(block).build() /** * Creates [NumberedPolynomial] with lambda [block] in context of [this] field of [NumberedRationalFunction]s. * @@ -417,7 +417,7 @@ public inline fun > NumberedPolynomialSpace.NumberedPolynomi * ``` */ @UnstableKMathAPI -public inline fun > NumberedRationalFunctionSpace.NumberedPolynomial(initialCapacity: Int = 0, block: NumberedPolynomialBuilder.() -> Unit) : NumberedPolynomial = NumberedPolynomialBuilder({ left: C, right: C -> left + right }, initialCapacity).apply(block).build() +public inline fun > NumberedRationalFunctionSpace.NumberedPolynomialDSL1(initialCapacity: Int = 0, block: DSL1NumberedPolynomialBuilder.() -> Unit) : NumberedPolynomial = DSL1NumberedPolynomialBuilder({ left: C, right: C -> left + right }, initialCapacity).apply(block).build() // Waiting for context receivers :( FIXME: Replace with context receivers when they will be available diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/NumberedConstructorsTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/NumberedConstructorsTest.kt index 8d1b128cf..f9a5a041b 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/NumberedConstructorsTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/NumberedConstructorsTest.kt @@ -15,14 +15,14 @@ import kotlin.test.assertEquals class NumberedConstructorsTest { @Test @UnstableKMathAPI - fun testBuilder() { + fun testDSL1() { assertEquals( NumberedPolynomialAsIs( listOf(2u, 0u, 3u) to 5, listOf(0u, 1u) to -6, ), Int.algebra.numberedPolynomialSpace { - NumberedPolynomial { + NumberedPolynomialDSL1 { 5 { 1 pow 2u; 3 pow 3u } (-6) { 2 pow 1u } } @@ -34,7 +34,7 @@ class NumberedConstructorsTest { listOf() to -1, ), Int.algebra.numberedPolynomialSpace { - NumberedPolynomial { + NumberedPolynomialDSL1 { 5 { } (-6) { } } @@ -46,7 +46,7 @@ class NumberedConstructorsTest { listOf(2u) to -1, ), Int.algebra.numberedPolynomialSpace { - NumberedPolynomial { + NumberedPolynomialDSL1 { 5 { 1 pow 1u; 1 pow 1u } (-6) { 1 pow 2u } } @@ -58,7 +58,7 @@ class NumberedConstructorsTest { listOf(2u) to -1, ), Int.algebra.numberedPolynomialSpace { - NumberedPolynomial { + NumberedPolynomialDSL1 { 5 { 1 pow 1u; 1 pow 1u } (-6) { 1 pow 2u; 3 pow 0u } } diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/NumberedPolynomialTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/NumberedPolynomialTest.kt index dac7c1a62..f0a1128b4 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/NumberedPolynomialTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/NumberedPolynomialTest.kt @@ -14,84 +14,85 @@ import kotlin.test.* @UnstableKMathAPI class NumberedPolynomialTest { + private val o = Rational(0) @Test fun test_Polynomial_Int_plus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(5, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + -3, + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(5, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + -3, "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-3, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + -3, + NumberedPolynomial( + listOf() to Rational(-3, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + -3, "test 2" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + -3, + NumberedPolynomial( + listOf() to Rational(0, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + -3, "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + -3, + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ) + -3, "test 4" ) - val polynomial_5 = NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_5 = NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_5, polynomial_5 + 0, "test 5" ) - val polynomial_6 = NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_6 = NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_6, polynomial_6 + 0, "test 6" ) - val polynomial_7 = NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_7 = NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_7, polynomial_7 + 0, @@ -103,80 +104,80 @@ class NumberedPolynomialTest { fun test_Polynomial_Int_minus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(5, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - 3, + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(5, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - 3, "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-3, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - 3, + NumberedPolynomial( + listOf() to Rational(-3, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - 3, "test 2" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - 3, + NumberedPolynomial( + listOf() to Rational(0, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - 3, "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - 3, + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ) - 3, "test 4" ) - val polynomial_5 = NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_5 = NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_5, polynomial_5 - 0, "test 5" ) - val polynomial_6 = NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_6 = NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_6, polynomial_6 - 0, "test 6" ) - val polynomial_7 = NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_7 = NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_7, polynomial_7 - 0, @@ -188,46 +189,46 @@ class NumberedPolynomialTest { fun test_Polynomial_Int_times() { IntModuloRing(35).numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - m(34) with {} - m(2) with { 1 pow 3u } - m(1) with { 2 pow 1u } - m(20) with { 1 pow 1u } - m(2) with { 3 pow 2u } - }, - NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - } * 27, + NumberedPolynomial( + listOf() to m(34), + listOf(3u) to m(2), + listOf(0u, 1u) to m(1), + listOf(1u) to m(20), + listOf(0u, 0u, 2u) to m(2), + ), + NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ) * 27, "test 1" ) assertEquals( - NumberedPolynomial { - m(0) with {} - m(0) with { 1 pow 3u } - m(0) with { 2 pow 1u } - m(0) with { 1 pow 1u } - m(0) with { 3 pow 2u } - }, - NumberedPolynomial { - m(7) with {} - m(0) with { 1 pow 3u } - m(49) with { 2 pow 1u } - m(21) with { 1 pow 1u } - m(14) with { 3 pow 2u } - } * 15, + NumberedPolynomial( + listOf() to m(0), + listOf(3u) to m(0), + listOf(0u, 1u) to m(0), + listOf(1u) to m(0), + listOf(0u, 0u, 2u) to m(0), + ), + NumberedPolynomial( + listOf() to m(7), + listOf(3u) to m(0), + listOf(0u, 1u) to m(49), + listOf(1u) to m(21), + listOf(0u, 0u, 2u) to m(14), + ) * 15, "test 2" ) - val polynomial = NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - } + val polynomial = NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ) assertSame( zero, polynomial * 0, @@ -244,80 +245,80 @@ class NumberedPolynomialTest { fun test_Int_Polynomial_plus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - -3 + NumberedPolynomial { - Rational(5, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + -3 + NumberedPolynomial( + listOf() to Rational(5, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-3, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - -3 + NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(-3, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + -3 + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 2" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - -3 + NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + -3 + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - -3 + NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), + -3 + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), "test 4" ) - val polynomial_5 = NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_5 = NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_5, 0 + polynomial_5, "test 5" ) - val polynomial_6 = NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_6 = NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_6, 0 + polynomial_6, "test 6" ) - val polynomial_7 = NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + val polynomial_7 = NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) assertSame( polynomial_7, 0 + polynomial_7, @@ -329,91 +330,91 @@ class NumberedPolynomialTest { fun test_Int_Polynomial_minus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(22, 9) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - 3 - NumberedPolynomial { - Rational(5, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(22, 9), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + 3 - NumberedPolynomial( + listOf() to Rational(5, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(3, 1) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - 3 - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(3, 1), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + 3 - NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 2" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - 3 - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0, 1), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + 3 - NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - 3 - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), + 3 - NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), "test 4" ) assertEquals( - NumberedPolynomial { - Rational(22, 9) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - 0 - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(22, 9), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + 0 - NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 5" ) assertEquals( - NumberedPolynomial { - Rational(0, 9) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - 0 - NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + 0 - NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 6" ) assertEquals( - NumberedPolynomial { - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - 0 - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + 0 - NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 7" ) } @@ -422,46 +423,46 @@ class NumberedPolynomialTest { fun test_Int_Polynomial_times() { IntModuloRing(35).numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - m(34) with {} - m(2) with { 1 pow 3u } - m(1) with { 2 pow 1u } - m(20) with { 1 pow 1u } - m(2) with { 3 pow 2u } - }, - 27 * NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - }, + NumberedPolynomial( + listOf() to m(34), + listOf(3u) to m(2), + listOf(0u, 1u) to m(1), + listOf(1u) to m(20), + listOf(0u, 0u, 2u) to m(2), + ), + 27 * NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ), "test 1" ) assertEquals( - NumberedPolynomial { - m(0) with {} - m(0) with { 1 pow 3u } - m(0) with { 2 pow 1u } - m(0) with { 1 pow 1u } - m(0) with { 3 pow 2u } - }, - 15 * NumberedPolynomial { - m(7) with {} - m(0) with { 1 pow 3u } - m(49) with { 2 pow 1u } - m(21) with { 1 pow 1u } - m(14) with { 3 pow 2u } - }, + NumberedPolynomial( + listOf() to m(0), + listOf(3u) to m(0), + listOf(0u, 1u) to m(0), + listOf(1u) to m(0), + listOf(0u, 0u, 2u) to m(0), + ), + 15 * NumberedPolynomial( + listOf() to m(7), + listOf(3u) to m(0), + listOf(0u, 1u) to m(49), + listOf(1u) to m(21), + listOf(0u, 0u, 2u) to m(14), + ), "test 2" ) - val polynomial = NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - } + val polynomial = NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ) assertSame( zero, 0 * polynomial, @@ -478,92 +479,91 @@ class NumberedPolynomialTest { fun test_Polynomial_Constant_plus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(5, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + Rational(-3), + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(5, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + Rational(-3), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-3, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + Rational(-3), + NumberedPolynomial( + listOf() to Rational(-3, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + Rational(-3), "test 2" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + Rational(-3), + NumberedPolynomial( + listOf() to Rational(0, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + Rational(-3), "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + Rational(-3), + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ) + Rational(-3), "test 4" ) assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + Rational(0), + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + Rational(0), "test 5" ) assertEquals( - NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + Rational(0), + NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + Rational(0), "test 6" ) assertEquals( - NumberedPolynomial { - Rational(0) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } + Rational(0), + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) + Rational(0), "test 7" ) } @@ -572,92 +572,91 @@ class NumberedPolynomialTest { fun test_Polynomial_Constant_minus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(5, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - Rational(3), + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(5, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - Rational(3), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-3, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - Rational(3), + NumberedPolynomial( + listOf() to Rational(-3, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - Rational(3), "test 2" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - Rational(3), + NumberedPolynomial( + listOf() to Rational(0, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - Rational(3), "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - Rational(3), + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ) - Rational(3), "test 4" ) assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - Rational(0), + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - Rational(0), "test 5" ) assertEquals( - NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - Rational(0), + NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - Rational(0), "test 6" ) assertEquals( - NumberedPolynomial { - Rational(0) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - } - Rational(0), + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ) - Rational(0), "test 7" ) } @@ -666,71 +665,71 @@ class NumberedPolynomialTest { fun test_Polynomial_Constant_times() { IntModuloRing(35).numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - m(34) with {} - m(2) with { 1 pow 3u } - m(1) with { 2 pow 1u } - m(20) with { 1 pow 1u } - m(2) with { 3 pow 2u } - }, - NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - } * m(27), + NumberedPolynomial( + listOf() to m(34), + listOf(3u) to m(2), + listOf(0u, 1u) to m(1), + listOf(1u) to m(20), + listOf(0u, 0u, 2u) to m(2), + ), + NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ) * m(27), "test 1" ) assertEquals( - NumberedPolynomial { - m(0) with {} - m(0) with { 1 pow 3u } - m(0) with { 2 pow 1u } - m(0) with { 1 pow 1u } - m(0) with { 3 pow 2u } - }, - NumberedPolynomial { - m(7) with {} - m(0) with { 1 pow 3u } - m(49) with { 2 pow 1u } - m(21) with { 1 pow 1u } - m(14) with { 3 pow 2u } - } * m(15), + NumberedPolynomial( + listOf() to m(0), + listOf(3u) to m(0), + listOf(0u, 1u) to m(0), + listOf(1u) to m(0), + listOf(0u, 0u, 2u) to m(0), + ), + NumberedPolynomial( + listOf() to m(7), + listOf(3u) to m(0), + listOf(0u, 1u) to m(49), + listOf(1u) to m(21), + listOf(0u, 0u, 2u) to m(14), + ) * m(15), "test 2" ) assertEquals( - NumberedPolynomial { - m(0) with {} - m(0) with { 1 pow 3u } - m(0) with { 2 pow 1u } - m(0) with { 1 pow 1u } - m(0) with { 3 pow 2u } - }, - NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - } * m(0), + NumberedPolynomial( + listOf() to m(0), + listOf(3u) to m(0), + listOf(0u, 1u) to m(0), + listOf(1u) to m(0), + listOf(0u, 0u, 2u) to m(0), + ), + NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ) * m(0), "test 3" ) assertEquals( - NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - }, - NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - } * m(1), + NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ), + NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ) * m(1), "test 4" ) } @@ -739,92 +738,91 @@ class NumberedPolynomialTest { fun test_Constant_Polynomial_plus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - Rational(-3) + NumberedPolynomial { - Rational(5, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + Rational(-3) + NumberedPolynomial( + listOf() to Rational(5, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-3, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - Rational(-3) + NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(-3, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + Rational(-3) + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 2" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - Rational(-3) + NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0, 1), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + Rational(-3) + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - Rational(-3) + NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), + Rational(-3) + NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), "test 4" ) assertEquals( - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - Rational(0) + NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + Rational(0) + NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 5" ) assertEquals( - NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - Rational(0) + NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + Rational(0) + NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 6" ) assertEquals( - NumberedPolynomial { - Rational(0) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, - Rational(0) + NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), + Rational(0) + NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 7" ) } @@ -833,92 +831,92 @@ class NumberedPolynomialTest { fun test_Constant_Polynomial_minus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(22, 9) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - Rational(3) - NumberedPolynomial { - Rational(5, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(22, 9), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + Rational(3) - NumberedPolynomial( + listOf() to Rational(5, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(3, 1) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - Rational(3) - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(3, 1), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + Rational(3) - NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 2" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - Rational(3) - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0, 1), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + Rational(3) - NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0, 1) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - Rational(3) - NumberedPolynomial { - Rational(27, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), + Rational(3) - NumberedPolynomial( + listOf() to Rational(27, 9), + listOf(3u) to Rational(0), + listOf(0u, 4u) to Rational(0), + ), "test 4" ) assertEquals( - NumberedPolynomial { - Rational(22, 9) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - Rational(0) - NumberedPolynomial { - Rational(-22, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(22, 9), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + Rational(0) - NumberedPolynomial( + listOf() to Rational(-22, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 5" ) assertEquals( - NumberedPolynomial { - Rational(0, 9) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - Rational(0) - NumberedPolynomial { - Rational(0, 9) with {} - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + Rational(0) - NumberedPolynomial( + listOf() to Rational(0, 9), + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 6" ) assertEquals( - NumberedPolynomial { - Rational(0) with {} - Rational(8, 9) with { 1 pow 3u } - Rational(8, 7) with { 2 pow 4u } - }, - Rational(0) - NumberedPolynomial { - Rational(-8, 9) with { 1 pow 3u } - Rational(-8, 7) with { 2 pow 4u } - }, + NumberedPolynomial( + listOf() to Rational(0), + listOf(3u) to Rational(8, 9), + listOf(0u, 4u) to Rational(8, 7), + ), + Rational(0) - NumberedPolynomial( + listOf(3u) to Rational(-8, 9), + listOf(0u, 4u) to Rational(-8, 7), + ), "test 7" ) } @@ -927,71 +925,71 @@ class NumberedPolynomialTest { fun test_Constant_Polynomial_times() { IntModuloRing(35).numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - m(34) with {} - m(2) with { 1 pow 3u } - m(1) with { 2 pow 1u } - m(20) with { 1 pow 1u } - m(2) with { 3 pow 2u } - }, - m(27) * NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - }, + NumberedPolynomial( + listOf() to m(34), + listOf(3u) to m(2), + listOf(0u, 1u) to m(1), + listOf(1u) to m(20), + listOf(0u, 0u, 2u) to m(2), + ), + m(27) * NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ), "test 1" ) assertEquals( - NumberedPolynomial { - m(0) with {} - m(0) with { 1 pow 3u } - m(0) with { 2 pow 1u } - m(0) with { 1 pow 1u } - m(0) with { 3 pow 2u } - }, - m(15) * NumberedPolynomial { - m(7) with {} - m(0) with { 1 pow 3u } - m(49) with { 2 pow 1u } - m(21) with { 1 pow 1u } - m(14) with { 3 pow 2u } - }, + NumberedPolynomial( + listOf() to m(0), + listOf(3u) to m(0), + listOf(0u, 1u) to m(0), + listOf(1u) to m(0), + listOf(0u, 0u, 2u) to m(0), + ), + m(15) * NumberedPolynomial( + listOf() to m(7), + listOf(3u) to m(0), + listOf(0u, 1u) to m(49), + listOf(1u) to m(21), + listOf(0u, 0u, 2u) to m(14), + ), "test 2" ) assertEquals( - NumberedPolynomial { - m(0) with {} - m(0) with { 1 pow 3u } - m(0) with { 2 pow 1u } - m(0) with { 1 pow 1u } - m(0) with { 3 pow 2u } - }, - m(0) * NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - }, + NumberedPolynomial( + listOf() to m(0), + listOf(3u) to m(0), + listOf(0u, 1u) to m(0), + listOf(1u) to m(0), + listOf(0u, 0u, 2u) to m(0), + ), + m(0) * NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ), "test 3" ) assertEquals( - NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - }, - m(1) * NumberedPolynomial { - m(22) with {} - m(26) with { 1 pow 3u } - m(13) with { 2 pow 1u } - m(15) with { 1 pow 1u } - m(26) with { 3 pow 2u } - }, + NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ), + m(1) * NumberedPolynomial( + listOf() to m(22), + listOf(3u) to m(26), + listOf(0u, 1u) to m(13), + listOf(1u) to m(15), + listOf(0u, 0u, 2u) to m(26), + ), "test 4" ) } @@ -1000,33 +998,33 @@ class NumberedPolynomialTest { fun test_Polynomial_unaryMinus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-5, 9) with { 1 pow 5u } - Rational(8, 9) with {} - Rational(8, 7) with { 7 pow 13u } - }, - -NumberedPolynomial { - Rational(5, 9) with { 1 pow 5u } - Rational(-8, 9) with {} - Rational(-8, 7) with { 7 pow 13u } - }, + NumberedPolynomial( + listOf(5u) to Rational(-5, 9), + listOf() to Rational(8, 9), + listOf(0u, 0u, 0u, 0u, 0u, 0u, 13u) to Rational(8, 7), + ), + -NumberedPolynomial( + listOf(5u) to Rational(5, 9), + listOf() to Rational(-8, 9), + listOf(0u, 0u, 0u, 0u, 0u, 0u, 13u) to Rational(-8, 7), + ), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-5, 9) with { 3 pow 7u } - Rational(8, 9) with {} - Rational(8, 7) with { 1 pow 3u } - Rational(0) with { 2 pow 4u } - Rational(0) with { 1 pow 5u } - }, - -NumberedPolynomial { - Rational(5, 9) with { 3 pow 7u } - Rational(-8, 9) with {} - Rational(-8, 7) with { 1 pow 3u } - Rational(0) with { 2 pow 4u } - Rational(0) with { 1 pow 5u } - }, + NumberedPolynomial( + listOf(5u) to Rational(-5, 9), + listOf() to Rational(8, 9), + listOf(0u, 0u, 0u, 0u, 0u, 0u, 13u) to Rational(8, 7), + listOf(0u, 4u) to Rational(0), + listOf(5u) to Rational(0), + ), + -NumberedPolynomial( + listOf(5u) to Rational(5, 9), + listOf() to Rational(-8, 9), + listOf(0u, 0u, 0u, 0u, 0u, 0u, 13u) to Rational(-8, 7), + listOf(0u, 4u) to Rational(0), + listOf(5u) to Rational(0), + ), "test 2" ) } @@ -1035,137 +1033,137 @@ class NumberedPolynomialTest { fun test_Polynomial_Polynomial_plus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-17, 2) with {} - Rational(-1, 3) with { 1 pow 1u } - Rational(-25, 21) with { 1 pow 2u } - Rational(146, 63) with { 2 pow 1u } - Rational(-3, 5) with { 1 pow 1u; 2 pow 1u } - Rational(61, 15) with { 1 pow 2u; 2 pow 1u } - Rational(157, 63) with { 2 pow 2u } - Rational(-55, 21) with { 1 pow 1u; 2 pow 2u } - Rational(11, 24) with { 1 pow 2u; 2 pow 2u } - }, - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(17, 7) with { 2 pow 1u } - Rational(-7, 7) with { 1 pow 1u; 2 pow 1u } - Rational(12, 5) with { 1 pow 2u; 2 pow 1u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - } + NumberedPolynomial { - Rational(-20, 2) with {} - Rational(0, 9) with { 1 pow 1u } - Rational(-20, 7) with { 1 pow 2u } - Rational(-1, 9) with { 2 pow 1u } - Rational(2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(7, 9) with { 2 pow 2u } - Rational(5, 7) with { 1 pow 1u; 2 pow 2u } - Rational(-2, 3) with { 1 pow 2u; 2 pow 2u } - }, + NumberedPolynomial( + listOf() to Rational(-17, 2), + listOf(1u) to Rational(-1, 3), + listOf(2u) to Rational(-25, 21), + listOf(0u, 1u) to Rational(146, 63), + listOf(1u, 1u) to Rational(-3, 5), + listOf(2u, 1u) to Rational(61, 15), + listOf(0u, 2u) to Rational(157, 63), + listOf(1u, 2u) to Rational(-55, 21), + listOf(2u, 2u) to Rational(11, 24), + ), + NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 1u) to Rational(17, 7), + listOf(1u, 1u) to Rational(-7, 7), + listOf(2u, 1u) to Rational(12, 5), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ) + NumberedPolynomial( + listOf() to Rational(-20, 2), + listOf(1u) to Rational(0, 9), + listOf(2u) to Rational(-20, 7), + listOf(0u, 1u) to Rational(-1, 9), + listOf(1u, 1u) to Rational(2, 5), + listOf(2u, 1u) to Rational(10, 6), + listOf(0u, 2u) to Rational(7, 9), + listOf(1u, 2u) to Rational(5, 7), + listOf(2u, 2u) to Rational(-2, 3), + ), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-17, 2) with {} - Rational(-1, 3) with { 1 pow 1u } - Rational(-25, 21) with { 1 pow 2u } - Rational(-1, 9) with { 2 pow 1u } - Rational(2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(157, 63) with { 2 pow 2u } - Rational(-55, 21) with { 1 pow 1u; 2 pow 2u } - Rational(11, 24) with { 1 pow 2u; 2 pow 2u } - }, - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - } + NumberedPolynomial { - Rational(-20, 2) with {} - Rational(0, 9) with { 1 pow 1u } - Rational(-20, 7) with { 1 pow 2u } - Rational(-1, 9) with { 2 pow 1u } - Rational(2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(7, 9) with { 2 pow 2u } - Rational(5, 7) with { 1 pow 1u; 2 pow 2u } - Rational(-2, 3) with { 1 pow 2u; 2 pow 2u } - }, + NumberedPolynomial( + listOf() to Rational(-17, 2), + listOf(1u) to Rational(-1, 3), + listOf(2u) to Rational(-25, 21), + listOf(0u, 1u) to Rational(-1, 9), + listOf(1u, 1u) to Rational(2, 5), + listOf(2u, 1u) to Rational(10, 6), + listOf(0u, 2u) to Rational(157, 63), + listOf(1u, 2u) to Rational(-55, 21), + listOf(2u, 2u) to Rational(11, 24), + ), + NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ) + NumberedPolynomial( + listOf() to Rational(-20, 2), + listOf(1u) to Rational(0, 9), + listOf(2u) to Rational(-20, 7), + listOf(0u, 1u) to Rational(-1, 9), + listOf(1u, 1u) to Rational(2, 5), + listOf(2u, 1u) to Rational(10, 6), + listOf(0u, 2u) to Rational(7, 9), + listOf(1u, 2u) to Rational(5, 7), + listOf(2u, 2u) to Rational(-2, 3), + ), "test 2" ) assertEquals( - NumberedPolynomial { - Rational(-17, 2) with {} - Rational(-1, 3) with { 1 pow 1u } - Rational(-25, 21) with { 1 pow 2u } - Rational(-1, 9) with { 2 pow 1u } - Rational(2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - }, - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - } + NumberedPolynomial { - Rational(-20, 2) with {} - Rational(0, 9) with { 1 pow 1u } - Rational(-20, 7) with { 1 pow 2u } - Rational(-1, 9) with { 2 pow 1u } - Rational(2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(0) with { 2 pow 2u } - Rational(0) with { 1 pow 1u; 2 pow 2u } - Rational(0) with { 1 pow 2u; 2 pow 2u } - }, + NumberedPolynomial( + listOf() to Rational(-17, 2), + listOf(1u) to Rational(-1, 3), + listOf(2u) to Rational(-25, 21), + listOf(0u, 1u) to Rational(-1, 9), + listOf(1u, 1u) to Rational(2, 5), + listOf(2u, 1u) to Rational(10, 6), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ), + NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ) + NumberedPolynomial( + listOf() to Rational(-20, 2), + listOf(1u) to Rational(0, 9), + listOf(2u) to Rational(-20, 7), + listOf(0u, 1u) to Rational(-1, 9), + listOf(1u, 1u) to Rational(2, 5), + listOf(2u, 1u) to Rational(10, 6), + listOf(0u, 2u) to Rational(0), + listOf(1u, 2u) to Rational(0), + listOf(2u, 2u) to Rational(0), + ), "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0) with {} - Rational(0) with { 1 pow 1u } - Rational(0) with { 1 pow 2u } - Rational(0) with { 2 pow 1u } - Rational(0) with { 1 pow 1u; 2 pow 1u } - Rational(0) with { 1 pow 2u; 2 pow 1u } - Rational(0) with { 2 pow 2u } - Rational(0) with { 1 pow 1u; 2 pow 2u } - Rational(0) with { 1 pow 2u; 2 pow 2u } - }, - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(17, 7) with { 2 pow 1u } - Rational(-7, 7) with { 1 pow 1u; 2 pow 1u } - Rational(12, 5) with { 1 pow 2u; 2 pow 1u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - } + NumberedPolynomial { - Rational(-6, 4) with {} - Rational(2, 6) with { 1 pow 1u } - Rational(-10, 6) with { 1 pow 2u } - Rational(-17, 7) with { 2 pow 1u } - Rational(7, 7) with { 1 pow 1u; 2 pow 1u } - Rational(-12, 5) with { 1 pow 2u; 2 pow 1u } - Rational(-12, 7) with { 2 pow 2u } - Rational(10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(-9, 8) with { 1 pow 2u; 2 pow 2u } - }, + NumberedPolynomial( + listOf() to Rational(0), + listOf(1u) to Rational(0), + listOf(2u) to Rational(0), + listOf(0u, 1u) to Rational(0), + listOf(1u, 1u) to Rational(0), + listOf(2u, 1u) to Rational(0), + listOf(0u, 2u) to Rational(0), + listOf(1u, 2u) to Rational(0), + listOf(2u, 2u) to Rational(0), + ), + NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 1u) to Rational(17, 7), + listOf(1u, 1u) to Rational(-7, 7), + listOf(2u, 1u) to Rational(12, 5), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ) + NumberedPolynomial( + listOf() to Rational(-6, 4), + listOf(1u) to Rational(2, 6), + listOf(2u) to Rational(-10, 6), + listOf(0u, 1u) to Rational(-17, 7), + listOf(1u, 1u) to Rational(7, 7), + listOf(2u, 1u) to Rational(-12, 5), + listOf(0u, 2u) to Rational(-12, 7), + listOf(1u, 2u) to Rational(10, 3), + listOf(2u, 2u) to Rational(-9, 8), + ), "test 4" ) } @@ -1174,137 +1172,137 @@ class NumberedPolynomialTest { fun test_Polynomial_Polynomial_minus() { RationalField.numberedPolynomialSpace { assertEquals( - NumberedPolynomial { - Rational(-17, 2) with {} - Rational(-1, 3) with { 1 pow 1u } - Rational(-25, 21) with { 1 pow 2u } - Rational(146, 63) with { 2 pow 1u } - Rational(-3, 5) with { 1 pow 1u; 2 pow 1u } - Rational(61, 15) with { 1 pow 2u; 2 pow 1u } - Rational(157, 63) with { 2 pow 2u } - Rational(-55, 21) with { 1 pow 1u; 2 pow 2u } - Rational(11, 24) with { 1 pow 2u; 2 pow 2u } - }, - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(17, 7) with { 2 pow 1u } - Rational(-7, 7) with { 1 pow 1u; 2 pow 1u } - Rational(12, 5) with { 1 pow 2u; 2 pow 1u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - } - NumberedPolynomial { - Rational(20, 2) with {} - Rational(0, 9) with { 1 pow 1u } - Rational(20, 7) with { 1 pow 2u } - Rational(1, 9) with { 2 pow 1u } - Rational(-2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(-10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(-7, 9) with { 2 pow 2u } - Rational(-5, 7) with { 1 pow 1u; 2 pow 2u } - Rational(2, 3) with { 1 pow 2u; 2 pow 2u } - }, + NumberedPolynomial( + listOf() to Rational(-17, 2), + listOf(1u) to Rational(-1, 3), + listOf(2u) to Rational(-25, 21), + listOf(0u, 1u) to Rational(146, 63), + listOf(1u, 1u) to Rational(-3, 5), + listOf(2u, 1u) to Rational(61, 15), + listOf(0u, 2u) to Rational(157, 63), + listOf(1u, 2u) to Rational(-55, 21), + listOf(2u, 2u) to Rational(11, 24), + ), + NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 1u) to Rational(17, 7), + listOf(1u, 1u) to Rational(-7, 7), + listOf(2u, 1u) to Rational(12, 5), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ) - NumberedPolynomial( + listOf() to Rational(20, 2), + listOf(1u) to Rational(0, 9), + listOf(2u) to Rational(20, 7), + listOf(0u, 1u) to Rational(1, 9), + listOf(1u, 1u) to Rational(-2, 5), + listOf(2u, 1u) to Rational(-10, 6), + listOf(0u, 2u) to Rational(-7, 9), + listOf(1u, 2u) to Rational(-5, 7), + listOf(2u, 2u) to Rational(2, 3), + ), "test 1" ) assertEquals( - NumberedPolynomial { - Rational(-17, 2) with {} - Rational(-1, 3) with { 1 pow 1u } - Rational(-25, 21) with { 1 pow 2u } - Rational(-1, 9) with { 2 pow 1u } - Rational(2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(157, 63) with { 2 pow 2u } - Rational(-55, 21) with { 1 pow 1u; 2 pow 2u } - Rational(11, 24) with { 1 pow 2u; 2 pow 2u } - }, - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - } - NumberedPolynomial { - Rational(20, 2) with {} - Rational(0, 9) with { 1 pow 1u } - Rational(20, 7) with { 1 pow 2u } - Rational(1, 9) with { 2 pow 1u } - Rational(-2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(-10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(-7, 9) with { 2 pow 2u } - Rational(-5, 7) with { 1 pow 1u; 2 pow 2u } - Rational(2, 3) with { 1 pow 2u; 2 pow 2u } - }, + NumberedPolynomial( + listOf() to Rational(-17, 2), + listOf(1u) to Rational(-1, 3), + listOf(2u) to Rational(-25, 21), + listOf(0u, 1u) to Rational(-1, 9), + listOf(1u, 1u) to Rational(2, 5), + listOf(2u, 1u) to Rational(10, 6), + listOf(0u, 2u) to Rational(157, 63), + listOf(1u, 2u) to Rational(-55, 21), + listOf(2u, 2u) to Rational(11, 24), + ), + NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ) - NumberedPolynomial( + listOf() to Rational(20, 2), + listOf(1u) to Rational(0, 9), + listOf(2u) to Rational(20, 7), + listOf(0u, 1u) to Rational(1, 9), + listOf(1u, 1u) to Rational(-2, 5), + listOf(2u, 1u) to Rational(-10, 6), + listOf(0u, 2u) to Rational(-7, 9), + listOf(1u, 2u) to Rational(-5, 7), + listOf(2u, 2u) to Rational(2, 3), + ), "test 2" ) assertEquals( - NumberedPolynomial { - Rational(-17, 2) with {} - Rational(-1, 3) with { 1 pow 1u } - Rational(-25, 21) with { 1 pow 2u } - Rational(-1, 9) with { 2 pow 1u } - Rational(2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - }, - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - } - NumberedPolynomial { - Rational(20, 2) with {} - Rational(0, 9) with { 1 pow 1u } - Rational(20, 7) with { 1 pow 2u } - Rational(1, 9) with { 2 pow 1u } - Rational(-2, 5) with { 1 pow 1u; 2 pow 1u } - Rational(-10, 6) with { 1 pow 2u; 2 pow 1u } - Rational(0) with { 2 pow 2u } - Rational(0) with { 1 pow 1u; 2 pow 2u } - Rational(0) with { 1 pow 2u; 2 pow 2u } - }, + NumberedPolynomial( + listOf() to Rational(-17, 2), + listOf(1u) to Rational(-1, 3), + listOf(2u) to Rational(-25, 21), + listOf(0u, 1u) to Rational(-1, 9), + listOf(1u, 1u) to Rational(2, 5), + listOf(2u, 1u) to Rational(10, 6), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ), + NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ) - NumberedPolynomial( + listOf() to Rational(20, 2), + listOf(1u) to Rational(0, 9), + listOf(2u) to Rational(20, 7), + listOf(0u, 1u) to Rational(1, 9), + listOf(1u, 1u) to Rational(-2, 5), + listOf(2u, 1u) to Rational(-10, 6), + listOf(0u, 2u) to Rational(0), + listOf(1u, 2u) to Rational(0), + listOf(2u, 2u) to Rational(0), + ), "test 3" ) assertEquals( - NumberedPolynomial { - Rational(0) with {} - Rational(0) with { 1 pow 1u } - Rational(0) with { 1 pow 2u } - Rational(0) with { 2 pow 1u } - Rational(0) with { 1 pow 1u; 2 pow 1u } - Rational(0) with { 1 pow 2u; 2 pow 1u } - Rational(0) with { 2 pow 2u } - Rational(0) with { 1 pow 1u; 2 pow 2u } - Rational(0) with { 1 pow 2u; 2 pow 2u } - }, - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(17, 7) with { 2 pow 1u } - Rational(-7, 7) with { 1 pow 1u; 2 pow 1u } - Rational(12, 5) with { 1 pow 2u; 2 pow 1u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - } - NumberedPolynomial { - Rational(6, 4) with {} - Rational(-2, 6) with { 1 pow 1u } - Rational(10, 6) with { 1 pow 2u } - Rational(17, 7) with { 2 pow 1u } - Rational(-7, 7) with { 1 pow 1u; 2 pow 1u } - Rational(12, 5) with { 1 pow 2u; 2 pow 1u } - Rational(12, 7) with { 2 pow 2u } - Rational(-10, 3) with { 1 pow 1u; 2 pow 2u } - Rational(9, 8) with { 1 pow 2u; 2 pow 2u } - }, + NumberedPolynomial( + listOf() to Rational(0), + listOf(1u) to Rational(0), + listOf(2u) to Rational(0), + listOf(0u, 1u) to Rational(0), + listOf(1u, 1u) to Rational(0), + listOf(2u, 1u) to Rational(0), + listOf(0u, 2u) to Rational(0), + listOf(1u, 2u) to Rational(0), + listOf(2u, 2u) to Rational(0), + ), + NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 1u) to Rational(17, 7), + listOf(1u, 1u) to Rational(-7, 7), + listOf(2u, 1u) to Rational(12, 5), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ) - NumberedPolynomial( + listOf() to Rational(6, 4), + listOf(1u) to Rational(-2, 6), + listOf(2u) to Rational(10, 6), + listOf(0u, 1u) to Rational(17, 7), + listOf(1u, 1u) to Rational(-7, 7), + listOf(2u, 1u) to Rational(12, 5), + listOf(0u, 2u) to Rational(12, 7), + listOf(1u, 2u) to Rational(-10, 3), + listOf(2u, 2u) to Rational(9, 8), + ), "test 4" ) } @@ -1314,255 +1312,250 @@ class NumberedPolynomialTest { IntModuloRing(35).numberedPolynomialSpace { // (p + q + r) * (p^2 + q^2 + r^2 - pq - pr - qr) = p^3 + q^3 + r^3 - 3pqr assertEquals( - NumberedPolynomial { - m(1) with { 1 pow 3u } - m(1) with { 2 pow 3u } - m(1) with { 3 pow 3u } - m(0) with { 1 pow 1u; 2 pow 2u } - m(0) with { 2 pow 1u; 3 pow 2u } - m(0) with { 3 pow 1u; 1 pow 2u } - m(0) with { 1 pow 1u; 3 pow 2u } - m(0) with { 2 pow 1u; 1 pow 2u } - m(0) with { 3 pow 1u; 2 pow 2u } - m(-3) with { 1 pow 1u; 2 pow 1u; 3 pow 1u } - }, - NumberedPolynomial { - m(1) with { 1 pow 1u } - m(1) with { 2 pow 1u } - m(1) with { 3 pow 1u } - } * NumberedPolynomial { - m(1) with { 1 pow 2u } - m(1) with { 2 pow 2u } - m(1) with { 3 pow 2u } - m(-1) with { 1 pow 1u; 2 pow 1u } - m(-1) with { 2 pow 1u; 3 pow 1u } - m(-1) with { 3 pow 1u; 1 pow 1u } - }, + NumberedPolynomial( + listOf(3u) to m(1), + listOf(0u, 3u) to m(1), + listOf(0u, 0u, 3u) to m(1), + listOf(1u, 2u) to m(0), + listOf(0u, 1u, 2u) to m(0), + listOf(2u, 0u, 1u) to m(0), + listOf(1u, 0u, 2u) to m(0), + listOf(2u, 1u) to m(0), + listOf(0u, 2u, 1u) to m(0), + listOf(1u, 1u, 1u) to m(-3), + ), + NumberedPolynomial( + listOf(1u) to m(1), + listOf(0u, 1u) to m(1), + listOf(0u, 0u, 1u) to m(1), + ) * NumberedPolynomial( + listOf(2u) to m(1), + listOf(0u, 2u) to m(1), + listOf(0u, 0u, 2u) to m(1), + listOf(1u, 1u) to m(-1), + listOf(0u, 1u, 1u) to m(-1), + listOf(1u, 0u, 1u) to m(-1), + ), "test 1" ) // Spoiler: 5 * 7 = 0 assertEquals( - NumberedPolynomial { - m(0) with { 1 pow 2u } - m(0) with { 2 pow 2u } - m(0) with { 3 pow 2u } - m(0) with { 1 pow 1u; 2 pow 1u } - m(0) with { 2 pow 1u; 3 pow 1u } - m(0) with { 3 pow 1u; 1 pow 1u } - }, - NumberedPolynomial { - m(5) with { 1 pow 1u } - m(-25) with { 2 pow 1u } - m(10) with { 3 pow 1u } - } * NumberedPolynomial { - m(21) with { 1 pow 1u } - m(14) with { 2 pow 1u } - m(-7) with { 3 pow 1u } - }, + NumberedPolynomial( + listOf(2u) to m(0), + listOf(0u, 2u) to m(0), + listOf(0u, 0u, 2u) to m(0), + listOf(1u, 1u) to m(0), + listOf(0u, 1u, 1u) to m(0), + listOf(1u, 0u, 1u) to m(0), + ), + NumberedPolynomial( + listOf(1u) to m(5), + listOf(0u, 1u) to m(-25), + listOf(0u, 0u, 1u) to m(10), + ) * NumberedPolynomial( + listOf(1u) to m(21), + listOf(0u, 1u) to m(14), + listOf(0u, 0u, 1u) to m(-7), + ), "test 2" ) } } @Test fun test_lastVariable() { - val o = Rational(0) RationalField.numberedPolynomialSpace { assertEquals( -1, - NumberedPolynomial {}.lastVariable, + NumberedPolynomial().lastVariable, "test 1" ) assertEquals( -1, - NumberedPolynomial { - o {} - }.lastVariable, + NumberedPolynomial( + listOf() to o + ).lastVariable, "test 2" ) assertEquals( 2, - NumberedPolynomial { - o { 1 pow 1u; 2 pow 2u; 3 pow 3u } - }.lastVariable, + NumberedPolynomial( + listOf(1u, 2u, 3u) to o + ).lastVariable, "test 3" ) assertEquals( 3, - NumberedPolynomial { - o { 1 pow 0u; 2 pow 1u; 3 pow 2u; 4 pow 1u; 5 pow 0u } - }.also { println(it) }.lastVariable, + NumberedPolynomial( + listOf(0u, 1u, 2u, 1u, 0u) to o + ).also { println(it) }.lastVariable, "test 4" ) assertEquals( 2, - NumberedPolynomial { - o {} - o { 2 pow 1u } - o { 1 pow 2u; 3 pow 1u } - }.lastVariable, + NumberedPolynomial( + listOf() to o, + listOf(0u, 1u) to o, + listOf(2u, 0u, 1u) to o, + ).lastVariable, "test 5" ) } } @Test fun test_degree() { - val o = Rational(0) RationalField.numberedPolynomialSpace { assertEquals( -1, - NumberedPolynomial {}.degree, + NumberedPolynomial().degree, "test 1" ) assertEquals( 0, - NumberedPolynomial { - o {} - }.degree, + NumberedPolynomial( + listOf() to o + ).degree, "test 2" ) assertEquals( 6, - NumberedPolynomial { - o { 1 pow 1u; 2 pow 2u; 3 pow 3u } - }.degree, + NumberedPolynomial( + listOf(1u, 2u, 3u) to o + ).degree, "test 3" ) assertEquals( 4, - NumberedPolynomial { - o { 1 pow 0u; 2 pow 1u; 3 pow 2u; 4 pow 1u; 5 pow 0u } - }.degree, + NumberedPolynomial( + listOf(0u, 1u, 2u, 1u, 0u) to o + ).degree, "test 4" ) assertEquals( 3, - NumberedPolynomial { - o {} - o { 2 pow 1u } - o { 1 pow 2u; 3 pow 1u } - }.degree, + NumberedPolynomial( + listOf() to o, + listOf(0u, 1u) to o, + listOf(2u, 0u, 1u) to o, + ).degree, "test 5" ) assertEquals( 4, - NumberedPolynomial { - o {} - o { 2 pow 1u } - o { 1 pow 2u; 3 pow 1u } - o { 4 pow 4u } - }.degree, + NumberedPolynomial( + listOf() to o, + listOf(0u, 1u) to o, + listOf(2u, 0u, 1u) to o, + listOf(0u, 0u, 0u, 4u) to o, + ).degree, "test 6" ) } } @Test fun test_degrees() { - val o = Rational(0) RationalField.numberedPolynomialSpace { assertEquals( listOf(), - NumberedPolynomial {}.degrees, + NumberedPolynomial().degrees, "test 1" ) assertEquals( listOf(), - NumberedPolynomial { - o {} - }.degrees, + NumberedPolynomial( + listOf() to o + ).degrees, "test 2" ) assertEquals( listOf(1u, 2u, 3u), - NumberedPolynomial { - o { 1 pow 1u; 2 pow 2u; 3 pow 3u } - }.degrees, + NumberedPolynomial( + listOf(1u, 2u, 3u) to o + ).degrees, "test 3" ) assertEquals( listOf(0u, 1u, 2u, 1u), - NumberedPolynomial { - o { 1 pow 0u; 2 pow 1u; 3 pow 2u; 4 pow 1u; 5 pow 0u } - }.degrees, + NumberedPolynomial( + listOf(0u, 1u, 2u, 1u, 0u) to o + ).degrees, "test 4" ) assertEquals( listOf(2u, 1u, 1u), - NumberedPolynomial { - o {} - o { 2 pow 1u } - o { 1 pow 2u; 3 pow 1u } - }.degrees, + NumberedPolynomial( + listOf() to o, + listOf(0u, 1u) to o, + listOf(2u, 0u, 1u) to o, + ).degrees, "test 5" ) assertEquals( listOf(2u, 2u, 2u, 4u), - NumberedPolynomial { - o {} - o { 1 pow 1u; 2 pow 2u } - o { 2 pow 1u; 3 pow 2u } - o { 1 pow 2u; 3 pow 1u } - o { 4 pow 4u } - }.degrees, + NumberedPolynomial( + listOf() to o, + listOf(1u, 2u) to o, + listOf(0u, 1u, 2u) to o, + listOf(2u, 0u, 1u) to o, + listOf(0u, 0u, 0u, 4u) to o, + ).degrees, "test 6" ) } } @Test fun test_degreeBy() { - val o = Rational(0) RationalField.numberedPolynomialSpace { fun NumberedPolynomial.collectDegrees(limit: Int = lastVariable + 2): List = List(limit) { degreeBy(it) } assertEquals( listOf(0u), - NumberedPolynomial {}.collectDegrees(), + NumberedPolynomial().collectDegrees(), "test 1" ) assertEquals( listOf(0u), - NumberedPolynomial { - o {} - }.collectDegrees(), + NumberedPolynomial( + listOf() to o + ).collectDegrees(), "test 2" ) assertEquals( listOf(1u, 2u, 3u, 0u), - NumberedPolynomial { - o { 1 pow 1u; 2 pow 2u; 3 pow 3u } - }.collectDegrees(), + NumberedPolynomial( + listOf(1u, 2u, 3u) to o + ).collectDegrees(), "test 3" ) assertEquals( listOf(0u, 1u, 2u, 1u, 0u), - NumberedPolynomial { - o { 1 pow 0u; 2 pow 1u; 3 pow 2u; 4 pow 1u; 5 pow 0u } - }.collectDegrees(), + NumberedPolynomial( + listOf(0u, 1u, 2u, 1u, 0u) to o + ).collectDegrees(), "test 4" ) assertEquals( listOf(2u, 1u, 1u, 0u), - NumberedPolynomial { - o {} - o { 2 pow 1u } - o { 1 pow 2u; 3 pow 1u } - }.collectDegrees(), + NumberedPolynomial( + listOf() to o, + listOf(0u, 1u) to o, + listOf(2u, 0u, 1u) to o, + ).collectDegrees(), "test 5" ) assertEquals( listOf(2u, 2u, 2u, 4u, 0u), - NumberedPolynomial { - o {} - o { 1 pow 1u; 2 pow 2u } - o { 2 pow 1u; 3 pow 2u } - o { 1 pow 2u; 3 pow 1u } - o { 4 pow 4u } - }.collectDegrees(), + NumberedPolynomial( + listOf() to o, + listOf(1u, 2u) to o, + listOf(0u, 1u, 2u) to o, + listOf(2u, 0u, 1u) to o, + listOf(0u, 0u, 0u, 4u) to o, + ).collectDegrees(), "test 6" ) } } @Test fun test_degreeBy_Collection() { - val o = Rational(0) RationalField.numberedPolynomialSpace { fun NumberedPolynomial.checkDegreeBy(message: String? = null) { val lastVariable = lastVariable @@ -1587,153 +1580,151 @@ class NumberedPolynomialTest { fail("${message ?: ""} Incorrect answer for variable collection $indexCollection: expected $expected, actual $actual") } } - NumberedPolynomial {}.checkDegreeBy("test 1") - NumberedPolynomial { - o {} - }.checkDegreeBy("test 2") - NumberedPolynomial { - o { 1 pow 1u; 2 pow 2u; 3 pow 3u } - }.checkDegreeBy("test 3") - NumberedPolynomial { - o { 1 pow 0u; 2 pow 1u; 3 pow 2u; 4 pow 1u; 5 pow 0u } - }.checkDegreeBy("test 4") - NumberedPolynomial { - o {} - o { 2 pow 1u } - o { 1 pow 2u; 3 pow 1u } - }.checkDegreeBy("test 5") - NumberedPolynomial { - o {} - o { 1 pow 1u; 2 pow 2u } - o { 2 pow 1u; 3 pow 2u } - o { 1 pow 2u; 3 pow 1u } - o { 4 pow 4u } - }.checkDegreeBy("test 6") + NumberedPolynomial().checkDegreeBy("test 1") + NumberedPolynomial( + listOf() to o + ).checkDegreeBy("test 2") + NumberedPolynomial( + listOf(1u, 2u, 3u) to o + ).checkDegreeBy("test 3") + NumberedPolynomial( + listOf(0u, 1u, 2u, 1u, 0u) to o + ).checkDegreeBy("test 4") + NumberedPolynomial( + listOf() to o, + listOf(0u, 1u) to o, + listOf(2u, 0u, 1u) to o, + ).checkDegreeBy("test 5") + NumberedPolynomial( + listOf() to o, + listOf(1u, 2u) to o, + listOf(0u, 1u, 2u) to o, + listOf(2u, 0u, 1u) to o, + listOf(0u, 0u, 0u, 4u) to o, + ).checkDegreeBy("test 6") } } @Test fun test_countOfVariables() { - val o = Rational(0) RationalField.numberedPolynomialSpace { assertEquals( 0, - NumberedPolynomial {}.countOfVariables, + NumberedPolynomial().countOfVariables, "test 1" ) assertEquals( 0, - NumberedPolynomial { - o {} - }.countOfVariables, + NumberedPolynomial( + listOf() to o + ).countOfVariables, "test 2" ) assertEquals( 3, - NumberedPolynomial { - o { 1 pow 1u; 2 pow 2u; 3 pow 3u } - }.countOfVariables, + NumberedPolynomial( + listOf(1u, 2u, 3u) to o + ).countOfVariables, "test 3" ) assertEquals( 3, - NumberedPolynomial { - o { 1 pow 0u; 2 pow 1u; 3 pow 2u; 4 pow 1u; 5 pow 0u } - }.countOfVariables, + NumberedPolynomial( + listOf(0u, 1u, 2u, 1u, 0u) to o + ).countOfVariables, "test 4" ) assertEquals( 3, - NumberedPolynomial { - o {} - o { 2 pow 1u } - o { 1 pow 2u; 3 pow 1u } - }.countOfVariables, + NumberedPolynomial( + listOf() to o, + listOf(0u, 1u) to o, + listOf(2u, 0u, 1u) to o, + ).countOfVariables, "test 5" ) assertEquals( 4, - NumberedPolynomial { - o {} - o { 1 pow 1u; 2 pow 2u } - o { 2 pow 1u; 3 pow 2u } - o { 1 pow 2u; 3 pow 1u } - o { 4 pow 4u } - }.countOfVariables, + NumberedPolynomial( + listOf() to o, + listOf(1u, 2u) to o, + listOf(0u, 1u, 2u) to o, + listOf(2u, 0u, 1u) to o, + listOf(0u, 0u, 0u, 4u) to o, + ).countOfVariables, "test 6" ) } } @Test fun test_RF_countOfVariables() { - val o = Rational(0) RationalField.numberedRationalFunctionSpace { assertEquals( 0, NumberedRationalFunction( - NumberedPolynomial {} + NumberedPolynomial() ).countOfVariables, "test 1" ) assertEquals( 0, NumberedRationalFunction( - NumberedPolynomial {}, - NumberedPolynomial {} + NumberedPolynomial(), + NumberedPolynomial() ).countOfVariables, "test 2" ) assertEquals( 0, NumberedRationalFunction( - NumberedPolynomial { - o {} - } + NumberedPolynomial( + listOf() to o + ) ).countOfVariables, "test 3" ) assertEquals( 3, NumberedRationalFunction( - NumberedPolynomial { - o { 1 pow 1u; 2 pow 2u; 3 pow 3u } - } + NumberedPolynomial( + listOf(1u, 2u, 3u) to o + ) ).countOfVariables, "test 4" ) assertEquals( 3, NumberedRationalFunction( - NumberedPolynomial { - o { 2 pow 1u; 4 pow 1u } - }, - NumberedPolynomial { - o { 1 pow 0u; 3 pow 2u; 5 pow 0u } - } + NumberedPolynomial( + listOf(0u, 1u, 0u, 1u) to o + ), + NumberedPolynomial( + listOf(0u, 0u, 2u) to o + ) ).countOfVariables, "test 5" ) assertEquals( 3, NumberedRationalFunction( - NumberedPolynomial { - o {} - o { 2 pow 1u } - o { 1 pow 2u; 3 pow 1u } - } + NumberedPolynomial( + listOf() to o, + listOf(0u, 1u) to o, + listOf(2u, 0u, 1u) to o, + ) ).countOfVariables, "test 6" ) assertEquals( 4, NumberedRationalFunction( - NumberedPolynomial { - o {} - o { 1 pow 1u; 2 pow 2u } - o { 1 pow 2u; 3 pow 1u } - }, NumberedPolynomial { - o { 2 pow 1u; 3 pow 2u } - o { 4 pow 4u } - } + NumberedPolynomial( + listOf() to o, + listOf(1u, 2u) to o, + listOf(2u, 0u, 1u) to o, + ), NumberedPolynomial( + listOf(0u, 1u, 2u) to o, + listOf(0u, 0u, 0u, 4u) to o, + ) ).countOfVariables, "test 7" )