diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/LabeledPolynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/LabeledPolynomial.kt index 6d9af631a..1477796ea 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/LabeledPolynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/LabeledPolynomial.kt @@ -177,14 +177,17 @@ public class LabeledPolynomialSpace>( * The operation is equivalent to sum of [other] copies of [this]. */ public override operator fun LabeledPolynomial.times(other: Int): LabeledPolynomial = - if (other == 0) zero - else LabeledPolynomial( - coefficients - .toMutableMap() - .apply { - for (degs in keys) this[degs] = this[degs]!! * other - } - ) + when(other) { + 0 -> zero + 1 -> this + else -> LabeledPolynomial( + coefficients + .toMutableMap() + .apply { + for (degs in keys) this[degs] = this[degs]!! * other + } + ) + } /** * Returns sum of the integer represented as a polynomial and the polynomial. @@ -210,7 +213,7 @@ public class LabeledPolynomialSpace>( * The operation is equivalent to subtraction [this] copies of unit polynomial from [other]. */ public override operator fun Int.minus(other: LabeledPolynomial): LabeledPolynomial = - if (this == 0) other + if (this == 0) -other else with(other.coefficients) { if (isEmpty()) LabeledPolynomialAsIs(mapOf(emptyMap() to this@minus.asConstant())) else LabeledPolynomialAsIs( @@ -230,14 +233,17 @@ public class LabeledPolynomialSpace>( * The operation is equivalent to sum of [this] copies of [other]. */ public override operator fun Int.times(other: LabeledPolynomial): LabeledPolynomial = - if (this == 0) zero - else LabeledPolynomial( - other.coefficients - .toMutableMap() - .apply { - for (degs in keys) this[degs] = this@times * this[degs]!! - } - ) + when(this) { + 0 -> zero + 1 -> other + else -> LabeledPolynomial( + other.coefficients + .toMutableMap() + .apply { + for (degs in keys) this[degs] = this@times * this[degs]!! + } + ) + } /** * Converts the integer [value] to polynomial. @@ -360,8 +366,6 @@ public class LabeledPolynomialSpace>( else LabeledPolynomialAsIs( toMutableMap() .apply { - forEach { (degs, c) -> if(degs.isNotEmpty()) this[degs] = -c } - val degs = emptyMap() this[degs] = getOrElse(degs) { constantZero } - other 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 8442d3f91..819a36449 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 @@ -302,6 +302,7 @@ public class DSL1LabeledPolynomialTermSignatureBuilder { * Declaring another power of the same variable will increase its degree by received degree. */ public infix fun Symbol.inPowerOf(deg: UInt) { + if (deg == 0u) return signature[this] = signature.getOrElse(this) { 0u } + deg } /** diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledConstructorsTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledConstructorsTest.kt new file mode 100644 index 000000000..edeaef6a7 --- /dev/null +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledConstructorsTest.kt @@ -0,0 +1,129 @@ +/* + * Copyright 2018-2021 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.functions + +import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.symbol +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.algebra +import space.kscience.kmath.operations.invoke +import kotlin.test.Test +import kotlin.test.assertEquals + +class LabeledConstructorsTest { + val x by symbol + val y by symbol + val z by symbol + val t by symbol + + @Test + @UnstableKMathAPI + fun testDSL1() { + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u, z to 3u) to 5, + mapOf(y to 1u) to -6, + ), + Int.algebra.labeledPolynomialSpace { + LabeledPolynomialDSL1 { + 5 { x pow 2u; z pow 3u } + (-6) { y pow 1u } + } + }, + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to -1, + ), + Int.algebra.labeledPolynomialSpace { + LabeledPolynomialDSL1 { + 5 { } + (-6) { } + } + }, + "test 2" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to -1, + ), + Int.algebra.labeledPolynomialSpace { + LabeledPolynomialDSL1 { + 5 { x pow 1u; x pow 1u } + (-6) { x pow 2u } + } + }, + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to -1, + ), + Int.algebra.labeledPolynomialSpace { + LabeledPolynomialDSL1 { + 5 { x pow 1u; x pow 1u } + (-6) { x pow 2u; z pow 0u } + } + }, + "test 3" + ) + } + @Test + @UnstableKMathAPI + fun testFabric() { + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u, z to 3u) to 5, + mapOf(y to 1u) to -6, + ), + Int.algebra { + LabeledPolynomial( + mapOf(x to 2u, z to 3u) to 5, + mapOf(y to 1u) to -6, + ) + }, + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u, z to 3u) to 5, + mapOf(y to 1u) to -6, + ), + Int.algebra { + LabeledPolynomial( + mapOf(x to 2u, y to 0u, z to 3u, t to 0u) to 5, + mapOf(x to 0u, y to 1u, z to 0u, t to 0u) to -6, + ) + }, + "test 2" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to -1, + ), + Int.algebra { + LabeledPolynomial( + mapOf(x to 0u) to 5, + mapOf(y to 0u, z to 0u) to -6, + ) + }, + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 0, + ), + Int.algebra { + LabeledPolynomial( + mapOf(x to 0u) to 5, + mapOf(z to 0u, t to 0u) to -5, + ) + }, + "test 4" + ) + } +} \ No newline at end of file diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledPolynomialTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledPolynomialTest.kt new file mode 100644 index 000000000..15c4c3656 --- /dev/null +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledPolynomialTest.kt @@ -0,0 +1,1872 @@ +/* + * Copyright 2018-2021 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.functions + +import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.symbol +import space.kscience.kmath.test.misc.IntModuloRing +import space.kscience.kmath.test.misc.Rational +import space.kscience.kmath.test.misc.RationalField +import space.kscience.kmath.test.misc.m +import kotlin.test.* + + +// TODO: Тесты на конвертацию. +class LabeledPolynomialTest { + val x by symbol + val y by symbol + val z by symbol + val t by symbol + val s by symbol + val iota by symbol + + val o = Rational(0) + + @Test + @Ignore + fun test_Variable_Int_plus() { + // TODO + } + @Test + @Ignore + fun test_Variable_Int_minus() { + // TODO + } + @Test + @Ignore + fun test_Variable_Int_times() { + // TODO + } + @Test + @Ignore + fun test_Int_Variable_plus() { + // TODO + } + @Test + @Ignore + fun test_Int_Variable_minus() { + // TODO + } + @Test + @Ignore + fun test_Int_Variable_times() { + // TODO + } + @Test + fun test_Polynomial_Int_plus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(5, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + -3, + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-3, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + -3, + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + -3, + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ) + -3, + "test 4" + ) + val polynomial_5 = LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_5, + polynomial_5 + 0, + "test 5" + ) + val polynomial_6 = LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_6, + polynomial_6 + 0, + "test 6" + ) + val polynomial_7 = LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_7, + polynomial_7 + 0, + "test 7" + ) + } + } + @Test + fun test_Polynomial_Int_minus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(5, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - 3, + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-3, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - 3, + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - 3, + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ) - 3, + "test 4" + ) + val polynomial_5 = LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_5, + polynomial_5 - 0, + "test 5" + ) + val polynomial_6 = LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_6, + polynomial_6 - 0, + "test 6" + ) + val polynomial_7 = LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_7, + polynomial_7 - 0, + "test 7" + ) + } + } + @Test + fun test_Polynomial_Int_times() { + IntModuloRing(35).labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to m(34), + mapOf(x to 3u) to m(2), + mapOf(x to 0u, y to 1u) to m(1), + mapOf(x to 1u) to m(20), + mapOf(x to 0u, y to 0u, z to 2u) to m(2), + ), + LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ) * 27, + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to m(0), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(0), + mapOf(x to 1u) to m(0), + mapOf(x to 0u, y to 0u, z to 2u) to m(0), + ), + LabeledPolynomial( + mapOf() to m(7), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(49), + mapOf(x to 1u) to m(21), + mapOf(x to 0u, y to 0u, z to 2u) to m(14), + ) * 15, + "test 2" + ) + val polynomial = LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ) + assertSame( + zero, + polynomial * 0, + "test 3" + ) + assertSame( + polynomial, + polynomial * 1, + "test 4" + ) + } + } + @Test + fun test_Int_Polynomial_plus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + -3 + LabeledPolynomial( + mapOf() to Rational(5, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-3, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + -3 + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + -3 + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + -3 + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + "test 4" + ) + val polynomial_5 = LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_5, + 0 + polynomial_5, + "test 5" + ) + val polynomial_6 = LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_6, + 0 + polynomial_6, + "test 6" + ) + val polynomial_7 = LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + assertSame( + polynomial_7, + 0 + polynomial_7, + "test 7" + ) + } + } + @Test + fun test_Int_Polynomial_minus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(22, 9), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + 3 - LabeledPolynomial( + mapOf() to Rational(5, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(3, 1), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + 3 - LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 1), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + 3 - LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + 3 - LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + "test 4" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(22, 9), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + 0 - LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 5" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + 0 - LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 6" + ) + assertEquals( + LabeledPolynomial( + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + 0 - LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 7" + ) + } + } + @Test + fun test_Int_Polynomial_times() { + IntModuloRing(35).labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to m(34), + mapOf(x to 3u) to m(2), + mapOf(x to 0u, y to 1u) to m(1), + mapOf(x to 1u) to m(20), + mapOf(x to 0u, y to 0u, z to 2u) to m(2), + ), + 27 * LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to m(0), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(0), + mapOf(x to 1u) to m(0), + mapOf(x to 0u, y to 0u, z to 2u) to m(0), + ), + 15 * LabeledPolynomial( + mapOf() to m(7), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(49), + mapOf(x to 1u) to m(21), + mapOf(x to 0u, y to 0u, z to 2u) to m(14), + ), + "test 2" + ) + val polynomial = LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ) + assertSame( + zero, + 0 * polynomial, + "test 3" + ) + assertSame( + polynomial, + 1 * polynomial, + "test 4" + ) + } + } + @Test + @Ignore + fun test_Variable_Constant_plus() { + // TODO + } + @Test + @Ignore + fun test_Variable_Constant_minus() { + // TODO + } + @Test + @Ignore + fun test_Variable_Constant_times() { + // TODO + } + @Test + @Ignore + fun test_Constant_Variable_plus() { + // TODO + } + @Test + @Ignore + fun test_Constant_Variable_minus() { + // TODO + } + @Test + @Ignore + fun test_Constant_Variable_times() { + // TODO + } + @Test + fun test_Polynomial_Constant_plus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(5, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + Rational(-3), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-3, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + Rational(-3), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + Rational(-3), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ) + Rational(-3), + "test 4" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + Rational(0), + "test 5" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + Rational(0), + "test 6" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) + Rational(0), + "test 7" + ) + } + } + @Test + fun test_Polynomial_Constant_minus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(5, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - Rational(3), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-3, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - Rational(3), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - Rational(3), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ) - Rational(3), + "test 4" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - Rational(0), + "test 5" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - Rational(0), + "test 6" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ) - Rational(0), + "test 7" + ) + } + } + @Test + fun test_Polynomial_Constant_times() { + IntModuloRing(35).labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to m(34), + mapOf(x to 3u) to m(2), + mapOf(x to 0u, y to 1u) to m(1), + mapOf(x to 1u) to m(20), + mapOf(x to 0u, y to 0u, z to 2u) to m(2), + ), + LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ) * m(27), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to m(0), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(0), + mapOf(x to 1u) to m(0), + mapOf(x to 0u, y to 0u, z to 2u) to m(0), + ), + LabeledPolynomial( + mapOf() to m(7), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(49), + mapOf(x to 1u) to m(21), + mapOf(x to 0u, y to 0u, z to 2u) to m(14), + ) * m(15), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to m(0), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(0), + mapOf(x to 1u) to m(0), + mapOf(x to 0u, y to 0u, z to 2u) to m(0), + ), + LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ) * m(0), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ), + LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ) * m(1), + "test 4" + ) + } + } + @Test + fun test_Constant_Polynomial_plus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + Rational(-3) + LabeledPolynomial( + mapOf() to Rational(5, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-3, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + Rational(-3) + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 1), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + Rational(-3) + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + Rational(-3) + LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + "test 4" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + Rational(0) + LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 5" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + Rational(0) + LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 6" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + Rational(0) + LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 7" + ) + } + } + @Test + fun test_Constant_Polynomial_minus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(22, 9), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + Rational(3) - LabeledPolynomial( + mapOf() to Rational(5, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(3, 1), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + Rational(3) - LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 1), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + Rational(3) - LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + Rational(3) - LabeledPolynomial( + mapOf() to Rational(27, 9), + mapOf(x to 3u) to Rational(0), + mapOf(x to 0u, y to 4u) to Rational(0), + ), + "test 4" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(22, 9), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + Rational(0) - LabeledPolynomial( + mapOf() to Rational(-22, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 5" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + Rational(0) - LabeledPolynomial( + mapOf() to Rational(0, 9), + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 6" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 3u) to Rational(8, 9), + mapOf(x to 0u, y to 4u) to Rational(8, 7), + ), + Rational(0) - LabeledPolynomial( + mapOf(x to 3u) to Rational(-8, 9), + mapOf(x to 0u, y to 4u) to Rational(-8, 7), + ), + "test 7" + ) + } + } + @Test + fun test_Constant_Polynomial_times() { + IntModuloRing(35).labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to m(34), + mapOf(x to 3u) to m(2), + mapOf(x to 0u, y to 1u) to m(1), + mapOf(x to 1u) to m(20), + mapOf(x to 0u, y to 0u, z to 2u) to m(2), + ), + m(27) * LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to m(0), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(0), + mapOf(x to 1u) to m(0), + mapOf(x to 0u, y to 0u, z to 2u) to m(0), + ), + m(15) * LabeledPolynomial( + mapOf() to m(7), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(49), + mapOf(x to 1u) to m(21), + mapOf(x to 0u, y to 0u, z to 2u) to m(14), + ), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to m(0), + mapOf(x to 3u) to m(0), + mapOf(x to 0u, y to 1u) to m(0), + mapOf(x to 1u) to m(0), + mapOf(x to 0u, y to 0u, z to 2u) to m(0), + ), + m(0) * LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ), + m(1) * LabeledPolynomial( + mapOf() to m(22), + mapOf(x to 3u) to m(26), + mapOf(x to 0u, y to 1u) to m(13), + mapOf(x to 1u) to m(15), + mapOf(x to 0u, y to 0u, z to 2u) to m(26), + ), + "test 4" + ) + } + } + @Test + @Ignore + fun test_Variable_unaryPlus(){ + // TODO + } + @Test + @Ignore + fun test_Variable_unaryMinus(){ + // TODO + } + @Test + @Ignore + fun test_Variable_Variable_plus(){ + // TODO + } + @Test + @Ignore + fun test_Variable_Variable_minus(){ + // TODO + } + @Test + @Ignore + fun test_Variable_Variable_times(){ + // TODO + } + @Test + @Ignore + fun test_Variable_Polynomial_plus(){ + // TODO + } + @Test + @Ignore + fun test_Variable_Polynomial_minus(){ + // TODO + } + @Test + @Ignore + fun test_Variable_Polynomial_times(){ + // TODO + } + @Test + @Ignore + fun test_Polynomial_Variable_plus(){ + // TODO + } + @Test + @Ignore + fun test_Polynomial_Variable_minus(){ + // TODO + } + @Test + @Ignore + fun test_Polynomial_Variable_times(){ + // TODO + } + @Test + fun test_Polynomial_unaryMinus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf(x to 5u) to Rational(-5, 9), + mapOf() to Rational(8, 9), + mapOf(iota to 13u) to Rational(8, 7), + ), + -LabeledPolynomial( + mapOf(x to 5u) to Rational(5, 9), + mapOf() to Rational(-8, 9), + mapOf(iota to 13u) to Rational(-8, 7), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf(x to 5u) to Rational(-5, 9), + mapOf() to Rational(8, 9), + mapOf(iota to 13u) to Rational(8, 7), + mapOf(x to 0u, y to 4u) to Rational(0), + mapOf(x to 5u) to Rational(0), + ), + -LabeledPolynomial( + mapOf(x to 5u) to Rational(5, 9), + mapOf() to Rational(-8, 9), + mapOf(iota to 13u) to Rational(-8, 7), + mapOf(x to 0u, y to 4u) to Rational(0), + mapOf(x to 5u) to Rational(0), + ), + "test 2" + ) + } + } + @Test + fun test_Polynomial_Polynomial_plus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-17, 2), + mapOf(x to 1u) to Rational(-1, 3), + mapOf(x to 2u) to Rational(-25, 21), + mapOf(x to 0u, y to 1u) to Rational(146, 63), + mapOf(x to 1u, y to 1u) to Rational(-3, 5), + mapOf(x to 2u, y to 1u) to Rational(61, 15), + mapOf(x to 0u, y to 2u) to Rational(157, 63), + mapOf(x to 1u, y to 2u) to Rational(-55, 21), + mapOf(x to 2u, y to 2u) to Rational(11, 24), + ), + LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(-7, 7), + mapOf(x to 2u, y to 1u) to Rational(12, 5), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ) + LabeledPolynomial( + mapOf() to Rational(-20, 2), + mapOf(x to 1u) to Rational(0, 9), + mapOf(x to 2u) to Rational(-20, 7), + mapOf(x to 0u, y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(2, 5), + mapOf(x to 2u, y to 1u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(7, 9), + mapOf(x to 1u, y to 2u) to Rational(5, 7), + mapOf(x to 2u, y to 2u) to Rational(-2, 3), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-17, 2), + mapOf(x to 1u) to Rational(-1, 3), + mapOf(x to 2u) to Rational(-25, 21), + mapOf(x to 0u, y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(2, 5), + mapOf(x to 2u, y to 1u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(157, 63), + mapOf(x to 1u, y to 2u) to Rational(-55, 21), + mapOf(x to 2u, y to 2u) to Rational(11, 24), + ), + LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ) + LabeledPolynomial( + mapOf() to Rational(-20, 2), + mapOf(x to 1u) to Rational(0, 9), + mapOf(x to 2u) to Rational(-20, 7), + mapOf(x to 0u, y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(2, 5), + mapOf(x to 2u, y to 1u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(7, 9), + mapOf(x to 1u, y to 2u) to Rational(5, 7), + mapOf(x to 2u, y to 2u) to Rational(-2, 3), + ), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-17, 2), + mapOf(x to 1u) to Rational(-1, 3), + mapOf(x to 2u) to Rational(-25, 21), + mapOf(x to 0u, y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(2, 5), + mapOf(x to 2u, y to 1u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ), + LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ) + LabeledPolynomial( + mapOf() to Rational(-20, 2), + mapOf(x to 1u) to Rational(0, 9), + mapOf(x to 2u) to Rational(-20, 7), + mapOf(x to 0u, y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(2, 5), + mapOf(x to 2u, y to 1u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + ), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 0u, y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 0u, y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + ), + LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(-7, 7), + mapOf(x to 2u, y to 1u) to Rational(12, 5), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ) + LabeledPolynomial( + mapOf() to Rational(-6, 4), + mapOf(x to 1u) to Rational(2, 6), + mapOf(x to 2u) to Rational(-10, 6), + mapOf(x to 0u, y to 1u) to Rational(-17, 7), + mapOf(x to 1u, y to 1u) to Rational(7, 7), + mapOf(x to 2u, y to 1u) to Rational(-12, 5), + mapOf(x to 0u, y to 2u) to Rational(-12, 7), + mapOf(x to 1u, y to 2u) to Rational(10, 3), + mapOf(x to 2u, y to 2u) to Rational(-9, 8), + ), + "test 4" + ) + } + } + @Test + fun test_Polynomial_Polynomial_minus() { + RationalField.labeledPolynomialSpace { + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-17, 2), + mapOf(x to 1u) to Rational(-1, 3), + mapOf(x to 2u) to Rational(-25, 21), + mapOf(x to 0u, y to 1u) to Rational(146, 63), + mapOf(x to 1u, y to 1u) to Rational(-3, 5), + mapOf(x to 2u, y to 1u) to Rational(61, 15), + mapOf(x to 0u, y to 2u) to Rational(157, 63), + mapOf(x to 1u, y to 2u) to Rational(-55, 21), + mapOf(x to 2u, y to 2u) to Rational(11, 24), + ), + LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(-7, 7), + mapOf(x to 2u, y to 1u) to Rational(12, 5), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ) - LabeledPolynomial( + mapOf() to Rational(20, 2), + mapOf(x to 1u) to Rational(0, 9), + mapOf(x to 2u) to Rational(20, 7), + mapOf(x to 0u, y to 1u) to Rational(1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 5), + mapOf(x to 2u, y to 1u) to Rational(-10, 6), + mapOf(x to 0u, y to 2u) to Rational(-7, 9), + mapOf(x to 1u, y to 2u) to Rational(-5, 7), + mapOf(x to 2u, y to 2u) to Rational(2, 3), + ), + "test 1" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-17, 2), + mapOf(x to 1u) to Rational(-1, 3), + mapOf(x to 2u) to Rational(-25, 21), + mapOf(x to 0u, y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(2, 5), + mapOf(x to 2u, y to 1u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(157, 63), + mapOf(x to 1u, y to 2u) to Rational(-55, 21), + mapOf(x to 2u, y to 2u) to Rational(11, 24), + ), + LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ) - LabeledPolynomial( + mapOf() to Rational(20, 2), + mapOf(x to 1u) to Rational(0, 9), + mapOf(x to 2u) to Rational(20, 7), + mapOf(x to 0u, y to 1u) to Rational(1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 5), + mapOf(x to 2u, y to 1u) to Rational(-10, 6), + mapOf(x to 0u, y to 2u) to Rational(-7, 9), + mapOf(x to 1u, y to 2u) to Rational(-5, 7), + mapOf(x to 2u, y to 2u) to Rational(2, 3), + ), + "test 2" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(-17, 2), + mapOf(x to 1u) to Rational(-1, 3), + mapOf(x to 2u) to Rational(-25, 21), + mapOf(x to 0u, y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(2, 5), + mapOf(x to 2u, y to 1u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ), + LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ) - LabeledPolynomial( + mapOf() to Rational(20, 2), + mapOf(x to 1u) to Rational(0, 9), + mapOf(x to 2u) to Rational(20, 7), + mapOf(x to 0u, y to 1u) to Rational(1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 5), + mapOf(x to 2u, y to 1u) to Rational(-10, 6), + mapOf(x to 0u, y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + ), + "test 3" + ) + assertEquals( + LabeledPolynomial( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 0u, y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 0u, y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + ), + LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(-7, 7), + mapOf(x to 2u, y to 1u) to Rational(12, 5), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ) - LabeledPolynomial( + mapOf() to Rational(6, 4), + mapOf(x to 1u) to Rational(-2, 6), + mapOf(x to 2u) to Rational(10, 6), + mapOf(x to 0u, y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(-7, 7), + mapOf(x to 2u, y to 1u) to Rational(12, 5), + mapOf(x to 0u, y to 2u) to Rational(12, 7), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(9, 8), + ), + "test 4" + ) + } + } + @Test + fun test_Polynomial_Polynomial_times() { + IntModuloRing(35).labeledPolynomialSpace { + // (p + q + r) * (p^2 + q^2 + r^2 - pq - pr - qr) = p^3 + q^3 + r^3 - 3pqr + assertEquals( + LabeledPolynomial( + mapOf(x to 3u) to m(1), + mapOf(x to 0u, y to 3u) to m(1), + mapOf(x to 0u, y to 0u, z to 3u) to m(1), + mapOf(x to 1u, y to 2u) to m(0), + mapOf(x to 0u, y to 1u, z to 2u) to m(0), + mapOf(x to 2u, y to 0u, z to 1u) to m(0), + mapOf(x to 1u, y to 0u, z to 2u) to m(0), + mapOf(x to 2u, y to 1u) to m(0), + mapOf(x to 0u, y to 2u, z to 1u) to m(0), + mapOf(x to 1u, y to 1u, z to 1u) to m(-3), + ), + LabeledPolynomial( + mapOf(x to 1u) to m(1), + mapOf(x to 0u, y to 1u) to m(1), + mapOf(x to 0u, y to 0u, z to 1u) to m(1), + ) * LabeledPolynomial( + mapOf(x to 2u) to m(1), + mapOf(x to 0u, y to 2u) to m(1), + mapOf(x to 0u, y to 0u, z to 2u) to m(1), + mapOf(x to 1u, y to 1u) to m(-1), + mapOf(x to 0u, y to 1u, z to 1u) to m(-1), + mapOf(x to 1u, y to 0u, z to 1u) to m(-1), + ), + "test 1" + ) + // Spoiler: 5 * 7 = 0 + assertEquals( + LabeledPolynomial( + mapOf(x to 2u) to m(0), + mapOf(x to 0u, y to 2u) to m(0), + mapOf(x to 0u, y to 0u, z to 2u) to m(0), + mapOf(x to 1u, y to 1u) to m(0), + mapOf(x to 0u, y to 1u, z to 1u) to m(0), + mapOf(x to 1u, y to 0u, z to 1u) to m(0), + ), + LabeledPolynomial( + mapOf(x to 1u) to m(5), + mapOf(x to 0u, y to 1u) to m(-25), + mapOf(x to 0u, y to 0u, z to 1u) to m(10), + ) * LabeledPolynomial( + mapOf(x to 1u) to m(21), + mapOf(x to 0u, y to 1u) to m(14), + mapOf(x to 0u, y to 0u, z to 1u) to m(-7), + ), + "test 2" + ) + } + } + @Test + fun test_degree() { + RationalField.labeledPolynomialSpace { + assertEquals( + -1, + LabeledPolynomial().degree, + "test 1" + ) + assertEquals( + 0, + LabeledPolynomial( + mapOf() to o + ).degree, + "test 2" + ) + assertEquals( + 6, + LabeledPolynomial( + mapOf(x to 1u, y to 2u, z to 3u) to o + ).degree, + "test 3" + ) + assertEquals( + 4, + LabeledPolynomial( + mapOf(x to 0u, y to 1u, z to 2u, t to 1u, s to 0u) to o + ).degree, + "test 4" + ) + assertEquals( + 3, + LabeledPolynomial( + mapOf() to o, + mapOf(x to 0u, y to 1u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + ).degree, + "test 5" + ) + assertEquals( + 4, + LabeledPolynomial( + mapOf() to o, + mapOf(x to 0u, y to 1u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + mapOf(x to 0u, y to 0u, z to 0u, t to 4u) to o, + ).degree, + "test 6" + ) + } + } + @Test + fun test_degrees() { + RationalField.labeledPolynomialSpace { + assertEquals( + mapOf(), + LabeledPolynomial().degrees, + "test 1" + ) + assertEquals( + mapOf(), + LabeledPolynomial( + mapOf() to o + ).degrees, + "test 2" + ) + assertEquals( + mapOf(x to 1u, y to 2u, z to 3u), + LabeledPolynomial( + mapOf(x to 1u, y to 2u, z to 3u) to o + ).degrees, + "test 3" + ) + assertEquals( + mapOf(y to 1u, z to 2u, t to 1u), + LabeledPolynomial( + mapOf(x to 0u, y to 1u, z to 2u, t to 1u, s to 0u) to o + ).degrees, + "test 4" + ) + assertEquals( + mapOf(x to 2u, y to 1u, z to 1u), + LabeledPolynomial( + mapOf() to o, + mapOf(x to 0u, y to 1u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + ).degrees, + "test 5" + ) + assertEquals( + mapOf(x to 2u, y to 2u, z to 2u, t to 4u), + LabeledPolynomial( + mapOf() to o, + mapOf(x to 1u, y to 2u) to o, + mapOf(x to 0u, y to 1u, z to 2u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + mapOf(x to 0u, y to 0u, z to 0u, t to 4u) to o, + ).degrees, + "test 6" + ) + } + } + @Test + fun test_degreeBy() { + RationalField.labeledPolynomialSpace { + fun LabeledPolynomial.collectDegrees(variables: Set = this.variables + iota): Map = variables.associateWith { degreeBy(it) } + assertEquals( + mapOf(iota to 0u), + LabeledPolynomial().collectDegrees(), + "test 1" + ) + assertEquals( + mapOf(iota to 0u), + LabeledPolynomial( + mapOf() to o + ).collectDegrees(), + "test 2" + ) + assertEquals( + mapOf(x to 1u, y to 2u, z to 3u, iota to 0u), + LabeledPolynomial( + mapOf(x to 1u, y to 2u, z to 3u) to o + ).collectDegrees(), + "test 3" + ) + assertEquals( + mapOf(y to 1u, z to 2u, t to 1u, iota to 0u), + LabeledPolynomial( + mapOf(x to 0u, y to 1u, z to 2u, t to 1u, s to 0u) to o + ).collectDegrees(), + "test 4" + ) + assertEquals( + mapOf(x to 2u, y to 1u, z to 1u, iota to 0u), + LabeledPolynomial( + mapOf() to o, + mapOf(x to 0u, y to 1u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + ).collectDegrees(), + "test 5" + ) + assertEquals( + mapOf(x to 2u, y to 2u, z to 2u, t to 4u, iota to 0u), + LabeledPolynomial( + mapOf() to o, + mapOf(x to 1u, y to 2u) to o, + mapOf(x to 0u, y to 1u, z to 2u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + mapOf(x to 0u, y to 0u, z to 0u, t to 4u) to o, + ).collectDegrees(), + "test 6" + ) + } + } + @Test + fun test_degreeBy_Collection() { + RationalField.labeledPolynomialSpace { + fun LabeledPolynomial.checkDegreeBy(message: String? = null) { + val variables = variables.toList() + iota + val variablesCollectionSequence: Sequence> = sequence { + val appearances = MutableList(variables.size) { 0 } + while (true) { + yield( + buildList { + for ((variableIndex, count) in appearances.withIndex()) repeat(count) { add(variables[variableIndex]) } + } + ) + val indexChange = appearances.indexOfFirst { it < 4 } + if (indexChange == -1) break + appearances[indexChange] += 1 + for (index in 0 until indexChange) appearances[index] = 0 + } + } + for (variablesCollection in variablesCollectionSequence) { + val expected = coefficients.keys.maxOfOrNull { degs -> degs.filterKeys { it in variablesCollection }.values.sum() } ?: 0u + val actual = degreeBy(variablesCollection) + if (actual != expected) + fail("${message ?: ""} Incorrect answer for variable collection $variablesCollection: expected $expected, actual $actual") + } + } + LabeledPolynomial().checkDegreeBy("test 1") + LabeledPolynomial( + mapOf() to o + ).checkDegreeBy("test 2") + LabeledPolynomial( + mapOf(x to 1u, y to 2u, z to 3u) to o + ).checkDegreeBy("test 3") + LabeledPolynomial( + mapOf(x to 0u, y to 1u, z to 2u, t to 1u, s to 0u) to o + ).checkDegreeBy("test 4") + LabeledPolynomial( + mapOf() to o, + mapOf(x to 0u, y to 1u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + ).checkDegreeBy("test 5") + LabeledPolynomial( + mapOf() to o, + mapOf(x to 1u, y to 2u) to o, + mapOf(x to 0u, y to 1u, z to 2u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + mapOf(x to 0u, y to 0u, z to 0u, t to 4u) to o, + ).checkDegreeBy("test 6") + } + } + @Test + fun test_variables() { + RationalField.labeledPolynomialSpace { + assertEquals( + setOf(), + LabeledPolynomial().variables, + "test 1" + ) + assertEquals( + setOf(), + LabeledPolynomial( + mapOf() to o + ).variables, + "test 2" + ) + assertEquals( + setOf(x, y, z), + LabeledPolynomial( + mapOf(x to 1u, y to 2u, z to 3u) to o + ).variables, + "test 3" + ) + assertEquals( + setOf(y, z, t), + LabeledPolynomial( + mapOf(x to 0u, y to 1u, z to 2u, t to 1u, s to 0u) to o + ).variables, + "test 4" + ) + assertEquals( + setOf(x, y, z), + LabeledPolynomial( + mapOf() to o, + mapOf(x to 0u, y to 1u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + ).variables, + "test 5" + ) + assertEquals( + setOf(x, y, z, t), + LabeledPolynomial( + mapOf() to o, + mapOf(x to 1u, y to 2u) to o, + mapOf(x to 0u, y to 1u, z to 2u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + mapOf(x to 0u, y to 0u, z to 0u, t to 4u) to o, + ).variables, + "test 6" + ) + } + } + @Test + fun test_countOfVariables() { + RationalField.labeledPolynomialSpace { + assertEquals( + 0, + LabeledPolynomial().countOfVariables, + "test 1" + ) + assertEquals( + 0, + LabeledPolynomial( + mapOf() to o + ).countOfVariables, + "test 2" + ) + assertEquals( + 3, + LabeledPolynomial( + mapOf(x to 1u, y to 2u, z to 3u) to o + ).countOfVariables, + "test 3" + ) + assertEquals( + 3, + LabeledPolynomial( + mapOf(x to 0u, y to 1u, z to 2u, t to 1u, s to 0u) to o + ).countOfVariables, + "test 4" + ) + assertEquals( + 3, + LabeledPolynomial( + mapOf() to o, + mapOf(x to 0u, y to 1u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + ).countOfVariables, + "test 5" + ) + assertEquals( + 4, + LabeledPolynomial( + mapOf() to o, + mapOf(x to 1u, y to 2u) to o, + mapOf(x to 0u, y to 1u, z to 2u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + mapOf(x to 0u, y to 0u, z to 0u, t to 4u) to o, + ).countOfVariables, + "test 6" + ) + } + } + @Test + fun test_RF_countOfVariables() { + RationalField.labeledRationalFunctionSpace { + assertEquals( + 0, + LabeledRationalFunction( + LabeledPolynomial() + ).countOfVariables, + "test 1" + ) + assertEquals( + 0, + LabeledRationalFunction( + LabeledPolynomial(), + LabeledPolynomial() + ).countOfVariables, + "test 2" + ) + assertEquals( + 0, + LabeledRationalFunction( + LabeledPolynomial( + mapOf() to o + ) + ).countOfVariables, + "test 3" + ) + assertEquals( + 3, + LabeledRationalFunction( + LabeledPolynomial( + mapOf(x to 1u, y to 2u, z to 3u) to o + ) + ).countOfVariables, + "test 4" + ) + assertEquals( + 3, + LabeledRationalFunction( + LabeledPolynomial( + mapOf(x to 0u, y to 1u, z to 0u, t to 1u) to o + ), + LabeledPolynomial( + mapOf(x to 0u, y to 0u, z to 2u) to o + ) + ).countOfVariables, + "test 5" + ) + assertEquals( + 3, + LabeledRationalFunction( + LabeledPolynomial( + mapOf() to o, + mapOf(x to 0u, y to 1u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + ) + ).countOfVariables, + "test 6" + ) + assertEquals( + 4, + LabeledRationalFunction( + LabeledPolynomial( + mapOf() to o, + mapOf(x to 1u, y to 2u) to o, + mapOf(x to 2u, y to 0u, z to 1u) to o, + ), LabeledPolynomial( + mapOf(x to 0u, y to 1u, z to 2u) to o, + mapOf(x to 0u, y to 0u, z to 0u, t to 4u) to o, + ) + ).countOfVariables, + "test 7" + ) + } + } +} \ No newline at end of file diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledPolynomialUtilTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledPolynomialUtilTest.kt new file mode 100644 index 000000000..cdfe309f9 --- /dev/null +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/LabeledPolynomialUtilTest.kt @@ -0,0 +1,8224 @@ +/* + * Copyright 2018-2021 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.functions + +import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.symbol +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.test.misc.Rational +import space.kscience.kmath.test.misc.RationalField +import space.kscience.kmath.test.misc.assertEquals +import kotlin.test.Ignore +import kotlin.test.Test +import kotlin.test.assertEquals + +class LabeledPolynomialUtilTest { + val x by symbol + val y by symbol + val iota by symbol + + @Test + fun test_Polynomial_substitute_Double() { + assertEquals( + LabeledPolynomialAsIs(emptyMap() to 0.0), + LabeledPolynomialAsIs( + mapOf() to 1.0, + mapOf(x to 1u) to -2.0, + mapOf(x to 2u) to 1.0, + ).substitute(mapOf( + x to 1.0 + )), + 0.001, + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ), + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ).substitute(mapOf()), + 0.001, + "test 2" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ), + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ).substitute(mapOf( + iota to 0.9211194782050933 + )), + 0.001, + "test 2'" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(y to 2u) to 0.2700930201481795, + ), + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ).substitute(mapOf( + x to 0.0 + )), + 0.001, + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(y to 2u) to 0.2700930201481795, + ), + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ).substitute(mapOf( + x to 0.0, + iota to 0.9211194782050933 + )), + 0.001, + "test 3'" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 1.433510890645169, + mapOf(x to 1u) to 0.6264844682514724, + mapOf(x to 2u) to 0.8405727903771333, + ), + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ).substitute(mapOf( + y to 0.8400458576651112 + )), + 0.001, + "test 4" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 1.433510890645169, + mapOf(x to 1u) to 0.6264844682514724, + mapOf(x to 2u) to 0.8405727903771333, + ), + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ).substitute(mapOf( + y to 0.8400458576651112, + iota to 0.9211194782050933 + )), + 0.001, + "test 4'" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 1.934530767358133, + ), + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ).substitute(mapOf( + x to 0.4846192734143442, + y to 0.8400458576651112, + )), + 0.001, + "test 5" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to 1.934530767358133, + ), + LabeledPolynomialAsIs( + mapOf() to 0.8597048543814783, + mapOf(x to 1u) to 0.22997637465889875, + mapOf(x to 2u) to 0.32675302591924016, + mapOf(y to 1u) to 0.4561746111587508, + mapOf(x to 1u, y to 1u) to 0.5304946210170756, + mapOf(x to 2u, y to 1u) to 0.6244313712888998, + mapOf(y to 2u) to 0.2700930201481795, + mapOf(x to 1u, y to 2u) to -0.06962351375204712, + mapOf(x to 2u, y to 2u) to -0.015206988092131501, + ).substitute(mapOf( + x to 0.4846192734143442, + y to 0.8400458576651112, + iota to 0.9211194782050933 + )), + 0.001, + "test 5'" + ) + } + @Test + fun test_Polynomial_substitute_Constant_Map() { + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1) + ).substitute(RationalField, mapOf( + x to Rational(1) + )), + "test 1" + ) + // https://www.wolframalpha.com/input?i=%28-3%2F2+%2B+8%2F6+x+%2B+14%2F6+x%5E2%29+%2B+%28-3%2F1+%2B+-19%2F2+x+%2B+9%2F4+x%5E2%29+y+%2B+%285%2F5+%2B+18%2F9+x+%2B+5%2F2+x%5E2%29+y%5E2+where+x+%3D+-2%2F5%2C+y+%3D+12%2F9 + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(143, 150) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to Rational(-2, 5), + y to Rational(12, 9), + )), + "test 2" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(143, 150) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to Rational(-2, 5), + y to Rational(12, 9), + iota to Rational(57, 179), + )), + "test 2'" + ) + // https://www.wolframalpha.com/input?i=%28-3%2F2+%2B+8%2F6+x+%2B+14%2F6+x%5E2%29+%2B+%28-3%2F1+%2B+-19%2F2+x+%2B+9%2F4+x%5E2%29+y+%2B+%285%2F5+%2B+18%2F9+x+%2B+5%2F2+x%5E2%29+y%5E2+where+y+%3D+12%2F9 + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-67, 18), + mapOf(x to 1u) to Rational(-70, 9), + mapOf(x to 2u) to Rational(88, 9), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + y to Rational(12, 9), + )), + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-67, 18), + mapOf(x to 1u) to Rational(-70, 9), + mapOf(x to 2u) to Rational(88, 9), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + y to Rational(12, 9), + iota to Rational(57, 179), + )), + "test 3'" + ) + // https://www.wolframalpha.com/input?i=%28-3%2F2+%2B+8%2F6+x+%2B+14%2F6+x%5E2%29+%2B+%28-3%2F1+%2B+-19%2F2+x+%2B+9%2F4+x%5E2%29+y+%2B+%285%2F5+%2B+18%2F9+x+%2B+5%2F2+x%5E2%29+y%5E2+where+x+%3D+-2%2F5 + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-83, 50), + mapOf(y to 1u) to Rational(29, 25), + mapOf(y to 2u) to Rational(3, 5), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to Rational(-2, 5), + )), + "test 4" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-83, 50), + mapOf(y to 1u) to Rational(29, 25), + mapOf(y to 2u) to Rational(3, 5), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to Rational(-2, 5), + iota to Rational(57, 179), + )), + "test 4'" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf()), + "test 5" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + iota to Rational(57, 179), + )), + "test 5'" + ) + // https://www.wolframalpha.com/input?i=%28%28-3%2F2+%2B+8%2F6+x+%2B+14%2F6+x%5E2%29+%2B+%28-3%2F1+%2B+-19%2F2+x+%2B+9%2F4+x%5E2%29+y+%2B+%285%2F5+%2B+18%2F9+x+%2B+5%2F2+x%5E2%29+y%5E2%29+p%5E8+where+x+%3D+q%2Fp%2C+y+%3D+x%5E3%2C+p+%3D+-2%2F5%2C+q+%3D+12%2F9 + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(47639065216, 2562890625) + ), + LabeledPolynomialAsIs( + mapOf(x to 8u) to Rational(-3, 2), + mapOf(x to 7u, y to 1u) to Rational(8, 6), + mapOf(x to 6u, y to 2u) to Rational(14, 6), + mapOf(x to 5u, y to 3u) to Rational(-3, 1), + mapOf(x to 4u, y to 4u) to Rational(-19, 2), + mapOf(x to 3u, y to 5u) to Rational(9, 4), + mapOf(x to 2u, y to 6u) to Rational(5, 5), + mapOf(x to 1u, y to 7u) to Rational(18, 9), + mapOf(y to 8u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to Rational(-2, 5), + y to Rational(12, 9), + )), + "test 6" + ) + } + @Test + fun test_Polynomial_substitute_Polynomial_Map() { + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1) + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + )), + "test 1" + ) + // https://www.wolframalpha.com/input?i=%28-3%2F2+%2B+8%2F6+x+%2B+14%2F6+x%5E2%29+%2B+%28-3%2F1+%2B+-19%2F2+x+%2B+9%2F4+x%5E2%29+y+%2B+%285%2F5+%2B+18%2F9+x+%2B+5%2F2+x%5E2%29+y%5E2+where+x+%3D+-5%2F1+s+%2B+2%2F8+t%2C+y+%3D+11%2F7+t + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(y to 1u) to Rational(-92, 21), + mapOf(y to 2u) to Rational(-2627, 2352), + mapOf(y to 3u) to Rational(4565, 3136), + mapOf(y to 4u) to Rational(605, 1568), + mapOf(x to 1u) to Rational(-20, 3), + mapOf(x to 1u, y to 1u) to Rational(1445, 21), + mapOf(x to 1u, y to 2u) to Rational(-13145, 392), + mapOf(x to 1u, y to 3u) to Rational(-3025, 196), + mapOf(x to 2u) to Rational(175, 3), + mapOf(x to 2u, y to 1u) to Rational(2475, 28), + mapOf(x to 2u, y to 2u) to Rational(15125, 98), + mapOf(x to 3u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(-5, 1), + mapOf(y to 1u) to Rational(2, 8), + ), + y to LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(0, 5), + mapOf(y to 1u) to Rational(11, 7), + ), + )), + "test 2" + ) + // (-3/2 + 8/6 x + 14/6 x^2) + (-3/1 + -19/2 x + 9/4 x^2) y + (5/5 + 18/9 x + 5/2 x^2) y^2 where x = (0/6 + 14/8 s + -14/2 s^2) + (-3/5 + 11/1 s + 3/7 s^2) t + (-3/7 + -18/5 s + -9/1 s^2) t^2, y = (-9/2 + 2/7 s + 9/1 s^2) + (13/1 + -1/8 s + 2/8 s^2) t + (19/4 + 15/7 s + -19/4 s^2) t^2 + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(129, 4), + mapOf(x to 1u) to Rational(48583, 336), + mapOf(x to 2u) to Rational(-913477, 1568), + mapOf(x to 3u) to Rational(-967567, 672), + mapOf(x to 4u) to Rational(4722043, 1344), + mapOf(x to 5u) to Rational(8855, 2), + mapOf(x to 6u) to Rational(-311971, 32), + mapOf(x to 7u) to Rational(-17325, 4), + mapOf(x to 8u) to Rational(19845, 2), + mapOf(y to 1u) to Rational(-827, 4), + mapOf(x to 1u, y to 1u) to Rational(191927, 840), + mapOf(x to 2u, y to 1u) to Rational(9592627, 2352), + mapOf(x to 3u, y to 1u) to Rational(-105400711, 53760), + mapOf(x to 4u, y to 1u) to Rational(-10054101459, 439040), + mapOf(x to 5u, y to 1u) to Rational(2127351, 128), + mapOf(x to 6u, y to 1u) to Rational(116680973, 3136), + mapOf(x to 7u, y to 1u) to Rational(-220445, 7), + mapOf(x to 8u, y to 1u) to Rational(-2655, 4), + mapOf(y to 2u) to Rational(30567, 100), + mapOf(x to 1u, y to 2u) to Rational(-156284953, 39200), + mapOf(x to 2u, y to 2u) to Rational(-57661541711, 6585600), + mapOf(x to 3u, y to 2u) to Rational(131931579, 3136), + mapOf(x to 4u, y to 2u) to Rational(98818124791, 3512320), + mapOf(x to 5u, y to 2u) to Rational(-94458855053, 878080), + mapOf(x to 6u, y to 2u) to Rational(13937705305, 1229312), + mapOf(x to 7u, y to 2u) to Rational(335706887, 21952), + mapOf(x to 8u, y to 2u) to Rational(23549165, 1568), + mapOf(y to 3u) to Rational(111367, 1400), + mapOf(x to 1u, y to 3u) to Rational(4937369, 700), + mapOf(x to 2u, y to 3u) to Rational(-4449423711, 274400), + mapOf(x to 3u, y to 3u) to Rational(-351873325703, 4390400), + mapOf(x to 4u, y to 3u) to Rational(23495875029, 307328), + mapOf(x to 5u, y to 3u) to Rational(17576300919, 878080), + mapOf(x to 6u, y to 3u) to Rational(230316993, 12544), + mapOf(x to 7u, y to 3u) to Rational(-191130515, 21952), + mapOf(x to 8u, y to 3u) to Rational(332435, 392), + mapOf(y to 4u) to Rational(-275084, 1225), + mapOf(x to 1u, y to 4u) to Rational(-266774603, 137200), + mapOf(x to 2u, y to 4u) to Rational(2176279167121, 30732800), + mapOf(x to 3u, y to 4u) to Rational(10904913303, 2195200), + mapOf(x to 4u, y to 4u) to Rational(-10769286147, 2195200), + mapOf(x to 5u, y to 4u) to Rational(-26277119793, 439040), + mapOf(x to 6u, y to 4u) to Rational(25859735869, 6146560), + mapOf(x to 7u, y to 4u) to Rational(38906289, 2744), + mapOf(x to 8u, y to 4u) to Rational(-3072025, 392), + mapOf(y to 5u) to Rational(9573, 98), + mapOf(x to 1u, y to 5u) to Rational(-4154651399, 548800), + mapOf(x to 2u, y to 5u) to Rational(3446069019, 548800), + mapOf(x to 3u, y to 5u) to Rational(-7851500623, 137200), + mapOf(x to 4u, y to 5u) to Rational(-53205142903, 1920800), + mapOf(x to 5u, y to 5u) to Rational(-31953611, 3430), + mapOf(x to 6u, y to 5u) to Rational(1447380313, 109760), + mapOf(x to 7u, y to 5u) to Rational(764158625, 21952), + mapOf(x to 8u, y to 5u) to Rational(1153515, 784), + mapOf(y to 6u) to Rational(1722351, 7840), + mapOf(x to 1u, y to 6u) to Rational(-164554821, 109760), + mapOf(x to 2u, y to 6u) to Rational(-79096147243, 7683200), + mapOf(x to 3u, y to 6u) to Rational(-624721089, 15680), + mapOf(x to 4u, y to 6u) to Rational(11147305567, 548800), + mapOf(x to 5u, y to 6u) to Rational(8318333679, 109760), + mapOf(x to 6u, y to 6u) to Rational(32981871553, 1536640), + mapOf(x to 7u, y to 6u) to Rational(-225359619, 21952), + mapOf(x to 8u, y to 6u) to Rational(-3973995, 392), + mapOf(y to 7u) to Rational(67203, 784), + mapOf(x to 1u, y to 7u) to Rational(39281469, 54880), + mapOf(x to 2u, y to 7u) to Rational(70162551, 27440), + mapOf(x to 3u, y to 7u) to Rational(413630709, 54880), + mapOf(x to 4u, y to 7u) to Rational(4640410269, 192080), + mapOf(x to 5u, y to 7u) to Rational(802712247, 54880), + mapOf(x to 6u, y to 7u) to Rational(-473517603, 27440), + mapOf(x to 7u, y to 7u) to Rational(-17055459, 1568), + mapOf(x to 8u, y to 7u) to Rational(-12825, 14), + mapOf(y to 8u) to Rational(16245, 1568), + mapOf(x to 1u, y to 8u) to Rational(503253, 2744), + mapOf(x to 2u, y to 8u) to Rational(125292591, 96040), + mapOf(x to 3u, y to 8u) to Rational(12033171, 2744), + mapOf(x to 4u, y to 8u) to Rational(154352673, 27440), + mapOf(x to 5u, y to 8u) to Rational(-1302291, 392), + mapOf(x to 6u, y to 8u) to Rational(-20265741, 1960), + mapOf(x to 7u, y to 8u) to Rational(-26163, 56), + mapOf(x to 8u, y to 8u) to Rational(146205, 32), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(0, 6), + mapOf(x to 1u) to Rational(14, 8), + mapOf(x to 2u) to Rational(-14, 2), + mapOf(y to 1u) to Rational(-3, 5), + mapOf(x to 1u, y to 1u) to Rational(11, 1), + mapOf(x to 2u, y to 1u) to Rational(3, 7), + mapOf(y to 2u) to Rational(-3, 7), + mapOf(x to 1u, y to 2u) to Rational(-18, 5), + mapOf(x to 2u, y to 2u) to Rational(-9, 1), + ), + y to LabeledPolynomialAsIs( + mapOf() to Rational(-9, 2), + mapOf(x to 1u) to Rational(2, 7), + mapOf(x to 2u) to Rational(9, 1), + mapOf(y to 1u) to Rational(13, 1), + mapOf(x to 1u, y to 1u) to Rational(-1, 8), + mapOf(x to 2u, y to 1u) to Rational(2, 8), + mapOf(y to 2u) to Rational(19, 4), + mapOf(x to 1u, y to 2u) to Rational(15, 7), + mapOf(x to 2u, y to 2u) to Rational(-19, 4), + ), + )), + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(129, 4), + mapOf(x to 1u) to Rational(48583, 336), + mapOf(x to 2u) to Rational(-913477, 1568), + mapOf(x to 3u) to Rational(-967567, 672), + mapOf(x to 4u) to Rational(4722043, 1344), + mapOf(x to 5u) to Rational(8855, 2), + mapOf(x to 6u) to Rational(-311971, 32), + mapOf(x to 7u) to Rational(-17325, 4), + mapOf(x to 8u) to Rational(19845, 2), + mapOf(y to 1u) to Rational(-827, 4), + mapOf(x to 1u, y to 1u) to Rational(191927, 840), + mapOf(x to 2u, y to 1u) to Rational(9592627, 2352), + mapOf(x to 3u, y to 1u) to Rational(-105400711, 53760), + mapOf(x to 4u, y to 1u) to Rational(-10054101459, 439040), + mapOf(x to 5u, y to 1u) to Rational(2127351, 128), + mapOf(x to 6u, y to 1u) to Rational(116680973, 3136), + mapOf(x to 7u, y to 1u) to Rational(-220445, 7), + mapOf(x to 8u, y to 1u) to Rational(-2655, 4), + mapOf(y to 2u) to Rational(30567, 100), + mapOf(x to 1u, y to 2u) to Rational(-156284953, 39200), + mapOf(x to 2u, y to 2u) to Rational(-57661541711, 6585600), + mapOf(x to 3u, y to 2u) to Rational(131931579, 3136), + mapOf(x to 4u, y to 2u) to Rational(98818124791, 3512320), + mapOf(x to 5u, y to 2u) to Rational(-94458855053, 878080), + mapOf(x to 6u, y to 2u) to Rational(13937705305, 1229312), + mapOf(x to 7u, y to 2u) to Rational(335706887, 21952), + mapOf(x to 8u, y to 2u) to Rational(23549165, 1568), + mapOf(y to 3u) to Rational(111367, 1400), + mapOf(x to 1u, y to 3u) to Rational(4937369, 700), + mapOf(x to 2u, y to 3u) to Rational(-4449423711, 274400), + mapOf(x to 3u, y to 3u) to Rational(-351873325703, 4390400), + mapOf(x to 4u, y to 3u) to Rational(23495875029, 307328), + mapOf(x to 5u, y to 3u) to Rational(17576300919, 878080), + mapOf(x to 6u, y to 3u) to Rational(230316993, 12544), + mapOf(x to 7u, y to 3u) to Rational(-191130515, 21952), + mapOf(x to 8u, y to 3u) to Rational(332435, 392), + mapOf(y to 4u) to Rational(-275084, 1225), + mapOf(x to 1u, y to 4u) to Rational(-266774603, 137200), + mapOf(x to 2u, y to 4u) to Rational(2176279167121, 30732800), + mapOf(x to 3u, y to 4u) to Rational(10904913303, 2195200), + mapOf(x to 4u, y to 4u) to Rational(-10769286147, 2195200), + mapOf(x to 5u, y to 4u) to Rational(-26277119793, 439040), + mapOf(x to 6u, y to 4u) to Rational(25859735869, 6146560), + mapOf(x to 7u, y to 4u) to Rational(38906289, 2744), + mapOf(x to 8u, y to 4u) to Rational(-3072025, 392), + mapOf(y to 5u) to Rational(9573, 98), + mapOf(x to 1u, y to 5u) to Rational(-4154651399, 548800), + mapOf(x to 2u, y to 5u) to Rational(3446069019, 548800), + mapOf(x to 3u, y to 5u) to Rational(-7851500623, 137200), + mapOf(x to 4u, y to 5u) to Rational(-53205142903, 1920800), + mapOf(x to 5u, y to 5u) to Rational(-31953611, 3430), + mapOf(x to 6u, y to 5u) to Rational(1447380313, 109760), + mapOf(x to 7u, y to 5u) to Rational(764158625, 21952), + mapOf(x to 8u, y to 5u) to Rational(1153515, 784), + mapOf(y to 6u) to Rational(1722351, 7840), + mapOf(x to 1u, y to 6u) to Rational(-164554821, 109760), + mapOf(x to 2u, y to 6u) to Rational(-79096147243, 7683200), + mapOf(x to 3u, y to 6u) to Rational(-624721089, 15680), + mapOf(x to 4u, y to 6u) to Rational(11147305567, 548800), + mapOf(x to 5u, y to 6u) to Rational(8318333679, 109760), + mapOf(x to 6u, y to 6u) to Rational(32981871553, 1536640), + mapOf(x to 7u, y to 6u) to Rational(-225359619, 21952), + mapOf(x to 8u, y to 6u) to Rational(-3973995, 392), + mapOf(y to 7u) to Rational(67203, 784), + mapOf(x to 1u, y to 7u) to Rational(39281469, 54880), + mapOf(x to 2u, y to 7u) to Rational(70162551, 27440), + mapOf(x to 3u, y to 7u) to Rational(413630709, 54880), + mapOf(x to 4u, y to 7u) to Rational(4640410269, 192080), + mapOf(x to 5u, y to 7u) to Rational(802712247, 54880), + mapOf(x to 6u, y to 7u) to Rational(-473517603, 27440), + mapOf(x to 7u, y to 7u) to Rational(-17055459, 1568), + mapOf(x to 8u, y to 7u) to Rational(-12825, 14), + mapOf(y to 8u) to Rational(16245, 1568), + mapOf(x to 1u, y to 8u) to Rational(503253, 2744), + mapOf(x to 2u, y to 8u) to Rational(125292591, 96040), + mapOf(x to 3u, y to 8u) to Rational(12033171, 2744), + mapOf(x to 4u, y to 8u) to Rational(154352673, 27440), + mapOf(x to 5u, y to 8u) to Rational(-1302291, 392), + mapOf(x to 6u, y to 8u) to Rational(-20265741, 1960), + mapOf(x to 7u, y to 8u) to Rational(-26163, 56), + mapOf(x to 8u, y to 8u) to Rational(146205, 32), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(0, 6), + mapOf(x to 1u) to Rational(14, 8), + mapOf(x to 2u) to Rational(-14, 2), + mapOf(y to 1u) to Rational(-3, 5), + mapOf(x to 1u, y to 1u) to Rational(11, 1), + mapOf(x to 2u, y to 1u) to Rational(3, 7), + mapOf(y to 2u) to Rational(-3, 7), + mapOf(x to 1u, y to 2u) to Rational(-18, 5), + mapOf(x to 2u, y to 2u) to Rational(-9, 1), + ), + y to LabeledPolynomialAsIs( + mapOf() to Rational(-9, 2), + mapOf(x to 1u) to Rational(2, 7), + mapOf(x to 2u) to Rational(9, 1), + mapOf(y to 1u) to Rational(13, 1), + mapOf(x to 1u, y to 1u) to Rational(-1, 8), + mapOf(x to 2u, y to 1u) to Rational(2, 8), + mapOf(y to 2u) to Rational(19, 4), + mapOf(x to 1u, y to 2u) to Rational(15, 7), + mapOf(x to 2u, y to 2u) to Rational(-19, 4), + ), + iota to LabeledPolynomialAsIs( + mapOf() to Rational(-11, 3), + mapOf(x to 1u) to Rational(5, 2), + mapOf(x to 2u) to Rational(13, 7), + mapOf(y to 1u) to Rational(16, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(6, 1), + mapOf(y to 2u) to Rational(-14, 3), + mapOf(x to 1u, y to 2u) to Rational(-2, 7), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + )), + "test 3'" + ) + // (-3/2 + 8/6 x + 14/6 x^2) + (-3/1 + -19/2 x + 9/4 x^2) y + (5/5 + 18/9 x + 5/2 x^2) y^2 where x = s, y = (-9/2 + 2/7 s + 9/1 s^2) + (13/1 + -1/8 s + 2/8 s^2) t + (19/4 + 15/7 s + -19/4 s^2) t^2 + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(129, 4), + mapOf(x to 1u) to Rational(6817, 84), + mapOf(x to 2u) to Rational(-21445, 294), + mapOf(x to 3u) to Rational(-12151, 49), + mapOf(x to 4u) to Rational(-17789, 196), + mapOf(x to 5u) to Rational(1224, 7), + mapOf(x to 6u) to Rational(405, 2), + mapOf(y to 1u) to Rational(-156), + mapOf(x to 1u, y to 1u) to Rational(-2440, 7), + mapOf(x to 2u, y to 1u) to Rational(-1571, 112), + mapOf(x to 3u, y to 1u) to Rational(107515, 224), + mapOf(x to 4u, y to 1u) to Rational(64965, 112), + mapOf(x to 5u, y to 1u) to Rational(209, 56), + mapOf(x to 6u, y to 1u) to Rational(45, 4), + mapOf(y to 2u) to Rational(112), + mapOf(x to 1u, y to 2u) to Rational(1449, 8), + mapOf(x to 2u, y to 2u) to Rational(1306309, 3136), + mapOf(x to 3u, y to 2u) to Rational(483207, 1568), + mapOf(x to 4u, y to 2u) to Rational(1978437, 6272), + mapOf(x to 5u, y to 2u) to Rational(-18231, 224), + mapOf(x to 6u, y to 2u) to Rational(-6835, 32), + mapOf(y to 3u) to Rational(247, 2), + mapOf(x to 1u, y to 3u) to Rational(33771, 112), + mapOf(x to 2u, y to 3u) to Rational(2073, 7), + mapOf(x to 3u, y to 3u) to Rational(-23463, 224), + mapOf(x to 4u, y to 3u) to Rational(-33825, 112), + mapOf(x to 5u, y to 3u) to Rational(201, 224), + mapOf(x to 6u, y to 3u) to Rational(-95, 16), + mapOf(y to 4u) to Rational(361, 16), + mapOf(x to 1u, y to 4u) to Rational(3667, 56), + mapOf(x to 2u, y to 4u) to Rational(88729, 1568), + mapOf(x to 3u, y to 4u) to Rational(-2476, 49), + mapOf(x to 4u, y to 4u) to Rational(-23419, 196), + mapOf(x to 5u, y to 4u) to Rational(-323, 56), + mapOf(x to 6u, y to 4u) to Rational(1805, 32), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + y to LabeledPolynomialAsIs( + mapOf() to Rational(-9, 2), + mapOf(x to 1u) to Rational(2, 7), + mapOf(x to 2u) to Rational(9, 1), + mapOf(y to 1u) to Rational(13, 1), + mapOf(x to 1u, y to 1u) to Rational(-1, 8), + mapOf(x to 2u, y to 1u) to Rational(2, 8), + mapOf(y to 2u) to Rational(19, 4), + mapOf(x to 1u, y to 2u) to Rational(15, 7), + mapOf(x to 2u, y to 2u) to Rational(-19, 4), + ), + )), + "test 4" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(129, 4), + mapOf(x to 1u) to Rational(6817, 84), + mapOf(x to 2u) to Rational(-21445, 294), + mapOf(x to 3u) to Rational(-12151, 49), + mapOf(x to 4u) to Rational(-17789, 196), + mapOf(x to 5u) to Rational(1224, 7), + mapOf(x to 6u) to Rational(405, 2), + mapOf(y to 1u) to Rational(-156), + mapOf(x to 1u, y to 1u) to Rational(-2440, 7), + mapOf(x to 2u, y to 1u) to Rational(-1571, 112), + mapOf(x to 3u, y to 1u) to Rational(107515, 224), + mapOf(x to 4u, y to 1u) to Rational(64965, 112), + mapOf(x to 5u, y to 1u) to Rational(209, 56), + mapOf(x to 6u, y to 1u) to Rational(45, 4), + mapOf(y to 2u) to Rational(112), + mapOf(x to 1u, y to 2u) to Rational(1449, 8), + mapOf(x to 2u, y to 2u) to Rational(1306309, 3136), + mapOf(x to 3u, y to 2u) to Rational(483207, 1568), + mapOf(x to 4u, y to 2u) to Rational(1978437, 6272), + mapOf(x to 5u, y to 2u) to Rational(-18231, 224), + mapOf(x to 6u, y to 2u) to Rational(-6835, 32), + mapOf(y to 3u) to Rational(247, 2), + mapOf(x to 1u, y to 3u) to Rational(33771, 112), + mapOf(x to 2u, y to 3u) to Rational(2073, 7), + mapOf(x to 3u, y to 3u) to Rational(-23463, 224), + mapOf(x to 4u, y to 3u) to Rational(-33825, 112), + mapOf(x to 5u, y to 3u) to Rational(201, 224), + mapOf(x to 6u, y to 3u) to Rational(-95, 16), + mapOf(y to 4u) to Rational(361, 16), + mapOf(x to 1u, y to 4u) to Rational(3667, 56), + mapOf(x to 2u, y to 4u) to Rational(88729, 1568), + mapOf(x to 3u, y to 4u) to Rational(-2476, 49), + mapOf(x to 4u, y to 4u) to Rational(-23419, 196), + mapOf(x to 5u, y to 4u) to Rational(-323, 56), + mapOf(x to 6u, y to 4u) to Rational(1805, 32), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + y to LabeledPolynomialAsIs( + mapOf() to Rational(-9, 2), + mapOf(x to 1u) to Rational(2, 7), + mapOf(x to 2u) to Rational(9, 1), + mapOf(y to 1u) to Rational(13, 1), + mapOf(x to 1u, y to 1u) to Rational(-1, 8), + mapOf(x to 2u, y to 1u) to Rational(2, 8), + mapOf(y to 2u) to Rational(19, 4), + mapOf(x to 1u, y to 2u) to Rational(15, 7), + mapOf(x to 2u, y to 2u) to Rational(-19, 4), + ), + iota to LabeledPolynomialAsIs( + mapOf() to Rational(-11, 3), + mapOf(x to 1u) to Rational(5, 2), + mapOf(x to 2u) to Rational(13, 7), + mapOf(y to 1u) to Rational(16, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(6, 1), + mapOf(y to 2u) to Rational(-14, 3), + mapOf(x to 1u, y to 2u) to Rational(-2, 7), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + )), + "test 4'" + ) + // (-3/2 + 8/6 x + 14/6 x^2) + (-3/1 + -19/2 x + 9/4 x^2) y + (5/5 + 18/9 x + 5/2 x^2) y^2 where x = (0/6 + 14/8 s + -14/2 s^2) + (-3/5 + 11/1 s + 3/7 s^2) t + (-3/7 + -18/5 s + -9/1 s^2) t^2, y = t + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(7, 3), + mapOf(x to 2u) to Rational(-35, 16), + mapOf(x to 3u) to Rational(-343, 6), + mapOf(x to 4u) to Rational(343, 3), + mapOf(y to 1u) to Rational(-19, 5), + mapOf(x to 1u, y to 1u) to Rational(-823, 120), + mapOf(x to 2u, y to 1u) to Rational(1232417, 6720), + mapOf(x to 3u, y to 1u) to Rational(-9863, 24), + mapOf(x to 4u, y to 1u) to Rational(385, 4), + mapOf(y to 2u) to Rational(2439, 350), + mapOf(x to 1u, y to 2u) to Rational(-5793, 40), + mapOf(x to 2u, y to 2u) to Rational(1172113, 3360), + mapOf(x to 3u, y to 2u) to Rational(-13531, 40), + mapOf(x to 4u, y to 2u) to Rational(2824, 7), + mapOf(y to 3u) to Rational(3417, 700), + mapOf(x to 1u, y to 3u) to Rational(1191, 200), + mapOf(x to 2u, y to 3u) to Rational(8383, 28), + mapOf(x to 3u, y to 3u) to Rational(-220279, 280), + mapOf(x to 4u, y to 3u) to Rational(49179, 196), + mapOf(y to 4u) to Rational(57, 35), + mapOf(x to 1u, y to 4u) to Rational(-33771, 700), + mapOf(x to 2u, y to 4u) to Rational(196279, 1225), + mapOf(x to 3u, y to 4u) to Rational(-32259, 140), + mapOf(x to 4u, y to 4u) to Rational(23868, 49), + mapOf(y to 5u) to Rational(333, 196), + mapOf(x to 1u, y to 5u) to Rational(-204, 35), + mapOf(x to 2u, y to 5u) to Rational(-307233, 2450), + mapOf(x to 3u, y to 5u) to Rational(-12492, 35), + mapOf(x to 4u, y to 5u) to Rational(4563, 28), + mapOf(y to 6u) to Rational(45, 98), + mapOf(x to 1u, y to 6u) to Rational(54, 7), + mapOf(x to 2u, y to 6u) to Rational(1809, 35), + mapOf(x to 3u, y to 6u) to Rational(162), + mapOf(x to 4u, y to 6u) to Rational(405, 2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(0, 6), + mapOf(x to 1u) to Rational(14, 8), + mapOf(x to 2u) to Rational(-14, 2), + mapOf(y to 1u) to Rational(-3, 5), + mapOf(x to 1u, y to 1u) to Rational(11, 1), + mapOf(x to 2u, y to 1u) to Rational(3, 7), + mapOf(y to 2u) to Rational(-3, 7), + mapOf(x to 1u, y to 2u) to Rational(-18, 5), + mapOf(x to 2u, y to 2u) to Rational(-9, 1), + ), + )), + "test 5" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(7, 3), + mapOf(x to 2u) to Rational(-35, 16), + mapOf(x to 3u) to Rational(-343, 6), + mapOf(x to 4u) to Rational(343, 3), + mapOf(y to 1u) to Rational(-19, 5), + mapOf(x to 1u, y to 1u) to Rational(-823, 120), + mapOf(x to 2u, y to 1u) to Rational(1232417, 6720), + mapOf(x to 3u, y to 1u) to Rational(-9863, 24), + mapOf(x to 4u, y to 1u) to Rational(385, 4), + mapOf(y to 2u) to Rational(2439, 350), + mapOf(x to 1u, y to 2u) to Rational(-5793, 40), + mapOf(x to 2u, y to 2u) to Rational(1172113, 3360), + mapOf(x to 3u, y to 2u) to Rational(-13531, 40), + mapOf(x to 4u, y to 2u) to Rational(2824, 7), + mapOf(y to 3u) to Rational(3417, 700), + mapOf(x to 1u, y to 3u) to Rational(1191, 200), + mapOf(x to 2u, y to 3u) to Rational(8383, 28), + mapOf(x to 3u, y to 3u) to Rational(-220279, 280), + mapOf(x to 4u, y to 3u) to Rational(49179, 196), + mapOf(y to 4u) to Rational(57, 35), + mapOf(x to 1u, y to 4u) to Rational(-33771, 700), + mapOf(x to 2u, y to 4u) to Rational(196279, 1225), + mapOf(x to 3u, y to 4u) to Rational(-32259, 140), + mapOf(x to 4u, y to 4u) to Rational(23868, 49), + mapOf(y to 5u) to Rational(333, 196), + mapOf(x to 1u, y to 5u) to Rational(-204, 35), + mapOf(x to 2u, y to 5u) to Rational(-307233, 2450), + mapOf(x to 3u, y to 5u) to Rational(-12492, 35), + mapOf(x to 4u, y to 5u) to Rational(4563, 28), + mapOf(y to 6u) to Rational(45, 98), + mapOf(x to 1u, y to 6u) to Rational(54, 7), + mapOf(x to 2u, y to 6u) to Rational(1809, 35), + mapOf(x to 3u, y to 6u) to Rational(162), + mapOf(x to 4u, y to 6u) to Rational(405, 2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(0, 6), + mapOf(x to 1u) to Rational(14, 8), + mapOf(x to 2u) to Rational(-14, 2), + mapOf(y to 1u) to Rational(-3, 5), + mapOf(x to 1u, y to 1u) to Rational(11, 1), + mapOf(x to 2u, y to 1u) to Rational(3, 7), + mapOf(y to 2u) to Rational(-3, 7), + mapOf(x to 1u, y to 2u) to Rational(-18, 5), + mapOf(x to 2u, y to 2u) to Rational(-9, 1), + ), + iota to LabeledPolynomialAsIs( + mapOf() to Rational(-11, 3), + mapOf(x to 1u) to Rational(5, 2), + mapOf(x to 2u) to Rational(13, 7), + mapOf(y to 1u) to Rational(16, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(6, 1), + mapOf(y to 2u) to Rational(-14, 3), + mapOf(x to 1u, y to 2u) to Rational(-2, 7), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + )), + "test 5'" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf>()), + "test 6" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 2), + mapOf(x to 1u) to Rational(8, 6), + mapOf(x to 2u) to Rational(14, 6), + mapOf(y to 1u) to Rational(-3, 1), + mapOf(x to 1u, y to 1u) to Rational(-19, 2), + mapOf(x to 2u, y to 1u) to Rational(9, 4), + mapOf(y to 2u) to Rational(5, 5), + mapOf(x to 1u, y to 2u) to Rational(18, 9), + mapOf(x to 2u, y to 2u) to Rational(5, 2), + ).substitute(RationalField, mapOf( + iota to LabeledPolynomialAsIs( + mapOf() to Rational(-11, 3), + mapOf(x to 1u) to Rational(5, 2), + mapOf(x to 2u) to Rational(13, 7), + mapOf(y to 1u) to Rational(16, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(6, 1), + mapOf(y to 2u) to Rational(-14, 3), + mapOf(x to 1u, y to 2u) to Rational(-2, 7), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + )), + "test 6'" + ) + } + @Test + @Ignore // FIXME: This tests work only for sane realisations of the substitutions. Currently, it is not. + // Sane algorithm for substitution p(q/r) (p, q, and r are polynomials) should return denominator r^deg(p), + // not r^(deg(p)(deg(p)+1)/2) as it is now. + fun test_Polynomial_substitute_RationalFunction_Map() { + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(0) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1) + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + ) + )), + "test 1" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf(x to 4u) to Rational(-194071, 4900), + mapOf(x to 3u, y to 1u) to Rational(394811, 225), + mapOf(x to 2u, y to 2u) to Rational(-444183161, 66150), + mapOf(x to 1u, y to 3u) to Rational(70537618, 59535), + mapOf(y to 4u) to Rational(9655504, 2835), + ), + LabeledPolynomialAsIs( + mapOf(x to 4u) to Rational(9, 1), + mapOf(x to 3u, y to 1u) to Rational(61, 1), + mapOf(x to 2u, y to 2u) to Rational(2137, 36), + mapOf(x to 1u, y to 3u) to Rational(-1342, 9), + mapOf(y to 4u) to Rational(484, 9), + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(17, 7), + mapOf(y to 1u) to Rational(-13, 1), + ), + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(-18, 6), + mapOf(y to 1u) to Rational(11, 6), + ) + ), + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(18, 5), + mapOf(y to 1u) to Rational(-16, 3), + ), + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(-1, 1), + mapOf(y to 1u) to Rational(-4, 1), + ) + ), + )), + "test 2" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-6443599, 10000), + mapOf(x to 1u) to Rational(166251223, 210000), + mapOf(x to 2u) to Rational(-4606805099, 3528000), + mapOf(x to 3u) to Rational(51204379, 19600), + mapOf(x to 4u) to Rational(-529045460659, 277830000), + mapOf(x to 5u) to Rational(2630836709, 1488375), + mapOf(x to 6u) to Rational(-42675691369, 25004700), + mapOf(x to 7u) to Rational(495825223, 1250235), + mapOf(x to 8u) to Rational(-22531756, 1750329), + mapOf(y to 1u) to Rational(-2526552797, 420000), + mapOf(x to 1u, y to 1u) to Rational(31108840471, 2520000), + mapOf(x to 2u, y to 1u) to Rational(-4789740847, 1102500), + mapOf(x to 3u, y to 1u) to Rational(186594307807, 11340000), + mapOf(x to 4u, y to 1u) to Rational(-11677815943, 1488375), + mapOf(x to 5u, y to 1u) to Rational(-181118486447, 27783000), + mapOf(x to 6u, y to 1u) to Rational(-16123292162, 14586075), + mapOf(x to 7u, y to 1u) to Rational(-140339343808, 26254935), + mapOf(x to 8u, y to 1u) to Rational(4570171616, 5250987), + mapOf(y to 2u) to Rational(-181436530573, 10080000), + mapOf(x to 1u, y to 2u) to Rational(6700437957491, 105840000), + mapOf(x to 2u, y to 2u) to Rational(-3527267461, 1417500), + mapOf(x to 3u, y to 2u) to Rational(-38084563451, 5556600), + mapOf(x to 4u, y to 2u) to Rational(-565662040631, 13891500), + mapOf(x to 5u, y to 2u) to Rational(-35479071126397, 583443000), + mapOf(x to 6u, y to 2u) to Rational(-11717559078469, 525098700), + mapOf(x to 7u, y to 2u) to Rational(-2043385293517, 225042300), + mapOf(x to 8u, y to 2u) to Rational(-3644439630451, 551353635), + mapOf(y to 3u) to Rational(-1760423269, 126000), + mapOf(x to 1u, y to 3u) to Rational(310176758299, 2352000), + mapOf(x to 2u, y to 3u) to Rational(-907229584837, 21168000), + mapOf(x to 3u, y to 3u) to Rational(-16717135885963, 95256000), + mapOf(x to 4u, y to 3u) to Rational(-43762928025353, 333396000), + mapOf(x to 5u, y to 3u) to Rational(-328427480571607, 3000564000), + mapOf(x to 6u, y to 3u) to Rational(-7722675917197, 210039480), + mapOf(x to 7u, y to 3u) to Rational(1713350137019, 1225230300), + mapOf(x to 8u, y to 3u) to Rational(156695935643, 31505922), + mapOf(y to 4u) to Rational(18362364269, 1008000), + mapOf(x to 1u, y to 4u) to Rational(955674858553, 10584000), + mapOf(x to 2u, y to 4u) to Rational(-71937470607371, 444528000), + mapOf(x to 3u, y to 4u) to Rational(-34097985615163, 95256000), + mapOf(x to 4u, y to 4u) to Rational(-340736178775883, 2000376000), + mapOf(x to 5u, y to 4u) to Rational(-511324523441897, 10501974000), + mapOf(x to 6u, y to 4u) to Rational(-125375649409151, 8821658160), + mapOf(x to 7u, y to 4u) to Rational(-2813518533421, 1575296100), + mapOf(x to 8u, y to 4u) to Rational(-17044089109, 5250987), + mapOf(y to 5u) to Rational(600086461, 20160), + mapOf(x to 1u, y to 5u) to Rational(-18959931367, 423360), + mapOf(x to 2u, y to 5u) to Rational(-9178804929607, 44452800), + mapOf(x to 3u, y to 5u) to Rational(-1460114275979, 5334336), + mapOf(x to 4u, y to 5u) to Rational(-342533479090169, 4200789600), + mapOf(x to 5u, y to 5u) to Rational(20335453022963, 4200789600), + mapOf(x to 6u, y to 5u) to Rational(-21649775090197, 6301184400), + mapOf(x to 7u, y to 5u) to Rational(-197301716069, 131274675), + mapOf(x to 8u, y to 5u) to Rational(18711357470, 15752961), + mapOf(y to 6u) to Rational(621417991, 100800), + mapOf(x to 1u, y to 6u) to Rational(-159236792977, 2116800), + mapOf(x to 2u, y to 6u) to Rational(-6602528890883, 66679200), + mapOf(x to 3u, y to 6u) to Rational(-1086091664047, 19051200), + mapOf(x to 4u, y to 6u) to Rational(3769375009003, 1680315840), + mapOf(x to 5u, y to 6u) to Rational(-12920385574769, 1050197400), + mapOf(x to 6u, y to 6u) to Rational(-90219591809287, 6301184400), + mapOf(x to 7u, y to 6u) to Rational(656361553391, 1575296100), + mapOf(x to 8u, y to 6u) to Rational(757900793, 2250423), + mapOf(y to 7u) to Rational(-100770017, 15120), + mapOf(x to 1u, y to 7u) to Rational(-316364851, 17640), + mapOf(x to 2u, y to 7u) to Rational(-85118560057, 6667920), + mapOf(x to 3u, y to 7u) to Rational(6286563719, 416745), + mapOf(x to 4u, y to 7u) to Rational(26803885301, 1714608), + mapOf(x to 5u, y to 7u) to Rational(-13767154393, 4286520), + mapOf(x to 6u, y to 7u) to Rational(-3875138933, 1224720), + mapOf(x to 7u, y to 7u) to Rational(65193755, 333396), + mapOf(x to 8u, y to 7u) to Rational(90974351, 2500470), + mapOf(y to 8u) to Rational(-3182197, 1260), + mapOf(x to 1u, y to 8u) to Rational(24899923, 8820), + mapOf(x to 2u, y to 8u) to Rational(-19999556, 19845), + mapOf(x to 3u, y to 8u) to Rational(3276587, 3969), + mapOf(x to 4u, y to 8u) to Rational(13719549239, 5000940), + mapOf(x to 5u, y to 8u) to Rational(-961839938, 1250235), + mapOf(x to 6u, y to 8u) to Rational(-198184871, 833490), + mapOf(x to 7u, y to 8u) to Rational(230659711, 5000940), + mapOf(x to 8u, y to 8u) to Rational(292447, 35721) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(9, 100), + mapOf(x to 1u) to Rational(-21, 50), + mapOf(x to 2u) to Rational(293, 700), + mapOf(x to 3u) to Rational(29, 210), + mapOf(x to 4u) to Rational(3233, 8820), + mapOf(x to 5u) to Rational(-289, 441), + mapOf(x to 6u) to Rational(-1, 9), + mapOf(x to 7u) to Rational(-20, 441), + mapOf(x to 8u) to Rational(100, 441), + mapOf(y to 1u) to Rational(-57, 80), + mapOf(x to 1u, y to 1u) to Rational(-121, 400), + mapOf(x to 2u, y to 1u) to Rational(37117, 8400), + mapOf(x to 3u, y to 1u) to Rational(-4853, 3150), + mapOf(x to 4u, y to 1u) to Rational(1166203, 132300), + mapOf(x to 5u, y to 1u) to Rational(-2708, 567), + mapOf(x to 6u, y to 1u) to Rational(-287159, 416745), + mapOf(x to 7u, y to 1u) to Rational(-478204, 83349), + mapOf(x to 8u, y to 1u) to Rational(176320, 83349), + mapOf(y to 2u) to Rational(-6239, 6400), + mapOf(x to 1u, y to 2u) to Rational(264211, 11200), + mapOf(x to 2u, y to 2u) to Rational(-1591999, 100800), + mapOf(x to 3u, y to 2u) to Rational(12450091, 529200), + mapOf(x to 4u, y to 2u) to Rational(9230759, 226800), + mapOf(x to 5u, y to 2u) to Rational(18995554, 2083725), + mapOf(x to 6u, y to 2u) to Rational(136706258, 6251175), + mapOf(x to 7u, y to 2u) to Rational(-120907496, 3750705), + mapOf(x to 8u, y to 2u) to Rational(117200176, 15752961), + mapOf(y to 3u) to Rational(5653, 320), + mapOf(x to 1u, y to 3u) to Rational(-130853, 8400), + mapOf(x to 2u, y to 3u) to Rational(-20939327, 151200), + mapOf(x to 3u, y to 3u) to Rational(2566691, 25200), + mapOf(x to 4u, y to 3u) to Rational(-68441519, 476280), + mapOf(x to 5u, y to 3u) to Rational(2462904247, 12502350), + mapOf(x to 6u, y to 3u) to Rational(353667161, 18753525), + mapOf(x to 7u, y to 3u) to Rational(-1689134372, 26254935), + mapOf(x to 8u, y to 3u) to Rational(35084104, 2250423), + mapOf(y to 4u) to Rational(-3587, 300), + mapOf(x to 1u, y to 4u) to Rational(-10513243, 33600), + mapOf(x to 2u, y to 4u) to Rational(30766733, 176400), + mapOf(x to 3u, y to 4u) to Rational(-65680021, 198450), + mapOf(x to 4u, y to 4u) to Rational(-8108910547, 20003760), + mapOf(x to 5u, y to 4u) to Rational(2922125159, 6251175), + mapOf(x to 6u, y to 4u) to Rational(-4245279943, 131274675), + mapOf(x to 7u, y to 4u) to Rational(-371946872, 3750705), + mapOf(x to 8u, y to 4u) to Rational(61286752, 2250423), + mapOf(y to 5u) to Rational(-20477, 160), + mapOf(x to 1u, y to 5u) to Rational(215741, 1120), + mapOf(x to 2u, y to 5u) to Rational(30785843, 31752), + mapOf(x to 3u, y to 5u) to Rational(-357495959, 317520), + mapOf(x to 4u, y to 5u) to Rational(-1611242993, 10001880), + mapOf(x to 5u, y to 5u) to Rational(345925495, 500094), + mapOf(x to 6u, y to 5u) to Rational(-755948411, 3750705), + mapOf(x to 7u, y to 5u) to Rational(-108643496, 1250235), + mapOf(x to 8u, y to 5u) to Rational(1122512, 35721), + mapOf(y to 6u) to Rational(358037, 2880), + mapOf(x to 1u, y to 6u) to Rational(3895837, 3360), + mapOf(x to 2u, y to 6u) to Rational(359419201, 1270080), + mapOf(x to 3u, y to 6u) to Rational(-158522587, 105840), + mapOf(x to 4u, y to 6u) to Rational(10909002599, 20003760), + mapOf(x to 5u, y to 6u) to Rational(76846972, 138915), + mapOf(x to 6u, y to 6u) to Rational(-327696553, 1250235), + mapOf(x to 7u, y to 6u) to Rational(-1687328, 35721), + mapOf(x to 8u, y to 6u) to Rational(1016836, 35721), + mapOf(y to 7u) to Rational(658, 3), + mapOf(x to 1u, y to 7u) to Rational(48035, 168), + mapOf(x to 2u, y to 7u) to Rational(-5777875, 5292), + mapOf(x to 3u, y to 7u) to Rational(-7893899, 10584), + mapOf(x to 4u, y to 7u) to Rational(10191652, 11907), + mapOf(x to 5u, y to 7u) to Rational(2920121, 23814), + mapOf(x to 6u, y to 7u) to Rational(-2699780, 11907), + mapOf(x to 7u, y to 7u) to Rational(4556, 441), + mapOf(x to 8u, y to 7u) to Rational(3440, 189), + mapOf(y to 8u) to Rational(64, 1), + mapOf(x to 1u, y to 8u) to Rational(-808, 7), + mapOf(x to 2u, y to 8u) to Rational(-360895, 1764), + mapOf(x to 3u, y to 8u) to Rational(257657, 882), + mapOf(x to 4u, y to 8u) to Rational(3779917, 15876), + mapOf(x to 5u, y to 8u) to Rational(-610279, 3969), + mapOf(x to 6u, y to 8u) to Rational(-25091, 441), + mapOf(x to 7u, y to 8u) to Rational(9560, 567), + mapOf(x to 8u, y to 8u) to Rational(400, 81) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(17, 5), + mapOf(x to 1u) to Rational(11, 6), + mapOf(x to 2u) to Rational(14, 3), + mapOf(y to 1u) to Rational(17, 1), + mapOf(x to 1u, y to 1u) to Rational(12, 3), + mapOf(x to 2u, y to 1u) to Rational(-6, 2), + mapOf(y to 2u) to Rational(17, 1), + mapOf(x to 1u, y to 2u) to Rational(-4, 3), + mapOf(x to 2u, y to 2u) to Rational(2, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(3, 5), + mapOf(x to 1u) to Rational(3, 5), + mapOf(x to 2u) to Rational(3, 7), + mapOf(y to 1u) to Rational(-3, 8), + mapOf(x to 1u, y to 1u) to Rational(-1, 1), + mapOf(x to 2u, y to 1u) to Rational(17, 9), + mapOf(y to 2u) to Rational(-8, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 4), + mapOf(x to 2u, y to 2u) to Rational(10, 9), + ) + ), + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(18, 5), + mapOf(x to 1u) to Rational(-17, 5), + mapOf(x to 2u) to Rational(-2, 7), + mapOf(y to 1u) to Rational(6, 5), + mapOf(x to 1u, y to 1u) to Rational(-5, 1), + mapOf(x to 2u, y to 1u) to Rational(-9, 1), + mapOf(y to 2u) to Rational(-8, 8), + mapOf(x to 1u, y to 2u) to Rational(2, 7), + mapOf(x to 2u, y to 2u) to Rational(-13, 7), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-4, 8), + mapOf(x to 1u) to Rational(15, 9), + mapOf(x to 2u) to Rational(-10, 9), + mapOf(y to 1u) to Rational(5, 3), + mapOf(x to 1u, y to 1u) to Rational(4, 1), + mapOf(x to 2u, y to 1u) to Rational(-2, 7), + mapOf(y to 2u) to Rational(2, 2), + mapOf(x to 1u, y to 2u) to Rational(-5, 7), + mapOf(x to 2u, y to 2u) to Rational(-18, 9), + ) + ), + )), + "test 3" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-6443599, 10000), + mapOf(x to 1u) to Rational(166251223, 210000), + mapOf(x to 2u) to Rational(-4606805099, 3528000), + mapOf(x to 3u) to Rational(51204379, 19600), + mapOf(x to 4u) to Rational(-529045460659, 277830000), + mapOf(x to 5u) to Rational(2630836709, 1488375), + mapOf(x to 6u) to Rational(-42675691369, 25004700), + mapOf(x to 7u) to Rational(495825223, 1250235), + mapOf(x to 8u) to Rational(-22531756, 1750329), + mapOf(y to 1u) to Rational(-2526552797, 420000), + mapOf(x to 1u, y to 1u) to Rational(31108840471, 2520000), + mapOf(x to 2u, y to 1u) to Rational(-4789740847, 1102500), + mapOf(x to 3u, y to 1u) to Rational(186594307807, 11340000), + mapOf(x to 4u, y to 1u) to Rational(-11677815943, 1488375), + mapOf(x to 5u, y to 1u) to Rational(-181118486447, 27783000), + mapOf(x to 6u, y to 1u) to Rational(-16123292162, 14586075), + mapOf(x to 7u, y to 1u) to Rational(-140339343808, 26254935), + mapOf(x to 8u, y to 1u) to Rational(4570171616, 5250987), + mapOf(y to 2u) to Rational(-181436530573, 10080000), + mapOf(x to 1u, y to 2u) to Rational(6700437957491, 105840000), + mapOf(x to 2u, y to 2u) to Rational(-3527267461, 1417500), + mapOf(x to 3u, y to 2u) to Rational(-38084563451, 5556600), + mapOf(x to 4u, y to 2u) to Rational(-565662040631, 13891500), + mapOf(x to 5u, y to 2u) to Rational(-35479071126397, 583443000), + mapOf(x to 6u, y to 2u) to Rational(-11717559078469, 525098700), + mapOf(x to 7u, y to 2u) to Rational(-2043385293517, 225042300), + mapOf(x to 8u, y to 2u) to Rational(-3644439630451, 551353635), + mapOf(y to 3u) to Rational(-1760423269, 126000), + mapOf(x to 1u, y to 3u) to Rational(310176758299, 2352000), + mapOf(x to 2u, y to 3u) to Rational(-907229584837, 21168000), + mapOf(x to 3u, y to 3u) to Rational(-16717135885963, 95256000), + mapOf(x to 4u, y to 3u) to Rational(-43762928025353, 333396000), + mapOf(x to 5u, y to 3u) to Rational(-328427480571607, 3000564000), + mapOf(x to 6u, y to 3u) to Rational(-7722675917197, 210039480), + mapOf(x to 7u, y to 3u) to Rational(1713350137019, 1225230300), + mapOf(x to 8u, y to 3u) to Rational(156695935643, 31505922), + mapOf(y to 4u) to Rational(18362364269, 1008000), + mapOf(x to 1u, y to 4u) to Rational(955674858553, 10584000), + mapOf(x to 2u, y to 4u) to Rational(-71937470607371, 444528000), + mapOf(x to 3u, y to 4u) to Rational(-34097985615163, 95256000), + mapOf(x to 4u, y to 4u) to Rational(-340736178775883, 2000376000), + mapOf(x to 5u, y to 4u) to Rational(-511324523441897, 10501974000), + mapOf(x to 6u, y to 4u) to Rational(-125375649409151, 8821658160), + mapOf(x to 7u, y to 4u) to Rational(-2813518533421, 1575296100), + mapOf(x to 8u, y to 4u) to Rational(-17044089109, 5250987), + mapOf(y to 5u) to Rational(600086461, 20160), + mapOf(x to 1u, y to 5u) to Rational(-18959931367, 423360), + mapOf(x to 2u, y to 5u) to Rational(-9178804929607, 44452800), + mapOf(x to 3u, y to 5u) to Rational(-1460114275979, 5334336), + mapOf(x to 4u, y to 5u) to Rational(-342533479090169, 4200789600), + mapOf(x to 5u, y to 5u) to Rational(20335453022963, 4200789600), + mapOf(x to 6u, y to 5u) to Rational(-21649775090197, 6301184400), + mapOf(x to 7u, y to 5u) to Rational(-197301716069, 131274675), + mapOf(x to 8u, y to 5u) to Rational(18711357470, 15752961), + mapOf(y to 6u) to Rational(621417991, 100800), + mapOf(x to 1u, y to 6u) to Rational(-159236792977, 2116800), + mapOf(x to 2u, y to 6u) to Rational(-6602528890883, 66679200), + mapOf(x to 3u, y to 6u) to Rational(-1086091664047, 19051200), + mapOf(x to 4u, y to 6u) to Rational(3769375009003, 1680315840), + mapOf(x to 5u, y to 6u) to Rational(-12920385574769, 1050197400), + mapOf(x to 6u, y to 6u) to Rational(-90219591809287, 6301184400), + mapOf(x to 7u, y to 6u) to Rational(656361553391, 1575296100), + mapOf(x to 8u, y to 6u) to Rational(757900793, 2250423), + mapOf(y to 7u) to Rational(-100770017, 15120), + mapOf(x to 1u, y to 7u) to Rational(-316364851, 17640), + mapOf(x to 2u, y to 7u) to Rational(-85118560057, 6667920), + mapOf(x to 3u, y to 7u) to Rational(6286563719, 416745), + mapOf(x to 4u, y to 7u) to Rational(26803885301, 1714608), + mapOf(x to 5u, y to 7u) to Rational(-13767154393, 4286520), + mapOf(x to 6u, y to 7u) to Rational(-3875138933, 1224720), + mapOf(x to 7u, y to 7u) to Rational(65193755, 333396), + mapOf(x to 8u, y to 7u) to Rational(90974351, 2500470), + mapOf(y to 8u) to Rational(-3182197, 1260), + mapOf(x to 1u, y to 8u) to Rational(24899923, 8820), + mapOf(x to 2u, y to 8u) to Rational(-19999556, 19845), + mapOf(x to 3u, y to 8u) to Rational(3276587, 3969), + mapOf(x to 4u, y to 8u) to Rational(13719549239, 5000940), + mapOf(x to 5u, y to 8u) to Rational(-961839938, 1250235), + mapOf(x to 6u, y to 8u) to Rational(-198184871, 833490), + mapOf(x to 7u, y to 8u) to Rational(230659711, 5000940), + mapOf(x to 8u, y to 8u) to Rational(292447, 35721) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(9, 100), + mapOf(x to 1u) to Rational(-21, 50), + mapOf(x to 2u) to Rational(293, 700), + mapOf(x to 3u) to Rational(29, 210), + mapOf(x to 4u) to Rational(3233, 8820), + mapOf(x to 5u) to Rational(-289, 441), + mapOf(x to 6u) to Rational(-1, 9), + mapOf(x to 7u) to Rational(-20, 441), + mapOf(x to 8u) to Rational(100, 441), + mapOf(y to 1u) to Rational(-57, 80), + mapOf(x to 1u, y to 1u) to Rational(-121, 400), + mapOf(x to 2u, y to 1u) to Rational(37117, 8400), + mapOf(x to 3u, y to 1u) to Rational(-4853, 3150), + mapOf(x to 4u, y to 1u) to Rational(1166203, 132300), + mapOf(x to 5u, y to 1u) to Rational(-2708, 567), + mapOf(x to 6u, y to 1u) to Rational(-287159, 416745), + mapOf(x to 7u, y to 1u) to Rational(-478204, 83349), + mapOf(x to 8u, y to 1u) to Rational(176320, 83349), + mapOf(y to 2u) to Rational(-6239, 6400), + mapOf(x to 1u, y to 2u) to Rational(264211, 11200), + mapOf(x to 2u, y to 2u) to Rational(-1591999, 100800), + mapOf(x to 3u, y to 2u) to Rational(12450091, 529200), + mapOf(x to 4u, y to 2u) to Rational(9230759, 226800), + mapOf(x to 5u, y to 2u) to Rational(18995554, 2083725), + mapOf(x to 6u, y to 2u) to Rational(136706258, 6251175), + mapOf(x to 7u, y to 2u) to Rational(-120907496, 3750705), + mapOf(x to 8u, y to 2u) to Rational(117200176, 15752961), + mapOf(y to 3u) to Rational(5653, 320), + mapOf(x to 1u, y to 3u) to Rational(-130853, 8400), + mapOf(x to 2u, y to 3u) to Rational(-20939327, 151200), + mapOf(x to 3u, y to 3u) to Rational(2566691, 25200), + mapOf(x to 4u, y to 3u) to Rational(-68441519, 476280), + mapOf(x to 5u, y to 3u) to Rational(2462904247, 12502350), + mapOf(x to 6u, y to 3u) to Rational(353667161, 18753525), + mapOf(x to 7u, y to 3u) to Rational(-1689134372, 26254935), + mapOf(x to 8u, y to 3u) to Rational(35084104, 2250423), + mapOf(y to 4u) to Rational(-3587, 300), + mapOf(x to 1u, y to 4u) to Rational(-10513243, 33600), + mapOf(x to 2u, y to 4u) to Rational(30766733, 176400), + mapOf(x to 3u, y to 4u) to Rational(-65680021, 198450), + mapOf(x to 4u, y to 4u) to Rational(-8108910547, 20003760), + mapOf(x to 5u, y to 4u) to Rational(2922125159, 6251175), + mapOf(x to 6u, y to 4u) to Rational(-4245279943, 131274675), + mapOf(x to 7u, y to 4u) to Rational(-371946872, 3750705), + mapOf(x to 8u, y to 4u) to Rational(61286752, 2250423), + mapOf(y to 5u) to Rational(-20477, 160), + mapOf(x to 1u, y to 5u) to Rational(215741, 1120), + mapOf(x to 2u, y to 5u) to Rational(30785843, 31752), + mapOf(x to 3u, y to 5u) to Rational(-357495959, 317520), + mapOf(x to 4u, y to 5u) to Rational(-1611242993, 10001880), + mapOf(x to 5u, y to 5u) to Rational(345925495, 500094), + mapOf(x to 6u, y to 5u) to Rational(-755948411, 3750705), + mapOf(x to 7u, y to 5u) to Rational(-108643496, 1250235), + mapOf(x to 8u, y to 5u) to Rational(1122512, 35721), + mapOf(y to 6u) to Rational(358037, 2880), + mapOf(x to 1u, y to 6u) to Rational(3895837, 3360), + mapOf(x to 2u, y to 6u) to Rational(359419201, 1270080), + mapOf(x to 3u, y to 6u) to Rational(-158522587, 105840), + mapOf(x to 4u, y to 6u) to Rational(10909002599, 20003760), + mapOf(x to 5u, y to 6u) to Rational(76846972, 138915), + mapOf(x to 6u, y to 6u) to Rational(-327696553, 1250235), + mapOf(x to 7u, y to 6u) to Rational(-1687328, 35721), + mapOf(x to 8u, y to 6u) to Rational(1016836, 35721), + mapOf(y to 7u) to Rational(658, 3), + mapOf(x to 1u, y to 7u) to Rational(48035, 168), + mapOf(x to 2u, y to 7u) to Rational(-5777875, 5292), + mapOf(x to 3u, y to 7u) to Rational(-7893899, 10584), + mapOf(x to 4u, y to 7u) to Rational(10191652, 11907), + mapOf(x to 5u, y to 7u) to Rational(2920121, 23814), + mapOf(x to 6u, y to 7u) to Rational(-2699780, 11907), + mapOf(x to 7u, y to 7u) to Rational(4556, 441), + mapOf(x to 8u, y to 7u) to Rational(3440, 189), + mapOf(y to 8u) to Rational(64, 1), + mapOf(x to 1u, y to 8u) to Rational(-808, 7), + mapOf(x to 2u, y to 8u) to Rational(-360895, 1764), + mapOf(x to 3u, y to 8u) to Rational(257657, 882), + mapOf(x to 4u, y to 8u) to Rational(3779917, 15876), + mapOf(x to 5u, y to 8u) to Rational(-610279, 3969), + mapOf(x to 6u, y to 8u) to Rational(-25091, 441), + mapOf(x to 7u, y to 8u) to Rational(9560, 567), + mapOf(x to 8u, y to 8u) to Rational(400, 81) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(17, 5), + mapOf(x to 1u) to Rational(11, 6), + mapOf(x to 2u) to Rational(14, 3), + mapOf(y to 1u) to Rational(17, 1), + mapOf(x to 1u, y to 1u) to Rational(12, 3), + mapOf(x to 2u, y to 1u) to Rational(-6, 2), + mapOf(y to 2u) to Rational(17, 1), + mapOf(x to 1u, y to 2u) to Rational(-4, 3), + mapOf(x to 2u, y to 2u) to Rational(2, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(3, 5), + mapOf(x to 1u) to Rational(3, 5), + mapOf(x to 2u) to Rational(3, 7), + mapOf(y to 1u) to Rational(-3, 8), + mapOf(x to 1u, y to 1u) to Rational(-1, 1), + mapOf(x to 2u, y to 1u) to Rational(17, 9), + mapOf(y to 2u) to Rational(-8, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 4), + mapOf(x to 2u, y to 2u) to Rational(10, 9), + ) + ), + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(18, 5), + mapOf(x to 1u) to Rational(-17, 5), + mapOf(x to 2u) to Rational(-2, 7), + mapOf(y to 1u) to Rational(6, 5), + mapOf(x to 1u, y to 1u) to Rational(-5, 1), + mapOf(x to 2u, y to 1u) to Rational(-9, 1), + mapOf(y to 2u) to Rational(-8, 8), + mapOf(x to 1u, y to 2u) to Rational(2, 7), + mapOf(x to 2u, y to 2u) to Rational(-13, 7), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-4, 8), + mapOf(x to 1u) to Rational(15, 9), + mapOf(x to 2u) to Rational(-10, 9), + mapOf(y to 1u) to Rational(5, 3), + mapOf(x to 1u, y to 1u) to Rational(4, 1), + mapOf(x to 2u, y to 1u) to Rational(-2, 7), + mapOf(y to 2u) to Rational(2, 2), + mapOf(x to 1u, y to 2u) to Rational(-5, 7), + mapOf(x to 2u, y to 2u) to Rational(-18, 9), + ) + ), + iota to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-2, 9), + mapOf(x to 1u) to Rational(-6, 3), + mapOf(x to 2u) to Rational(10, 9), + mapOf(y to 1u) to Rational(13, 3), + mapOf(x to 1u, y to 1u) to Rational(-12, 4), + mapOf(x to 2u, y to 1u) to Rational(3, 6), + mapOf(y to 2u) to Rational(2, 9), + mapOf(x to 1u, y to 2u) to Rational(7, 3), + mapOf(x to 2u, y to 2u) to Rational(16, 5), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 2), + mapOf(x to 1u) to Rational(6, 2), + mapOf(x to 2u) to Rational(2, 7), + mapOf(y to 1u) to Rational(-18, 1), + mapOf(x to 1u, y to 1u) to Rational(-11, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 5), + mapOf(y to 2u) to Rational(8, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(17, 4), + ) + ) + )), + "test 3'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-66677, 3500), + mapOf(x to 1u) to Rational(-206281, 10500), + mapOf(x to 2u) to Rational(-412567, 7056), + mapOf(x to 3u) to Rational(-310081, 11025), + mapOf(x to 4u) to Rational(-575996, 15435), + mapOf(y to 1u) to Rational(-573701, 4200), + mapOf(x to 1u, y to 1u) to Rational(-2239001, 25200), + mapOf(x to 2u, y to 1u) to Rational(-8817889, 132300), + mapOf(x to 3u, y to 1u) to Rational(2317919, 44100), + mapOf(x to 4u, y to 1u) to Rational(1169471, 6615), + mapOf(y to 2u) to Rational(-4057819, 33600), + mapOf(x to 1u, y to 2u) to Rational(1373311, 12600), + mapOf(x to 2u, y to 2u) to Rational(32433493, 52920), + mapOf(x to 3u, y to 2u) to Rational(4998053, 33075), + mapOf(x to 4u, y to 2u) to Rational(-2147779, 8820), + mapOf(y to 3u) to Rational(2018481, 2240), + mapOf(x to 1u, y to 3u) to Rational(941713, 1440), + mapOf(x to 2u, y to 3u) to Rational(183749, 6615), + mapOf(x to 3u, y to 3u) to Rational(-4631023, 15876), + mapOf(x to 4u, y to 3u) to Rational(25609336, 178605), + mapOf(y to 4u) to Rational(11886431, 6720), + mapOf(x to 1u, y to 4u) to Rational(18433, 504), + mapOf(x to 2u, y to 4u) to Rational(-39613331, 45360), + mapOf(x to 3u, y to 4u) to Rational(681619, 5670), + mapOf(x to 4u, y to 4u) to Rational(-864841, 20412), + mapOf(y to 5u) to Rational(343535, 1008), + mapOf(x to 1u, y to 5u) to Rational(-33583, 72), + mapOf(x to 2u, y to 5u) to Rational(1194625, 9072), + mapOf(x to 3u, y to 5u) to Rational(-62917, 2268), + mapOf(x to 4u, y to 5u) to Rational(157645, 10206), + mapOf(y to 6u) to Rational(-1381, 3), + mapOf(x to 1u, y to 6u) to Rational(919, 36), + mapOf(x to 2u, y to 6u) to Rational(-3053, 36), + mapOf(x to 3u, y to 6u) to Rational(2125, 324), + mapOf(x to 4u, y to 6u) to Rational(-236, 243) + ), + LabeledPolynomialAsIs(mapOf() to Rational(0, 1), + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-5, 3), + mapOf(x to 2u) to Rational(35, 9), + mapOf(x to 3u) to Rational(-100, 27), + mapOf(x to 4u) to Rational(100, 81), + mapOf(y to 1u) to Rational(-5, 3), + mapOf(x to 1u, y to 1u) to Rational(14, 9), + mapOf(x to 2u, y to 1u) to Rational(1874, 189), + mapOf(x to 3u, y to 1u) to Rational(-620, 63), + mapOf(x to 4u, y to 1u) to Rational(40, 63), + mapOf(y to 2u) to Rational(16, 9), + mapOf(x to 1u, y to 2u) to Rational(365, 21), + mapOf(x to 2u, y to 2u) to Rational(112, 9), + mapOf(x to 3u, y to 2u) to Rational(-464, 63), + mapOf(x to 4u, y to 2u) to Rational(1996, 441), + mapOf(y to 3u) to Rational(10, 3), + mapOf(x to 1u, y to 3u) to Rational(118, 21), + mapOf(x to 2u, y to 3u) to Rational(-272, 21), + mapOf(x to 3u, y to 3u) to Rational(-764, 49), + mapOf(x to 4u, y to 3u) to Rational(8, 7), + mapOf(y to 4u) to Rational(1, 1), + mapOf(x to 1u, y to 4u) to Rational(-10, 7), + mapOf(x to 2u, y to 4u) to Rational(-171, 49), + mapOf(x to 3u, y to 4u) to Rational(20, 7), + mapOf(x to 4u, y to 4u) to Rational(4, 1) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(17, 5), + mapOf(x to 1u) to Rational(11, 6), + mapOf(x to 2u) to Rational(14, 3), + mapOf(y to 1u) to Rational(17, 1), + mapOf(x to 1u, y to 1u) to Rational(12, 3), + mapOf(x to 2u, y to 1u) to Rational(-6, 2), + mapOf(y to 2u) to Rational(17, 1), + mapOf(x to 1u, y to 2u) to Rational(-4, 3), + mapOf(x to 2u, y to 2u) to Rational(2, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(3, 5), + mapOf(x to 1u) to Rational(3, 5), + mapOf(x to 2u) to Rational(3, 7), + mapOf(y to 1u) to Rational(-3, 8), + mapOf(x to 1u, y to 1u) to Rational(-1, 1), + mapOf(x to 2u, y to 1u) to Rational(17, 9), + mapOf(y to 2u) to Rational(-8, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 4), + mapOf(x to 2u, y to 2u) to Rational(10, 9), + ) + ), + )), + "test 4" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-66677, 3500), + mapOf(x to 1u) to Rational(-206281, 10500), + mapOf(x to 2u) to Rational(-412567, 7056), + mapOf(x to 3u) to Rational(-310081, 11025), + mapOf(x to 4u) to Rational(-575996, 15435), + mapOf(y to 1u) to Rational(-573701, 4200), + mapOf(x to 1u, y to 1u) to Rational(-2239001, 25200), + mapOf(x to 2u, y to 1u) to Rational(-8817889, 132300), + mapOf(x to 3u, y to 1u) to Rational(2317919, 44100), + mapOf(x to 4u, y to 1u) to Rational(1169471, 6615), + mapOf(y to 2u) to Rational(-4057819, 33600), + mapOf(x to 1u, y to 2u) to Rational(1373311, 12600), + mapOf(x to 2u, y to 2u) to Rational(32433493, 52920), + mapOf(x to 3u, y to 2u) to Rational(4998053, 33075), + mapOf(x to 4u, y to 2u) to Rational(-2147779, 8820), + mapOf(y to 3u) to Rational(2018481, 2240), + mapOf(x to 1u, y to 3u) to Rational(941713, 1440), + mapOf(x to 2u, y to 3u) to Rational(183749, 6615), + mapOf(x to 3u, y to 3u) to Rational(-4631023, 15876), + mapOf(x to 4u, y to 3u) to Rational(25609336, 178605), + mapOf(y to 4u) to Rational(11886431, 6720), + mapOf(x to 1u, y to 4u) to Rational(18433, 504), + mapOf(x to 2u, y to 4u) to Rational(-39613331, 45360), + mapOf(x to 3u, y to 4u) to Rational(681619, 5670), + mapOf(x to 4u, y to 4u) to Rational(-864841, 20412), + mapOf(y to 5u) to Rational(343535, 1008), + mapOf(x to 1u, y to 5u) to Rational(-33583, 72), + mapOf(x to 2u, y to 5u) to Rational(1194625, 9072), + mapOf(x to 3u, y to 5u) to Rational(-62917, 2268), + mapOf(x to 4u, y to 5u) to Rational(157645, 10206), + mapOf(y to 6u) to Rational(-1381, 3), + mapOf(x to 1u, y to 6u) to Rational(919, 36), + mapOf(x to 2u, y to 6u) to Rational(-3053, 36), + mapOf(x to 3u, y to 6u) to Rational(2125, 324), + mapOf(x to 4u, y to 6u) to Rational(-236, 243) + ), + LabeledPolynomialAsIs(mapOf() to Rational(0, 1), + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-5, 3), + mapOf(x to 2u) to Rational(35, 9), + mapOf(x to 3u) to Rational(-100, 27), + mapOf(x to 4u) to Rational(100, 81), + mapOf(y to 1u) to Rational(-5, 3), + mapOf(x to 1u, y to 1u) to Rational(14, 9), + mapOf(x to 2u, y to 1u) to Rational(1874, 189), + mapOf(x to 3u, y to 1u) to Rational(-620, 63), + mapOf(x to 4u, y to 1u) to Rational(40, 63), + mapOf(y to 2u) to Rational(16, 9), + mapOf(x to 1u, y to 2u) to Rational(365, 21), + mapOf(x to 2u, y to 2u) to Rational(112, 9), + mapOf(x to 3u, y to 2u) to Rational(-464, 63), + mapOf(x to 4u, y to 2u) to Rational(1996, 441), + mapOf(y to 3u) to Rational(10, 3), + mapOf(x to 1u, y to 3u) to Rational(118, 21), + mapOf(x to 2u, y to 3u) to Rational(-272, 21), + mapOf(x to 3u, y to 3u) to Rational(-764, 49), + mapOf(x to 4u, y to 3u) to Rational(8, 7), + mapOf(y to 4u) to Rational(1, 1), + mapOf(x to 1u, y to 4u) to Rational(-10, 7), + mapOf(x to 2u, y to 4u) to Rational(-171, 49), + mapOf(x to 3u, y to 4u) to Rational(20, 7), + mapOf(x to 4u, y to 4u) to Rational(4, 1) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(17, 5), + mapOf(x to 1u) to Rational(11, 6), + mapOf(x to 2u) to Rational(14, 3), + mapOf(y to 1u) to Rational(17, 1), + mapOf(x to 1u, y to 1u) to Rational(12, 3), + mapOf(x to 2u, y to 1u) to Rational(-6, 2), + mapOf(y to 2u) to Rational(17, 1), + mapOf(x to 1u, y to 2u) to Rational(-4, 3), + mapOf(x to 2u, y to 2u) to Rational(2, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(3, 5), + mapOf(x to 1u) to Rational(3, 5), + mapOf(x to 2u) to Rational(3, 7), + mapOf(y to 1u) to Rational(-3, 8), + mapOf(x to 1u, y to 1u) to Rational(-1, 1), + mapOf(x to 2u, y to 1u) to Rational(17, 9), + mapOf(y to 2u) to Rational(-8, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 4), + mapOf(x to 2u, y to 2u) to Rational(10, 9), + ) + ), + iota to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-2, 9), + mapOf(x to 1u) to Rational(-6, 3), + mapOf(x to 2u) to Rational(10, 9), + mapOf(y to 1u) to Rational(13, 3), + mapOf(x to 1u, y to 1u) to Rational(-12, 4), + mapOf(x to 2u, y to 1u) to Rational(3, 6), + mapOf(y to 2u) to Rational(2, 9), + mapOf(x to 1u, y to 2u) to Rational(7, 3), + mapOf(x to 2u, y to 2u) to Rational(16, 5), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 2), + mapOf(x to 1u) to Rational(6, 2), + mapOf(x to 2u) to Rational(2, 7), + mapOf(y to 1u) to Rational(-18, 1), + mapOf(x to 1u, y to 1u) to Rational(-11, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 5), + mapOf(y to 2u) to Rational(8, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(17, 4), + ) + ) + )), + "test 4'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(3539, 700), + mapOf(x to 1u) to Rational(-307079, 6300), + mapOf(x to 2u) to Rational(451609, 15120), + mapOf(x to 3u) to Rational(35287733, 396900), + mapOf(x to 4u) to Rational(-37242617, 396900), + mapOf(x to 5u) to Rational(382747, 19845), + mapOf(x to 6u) to Rational(-2407, 3969), + mapOf(y to 1u) to Rational(-226, 175), + mapOf(x to 1u, y to 1u) to Rational(-74113, 1890), + mapOf(x to 2u, y to 1u) to Rational(250931, 1764), + mapOf(x to 3u, y to 1u) to Rational(30071473, 99225), + mapOf(x to 4u, y to 1u) to Rational(-286466, 1323), + mapOf(x to 5u, y to 1u) to Rational(-2285282, 9261), + mapOf(x to 6u, y to 1u) to Rational(17900, 441), + mapOf(y to 2u) to Rational(3817, 3150), + mapOf(x to 1u, y to 2u) to Rational(577568, 11025), + mapOf(x to 2u, y to 2u) to Rational(9073553, 99225), + mapOf(x to 3u, y to 2u) to Rational(-1415849, 79380), + mapOf(x to 4u, y to 2u) to Rational(-124715629, 277830), + mapOf(x to 5u, y to 2u) to Rational(-1328953, 1890), + mapOf(x to 6u, y to 2u) to Rational(-297148, 1323), + mapOf(y to 3u) to Rational(6043, 945), + mapOf(x to 1u, y to 3u) to Rational(160381, 6615), + mapOf(x to 2u, y to 3u) to Rational(-673249, 13230), + mapOf(x to 3u, y to 3u) to Rational(-319255, 2058), + mapOf(x to 4u, y to 3u) to Rational(-98144, 1029), + mapOf(x to 5u, y to 3u) to Rational(-320239, 5145), + mapOf(x to 6u, y to 3u) to Rational(400, 147), + mapOf(y to 4u) to Rational(163, 63), + mapOf(x to 1u, y to 4u) to Rational(-25183, 4410), + mapOf(x to 2u, y to 4u) to Rational(-21369, 1372), + mapOf(x to 3u, y to 4u) to Rational(127499, 30870), + mapOf(x to 4u, y to 4u) to Rational(86971, 12348), + mapOf(x to 5u, y to 4u) to Rational(-11129, 1470), + mapOf(x to 6u, y to 4u) to Rational(544, 147) + ), + LabeledPolynomialAsIs(mapOf() to Rational(0, 1), + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-5, 3), + mapOf(x to 2u) to Rational(35, 9), + mapOf(x to 3u) to Rational(-100, 27), + mapOf(x to 4u) to Rational(100, 81), + mapOf(y to 1u) to Rational(-5, 3), + mapOf(x to 1u, y to 1u) to Rational(14, 9), + mapOf(x to 2u, y to 1u) to Rational(1874, 189), + mapOf(x to 3u, y to 1u) to Rational(-620, 63), + mapOf(x to 4u, y to 1u) to Rational(40, 63), + mapOf(y to 2u) to Rational(16, 9), + mapOf(x to 1u, y to 2u) to Rational(365, 21), + mapOf(x to 2u, y to 2u) to Rational(112, 9), + mapOf(x to 3u, y to 2u) to Rational(-464, 63), + mapOf(x to 4u, y to 2u) to Rational(1996, 441), + mapOf(y to 3u) to Rational(10, 3), + mapOf(x to 1u, y to 3u) to Rational(118, 21), + mapOf(x to 2u, y to 3u) to Rational(-272, 21), + mapOf(x to 3u, y to 3u) to Rational(-764, 49), + mapOf(x to 4u, y to 3u) to Rational(8, 7), + mapOf(y to 4u) to Rational(1, 1), + mapOf(x to 1u, y to 4u) to Rational(-10, 7), + mapOf(x to 2u, y to 4u) to Rational(-171, 49), + mapOf(x to 3u, y to 4u) to Rational(20, 7), + mapOf(x to 4u, y to 4u) to Rational(4, 1) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf( + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(18, 5), + mapOf(x to 1u) to Rational(-17, 5), + mapOf(x to 2u) to Rational(-2, 7), + mapOf(y to 1u) to Rational(6, 5), + mapOf(x to 1u, y to 1u) to Rational(-5, 1), + mapOf(x to 2u, y to 1u) to Rational(-9, 1), + mapOf(y to 2u) to Rational(-8, 8), + mapOf(x to 1u, y to 2u) to Rational(2, 7), + mapOf(x to 2u, y to 2u) to Rational(-13, 7), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-4, 8), + mapOf(x to 1u) to Rational(15, 9), + mapOf(x to 2u) to Rational(-10, 9), + mapOf(y to 1u) to Rational(5, 3), + mapOf(x to 1u, y to 1u) to Rational(4, 1), + mapOf(x to 2u, y to 1u) to Rational(-2, 7), + mapOf(y to 2u) to Rational(2, 2), + mapOf(x to 1u, y to 2u) to Rational(-5, 7), + mapOf(x to 2u, y to 2u) to Rational(-18, 9), + ) + ), + )), + "test 5" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(3539, 700), + mapOf(x to 1u) to Rational(-307079, 6300), + mapOf(x to 2u) to Rational(451609, 15120), + mapOf(x to 3u) to Rational(35287733, 396900), + mapOf(x to 4u) to Rational(-37242617, 396900), + mapOf(x to 5u) to Rational(382747, 19845), + mapOf(x to 6u) to Rational(-2407, 3969), + mapOf(y to 1u) to Rational(-226, 175), + mapOf(x to 1u, y to 1u) to Rational(-74113, 1890), + mapOf(x to 2u, y to 1u) to Rational(250931, 1764), + mapOf(x to 3u, y to 1u) to Rational(30071473, 99225), + mapOf(x to 4u, y to 1u) to Rational(-286466, 1323), + mapOf(x to 5u, y to 1u) to Rational(-2285282, 9261), + mapOf(x to 6u, y to 1u) to Rational(17900, 441), + mapOf(y to 2u) to Rational(3817, 3150), + mapOf(x to 1u, y to 2u) to Rational(577568, 11025), + mapOf(x to 2u, y to 2u) to Rational(9073553, 99225), + mapOf(x to 3u, y to 2u) to Rational(-1415849, 79380), + mapOf(x to 4u, y to 2u) to Rational(-124715629, 277830), + mapOf(x to 5u, y to 2u) to Rational(-1328953, 1890), + mapOf(x to 6u, y to 2u) to Rational(-297148, 1323), + mapOf(y to 3u) to Rational(6043, 945), + mapOf(x to 1u, y to 3u) to Rational(160381, 6615), + mapOf(x to 2u, y to 3u) to Rational(-673249, 13230), + mapOf(x to 3u, y to 3u) to Rational(-319255, 2058), + mapOf(x to 4u, y to 3u) to Rational(-98144, 1029), + mapOf(x to 5u, y to 3u) to Rational(-320239, 5145), + mapOf(x to 6u, y to 3u) to Rational(400, 147), + mapOf(y to 4u) to Rational(163, 63), + mapOf(x to 1u, y to 4u) to Rational(-25183, 4410), + mapOf(x to 2u, y to 4u) to Rational(-21369, 1372), + mapOf(x to 3u, y to 4u) to Rational(127499, 30870), + mapOf(x to 4u, y to 4u) to Rational(86971, 12348), + mapOf(x to 5u, y to 4u) to Rational(-11129, 1470), + mapOf(x to 6u, y to 4u) to Rational(544, 147) + ), + LabeledPolynomialAsIs(mapOf() to Rational(0, 1), + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-5, 3), + mapOf(x to 2u) to Rational(35, 9), + mapOf(x to 3u) to Rational(-100, 27), + mapOf(x to 4u) to Rational(100, 81), + mapOf(y to 1u) to Rational(-5, 3), + mapOf(x to 1u, y to 1u) to Rational(14, 9), + mapOf(x to 2u, y to 1u) to Rational(1874, 189), + mapOf(x to 3u, y to 1u) to Rational(-620, 63), + mapOf(x to 4u, y to 1u) to Rational(40, 63), + mapOf(y to 2u) to Rational(16, 9), + mapOf(x to 1u, y to 2u) to Rational(365, 21), + mapOf(x to 2u, y to 2u) to Rational(112, 9), + mapOf(x to 3u, y to 2u) to Rational(-464, 63), + mapOf(x to 4u, y to 2u) to Rational(1996, 441), + mapOf(y to 3u) to Rational(10, 3), + mapOf(x to 1u, y to 3u) to Rational(118, 21), + mapOf(x to 2u, y to 3u) to Rational(-272, 21), + mapOf(x to 3u, y to 3u) to Rational(-764, 49), + mapOf(x to 4u, y to 3u) to Rational(8, 7), + mapOf(y to 4u) to Rational(1, 1), + mapOf(x to 1u, y to 4u) to Rational(-10, 7), + mapOf(x to 2u, y to 4u) to Rational(-171, 49), + mapOf(x to 3u, y to 4u) to Rational(20, 7), + mapOf(x to 4u, y to 4u) to Rational(4, 1) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf( + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(18, 5), + mapOf(x to 1u) to Rational(-17, 5), + mapOf(x to 2u) to Rational(-2, 7), + mapOf(y to 1u) to Rational(6, 5), + mapOf(x to 1u, y to 1u) to Rational(-5, 1), + mapOf(x to 2u, y to 1u) to Rational(-9, 1), + mapOf(y to 2u) to Rational(-8, 8), + mapOf(x to 1u, y to 2u) to Rational(2, 7), + mapOf(x to 2u, y to 2u) to Rational(-13, 7), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-4, 8), + mapOf(x to 1u) to Rational(15, 9), + mapOf(x to 2u) to Rational(-10, 9), + mapOf(y to 1u) to Rational(5, 3), + mapOf(x to 1u, y to 1u) to Rational(4, 1), + mapOf(x to 2u, y to 1u) to Rational(-2, 7), + mapOf(y to 2u) to Rational(2, 2), + mapOf(x to 1u, y to 2u) to Rational(-5, 7), + mapOf(x to 2u, y to 2u) to Rational(-18, 9), + ) + ), + iota to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-2, 9), + mapOf(x to 1u) to Rational(-6, 3), + mapOf(x to 2u) to Rational(10, 9), + mapOf(y to 1u) to Rational(13, 3), + mapOf(x to 1u, y to 1u) to Rational(-12, 4), + mapOf(x to 2u, y to 1u) to Rational(3, 6), + mapOf(y to 2u) to Rational(2, 9), + mapOf(x to 1u, y to 2u) to Rational(7, 3), + mapOf(x to 2u, y to 2u) to Rational(16, 5), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 2), + mapOf(x to 1u) to Rational(6, 2), + mapOf(x to 2u) to Rational(2, 7), + mapOf(y to 1u) to Rational(-18, 1), + mapOf(x to 1u, y to 1u) to Rational(-11, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 5), + mapOf(y to 2u) to Rational(8, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(17, 4), + ) + ) + )), + "test 5'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ), + LabeledPolynomialAsIs(mapOf() to Rational(0, 1), + mapOf() to Rational(0, 1) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf>()), + "test 6" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ), + LabeledPolynomialAsIs(mapOf() to Rational(0, 1), + mapOf() to Rational(0, 1) + ) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(15, 7), + mapOf(x to 1u) to Rational(1, 5), + mapOf(x to 2u) to Rational(-7, 4), + mapOf(y to 1u) to Rational(-1, 9), + mapOf(x to 1u, y to 1u) to Rational(-2, 7), + mapOf(x to 2u, y to 1u) to Rational(17, 3), + mapOf(y to 2u) to Rational(2, 6), + mapOf(x to 1u, y to 2u) to Rational(-17, 6), + mapOf(x to 2u, y to 2u) to Rational(-6, 2), + ).substitute(RationalField, mapOf( + iota to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-2, 9), + mapOf(x to 1u) to Rational(-6, 3), + mapOf(x to 2u) to Rational(10, 9), + mapOf(y to 1u) to Rational(13, 3), + mapOf(x to 1u, y to 1u) to Rational(-12, 4), + mapOf(x to 2u, y to 1u) to Rational(3, 6), + mapOf(y to 2u) to Rational(2, 9), + mapOf(x to 1u, y to 2u) to Rational(7, 3), + mapOf(x to 2u, y to 2u) to Rational(16, 5), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 2), + mapOf(x to 1u) to Rational(6, 2), + mapOf(x to 2u) to Rational(2, 7), + mapOf(y to 1u) to Rational(-18, 1), + mapOf(x to 1u, y to 1u) to Rational(-11, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 5), + mapOf(y to 2u) to Rational(8, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(17, 4), + ) + ) + )), + "test 6'" + ) + } + @Test + fun test_RationalFunction_substitute_Double_Map() { + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs(emptyMap() to 0.0), + LabeledPolynomialAsIs(emptyMap() to 1.0), + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 1.0, + mapOf(x to 1u) to -2.0, + mapOf(x to 2u) to 1.0, + ), + LabeledPolynomialAsIs( + mapOf() to 1.0, + ) + ).substitute(mapOf( + x to 1.0 + )), + 0.001, + "test 1" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ).substitute(mapOf()), + 0.001, + "test 2" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ).substitute(mapOf( + iota to 0.9211194782050933 + )), + 0.001, + "test 2'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 151.1502229133916, + mapOf(y to 1u) to -262.3790170577034, + mapOf(y to 2u) to 102.5097937392923, + ), + LabeledPolynomialAsIs( + mapOf() to -367.9969733169944, + mapOf(y to 1u) to 112.4911133334554, + mapOf(y to 2u) to -469.755906895345, + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ).substitute(mapOf( + x to -8.11707689492641, + )), + 0.001, + "test 3" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 151.1502229133916, + mapOf(y to 1u) to -262.3790170577034, + mapOf(y to 2u) to 102.5097937392923, + ), + LabeledPolynomialAsIs( + mapOf() to -367.9969733169944, + mapOf(y to 1u) to 112.4911133334554, + mapOf(y to 2u) to -469.755906895345, + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ).substitute(mapOf( + x to -8.11707689492641, + iota to 0.9211194782050933 + )), + 0.001, + "test 3'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 14.24074356896978, + mapOf(x to 1u) to -17.71987055153461, + mapOf(x to 2u) to -2.288056483312383, + ), + LabeledPolynomialAsIs( + mapOf() to 7.480604285873397, + mapOf(x to 1u) to -8.43478016688617, + mapOf(x to 2u) to -9.88934943900592, + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ).substitute(mapOf( + y to 0.795265651276015, + )), + 0.001, + "test 4" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 14.24074356896978, + mapOf(x to 1u) to -17.71987055153461, + mapOf(x to 2u) to -2.288056483312383, + ), + LabeledPolynomialAsIs( + mapOf() to 7.480604285873397, + mapOf(x to 1u) to -8.43478016688617, + mapOf(x to 2u) to -9.88934943900592, + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ).substitute(mapOf( + y to 0.795265651276015, + iota to 0.9211194782050933 + )), + 0.001, + "test 4'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 7.321261307532708, + ), + LabeledPolynomialAsIs( + mapOf() to -575.6325831127576, + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ).substitute(mapOf( + x to -8.11707689492641, + y to 0.795265651276015, + )), + 0.001, + "test 5" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 7.321261307532708, + ), + LabeledPolynomialAsIs( + mapOf() to -575.6325831127576, + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to 6.593754860231304, + mapOf(x to 1u) to -7.853302571550634, + mapOf(x to 2u) to 1.2265042281530025, + mapOf(y to 1u) to 3.762648877294904, + mapOf(x to 1u, y to 1u) to -8.945144619305292, + mapOf(x to 2u, y to 1u) to -5.141384718042281, + mapOf(y to 2u) to 7.359794483988782, + mapOf(x to 1u, y to 2u) to -4.3526172680518815, + mapOf(x to 2u, y to 2u) to 0.907910924854372, + ), + LabeledPolynomialAsIs( + mapOf() to 9.533292132172562, + mapOf(x to 1u) to -1.982814534018857, + mapOf(x to 2u) to -5.974248303415283, + mapOf(y to 1u) to 1.5876716499288879, + mapOf(x to 1u, y to 1u) to -7.535152566659664, + mapOf(x to 2u, y to 1u) to 0.7549300500153517, + mapOf(y to 2u) to -5.242030058021028, + mapOf(x to 1u, y to 2u) to -0.7265704289690582, + mapOf(x to 2u, y to 2u) to -7.139677818189821, + ) + ).substitute(mapOf( + x to -8.11707689492641, + y to 0.795265651276015, + iota to 0.9211194782050933 + )), + 0.001, + "test 5'" + ) + } + @Test + fun test_RationalFunction_substitute_Constant_Map() { + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(0) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + ).substitute(RationalField, mapOf( + x to Rational(1) + )), + "test 1" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(22047, 2450), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-2204953, 147000), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ).substitute(RationalField, mapOf( + x to Rational(7, 5), + y to Rational(-13, 7), + )), + "test 2" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(22047, 2450), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-2204953, 147000), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ).substitute(RationalField, mapOf( + x to Rational(7, 5), + y to Rational(-13, 7), + iota to Rational(-16, 4), + )), + "test 2'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(4191, 490), + mapOf(x to 1u) to Rational(14975, 1176), + mapOf(x to 2u) to Rational(-10429, 1176) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-775, 147), + mapOf(x to 1u) to Rational(-155, 49), + mapOf(x to 2u) to Rational(-757, 280) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ).substitute(RationalField, mapOf( + y to Rational(-13, 7), + )), + "test 3" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(4191, 490), + mapOf(x to 1u) to Rational(14975, 1176), + mapOf(x to 2u) to Rational(-10429, 1176) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-775, 147), + mapOf(x to 1u) to Rational(-155, 49), + mapOf(x to 2u) to Rational(-757, 280) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ).substitute(RationalField, mapOf( + y to Rational(-13, 7), + iota to Rational(-16, 4), + )), + "test 3'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-939, 200), + mapOf(y to 1u) to Rational(123, 50), + mapOf(y to 2u) to Rational(1059, 200) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(121, 25), + mapOf(y to 1u) to Rational(-949, 375), + mapOf(y to 2u) to Rational(-1423, 200) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ).substitute(RationalField, mapOf( + x to Rational(7, 5), + )), + "test 4" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-939, 200), + mapOf(y to 1u) to Rational(123, 50), + mapOf(y to 2u) to Rational(1059, 200) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(121, 25), + mapOf(y to 1u) to Rational(-949, 375), + mapOf(y to 2u) to Rational(-1423, 200) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ).substitute(RationalField, mapOf( + x to Rational(7, 5), + iota to Rational(-16, 4), + )), + "test 4'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ).substitute(RationalField, mapOf()), + "test 5" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-3, 5), + mapOf(x to 1u) to Rational(-18, 4), + mapOf(x to 2u) to Rational(9, 8), + mapOf(y to 1u) to Rational(-11, 6), + mapOf(x to 1u, y to 1u) to Rational(-16, 3), + mapOf(x to 2u, y to 1u) to Rational(12, 2), + mapOf(y to 2u) to Rational(5, 3), + mapOf(x to 1u, y to 2u) to Rational(17, 8), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(11, 1), + mapOf(x to 1u) to Rational(4, 1), + mapOf(x to 2u) to Rational(-18, 3), + mapOf(y to 1u) to Rational(12, 9), + mapOf(x to 1u, y to 1u) to Rational(14, 7), + mapOf(x to 2u, y to 1u) to Rational(-17, 5), + mapOf(y to 2u) to Rational(-4, 1), + mapOf(x to 1u, y to 2u) to Rational(-5, 5), + mapOf(x to 2u, y to 2u) to Rational(-7, 8), + ) + ).substitute(RationalField, mapOf( + iota to Rational(-16, 4), + )), + "test 5'" + ) + } + @Test + fun test_RationalFunction_substitute_Polynomial_Map() { + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(0) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + )), + "test 1" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(211, 4), + mapOf(x to 2u) to Rational(88, 3), + mapOf(x to 3u) to Rational(-63, 8), + mapOf(x to 4u) to Rational(441, 16), + mapOf(y to 1u) to Rational(-671, 15), + mapOf(x to 1u, y to 1u) to Rational(-551, 21), + mapOf(x to 2u, y to 1u) to Rational(279, 25), + mapOf(x to 3u, y to 1u) to Rational(231, 20), + mapOf(y to 2u) to Rational(-1436, 1575), + mapOf(x to 1u, y to 2u) to Rational(2471, 250), + mapOf(x to 2u, y to 2u) to Rational(-4919, 100), + mapOf(y to 3u) to Rational(-1464, 125), + mapOf(x to 1u, y to 3u) to Rational(-264, 25), + mapOf(y to 4u) to Rational(576, 25), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(-9, 4), + mapOf(x to 2u) to Rational(943, 8), + mapOf(x to 3u) to Rational(117, 8), + mapOf(x to 4u) to Rational(147, 16), + mapOf(y to 1u) to Rational(289, 90), + mapOf(x to 1u, y to 1u) to Rational(-2692, 15), + mapOf(x to 2u, y to 1u) to Rational(-1629, 140), + mapOf(x to 3u, y to 1u) to Rational(77, 20), + mapOf(y to 2u) to Rational(6187, 75), + mapOf(x to 1u, y to 2u) to Rational(-2879, 175), + mapOf(x to 2u, y to 2u) to Rational(-4919, 300), + mapOf(y to 3u) to Rational(336, 25), + mapOf(x to 1u, y to 3u) to Rational(-88, 25), + mapOf(y to 4u) to Rational(192, 25), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(3, 2), + mapOf(y to 1u) to Rational(8, 5), + ), + y to LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(7, 2), + mapOf(y to 1u) to Rational(-3, 1), + ) + )), + "test 2" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(1202861, 210), + mapOf(x to 1u) to Rational(-215117, 45), + mapOf(x to 2u) to Rational(10889651, 19845), + mapOf(x to 3u) to Rational(-3503956, 6615), + mapOf(x to 4u) to Rational(809066, 2205), + mapOf(x to 5u) to Rational(-9056, 735), + mapOf(x to 6u) to Rational(5396, 315), + mapOf(x to 7u) to Rational(-752, 147), + mapOf(x to 8u) to Rational(16, 49), + mapOf(y to 1u) to Rational(1738469, 1470), + mapOf(x to 1u, y to 1u) to Rational(-926238703, 52920), + mapOf(x to 2u, y to 1u) to Rational(-44113982, 6615), + mapOf(x to 3u, y to 1u) to Rational(10423519, 5292), + mapOf(x to 4u, y to 1u) to Rational(3769712, 2205), + mapOf(x to 5u, y to 1u) to Rational(8905046, 6615), + mapOf(x to 6u, y to 1u) to Rational(1186972, 6615), + mapOf(x to 7u, y to 1u) to Rational(22124, 441), + mapOf(x to 8u, y to 1u) to Rational(-1504, 147), + mapOf(y to 2u) to Rational(-54723628, 2205), + mapOf(x to 1u, y to 2u) to Rational(70109407, 1323), + mapOf(x to 2u, y to 2u) to Rational(151072591, 17640), + mapOf(x to 3u, y to 2u) to Rational(1216428107, 52920), + mapOf(x to 4u, y to 2u) to Rational(2587873193, 317520), + mapOf(x to 5u, y to 2u) to Rational(393536369, 79380), + mapOf(x to 6u, y to 2u) to Rational(137614937, 79380), + mapOf(x to 7u, y to 2u) to Rational(566866, 1323), + mapOf(x to 8u, y to 2u) to Rational(41848, 441), + mapOf(y to 3u) to Rational(-19470406, 2205), + mapOf(x to 1u, y to 3u) to Rational(72514195, 882), + mapOf(x to 2u, y to 3u) to Rational(-78090707, 1764), + mapOf(x to 3u, y to 3u) to Rational(-1988237707, 26460), + mapOf(x to 4u, y to 3u) to Rational(-802137919, 17640), + mapOf(x to 5u, y to 3u) to Rational(-139989463, 5880), + mapOf(x to 6u, y to 3u) to Rational(-26066641, 3780), + mapOf(x to 7u, y to 3u) to Rational(-2363369, 1323), + mapOf(x to 8u, y to 3u) to Rational(-108280, 441), + mapOf(y to 4u) to Rational(14878516, 441), + mapOf(x to 1u, y to 4u) to Rational(-253416724, 2205), + mapOf(x to 2u, y to 4u) to Rational(16699157, 840), + mapOf(x to 3u, y to 4u) to Rational(-105220979, 13230), + mapOf(x to 4u, y to 4u) to Rational(208266383, 5880), + mapOf(x to 5u, y to 4u) to Rational(650135309, 26460), + mapOf(x to 6u, y to 4u) to Rational(123808663, 11760), + mapOf(x to 7u, y to 4u) to Rational(8563385, 2646), + mapOf(x to 8u, y to 4u) to Rational(19721, 49), + mapOf(y to 5u) to Rational(675645, 49), + mapOf(x to 1u, y to 5u) to Rational(-70554077, 588), + mapOf(x to 2u, y to 5u) to Rational(157884029, 980), + mapOf(x to 3u, y to 5u) to Rational(489548623, 4410), + mapOf(x to 4u, y to 5u) to Rational(148540519, 17640), + mapOf(x to 5u, y to 5u) to Rational(-5559551, 392), + mapOf(x to 6u, y to 5u) to Rational(-18335711, 1470), + mapOf(x to 7u, y to 5u) to Rational(-38437, 9), + mapOf(x to 8u, y to 5u) to Rational(-29620, 63), + mapOf(y to 6u) to Rational(-727625, 49), + mapOf(x to 1u, y to 6u) to Rational(7046685, 98), + mapOf(x to 2u, y to 6u) to Rational(-334814231, 7056), + mapOf(x to 3u, y to 6u) to Rational(-243971737, 17640), + mapOf(x to 4u, y to 6u) to Rational(-571116659, 35280), + mapOf(x to 5u, y to 6u) to Rational(567538, 315), + mapOf(x to 6u, y to 6u) to Rational(3199768, 315), + mapOf(x to 7u, y to 6u) to Rational(227744, 63), + mapOf(x to 8u, y to 6u) to Rational(23116, 63), + mapOf(y to 7u) to Rational(-27500, 7), + mapOf(x to 1u, y to 7u) to Rational(120125, 3), + mapOf(x to 2u, y to 7u) to Rational(-279200, 3), + mapOf(x to 3u, y to 7u) to Rational(-100160, 7), + mapOf(x to 4u, y to 7u) to Rational(920452, 21), + mapOf(x to 5u, y to 7u) to Rational(226481, 21), + mapOf(x to 6u, y to 7u) to Rational(-34428, 7), + mapOf(x to 7u, y to 7u) to Rational(-6232, 3), + mapOf(x to 8u, y to 7u) to Rational(-608, 3), + mapOf(y to 8u) to Rational(2500, 1), + mapOf(x to 1u, y to 8u) to Rational(-19000, 1), + mapOf(x to 2u, y to 8u) to Rational(37900, 1), + mapOf(x to 3u, y to 8u) to Rational(-1840, 1), + mapOf(x to 4u, y to 8u) to Rational(-17876, 1), + mapOf(x to 5u, y to 8u) to Rational(-1240, 1), + mapOf(x to 6u, y to 8u) to Rational(2788, 1), + mapOf(x to 7u, y to 8u) to Rational(800, 1), + mapOf(x to 8u, y to 8u) to Rational(64, 1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(162487, 63), + mapOf(x to 1u) to Rational(-92713, 54), + mapOf(x to 2u) to Rational(802436, 1323), + mapOf(x to 3u) to Rational(-55088, 441), + mapOf(x to 4u) to Rational(1404034, 9261), + mapOf(x to 5u) to Rational(-5804, 1029), + mapOf(x to 6u) to Rational(51556, 9261), + mapOf(x to 7u) to Rational(-752, 441), + mapOf(x to 8u) to Rational(16, 147), + mapOf(y to 1u) to Rational(296071, 441), + mapOf(x to 1u, y to 1u) to Rational(-4991281, 882), + mapOf(x to 2u, y to 1u) to Rational(-18702811, 9261), + mapOf(x to 3u, y to 1u) to Rational(40759043, 27783), + mapOf(x to 4u, y to 1u) to Rational(19768501, 27783), + mapOf(x to 5u, y to 1u) to Rational(14307337, 27783), + mapOf(x to 6u, y to 1u) to Rational(1655684, 27783), + mapOf(x to 7u, y to 1u) to Rational(22124, 1323), + mapOf(x to 8u, y to 1u) to Rational(-1504, 441), + mapOf(y to 2u) to Rational(-27667474, 3087), + mapOf(x to 1u, y to 2u) to Rational(265605901, 12348), + mapOf(x to 2u, y to 2u) to Rational(160360775, 98784), + mapOf(x to 3u, y to 2u) to Rational(1169992093, 148176), + mapOf(x to 4u, y to 2u) to Rational(3978014077, 1333584), + mapOf(x to 5u, y to 2u) to Rational(567058123, 333396), + mapOf(x to 6u, y to 2u) to Rational(205132579, 333396), + mapOf(x to 7u, y to 2u) to Rational(566866, 3969), + mapOf(x to 8u, y to 2u) to Rational(41848, 1323), + mapOf(y to 3u) to Rational(-2228822, 1029), + mapOf(x to 1u, y to 3u) to Rational(80179390, 3087), + mapOf(x to 2u, y to 3u) to Rational(-1378630487, 74088), + mapOf(x to 3u, y to 3u) to Rational(-3385811693, 111132), + mapOf(x to 4u, y to 3u) to Rational(-820686977, 49392), + mapOf(x to 5u, y to 3u) to Rational(-89101027, 10584), + mapOf(x to 6u, y to 3u) to Rational(-37847387, 15876), + mapOf(x to 7u, y to 3u) to Rational(-2363369, 3969), + mapOf(x to 8u, y to 3u) to Rational(-108280, 1323), + mapOf(y to 4u) to Rational(12619982, 1029), + mapOf(x to 1u, y to 4u) to Rational(-277723177, 6174), + mapOf(x to 2u, y to 4u) to Rational(649414169, 49392), + mapOf(x to 3u, y to 4u) to Rational(14457595, 63504), + mapOf(x to 4u, y to 4u) to Rational(139270339, 10584), + mapOf(x to 5u, y to 4u) to Rational(140367961, 15876), + mapOf(x to 6u, y to 4u) to Rational(25467083, 7056), + mapOf(x to 7u, y to 4u) to Rational(8563385, 7938), + mapOf(x to 8u, y to 4u) to Rational(19721, 147), + mapOf(y to 5u) to Rational(643850, 147), + mapOf(x to 1u, y to 5u) to Rational(-11818025, 294), + mapOf(x to 2u, y to 5u) to Rational(33963203, 588), + mapOf(x to 3u, y to 5u) to Rational(207216235, 5292), + mapOf(x to 4u, y to 5u) to Rational(2861021, 1512), + mapOf(x to 5u, y to 5u) to Rational(-6302335, 1176), + mapOf(x to 6u, y to 5u) to Rational(-3738587, 882), + mapOf(x to 7u, y to 5u) to Rational(-38437, 27), + mapOf(x to 8u, y to 5u) to Rational(-29620, 189), + mapOf(y to 6u) to Rational(-248725, 49), + mapOf(x to 1u, y to 6u) to Rational(2478535, 98), + mapOf(x to 2u, y to 6u) to Rational(-399721367, 21168), + mapOf(x to 3u, y to 6u) to Rational(-54309317, 10584), + mapOf(x to 4u, y to 6u) to Rational(-95398327, 21168), + mapOf(x to 5u, y to 6u) to Rational(173750, 189), + mapOf(x to 6u, y to 6u) to Rational(92216, 27), + mapOf(x to 7u, y to 6u) to Rational(227744, 189), + mapOf(x to 8u, y to 6u) to Rational(23116, 189), + mapOf(y to 7u) to Rational(-27500, 21), + mapOf(x to 1u, y to 7u) to Rational(120125, 9), + mapOf(x to 2u, y to 7u) to Rational(-279200, 9), + mapOf(x to 3u, y to 7u) to Rational(-100160, 21), + mapOf(x to 4u, y to 7u) to Rational(920452, 63), + mapOf(x to 5u, y to 7u) to Rational(226481, 63), + mapOf(x to 6u, y to 7u) to Rational(-11476, 7), + mapOf(x to 7u, y to 7u) to Rational(-6232, 9), + mapOf(x to 8u, y to 7u) to Rational(-608, 9), + mapOf(y to 8u) to Rational(2500, 3), + mapOf(x to 1u, y to 8u) to Rational(-19000, 3), + mapOf(x to 2u, y to 8u) to Rational(37900, 3), + mapOf(x to 3u, y to 8u) to Rational(-1840, 3), + mapOf(x to 4u, y to 8u) to Rational(-17876, 3), + mapOf(x to 5u, y to 8u) to Rational(-1240, 3), + mapOf(x to 6u, y to 8u) to Rational(2788, 3), + mapOf(x to 7u, y to 8u) to Rational(800, 3), + mapOf(x to 8u, y to 8u) to Rational(64, 3) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(18, 1), + mapOf(x to 1u) to Rational(16, 3), + mapOf(x to 2u) to Rational(12, 6), + mapOf(y to 1u) to Rational(13, 1), + mapOf(x to 1u, y to 1u) to Rational(-11, 4), + mapOf(x to 2u, y to 1u) to Rational(-1, 1), + mapOf(y to 2u) to Rational(-10, 1), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(2, 1), + ), + y to LabeledPolynomialAsIs( + mapOf() to Rational(8, 2), + mapOf(x to 1u) to Rational(-15, 5), + mapOf(x to 2u) to Rational(2, 7), + mapOf(y to 1u) to Rational(-18, 7), + mapOf(x to 1u, y to 1u) to Rational(-16, 6), + mapOf(x to 2u, y to 1u) to Rational(-13, 3), + mapOf(y to 2u) to Rational(-5, 1), + mapOf(x to 1u, y to 2u) to Rational(17, 1), + mapOf(x to 2u, y to 2u) to Rational(8, 2), + ), + )), + "test 3" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(1202861, 210), + mapOf(x to 1u) to Rational(-215117, 45), + mapOf(x to 2u) to Rational(10889651, 19845), + mapOf(x to 3u) to Rational(-3503956, 6615), + mapOf(x to 4u) to Rational(809066, 2205), + mapOf(x to 5u) to Rational(-9056, 735), + mapOf(x to 6u) to Rational(5396, 315), + mapOf(x to 7u) to Rational(-752, 147), + mapOf(x to 8u) to Rational(16, 49), + mapOf(y to 1u) to Rational(1738469, 1470), + mapOf(x to 1u, y to 1u) to Rational(-926238703, 52920), + mapOf(x to 2u, y to 1u) to Rational(-44113982, 6615), + mapOf(x to 3u, y to 1u) to Rational(10423519, 5292), + mapOf(x to 4u, y to 1u) to Rational(3769712, 2205), + mapOf(x to 5u, y to 1u) to Rational(8905046, 6615), + mapOf(x to 6u, y to 1u) to Rational(1186972, 6615), + mapOf(x to 7u, y to 1u) to Rational(22124, 441), + mapOf(x to 8u, y to 1u) to Rational(-1504, 147), + mapOf(y to 2u) to Rational(-54723628, 2205), + mapOf(x to 1u, y to 2u) to Rational(70109407, 1323), + mapOf(x to 2u, y to 2u) to Rational(151072591, 17640), + mapOf(x to 3u, y to 2u) to Rational(1216428107, 52920), + mapOf(x to 4u, y to 2u) to Rational(2587873193, 317520), + mapOf(x to 5u, y to 2u) to Rational(393536369, 79380), + mapOf(x to 6u, y to 2u) to Rational(137614937, 79380), + mapOf(x to 7u, y to 2u) to Rational(566866, 1323), + mapOf(x to 8u, y to 2u) to Rational(41848, 441), + mapOf(y to 3u) to Rational(-19470406, 2205), + mapOf(x to 1u, y to 3u) to Rational(72514195, 882), + mapOf(x to 2u, y to 3u) to Rational(-78090707, 1764), + mapOf(x to 3u, y to 3u) to Rational(-1988237707, 26460), + mapOf(x to 4u, y to 3u) to Rational(-802137919, 17640), + mapOf(x to 5u, y to 3u) to Rational(-139989463, 5880), + mapOf(x to 6u, y to 3u) to Rational(-26066641, 3780), + mapOf(x to 7u, y to 3u) to Rational(-2363369, 1323), + mapOf(x to 8u, y to 3u) to Rational(-108280, 441), + mapOf(y to 4u) to Rational(14878516, 441), + mapOf(x to 1u, y to 4u) to Rational(-253416724, 2205), + mapOf(x to 2u, y to 4u) to Rational(16699157, 840), + mapOf(x to 3u, y to 4u) to Rational(-105220979, 13230), + mapOf(x to 4u, y to 4u) to Rational(208266383, 5880), + mapOf(x to 5u, y to 4u) to Rational(650135309, 26460), + mapOf(x to 6u, y to 4u) to Rational(123808663, 11760), + mapOf(x to 7u, y to 4u) to Rational(8563385, 2646), + mapOf(x to 8u, y to 4u) to Rational(19721, 49), + mapOf(y to 5u) to Rational(675645, 49), + mapOf(x to 1u, y to 5u) to Rational(-70554077, 588), + mapOf(x to 2u, y to 5u) to Rational(157884029, 980), + mapOf(x to 3u, y to 5u) to Rational(489548623, 4410), + mapOf(x to 4u, y to 5u) to Rational(148540519, 17640), + mapOf(x to 5u, y to 5u) to Rational(-5559551, 392), + mapOf(x to 6u, y to 5u) to Rational(-18335711, 1470), + mapOf(x to 7u, y to 5u) to Rational(-38437, 9), + mapOf(x to 8u, y to 5u) to Rational(-29620, 63), + mapOf(y to 6u) to Rational(-727625, 49), + mapOf(x to 1u, y to 6u) to Rational(7046685, 98), + mapOf(x to 2u, y to 6u) to Rational(-334814231, 7056), + mapOf(x to 3u, y to 6u) to Rational(-243971737, 17640), + mapOf(x to 4u, y to 6u) to Rational(-571116659, 35280), + mapOf(x to 5u, y to 6u) to Rational(567538, 315), + mapOf(x to 6u, y to 6u) to Rational(3199768, 315), + mapOf(x to 7u, y to 6u) to Rational(227744, 63), + mapOf(x to 8u, y to 6u) to Rational(23116, 63), + mapOf(y to 7u) to Rational(-27500, 7), + mapOf(x to 1u, y to 7u) to Rational(120125, 3), + mapOf(x to 2u, y to 7u) to Rational(-279200, 3), + mapOf(x to 3u, y to 7u) to Rational(-100160, 7), + mapOf(x to 4u, y to 7u) to Rational(920452, 21), + mapOf(x to 5u, y to 7u) to Rational(226481, 21), + mapOf(x to 6u, y to 7u) to Rational(-34428, 7), + mapOf(x to 7u, y to 7u) to Rational(-6232, 3), + mapOf(x to 8u, y to 7u) to Rational(-608, 3), + mapOf(y to 8u) to Rational(2500, 1), + mapOf(x to 1u, y to 8u) to Rational(-19000, 1), + mapOf(x to 2u, y to 8u) to Rational(37900, 1), + mapOf(x to 3u, y to 8u) to Rational(-1840, 1), + mapOf(x to 4u, y to 8u) to Rational(-17876, 1), + mapOf(x to 5u, y to 8u) to Rational(-1240, 1), + mapOf(x to 6u, y to 8u) to Rational(2788, 1), + mapOf(x to 7u, y to 8u) to Rational(800, 1), + mapOf(x to 8u, y to 8u) to Rational(64, 1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(162487, 63), + mapOf(x to 1u) to Rational(-92713, 54), + mapOf(x to 2u) to Rational(802436, 1323), + mapOf(x to 3u) to Rational(-55088, 441), + mapOf(x to 4u) to Rational(1404034, 9261), + mapOf(x to 5u) to Rational(-5804, 1029), + mapOf(x to 6u) to Rational(51556, 9261), + mapOf(x to 7u) to Rational(-752, 441), + mapOf(x to 8u) to Rational(16, 147), + mapOf(y to 1u) to Rational(296071, 441), + mapOf(x to 1u, y to 1u) to Rational(-4991281, 882), + mapOf(x to 2u, y to 1u) to Rational(-18702811, 9261), + mapOf(x to 3u, y to 1u) to Rational(40759043, 27783), + mapOf(x to 4u, y to 1u) to Rational(19768501, 27783), + mapOf(x to 5u, y to 1u) to Rational(14307337, 27783), + mapOf(x to 6u, y to 1u) to Rational(1655684, 27783), + mapOf(x to 7u, y to 1u) to Rational(22124, 1323), + mapOf(x to 8u, y to 1u) to Rational(-1504, 441), + mapOf(y to 2u) to Rational(-27667474, 3087), + mapOf(x to 1u, y to 2u) to Rational(265605901, 12348), + mapOf(x to 2u, y to 2u) to Rational(160360775, 98784), + mapOf(x to 3u, y to 2u) to Rational(1169992093, 148176), + mapOf(x to 4u, y to 2u) to Rational(3978014077, 1333584), + mapOf(x to 5u, y to 2u) to Rational(567058123, 333396), + mapOf(x to 6u, y to 2u) to Rational(205132579, 333396), + mapOf(x to 7u, y to 2u) to Rational(566866, 3969), + mapOf(x to 8u, y to 2u) to Rational(41848, 1323), + mapOf(y to 3u) to Rational(-2228822, 1029), + mapOf(x to 1u, y to 3u) to Rational(80179390, 3087), + mapOf(x to 2u, y to 3u) to Rational(-1378630487, 74088), + mapOf(x to 3u, y to 3u) to Rational(-3385811693, 111132), + mapOf(x to 4u, y to 3u) to Rational(-820686977, 49392), + mapOf(x to 5u, y to 3u) to Rational(-89101027, 10584), + mapOf(x to 6u, y to 3u) to Rational(-37847387, 15876), + mapOf(x to 7u, y to 3u) to Rational(-2363369, 3969), + mapOf(x to 8u, y to 3u) to Rational(-108280, 1323), + mapOf(y to 4u) to Rational(12619982, 1029), + mapOf(x to 1u, y to 4u) to Rational(-277723177, 6174), + mapOf(x to 2u, y to 4u) to Rational(649414169, 49392), + mapOf(x to 3u, y to 4u) to Rational(14457595, 63504), + mapOf(x to 4u, y to 4u) to Rational(139270339, 10584), + mapOf(x to 5u, y to 4u) to Rational(140367961, 15876), + mapOf(x to 6u, y to 4u) to Rational(25467083, 7056), + mapOf(x to 7u, y to 4u) to Rational(8563385, 7938), + mapOf(x to 8u, y to 4u) to Rational(19721, 147), + mapOf(y to 5u) to Rational(643850, 147), + mapOf(x to 1u, y to 5u) to Rational(-11818025, 294), + mapOf(x to 2u, y to 5u) to Rational(33963203, 588), + mapOf(x to 3u, y to 5u) to Rational(207216235, 5292), + mapOf(x to 4u, y to 5u) to Rational(2861021, 1512), + mapOf(x to 5u, y to 5u) to Rational(-6302335, 1176), + mapOf(x to 6u, y to 5u) to Rational(-3738587, 882), + mapOf(x to 7u, y to 5u) to Rational(-38437, 27), + mapOf(x to 8u, y to 5u) to Rational(-29620, 189), + mapOf(y to 6u) to Rational(-248725, 49), + mapOf(x to 1u, y to 6u) to Rational(2478535, 98), + mapOf(x to 2u, y to 6u) to Rational(-399721367, 21168), + mapOf(x to 3u, y to 6u) to Rational(-54309317, 10584), + mapOf(x to 4u, y to 6u) to Rational(-95398327, 21168), + mapOf(x to 5u, y to 6u) to Rational(173750, 189), + mapOf(x to 6u, y to 6u) to Rational(92216, 27), + mapOf(x to 7u, y to 6u) to Rational(227744, 189), + mapOf(x to 8u, y to 6u) to Rational(23116, 189), + mapOf(y to 7u) to Rational(-27500, 21), + mapOf(x to 1u, y to 7u) to Rational(120125, 9), + mapOf(x to 2u, y to 7u) to Rational(-279200, 9), + mapOf(x to 3u, y to 7u) to Rational(-100160, 21), + mapOf(x to 4u, y to 7u) to Rational(920452, 63), + mapOf(x to 5u, y to 7u) to Rational(226481, 63), + mapOf(x to 6u, y to 7u) to Rational(-11476, 7), + mapOf(x to 7u, y to 7u) to Rational(-6232, 9), + mapOf(x to 8u, y to 7u) to Rational(-608, 9), + mapOf(y to 8u) to Rational(2500, 3), + mapOf(x to 1u, y to 8u) to Rational(-19000, 3), + mapOf(x to 2u, y to 8u) to Rational(37900, 3), + mapOf(x to 3u, y to 8u) to Rational(-1840, 3), + mapOf(x to 4u, y to 8u) to Rational(-17876, 3), + mapOf(x to 5u, y to 8u) to Rational(-1240, 3), + mapOf(x to 6u, y to 8u) to Rational(2788, 3), + mapOf(x to 7u, y to 8u) to Rational(800, 3), + mapOf(x to 8u, y to 8u) to Rational(64, 3) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(18, 1), + mapOf(x to 1u) to Rational(16, 3), + mapOf(x to 2u) to Rational(12, 6), + mapOf(y to 1u) to Rational(13, 1), + mapOf(x to 1u, y to 1u) to Rational(-11, 4), + mapOf(x to 2u, y to 1u) to Rational(-1, 1), + mapOf(y to 2u) to Rational(-10, 1), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(2, 1), + ), + y to LabeledPolynomialAsIs( + mapOf() to Rational(8, 2), + mapOf(x to 1u) to Rational(-15, 5), + mapOf(x to 2u) to Rational(2, 7), + mapOf(y to 1u) to Rational(-18, 7), + mapOf(x to 1u, y to 1u) to Rational(-16, 6), + mapOf(x to 2u, y to 1u) to Rational(-13, 3), + mapOf(y to 2u) to Rational(-5, 1), + mapOf(x to 1u, y to 2u) to Rational(17, 1), + mapOf(x to 2u, y to 2u) to Rational(8, 2), + ), + iota to LabeledPolynomialAsIs( + mapOf() to Rational(-6, 1), + mapOf(x to 1u) to Rational(-9, 8), + mapOf(x to 2u) to Rational(17, 5), + mapOf(y to 1u) to Rational(-2, 3), + mapOf(x to 1u, y to 1u) to Rational(1, 5), + mapOf(x to 2u, y to 1u) to Rational(-11, 7), + mapOf(y to 2u) to Rational(13, 6), + mapOf(x to 1u, y to 2u) to Rational(-15, 2), + mapOf(x to 2u, y to 2u) to Rational(-14, 4), + ) + )), + "test 3'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(493, 6), + mapOf(x to 1u) to Rational(-15991, 210), + mapOf(x to 2u) to Rational(2734, 63), + mapOf(x to 3u) to Rational(-8213, 245), + mapOf(x to 4u) to Rational(1843, 147), + mapOf(x to 5u) to Rational(-432, 245), + mapOf(x to 6u) to Rational(4, 49), + mapOf(y to 1u) to Rational(-66, 1), + mapOf(x to 1u, y to 1u) to Rational(-92924, 2205), + mapOf(x to 2u, y to 1u) to Rational(-257461, 2205), + mapOf(x to 3u, y to 1u) to Rational(58658, 2205), + mapOf(x to 4u, y to 1u) to Rational(-87884, 2205), + mapOf(x to 5u, y to 1u) to Rational(2726, 105), + mapOf(x to 6u, y to 1u) to Rational(-52, 21), + mapOf(y to 2u) to Rational(-17569, 147), + mapOf(x to 1u, y to 2u) to Rational(368819, 735), + mapOf(x to 2u, y to 2u) to Rational(-644626, 6615), + mapOf(x to 3u, y to 2u) to Rational(221738, 945), + mapOf(x to 4u, y to 2u) to Rational(-18022, 945), + mapOf(x to 5u, y to 2u) to Rational(-1201, 315), + mapOf(x to 6u, y to 2u) to Rational(1327, 63), + mapOf(y to 3u) to Rational(240, 7), + mapOf(x to 1u, y to 3u) to Rational(-868, 9), + mapOf(x to 2u, y to 3u) to Rational(-8936, 315), + mapOf(x to 3u, y to 3u) to Rational(-77146, 315), + mapOf(x to 4u, y to 3u) to Rational(-4072, 315), + mapOf(x to 5u, y to 3u) to Rational(-2218, 15), + mapOf(x to 6u, y to 3u) to Rational(-104, 3), + mapOf(y to 4u) to Rational(100, 3), + mapOf(x to 1u, y to 4u) to Rational(-725, 3), + mapOf(x to 2u, y to 4u) to Rational(459, 1), + mapOf(x to 3u, y to 4u) to Rational(-2071, 15), + mapOf(x to 4u, y to 4u) to Rational(2831, 15), + mapOf(x to 5u, y to 4u) to Rational(632, 5), + mapOf(x to 6u, y to 4u) to Rational(16, 1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1255, 9), + mapOf(x to 1u) to Rational(-24781, 126), + mapOf(x to 2u) to Rational(1195, 14), + mapOf(x to 3u) to Rational(-1931, 147), + mapOf(x to 4u) to Rational(439, 147), + mapOf(x to 5u) to Rational(-172, 343), + mapOf(x to 6u) to Rational(4, 147), + mapOf(y to 1u) to Rational(-183, 1), + mapOf(x to 1u, y to 1u) to Rational(-30988, 441), + mapOf(x to 2u, y to 1u) to Rational(-56137, 294), + mapOf(x to 3u, y to 1u) to Rational(204308, 1029), + mapOf(x to 4u, y to 1u) to Rational(-3263, 441), + mapOf(x to 5u, y to 1u) to Rational(2662, 441), + mapOf(x to 6u, y to 1u) to Rational(-52, 63), + mapOf(y to 2u) to Rational(-87119, 294), + mapOf(x to 1u, y to 2u) to Rational(1077919, 686), + mapOf(x to 2u, y to 2u) to Rational(-35209, 147), + mapOf(x to 3u, y to 2u) to Rational(15041, 147), + mapOf(x to 4u, y to 2u) to Rational(240889, 1323), + mapOf(x to 5u, y to 2u) to Rational(27778, 1323), + mapOf(x to 6u, y to 2u) to Rational(1327, 189), + mapOf(y to 3u) to Rational(1620, 7), + mapOf(x to 1u, y to 3u) to Rational(-25716, 49), + mapOf(x to 2u, y to 3u) to Rational(-32078, 49), + mapOf(x to 3u, y to 3u) to Rational(-704038, 441), + mapOf(x to 4u, y to 3u) to Rational(-30190, 63), + mapOf(x to 5u, y to 3u) to Rational(-5414, 63), + mapOf(x to 6u, y to 3u) to Rational(-104, 9), + mapOf(y to 4u) to Rational(225, 1), + mapOf(x to 1u, y to 4u) to Rational(-10560, 7), + mapOf(x to 2u, y to 4u) to Rational(44176, 21), + mapOf(x to 3u, y to 4u) to Rational(28996, 21), + mapOf(x to 4u, y to 4u) to Rational(2405, 7), + mapOf(x to 5u, y to 4u) to Rational(1240, 21), + mapOf(x to 6u, y to 4u) to Rational(16, 3) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf( + y to LabeledPolynomialAsIs( + mapOf() to Rational(8, 2), + mapOf(x to 1u) to Rational(-15, 5), + mapOf(x to 2u) to Rational(2, 7), + mapOf(y to 1u) to Rational(-18, 7), + mapOf(x to 1u, y to 1u) to Rational(-16, 6), + mapOf(x to 2u, y to 1u) to Rational(-13, 3), + mapOf(y to 2u) to Rational(-5, 1), + mapOf(x to 1u, y to 2u) to Rational(17, 1), + mapOf(x to 2u, y to 2u) to Rational(8, 2), + ), + )), + "test 4" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(493, 6), + mapOf(x to 1u) to Rational(-15991, 210), + mapOf(x to 2u) to Rational(2734, 63), + mapOf(x to 3u) to Rational(-8213, 245), + mapOf(x to 4u) to Rational(1843, 147), + mapOf(x to 5u) to Rational(-432, 245), + mapOf(x to 6u) to Rational(4, 49), + mapOf(y to 1u) to Rational(-66, 1), + mapOf(x to 1u, y to 1u) to Rational(-92924, 2205), + mapOf(x to 2u, y to 1u) to Rational(-257461, 2205), + mapOf(x to 3u, y to 1u) to Rational(58658, 2205), + mapOf(x to 4u, y to 1u) to Rational(-87884, 2205), + mapOf(x to 5u, y to 1u) to Rational(2726, 105), + mapOf(x to 6u, y to 1u) to Rational(-52, 21), + mapOf(y to 2u) to Rational(-17569, 147), + mapOf(x to 1u, y to 2u) to Rational(368819, 735), + mapOf(x to 2u, y to 2u) to Rational(-644626, 6615), + mapOf(x to 3u, y to 2u) to Rational(221738, 945), + mapOf(x to 4u, y to 2u) to Rational(-18022, 945), + mapOf(x to 5u, y to 2u) to Rational(-1201, 315), + mapOf(x to 6u, y to 2u) to Rational(1327, 63), + mapOf(y to 3u) to Rational(240, 7), + mapOf(x to 1u, y to 3u) to Rational(-868, 9), + mapOf(x to 2u, y to 3u) to Rational(-8936, 315), + mapOf(x to 3u, y to 3u) to Rational(-77146, 315), + mapOf(x to 4u, y to 3u) to Rational(-4072, 315), + mapOf(x to 5u, y to 3u) to Rational(-2218, 15), + mapOf(x to 6u, y to 3u) to Rational(-104, 3), + mapOf(y to 4u) to Rational(100, 3), + mapOf(x to 1u, y to 4u) to Rational(-725, 3), + mapOf(x to 2u, y to 4u) to Rational(459, 1), + mapOf(x to 3u, y to 4u) to Rational(-2071, 15), + mapOf(x to 4u, y to 4u) to Rational(2831, 15), + mapOf(x to 5u, y to 4u) to Rational(632, 5), + mapOf(x to 6u, y to 4u) to Rational(16, 1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1255, 9), + mapOf(x to 1u) to Rational(-24781, 126), + mapOf(x to 2u) to Rational(1195, 14), + mapOf(x to 3u) to Rational(-1931, 147), + mapOf(x to 4u) to Rational(439, 147), + mapOf(x to 5u) to Rational(-172, 343), + mapOf(x to 6u) to Rational(4, 147), + mapOf(y to 1u) to Rational(-183, 1), + mapOf(x to 1u, y to 1u) to Rational(-30988, 441), + mapOf(x to 2u, y to 1u) to Rational(-56137, 294), + mapOf(x to 3u, y to 1u) to Rational(204308, 1029), + mapOf(x to 4u, y to 1u) to Rational(-3263, 441), + mapOf(x to 5u, y to 1u) to Rational(2662, 441), + mapOf(x to 6u, y to 1u) to Rational(-52, 63), + mapOf(y to 2u) to Rational(-87119, 294), + mapOf(x to 1u, y to 2u) to Rational(1077919, 686), + mapOf(x to 2u, y to 2u) to Rational(-35209, 147), + mapOf(x to 3u, y to 2u) to Rational(15041, 147), + mapOf(x to 4u, y to 2u) to Rational(240889, 1323), + mapOf(x to 5u, y to 2u) to Rational(27778, 1323), + mapOf(x to 6u, y to 2u) to Rational(1327, 189), + mapOf(y to 3u) to Rational(1620, 7), + mapOf(x to 1u, y to 3u) to Rational(-25716, 49), + mapOf(x to 2u, y to 3u) to Rational(-32078, 49), + mapOf(x to 3u, y to 3u) to Rational(-704038, 441), + mapOf(x to 4u, y to 3u) to Rational(-30190, 63), + mapOf(x to 5u, y to 3u) to Rational(-5414, 63), + mapOf(x to 6u, y to 3u) to Rational(-104, 9), + mapOf(y to 4u) to Rational(225, 1), + mapOf(x to 1u, y to 4u) to Rational(-10560, 7), + mapOf(x to 2u, y to 4u) to Rational(44176, 21), + mapOf(x to 3u, y to 4u) to Rational(28996, 21), + mapOf(x to 4u, y to 4u) to Rational(2405, 7), + mapOf(x to 5u, y to 4u) to Rational(1240, 21), + mapOf(x to 6u, y to 4u) to Rational(16, 3) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf( + y to LabeledPolynomialAsIs( + mapOf() to Rational(8, 2), + mapOf(x to 1u) to Rational(-15, 5), + mapOf(x to 2u) to Rational(2, 7), + mapOf(y to 1u) to Rational(-18, 7), + mapOf(x to 1u, y to 1u) to Rational(-16, 6), + mapOf(x to 2u, y to 1u) to Rational(-13, 3), + mapOf(y to 2u) to Rational(-5, 1), + mapOf(x to 1u, y to 2u) to Rational(17, 1), + mapOf(x to 2u, y to 2u) to Rational(8, 2), + ), + iota to LabeledPolynomialAsIs( + mapOf() to Rational(-6, 1), + mapOf(x to 1u) to Rational(-9, 8), + mapOf(x to 2u) to Rational(17, 5), + mapOf(y to 1u) to Rational(-2, 3), + mapOf(x to 1u, y to 1u) to Rational(1, 5), + mapOf(x to 2u, y to 1u) to Rational(-11, 7), + mapOf(y to 2u) to Rational(13, 6), + mapOf(x to 1u, y to 2u) to Rational(-15, 2), + mapOf(x to 2u, y to 2u) to Rational(-14, 4), + ) + )), + "test 4'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-409, 6), + mapOf(x to 1u) to Rational(-376, 9), + mapOf(x to 2u) to Rational(-1781, 81), + mapOf(x to 3u) to Rational(-128, 27), + mapOf(x to 4u) to Rational(-8, 9), + mapOf(y to 1u) to Rational(18701, 210), + mapOf(x to 1u, y to 1u) to Rational(614183, 7560), + mapOf(x to 2u, y to 1u) to Rational(90941, 1890), + mapOf(x to 3u, y to 1u) to Rational(1802, 135), + mapOf(x to 4u, y to 1u) to Rational(112, 45), + mapOf(y to 2u) to Rational(181421, 315), + mapOf(x to 1u, y to 2u) to Rational(77813, 378), + mapOf(x to 2u, y to 2u) to Rational(598583, 7560), + mapOf(x to 3u, y to 2u) to Rational(85, 27), + mapOf(x to 4u, y to 2u) to Rational(2, 5), + mapOf(y to 3u) to Rational(130997, 315), + mapOf(x to 1u, y to 3u) to Rational(1093, 420), + mapOf(x to 2u, y to 3u) to Rational(9551, 2520), + mapOf(x to 3u, y to 3u) to Rational(-14, 45), + mapOf(x to 4u, y to 3u) to Rational(22, 45), + mapOf(y to 4u) to Rational(-2801, 9), + mapOf(x to 1u, y to 4u) to Rational(4033, 90), + mapOf(x to 2u, y to 4u) to Rational(6429, 80), + mapOf(x to 3u, y to 4u) to Rational(2851, 90), + mapOf(x to 4u, y to 4u) to Rational(293, 45), + mapOf(y to 5u) to Rational(-220, 1), + mapOf(x to 1u, y to 5u) to Rational(127, 1), + mapOf(x to 2u, y to 5u) to Rational(202, 5), + mapOf(x to 3u, y to 5u) to Rational(-63, 5), + mapOf(x to 4u, y to 5u) to Rational(-12, 5), + mapOf(y to 6u) to Rational(100, 1), + mapOf(x to 1u, y to 6u) to Rational(-80, 1), + mapOf(x to 2u, y to 6u) to Rational(-24, 1), + mapOf(x to 3u, y to 6u) to Rational(16, 1), + mapOf(x to 4u, y to 6u) to Rational(4, 1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(5407, 9), + mapOf(x to 1u) to Rational(9568, 27), + mapOf(x to 2u) to Rational(4996, 27), + mapOf(x to 3u) to Rational(352, 9), + mapOf(x to 4u) to Rational(22, 3), + mapOf(y to 1u) to Rational(104411, 126), + mapOf(x to 1u, y to 1u) to Rational(6001, 126), + mapOf(x to 2u, y to 1u) to Rational(-796, 21), + mapOf(x to 3u, y to 1u) to Rational(-5389, 126), + mapOf(x to 4u, y to 1u) to Rational(-166, 21), + mapOf(y to 2u) to Rational(-35327, 126), + mapOf(x to 1u, y to 2u) to Rational(53, 252), + mapOf(x to 2u, y to 2u) to Rational(849197, 6048), + mapOf(x to 3u, y to 2u) to Rational(22361, 252), + mapOf(x to 4u, y to 2u) to Rational(773, 42), + mapOf(y to 3u) to Rational(-6067, 21), + mapOf(x to 1u, y to 3u) to Rational(39049, 126), + mapOf(x to 2u, y to 3u) to Rational(80303, 1008), + mapOf(x to 3u, y to 3u) to Rational(-3035, 63), + mapOf(x to 4u, y to 3u) to Rational(-209, 21), + mapOf(y to 4u) to Rational(3113, 21), + mapOf(x to 1u, y to 4u) to Rational(-22345, 126), + mapOf(x to 2u, y to 4u) to Rational(-30931, 1008), + mapOf(x to 3u, y to 4u) to Rational(5837, 126), + mapOf(x to 4u, y to 4u) to Rational(229, 21), + mapOf(y to 5u) to Rational(-2120, 21), + mapOf(x to 1u, y to 5u) to Rational(451, 7), + mapOf(x to 2u, y to 5u) to Rational(422, 21), + mapOf(x to 3u, y to 5u) to Rational(-181, 21), + mapOf(x to 4u, y to 5u) to Rational(-40, 21), + mapOf(y to 6u) to Rational(100, 3), + mapOf(x to 1u, y to 6u) to Rational(-80, 3), + mapOf(x to 2u, y to 6u) to Rational(-8, 1), + mapOf(x to 3u, y to 6u) to Rational(16, 3), + mapOf(x to 4u, y to 6u) to Rational(4, 3) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(18, 1), + mapOf(x to 1u) to Rational(16, 3), + mapOf(x to 2u) to Rational(12, 6), + mapOf(y to 1u) to Rational(13, 1), + mapOf(x to 1u, y to 1u) to Rational(-11, 4), + mapOf(x to 2u, y to 1u) to Rational(-1, 1), + mapOf(y to 2u) to Rational(-10, 1), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(2, 1), + ), + )), + "test 5" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-409, 6), + mapOf(x to 1u) to Rational(-376, 9), + mapOf(x to 2u) to Rational(-1781, 81), + mapOf(x to 3u) to Rational(-128, 27), + mapOf(x to 4u) to Rational(-8, 9), + mapOf(y to 1u) to Rational(18701, 210), + mapOf(x to 1u, y to 1u) to Rational(614183, 7560), + mapOf(x to 2u, y to 1u) to Rational(90941, 1890), + mapOf(x to 3u, y to 1u) to Rational(1802, 135), + mapOf(x to 4u, y to 1u) to Rational(112, 45), + mapOf(y to 2u) to Rational(181421, 315), + mapOf(x to 1u, y to 2u) to Rational(77813, 378), + mapOf(x to 2u, y to 2u) to Rational(598583, 7560), + mapOf(x to 3u, y to 2u) to Rational(85, 27), + mapOf(x to 4u, y to 2u) to Rational(2, 5), + mapOf(y to 3u) to Rational(130997, 315), + mapOf(x to 1u, y to 3u) to Rational(1093, 420), + mapOf(x to 2u, y to 3u) to Rational(9551, 2520), + mapOf(x to 3u, y to 3u) to Rational(-14, 45), + mapOf(x to 4u, y to 3u) to Rational(22, 45), + mapOf(y to 4u) to Rational(-2801, 9), + mapOf(x to 1u, y to 4u) to Rational(4033, 90), + mapOf(x to 2u, y to 4u) to Rational(6429, 80), + mapOf(x to 3u, y to 4u) to Rational(2851, 90), + mapOf(x to 4u, y to 4u) to Rational(293, 45), + mapOf(y to 5u) to Rational(-220, 1), + mapOf(x to 1u, y to 5u) to Rational(127, 1), + mapOf(x to 2u, y to 5u) to Rational(202, 5), + mapOf(x to 3u, y to 5u) to Rational(-63, 5), + mapOf(x to 4u, y to 5u) to Rational(-12, 5), + mapOf(y to 6u) to Rational(100, 1), + mapOf(x to 1u, y to 6u) to Rational(-80, 1), + mapOf(x to 2u, y to 6u) to Rational(-24, 1), + mapOf(x to 3u, y to 6u) to Rational(16, 1), + mapOf(x to 4u, y to 6u) to Rational(4, 1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(5407, 9), + mapOf(x to 1u) to Rational(9568, 27), + mapOf(x to 2u) to Rational(4996, 27), + mapOf(x to 3u) to Rational(352, 9), + mapOf(x to 4u) to Rational(22, 3), + mapOf(y to 1u) to Rational(104411, 126), + mapOf(x to 1u, y to 1u) to Rational(6001, 126), + mapOf(x to 2u, y to 1u) to Rational(-796, 21), + mapOf(x to 3u, y to 1u) to Rational(-5389, 126), + mapOf(x to 4u, y to 1u) to Rational(-166, 21), + mapOf(y to 2u) to Rational(-35327, 126), + mapOf(x to 1u, y to 2u) to Rational(53, 252), + mapOf(x to 2u, y to 2u) to Rational(849197, 6048), + mapOf(x to 3u, y to 2u) to Rational(22361, 252), + mapOf(x to 4u, y to 2u) to Rational(773, 42), + mapOf(y to 3u) to Rational(-6067, 21), + mapOf(x to 1u, y to 3u) to Rational(39049, 126), + mapOf(x to 2u, y to 3u) to Rational(80303, 1008), + mapOf(x to 3u, y to 3u) to Rational(-3035, 63), + mapOf(x to 4u, y to 3u) to Rational(-209, 21), + mapOf(y to 4u) to Rational(3113, 21), + mapOf(x to 1u, y to 4u) to Rational(-22345, 126), + mapOf(x to 2u, y to 4u) to Rational(-30931, 1008), + mapOf(x to 3u, y to 4u) to Rational(5837, 126), + mapOf(x to 4u, y to 4u) to Rational(229, 21), + mapOf(y to 5u) to Rational(-2120, 21), + mapOf(x to 1u, y to 5u) to Rational(451, 7), + mapOf(x to 2u, y to 5u) to Rational(422, 21), + mapOf(x to 3u, y to 5u) to Rational(-181, 21), + mapOf(x to 4u, y to 5u) to Rational(-40, 21), + mapOf(y to 6u) to Rational(100, 3), + mapOf(x to 1u, y to 6u) to Rational(-80, 3), + mapOf(x to 2u, y to 6u) to Rational(-8, 1), + mapOf(x to 3u, y to 6u) to Rational(16, 3), + mapOf(x to 4u, y to 6u) to Rational(4, 3) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf( + x to LabeledPolynomialAsIs( + mapOf() to Rational(18, 1), + mapOf(x to 1u) to Rational(16, 3), + mapOf(x to 2u) to Rational(12, 6), + mapOf(y to 1u) to Rational(13, 1), + mapOf(x to 1u, y to 1u) to Rational(-11, 4), + mapOf(x to 2u, y to 1u) to Rational(-1, 1), + mapOf(y to 2u) to Rational(-10, 1), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(2, 1), + ), + iota to LabeledPolynomialAsIs( + mapOf() to Rational(-6, 1), + mapOf(x to 1u) to Rational(-9, 8), + mapOf(x to 2u) to Rational(17, 5), + mapOf(y to 1u) to Rational(-2, 3), + mapOf(x to 1u, y to 1u) to Rational(1, 5), + mapOf(x to 2u, y to 1u) to Rational(-11, 7), + mapOf(y to 2u) to Rational(13, 6), + mapOf(x to 1u, y to 2u) to Rational(-15, 2), + mapOf(x to 2u, y to 2u) to Rational(-14, 4), + ) + )), + "test 5'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf>()), + "test 6" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 6), + mapOf(x to 1u) to Rational(1, 6), + mapOf(x to 2u) to Rational(-2, 9), + mapOf(y to 1u) to Rational(15, 1), + mapOf(x to 1u, y to 1u) to Rational(18, 7), + mapOf(x to 2u, y to 1u) to Rational(2, 5), + mapOf(y to 2u) to Rational(12, 9), + mapOf(x to 1u, y to 2u) to Rational(-3, 5), + mapOf(x to 2u, y to 2u) to Rational(4, 4), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-11, 9), + mapOf(x to 1u) to Rational(4, 9), + mapOf(x to 2u) to Rational(11, 6), + mapOf(y to 1u) to Rational(-5, 6), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(-1, 7), + mapOf(y to 2u) to Rational(9, 1), + mapOf(x to 1u, y to 2u) to Rational(6, 7), + mapOf(x to 2u, y to 2u) to Rational(1, 3), + ) + ).substitute(RationalField, mapOf( + iota to LabeledPolynomialAsIs( + mapOf() to Rational(-6, 1), + mapOf(x to 1u) to Rational(-9, 8), + mapOf(x to 2u) to Rational(17, 5), + mapOf(y to 1u) to Rational(-2, 3), + mapOf(x to 1u, y to 1u) to Rational(1, 5), + mapOf(x to 2u, y to 1u) to Rational(-11, 7), + mapOf(y to 2u) to Rational(13, 6), + mapOf(x to 1u, y to 2u) to Rational(-15, 2), + mapOf(x to 2u, y to 2u) to Rational(-14, 4), + ) + )), + "test 6'" + ) + } + @Test + @Ignore // FIXME: This tests work only for sane realisations of the substitutions. Currently, it is not. + // Sane algorithm for substitution p(q/r) (p, q, and r are polynomials) should return denominator r^deg(p), + // not r^(deg(p)(deg(p)+1)/2) as it is now. + fun test_RationalFunction_substitute_RationalFunction_Map() { + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(0) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ), + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1) + ) + ) + )), + "test 1" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf(x to 4u) to Rational(-17166109, 793800), + mapOf(x to 3u, y to 1u) to Rational(-930960143, 5556600), + mapOf(x to 2u, y to 2u) to Rational(-144665109691, 350065800), + mapOf(x to 1u, y to 3u) to Rational(-17232577, 52920), + mapOf(y to 4u) to Rational(-68141, 1323), + ), + LabeledPolynomialAsIs( + mapOf(x to 4u) to Rational(-57522533, 14288400), + mapOf(x to 3u, y to 1u) to Rational(-13085162953, 300056400), + mapOf(x to 2u, y to 2u) to Rational(-92093367341, 525098700), + mapOf(x to 1u, y to 3u) to Rational(-1979342797, 6667920), + mapOf(y to 4u) to Rational(-3082727, 21168), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(11, 5), + mapOf(y to 1u) to Rational(8, 4), + ), + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(1, 9), + mapOf(y to 1u) to Rational(11, 7), + ) + ), + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(-2, 7), + mapOf(y to 1u) to Rational(-4, 3), + ), + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(3, 6), + mapOf(y to 1u) to Rational(12, 8), + ) + ), + )), + "test 2" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-130778291, 76800), + mapOf(x to 1u) to Rational(-445270919, 230400), + mapOf(x to 2u) to Rational(44578444937, 14515200), + mapOf(x to 3u) to Rational(17329402153, 1555200), + mapOf(x to 4u) to Rational(89239926809, 2332800), + mapOf(x to 5u) to Rational(2808812267, 145152), + mapOf(x to 6u) to Rational(-21362661007, 725760), + mapOf(x to 7u) to Rational(-258455443, 2016), + mapOf(x to 8u) to Rational(-21454693, 96), + mapOf(y to 1u) to Rational(-1002137, 15360), + mapOf(x to 1u, y to 1u) to Rational(-1704849697, 430080), + mapOf(x to 2u, y to 1u) to Rational(-57657676789, 4838400), + mapOf(x to 3u, y to 1u) to Rational(-101331731, 89600), + mapOf(x to 4u, y to 1u) to Rational(5362280079329, 130636800), + mapOf(x to 5u, y to 1u) to Rational(4069896167053, 130636800), + mapOf(x to 6u, y to 1u) to Rational(12011514569, 544320), + mapOf(x to 7u, y to 1u) to Rational(138293195623, 725760), + mapOf(x to 8u, y to 1u) to Rational(6228779419, 48384), + mapOf(y to 2u) to Rational(-32395872823, 8064000), + mapOf(x to 1u, y to 2u) to Rational(-7398505523, 2304000), + mapOf(x to 2u, y to 2u) to Rational(95217051699521, 3048192000), + mapOf(x to 3u, y to 2u) to Rational(198026968812079, 3657830400), + mapOf(x to 4u, y to 2u) to Rational(4291645618499, 228614400), + mapOf(x to 5u, y to 2u) to Rational(-33211690942439, 914457600), + mapOf(x to 6u, y to 2u) to Rational(-637385538163153, 1371686400), + mapOf(x to 7u, y to 2u) to Rational(-138671528276273, 182891520), + mapOf(x to 8u, y to 2u) to Rational(-14566368751, 217728), + mapOf(y to 3u) to Rational(-10538718719, 2016000), + mapOf(x to 1u, y to 3u) to Rational(-1844485375199, 84672000), + mapOf(x to 2u, y to 3u) to Rational(103968665891, 12096000), + mapOf(x to 3u, y to 3u) to Rational(175402107278351, 1828915200), + mapOf(x to 4u, y to 3u) to Rational(8020699588879, 114307200), + mapOf(x to 5u, y to 3u) to Rational(3414841894991, 38102400), + mapOf(x to 6u, y to 3u) to Rational(1848405591611, 4665600), + mapOf(x to 7u, y to 3u) to Rational(39486708738989, 137168640), + mapOf(x to 8u, y to 3u) to Rational(255926289517, 9144576), + mapOf(y to 4u) to Rational(-655379564629, 105840000), + mapOf(x to 1u, y to 4u) to Rational(-208336039441, 127008000), + mapOf(x to 2u, y to 4u) to Rational(40173146771411, 1143072000), + mapOf(x to 3u, y to 4u) to Rational(150473493581239, 2667168000), + mapOf(x to 4u, y to 4u) to Rational(38833783990483, 1143072000), + mapOf(x to 5u, y to 4u) to Rational(-1963676248203053, 4800902400), + mapOf(x to 6u, y to 4u) to Rational(-2598759412825747, 3200601600), + mapOf(x to 7u, y to 4u) to Rational(-192895352019667, 1280240640), + mapOf(x to 8u, y to 4u) to Rational(3737382679, 6858432), + mapOf(y to 5u) to Rational(-16959378721, 1890000), + mapOf(x to 1u, y to 5u) to Rational(-1864802244743, 79380000), + mapOf(x to 2u, y to 5u) to Rational(13449261536489, 666792000), + mapOf(x to 3u, y to 5u) to Rational(215272234137329, 2667168000), + mapOf(x to 4u, y to 5u) to Rational(6040691379277, 83349000), + mapOf(x to 5u, y to 5u) to Rational(153687143525887, 800150400), + mapOf(x to 6u, y to 5u) to Rational(475602854903563, 2400451200), + mapOf(x to 7u, y to 5u) to Rational(27315599358749, 640120320), + mapOf(x to 8u, y to 5u) to Rational(-2630413357, 10668672), + mapOf(y to 6u) to Rational(-6654999511, 2646000), + mapOf(x to 1u, y to 6u) to Rational(-67885252327, 15876000), + mapOf(x to 2u, y to 6u) to Rational(5786776220983, 2667168000), + mapOf(x to 3u, y to 6u) to Rational(60615922629083, 1143072000), + mapOf(x to 4u, y to 6u) to Rational(-34703539637627407, 672126336000), + mapOf(x to 5u, y to 6u) to Rational(-744694192134101, 2240421120), + mapOf(x to 6u, y to 6u) to Rational(-1782470617231, 14817600), + mapOf(x to 7u, y to 6u) to Rational(59123208433, 8890560), + mapOf(x to 8u, y to 6u) to Rational(-141653, 5292), + mapOf(y to 7u) to Rational(-338051969, 441000), + mapOf(x to 1u, y to 7u) to Rational(468850013, 1764000), + mapOf(x to 2u, y to 7u) to Rational(2102343426101, 222264000), + mapOf(x to 3u, y to 7u) to Rational(7836130602007, 1333584000), + mapOf(x to 4u, y to 7u) to Rational(16239111865997, 746807040), + mapOf(x to 5u, y to 7u) to Rational(3824649185383, 88905600), + mapOf(x to 6u, y to 7u) to Rational(56058614459, 3457440), + mapOf(x to 7u, y to 7u) to Rational(-396766339, 493920), + mapOf(x to 8u, y to 7u) to Rational(-165147, 2744), + mapOf(y to 8u) to Rational(-3088619, 58800), + mapOf(x to 1u, y to 8u) to Rational(155343347, 88200), + mapOf(x to 2u, y to 8u) to Rational(100098736469, 7408800), + mapOf(x to 3u, y to 8u) to Rational(109725511381, 7408800), + mapOf(x to 4u, y to 8u) to Rational(-2431199641013, 59270400), + mapOf(x to 5u, y to 8u) to Rational(-102872383249, 3457440), + mapOf(x to 6u, y to 8u) to Rational(1449461309, 576240), + mapOf(x to 7u, y to 8u) to Rational(812775, 1372), + mapOf(x to 8u, y to 8u) to Rational(-16461, 343) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(164202773, 230400), + mapOf(x to 1u) to Rational(-70345303, 518400), + mapOf(x to 2u) to Rational(-4229702731, 4665600), + mapOf(x to 3u) to Rational(3262171027, 6998400), + mapOf(x to 4u) to Rational(-25423104169, 13996800), + mapOf(x to 5u) to Rational(64061869, 349920), + mapOf(x to 6u) to Rational(-1655878091, 116640), + mapOf(x to 7u) to Rational(-7991441, 648), + mapOf(x to 8u) to Rational(-502591, 18), + mapOf(y to 1u) to Rational(-8780429, 3840), + mapOf(x to 1u, y to 1u) to Rational(434272361, 115200), + mapOf(x to 2u, y to 1u) to Rational(429825727, 41472), + mapOf(x to 3u, y to 1u) to Rational(-10066790339, 6998400), + mapOf(x to 4u, y to 1u) to Rational(70022035471, 20995200), + mapOf(x to 5u, y to 1u) to Rational(-32070283493, 1399680), + mapOf(x to 6u, y to 1u) to Rational(-22051101001, 1399680), + mapOf(x to 7u, y to 1u) to Rational(-126493427, 12960), + mapOf(x to 8u, y to 1u) to Rational(3050245, 864), + mapOf(y to 2u) to Rational(-1194654631, 345600), + mapOf(x to 1u, y to 2u) to Rational(-542961452671, 31104000), + mapOf(x to 2u, y to 2u) to Rational(-234000873607, 48988800), + mapOf(x to 3u, y to 2u) to Rational(140520538087, 3628800), + mapOf(x to 4u, y to 2u) to Rational(9215088876563, 130636800), + mapOf(x to 5u, y to 2u) to Rational(27590569647253, 293932800), + mapOf(x to 6u, y to 2u) to Rational(5129057792891, 97977600), + mapOf(x to 7u, y to 2u) to Rational(-106334191, 5103), + mapOf(x to 8u, y to 2u) to Rational(-1024113911, 435456), + mapOf(y to 3u) to Rational(76223843, 6000), + mapOf(x to 1u, y to 3u) to Rational(57425857357, 2592000), + mapOf(x to 2u, y to 3u) to Rational(-2044736497573, 46656000), + mapOf(x to 3u, y to 3u) to Rational(-26155810120031, 293932800), + mapOf(x to 4u, y to 3u) to Rational(-1064419459813, 6998400), + mapOf(x to 5u, y to 3u) to Rational(-753782018389, 4082400), + mapOf(x to 6u, y to 3u) to Rational(-291973360873, 2799360), + mapOf(x to 7u, y to 3u) to Rational(-46372122599, 816480), + mapOf(x to 8u, y to 3u) to Rational(3579859657, 653184), + mapOf(y to 4u) to Rational(-13374241901, 4320000), + mapOf(x to 1u, y to 4u) to Rational(306606499811, 54432000), + mapOf(x to 2u, y to 4u) to Rational(964267124745437, 13716864000), + mapOf(x to 3u, y to 4u) to Rational(21603809415373, 182891520), + mapOf(x to 4u, y to 4u) to Rational(1097860214654027, 6858432000), + mapOf(x to 5u, y to 4u) to Rational(161615254570669, 914457600), + mapOf(x to 6u, y to 4u) to Rational(758415239461, 22861440), + mapOf(x to 7u, y to 4u) to Rational(2585568355471, 274337280), + mapOf(x to 8u, y to 4u) to Rational(-70433747863, 9144576), + mapOf(y to 5u) to Rational(-9582586217, 2520000), + mapOf(x to 1u, y to 5u) to Rational(-19093471394171, 635040000), + mapOf(x to 2u, y to 5u) to Rational(-13010261944411, 381024000), + mapOf(x to 3u, y to 5u) to Rational(-259039825301861, 4572288000), + mapOf(x to 4u, y to 5u) to Rational(-305081119071079, 2286144000), + mapOf(x to 5u, y to 5u) to Rational(-1923114383311, 19595520), + mapOf(x to 6u, y to 5u) to Rational(-14181787253231, 228614400), + mapOf(x to 7u, y to 5u) to Rational(-3959584789, 4354560), + mapOf(x to 8u, y to 5u) to Rational(4691742523, 762048), + mapOf(y to 6u) to Rational(-588323437, 180000), + mapOf(x to 1u, y to 6u) to Rational(5952234691, 52920000), + mapOf(x to 2u, y to 6u) to Rational(21001851056959, 1088640000), + mapOf(x to 3u, y to 6u) to Rational(84668034357563, 2133734400), + mapOf(x to 4u, y to 6u) to Rational(2029754605811557, 25604812800), + mapOf(x to 5u, y to 6u) to Rational(11721216739823, 426746880), + mapOf(x to 6u, y to 6u) to Rational(-8275903187003, 2133734400), + mapOf(x to 7u, y to 6u) to Rational(-4730447299, 2540160), + mapOf(x to 8u, y to 6u) to Rational(-46069985, 21168), + mapOf(y to 7u) to Rational(-75711301, 117600), + mapOf(x to 1u, y to 7u) to Rational(32430417413, 7056000), + mapOf(x to 2u, y to 7u) to Rational(677988533153, 98784000), + mapOf(x to 3u, y to 7u) to Rational(-948417645827, 71124480), + mapOf(x to 4u, y to 7u) to Rational(-11320265215207, 711244800), + mapOf(x to 5u, y to 7u) to Rational(-676438627783, 50803200), + mapOf(x to 6u, y to 7u) to Rational(-7382274253, 1975680), + mapOf(x to 7u, y to 7u) to Rational(6505733, 2205), + mapOf(x to 8u, y to 7u) to Rational(450137, 882), + mapOf(y to 8u) to Rational(-8368253, 78400), + mapOf(x to 1u, y to 8u) to Rational(6833783, 117600), + mapOf(x to 2u, y to 8u) to Rational(4528971133, 5927040), + mapOf(x to 3u, y to 8u) to Rational(146252636617, 29635200), + mapOf(x to 4u, y to 8u) to Rational(8321882556889, 1659571200), + mapOf(x to 5u, y to 8u) to Rational(-4686033011, 1975680), + mapOf(x to 6u, y to 8u) to Rational(-1074445963, 987840), + mapOf(x to 7u, y to 8u) to Rational(-142313, 588), + mapOf(x to 8u, y to 8u) to Rational(-4281, 49) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-17, 5), + mapOf(x to 1u) to Rational(2, 6), + mapOf(x to 2u) to Rational(14, 1), + mapOf(y to 1u) to Rational(-6, 6), + mapOf(x to 1u, y to 1u) to Rational(-7, 3), + mapOf(x to 2u, y to 1u) to Rational(-2, 9), + mapOf(y to 2u) to Rational(-9, 6), + mapOf(x to 1u, y to 2u) to Rational(17, 4), + mapOf(x to 2u, y to 2u) to Rational(2, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(5, 4), + mapOf(x to 1u) to Rational(-5, 9), + mapOf(x to 2u) to Rational(-3, 6), + mapOf(y to 1u) to Rational(6, 5), + mapOf(x to 1u, y to 1u) to Rational(14, 5), + mapOf(x to 2u, y to 1u) to Rational(5, 2), + mapOf(y to 2u) to Rational(-18, 7), + mapOf(x to 1u, y to 2u) to Rational(-8, 2), + mapOf(x to 2u, y to 2u) to Rational(18, 9), + ) + ), + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(14, 4), + mapOf(x to 1u) to Rational(7, 6), + mapOf(x to 2u) to Rational(7, 2), + mapOf(y to 1u) to Rational(-15, 2), + mapOf(x to 1u, y to 1u) to Rational(-13, 8), + mapOf(x to 2u, y to 1u) to Rational(-14, 3), + mapOf(y to 2u) to Rational(-7, 6), + mapOf(x to 1u, y to 2u) to Rational(7, 4), + mapOf(x to 2u, y to 2u) to Rational(9, 7), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-7, 4), + mapOf(x to 1u) to Rational(-6, 3), + mapOf(x to 2u) to Rational(-16, 2), + mapOf(y to 1u) to Rational(-15, 5), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(5, 4), + mapOf(y to 2u) to Rational(-12, 5), + mapOf(x to 1u, y to 2u) to Rational(-18, 2), + mapOf(x to 2u, y to 2u) to Rational(6, 7), + ) + ), + )), + "test 3" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-130778291, 76800), + mapOf(x to 1u) to Rational(-445270919, 230400), + mapOf(x to 2u) to Rational(44578444937, 14515200), + mapOf(x to 3u) to Rational(17329402153, 1555200), + mapOf(x to 4u) to Rational(89239926809, 2332800), + mapOf(x to 5u) to Rational(2808812267, 145152), + mapOf(x to 6u) to Rational(-21362661007, 725760), + mapOf(x to 7u) to Rational(-258455443, 2016), + mapOf(x to 8u) to Rational(-21454693, 96), + mapOf(y to 1u) to Rational(-1002137, 15360), + mapOf(x to 1u, y to 1u) to Rational(-1704849697, 430080), + mapOf(x to 2u, y to 1u) to Rational(-57657676789, 4838400), + mapOf(x to 3u, y to 1u) to Rational(-101331731, 89600), + mapOf(x to 4u, y to 1u) to Rational(5362280079329, 130636800), + mapOf(x to 5u, y to 1u) to Rational(4069896167053, 130636800), + mapOf(x to 6u, y to 1u) to Rational(12011514569, 544320), + mapOf(x to 7u, y to 1u) to Rational(138293195623, 725760), + mapOf(x to 8u, y to 1u) to Rational(6228779419, 48384), + mapOf(y to 2u) to Rational(-32395872823, 8064000), + mapOf(x to 1u, y to 2u) to Rational(-7398505523, 2304000), + mapOf(x to 2u, y to 2u) to Rational(95217051699521, 3048192000), + mapOf(x to 3u, y to 2u) to Rational(198026968812079, 3657830400), + mapOf(x to 4u, y to 2u) to Rational(4291645618499, 228614400), + mapOf(x to 5u, y to 2u) to Rational(-33211690942439, 914457600), + mapOf(x to 6u, y to 2u) to Rational(-637385538163153, 1371686400), + mapOf(x to 7u, y to 2u) to Rational(-138671528276273, 182891520), + mapOf(x to 8u, y to 2u) to Rational(-14566368751, 217728), + mapOf(y to 3u) to Rational(-10538718719, 2016000), + mapOf(x to 1u, y to 3u) to Rational(-1844485375199, 84672000), + mapOf(x to 2u, y to 3u) to Rational(103968665891, 12096000), + mapOf(x to 3u, y to 3u) to Rational(175402107278351, 1828915200), + mapOf(x to 4u, y to 3u) to Rational(8020699588879, 114307200), + mapOf(x to 5u, y to 3u) to Rational(3414841894991, 38102400), + mapOf(x to 6u, y to 3u) to Rational(1848405591611, 4665600), + mapOf(x to 7u, y to 3u) to Rational(39486708738989, 137168640), + mapOf(x to 8u, y to 3u) to Rational(255926289517, 9144576), + mapOf(y to 4u) to Rational(-655379564629, 105840000), + mapOf(x to 1u, y to 4u) to Rational(-208336039441, 127008000), + mapOf(x to 2u, y to 4u) to Rational(40173146771411, 1143072000), + mapOf(x to 3u, y to 4u) to Rational(150473493581239, 2667168000), + mapOf(x to 4u, y to 4u) to Rational(38833783990483, 1143072000), + mapOf(x to 5u, y to 4u) to Rational(-1963676248203053, 4800902400), + mapOf(x to 6u, y to 4u) to Rational(-2598759412825747, 3200601600), + mapOf(x to 7u, y to 4u) to Rational(-192895352019667, 1280240640), + mapOf(x to 8u, y to 4u) to Rational(3737382679, 6858432), + mapOf(y to 5u) to Rational(-16959378721, 1890000), + mapOf(x to 1u, y to 5u) to Rational(-1864802244743, 79380000), + mapOf(x to 2u, y to 5u) to Rational(13449261536489, 666792000), + mapOf(x to 3u, y to 5u) to Rational(215272234137329, 2667168000), + mapOf(x to 4u, y to 5u) to Rational(6040691379277, 83349000), + mapOf(x to 5u, y to 5u) to Rational(153687143525887, 800150400), + mapOf(x to 6u, y to 5u) to Rational(475602854903563, 2400451200), + mapOf(x to 7u, y to 5u) to Rational(27315599358749, 640120320), + mapOf(x to 8u, y to 5u) to Rational(-2630413357, 10668672), + mapOf(y to 6u) to Rational(-6654999511, 2646000), + mapOf(x to 1u, y to 6u) to Rational(-67885252327, 15876000), + mapOf(x to 2u, y to 6u) to Rational(5786776220983, 2667168000), + mapOf(x to 3u, y to 6u) to Rational(60615922629083, 1143072000), + mapOf(x to 4u, y to 6u) to Rational(-34703539637627407, 672126336000), + mapOf(x to 5u, y to 6u) to Rational(-744694192134101, 2240421120), + mapOf(x to 6u, y to 6u) to Rational(-1782470617231, 14817600), + mapOf(x to 7u, y to 6u) to Rational(59123208433, 8890560), + mapOf(x to 8u, y to 6u) to Rational(-141653, 5292), + mapOf(y to 7u) to Rational(-338051969, 441000), + mapOf(x to 1u, y to 7u) to Rational(468850013, 1764000), + mapOf(x to 2u, y to 7u) to Rational(2102343426101, 222264000), + mapOf(x to 3u, y to 7u) to Rational(7836130602007, 1333584000), + mapOf(x to 4u, y to 7u) to Rational(16239111865997, 746807040), + mapOf(x to 5u, y to 7u) to Rational(3824649185383, 88905600), + mapOf(x to 6u, y to 7u) to Rational(56058614459, 3457440), + mapOf(x to 7u, y to 7u) to Rational(-396766339, 493920), + mapOf(x to 8u, y to 7u) to Rational(-165147, 2744), + mapOf(y to 8u) to Rational(-3088619, 58800), + mapOf(x to 1u, y to 8u) to Rational(155343347, 88200), + mapOf(x to 2u, y to 8u) to Rational(100098736469, 7408800), + mapOf(x to 3u, y to 8u) to Rational(109725511381, 7408800), + mapOf(x to 4u, y to 8u) to Rational(-2431199641013, 59270400), + mapOf(x to 5u, y to 8u) to Rational(-102872383249, 3457440), + mapOf(x to 6u, y to 8u) to Rational(1449461309, 576240), + mapOf(x to 7u, y to 8u) to Rational(812775, 1372), + mapOf(x to 8u, y to 8u) to Rational(-16461, 343) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(164202773, 230400), + mapOf(x to 1u) to Rational(-70345303, 518400), + mapOf(x to 2u) to Rational(-4229702731, 4665600), + mapOf(x to 3u) to Rational(3262171027, 6998400), + mapOf(x to 4u) to Rational(-25423104169, 13996800), + mapOf(x to 5u) to Rational(64061869, 349920), + mapOf(x to 6u) to Rational(-1655878091, 116640), + mapOf(x to 7u) to Rational(-7991441, 648), + mapOf(x to 8u) to Rational(-502591, 18), + mapOf(y to 1u) to Rational(-8780429, 3840), + mapOf(x to 1u, y to 1u) to Rational(434272361, 115200), + mapOf(x to 2u, y to 1u) to Rational(429825727, 41472), + mapOf(x to 3u, y to 1u) to Rational(-10066790339, 6998400), + mapOf(x to 4u, y to 1u) to Rational(70022035471, 20995200), + mapOf(x to 5u, y to 1u) to Rational(-32070283493, 1399680), + mapOf(x to 6u, y to 1u) to Rational(-22051101001, 1399680), + mapOf(x to 7u, y to 1u) to Rational(-126493427, 12960), + mapOf(x to 8u, y to 1u) to Rational(3050245, 864), + mapOf(y to 2u) to Rational(-1194654631, 345600), + mapOf(x to 1u, y to 2u) to Rational(-542961452671, 31104000), + mapOf(x to 2u, y to 2u) to Rational(-234000873607, 48988800), + mapOf(x to 3u, y to 2u) to Rational(140520538087, 3628800), + mapOf(x to 4u, y to 2u) to Rational(9215088876563, 130636800), + mapOf(x to 5u, y to 2u) to Rational(27590569647253, 293932800), + mapOf(x to 6u, y to 2u) to Rational(5129057792891, 97977600), + mapOf(x to 7u, y to 2u) to Rational(-106334191, 5103), + mapOf(x to 8u, y to 2u) to Rational(-1024113911, 435456), + mapOf(y to 3u) to Rational(76223843, 6000), + mapOf(x to 1u, y to 3u) to Rational(57425857357, 2592000), + mapOf(x to 2u, y to 3u) to Rational(-2044736497573, 46656000), + mapOf(x to 3u, y to 3u) to Rational(-26155810120031, 293932800), + mapOf(x to 4u, y to 3u) to Rational(-1064419459813, 6998400), + mapOf(x to 5u, y to 3u) to Rational(-753782018389, 4082400), + mapOf(x to 6u, y to 3u) to Rational(-291973360873, 2799360), + mapOf(x to 7u, y to 3u) to Rational(-46372122599, 816480), + mapOf(x to 8u, y to 3u) to Rational(3579859657, 653184), + mapOf(y to 4u) to Rational(-13374241901, 4320000), + mapOf(x to 1u, y to 4u) to Rational(306606499811, 54432000), + mapOf(x to 2u, y to 4u) to Rational(964267124745437, 13716864000), + mapOf(x to 3u, y to 4u) to Rational(21603809415373, 182891520), + mapOf(x to 4u, y to 4u) to Rational(1097860214654027, 6858432000), + mapOf(x to 5u, y to 4u) to Rational(161615254570669, 914457600), + mapOf(x to 6u, y to 4u) to Rational(758415239461, 22861440), + mapOf(x to 7u, y to 4u) to Rational(2585568355471, 274337280), + mapOf(x to 8u, y to 4u) to Rational(-70433747863, 9144576), + mapOf(y to 5u) to Rational(-9582586217, 2520000), + mapOf(x to 1u, y to 5u) to Rational(-19093471394171, 635040000), + mapOf(x to 2u, y to 5u) to Rational(-13010261944411, 381024000), + mapOf(x to 3u, y to 5u) to Rational(-259039825301861, 4572288000), + mapOf(x to 4u, y to 5u) to Rational(-305081119071079, 2286144000), + mapOf(x to 5u, y to 5u) to Rational(-1923114383311, 19595520), + mapOf(x to 6u, y to 5u) to Rational(-14181787253231, 228614400), + mapOf(x to 7u, y to 5u) to Rational(-3959584789, 4354560), + mapOf(x to 8u, y to 5u) to Rational(4691742523, 762048), + mapOf(y to 6u) to Rational(-588323437, 180000), + mapOf(x to 1u, y to 6u) to Rational(5952234691, 52920000), + mapOf(x to 2u, y to 6u) to Rational(21001851056959, 1088640000), + mapOf(x to 3u, y to 6u) to Rational(84668034357563, 2133734400), + mapOf(x to 4u, y to 6u) to Rational(2029754605811557, 25604812800), + mapOf(x to 5u, y to 6u) to Rational(11721216739823, 426746880), + mapOf(x to 6u, y to 6u) to Rational(-8275903187003, 2133734400), + mapOf(x to 7u, y to 6u) to Rational(-4730447299, 2540160), + mapOf(x to 8u, y to 6u) to Rational(-46069985, 21168), + mapOf(y to 7u) to Rational(-75711301, 117600), + mapOf(x to 1u, y to 7u) to Rational(32430417413, 7056000), + mapOf(x to 2u, y to 7u) to Rational(677988533153, 98784000), + mapOf(x to 3u, y to 7u) to Rational(-948417645827, 71124480), + mapOf(x to 4u, y to 7u) to Rational(-11320265215207, 711244800), + mapOf(x to 5u, y to 7u) to Rational(-676438627783, 50803200), + mapOf(x to 6u, y to 7u) to Rational(-7382274253, 1975680), + mapOf(x to 7u, y to 7u) to Rational(6505733, 2205), + mapOf(x to 8u, y to 7u) to Rational(450137, 882), + mapOf(y to 8u) to Rational(-8368253, 78400), + mapOf(x to 1u, y to 8u) to Rational(6833783, 117600), + mapOf(x to 2u, y to 8u) to Rational(4528971133, 5927040), + mapOf(x to 3u, y to 8u) to Rational(146252636617, 29635200), + mapOf(x to 4u, y to 8u) to Rational(8321882556889, 1659571200), + mapOf(x to 5u, y to 8u) to Rational(-4686033011, 1975680), + mapOf(x to 6u, y to 8u) to Rational(-1074445963, 987840), + mapOf(x to 7u, y to 8u) to Rational(-142313, 588), + mapOf(x to 8u, y to 8u) to Rational(-4281, 49) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-17, 5), + mapOf(x to 1u) to Rational(2, 6), + mapOf(x to 2u) to Rational(14, 1), + mapOf(y to 1u) to Rational(-6, 6), + mapOf(x to 1u, y to 1u) to Rational(-7, 3), + mapOf(x to 2u, y to 1u) to Rational(-2, 9), + mapOf(y to 2u) to Rational(-9, 6), + mapOf(x to 1u, y to 2u) to Rational(17, 4), + mapOf(x to 2u, y to 2u) to Rational(2, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(5, 4), + mapOf(x to 1u) to Rational(-5, 9), + mapOf(x to 2u) to Rational(-3, 6), + mapOf(y to 1u) to Rational(6, 5), + mapOf(x to 1u, y to 1u) to Rational(14, 5), + mapOf(x to 2u, y to 1u) to Rational(5, 2), + mapOf(y to 2u) to Rational(-18, 7), + mapOf(x to 1u, y to 2u) to Rational(-8, 2), + mapOf(x to 2u, y to 2u) to Rational(18, 9), + ) + ), + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(14, 4), + mapOf(x to 1u) to Rational(7, 6), + mapOf(x to 2u) to Rational(7, 2), + mapOf(y to 1u) to Rational(-15, 2), + mapOf(x to 1u, y to 1u) to Rational(-13, 8), + mapOf(x to 2u, y to 1u) to Rational(-14, 3), + mapOf(y to 2u) to Rational(-7, 6), + mapOf(x to 1u, y to 2u) to Rational(7, 4), + mapOf(x to 2u, y to 2u) to Rational(9, 7), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-7, 4), + mapOf(x to 1u) to Rational(-6, 3), + mapOf(x to 2u) to Rational(-16, 2), + mapOf(y to 1u) to Rational(-15, 5), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(5, 4), + mapOf(y to 2u) to Rational(-12, 5), + mapOf(x to 1u, y to 2u) to Rational(-18, 2), + mapOf(x to 2u, y to 2u) to Rational(6, 7), + ) + ), + iota to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 8), + mapOf(x to 1u) to Rational(-12, 6), + mapOf(x to 2u) to Rational(7, 6), + mapOf(y to 1u) to Rational(-10, 4), + mapOf(x to 1u, y to 1u) to Rational(-7, 6), + mapOf(x to 2u, y to 1u) to Rational(8, 9), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-13, 4), + mapOf(x to 2u, y to 2u) to Rational(5, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(10, 6), + mapOf(x to 1u) to Rational(-18, 6), + mapOf(x to 2u) to Rational(5, 1), + mapOf(y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(8, 4), + mapOf(x to 2u, y to 1u) to Rational(-4, 9), + mapOf(y to 2u) to Rational(-6, 5), + mapOf(x to 1u, y to 2u) to Rational(-15, 8), + mapOf(x to 2u, y to 2u) to Rational(-18, 5), + ) + ), + )), + "test 3'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(2303, 64), + mapOf(x to 1u) to Rational(31843, 192), + mapOf(x to 2u) to Rational(118891, 576), + mapOf(x to 3u) to Rational(94453, 168), + mapOf(x to 4u) to Rational(-179203, 1512), + mapOf(x to 5u) to Rational(-16979, 126), + mapOf(x to 6u) to Rational(-13499, 12), + mapOf(y to 1u) to Rational(-4767, 64), + mapOf(x to 1u, y to 1u) to Rational(-58689, 256), + mapOf(x to 2u, y to 1u) to Rational(-757333, 4032), + mapOf(x to 3u, y to 1u) to Rational(-4921205, 4032), + mapOf(x to 4u, y to 1u) to Rational(-2930815, 4032), + mapOf(x to 5u, y to 1u) to Rational(-398803, 1512), + mapOf(x to 6u, y to 1u) to Rational(18835, 36), + mapOf(y to 2u) to Rational(224101, 960), + mapOf(x to 1u, y to 2u) to Rational(9139699, 40320), + mapOf(x to 2u, y to 2u) to Rational(3848803, 5760), + mapOf(x to 3u, y to 2u) to Rational(93102371, 241920), + mapOf(x to 4u, y to 2u) to Rational(-65821229, 141120), + mapOf(x to 5u, y to 2u) to Rational(-15675899, 7056), + mapOf(x to 6u, y to 2u) to Rational(10459, 189), + mapOf(y to 3u) to Rational(2411, 16), + mapOf(x to 1u, y to 3u) to Rational(1294543, 10080), + mapOf(x to 2u, y to 3u) to Rational(-1740199, 1440), + mapOf(x to 3u, y to 3u) to Rational(-266994841, 282240), + mapOf(x to 4u, y to 3u) to Rational(-41261893, 211680), + mapOf(x to 5u, y to 3u) to Rational(1717357, 3528), + mapOf(x to 6u, y to 3u) to Rational(69, 14), + mapOf(y to 4u) to Rational(13231, 360), + mapOf(x to 1u, y to 4u) to Rational(4858831, 25200), + mapOf(x to 2u, y to 4u) to Rational(15565759, 75600), + mapOf(x to 3u, y to 4u) to Rational(-15583391, 35280), + mapOf(x to 4u, y to 4u) to Rational(-13345747, 11760), + mapOf(x to 5u, y to 4u) to Rational(140103, 686), + mapOf(x to 6u, y to 4u) to Rational(-765, 49) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(31409, 576), + mapOf(x to 1u) to Rational(-337099, 1728), + mapOf(x to 2u) to Rational(-211429, 1728), + mapOf(x to 3u) to Rational(-259241, 432), + mapOf(x to 4u) to Rational(-13777, 36), + mapOf(x to 5u) to Rational(-41389, 72), + mapOf(x to 6u) to Rational(-7679, 48), + mapOf(y to 1u) to Rational(-3269, 12), + mapOf(x to 1u, y to 1u) to Rational(629569, 864), + mapOf(x to 2u, y to 1u) to Rational(53867, 324), + mapOf(x to 3u, y to 1u) to Rational(2290577, 1728), + mapOf(x to 4u, y to 1u) to Rational(101507, 216), + mapOf(x to 5u, y to 1u) to Rational(213109, 288), + mapOf(x to 6u, y to 1u) to Rational(17927, 144), + mapOf(y to 2u) to Rational(314587, 1080), + mapOf(x to 1u, y to 2u) to Rational(-109771, 144), + mapOf(x to 2u, y to 2u) to Rational(-6469, 16), + mapOf(x to 3u, y to 2u) to Rational(-298291681, 181440), + mapOf(x to 4u, y to 2u) to Rational(-59147357, 48384), + mapOf(x to 5u, y to 2u) to Rational(-4982365, 6048), + mapOf(x to 6u, y to 2u) to Rational(-18727, 576), + mapOf(y to 3u) to Rational(12379, 90), + mapOf(x to 1u, y to 3u) to Rational(-542911, 1620), + mapOf(x to 2u, y to 3u) to Rational(143123, 1260), + mapOf(x to 3u, y to 3u) to Rational(9859177, 30240), + mapOf(x to 4u, y to 3u) to Rational(9312529, 20160), + mapOf(x to 5u, y to 3u) to Rational(207001, 672), + mapOf(x to 6u, y to 3u) to Rational(203, 24), + mapOf(y to 4u) to Rational(9442, 675), + mapOf(x to 1u, y to 4u) to Rational(-13729, 300), + mapOf(x to 2u, y to 4u) to Rational(-3490471, 25200), + mapOf(x to 3u, y to 4u) to Rational(-333031, 840), + mapOf(x to 4u, y to 4u) to Rational(-7572211, 47040), + mapOf(x to 5u, y to 4u) to Rational(-1189, 56), + mapOf(x to 6u, y to 4u) to Rational(-405, 196) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf( + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(14, 4), + mapOf(x to 1u) to Rational(7, 6), + mapOf(x to 2u) to Rational(7, 2), + mapOf(y to 1u) to Rational(-15, 2), + mapOf(x to 1u, y to 1u) to Rational(-13, 8), + mapOf(x to 2u, y to 1u) to Rational(-14, 3), + mapOf(y to 2u) to Rational(-7, 6), + mapOf(x to 1u, y to 2u) to Rational(7, 4), + mapOf(x to 2u, y to 2u) to Rational(9, 7), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-7, 4), + mapOf(x to 1u) to Rational(-6, 3), + mapOf(x to 2u) to Rational(-16, 2), + mapOf(y to 1u) to Rational(-15, 5), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(5, 4), + mapOf(y to 2u) to Rational(-12, 5), + mapOf(x to 1u, y to 2u) to Rational(-18, 2), + mapOf(x to 2u, y to 2u) to Rational(6, 7), + ) + ), + )), + "test 4" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(2303, 64), + mapOf(x to 1u) to Rational(31843, 192), + mapOf(x to 2u) to Rational(118891, 576), + mapOf(x to 3u) to Rational(94453, 168), + mapOf(x to 4u) to Rational(-179203, 1512), + mapOf(x to 5u) to Rational(-16979, 126), + mapOf(x to 6u) to Rational(-13499, 12), + mapOf(y to 1u) to Rational(-4767, 64), + mapOf(x to 1u, y to 1u) to Rational(-58689, 256), + mapOf(x to 2u, y to 1u) to Rational(-757333, 4032), + mapOf(x to 3u, y to 1u) to Rational(-4921205, 4032), + mapOf(x to 4u, y to 1u) to Rational(-2930815, 4032), + mapOf(x to 5u, y to 1u) to Rational(-398803, 1512), + mapOf(x to 6u, y to 1u) to Rational(18835, 36), + mapOf(y to 2u) to Rational(224101, 960), + mapOf(x to 1u, y to 2u) to Rational(9139699, 40320), + mapOf(x to 2u, y to 2u) to Rational(3848803, 5760), + mapOf(x to 3u, y to 2u) to Rational(93102371, 241920), + mapOf(x to 4u, y to 2u) to Rational(-65821229, 141120), + mapOf(x to 5u, y to 2u) to Rational(-15675899, 7056), + mapOf(x to 6u, y to 2u) to Rational(10459, 189), + mapOf(y to 3u) to Rational(2411, 16), + mapOf(x to 1u, y to 3u) to Rational(1294543, 10080), + mapOf(x to 2u, y to 3u) to Rational(-1740199, 1440), + mapOf(x to 3u, y to 3u) to Rational(-266994841, 282240), + mapOf(x to 4u, y to 3u) to Rational(-41261893, 211680), + mapOf(x to 5u, y to 3u) to Rational(1717357, 3528), + mapOf(x to 6u, y to 3u) to Rational(69, 14), + mapOf(y to 4u) to Rational(13231, 360), + mapOf(x to 1u, y to 4u) to Rational(4858831, 25200), + mapOf(x to 2u, y to 4u) to Rational(15565759, 75600), + mapOf(x to 3u, y to 4u) to Rational(-15583391, 35280), + mapOf(x to 4u, y to 4u) to Rational(-13345747, 11760), + mapOf(x to 5u, y to 4u) to Rational(140103, 686), + mapOf(x to 6u, y to 4u) to Rational(-765, 49) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(31409, 576), + mapOf(x to 1u) to Rational(-337099, 1728), + mapOf(x to 2u) to Rational(-211429, 1728), + mapOf(x to 3u) to Rational(-259241, 432), + mapOf(x to 4u) to Rational(-13777, 36), + mapOf(x to 5u) to Rational(-41389, 72), + mapOf(x to 6u) to Rational(-7679, 48), + mapOf(y to 1u) to Rational(-3269, 12), + mapOf(x to 1u, y to 1u) to Rational(629569, 864), + mapOf(x to 2u, y to 1u) to Rational(53867, 324), + mapOf(x to 3u, y to 1u) to Rational(2290577, 1728), + mapOf(x to 4u, y to 1u) to Rational(101507, 216), + mapOf(x to 5u, y to 1u) to Rational(213109, 288), + mapOf(x to 6u, y to 1u) to Rational(17927, 144), + mapOf(y to 2u) to Rational(314587, 1080), + mapOf(x to 1u, y to 2u) to Rational(-109771, 144), + mapOf(x to 2u, y to 2u) to Rational(-6469, 16), + mapOf(x to 3u, y to 2u) to Rational(-298291681, 181440), + mapOf(x to 4u, y to 2u) to Rational(-59147357, 48384), + mapOf(x to 5u, y to 2u) to Rational(-4982365, 6048), + mapOf(x to 6u, y to 2u) to Rational(-18727, 576), + mapOf(y to 3u) to Rational(12379, 90), + mapOf(x to 1u, y to 3u) to Rational(-542911, 1620), + mapOf(x to 2u, y to 3u) to Rational(143123, 1260), + mapOf(x to 3u, y to 3u) to Rational(9859177, 30240), + mapOf(x to 4u, y to 3u) to Rational(9312529, 20160), + mapOf(x to 5u, y to 3u) to Rational(207001, 672), + mapOf(x to 6u, y to 3u) to Rational(203, 24), + mapOf(y to 4u) to Rational(9442, 675), + mapOf(x to 1u, y to 4u) to Rational(-13729, 300), + mapOf(x to 2u, y to 4u) to Rational(-3490471, 25200), + mapOf(x to 3u, y to 4u) to Rational(-333031, 840), + mapOf(x to 4u, y to 4u) to Rational(-7572211, 47040), + mapOf(x to 5u, y to 4u) to Rational(-1189, 56), + mapOf(x to 6u, y to 4u) to Rational(-405, 196) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf( + y to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(14, 4), + mapOf(x to 1u) to Rational(7, 6), + mapOf(x to 2u) to Rational(7, 2), + mapOf(y to 1u) to Rational(-15, 2), + mapOf(x to 1u, y to 1u) to Rational(-13, 8), + mapOf(x to 2u, y to 1u) to Rational(-14, 3), + mapOf(y to 2u) to Rational(-7, 6), + mapOf(x to 1u, y to 2u) to Rational(7, 4), + mapOf(x to 2u, y to 2u) to Rational(9, 7), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-7, 4), + mapOf(x to 1u) to Rational(-6, 3), + mapOf(x to 2u) to Rational(-16, 2), + mapOf(y to 1u) to Rational(-15, 5), + mapOf(x to 1u, y to 1u) to Rational(4, 6), + mapOf(x to 2u, y to 1u) to Rational(5, 4), + mapOf(y to 2u) to Rational(-12, 5), + mapOf(x to 1u, y to 2u) to Rational(-18, 2), + mapOf(x to 2u, y to 2u) to Rational(6, 7), + ) + ), + iota to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 8), + mapOf(x to 1u) to Rational(-12, 6), + mapOf(x to 2u) to Rational(7, 6), + mapOf(y to 1u) to Rational(-10, 4), + mapOf(x to 1u, y to 1u) to Rational(-7, 6), + mapOf(x to 2u, y to 1u) to Rational(8, 9), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-13, 4), + mapOf(x to 2u, y to 2u) to Rational(5, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(10, 6), + mapOf(x to 1u) to Rational(-18, 6), + mapOf(x to 2u) to Rational(5, 1), + mapOf(y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(8, 4), + mapOf(x to 2u, y to 1u) to Rational(-4, 9), + mapOf(y to 2u) to Rational(-6, 5), + mapOf(x to 1u, y to 2u) to Rational(-15, 8), + mapOf(x to 2u, y to 2u) to Rational(-18, 5), + ) + ), + )), + "test 4'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-506213, 2800), + mapOf(x to 1u) to Rational(9859, 315), + mapOf(x to 2u) to Rational(17384377, 11340), + mapOf(x to 3u) to Rational(-9662, 63), + mapOf(x to 4u) to Rational(-12563, 4), + mapOf(y to 1u) to Rational(-486293, 22400), + mapOf(x to 1u, y to 1u) to Rational(-6530947, 25200), + mapOf(x to 2u, y to 1u) to Rational(866125, 18144), + mapOf(x to 3u, y to 1u) to Rational(2948747, 2520), + mapOf(x to 4u, y to 1u) to Rational(1196611, 2016), + mapOf(y to 2u) to Rational(-20266021, 117600), + mapOf(x to 1u, y to 2u) to Rational(26656339, 44100), + mapOf(x to 2u, y to 2u) to Rational(19499183, 18144), + mapOf(x to 3u, y to 2u) to Rational(-19801849, 7560), + mapOf(x to 4u, y to 2u) to Rational(-2639635, 1296), + mapOf(y to 3u) to Rational(-5017697, 29400), + mapOf(x to 1u, y to 3u) to Rational(-606007, 1575), + mapOf(x to 2u, y to 3u) to Rational(127494487, 132300), + mapOf(x to 3u, y to 3u) to Rational(166567, 105), + mapOf(x to 4u, y to 3u) to Rational(486403, 18144), + mapOf(y to 4u) to Rational(-32182, 735), + mapOf(x to 1u, y to 4u) to Rational(2420671, 8820), + mapOf(x to 2u, y to 4u) to Rational(-12619193, 26460), + mapOf(x to 3u, y to 4u) to Rational(-6823067, 5670), + mapOf(x to 4u, y to 4u) to Rational(-2311693, 13608), + mapOf(y to 5u) to Rational(-13324, 245), + mapOf(x to 1u, y to 5u) to Rational(1966, 35), + mapOf(x to 2u, y to 5u) to Rational(1052719, 2520), + mapOf(x to 3u, y to 5u) to Rational(19153, 270), + mapOf(x to 4u, y to 5u) to Rational(701, 54), + mapOf(y to 6u) to Rational(4647, 196), + mapOf(x to 1u, y to 6u) to Rational(2197, 28), + mapOf(x to 2u, y to 6u) to Rational(-43853, 336), + mapOf(x to 3u, y to 6u) to Rational(-301, 3), + mapOf(x to 4u, y to 6u) to Rational(34, 3) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-2843, 1600), + mapOf(x to 1u) to Rational(-1483, 240), + mapOf(x to 2u) to Rational(110623, 1296), + mapOf(x to 3u) to Rational(1265, 72), + mapOf(x to 4u) to Rational(-5011, 16), + mapOf(y to 1u) to Rational(47743, 1800), + mapOf(x to 1u, y to 1u) to Rational(619229, 32400), + mapOf(x to 2u, y to 1u) to Rational(-5978369, 58320), + mapOf(x to 3u, y to 1u) to Rational(-86081, 1620), + mapOf(x to 4u, y to 1u) to Rational(6325, 72), + mapOf(y to 2u) to Rational(110951, 3360), + mapOf(x to 1u, y to 2u) to Rational(-9550649, 302400), + mapOf(x to 2u, y to 2u) to Rational(6542933, 85050), + mapOf(x to 3u, y to 2u) to Rational(4708291, 38880), + mapOf(x to 4u, y to 2u) to Rational(-433327, 1296), + mapOf(y to 3u) to Rational(56143, 600), + mapOf(x to 1u, y to 3u) to Rational(94243, 720), + mapOf(x to 2u, y to 3u) to Rational(-46779139, 226800), + mapOf(x to 3u, y to 3u) to Rational(-6948253, 12960), + mapOf(x to 4u, y to 3u) to Rational(-260261, 486), + mapOf(y to 4u) to Rational(-3205317, 19600), + mapOf(x to 1u, y to 4u) to Rational(-201253, 1050), + mapOf(x to 2u, y to 4u) to Rational(332192677, 302400), + mapOf(x to 3u, y to 4u) to Rational(351511, 360), + mapOf(x to 4u, y to 4u) to Rational(-40547, 81), + mapOf(y to 5u) to Rational(-65421, 1960), + mapOf(x to 1u, y to 5u) to Rational(-10118, 35), + mapOf(x to 2u, y to 5u) to Rational(-4341709, 10080), + mapOf(x to 3u, y to 5u) to Rational(-91703, 360), + mapOf(x to 4u, y to 5u) to Rational(-85, 9), + mapOf(y to 6u) to Rational(-25965, 784), + mapOf(x to 1u, y to 6u) to Rational(3351, 16), + mapOf(x to 2u, y to 6u) to Rational(595159, 1344), + mapOf(x to 3u, y to 6u) to Rational(-1381, 12), + mapOf(x to 4u, y to 6u) to Rational(-155, 3) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-17, 5), + mapOf(x to 1u) to Rational(2, 6), + mapOf(x to 2u) to Rational(14, 1), + mapOf(y to 1u) to Rational(-6, 6), + mapOf(x to 1u, y to 1u) to Rational(-7, 3), + mapOf(x to 2u, y to 1u) to Rational(-2, 9), + mapOf(y to 2u) to Rational(-9, 6), + mapOf(x to 1u, y to 2u) to Rational(17, 4), + mapOf(x to 2u, y to 2u) to Rational(2, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(5, 4), + mapOf(x to 1u) to Rational(-5, 9), + mapOf(x to 2u) to Rational(-3, 6), + mapOf(y to 1u) to Rational(6, 5), + mapOf(x to 1u, y to 1u) to Rational(14, 5), + mapOf(x to 2u, y to 1u) to Rational(5, 2), + mapOf(y to 2u) to Rational(-18, 7), + mapOf(x to 1u, y to 2u) to Rational(-8, 2), + mapOf(x to 2u, y to 2u) to Rational(18, 9), + ) + ), + )), + "test 5" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-506213, 2800), + mapOf(x to 1u) to Rational(9859, 315), + mapOf(x to 2u) to Rational(17384377, 11340), + mapOf(x to 3u) to Rational(-9662, 63), + mapOf(x to 4u) to Rational(-12563, 4), + mapOf(y to 1u) to Rational(-486293, 22400), + mapOf(x to 1u, y to 1u) to Rational(-6530947, 25200), + mapOf(x to 2u, y to 1u) to Rational(866125, 18144), + mapOf(x to 3u, y to 1u) to Rational(2948747, 2520), + mapOf(x to 4u, y to 1u) to Rational(1196611, 2016), + mapOf(y to 2u) to Rational(-20266021, 117600), + mapOf(x to 1u, y to 2u) to Rational(26656339, 44100), + mapOf(x to 2u, y to 2u) to Rational(19499183, 18144), + mapOf(x to 3u, y to 2u) to Rational(-19801849, 7560), + mapOf(x to 4u, y to 2u) to Rational(-2639635, 1296), + mapOf(y to 3u) to Rational(-5017697, 29400), + mapOf(x to 1u, y to 3u) to Rational(-606007, 1575), + mapOf(x to 2u, y to 3u) to Rational(127494487, 132300), + mapOf(x to 3u, y to 3u) to Rational(166567, 105), + mapOf(x to 4u, y to 3u) to Rational(486403, 18144), + mapOf(y to 4u) to Rational(-32182, 735), + mapOf(x to 1u, y to 4u) to Rational(2420671, 8820), + mapOf(x to 2u, y to 4u) to Rational(-12619193, 26460), + mapOf(x to 3u, y to 4u) to Rational(-6823067, 5670), + mapOf(x to 4u, y to 4u) to Rational(-2311693, 13608), + mapOf(y to 5u) to Rational(-13324, 245), + mapOf(x to 1u, y to 5u) to Rational(1966, 35), + mapOf(x to 2u, y to 5u) to Rational(1052719, 2520), + mapOf(x to 3u, y to 5u) to Rational(19153, 270), + mapOf(x to 4u, y to 5u) to Rational(701, 54), + mapOf(y to 6u) to Rational(4647, 196), + mapOf(x to 1u, y to 6u) to Rational(2197, 28), + mapOf(x to 2u, y to 6u) to Rational(-43853, 336), + mapOf(x to 3u, y to 6u) to Rational(-301, 3), + mapOf(x to 4u, y to 6u) to Rational(34, 3) + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-2843, 1600), + mapOf(x to 1u) to Rational(-1483, 240), + mapOf(x to 2u) to Rational(110623, 1296), + mapOf(x to 3u) to Rational(1265, 72), + mapOf(x to 4u) to Rational(-5011, 16), + mapOf(y to 1u) to Rational(47743, 1800), + mapOf(x to 1u, y to 1u) to Rational(619229, 32400), + mapOf(x to 2u, y to 1u) to Rational(-5978369, 58320), + mapOf(x to 3u, y to 1u) to Rational(-86081, 1620), + mapOf(x to 4u, y to 1u) to Rational(6325, 72), + mapOf(y to 2u) to Rational(110951, 3360), + mapOf(x to 1u, y to 2u) to Rational(-9550649, 302400), + mapOf(x to 2u, y to 2u) to Rational(6542933, 85050), + mapOf(x to 3u, y to 2u) to Rational(4708291, 38880), + mapOf(x to 4u, y to 2u) to Rational(-433327, 1296), + mapOf(y to 3u) to Rational(56143, 600), + mapOf(x to 1u, y to 3u) to Rational(94243, 720), + mapOf(x to 2u, y to 3u) to Rational(-46779139, 226800), + mapOf(x to 3u, y to 3u) to Rational(-6948253, 12960), + mapOf(x to 4u, y to 3u) to Rational(-260261, 486), + mapOf(y to 4u) to Rational(-3205317, 19600), + mapOf(x to 1u, y to 4u) to Rational(-201253, 1050), + mapOf(x to 2u, y to 4u) to Rational(332192677, 302400), + mapOf(x to 3u, y to 4u) to Rational(351511, 360), + mapOf(x to 4u, y to 4u) to Rational(-40547, 81), + mapOf(y to 5u) to Rational(-65421, 1960), + mapOf(x to 1u, y to 5u) to Rational(-10118, 35), + mapOf(x to 2u, y to 5u) to Rational(-4341709, 10080), + mapOf(x to 3u, y to 5u) to Rational(-91703, 360), + mapOf(x to 4u, y to 5u) to Rational(-85, 9), + mapOf(y to 6u) to Rational(-25965, 784), + mapOf(x to 1u, y to 6u) to Rational(3351, 16), + mapOf(x to 2u, y to 6u) to Rational(595159, 1344), + mapOf(x to 3u, y to 6u) to Rational(-1381, 12), + mapOf(x to 4u, y to 6u) to Rational(-155, 3) + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf( + x to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(-17, 5), + mapOf(x to 1u) to Rational(2, 6), + mapOf(x to 2u) to Rational(14, 1), + mapOf(y to 1u) to Rational(-6, 6), + mapOf(x to 1u, y to 1u) to Rational(-7, 3), + mapOf(x to 2u, y to 1u) to Rational(-2, 9), + mapOf(y to 2u) to Rational(-9, 6), + mapOf(x to 1u, y to 2u) to Rational(17, 4), + mapOf(x to 2u, y to 2u) to Rational(2, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(5, 4), + mapOf(x to 1u) to Rational(-5, 9), + mapOf(x to 2u) to Rational(-3, 6), + mapOf(y to 1u) to Rational(6, 5), + mapOf(x to 1u, y to 1u) to Rational(14, 5), + mapOf(x to 2u, y to 1u) to Rational(5, 2), + mapOf(y to 2u) to Rational(-18, 7), + mapOf(x to 1u, y to 2u) to Rational(-8, 2), + mapOf(x to 2u, y to 2u) to Rational(18, 9), + ) + ), + iota to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 8), + mapOf(x to 1u) to Rational(-12, 6), + mapOf(x to 2u) to Rational(7, 6), + mapOf(y to 1u) to Rational(-10, 4), + mapOf(x to 1u, y to 1u) to Rational(-7, 6), + mapOf(x to 2u, y to 1u) to Rational(8, 9), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-13, 4), + mapOf(x to 2u, y to 2u) to Rational(5, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(10, 6), + mapOf(x to 1u) to Rational(-18, 6), + mapOf(x to 2u) to Rational(5, 1), + mapOf(y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(8, 4), + mapOf(x to 2u, y to 1u) to Rational(-4, 9), + mapOf(y to 2u) to Rational(-6, 5), + mapOf(x to 1u, y to 2u) to Rational(-15, 8), + mapOf(x to 2u, y to 2u) to Rational(-18, 5), + ) + ), + )), + "test 5'" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf>()), + "test 6" + ) + assertEquals( + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ), + LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(10, 2), + mapOf(x to 1u) to Rational(6, 7), + mapOf(x to 2u) to Rational(-16, 1), + mapOf(y to 1u) to Rational(13, 8), + mapOf(x to 1u, y to 1u) to Rational(-12, 1), + mapOf(x to 2u, y to 1u) to Rational(16, 8), + mapOf(y to 2u) to Rational(10, 4), + mapOf(x to 1u, y to 2u) to Rational(4, 1), + mapOf(x to 2u, y to 2u) to Rational(-11, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1, 4), + mapOf(x to 1u) to Rational(-17, 4), + mapOf(x to 2u) to Rational(-14, 8), + mapOf(y to 1u) to Rational(17, 9), + mapOf(x to 1u, y to 1u) to Rational(1, 3), + mapOf(x to 2u, y to 1u) to Rational(7, 6), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-17, 1), + mapOf(x to 2u, y to 2u) to Rational(-10, 8), + ) + ).substitute(RationalField, mapOf( + iota to LabeledRationalFunction( + LabeledPolynomialAsIs( + mapOf() to Rational(5, 8), + mapOf(x to 1u) to Rational(-12, 6), + mapOf(x to 2u) to Rational(7, 6), + mapOf(y to 1u) to Rational(-10, 4), + mapOf(x to 1u, y to 1u) to Rational(-7, 6), + mapOf(x to 2u, y to 1u) to Rational(8, 9), + mapOf(y to 2u) to Rational(16, 3), + mapOf(x to 1u, y to 2u) to Rational(-13, 4), + mapOf(x to 2u, y to 2u) to Rational(5, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(10, 6), + mapOf(x to 1u) to Rational(-18, 6), + mapOf(x to 2u) to Rational(5, 1), + mapOf(y to 1u) to Rational(17, 7), + mapOf(x to 1u, y to 1u) to Rational(8, 4), + mapOf(x to 2u, y to 1u) to Rational(-4, 9), + mapOf(y to 2u) to Rational(-6, 5), + mapOf(x to 1u, y to 2u) to Rational(-15, 8), + mapOf(x to 2u, y to 2u) to Rational(-18, 5), + ) + ), + )), + "test 6'" + ) + } + @Test + @OptIn(UnstableKMathAPI::class) + fun test_Polynomial_derivativeWithRespectTo_variable() { + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-2), + mapOf(x to 1u) to Rational(2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).derivativeWithRespectTo(RationalField, x), + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-2, 3), + mapOf(x to 1u) to Rational(1, 1), + mapOf(x to 2u) to Rational(-33, 8), + mapOf(x to 3u) to Rational(72, 1), + mapOf(y to 1u) to Rational(2, 3), + mapOf(x to 1u, y to 1u) to Rational(-22, 1), + mapOf(x to 2u, y to 1u) to Rational(-1, 1), + mapOf(x to 3u, y to 1u) to Rational(-36, 1), + mapOf(y to 2u) to Rational(-8, 5), + mapOf(x to 1u, y to 2u) to Rational(-1, 4), + mapOf(x to 2u, y to 2u) to Rational(12, 7), + mapOf(x to 3u, y to 2u) to Rational(-2, 1), + mapOf(y to 3u) to Rational(16, 8), + mapOf(x to 1u, y to 3u) to Rational(-4, 1), + mapOf(x to 2u, y to 3u) to Rational(9, 2), + mapOf(x to 3u, y to 3u) to Rational(20, 9), + mapOf(y to 4u) to Rational(-10, 1), + mapOf(x to 1u, y to 4u) to Rational(-14, 1), + mapOf(x to 2u, y to 4u) to Rational(3, 7), + mapOf(x to 3u, y to 4u) to Rational(20, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).derivativeWithRespectTo(RationalField, x), + "test 2a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-18, 3), + mapOf(x to 1u) to Rational(2, 3), + mapOf(x to 2u) to Rational(-11, 1), + mapOf(x to 3u) to Rational(-1, 3), + mapOf(x to 4u) to Rational(-18, 2), + mapOf(y to 1u) to Rational(-20, 3), + mapOf(x to 1u, y to 1u) to Rational(-16, 5), + mapOf(x to 2u, y to 1u) to Rational(-1, 4), + mapOf(x to 3u, y to 1u) to Rational(8, 7), + mapOf(x to 4u, y to 1u) to Rational(-1, 1), + mapOf(y to 2u) to Rational(9, 7), + mapOf(x to 1u, y to 2u) to Rational(6, 1), + mapOf(x to 2u, y to 2u) to Rational(-6, 1), + mapOf(x to 3u, y to 2u) to Rational(9, 2), + mapOf(x to 4u, y to 2u) to Rational(5, 3), + mapOf(y to 3u) to Rational(-9, 1), + mapOf(x to 1u, y to 3u) to Rational(-40, 1), + mapOf(x to 2u, y to 3u) to Rational(-28, 1), + mapOf(x to 3u, y to 3u) to Rational(4, 7), + mapOf(x to 4u, y to 3u) to Rational(20, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).derivativeWithRespectTo(RationalField, y), + "test 2b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(-1, 4), + mapOf(x to 2u, y to 2u) to Rational(12, 7), + mapOf(x to 3u, y to 2u) to Rational(-2, 1), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(-4, 1), + mapOf(x to 2u, y to 3u) to Rational(9, 2), + mapOf(x to 3u, y to 3u) to Rational(20, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(-14, 1), + mapOf(x to 2u, y to 4u) to Rational(3, 7), + mapOf(x to 3u, y to 4u) to Rational(20, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).derivativeWithRespectTo(RationalField, x), + "test 3a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(-1, 4), + mapOf(x to 3u, y to 1u) to Rational(8, 7), + mapOf(x to 4u, y to 1u) to Rational(-1, 1), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-6, 1), + mapOf(x to 3u, y to 2u) to Rational(9, 2), + mapOf(x to 4u, y to 2u) to Rational(5, 3), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-28, 1), + mapOf(x to 3u, y to 3u) to Rational(4, 7), + mapOf(x to 4u, y to 3u) to Rational(20, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).derivativeWithRespectTo(RationalField, y), + "test 3b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-2, 3), + mapOf(x to 1u) to Rational(1, 1), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(y to 1u) to Rational(2, 3), + mapOf(x to 1u, y to 1u) to Rational(-22, 1), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-8, 5), + mapOf(x to 1u, y to 2u) to Rational(-1, 4), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).derivativeWithRespectTo(RationalField, x), + "test 4a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-18, 3), + mapOf(x to 1u) to Rational(2, 3), + mapOf(x to 2u) to Rational(-11, 1), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-20, 3), + mapOf(x to 1u, y to 1u) to Rational(-16, 5), + mapOf(x to 2u, y to 1u) to Rational(-1, 4), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).derivativeWithRespectTo(RationalField, y), + "test 4b" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).derivativeWithRespectTo(RationalField, iota), + "test 5" + ) + } + @Test + @OptIn(UnstableKMathAPI::class) + fun test_Polynomial_nthDerivativeWithRespectTo_variable_order() { + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-2), + mapOf(x to 1u) to Rational(2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, x, 1u), + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, x, 0u), + "test 2" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, x, 2u), + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, x, 3u), + "test 4" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, x, 4u), + "test 5" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, y, 0u), + "test 6" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, y, 1u), + "test 7" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, y, 2u), + "test 8" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1, 1), + mapOf(x to 1u) to Rational(-33, 4), + mapOf(x to 2u) to Rational(216, 1), + mapOf(y to 1u) to Rational(-22, 1), + mapOf(x to 1u, y to 1u) to Rational(-2, 1), + mapOf(x to 2u, y to 1u) to Rational(-108, 1), + mapOf(y to 2u) to Rational(-1, 4), + mapOf(x to 1u, y to 2u) to Rational(24, 7), + mapOf(x to 2u, y to 2u) to Rational(-6, 1), + mapOf(y to 3u) to Rational(-4, 1), + mapOf(x to 1u, y to 3u) to Rational(9, 1), + mapOf(x to 2u, y to 3u) to Rational(20, 3), + mapOf(y to 4u) to Rational(-14, 1), + mapOf(x to 1u, y to 4u) to Rational(6, 7), + mapOf(x to 2u, y to 4u) to Rational(60, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, x, 2u), + "test 9a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-20, 3), + mapOf(x to 1u) to Rational(-16, 5), + mapOf(x to 2u) to Rational(-1, 4), + mapOf(x to 3u) to Rational(8, 7), + mapOf(x to 4u) to Rational(-1, 1), + mapOf(y to 1u) to Rational(18, 7), + mapOf(x to 1u, y to 1u) to Rational(12, 1), + mapOf(x to 2u, y to 1u) to Rational(-12, 1), + mapOf(x to 3u, y to 1u) to Rational(9, 1), + mapOf(x to 4u, y to 1u) to Rational(10, 3), + mapOf(y to 2u) to Rational(-27, 1), + mapOf(x to 1u, y to 2u) to Rational(-120, 1), + mapOf(x to 2u, y to 2u) to Rational(-84, 1), + mapOf(x to 3u, y to 2u) to Rational(12, 7), + mapOf(x to 4u, y to 2u) to Rational(60, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, y, 2u), + "test 9b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-1, 4), + mapOf(x to 1u, y to 2u) to Rational(24, 7), + mapOf(x to 2u, y to 2u) to Rational(-6, 1), + mapOf(y to 3u) to Rational(-4, 1), + mapOf(x to 1u, y to 3u) to Rational(9, 1), + mapOf(x to 2u, y to 3u) to Rational(20, 3), + mapOf(y to 4u) to Rational(-14, 1), + mapOf(x to 1u, y to 4u) to Rational(6, 7), + mapOf(x to 2u, y to 4u) to Rational(60, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, x, 2u), + "test 10a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(-1, 4), + mapOf(x to 3u) to Rational(8, 7), + mapOf(x to 4u) to Rational(-1, 1), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(-12, 1), + mapOf(x to 3u, y to 1u) to Rational(9, 1), + mapOf(x to 4u, y to 1u) to Rational(10, 3), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-84, 1), + mapOf(x to 3u, y to 2u) to Rational(12, 7), + mapOf(x to 4u, y to 2u) to Rational(60, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, y, 2u), + "test 10b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1, 1), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(y to 1u) to Rational(-22, 1), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-1, 4), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthDerivativeWithRespectTo(RationalField, x, 2u), + "test 11a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-20, 3), + mapOf(x to 1u) to Rational(-16, 5), + mapOf(x to 2u) to Rational(-1, 4), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthDerivativeWithRespectTo(RationalField, y, 2u), + "test 11b" + ) + } + @Test + @OptIn(UnstableKMathAPI::class) + fun test_Polynomial_nthDerivativeWithRespectTo_variablesAndOrders() { + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-2), + mapOf(x to 1u) to Rational(2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 1u)), + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 0u)), + "test 2" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 2u)), + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 3u)), + "test 4" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 4u)), + "test 5" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf(y to 0u)), + "test 6" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf(y to 1u)), + "test 7" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf(y to 2u)), + "test 8" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf()), + "test 9" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-2), + mapOf(x to 1u) to Rational(2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf( + x to 1u, + y to 0u + )), + "test 10" + ) + assertEquals( + LabeledPolynomialAsIs(), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthDerivativeWithRespectTo(RationalField, mapOf( + x to 0u, + y to 1u + )), + "test 11" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1, 1), + mapOf(x to 1u) to Rational(-33, 4), + mapOf(x to 2u) to Rational(216, 1), + mapOf(y to 1u) to Rational(-22, 1), + mapOf(x to 1u, y to 1u) to Rational(-2, 1), + mapOf(x to 2u, y to 1u) to Rational(-108, 1), + mapOf(y to 2u) to Rational(-1, 4), + mapOf(x to 1u, y to 2u) to Rational(24, 7), + mapOf(x to 2u, y to 2u) to Rational(-6, 1), + mapOf(y to 3u) to Rational(-4, 1), + mapOf(x to 1u, y to 3u) to Rational(9, 1), + mapOf(x to 2u, y to 3u) to Rational(20, 3), + mapOf(y to 4u) to Rational(-14, 1), + mapOf(x to 1u, y to 4u) to Rational(6, 7), + mapOf(x to 2u, y to 4u) to Rational(60, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 2u)), + "test 12a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(2, 3), + mapOf(x to 1u) to Rational(-22, 1), + mapOf(x to 2u) to Rational(-1, 1), + mapOf(x to 3u) to Rational(-36, 1), + mapOf(y to 1u) to Rational(-16, 5), + mapOf(x to 1u, y to 1u) to Rational(-1, 2), + mapOf(x to 2u, y to 1u) to Rational(24, 7), + mapOf(x to 3u, y to 1u) to Rational(-4, 1), + mapOf(y to 2u) to Rational(6, 1), + mapOf(x to 1u, y to 2u) to Rational(-12, 1), + mapOf(x to 2u, y to 2u) to Rational(27, 2), + mapOf(x to 3u, y to 2u) to Rational(20, 3), + mapOf(y to 3u) to Rational(-40, 1), + mapOf(x to 1u, y to 3u) to Rational(-56, 1), + mapOf(x to 2u, y to 3u) to Rational(12, 7), + mapOf(x to 3u, y to 3u) to Rational(80, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 1u, y to 1u)), + "test 12b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-20, 3), + mapOf(x to 1u) to Rational(-16, 5), + mapOf(x to 2u) to Rational(-1, 4), + mapOf(x to 3u) to Rational(8, 7), + mapOf(x to 4u) to Rational(-1, 1), + mapOf(y to 1u) to Rational(18, 7), + mapOf(x to 1u, y to 1u) to Rational(12, 1), + mapOf(x to 2u, y to 1u) to Rational(-12, 1), + mapOf(x to 3u, y to 1u) to Rational(9, 1), + mapOf(x to 4u, y to 1u) to Rational(10, 3), + mapOf(y to 2u) to Rational(-27, 1), + mapOf(x to 1u, y to 2u) to Rational(-120, 1), + mapOf(x to 2u, y to 2u) to Rational(-84, 1), + mapOf(x to 3u, y to 2u) to Rational(12, 7), + mapOf(x to 4u, y to 2u) to Rational(60, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, mapOf(y to 2u)), + "test 12c" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-1, 4), + mapOf(x to 1u, y to 2u) to Rational(24, 7), + mapOf(x to 2u, y to 2u) to Rational(-6, 1), + mapOf(y to 3u) to Rational(-4, 1), + mapOf(x to 1u, y to 3u) to Rational(9, 1), + mapOf(x to 2u, y to 3u) to Rational(20, 3), + mapOf(y to 4u) to Rational(-14, 1), + mapOf(x to 1u, y to 4u) to Rational(6, 7), + mapOf(x to 2u, y to 4u) to Rational(60, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 2u)), + "test 13a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(-1, 2), + mapOf(x to 2u, y to 1u) to Rational(24, 7), + mapOf(x to 3u, y to 1u) to Rational(-4, 1), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(-12, 1), + mapOf(x to 2u, y to 2u) to Rational(27, 2), + mapOf(x to 3u, y to 2u) to Rational(20, 3), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(-56, 1), + mapOf(x to 2u, y to 3u) to Rational(12, 7), + mapOf(x to 3u, y to 3u) to Rational(80, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 1u, y to 1u)), + "test 13b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(-1, 4), + mapOf(x to 3u) to Rational(8, 7), + mapOf(x to 4u) to Rational(-1, 1), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(-12, 1), + mapOf(x to 3u, y to 1u) to Rational(9, 1), + mapOf(x to 4u, y to 1u) to Rational(10, 3), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-84, 1), + mapOf(x to 3u, y to 2u) to Rational(12, 7), + mapOf(x to 4u, y to 2u) to Rational(60, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthDerivativeWithRespectTo(RationalField, mapOf(y to 2u)), + "test 13c" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1, 1), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(y to 1u) to Rational(-22, 1), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-1, 4), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 2u)), + "test 14a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(2, 3), + mapOf(x to 1u) to Rational(-22, 1), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(y to 1u) to Rational(-16, 5), + mapOf(x to 1u, y to 1u) to Rational(-1, 2), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthDerivativeWithRespectTo(RationalField, mapOf(x to 1u, y to 1u)), + "test 14b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(-20, 3), + mapOf(x to 1u) to Rational(-16, 5), + mapOf(x to 2u) to Rational(-1, 4), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthDerivativeWithRespectTo(RationalField, mapOf(y to 2u)), + "test 14c" + ) + } + @Test + @OptIn(UnstableKMathAPI::class) + fun test_Polynomial_antiderivativeWithRespectTo_variable() { + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(1), + mapOf(x to 2u) to Rational(-1), + mapOf(x to 3u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).antiderivativeWithRespectTo(RationalField, x), + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(-6, 8), + mapOf(x to 2u) to Rational(-1, 3), + mapOf(x to 3u) to Rational(1, 6), + mapOf(x to 4u) to Rational(-11, 32), + mapOf(x to 5u) to Rational(18, 5), + mapOf(x to 1u, y to 1u) to Rational(-18, 3), + mapOf(x to 2u, y to 1u) to Rational(1, 3), + mapOf(x to 3u, y to 1u) to Rational(-11, 3), + mapOf(x to 4u, y to 1u) to Rational(-1, 12), + mapOf(x to 5u, y to 1u) to Rational(-18, 10), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(-4, 5), + mapOf(x to 3u, y to 2u) to Rational(-1, 24), + mapOf(x to 4u, y to 2u) to Rational(1, 7), + mapOf(x to 5u, y to 2u) to Rational(-1, 10), + mapOf(x to 1u, y to 3u) to Rational(3, 7), + mapOf(x to 2u, y to 3u) to Rational(1, 1), + mapOf(x to 3u, y to 3u) to Rational(-2, 3), + mapOf(x to 4u, y to 3u) to Rational(3, 8), + mapOf(x to 5u, y to 3u) to Rational(1, 9), + mapOf(x to 1u, y to 4u) to Rational(-18, 8), + mapOf(x to 2u, y to 4u) to Rational(-5, 1), + mapOf(x to 3u, y to 4u) to Rational(-7, 3), + mapOf(x to 4u, y to 4u) to Rational(1, 28), + mapOf(x to 5u, y to 4u) to Rational(1, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).antiderivativeWithRespectTo(RationalField, x), + "test 2a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 1u) to Rational(-6, 8), + mapOf(x to 1u, y to 1u) to Rational(-2, 3), + mapOf(x to 2u, y to 1u) to Rational(1, 2), + mapOf(x to 3u, y to 1u) to Rational(-11, 8), + mapOf(x to 4u, y to 1u) to Rational(18, 1), + mapOf(y to 2u) to Rational(-9, 3), + mapOf(x to 1u, y to 2u) to Rational(1, 3), + mapOf(x to 2u, y to 2u) to Rational(-11, 2), + mapOf(x to 3u, y to 2u) to Rational(-1, 6), + mapOf(x to 4u, y to 2u) to Rational(-9, 2), + mapOf(y to 3u) to Rational(-10, 9), + mapOf(x to 1u, y to 3u) to Rational(-8, 15), + mapOf(x to 2u, y to 3u) to Rational(-1, 24), + mapOf(x to 3u, y to 3u) to Rational(4, 21), + mapOf(x to 4u, y to 3u) to Rational(-1, 6), + mapOf(y to 4u) to Rational(3, 28), + mapOf(x to 1u, y to 4u) to Rational(1, 2), + mapOf(x to 2u, y to 4u) to Rational(-1, 2), + mapOf(x to 3u, y to 4u) to Rational(3, 8), + mapOf(x to 4u, y to 4u) to Rational(5, 36), + mapOf(y to 5u) to Rational(-9, 20), + mapOf(x to 1u, y to 5u) to Rational(-2, 1), + mapOf(x to 2u, y to 5u) to Rational(-7, 5), + mapOf(x to 3u, y to 5u) to Rational(1, 35), + mapOf(x to 4u, y to 5u) to Rational(1, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).antiderivativeWithRespectTo(RationalField, y), + "test 2b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(x to 5u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(x to 5u, y to 1u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(-1, 24), + mapOf(x to 4u, y to 2u) to Rational(1, 7), + mapOf(x to 5u, y to 2u) to Rational(-1, 10), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(-2, 3), + mapOf(x to 4u, y to 3u) to Rational(3, 8), + mapOf(x to 5u, y to 3u) to Rational(1, 9), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(-7, 3), + mapOf(x to 4u, y to 4u) to Rational(1, 28), + mapOf(x to 5u, y to 4u) to Rational(1, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).antiderivativeWithRespectTo(RationalField, x), + "test 3a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-1, 24), + mapOf(x to 3u, y to 3u) to Rational(4, 21), + mapOf(x to 4u, y to 3u) to Rational(-1, 6), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-1, 2), + mapOf(x to 3u, y to 4u) to Rational(3, 8), + mapOf(x to 4u, y to 4u) to Rational(5, 36), + mapOf(y to 5u) to Rational(0), + mapOf(x to 1u, y to 5u) to Rational(0), + mapOf(x to 2u, y to 5u) to Rational(-7, 5), + mapOf(x to 3u, y to 5u) to Rational(1, 35), + mapOf(x to 4u, y to 5u) to Rational(1, 1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).antiderivativeWithRespectTo(RationalField, y), + "test 3b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(-6, 8), + mapOf(x to 2u) to Rational(-1, 3), + mapOf(x to 3u) to Rational(1, 6), + mapOf(x to 4u) to Rational(0), + mapOf(x to 5u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(-18, 3), + mapOf(x to 2u, y to 1u) to Rational(1, 3), + mapOf(x to 3u, y to 1u) to Rational(-11, 3), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(x to 5u, y to 1u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(-10, 3), + mapOf(x to 2u, y to 2u) to Rational(-4, 5), + mapOf(x to 3u, y to 2u) to Rational(-1, 24), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(x to 5u, y to 2u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(x to 5u, y to 3u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + mapOf(x to 5u, y to 4u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).antiderivativeWithRespectTo(RationalField, x), + "test 4a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 1u) to Rational(-6, 8), + mapOf(x to 1u, y to 1u) to Rational(-2, 3), + mapOf(x to 2u, y to 1u) to Rational(1, 2), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-9, 3), + mapOf(x to 1u, y to 2u) to Rational(1, 3), + mapOf(x to 2u, y to 2u) to Rational(-11, 2), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(-10, 9), + mapOf(x to 1u, y to 3u) to Rational(-8, 15), + mapOf(x to 2u, y to 3u) to Rational(-1, 24), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + mapOf(y to 5u) to Rational(0), + mapOf(x to 1u, y to 5u) to Rational(0), + mapOf(x to 2u, y to 5u) to Rational(0), + mapOf(x to 3u, y to 5u) to Rational(0), + mapOf(x to 4u, y to 5u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).antiderivativeWithRespectTo(RationalField, y), + "test 4b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(iota to 1u) to Rational(-6, 8), + mapOf(x to 1u, iota to 1u) to Rational(-2, 3), + mapOf(x to 2u, iota to 1u) to Rational(1, 2), + mapOf(x to 3u, iota to 1u) to Rational(-11, 8), + mapOf(x to 4u, iota to 1u) to Rational(18, 1), + mapOf(y to 1u, iota to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u, iota to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u, iota to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u, iota to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u, iota to 1u) to Rational(-18, 2), + mapOf(y to 2u, iota to 1u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u, iota to 1u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u, iota to 1u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u, iota to 1u) to Rational(4, 7), + mapOf(x to 4u, y to 2u, iota to 1u) to Rational(-4, 8), + mapOf(y to 3u, iota to 1u) to Rational(3, 7), + mapOf(x to 1u, y to 3u, iota to 1u) to Rational(16, 8), + mapOf(x to 2u, y to 3u, iota to 1u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u, iota to 1u) to Rational(12, 8), + mapOf(x to 4u, y to 3u, iota to 1u) to Rational(5, 9), + mapOf(y to 4u, iota to 1u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u, iota to 1u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u, iota to 1u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u, iota to 1u) to Rational(1, 7), + mapOf(x to 4u, y to 4u, iota to 1u) to Rational(15, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).antiderivativeWithRespectTo(RationalField, iota), + "test 5" + ) + } + @Test + @OptIn(UnstableKMathAPI::class) + fun test_Polynomial_nthAntiderivativeWithRespectTo_variable_order() { + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(1), + mapOf(x to 2u) to Rational(-1), + mapOf(x to 3u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 1u), + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 0u), + "test 2" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-1, 3), + mapOf(x to 4u) to Rational(1, 12), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 2u), + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 3u) to Rational(1, 6), + mapOf(x to 4u) to Rational(-1, 12), + mapOf(x to 5u) to Rational(1, 60), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 3u), + "test 4" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 4u) to Rational(1, 24), + mapOf(x to 5u) to Rational(-1, 60), + mapOf(x to 6u) to Rational(1, 360), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 4u), + "test 5" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, y, 0u), + "test 6" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 1u) to Rational(1), + mapOf(x to 1u, y to 1u) to Rational(-2), + mapOf(x to 2u, y to 1u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, y, 1u), + "test 7" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 2u) to Rational(1, 2), + mapOf(x to 1u, y to 2u) to Rational(-1), + mapOf(x to 2u, y to 2u) to Rational(1, 2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, y, 2u), + "test 8" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to Rational(-3, 8), + mapOf(x to 3u) to Rational(-1, 9), + mapOf(x to 4u) to Rational(1, 24), + mapOf(x to 5u) to Rational(-11, 160), + mapOf(x to 6u) to Rational(3, 5), + mapOf(x to 2u, y to 1u) to Rational(-9, 3), + mapOf(x to 3u, y to 1u) to Rational(1, 9), + mapOf(x to 4u, y to 1u) to Rational(-11, 12), + mapOf(x to 5u, y to 1u) to Rational(-1, 60), + mapOf(x to 6u, y to 1u) to Rational(-3, 10), + mapOf(x to 2u, y to 2u) to Rational(-5, 3), + mapOf(x to 3u, y to 2u) to Rational(-4, 15), + mapOf(x to 4u, y to 2u) to Rational(-1, 96), + mapOf(x to 5u, y to 2u) to Rational(1, 35), + mapOf(x to 6u, y to 2u) to Rational(-1, 60), + mapOf(x to 2u, y to 3u) to Rational(3, 14), + mapOf(x to 3u, y to 3u) to Rational(1, 3), + mapOf(x to 4u, y to 3u) to Rational(-1, 6), + mapOf(x to 5u, y to 3u) to Rational(3, 40), + mapOf(x to 6u, y to 3u) to Rational(1, 54), + mapOf(x to 2u, y to 4u) to Rational(-9, 8), + mapOf(x to 3u, y to 4u) to Rational(-5, 3), + mapOf(x to 4u, y to 4u) to Rational(-7, 12), + mapOf(x to 5u, y to 4u) to Rational(1, 140), + mapOf(x to 6u, y to 4u) to Rational(1, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, x, 2u), + "test 9a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 2u) to Rational(-3, 8), + mapOf(x to 1u, y to 2u) to Rational(-1, 3), + mapOf(x to 2u, y to 2u) to Rational(1, 4), + mapOf(x to 3u, y to 2u) to Rational(-11, 16), + mapOf(x to 4u, y to 2u) to Rational(9, 1), + mapOf(y to 3u) to Rational(-1, 1), + mapOf(x to 1u, y to 3u) to Rational(1, 9), + mapOf(x to 2u, y to 3u) to Rational(-11, 6), + mapOf(x to 3u, y to 3u) to Rational(-1, 18), + mapOf(x to 4u, y to 3u) to Rational(-9, 6), + mapOf(y to 4u) to Rational(-5, 18), + mapOf(x to 1u, y to 4u) to Rational(-2, 15), + mapOf(x to 2u, y to 4u) to Rational(-1, 96), + mapOf(x to 3u, y to 4u) to Rational(1, 21), + mapOf(x to 4u, y to 4u) to Rational(-1, 24), + mapOf(y to 5u) to Rational(3, 140), + mapOf(x to 1u, y to 5u) to Rational(1, 10), + mapOf(x to 2u, y to 5u) to Rational(-1, 10), + mapOf(x to 3u, y to 5u) to Rational(3, 40), + mapOf(x to 4u, y to 5u) to Rational(1, 36), + mapOf(y to 6u) to Rational(-3, 40), + mapOf(x to 1u, y to 6u) to Rational(-1, 3), + mapOf(x to 2u, y to 6u) to Rational(-7, 30), + mapOf(x to 3u, y to 6u) to Rational(1, 210), + mapOf(x to 4u, y to 6u) to Rational(1, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, y, 2u), + "test 9b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(x to 5u) to Rational(0), + mapOf(x to 6u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(x to 5u, y to 1u) to Rational(0), + mapOf(x to 6u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(-1, 96), + mapOf(x to 5u, y to 2u) to Rational(1, 35), + mapOf(x to 6u, y to 2u) to Rational(-1, 60), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(-1, 6), + mapOf(x to 5u, y to 3u) to Rational(3, 40), + mapOf(x to 6u, y to 3u) to Rational(1, 54), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(-7, 12), + mapOf(x to 5u, y to 4u) to Rational(1, 140), + mapOf(x to 6u, y to 4u) to Rational(1, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, x, 2u), + "test 10a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-1, 96), + mapOf(x to 3u, y to 4u) to Rational(1, 21), + mapOf(x to 4u, y to 4u) to Rational(-1, 24), + mapOf(y to 5u) to Rational(0), + mapOf(x to 1u, y to 5u) to Rational(0), + mapOf(x to 2u, y to 5u) to Rational(-1, 10), + mapOf(x to 3u, y to 5u) to Rational(3, 40), + mapOf(x to 4u, y to 5u) to Rational(1, 36), + mapOf(y to 6u) to Rational(0), + mapOf(x to 1u, y to 6u) to Rational(0), + mapOf(x to 2u, y to 6u) to Rational(-7, 30), + mapOf(x to 3u, y to 6u) to Rational(1, 210), + mapOf(x to 4u, y to 6u) to Rational(1, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, y, 2u), + "test 10b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to Rational(-3, 8), + mapOf(x to 3u) to Rational(-1, 9), + mapOf(x to 4u) to Rational(1, 24), + mapOf(x to 5u) to Rational(0), + mapOf(x to 6u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(-9, 3), + mapOf(x to 3u, y to 1u) to Rational(1, 9), + mapOf(x to 4u, y to 1u) to Rational(-11, 12), + mapOf(x to 5u, y to 1u) to Rational(0), + mapOf(x to 6u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-5, 3), + mapOf(x to 3u, y to 2u) to Rational(-4, 15), + mapOf(x to 4u, y to 2u) to Rational(-1, 96), + mapOf(x to 5u, y to 2u) to Rational(0), + mapOf(x to 6u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(x to 5u, y to 3u) to Rational(0), + mapOf(x to 6u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + mapOf(x to 5u, y to 4u) to Rational(0), + mapOf(x to 6u, y to 4u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthAntiderivativeWithRespectTo(RationalField, x, 2u), + "test 11a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 2u) to Rational(-3, 8), + mapOf(x to 1u, y to 2u) to Rational(-1, 3), + mapOf(x to 2u, y to 2u) to Rational(1, 4), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(-1, 1), + mapOf(x to 1u, y to 3u) to Rational(1, 9), + mapOf(x to 2u, y to 3u) to Rational(-11, 6), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(-5, 18), + mapOf(x to 1u, y to 4u) to Rational(-2, 15), + mapOf(x to 2u, y to 4u) to Rational(-1, 96), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + mapOf(y to 5u) to Rational(0), + mapOf(x to 1u, y to 5u) to Rational(0), + mapOf(x to 2u, y to 5u) to Rational(0), + mapOf(x to 3u, y to 5u) to Rational(0), + mapOf(x to 4u, y to 5u) to Rational(0), + mapOf(y to 6u) to Rational(0), + mapOf(x to 1u, y to 6u) to Rational(0), + mapOf(x to 2u, y to 6u) to Rational(0), + mapOf(x to 3u, y to 6u) to Rational(0), + mapOf(x to 4u, y to 6u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthAntiderivativeWithRespectTo(RationalField, y, 2u), + "test 11b" + ) + } + @Test + @OptIn(UnstableKMathAPI::class) + fun test_Polynomial_nthAntiderivativeWithRespectTo_variablesAndOrders() { + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(1), + mapOf(x to 2u) to Rational(-1), + mapOf(x to 3u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(x to 1u)), + "test 1" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 0u), + "test 2" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-1, 3), + mapOf(x to 4u) to Rational(1, 12), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 2u), + "test 3" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 3u) to Rational(1, 6), + mapOf(x to 4u) to Rational(-1, 12), + mapOf(x to 5u) to Rational(1, 60), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 3u), + "test 4" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 4u) to Rational(1, 24), + mapOf(x to 5u) to Rational(-1, 60), + mapOf(x to 6u) to Rational(1, 360), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, x, 4u), + "test 5" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, y, 0u), + "test 6" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 1u) to Rational(1), + mapOf(x to 1u, y to 1u) to Rational(-2), + mapOf(x to 2u, y to 1u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, y, 1u), + "test 7" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 2u) to Rational(1, 2), + mapOf(x to 1u, y to 2u) to Rational(-1), + mapOf(x to 2u, y to 2u) to Rational(1, 2), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, y, 2u), + "test 8" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf()), + "test 9" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u) to Rational(1), + mapOf(x to 2u) to Rational(-1), + mapOf(x to 3u) to Rational(1, 3), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf( + x to 1u, + y to 0u + )), + "test 10" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 1u) to Rational(1), + mapOf(x to 1u, y to 1u) to Rational(-2), + mapOf(x to 2u, y to 1u) to Rational(1), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(1), + mapOf(x to 1u) to Rational(-2), + mapOf(x to 2u) to Rational(1), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf( + x to 0u, + y to 1u + )), + "test 11" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to Rational(-3, 8), + mapOf(x to 3u) to Rational(-1, 9), + mapOf(x to 4u) to Rational(1, 24), + mapOf(x to 5u) to Rational(-11, 160), + mapOf(x to 6u) to Rational(3, 5), + mapOf(x to 2u, y to 1u) to Rational(-9, 3), + mapOf(x to 3u, y to 1u) to Rational(1, 9), + mapOf(x to 4u, y to 1u) to Rational(-11, 12), + mapOf(x to 5u, y to 1u) to Rational(-1, 60), + mapOf(x to 6u, y to 1u) to Rational(-3, 10), + mapOf(x to 2u, y to 2u) to Rational(-5, 3), + mapOf(x to 3u, y to 2u) to Rational(-4, 15), + mapOf(x to 4u, y to 2u) to Rational(-1, 96), + mapOf(x to 5u, y to 2u) to Rational(1, 35), + mapOf(x to 6u, y to 2u) to Rational(-1, 60), + mapOf(x to 2u, y to 3u) to Rational(3, 14), + mapOf(x to 3u, y to 3u) to Rational(1, 3), + mapOf(x to 4u, y to 3u) to Rational(-1, 6), + mapOf(x to 5u, y to 3u) to Rational(3, 40), + mapOf(x to 6u, y to 3u) to Rational(1, 54), + mapOf(x to 2u, y to 4u) to Rational(-9, 8), + mapOf(x to 3u, y to 4u) to Rational(-5, 3), + mapOf(x to 4u, y to 4u) to Rational(-7, 12), + mapOf(x to 5u, y to 4u) to Rational(1, 140), + mapOf(x to 6u, y to 4u) to Rational(1, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(x to 2u)), + "test 12a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u, y to 1u) to Rational(-6, 8), + mapOf(x to 2u, y to 1u) to Rational(-1, 3), + mapOf(x to 3u, y to 1u) to Rational(1, 6), + mapOf(x to 4u, y to 1u) to Rational(-11, 32), + mapOf(x to 5u, y to 1u) to Rational(18, 5), + mapOf(x to 1u, y to 2u) to Rational(-9, 3), + mapOf(x to 2u, y to 2u) to Rational(1, 6), + mapOf(x to 3u, y to 2u) to Rational(-11, 6), + mapOf(x to 4u, y to 2u) to Rational(-1, 24), + mapOf(x to 5u, y to 2u) to Rational(-9, 10), + mapOf(x to 1u, y to 3u) to Rational(-10, 9), + mapOf(x to 2u, y to 3u) to Rational(-4, 15), + mapOf(x to 3u, y to 3u) to Rational(-1, 72), + mapOf(x to 4u, y to 3u) to Rational(1, 21), + mapOf(x to 5u, y to 3u) to Rational(-1, 30), + mapOf(x to 1u, y to 4u) to Rational(3, 28), + mapOf(x to 2u, y to 4u) to Rational(1, 4), + mapOf(x to 3u, y to 4u) to Rational(-1, 6), + mapOf(x to 4u, y to 4u) to Rational(3, 32), + mapOf(x to 5u, y to 4u) to Rational(1, 36), + mapOf(x to 1u, y to 5u) to Rational(-9, 20), + mapOf(x to 2u, y to 5u) to Rational(-1, 1), + mapOf(x to 3u, y to 5u) to Rational(-7, 15), + mapOf(x to 4u, y to 5u) to Rational(1, 140), + mapOf(x to 5u, y to 5u) to Rational(1, 5), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(x to 1u, y to 1u)), + "test 12b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 2u) to Rational(-3, 8), + mapOf(x to 1u, y to 2u) to Rational(-1, 3), + mapOf(x to 2u, y to 2u) to Rational(1, 4), + mapOf(x to 3u, y to 2u) to Rational(-11, 16), + mapOf(x to 4u, y to 2u) to Rational(9, 1), + mapOf(y to 3u) to Rational(-1, 1), + mapOf(x to 1u, y to 3u) to Rational(1, 9), + mapOf(x to 2u, y to 3u) to Rational(-11, 6), + mapOf(x to 3u, y to 3u) to Rational(-1, 18), + mapOf(x to 4u, y to 3u) to Rational(-9, 6), + mapOf(y to 4u) to Rational(-5, 18), + mapOf(x to 1u, y to 4u) to Rational(-2, 15), + mapOf(x to 2u, y to 4u) to Rational(-1, 96), + mapOf(x to 3u, y to 4u) to Rational(1, 21), + mapOf(x to 4u, y to 4u) to Rational(-1, 24), + mapOf(y to 5u) to Rational(3, 140), + mapOf(x to 1u, y to 5u) to Rational(1, 10), + mapOf(x to 2u, y to 5u) to Rational(-1, 10), + mapOf(x to 3u, y to 5u) to Rational(3, 40), + mapOf(x to 4u, y to 5u) to Rational(1, 36), + mapOf(y to 6u) to Rational(-3, 40), + mapOf(x to 1u, y to 6u) to Rational(-1, 3), + mapOf(x to 2u, y to 6u) to Rational(-7, 30), + mapOf(x to 3u, y to 6u) to Rational(1, 210), + mapOf(x to 4u, y to 6u) to Rational(1, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(-11, 8), + mapOf(x to 4u) to Rational(18, 1), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(-1, 3), + mapOf(x to 4u, y to 1u) to Rational(-18, 2), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(3, 7), + mapOf(x to 1u, y to 3u) to Rational(16, 8), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(-18, 8), + mapOf(x to 1u, y to 4u) to Rational(-10, 1), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(y to 2u)), + "test 12c" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(x to 5u) to Rational(0), + mapOf(x to 6u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(x to 5u, y to 1u) to Rational(0), + mapOf(x to 6u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(-1, 96), + mapOf(x to 5u, y to 2u) to Rational(1, 35), + mapOf(x to 6u, y to 2u) to Rational(-1, 60), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(-1, 6), + mapOf(x to 5u, y to 3u) to Rational(3, 40), + mapOf(x to 6u, y to 3u) to Rational(1, 54), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(-7, 12), + mapOf(x to 5u, y to 4u) to Rational(1, 140), + mapOf(x to 6u, y to 4u) to Rational(1, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(x to 2u)), + "test 13a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(x to 5u, y to 1u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(x to 5u, y to 2u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(-1, 72), + mapOf(x to 4u, y to 3u) to Rational(1, 21), + mapOf(x to 5u, y to 3u) to Rational(-1, 30), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(-1, 6), + mapOf(x to 4u, y to 4u) to Rational(3, 32), + mapOf(x to 5u, y to 4u) to Rational(1, 36), + mapOf(x to 1u, y to 5u) to Rational(0), + mapOf(x to 2u, y to 5u) to Rational(0), + mapOf(x to 3u, y to 5u) to Rational(-7, 15), + mapOf(x to 4u, y to 5u) to Rational(1, 140), + mapOf(x to 5u, y to 5u) to Rational(1, 5), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(x to 1u, y to 1u)), + "test 13b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(0), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-1, 96), + mapOf(x to 3u, y to 4u) to Rational(1, 21), + mapOf(x to 4u, y to 4u) to Rational(-1, 24), + mapOf(y to 5u) to Rational(0), + mapOf(x to 1u, y to 5u) to Rational(0), + mapOf(x to 2u, y to 5u) to Rational(-1, 10), + mapOf(x to 3u, y to 5u) to Rational(3, 40), + mapOf(x to 4u, y to 5u) to Rational(1, 36), + mapOf(y to 6u) to Rational(0), + mapOf(x to 1u, y to 6u) to Rational(0), + mapOf(x to 2u, y to 6u) to Rational(-7, 30), + mapOf(x to 3u, y to 6u) to Rational(1, 210), + mapOf(x to 4u, y to 6u) to Rational(1, 6), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(0), + mapOf(x to 1u) to Rational(0), + mapOf(x to 2u) to Rational(0), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(0), + mapOf(x to 1u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(0), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(4, 7), + mapOf(x to 4u, y to 2u) to Rational(-4, 8), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(-16, 8), + mapOf(x to 3u, y to 3u) to Rational(12, 8), + mapOf(x to 4u, y to 3u) to Rational(5, 9), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(-14, 2), + mapOf(x to 3u, y to 4u) to Rational(1, 7), + mapOf(x to 4u, y to 4u) to Rational(15, 3), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(y to 2u)), + "test 13c" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 2u) to Rational(-3, 8), + mapOf(x to 3u) to Rational(-1, 9), + mapOf(x to 4u) to Rational(1, 24), + mapOf(x to 5u) to Rational(0), + mapOf(x to 6u) to Rational(0), + mapOf(x to 2u, y to 1u) to Rational(-9, 3), + mapOf(x to 3u, y to 1u) to Rational(1, 9), + mapOf(x to 4u, y to 1u) to Rational(-11, 12), + mapOf(x to 5u, y to 1u) to Rational(0), + mapOf(x to 6u, y to 1u) to Rational(0), + mapOf(x to 2u, y to 2u) to Rational(-5, 3), + mapOf(x to 3u, y to 2u) to Rational(-4, 15), + mapOf(x to 4u, y to 2u) to Rational(-1, 96), + mapOf(x to 5u, y to 2u) to Rational(0), + mapOf(x to 6u, y to 2u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(x to 5u, y to 3u) to Rational(0), + mapOf(x to 6u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + mapOf(x to 5u, y to 4u) to Rational(0), + mapOf(x to 6u, y to 4u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(x to 2u)), + "test 14a" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(x to 1u, y to 1u) to Rational(-6, 8), + mapOf(x to 2u, y to 1u) to Rational(-1, 3), + mapOf(x to 3u, y to 1u) to Rational(1, 6), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(x to 5u, y to 1u) to Rational(0), + mapOf(x to 1u, y to 2u) to Rational(-9, 3), + mapOf(x to 2u, y to 2u) to Rational(1, 6), + mapOf(x to 3u, y to 2u) to Rational(-11, 6), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(x to 5u, y to 2u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(-10, 9), + mapOf(x to 2u, y to 3u) to Rational(-4, 15), + mapOf(x to 3u, y to 3u) to Rational(-1, 72), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(x to 5u, y to 3u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + mapOf(x to 5u, y to 4u) to Rational(0), + mapOf(x to 1u, y to 5u) to Rational(0), + mapOf(x to 2u, y to 5u) to Rational(0), + mapOf(x to 3u, y to 5u) to Rational(0), + mapOf(x to 4u, y to 5u) to Rational(0), + mapOf(x to 5u, y to 5u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(x to 1u, y to 1u)), + "test 14b" + ) + assertEquals( + LabeledPolynomialAsIs( + mapOf(y to 2u) to Rational(-3, 8), + mapOf(x to 1u, y to 2u) to Rational(-1, 3), + mapOf(x to 2u, y to 2u) to Rational(1, 4), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(-1, 1), + mapOf(x to 1u, y to 3u) to Rational(1, 9), + mapOf(x to 2u, y to 3u) to Rational(-11, 6), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(-5, 18), + mapOf(x to 1u, y to 4u) to Rational(-2, 15), + mapOf(x to 2u, y to 4u) to Rational(-1, 96), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + mapOf(y to 5u) to Rational(0), + mapOf(x to 1u, y to 5u) to Rational(0), + mapOf(x to 2u, y to 5u) to Rational(0), + mapOf(x to 3u, y to 5u) to Rational(0), + mapOf(x to 4u, y to 5u) to Rational(0), + mapOf(y to 6u) to Rational(0), + mapOf(x to 1u, y to 6u) to Rational(0), + mapOf(x to 2u, y to 6u) to Rational(0), + mapOf(x to 3u, y to 6u) to Rational(0), + mapOf(x to 4u, y to 6u) to Rational(0), + ), + LabeledPolynomialAsIs( + mapOf() to Rational(-6, 8), + mapOf(x to 1u) to Rational(-2, 3), + mapOf(x to 2u) to Rational(1, 2), + mapOf(x to 3u) to Rational(0), + mapOf(x to 4u) to Rational(0), + mapOf(y to 1u) to Rational(-18, 3), + mapOf(x to 1u, y to 1u) to Rational(2, 3), + mapOf(x to 2u, y to 1u) to Rational(-11, 1), + mapOf(x to 3u, y to 1u) to Rational(0), + mapOf(x to 4u, y to 1u) to Rational(0), + mapOf(y to 2u) to Rational(-10, 3), + mapOf(x to 1u, y to 2u) to Rational(-8, 5), + mapOf(x to 2u, y to 2u) to Rational(-1, 8), + mapOf(x to 3u, y to 2u) to Rational(0), + mapOf(x to 4u, y to 2u) to Rational(0), + mapOf(y to 3u) to Rational(0), + mapOf(x to 1u, y to 3u) to Rational(0), + mapOf(x to 2u, y to 3u) to Rational(0), + mapOf(x to 3u, y to 3u) to Rational(0), + mapOf(x to 4u, y to 3u) to Rational(0), + mapOf(y to 4u) to Rational(0), + mapOf(x to 1u, y to 4u) to Rational(0), + mapOf(x to 2u, y to 4u) to Rational(0), + mapOf(x to 3u, y to 4u) to Rational(0), + mapOf(x to 4u, y to 4u) to Rational(0), + ).nthAntiderivativeWithRespectTo(RationalField, mapOf(y to 2u)), + "test 14c" + ) + } +} \ No newline at end of file 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 f0a1128b4..007c3e5e9 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 @@ -7,14 +7,19 @@ package space.kscience.kmath.functions -import space.kscience.kmath.misc.UnstableKMathAPI -import space.kscience.kmath.test.misc.* -import kotlin.test.* +import space.kscience.kmath.test.misc.IntModuloRing +import space.kscience.kmath.test.misc.Rational +import space.kscience.kmath.test.misc.RationalField +import space.kscience.kmath.test.misc.m +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertSame +import kotlin.test.fail -@UnstableKMathAPI class NumberedPolynomialTest { - private val o = Rational(0) + val o = Rational(0) + @Test fun test_Polynomial_Int_plus() { RationalField.numberedPolynomialSpace { @@ -557,6 +562,7 @@ class NumberedPolynomialTest { ) assertEquals( NumberedPolynomial( + listOf() to Rational(0), listOf(3u) to Rational(-8, 9), listOf(0u, 4u) to Rational(-8, 7), ), @@ -650,6 +656,7 @@ class NumberedPolynomialTest { ) assertEquals( NumberedPolynomial( + listOf() to Rational(0), listOf(3u) to Rational(-8, 9), listOf(0u, 4u) to Rational(-8, 7), ), @@ -816,6 +823,7 @@ class NumberedPolynomialTest { ) assertEquals( NumberedPolynomial( + listOf() to Rational(0), listOf(3u) to Rational(-8, 9), listOf(0u, 4u) to Rational(-8, 7), ), diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/test/misc/assertion.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/test/misc/assertion.kt index 3ad482454..85180bd2a 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/test/misc/assertion.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/test/misc/assertion.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.test.misc +import space.kscience.kmath.functions.LabeledPolynomial +import space.kscience.kmath.functions.LabeledRationalFunction import space.kscience.kmath.functions.NumberedPolynomial import space.kscience.kmath.functions.NumberedRationalFunction import kotlin.test.assertEquals @@ -28,6 +30,18 @@ fun assertEquals( message ) +fun assertEquals( + expected: LabeledPolynomial, + actual: LabeledPolynomial, + absoluteTolerance: Double, + message: String? = null +) = assertContentEquals( + expected.coefficients, + actual.coefficients, + absoluteTolerance, + message +) + fun assertEquals( expected: NumberedRationalFunction, actual: NumberedRationalFunction, @@ -48,6 +62,26 @@ fun assertEquals( ) } +fun assertEquals( + expected: LabeledRationalFunction, + actual: LabeledRationalFunction, + absoluteTolerance: Double, + message: String? = null +) { + assertEquals( + expected.numerator, + actual.numerator, + absoluteTolerance, + message + ) + assertEquals( + expected.denominator, + actual.denominator, + absoluteTolerance, + message + ) +} + inline fun assertFailsWithTypeAndMessage( expectedMessage: String? = null, assertionMessage: String? = null,