Feature: Polynomials and rational functions #469

Merged
lounres merged 132 commits from feature/polynomials into dev 2022-07-28 18:04:06 +03:00
6 changed files with 304 additions and 304 deletions
Showing only changes of commit 89cdbf4d71 - Show all commits

View File

@ -22,7 +22,7 @@ public interface Polynomial<C>
* @param C the type of constants. Polynomials have them as coefficients in their terms. * @param C the type of constants. Polynomials have them as coefficients in their terms.
* @param P the type of polynomials. * @param P the type of polynomials.
*/ */
@Suppress("INAPPLICABLE_JVM_NAME", "PARAMETER_NAME_CHANGED_ON_OVERRIDE") @Suppress("INAPPLICABLE_JVM_NAME", "PARAMETER_NAME_CHANGED_ON_OVERRIDE") // FIXME: Waiting for KT-31420
public interface PolynomialSpace<C, P: Polynomial<C>> : Ring<P> { public interface PolynomialSpace<C, P: Polynomial<C>> : Ring<P> {
/** /**
* Returns sum of the constant and the integer represented as constant (member of underlying ring). * Returns sum of the constant and the integer represented as constant (member of underlying ring).
@ -76,38 +76,38 @@ public interface PolynomialSpace<C, P: Polynomial<C>> : Ring<P> {
* *
* The operation is equivalent to adding [other] copies of unit polynomial to [this]. * The operation is equivalent to adding [other] copies of unit polynomial to [this].
*/ */
public operator fun P.plus(other: Int): P = addMultipliedBySquaring(this, one, other) public operator fun P.plus(other: Int): P = addMultipliedByDoubling(this, one, other)
/** /**
* Returns difference between the polynomial and the integer represented as polynomial. * Returns difference between the polynomial and the integer represented as polynomial.
* *
* The operation is equivalent to subtraction [other] copies of unit polynomial from [this]. * The operation is equivalent to subtraction [other] copies of unit polynomial from [this].
*/ */
public operator fun P.minus(other: Int): P = addMultipliedBySquaring(this, one, -other) public operator fun P.minus(other: Int): P = addMultipliedByDoubling(this, one, -other)
/** /**
* Returns product of the polynomial and the integer represented as polynomial. * Returns product of the polynomial and the integer represented as polynomial.
* *
* The operation is equivalent to sum of [other] copies of [this]. * The operation is equivalent to sum of [other] copies of [this].
*/ */
public operator fun P.times(other: Int): P = multiplyBySquaring(this, other) public operator fun P.times(other: Int): P = multiplyByDoubling(this, other)
/** /**
* Returns sum of the integer represented as polynomial and the polynomial. * Returns sum of the integer represented as polynomial and the polynomial.
* *
* The operation is equivalent to adding [this] copies of unit polynomial to [other]. * The operation is equivalent to adding [this] copies of unit polynomial to [other].
*/ */
public operator fun Int.plus(other: P): P = addMultipliedBySquaring(other, one, this) public operator fun Int.plus(other: P): P = addMultipliedByDoubling(other, one, this)
/** /**
* Returns difference between the integer represented as polynomial and the polynomial. * Returns difference between the integer represented as polynomial and the polynomial.
* *
* The operation is equivalent to subtraction [this] copies of unit polynomial from [other]. * The operation is equivalent to subtraction [this] copies of unit polynomial from [other].
*/ */
public operator fun Int.minus(other: P): P = addMultipliedBySquaring(-other, one, this) public operator fun Int.minus(other: P): P = addMultipliedByDoubling(-other, one, this)
/** /**
* Returns product of the integer represented as polynomial and the polynomial. * Returns product of the integer represented as polynomial and the polynomial.
* *
* The operation is equivalent to sum of [this] copies of [other]. * The operation is equivalent to sum of [this] copies of [other].
*/ */
public operator fun Int.times(other: P): P = multiplyBySquaring(other, this) public operator fun Int.times(other: P): P = multiplyByDoubling(other, this)
/** /**
* Converts the integer [value] to polynomial. * Converts the integer [value] to polynomial.
@ -121,38 +121,38 @@ public interface PolynomialSpace<C, P: Polynomial<C>> : Ring<P> {
/** /**
* Returns the same constant. * Returns the same constant.
*/ */
@JvmName("constantUnaryPlus") @JvmName("unaryPlusConstant")
@JsName("constantUnaryPlus") @JsName("unaryPlusConstant")
public operator fun C.unaryPlus(): C = this public operator fun C.unaryPlus(): C = this
/** /**
* Returns negation of the constant. * Returns negation of the constant.
*/ */
@JvmName("constantUnaryMinus") @JvmName("unaryMinusConstant")
@JsName("constantUnaryMinus") @JsName("unaryMinusConstant")
public operator fun C.unaryMinus(): C public operator fun C.unaryMinus(): C
/** /**
* Returns sum of the constants. * Returns sum of the constants.
*/ */
@JvmName("constantPlus") @JvmName("plusConstantConstant")
@JsName("constantPlus") @JsName("plusConstantConstant")
public operator fun C.plus(other: C): C public operator fun C.plus(other: C): C
/** /**
* Returns difference of the constants. * Returns difference of the constants.
*/ */
@JvmName("constantMinus") @JvmName("minusConstantConstant")
@JsName("constantMinus") @JsName("minusConstantConstant")
public operator fun C.minus(other: C): C public operator fun C.minus(other: C): C
/** /**
* Returns product of the constants. * Returns product of the constants.
*/ */
@JvmName("constantTimes") @JvmName("timesConstantConstant")
@JsName("constantTimes") @JsName("timesConstantConstant")
public operator fun C.times(other: C): C public operator fun C.times(other: C): C
/** /**
* Raises [arg] to the integer power [exponent]. * Raises [arg] to the integer power [exponent].
*/ */
@JvmName("constantPower") @JvmName("powerConstant")
@JsName("constantPower") @JsName("powerConstant")
public fun power(arg: C, exponent: UInt) : C public fun power(arg: C, exponent: UInt) : C
/** /**
@ -222,7 +222,7 @@ public interface PolynomialSpace<C, P: Polynomial<C>> : Ring<P> {
/** /**
* Raises [arg] to the integer power [exponent]. * Raises [arg] to the integer power [exponent].
*/ */
public override fun power(arg: P, exponent: UInt) : P = exponentiationBySquaring(arg, exponent) public override fun power(arg: P, exponent: UInt) : P = exponentiateBySquaring(arg, exponent)
/** /**
* Instance of zero polynomial (zero of the polynomial ring). * Instance of zero polynomial (zero of the polynomial ring).
@ -251,7 +251,7 @@ public interface PolynomialSpace<C, P: Polynomial<C>> : Ring<P> {
* @param P the type of polynomials. * @param P the type of polynomials.
* @param A the type of algebraic structure (precisely, of ring) provided for constants. * @param A the type of algebraic structure (precisely, of ring) provided for constants.
*/ */
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME") // FIXME: Waiting for KT-31420
public interface PolynomialSpaceOverRing<C, P: Polynomial<C>, A: Ring<C>> : PolynomialSpace<C, P> { public interface PolynomialSpaceOverRing<C, P: Polynomial<C>, A: Ring<C>> : PolynomialSpace<C, P> {
public val ring: A public val ring: A
@ -261,63 +261,63 @@ public interface PolynomialSpaceOverRing<C, P: Polynomial<C>, A: Ring<C>> : Poly
* *
* The operation is equivalent to adding [other] copies of unit of underlying ring to [this]. * The operation is equivalent to adding [other] copies of unit of underlying ring to [this].
*/ */
public override operator fun C.plus(other: Int): C = ring { addMultipliedBySquaring(this@plus, one, other) } public override operator fun C.plus(other: Int): C = ring { addMultipliedByDoubling(this@plus, one, other) }
/** /**
* Returns difference between the constant and the integer represented as constant (member of underlying ring). * Returns difference between the constant and the integer represented as constant (member of underlying ring).
* *
* The operation is equivalent to subtraction [other] copies of unit of underlying ring from [this]. * The operation is equivalent to subtraction [other] copies of unit of underlying ring from [this].
*/ */
public override operator fun C.minus(other: Int): C = ring { addMultipliedBySquaring(this@minus, one, -other) } public override operator fun C.minus(other: Int): C = ring { addMultipliedByDoubling(this@minus, one, -other) }
/** /**
* Returns product of the constant and the integer represented as constant (member of underlying ring). * Returns product of the constant and the integer represented as constant (member of underlying ring).
* *
* The operation is equivalent to sum of [other] copies of [this]. * The operation is equivalent to sum of [other] copies of [this].
*/ */
public override operator fun C.times(other: Int): C = ring { multiplyBySquaring(this@times, other) } public override operator fun C.times(other: Int): C = ring { multiplyByDoubling(this@times, other) }
/** /**
* Returns sum of the integer represented as constant (member of underlying ring) and the constant. * Returns sum of the integer represented as constant (member of underlying ring) and the constant.
* *
* The operation is equivalent to adding [this] copies of unit of underlying ring to [other]. * The operation is equivalent to adding [this] copies of unit of underlying ring to [other].
*/ */
public override operator fun Int.plus(other: C): C = ring { addMultipliedBySquaring(other, one, this@plus) } public override operator fun Int.plus(other: C): C = ring { addMultipliedByDoubling(other, one, this@plus) }
/** /**
* Returns difference between the integer represented as constant (member of underlying ring) and the constant. * Returns difference between the integer represented as constant (member of underlying ring) and the constant.
* *
* The operation is equivalent to subtraction [this] copies of unit of underlying ring from [other]. * The operation is equivalent to subtraction [this] copies of unit of underlying ring from [other].
*/ */
public override operator fun Int.minus(other: C): C = ring { addMultipliedBySquaring(-other, one, this@minus) } public override operator fun Int.minus(other: C): C = ring { addMultipliedByDoubling(-other, one, this@minus) }
/** /**
* Returns product of the integer represented as constant (member of underlying ring) and the constant. * Returns product of the integer represented as constant (member of underlying ring) and the constant.
* *
* The operation is equivalent to sum of [this] copies of [other]. * The operation is equivalent to sum of [this] copies of [other].
*/ */
public override operator fun Int.times(other: C): C = ring { multiplyBySquaring(other, this@times) } public override operator fun Int.times(other: C): C = ring { multiplyByDoubling(other, this@times) }
/** /**
* Returns negation of the constant. * Returns negation of the constant.
*/ */
@JvmName("constantUnaryMinus") @JvmName("unaryMinusConstant")
public override operator fun C.unaryMinus(): C = ring { -this@unaryMinus } public override operator fun C.unaryMinus(): C = ring { -this@unaryMinus }
/** /**
* Returns sum of the constants. * Returns sum of the constants.
*/ */
@JvmName("constantPlus") @JvmName("plusConstantConstant")
public override operator fun C.plus(other: C): C = ring { this@plus + other } public override operator fun C.plus(other: C): C = ring { this@plus + other }
/** /**
* Returns difference of the constants. * Returns difference of the constants.
*/ */
@JvmName("constantMinus") @JvmName("minusConstantConstant")
public override operator fun C.minus(other: C): C = ring { this@minus - other } public override operator fun C.minus(other: C): C = ring { this@minus - other }
/** /**
* Returns product of the constants. * Returns product of the constants.
*/ */
@JvmName("constantTimes") @JvmName("timesConstantConstant")
public override operator fun C.times(other: C): C = ring { this@times * other } public override operator fun C.times(other: C): C = ring { this@times * other }
/** /**
* Raises [arg] to the integer power [exponent]. * Raises [arg] to the integer power [exponent].
*/ */
@JvmName("constantPower") @JvmName("powerConstant")
override fun power(arg: C, exponent: UInt): C = ring { power(arg, exponent) } override fun power(arg: C, exponent: UInt): C = ring { power(arg, exponent) }
/** /**
@ -330,59 +330,59 @@ public interface PolynomialSpaceOverRing<C, P: Polynomial<C>, A: Ring<C>> : Poly
public override val constantOne: C get() = ring.one public override val constantOne: C get() = ring.one
} }
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME") // FIXME: Waiting for KT-31420
public interface MultivariatePolynomialSpace<C, V, P: Polynomial<C>>: PolynomialSpace<C, P> { public interface MultivariatePolynomialSpace<C, V, P: Polynomial<C>>: PolynomialSpace<C, P> {
@JvmName("VariableIntPlus") @JvmName("plusVariableInt")
public operator fun V.plus(other: Int): P public operator fun V.plus(other: Int): P
@JvmName("VariableIntMinus") @JvmName("minusVariableInt")
public operator fun V.minus(other: Int): P public operator fun V.minus(other: Int): P
@JvmName("VariableIntMinusTimes") @JvmName("timesVariableInt")
public operator fun V.times(other: Int): P public operator fun V.times(other: Int): P
@JvmName("IntVariablePlus") @JvmName("plusIntVariable")
public operator fun Int.plus(other: V): P public operator fun Int.plus(other: V): P
@JvmName("IntVariableMinus") @JvmName("minusIntVariable")
public operator fun Int.minus(other: V): P public operator fun Int.minus(other: V): P
@JvmName("IntVariableTimes") @JvmName("timesIntVariable")
public operator fun Int.times(other: V): P public operator fun Int.times(other: V): P
@JvmName("ConstantVariablePlus") @JvmName("plusConstantVariable")
public operator fun C.plus(other: V): P public operator fun C.plus(other: V): P
@JvmName("ConstantVariableMinus") @JvmName("minusConstantVariable")
public operator fun C.minus(other: V): P public operator fun C.minus(other: V): P
@JvmName("ConstantVariableTimes") @JvmName("timesConstantVariable")
public operator fun C.times(other: V): P public operator fun C.times(other: V): P
@JvmName("VariableConstantPlus") @JvmName("plusVariableConstant")
public operator fun V.plus(other: C): P public operator fun V.plus(other: C): P
@JvmName("VariableConstantMinus") @JvmName("minusVariableConstant")
public operator fun V.minus(other: C): P public operator fun V.minus(other: C): P
@JvmName("VariableConstantTimes") @JvmName("timesVariableConstant")
public operator fun V.times(other: C): P public operator fun V.times(other: C): P
@JvmName("VariableUnaryPlus") @JvmName("unaryPlusVariable")
public operator fun V.unaryPlus(): P public operator fun V.unaryPlus(): P
@JvmName("VariableUnaryMinus") @JvmName("unaryMinusVariable")
public operator fun V.unaryMinus(): P public operator fun V.unaryMinus(): P
@JvmName("VariablePlus") @JvmName("plusVariableVariable")
public operator fun V.plus(other: V): P public operator fun V.plus(other: V): P
@JvmName("VariableMinus") @JvmName("minusVariableVariable")
public operator fun V.minus(other: V): P public operator fun V.minus(other: V): P
@JvmName("VariableTimes") @JvmName("timesVariableVariable")
public operator fun V.times(other: V): P public operator fun V.times(other: V): P
@JvmName("VariablePolynomialPlus") @JvmName("plusVariablePolynomial")
public operator fun V.plus(other: P): P public operator fun V.plus(other: P): P
@JvmName("VariablePolynomialMinus") @JvmName("minusVariablePolynomial")
public operator fun V.minus(other: P): P public operator fun V.minus(other: P): P
@JvmName("VariablePolynomialTimes") @JvmName("timesVariablePolynomial")
public operator fun V.times(other: P): P public operator fun V.times(other: P): P
@JvmName("PolynomialVariablePlus") @JvmName("plusPolynomialVariable")
public operator fun P.plus(other: V): P public operator fun P.plus(other: V): P
@JvmName("PolynomialVariableMinus") @JvmName("minusPolynomialVariable")
public operator fun P.minus(other: V): P public operator fun P.minus(other: V): P
@JvmName("PolynomialVariableTimes") @JvmName("timesPolynomialVariable")
public operator fun P.times(other: V): P public operator fun P.times(other: V): P
/** /**

View File

@ -28,7 +28,7 @@ public interface RationalFunction<C, P: Polynomial<C>> {
* @param P the type of polynomials. Rational functions have them as numerators and denominators in them. * @param P the type of polynomials. Rational functions have them as numerators and denominators in them.
* @param R the type of rational functions. * @param R the type of rational functions.
*/ */
@Suppress("INAPPLICABLE_JVM_NAME", "PARAMETER_NAME_CHANGED_ON_OVERRIDE") @Suppress("INAPPLICABLE_JVM_NAME", "PARAMETER_NAME_CHANGED_ON_OVERRIDE") // FIXME: Waiting for KT-31420
public interface RationalFunctionalSpace<C, P: Polynomial<C>, R: RationalFunction<C, P>> : Ring<R> { public interface RationalFunctionalSpace<C, P: Polynomial<C>, R: RationalFunction<C, P>> : Ring<R> {
/** /**
* Returns sum of the constant and the integer represented as constant (member of underlying ring). * Returns sum of the constant and the integer represented as constant (member of underlying ring).
@ -129,52 +129,52 @@ public interface RationalFunctionalSpace<C, P: Polynomial<C>, R: RationalFunctio
* *
* The operation is equivalent to adding [other] copies of unit polynomial to [this]. * The operation is equivalent to adding [other] copies of unit polynomial to [this].
*/ */
public operator fun R.plus(other: Int): R = addMultipliedBySquaring(this, one, other) public operator fun R.plus(other: Int): R = addMultipliedByDoubling(this, one, other)
/** /**
* Returns difference between the rational function and the integer represented as rational function. * Returns difference between the rational function and the integer represented as rational function.
* *
* The operation is equivalent to subtraction [other] copies of unit polynomial from [this]. * The operation is equivalent to subtraction [other] copies of unit polynomial from [this].
*/ */
public operator fun R.minus(other: Int): R = addMultipliedBySquaring(this, one, -other) public operator fun R.minus(other: Int): R = addMultipliedByDoubling(this, one, -other)
/** /**
* Returns product of the rational function and the integer represented as rational function. * Returns product of the rational function and the integer represented as rational function.
* *
* The operation is equivalent to sum of [other] copies of [this]. * The operation is equivalent to sum of [other] copies of [this].
*/ */
public operator fun R.times(other: Int): R = multiplyBySquaring(this, other) public operator fun R.times(other: Int): R = multiplyByDoubling(this, other)
/** /**
* Returns quotient of the rational function and the integer represented as rational function. * Returns quotient of the rational function and the integer represented as rational function.
* *
* The operation is equivalent to creating a new rational function by preserving numerator of [this] and * The operation is equivalent to creating a new rational function by preserving numerator of [this] and
* multiplication denominator of [this] to [other]. * multiplication denominator of [this] to [other].
*/ */
public operator fun R.div(other: Int): R = this / multiplyBySquaring(one, other) public operator fun R.div(other: Int): R = this / multiplyByDoubling(one, other)
/** /**
* Returns sum of the integer represented as rational function and the rational function. * Returns sum of the integer represented as rational function and the rational function.
* *
* The operation is equivalent to adding [this] copies of unit polynomial to [other]. * The operation is equivalent to adding [this] copies of unit polynomial to [other].
*/ */
public operator fun Int.plus(other: R): R = addMultipliedBySquaring(other, one, this) public operator fun Int.plus(other: R): R = addMultipliedByDoubling(other, one, this)
/** /**
* Returns difference between the integer represented as rational function and the rational function. * Returns difference between the integer represented as rational function and the rational function.
* *
* The operation is equivalent to subtraction [this] copies of unit polynomial from [other]. * The operation is equivalent to subtraction [this] copies of unit polynomial from [other].
*/ */
public operator fun Int.minus(other: R): R = addMultipliedBySquaring(-other, one, this) public operator fun Int.minus(other: R): R = addMultipliedByDoubling(-other, one, this)
/** /**
* Returns product of the integer represented as rational function and the rational function. * Returns product of the integer represented as rational function and the rational function.
* *
* The operation is equivalent to sum of [this] copies of [other]. * The operation is equivalent to sum of [this] copies of [other].
*/ */
public operator fun Int.times(other: R): R = multiplyBySquaring(other, this) public operator fun Int.times(other: R): R = multiplyByDoubling(other, this)
/** /**
* Returns quotient of the integer represented as rational function and the rational function. * Returns quotient of the integer represented as rational function and the rational function.
* *
* The operation is equivalent to creating a new rational function which numerator is [this] times denominator of * The operation is equivalent to creating a new rational function which numerator is [this] times denominator of
* [other] and which denominator is [other]'s numerator. * [other] and which denominator is [other]'s numerator.
*/ */
public operator fun Int.div(other: R): R = multiplyBySquaring(one / other, this) public operator fun Int.div(other: R): R = multiplyByDoubling(one / other, this)
/** /**
* Converts the integer [value] to rational function. * Converts the integer [value] to rational function.
@ -188,38 +188,38 @@ public interface RationalFunctionalSpace<C, P: Polynomial<C>, R: RationalFunctio
/** /**
* Returns the same constant. * Returns the same constant.
*/ */
@JvmName("constantUnaryPlus") @JvmName("unaryPlusConstant")
@JsName("constantUnaryPlus") @JsName("unaryPlusConstant")
public operator fun C.unaryPlus(): C = this public operator fun C.unaryPlus(): C = this
/** /**
* Returns negation of the constant. * Returns negation of the constant.
*/ */
@JvmName("constantUnaryMinus") @JvmName("unaryMinusConstant")
@JsName("constantUnaryMinus") @JsName("unaryMinusConstant")
public operator fun C.unaryMinus(): C public operator fun C.unaryMinus(): C
/** /**
* Returns sum of the constants. * Returns sum of the constants.
*/ */
@JvmName("constantPlus") @JvmName("plusConstantConstant")
@JsName("constantPlus") @JsName("plusConstantConstant")
public operator fun C.plus(other: C): C public operator fun C.plus(other: C): C
/** /**
* Returns difference of the constants. * Returns difference of the constants.
*/ */
@JvmName("constantMinus") @JvmName("minusConstantConstant")
@JsName("constantMinus") @JsName("minusConstantConstant")
public operator fun C.minus(other: C): C public operator fun C.minus(other: C): C
/** /**
* Returns product of the constants. * Returns product of the constants.
*/ */
@JvmName("constantTimes") @JvmName("timesConstantConstant")
@JsName("constantTimes") @JsName("timesConstantConstant")
public operator fun C.times(other: C): C public operator fun C.times(other: C): C
/** /**
* Raises [arg] to the integer power [exponent]. * Raises [arg] to the integer power [exponent].
*/ */
@JvmName("constantPower") @JvmName("powerConstant")
@JsName("constantPower") @JsName("powerConstant")
public fun power(arg: C, exponent: UInt) : C public fun power(arg: C, exponent: UInt) : C
/** /**
@ -417,7 +417,7 @@ public interface RationalFunctionalSpace<C, P: Polynomial<C>, R: RationalFunctio
/** /**
* Raises [arg] to the integer power [exponent]. * Raises [arg] to the integer power [exponent].
*/ */
public override fun power(arg: R, exponent: UInt) : R = exponentiationBySquaring(arg, exponent) public override fun power(arg: R, exponent: UInt) : R = exponentiateBySquaring(arg, exponent)
/** /**
* Instance of zero rational function (zero of the rational functions ring). * Instance of zero rational function (zero of the rational functions ring).
@ -458,7 +458,7 @@ public interface RationalFunctionalSpace<C, P: Polynomial<C>, R: RationalFunctio
* @param R the type of rational functions. * @param R the type of rational functions.
* @param A the type of algebraic structure (precisely, of ring) provided for constants. * @param A the type of algebraic structure (precisely, of ring) provided for constants.
*/ */
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME") // FIXME: Waiting for KT-31420
public interface RationalFunctionalSpaceOverRing<C, P: Polynomial<C>, R: RationalFunction<C, P>, A: Ring<C>> : RationalFunctionalSpace<C, P, R> { public interface RationalFunctionalSpaceOverRing<C, P: Polynomial<C>, R: RationalFunction<C, P>, A: Ring<C>> : RationalFunctionalSpace<C, P, R> {
public val ring: A public val ring: A
@ -468,68 +468,68 @@ public interface RationalFunctionalSpaceOverRing<C, P: Polynomial<C>, R: Rationa
* *
* The operation is equivalent to adding [other] copies of unit of underlying ring to [this]. * The operation is equivalent to adding [other] copies of unit of underlying ring to [this].
*/ */
public override operator fun C.plus(other: Int): C = ring { addMultipliedBySquaring(this@plus, one, other) } public override operator fun C.plus(other: Int): C = ring { addMultipliedByDoubling(this@plus, one, other) }
/** /**
* Returns difference between the constant and the integer represented as constant (member of underlying ring). * Returns difference between the constant and the integer represented as constant (member of underlying ring).
* *
* The operation is equivalent to subtraction [other] copies of unit of underlying ring from [this]. * The operation is equivalent to subtraction [other] copies of unit of underlying ring from [this].
*/ */
public override operator fun C.minus(other: Int): C = ring { addMultipliedBySquaring(this@minus, one, -other) } public override operator fun C.minus(other: Int): C = ring { addMultipliedByDoubling(this@minus, one, -other) }
/** /**
* Returns product of the constant and the integer represented as constant (member of underlying ring). * Returns product of the constant and the integer represented as constant (member of underlying ring).
* *
* The operation is equivalent to sum of [other] copies of [this]. * The operation is equivalent to sum of [other] copies of [this].
*/ */
public override operator fun C.times(other: Int): C = ring { multiplyBySquaring(this@times, other) } public override operator fun C.times(other: Int): C = ring { multiplyByDoubling(this@times, other) }
/** /**
* Returns sum of the integer represented as constant (member of underlying ring) and the constant. * Returns sum of the integer represented as constant (member of underlying ring) and the constant.
* *
* The operation is equivalent to adding [this] copies of unit of underlying ring to [other]. * The operation is equivalent to adding [this] copies of unit of underlying ring to [other].
*/ */
public override operator fun Int.plus(other: C): C = ring { addMultipliedBySquaring(other, one, this@plus) } public override operator fun Int.plus(other: C): C = ring { addMultipliedByDoubling(other, one, this@plus) }
/** /**
* Returns difference between the integer represented as constant (member of underlying ring) and the constant. * Returns difference between the integer represented as constant (member of underlying ring) and the constant.
* *
* The operation is equivalent to subtraction [this] copies of unit of underlying ring from [other]. * The operation is equivalent to subtraction [this] copies of unit of underlying ring from [other].
*/ */
public override operator fun Int.minus(other: C): C = ring { addMultipliedBySquaring(-other, one, this@minus) } public override operator fun Int.minus(other: C): C = ring { addMultipliedByDoubling(-other, one, this@minus) }
/** /**
* Returns product of the integer represented as constant (member of underlying ring) and the constant. * Returns product of the integer represented as constant (member of underlying ring) and the constant.
* *
* The operation is equivalent to sum of [this] copies of [other]. * The operation is equivalent to sum of [this] copies of [other].
*/ */
public override operator fun Int.times(other: C): C = ring { multiplyBySquaring(other, this@times) } public override operator fun Int.times(other: C): C = ring { multiplyByDoubling(other, this@times) }
/** /**
* Returns the same constant. * Returns the same constant.
*/ */
@JvmName("constantUnaryPlus") @JvmName("unaryPlusConstant")
public override operator fun C.unaryPlus(): C = ring { +this@unaryPlus } public override operator fun C.unaryPlus(): C = ring { +this@unaryPlus }
/** /**
* Returns negation of the constant. * Returns negation of the constant.
*/ */
@JvmName("constantUnaryMinus") @JvmName("unaryMinusConstant")
public override operator fun C.unaryMinus(): C = ring { -this@unaryMinus } public override operator fun C.unaryMinus(): C = ring { -this@unaryMinus }
/** /**
* Returns sum of the constants. * Returns sum of the constants.
*/ */
@JvmName("constantPlus") @JvmName("plusConstantConstant")
public override operator fun C.plus(other: C): C = ring { this@plus + other } public override operator fun C.plus(other: C): C = ring { this@plus + other }
/** /**
* Returns difference of the constants. * Returns difference of the constants.
*/ */
@JvmName("constantMinus") @JvmName("minusConstantConstant")
public override operator fun C.minus(other: C): C = ring { this@minus - other } public override operator fun C.minus(other: C): C = ring { this@minus - other }
/** /**
* Returns product of the constants. * Returns product of the constants.
*/ */
@JvmName("constantTimes") @JvmName("timesConstantConstant")
public override operator fun C.times(other: C): C = ring { this@times * other } public override operator fun C.times(other: C): C = ring { this@times * other }
/** /**
* Raises [arg] to the integer power [exponent]. * Raises [arg] to the integer power [exponent].
*/ */
@JvmName("constantPower") @JvmName("powerConstant")
public override fun power(arg: C, exponent: UInt) : C = ring { power(arg, exponent) } public override fun power(arg: C, exponent: UInt) : C = ring { power(arg, exponent) }
/** /**
@ -552,7 +552,7 @@ public interface RationalFunctionalSpaceOverRing<C, P: Polynomial<C>, R: Rationa
* @param R the type of rational functions. * @param R the type of rational functions.
* @param AP the type of algebraic structure (precisely, of ring) provided for polynomials. * @param AP the type of algebraic structure (precisely, of ring) provided for polynomials.
*/ */
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME") // FIXME: Waiting for KT-31420
public interface RationalFunctionalSpaceOverPolynomialSpace< public interface RationalFunctionalSpaceOverPolynomialSpace<
C, C,
P: Polynomial<C>, P: Polynomial<C>,
@ -659,32 +659,32 @@ public interface RationalFunctionalSpaceOverPolynomialSpace<
/** /**
* Returns the same constant. * Returns the same constant.
*/ */
@JvmName("constantUnaryPlus") @JvmName("unaryPlusConstant")
public override operator fun C.unaryPlus(): C = polynomialRing { +this@unaryPlus } public override operator fun C.unaryPlus(): C = polynomialRing { +this@unaryPlus }
/** /**
* Returns negation of the constant. * Returns negation of the constant.
*/ */
@JvmName("constantUnaryMinus") @JvmName("unaryMinusConstant")
public override operator fun C.unaryMinus(): C = polynomialRing { -this@unaryMinus } public override operator fun C.unaryMinus(): C = polynomialRing { -this@unaryMinus }
/** /**
* Returns sum of the constants. * Returns sum of the constants.
*/ */
@JvmName("constantPlus") @JvmName("plusConstantConstant")
public override operator fun C.plus(other: C): C = polynomialRing { this@plus + other } public override operator fun C.plus(other: C): C = polynomialRing { this@plus + other }
/** /**
* Returns difference of the constants. * Returns difference of the constants.
*/ */
@JvmName("constantMinus") @JvmName("minusConstantConstant")
public override operator fun C.minus(other: C): C = polynomialRing { this@minus - other } public override operator fun C.minus(other: C): C = polynomialRing { this@minus - other }
/** /**
* Returns product of the constants. * Returns product of the constants.
*/ */
@JvmName("constantTimes") @JvmName("timesConstantConstant")
public override operator fun C.times(other: C): C = polynomialRing { this@times * other } public override operator fun C.times(other: C): C = polynomialRing { this@times * other }
/** /**
* Raises [arg] to the integer power [exponent]. * Raises [arg] to the integer power [exponent].
*/ */
@JvmName("constantPower") @JvmName("powerConstant")
public override fun power(arg: C, exponent: UInt) : C = polynomialRing { power(arg, exponent) } public override fun power(arg: C, exponent: UInt) : C = polynomialRing { power(arg, exponent) }
/** /**
@ -780,7 +780,7 @@ public interface RationalFunctionalSpaceOverPolynomialSpace<
* @param P the type of polynomials. Rational functions have them as numerators and denominators in them. * @param P the type of polynomials. Rational functions have them as numerators and denominators in them.
* @param R the type of rational functions. * @param R the type of rational functions.
*/ */
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME") // FIXME: Waiting for KT-31420
public abstract class PolynomialSpaceOfFractions< public abstract class PolynomialSpaceOfFractions<
C, C,
P: Polynomial<C>, P: Polynomial<C>,
@ -1052,78 +1052,78 @@ public abstract class PolynomialSpaceOfFractions<
public override val one: R get() = constructRationalFunction(polynomialOne) public override val one: R get() = constructRationalFunction(polynomialOne)
} }
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME") // FIXME: Waiting for KT-31420
public interface MultivariateRationalFunctionalSpace< public interface MultivariateRationalFunctionalSpace<
C, C,
V, V,
P: Polynomial<C>, P: Polynomial<C>,
R: RationalFunction<C, P> R: RationalFunction<C, P>
>: RationalFunctionalSpace<C, P, R> { >: RationalFunctionalSpace<C, P, R> {
@JvmName("VariableIntPlus") @JvmName("plusVariableInt")
public operator fun V.plus(other: Int): P public operator fun V.plus(other: Int): P
@JvmName("VariableIntMinus") @JvmName("minusVariableInt")
public operator fun V.minus(other: Int): P public operator fun V.minus(other: Int): P
@JvmName("VariableIntMinusTimes") @JvmName("timesVariableInt")
public operator fun V.times(other: Int): P public operator fun V.times(other: Int): P
@JvmName("IntVariablePlus") @JvmName("plusIntVariable")
public operator fun Int.plus(other: V): P public operator fun Int.plus(other: V): P
@JvmName("IntVariableMinus") @JvmName("minusIntVariable")
public operator fun Int.minus(other: V): P public operator fun Int.minus(other: V): P
@JvmName("IntVariableTimes") @JvmName("timesIntVariable")
public operator fun Int.times(other: V): P public operator fun Int.times(other: V): P
@JvmName("ConstantVariablePlus") @JvmName("plusConstantVariable")
public operator fun C.plus(other: V): P public operator fun C.plus(other: V): P
@JvmName("ConstantVariableMinus") @JvmName("minusConstantVariable")
public operator fun C.minus(other: V): P public operator fun C.minus(other: V): P
@JvmName("ConstantVariableTimes") @JvmName("timesConstantVariable")
public operator fun C.times(other: V): P public operator fun C.times(other: V): P
@JvmName("VariableConstantPlus") @JvmName("plusVariableConstant")
public operator fun V.plus(other: C): P public operator fun V.plus(other: C): P
@JvmName("VariableConstantMinus") @JvmName("minusVariableConstant")
public operator fun V.minus(other: C): P public operator fun V.minus(other: C): P
@JvmName("VariableConstantTimes") @JvmName("timesVariableConstant")
public operator fun V.times(other: C): P public operator fun V.times(other: C): P
@JvmName("VariableUnaryPlus") @JvmName("unaryPlusVariable")
public operator fun V.unaryPlus(): P public operator fun V.unaryPlus(): P
@JvmName("VariableUnaryMinus") @JvmName("unaryMinusVariable")
public operator fun V.unaryMinus(): P public operator fun V.unaryMinus(): P
@JvmName("VariablePlus") @JvmName("plusVariableVariable")
public operator fun V.plus(other: V): P public operator fun V.plus(other: V): P
@JvmName("VariableMinus") @JvmName("minusVariableVariable")
public operator fun V.minus(other: V): P public operator fun V.minus(other: V): P
@JvmName("VariableTimes") @JvmName("timesVariableVariable")
public operator fun V.times(other: V): P public operator fun V.times(other: V): P
@JvmName("VariablePolynomialPlus") @JvmName("plusVariablePolynomial")
public operator fun V.plus(other: P): P public operator fun V.plus(other: P): P
@JvmName("VariablePolynomialMinus") @JvmName("minusVariablePolynomial")
public operator fun V.minus(other: P): P public operator fun V.minus(other: P): P
@JvmName("VariablePolynomialTimes") @JvmName("timesVariablePolynomial")
public operator fun V.times(other: P): P public operator fun V.times(other: P): P
@JvmName("PolynomialVariablePlus") @JvmName("plusPolynomialVariable")
public operator fun P.plus(other: V): P public operator fun P.plus(other: V): P
@JvmName("PolynomialVariableMinus") @JvmName("minusPolynomialVariable")
public operator fun P.minus(other: V): P public operator fun P.minus(other: V): P
@JvmName("PolynomialVariableTimes") @JvmName("timesPolynomialVariable")
public operator fun P.times(other: V): P public operator fun P.times(other: V): P
@JvmName("VariableRationalFunctionPlus") @JvmName("plusVariableRational")
public operator fun V.plus(other: R): R public operator fun V.plus(other: R): R
@JvmName("VariableRationalFunctionMinus") @JvmName("minusVariableRational")
public operator fun V.minus(other: R): R public operator fun V.minus(other: R): R
@JvmName("VariableRationalFunctionTimes") @JvmName("timesVariableRational")
public operator fun V.times(other: R): R public operator fun V.times(other: R): R
@JvmName("RationalFunctionVariablePlus") @JvmName("plusRationalVariable")
public operator fun R.plus(other: V): R public operator fun R.plus(other: V): R
@JvmName("RationalFunctionVariableMinus") @JvmName("minusRationalVariable")
public operator fun R.minus(other: V): R public operator fun R.minus(other: V): R
@JvmName("RationalFunctionVariableTimes") @JvmName("timesRationalVariable")
public operator fun R.times(other: V): R public operator fun R.times(other: V): R
/** /**
@ -1177,7 +1177,7 @@ public interface MultivariateRationalFunctionalSpaceOverPolynomialSpace<
AP: PolynomialSpace<C, P>, AP: PolynomialSpace<C, P>,
> : RationalFunctionalSpaceOverPolynomialSpace<C, P, R, AP>, MultivariateRationalFunctionalSpace<C, V, P, R> > : RationalFunctionalSpaceOverPolynomialSpace<C, P, R, AP>, MultivariateRationalFunctionalSpace<C, V, P, R>
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME") // FIXME: Waiting for KT-31420
public interface MultivariateRationalFunctionalSpaceOverMultivariatePolynomialSpace< public interface MultivariateRationalFunctionalSpaceOverMultivariatePolynomialSpace<
C, C,
V, V,
@ -1185,57 +1185,57 @@ public interface MultivariateRationalFunctionalSpaceOverMultivariatePolynomialSp
R: RationalFunction<C, P>, R: RationalFunction<C, P>,
AP: MultivariatePolynomialSpace<C, V, P>, AP: MultivariatePolynomialSpace<C, V, P>,
> : MultivariateRationalFunctionalSpaceOverPolynomialSpace<C, V, P, R, AP> { > : MultivariateRationalFunctionalSpaceOverPolynomialSpace<C, V, P, R, AP> {
@JvmName("VariableIntPlus") @JvmName("plusVariableInt")
public override operator fun V.plus(other: Int): P = polynomialRing { this@plus + other } public override operator fun V.plus(other: Int): P = polynomialRing { this@plus + other }
@JvmName("VariableIntMinus") @JvmName("minusVariableInt")
public override operator fun V.minus(other: Int): P = polynomialRing { this@minus - other } public override operator fun V.minus(other: Int): P = polynomialRing { this@minus - other }
@JvmName("VariableIntMinusTimes") @JvmName("timesVariableInt")
public override operator fun V.times(other: Int): P = polynomialRing { this@times * other } public override operator fun V.times(other: Int): P = polynomialRing { this@times * other }
@JvmName("IntVariablePlus") @JvmName("plusIntVariable")
public override operator fun Int.plus(other: V): P = polynomialRing { this@plus + other } public override operator fun Int.plus(other: V): P = polynomialRing { this@plus + other }
@JvmName("IntVariableMinus") @JvmName("minusIntVariable")
public override operator fun Int.minus(other: V): P = polynomialRing { this@minus - other } public override operator fun Int.minus(other: V): P = polynomialRing { this@minus - other }
@JvmName("IntVariableTimes") @JvmName("timesIntVariable")
public override operator fun Int.times(other: V): P = polynomialRing { this@times * other } public override operator fun Int.times(other: V): P = polynomialRing { this@times * other }
@JvmName("ConstantVariablePlus") @JvmName("plusConstantVariable")
public override operator fun C.plus(other: V): P = polynomialRing { this@plus + other } public override operator fun C.plus(other: V): P = polynomialRing { this@plus + other }
@JvmName("ConstantVariableMinus") @JvmName("minusConstantVariable")
public override operator fun C.minus(other: V): P = polynomialRing { this@minus - other } public override operator fun C.minus(other: V): P = polynomialRing { this@minus - other }
@JvmName("ConstantVariableTimes") @JvmName("timesConstantVariable")
public override operator fun C.times(other: V): P = polynomialRing { this@times * other } public override operator fun C.times(other: V): P = polynomialRing { this@times * other }
@JvmName("VariableConstantPlus") @JvmName("plusVariableConstant")
public override operator fun V.plus(other: C): P = polynomialRing { this@plus + other } public override operator fun V.plus(other: C): P = polynomialRing { this@plus + other }
@JvmName("VariableConstantMinus") @JvmName("minusVariableConstant")
public override operator fun V.minus(other: C): P = polynomialRing { this@minus - other } public override operator fun V.minus(other: C): P = polynomialRing { this@minus - other }
@JvmName("VariableConstantTimes") @JvmName("timesVariableConstant")
public override operator fun V.times(other: C): P = polynomialRing { this@times * other } public override operator fun V.times(other: C): P = polynomialRing { this@times * other }
@JvmName("VariableUnaryPlus") @JvmName("unaryPlusVariable")
public override operator fun V.unaryPlus(): P = polynomialRing { +this@unaryPlus } public override operator fun V.unaryPlus(): P = polynomialRing { +this@unaryPlus }
@JvmName("VariableUnaryMinus") @JvmName("unaryMinusVariable")
public override operator fun V.unaryMinus(): P = polynomialRing { -this@unaryMinus } public override operator fun V.unaryMinus(): P = polynomialRing { -this@unaryMinus }
@JvmName("VariablePlus") @JvmName("plusVariableVariable")
public override operator fun V.plus(other: V): P = polynomialRing { this@plus + other } public override operator fun V.plus(other: V): P = polynomialRing { this@plus + other }
@JvmName("VariableMinus") @JvmName("minusVariableVariable")
public override operator fun V.minus(other: V): P = polynomialRing { this@minus - other } public override operator fun V.minus(other: V): P = polynomialRing { this@minus - other }
@JvmName("VariableTimes") @JvmName("timesVariableVariable")
public override operator fun V.times(other: V): P = polynomialRing { this@times * other } public override operator fun V.times(other: V): P = polynomialRing { this@times * other }
@JvmName("VariablePolynomialPlus") @JvmName("plusVariablePolynomial")
public override operator fun V.plus(other: P): P = polynomialRing { this@plus + other } public override operator fun V.plus(other: P): P = polynomialRing { this@plus + other }
@JvmName("VariablePolynomialMinus") @JvmName("minusVariablePolynomial")
public override operator fun V.minus(other: P): P = polynomialRing { this@minus - other } public override operator fun V.minus(other: P): P = polynomialRing { this@minus - other }
@JvmName("VariablePolynomialTimes") @JvmName("timesVariablePolynomial")
public override operator fun V.times(other: P): P = polynomialRing { this@times * other } public override operator fun V.times(other: P): P = polynomialRing { this@times * other }
@JvmName("PolynomialVariablePlus") @JvmName("plusPolynomialVariable")
public override operator fun P.plus(other: V): P = polynomialRing { this@plus + other } public override operator fun P.plus(other: V): P = polynomialRing { this@plus + other }
@JvmName("PolynomialVariableMinus") @JvmName("minusPolynomialVariable")
public override operator fun P.minus(other: V): P = polynomialRing { this@minus - other } public override operator fun P.minus(other: V): P = polynomialRing { this@minus - other }
@JvmName("PolynomialVariableTimes") @JvmName("timesPolynomialVariable")
public override operator fun P.times(other: V): P = polynomialRing { this@times * other } public override operator fun P.times(other: V): P = polynomialRing { this@times * other }
/** /**
@ -1264,45 +1264,45 @@ public interface MultivariateRationalFunctionalSpaceOverMultivariatePolynomialSp
public override val P.countOfVariables: Int get() = polynomialRing { countOfVariables } public override val P.countOfVariables: Int get() = polynomialRing { countOfVariables }
} }
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME") // FIXME: Waiting for KT-31420
public abstract class MultivariatePolynomialSpaceOfFractions< public abstract class MultivariatePolynomialSpaceOfFractions<
C, C,
V, V,
P: Polynomial<C>, P: Polynomial<C>,
R: RationalFunction<C, P>, R: RationalFunction<C, P>,
> : MultivariateRationalFunctionalSpace<C, V, P, R>, PolynomialSpaceOfFractions<C, P, R>() { > : MultivariateRationalFunctionalSpace<C, V, P, R>, PolynomialSpaceOfFractions<C, P, R>() {
@JvmName("VariableRationalFunctionPlus") @JvmName("plusVariableRational")
public override operator fun V.plus(other: R): R = public override operator fun V.plus(other: R): R =
constructRationalFunction( constructRationalFunction(
this * other.denominator + other.numerator, this * other.denominator + other.numerator,
other.denominator other.denominator
) )
@JvmName("VariableRationalFunctionMinus") @JvmName("minusVariableRational")
public override operator fun V.minus(other: R): R = public override operator fun V.minus(other: R): R =
constructRationalFunction( constructRationalFunction(
this * other.denominator - other.numerator, this * other.denominator - other.numerator,
other.denominator other.denominator
) )
@JvmName("VariableRationalFunctionTimes") @JvmName("timesVariableRational")
public override operator fun V.times(other: R): R = public override operator fun V.times(other: R): R =
constructRationalFunction( constructRationalFunction(
this * other.numerator, this * other.numerator,
other.denominator other.denominator
) )
@JvmName("RationalFunctionVariablePlus") @JvmName("plusRationalVariable")
public override operator fun R.plus(other: V): R = public override operator fun R.plus(other: V): R =
constructRationalFunction( constructRationalFunction(
numerator + denominator * other, numerator + denominator * other,
denominator denominator
) )
@JvmName("RationalFunctionVariableMinus") @JvmName("minusRationalVariable")
public override operator fun R.minus(other: V): R = public override operator fun R.minus(other: V): R =
constructRationalFunction( constructRationalFunction(
numerator - denominator * other, numerator - denominator * other,
denominator denominator
) )
@JvmName("RationalFunctionVariableTimes") @JvmName("timesRationalVariable")
public override operator fun R.times(other: V): R = public override operator fun R.times(other: V): R =
constructRationalFunction( constructRationalFunction(
numerator * other, numerator * other,

View File

@ -18,9 +18,9 @@ import space.kscience.kmath.operations.*
* @return product of the multiplicand [arg] and the multiplier [multiplier]. * @return product of the multiplicand [arg] and the multiplier [multiplier].
* @author Gleb Minaev * @author Gleb Minaev
*/ */
internal fun <C> Group<C>.multiplyBySquaring(arg: C, multiplier: Int): C = internal fun <C> Group<C>.multiplyByDoubling(arg: C, multiplier: Int): C =
if (multiplier >= 0) multiplyBySquaring(arg, multiplier.toUInt()) if (multiplier >= 0) multiplyByDoubling(arg, multiplier.toUInt())
else multiplyBySquaring(-arg, (-multiplier).toUInt()) else multiplyByDoubling(-arg, (-multiplier).toUInt())
// FIXME: Move receiver to context receiver // FIXME: Move receiver to context receiver
/** /**
@ -32,9 +32,9 @@ internal fun <C> Group<C>.multiplyBySquaring(arg: C, multiplier: Int): C =
* @return sum of the augend [base] and product of the multiplicand [arg] and the multiplier [multiplier]. * @return sum of the augend [base] and product of the multiplicand [arg] and the multiplier [multiplier].
* @author Gleb Minaev * @author Gleb Minaev
*/ */
internal fun <C> GroupOps<C>.addMultipliedBySquaring(base: C, arg: C, multiplier: Int): C = internal fun <C> GroupOps<C>.addMultipliedByDoubling(base: C, arg: C, multiplier: Int): C =
if (multiplier >= 0) addMultipliedBySquaring(base, arg, multiplier.toUInt()) if (multiplier >= 0) addMultipliedByDoubling(base, arg, multiplier.toUInt())
else addMultipliedBySquaring(base, -arg, (-multiplier).toUInt()) else addMultipliedByDoubling(base, -arg, (-multiplier).toUInt())
// FIXME: Move receiver to context receiver // FIXME: Move receiver to context receiver
/** /**
@ -47,12 +47,12 @@ internal fun <C> GroupOps<C>.addMultipliedBySquaring(base: C, arg: C, multiplier
* @return product of the multiplicand [arg] and the multiplier [multiplier]. * @return product of the multiplicand [arg] and the multiplier [multiplier].
* @author Gleb Minaev * @author Gleb Minaev
*/ */
internal tailrec fun <C> Group<C>.multiplyBySquaring(arg: C, multiplier: UInt): C = internal tailrec fun <C> Group<C>.multiplyByDoubling(arg: C, multiplier: UInt): C =
when { when {
multiplier == 0u -> zero multiplier == 0u -> zero
multiplier == 1u -> arg multiplier == 1u -> arg
multiplier and 1u == 0u -> multiplyBySquaring(arg + arg, multiplier shr 1) multiplier and 1u == 0u -> multiplyByDoubling(arg + arg, multiplier shr 1)
multiplier and 1u == 1u -> addMultipliedBySquaring(arg, arg + arg, multiplier shr 1) multiplier and 1u == 1u -> addMultipliedByDoubling(arg, arg + arg, multiplier shr 1)
else -> error("Error in multiplication group instant by unsigned integer: got reminder by division by 2 different from 0 and 1") else -> error("Error in multiplication group instant by unsigned integer: got reminder by division by 2 different from 0 and 1")
} }
@ -68,12 +68,12 @@ internal tailrec fun <C> Group<C>.multiplyBySquaring(arg: C, multiplier: UInt):
* @return sum of the augend [base] and product of the multiplicand [arg] and the multiplier [multiplier]. * @return sum of the augend [base] and product of the multiplicand [arg] and the multiplier [multiplier].
* @author Gleb Minaev * @author Gleb Minaev
*/ */
internal tailrec fun <C> GroupOps<C>.addMultipliedBySquaring(base: C, arg: C, multiplier: UInt): C = internal tailrec fun <C> GroupOps<C>.addMultipliedByDoubling(base: C, arg: C, multiplier: UInt): C =
when { when {
multiplier == 0u -> base multiplier == 0u -> base
multiplier == 1u -> base + arg multiplier == 1u -> base + arg
multiplier and 1u == 0u -> addMultipliedBySquaring(base, arg + arg, multiplier shr 1) multiplier and 1u == 0u -> addMultipliedByDoubling(base, arg + arg, multiplier shr 1)
multiplier and 1u == 1u -> addMultipliedBySquaring(base + arg, arg + arg, multiplier shr 1) multiplier and 1u == 1u -> addMultipliedByDoubling(base + arg, arg + arg, multiplier shr 1)
else -> error("Error in multiplication group instant by unsigned integer: got reminder by division by 2 different from 0 and 1") else -> error("Error in multiplication group instant by unsigned integer: got reminder by division by 2 different from 0 and 1")
} }
@ -86,9 +86,9 @@ internal tailrec fun <C> GroupOps<C>.addMultipliedBySquaring(base: C, arg: C, mu
* @return [arg] raised to the power [exponent]. * @return [arg] raised to the power [exponent].
* @author Gleb Minaev * @author Gleb Minaev
*/ */
internal fun <C> Field<C>.exponentiationBySquaring(arg: C, exponent: Int): C = internal fun <C> Field<C>.exponentiateBySquaring(arg: C, exponent: Int): C =
if (exponent >= 0) exponentiationBySquaring(arg, exponent.toUInt()) if (exponent >= 0) exponentiateBySquaring(arg, exponent.toUInt())
else exponentiationBySquaring(one / arg, (-exponent).toUInt()) else exponentiateBySquaring(one / arg, (-exponent).toUInt())
// FIXME: Move receiver to context receiver // FIXME: Move receiver to context receiver
/** /**
@ -100,9 +100,9 @@ internal fun <C> Field<C>.exponentiationBySquaring(arg: C, exponent: Int): C =
* @return product of [base] and [arg] raised to the power [exponent]. * @return product of [base] and [arg] raised to the power [exponent].
* @author Gleb Minaev * @author Gleb Minaev
*/ */
internal fun <C> Field<C>.multiplyExponentiationBySquaring(base: C, arg: C, exponent: Int): C = internal fun <C> Field<C>.multiplyExponentiatedBySquaring(base: C, arg: C, exponent: Int): C =
if (exponent >= 0) multiplyExponentiationBySquaring(base, arg, exponent.toUInt()) if (exponent >= 0) multiplyExponentiatedBySquaring(base, arg, exponent.toUInt())
else multiplyExponentiationBySquaring(base, one / arg, (-exponent).toUInt()) else multiplyExponentiatedBySquaring(base, one / arg, (-exponent).toUInt())
// FIXME: Move receiver to context receiver // FIXME: Move receiver to context receiver
/** /**
@ -115,12 +115,12 @@ internal fun <C> Field<C>.multiplyExponentiationBySquaring(base: C, arg: C, expo
* @return [arg] raised to the power [exponent]. * @return [arg] raised to the power [exponent].
* @author Gleb Minaev * @author Gleb Minaev
*/ */
internal tailrec fun <C> Ring<C>.exponentiationBySquaring(arg: C, exponent: UInt): C = internal tailrec fun <C> Ring<C>.exponentiateBySquaring(arg: C, exponent: UInt): C =
when { when {
exponent == 0u -> zero exponent == 0u -> zero
exponent == 1u -> arg exponent == 1u -> arg
exponent and 1u == 0u -> exponentiationBySquaring(arg * arg, exponent shr 1) exponent and 1u == 0u -> exponentiateBySquaring(arg * arg, exponent shr 1)
exponent and 1u == 1u -> multiplyExponentiationBySquaring(arg, arg * arg, exponent shr 1) exponent and 1u == 1u -> multiplyExponentiatedBySquaring(arg, arg * arg, exponent shr 1)
else -> error("Error in multiplication group instant by unsigned integer: got reminder by division by 2 different from 0 and 1") else -> error("Error in multiplication group instant by unsigned integer: got reminder by division by 2 different from 0 and 1")
} }
@ -136,11 +136,11 @@ internal tailrec fun <C> Ring<C>.exponentiationBySquaring(arg: C, exponent: UInt
* @return product of [base] and [arg] raised to the power [exponent]. * @return product of [base] and [arg] raised to the power [exponent].
* @author Gleb Minaev * @author Gleb Minaev
*/ */
internal tailrec fun <C> RingOps<C>.multiplyExponentiationBySquaring(base: C, arg: C, exponent: UInt): C = internal tailrec fun <C> RingOps<C>.multiplyExponentiatedBySquaring(base: C, arg: C, exponent: UInt): C =
when { when {
exponent == 0u -> base exponent == 0u -> base
exponent == 1u -> base * arg exponent == 1u -> base * arg
exponent and 1u == 0u -> multiplyExponentiationBySquaring(base, arg * arg, exponent shr 1) exponent and 1u == 0u -> multiplyExponentiatedBySquaring(base, arg * arg, exponent shr 1)
exponent and 1u == 1u -> multiplyExponentiationBySquaring(base * arg, arg * arg, exponent shr 1) exponent and 1u == 1u -> multiplyExponentiatedBySquaring(base * arg, arg * arg, exponent shr 1)
else -> error("Error in multiplication group instant by unsigned integer: got reminder by division by 2 different from 0 and 1") else -> error("Error in multiplication group instant by unsigned integer: got reminder by division by 2 different from 0 and 1")
} }

View File

@ -271,7 +271,7 @@ public fun <C, A : Ring<C>> LabeledPolynomial<C>.derivativeWithRespectTo(
} }
} }
}, },
multiplyBySquaring(c, degs[variable]!!) multiplyByDoubling(c, degs[variable]!!)
) )
} }
} }
@ -302,7 +302,7 @@ public fun <C, A : Ring<C>> LabeledPolynomial<C>.derivativeWithRespectTo(
} }
} }
}, },
cleanedVariables.fold(c) { acc, variable -> multiplyBySquaring(acc, degs[variable]!!) } cleanedVariables.fold(c) { acc, variable -> multiplyByDoubling(acc, degs[variable]!!) }
) )
} }
} }
@ -335,7 +335,7 @@ public fun <C, A : Ring<C>> LabeledPolynomial<C>.nthDerivativeWithRespectTo(
}, },
degs[variable]!!.let { deg -> degs[variable]!!.let { deg ->
(deg downTo deg - order + 1u) (deg downTo deg - order + 1u)
.fold(c) { acc, ord -> multiplyBySquaring(acc, ord) } .fold(c) { acc, ord -> multiplyByDoubling(acc, ord) }
} }
) )
} }
@ -371,7 +371,7 @@ public fun <C, A : Ring<C>> LabeledPolynomial<C>.nthDerivativeWithRespectTo(
filteredVariablesAndOrders.entries.fold(c) { acc1, (index, order) -> filteredVariablesAndOrders.entries.fold(c) { acc1, (index, order) ->
degs[index]!!.let { deg -> degs[index]!!.let { deg ->
(deg downTo deg - order + 1u) (deg downTo deg - order + 1u)
.fold(acc1) { acc2, ord -> multiplyBySquaring(acc2, ord) } .fold(acc1) { acc2, ord -> multiplyByDoubling(acc2, ord) }
} }
} }
) )
@ -398,7 +398,7 @@ public fun <C, A : Field<C>> LabeledPolynomial<C>.antiderivativeWithRespectTo(
} }
put( put(
newDegs, newDegs,
c / multiplyBySquaring(one, newDegs[variable]!!) c / multiplyByDoubling(one, newDegs[variable]!!)
) )
} }
} }
@ -425,7 +425,7 @@ public fun <C, A : Field<C>> LabeledPolynomial<C>.antiderivativeWithRespectTo(
} }
put( put(
newDegs, newDegs,
cleanedVariables.fold(c) { acc, variable -> acc / multiplyBySquaring(one, newDegs[variable]!!) } cleanedVariables.fold(c) { acc, variable -> acc / multiplyByDoubling(one, newDegs[variable]!!) }
) )
} }
} }
@ -454,7 +454,7 @@ public fun <C, A : Field<C>> LabeledPolynomial<C>.nthAntiderivativeWithRespectTo
newDegs, newDegs,
newDegs[variable]!!.let { deg -> newDegs[variable]!!.let { deg ->
(deg downTo deg - order + 1u) (deg downTo deg - order + 1u)
.fold(c) { acc, ord -> acc / multiplyBySquaring(one, ord) } .fold(c) { acc, ord -> acc / multiplyByDoubling(one, ord) }
} }
) )
} }
@ -485,7 +485,7 @@ public fun <C, A : Field<C>> LabeledPolynomial<C>.nthAntiderivativeWithRespectTo
filteredVariablesAndOrders.entries.fold(c) { acc1, (index, order) -> filteredVariablesAndOrders.entries.fold(c) { acc1, (index, order) ->
newDegs[index]!!.let { deg -> newDegs[index]!!.let { deg ->
(deg downTo deg - order + 1u) (deg downTo deg - order + 1u)
.fold(acc1) { acc2, ord -> acc2 / multiplyBySquaring(one, ord) } .fold(acc1) { acc2, ord -> acc2 / multiplyByDoubling(one, ord) }
} }
} }
) )

View File

@ -322,7 +322,7 @@ public fun <C, A : Ring<C>> NumberedPolynomial<C>.derivativeWithRespectTo(
else -> return@forEach else -> return@forEach
} }
}.cleanUp(), }.cleanUp(),
multiplyBySquaring(c, degs[variable]) multiplyByDoubling(c, degs[variable])
) )
} }
} }
@ -353,7 +353,7 @@ public fun <C, A : Ring<C>> NumberedPolynomial<C>.derivativeWithRespectTo(
else -> return@forEach else -> return@forEach
} }
}.cleanUp(), }.cleanUp(),
cleanedVariables.fold(c) { acc, variable -> multiplyBySquaring(acc, degs[variable]) } cleanedVariables.fold(c) { acc, variable -> multiplyByDoubling(acc, degs[variable]) }
) )
} }
} }
@ -385,7 +385,7 @@ public fun <C, A : Ring<C>> NumberedPolynomial<C>.nthDerivativeWithRespectTo(
}.cleanUp(), }.cleanUp(),
degs[variable].let { deg -> degs[variable].let { deg ->
(deg downTo deg - order + 1u) (deg downTo deg - order + 1u)
.fold(c) { acc, ord -> multiplyBySquaring(acc, ord) } .fold(c) { acc, ord -> multiplyByDoubling(acc, ord) }
} }
) )
} }
@ -418,7 +418,7 @@ public fun <C, A : Ring<C>> NumberedPolynomial<C>.nthDerivativeWithRespectTo(
filteredVariablesAndOrders.entries.fold(c) { acc1, (index, order) -> filteredVariablesAndOrders.entries.fold(c) { acc1, (index, order) ->
degs[index].let { deg -> degs[index].let { deg ->
(deg downTo deg - order + 1u) (deg downTo deg - order + 1u)
.fold(acc1) { acc2, ord -> multiplyBySquaring(acc2, ord) } .fold(acc1) { acc2, ord -> multiplyByDoubling(acc2, ord) }
} }
} }
) )
@ -441,7 +441,7 @@ public fun <C, A : Field<C>> NumberedPolynomial<C>.antiderivativeWithRespectTo(
.forEach { (degs, c) -> .forEach { (degs, c) ->
put( put(
List(max(variable + 1, degs.size)) { if (it != variable) degs[it] else degs[it] + 1u }, List(max(variable + 1, degs.size)) { if (it != variable) degs[it] else degs[it] + 1u },
c / multiplyBySquaring(one, degs[variable]) c / multiplyByDoubling(one, degs[variable])
) )
} }
} }
@ -465,7 +465,7 @@ public fun <C, A : Field<C>> NumberedPolynomial<C>.antiderivativeWithRespectTo(
.forEach { (degs, c) -> .forEach { (degs, c) ->
put( put(
List(max(maxRespectedVariable + 1, degs.size)) { if (it !in variables) degs[it] else degs[it] + 1u }, List(max(maxRespectedVariable + 1, degs.size)) { if (it !in variables) degs[it] else degs[it] + 1u },
cleanedVariables.fold(c) { acc, variable -> acc / multiplyBySquaring(one, degs[variable]) } cleanedVariables.fold(c) { acc, variable -> acc / multiplyByDoubling(one, degs[variable]) }
) )
} }
} }
@ -490,7 +490,7 @@ public fun <C, A : Field<C>> NumberedPolynomial<C>.nthAntiderivativeWithRespectT
List(max(variable + 1, degs.size)) { if (it != variable) degs[it] else degs[it] + order }, List(max(variable + 1, degs.size)) { if (it != variable) degs[it] else degs[it] + order },
degs[variable].let { deg -> degs[variable].let { deg ->
(deg downTo deg - order + 1u) (deg downTo deg - order + 1u)
.fold(c) { acc, ord -> acc / multiplyBySquaring(one, ord) } .fold(c) { acc, ord -> acc / multiplyByDoubling(one, ord) }
} }
) )
} }
@ -518,7 +518,7 @@ public fun <C, A : Field<C>> NumberedPolynomial<C>.nthAntiderivativeWithRespectT
filteredVariablesAndOrders.entries.fold(c) { acc1, (index, order) -> filteredVariablesAndOrders.entries.fold(c) { acc1, (index, order) ->
degs[index].let { deg -> degs[index].let { deg ->
(deg downTo deg - order + 1u) (deg downTo deg - order + 1u)
.fold(acc1) { acc2, ord -> acc2 / multiplyBySquaring(one, ord) } .fold(acc1) { acc2, ord -> acc2 / multiplyByDoubling(one, ord) }
} }
} }
) )

View File

@ -31,47 +31,47 @@ class AlgebraicStubTest {
ExprRing { ExprRing {
assertEquals( assertEquals(
"57", "57",
addMultipliedBySquaring(Expr("57"), Expr("179"), 0u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 0u).expr,
"tried addMultipliedBySquaring(57, 179, 0u)" "tried addMultipliedBySquaring(57, 179, 0u)"
) )
assertEquals( assertEquals(
"(57 + 179)", "(57 + 179)",
addMultipliedBySquaring(Expr("57"), Expr("179"), 1u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 1u).expr,
"tried addMultipliedBySquaring(57, 179, 1u)" "tried addMultipliedBySquaring(57, 179, 1u)"
) )
assertEquals( assertEquals(
"(57 + (179 + 179))", "(57 + (179 + 179))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 2u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 2u).expr,
"tried addMultipliedBySquaring(57, 179, 2u)" "tried addMultipliedBySquaring(57, 179, 2u)"
) )
assertEquals( assertEquals(
"((57 + 179) + (179 + 179))", "((57 + 179) + (179 + 179))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 3u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 3u).expr,
"tried addMultipliedBySquaring(57, 179, 3u)" "tried addMultipliedBySquaring(57, 179, 3u)"
) )
assertEquals( assertEquals(
"(57 + ((179 + 179) + (179 + 179)))", "(57 + ((179 + 179) + (179 + 179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 4u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 4u).expr,
"tried addMultipliedBySquaring(57, 179, 4u)" "tried addMultipliedBySquaring(57, 179, 4u)"
) )
assertEquals( assertEquals(
"((57 + 179) + ((179 + 179) + (179 + 179)))", "((57 + 179) + ((179 + 179) + (179 + 179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 5u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 5u).expr,
"tried addMultipliedBySquaring(57, 179, 5u)" "tried addMultipliedBySquaring(57, 179, 5u)"
) )
assertEquals( assertEquals(
"((57 + (179 + 179)) + ((179 + 179) + (179 + 179)))", "((57 + (179 + 179)) + ((179 + 179) + (179 + 179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 6u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 6u).expr,
"tried addMultipliedBySquaring(57, 179, 6u)" "tried addMultipliedBySquaring(57, 179, 6u)"
) )
assertEquals( assertEquals(
"(((57 + 179) + (179 + 179)) + ((179 + 179) + (179 + 179)))", "(((57 + 179) + (179 + 179)) + ((179 + 179) + (179 + 179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 7u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 7u).expr,
"tried addMultipliedBySquaring(57, 179, 7u)" "tried addMultipliedBySquaring(57, 179, 7u)"
) )
assertEquals( assertEquals(
"(57 + (((179 + 179) + (179 + 179)) + ((179 + 179) + (179 + 179))))", "(57 + (((179 + 179) + (179 + 179)) + ((179 + 179) + (179 + 179))))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 8u).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 8u).expr,
"tried addMultipliedBySquaring(57, 179, 8u)" "tried addMultipliedBySquaring(57, 179, 8u)"
) )
} }
@ -81,47 +81,47 @@ class AlgebraicStubTest {
ExprRing { ExprRing {
assertEquals( assertEquals(
"0", "0",
multiplyBySquaring(Expr("57"), 0u).expr, multiplyByDoubling(Expr("57"), 0u).expr,
"tried multiplyBySquaring(57, 0u)" "tried multiplyBySquaring(57, 0u)"
) )
assertEquals( assertEquals(
"57", "57",
multiplyBySquaring(Expr("57"), 1u).expr, multiplyByDoubling(Expr("57"), 1u).expr,
"tried multiplyBySquaring(57, 1u)" "tried multiplyBySquaring(57, 1u)"
) )
assertEquals( assertEquals(
"(57 + 57)", "(57 + 57)",
multiplyBySquaring(Expr("57"), 2u).expr, multiplyByDoubling(Expr("57"), 2u).expr,
"tried multiplyBySquaring(57, 2u)" "tried multiplyBySquaring(57, 2u)"
) )
assertEquals( assertEquals(
"(57 + (57 + 57))", "(57 + (57 + 57))",
multiplyBySquaring(Expr("57"), 3u).expr, multiplyByDoubling(Expr("57"), 3u).expr,
"tried multiplyBySquaring(57, 3u)" "tried multiplyBySquaring(57, 3u)"
) )
assertEquals( assertEquals(
"((57 + 57) + (57 + 57))", "((57 + 57) + (57 + 57))",
multiplyBySquaring(Expr("57"), 4u).expr, multiplyByDoubling(Expr("57"), 4u).expr,
"tried multiplyBySquaring(57, 4u)" "tried multiplyBySquaring(57, 4u)"
) )
assertEquals( assertEquals(
"(57 + ((57 + 57) + (57 + 57)))", "(57 + ((57 + 57) + (57 + 57)))",
multiplyBySquaring(Expr("57"), 5u).expr, multiplyByDoubling(Expr("57"), 5u).expr,
"tried multiplyBySquaring(57, 5u)" "tried multiplyBySquaring(57, 5u)"
) )
assertEquals( assertEquals(
"((57 + 57) + ((57 + 57) + (57 + 57)))", "((57 + 57) + ((57 + 57) + (57 + 57)))",
multiplyBySquaring(Expr("57"), 6u).expr, multiplyByDoubling(Expr("57"), 6u).expr,
"tried multiplyBySquaring(57, 6u)" "tried multiplyBySquaring(57, 6u)"
) )
assertEquals( assertEquals(
"((57 + (57 + 57)) + ((57 + 57) + (57 + 57)))", "((57 + (57 + 57)) + ((57 + 57) + (57 + 57)))",
multiplyBySquaring(Expr("57"), 7u).expr, multiplyByDoubling(Expr("57"), 7u).expr,
"tried multiplyBySquaring(57, 7u)" "tried multiplyBySquaring(57, 7u)"
) )
assertEquals( assertEquals(
"(((57 + 57) + (57 + 57)) + ((57 + 57) + (57 + 57)))", "(((57 + 57) + (57 + 57)) + ((57 + 57) + (57 + 57)))",
multiplyBySquaring(Expr("57"), 8u).expr, multiplyByDoubling(Expr("57"), 8u).expr,
"tried multiplyBySquaring(57, 8u)" "tried multiplyBySquaring(57, 8u)"
) )
} }
@ -131,87 +131,87 @@ class AlgebraicStubTest {
ExprRing { ExprRing {
assertEquals( assertEquals(
"57", "57",
addMultipliedBySquaring(Expr("57"), Expr("179"), 0).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 0).expr,
"tried addMultipliedBySquaring(57, 179, 0)" "tried addMultipliedBySquaring(57, 179, 0)"
) )
assertEquals( assertEquals(
"(57 + 179)", "(57 + 179)",
addMultipliedBySquaring(Expr("57"), Expr("179"), 1).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 1).expr,
"tried addMultipliedBySquaring(57, 179, 1)" "tried addMultipliedBySquaring(57, 179, 1)"
) )
assertEquals( assertEquals(
"(57 + -179)", "(57 + -179)",
addMultipliedBySquaring(Expr("57"), Expr("179"), -1).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), -1).expr,
"tried addMultipliedBySquaring(57, 179, -1)" "tried addMultipliedBySquaring(57, 179, -1)"
) )
assertEquals( assertEquals(
"(57 + (179 + 179))", "(57 + (179 + 179))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 2).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 2).expr,
"tried addMultipliedBySquaring(57, 179, 2)" "tried addMultipliedBySquaring(57, 179, 2)"
) )
assertEquals( assertEquals(
"(57 + (-179 + -179))", "(57 + (-179 + -179))",
addMultipliedBySquaring(Expr("57"), Expr("179"), -2).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), -2).expr,
"tried addMultipliedBySquaring(57, 179, -2)" "tried addMultipliedBySquaring(57, 179, -2)"
) )
assertEquals( assertEquals(
"((57 + 179) + (179 + 179))", "((57 + 179) + (179 + 179))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 3).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 3).expr,
"tried addMultipliedBySquaring(57, 179, 3)" "tried addMultipliedBySquaring(57, 179, 3)"
) )
assertEquals( assertEquals(
"((57 + -179) + (-179 + -179))", "((57 + -179) + (-179 + -179))",
addMultipliedBySquaring(Expr("57"), Expr("179"), -3).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), -3).expr,
"tried addMultipliedBySquaring(57, 179, -3)" "tried addMultipliedBySquaring(57, 179, -3)"
) )
assertEquals( assertEquals(
"(57 + ((179 + 179) + (179 + 179)))", "(57 + ((179 + 179) + (179 + 179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 4).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 4).expr,
"tried addMultipliedBySquaring(57, 179, 4)" "tried addMultipliedBySquaring(57, 179, 4)"
) )
assertEquals( assertEquals(
"(57 + ((-179 + -179) + (-179 + -179)))", "(57 + ((-179 + -179) + (-179 + -179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), -4).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), -4).expr,
"tried addMultipliedBySquaring(57, 179, -4)" "tried addMultipliedBySquaring(57, 179, -4)"
) )
assertEquals( assertEquals(
"((57 + 179) + ((179 + 179) + (179 + 179)))", "((57 + 179) + ((179 + 179) + (179 + 179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 5).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 5).expr,
"tried addMultipliedBySquaring(57, 179, 5)" "tried addMultipliedBySquaring(57, 179, 5)"
) )
assertEquals( assertEquals(
"((57 + -179) + ((-179 + -179) + (-179 + -179)))", "((57 + -179) + ((-179 + -179) + (-179 + -179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), -5).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), -5).expr,
"tried addMultipliedBySquaring(57, 179, -5)" "tried addMultipliedBySquaring(57, 179, -5)"
) )
assertEquals( assertEquals(
"((57 + (179 + 179)) + ((179 + 179) + (179 + 179)))", "((57 + (179 + 179)) + ((179 + 179) + (179 + 179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 6).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 6).expr,
"tried addMultipliedBySquaring(57, 179, 6)" "tried addMultipliedBySquaring(57, 179, 6)"
) )
assertEquals( assertEquals(
"((57 + (-179 + -179)) + ((-179 + -179) + (-179 + -179)))", "((57 + (-179 + -179)) + ((-179 + -179) + (-179 + -179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), -6).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), -6).expr,
"tried addMultipliedBySquaring(57, 179, -6)" "tried addMultipliedBySquaring(57, 179, -6)"
) )
assertEquals( assertEquals(
"(((57 + 179) + (179 + 179)) + ((179 + 179) + (179 + 179)))", "(((57 + 179) + (179 + 179)) + ((179 + 179) + (179 + 179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 7).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 7).expr,
"tried addMultipliedBySquaring(57, 179, 7)" "tried addMultipliedBySquaring(57, 179, 7)"
) )
assertEquals( assertEquals(
"(((57 + -179) + (-179 + -179)) + ((-179 + -179) + (-179 + -179)))", "(((57 + -179) + (-179 + -179)) + ((-179 + -179) + (-179 + -179)))",
addMultipliedBySquaring(Expr("57"), Expr("179"), -7).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), -7).expr,
"tried addMultipliedBySquaring(57, 179, -7)" "tried addMultipliedBySquaring(57, 179, -7)"
) )
assertEquals( assertEquals(
"(57 + (((179 + 179) + (179 + 179)) + ((179 + 179) + (179 + 179))))", "(57 + (((179 + 179) + (179 + 179)) + ((179 + 179) + (179 + 179))))",
addMultipliedBySquaring(Expr("57"), Expr("179"), 8).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), 8).expr,
"tried addMultipliedBySquaring(57, 179, 8)" "tried addMultipliedBySquaring(57, 179, 8)"
) )
assertEquals( assertEquals(
"(57 + (((-179 + -179) + (-179 + -179)) + ((-179 + -179) + (-179 + -179))))", "(57 + (((-179 + -179) + (-179 + -179)) + ((-179 + -179) + (-179 + -179))))",
addMultipliedBySquaring(Expr("57"), Expr("179"), -8).expr, addMultipliedByDoubling(Expr("57"), Expr("179"), -8).expr,
"tried addMultipliedBySquaring(57, 179, -8)" "tried addMultipliedBySquaring(57, 179, -8)"
) )
} }
@ -221,87 +221,87 @@ class AlgebraicStubTest {
ExprRing { ExprRing {
assertEquals( assertEquals(
"0", "0",
multiplyBySquaring(Expr("57"), 0).expr, multiplyByDoubling(Expr("57"), 0).expr,
"tried multiplyBySquaring(57, 0)" "tried multiplyBySquaring(57, 0)"
) )
assertEquals( assertEquals(
"57", "57",
multiplyBySquaring(Expr("57"), 1).expr, multiplyByDoubling(Expr("57"), 1).expr,
"tried multiplyBySquaring(57, 1)" "tried multiplyBySquaring(57, 1)"
) )
assertEquals( assertEquals(
"-57", "-57",
multiplyBySquaring(Expr("57"), -1).expr, multiplyByDoubling(Expr("57"), -1).expr,
"tried multiplyBySquaring(57, -1)" "tried multiplyBySquaring(57, -1)"
) )
assertEquals( assertEquals(
"(57 + 57)", "(57 + 57)",
multiplyBySquaring(Expr("57"), 2).expr, multiplyByDoubling(Expr("57"), 2).expr,
"tried multiplyBySquaring(57, 2)" "tried multiplyBySquaring(57, 2)"
) )
assertEquals( assertEquals(
"(-57 + -57)", "(-57 + -57)",
multiplyBySquaring(Expr("57"), -2).expr, multiplyByDoubling(Expr("57"), -2).expr,
"tried multiplyBySquaring(57, -2)" "tried multiplyBySquaring(57, -2)"
) )
assertEquals( assertEquals(
"(57 + (57 + 57))", "(57 + (57 + 57))",
multiplyBySquaring(Expr("57"), 3).expr, multiplyByDoubling(Expr("57"), 3).expr,
"tried multiplyBySquaring(57, 3)" "tried multiplyBySquaring(57, 3)"
) )
assertEquals( assertEquals(
"(-57 + (-57 + -57))", "(-57 + (-57 + -57))",
multiplyBySquaring(Expr("57"), -3).expr, multiplyByDoubling(Expr("57"), -3).expr,
"tried multiplyBySquaring(57, -3)" "tried multiplyBySquaring(57, -3)"
) )
assertEquals( assertEquals(
"((57 + 57) + (57 + 57))", "((57 + 57) + (57 + 57))",
multiplyBySquaring(Expr("57"), 4).expr, multiplyByDoubling(Expr("57"), 4).expr,
"tried multiplyBySquaring(57, 4)" "tried multiplyBySquaring(57, 4)"
) )
assertEquals( assertEquals(
"((-57 + -57) + (-57 + -57))", "((-57 + -57) + (-57 + -57))",
multiplyBySquaring(Expr("57"), -4).expr, multiplyByDoubling(Expr("57"), -4).expr,
"tried multiplyBySquaring(57, -4)" "tried multiplyBySquaring(57, -4)"
) )
assertEquals( assertEquals(
"(57 + ((57 + 57) + (57 + 57)))", "(57 + ((57 + 57) + (57 + 57)))",
multiplyBySquaring(Expr("57"), 5).expr, multiplyByDoubling(Expr("57"), 5).expr,
"tried multiplyBySquaring(57, 5)" "tried multiplyBySquaring(57, 5)"
) )
assertEquals( assertEquals(
"(-57 + ((-57 + -57) + (-57 + -57)))", "(-57 + ((-57 + -57) + (-57 + -57)))",
multiplyBySquaring(Expr("57"), -5).expr, multiplyByDoubling(Expr("57"), -5).expr,
"tried multiplyBySquaring(57, -5)" "tried multiplyBySquaring(57, -5)"
) )
assertEquals( assertEquals(
"((57 + 57) + ((57 + 57) + (57 + 57)))", "((57 + 57) + ((57 + 57) + (57 + 57)))",
multiplyBySquaring(Expr("57"), 6).expr, multiplyByDoubling(Expr("57"), 6).expr,
"tried multiplyBySquaring(57, 6)" "tried multiplyBySquaring(57, 6)"
) )
assertEquals( assertEquals(
"((-57 + -57) + ((-57 + -57) + (-57 + -57)))", "((-57 + -57) + ((-57 + -57) + (-57 + -57)))",
multiplyBySquaring(Expr("57"), -6).expr, multiplyByDoubling(Expr("57"), -6).expr,
"tried multiplyBySquaring(57, -6)" "tried multiplyBySquaring(57, -6)"
) )
assertEquals( assertEquals(
"((57 + (57 + 57)) + ((57 + 57) + (57 + 57)))", "((57 + (57 + 57)) + ((57 + 57) + (57 + 57)))",
multiplyBySquaring(Expr("57"), 7).expr, multiplyByDoubling(Expr("57"), 7).expr,
"tried multiplyBySquaring(57, 7)" "tried multiplyBySquaring(57, 7)"
) )
assertEquals( assertEquals(
"((-57 + (-57 + -57)) + ((-57 + -57) + (-57 + -57)))", "((-57 + (-57 + -57)) + ((-57 + -57) + (-57 + -57)))",
multiplyBySquaring(Expr("57"), -7).expr, multiplyByDoubling(Expr("57"), -7).expr,
"tried multiplyBySquaring(57, -7)" "tried multiplyBySquaring(57, -7)"
) )
assertEquals( assertEquals(
"(((57 + 57) + (57 + 57)) + ((57 + 57) + (57 + 57)))", "(((57 + 57) + (57 + 57)) + ((57 + 57) + (57 + 57)))",
multiplyBySquaring(Expr("57"), 8).expr, multiplyByDoubling(Expr("57"), 8).expr,
"tried multiplyBySquaring(57, 8)" "tried multiplyBySquaring(57, 8)"
) )
assertEquals( assertEquals(
"(((-57 + -57) + (-57 + -57)) + ((-57 + -57) + (-57 + -57)))", "(((-57 + -57) + (-57 + -57)) + ((-57 + -57) + (-57 + -57)))",
multiplyBySquaring(Expr("57"), -8).expr, multiplyByDoubling(Expr("57"), -8).expr,
"tried multiplyBySquaring(57, -8)" "tried multiplyBySquaring(57, -8)"
) )
} }
@ -311,47 +311,47 @@ class AlgebraicStubTest {
ExprRing { ExprRing {
assertEquals( assertEquals(
"57", "57",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 0u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 0u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 0u)" "tried multiplyExponentiationBySquaring(57, 179, 0u)"
) )
assertEquals( assertEquals(
"(57 * 179)", "(57 * 179)",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 1u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 1u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 1u)" "tried multiplyExponentiationBySquaring(57, 179, 1u)"
) )
assertEquals( assertEquals(
"(57 * (179 * 179))", "(57 * (179 * 179))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 2u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 2u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 2u)" "tried multiplyExponentiationBySquaring(57, 179, 2u)"
) )
assertEquals( assertEquals(
"((57 * 179) * (179 * 179))", "((57 * 179) * (179 * 179))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 3u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 3u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 3u)" "tried multiplyExponentiationBySquaring(57, 179, 3u)"
) )
assertEquals( assertEquals(
"(57 * ((179 * 179) * (179 * 179)))", "(57 * ((179 * 179) * (179 * 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 4u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 4u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 4u)" "tried multiplyExponentiationBySquaring(57, 179, 4u)"
) )
assertEquals( assertEquals(
"((57 * 179) * ((179 * 179) * (179 * 179)))", "((57 * 179) * ((179 * 179) * (179 * 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 5u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 5u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 5u)" "tried multiplyExponentiationBySquaring(57, 179, 5u)"
) )
assertEquals( assertEquals(
"((57 * (179 * 179)) * ((179 * 179) * (179 * 179)))", "((57 * (179 * 179)) * ((179 * 179) * (179 * 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 6u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 6u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 6u)" "tried multiplyExponentiationBySquaring(57, 179, 6u)"
) )
assertEquals( assertEquals(
"(((57 * 179) * (179 * 179)) * ((179 * 179) * (179 * 179)))", "(((57 * 179) * (179 * 179)) * ((179 * 179) * (179 * 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 7u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 7u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 7u)" "tried multiplyExponentiationBySquaring(57, 179, 7u)"
) )
assertEquals( assertEquals(
"(57 * (((179 * 179) * (179 * 179)) * ((179 * 179) * (179 * 179))))", "(57 * (((179 * 179) * (179 * 179)) * ((179 * 179) * (179 * 179))))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 8u).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 8u).expr,
"tried multiplyExponentiationBySquaring(57, 179, 8u)" "tried multiplyExponentiationBySquaring(57, 179, 8u)"
) )
} }
@ -361,47 +361,47 @@ class AlgebraicStubTest {
ExprRing { ExprRing {
assertEquals( assertEquals(
"0", "0",
exponentiationBySquaring(Expr("57"), 0u).expr, exponentiateBySquaring(Expr("57"), 0u).expr,
"tried exponentiationBySquaring(57, 0u)" "tried exponentiationBySquaring(57, 0u)"
) )
assertEquals( assertEquals(
"57", "57",
exponentiationBySquaring(Expr("57"), 1u).expr, exponentiateBySquaring(Expr("57"), 1u).expr,
"tried exponentiationBySquaring(57, 1u)" "tried exponentiationBySquaring(57, 1u)"
) )
assertEquals( assertEquals(
"(57 * 57)", "(57 * 57)",
exponentiationBySquaring(Expr("57"), 2u).expr, exponentiateBySquaring(Expr("57"), 2u).expr,
"tried exponentiationBySquaring(57, 2u)" "tried exponentiationBySquaring(57, 2u)"
) )
assertEquals( assertEquals(
"(57 * (57 * 57))", "(57 * (57 * 57))",
exponentiationBySquaring(Expr("57"), 3u).expr, exponentiateBySquaring(Expr("57"), 3u).expr,
"tried exponentiationBySquaring(57, 3u)" "tried exponentiationBySquaring(57, 3u)"
) )
assertEquals( assertEquals(
"((57 * 57) * (57 * 57))", "((57 * 57) * (57 * 57))",
exponentiationBySquaring(Expr("57"), 4u).expr, exponentiateBySquaring(Expr("57"), 4u).expr,
"tried exponentiationBySquaring(57, 4u)" "tried exponentiationBySquaring(57, 4u)"
) )
assertEquals( assertEquals(
"(57 * ((57 * 57) * (57 * 57)))", "(57 * ((57 * 57) * (57 * 57)))",
exponentiationBySquaring(Expr("57"), 5u).expr, exponentiateBySquaring(Expr("57"), 5u).expr,
"tried exponentiationBySquaring(57, 5u)" "tried exponentiationBySquaring(57, 5u)"
) )
assertEquals( assertEquals(
"((57 * 57) * ((57 * 57) * (57 * 57)))", "((57 * 57) * ((57 * 57) * (57 * 57)))",
exponentiationBySquaring(Expr("57"), 6u).expr, exponentiateBySquaring(Expr("57"), 6u).expr,
"tried exponentiationBySquaring(57, 6u)" "tried exponentiationBySquaring(57, 6u)"
) )
assertEquals( assertEquals(
"((57 * (57 * 57)) * ((57 * 57) * (57 * 57)))", "((57 * (57 * 57)) * ((57 * 57) * (57 * 57)))",
exponentiationBySquaring(Expr("57"), 7u).expr, exponentiateBySquaring(Expr("57"), 7u).expr,
"tried exponentiationBySquaring(57, 7u)" "tried exponentiationBySquaring(57, 7u)"
) )
assertEquals( assertEquals(
"(((57 * 57) * (57 * 57)) * ((57 * 57) * (57 * 57)))", "(((57 * 57) * (57 * 57)) * ((57 * 57) * (57 * 57)))",
exponentiationBySquaring(Expr("57"), 8u).expr, exponentiateBySquaring(Expr("57"), 8u).expr,
"tried exponentiationBySquaring(57, 8u)" "tried exponentiationBySquaring(57, 8u)"
) )
} }
@ -411,87 +411,87 @@ class AlgebraicStubTest {
ExprRing { ExprRing {
assertEquals( assertEquals(
"57", "57",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 0).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 0).expr,
"tried multiplyExponentiationBySquaring(57, 179, 0)" "tried multiplyExponentiationBySquaring(57, 179, 0)"
) )
assertEquals( assertEquals(
"(57 * 179)", "(57 * 179)",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 1).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 1).expr,
"tried multiplyExponentiationBySquaring(57, 179, 1)" "tried multiplyExponentiationBySquaring(57, 179, 1)"
) )
assertEquals( assertEquals(
"(57 * (1 / 179))", "(57 * (1 / 179))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), -1).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), -1).expr,
"tried multiplyExponentiationBySquaring(57, 179, -1)" "tried multiplyExponentiationBySquaring(57, 179, -1)"
) )
assertEquals( assertEquals(
"(57 * (179 * 179))", "(57 * (179 * 179))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 2).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 2).expr,
"tried multiplyExponentiationBySquaring(57, 179, 2)" "tried multiplyExponentiationBySquaring(57, 179, 2)"
) )
assertEquals( assertEquals(
"(57 * ((1 / 179) * (1 / 179)))", "(57 * ((1 / 179) * (1 / 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), -2).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), -2).expr,
"tried multiplyExponentiationBySquaring(57, 179, -2)" "tried multiplyExponentiationBySquaring(57, 179, -2)"
) )
assertEquals( assertEquals(
"((57 * 179) * (179 * 179))", "((57 * 179) * (179 * 179))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 3).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 3).expr,
"tried multiplyExponentiationBySquaring(57, 179, 3)" "tried multiplyExponentiationBySquaring(57, 179, 3)"
) )
assertEquals( assertEquals(
"((57 * (1 / 179)) * ((1 / 179) * (1 / 179)))", "((57 * (1 / 179)) * ((1 / 179) * (1 / 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), -3).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), -3).expr,
"tried multiplyExponentiationBySquaring(57, 179, -3)" "tried multiplyExponentiationBySquaring(57, 179, -3)"
) )
assertEquals( assertEquals(
"(57 * ((179 * 179) * (179 * 179)))", "(57 * ((179 * 179) * (179 * 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 4).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 4).expr,
"tried multiplyExponentiationBySquaring(57, 179, 4)" "tried multiplyExponentiationBySquaring(57, 179, 4)"
) )
assertEquals( assertEquals(
"(57 * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))))", "(57 * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), -4).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), -4).expr,
"tried multiplyExponentiationBySquaring(57, 179, -4)" "tried multiplyExponentiationBySquaring(57, 179, -4)"
) )
assertEquals( assertEquals(
"((57 * 179) * ((179 * 179) * (179 * 179)))", "((57 * 179) * ((179 * 179) * (179 * 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 5).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 5).expr,
"tried multiplyExponentiationBySquaring(57, 179, 5)" "tried multiplyExponentiationBySquaring(57, 179, 5)"
) )
assertEquals( assertEquals(
"((57 * (1 / 179)) * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))))", "((57 * (1 / 179)) * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), -5).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), -5).expr,
"tried multiplyExponentiationBySquaring(57, 179, -5)" "tried multiplyExponentiationBySquaring(57, 179, -5)"
) )
assertEquals( assertEquals(
"((57 * (179 * 179)) * ((179 * 179) * (179 * 179)))", "((57 * (179 * 179)) * ((179 * 179) * (179 * 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 6).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 6).expr,
"tried multiplyExponentiationBySquaring(57, 179, 6)" "tried multiplyExponentiationBySquaring(57, 179, 6)"
) )
assertEquals( assertEquals(
"((57 * ((1 / 179) * (1 / 179))) * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))))", "((57 * ((1 / 179) * (1 / 179))) * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), -6).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), -6).expr,
"tried multiplyExponentiationBySquaring(57, 179, -6)" "tried multiplyExponentiationBySquaring(57, 179, -6)"
) )
assertEquals( assertEquals(
"(((57 * 179) * (179 * 179)) * ((179 * 179) * (179 * 179)))", "(((57 * 179) * (179 * 179)) * ((179 * 179) * (179 * 179)))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 7).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 7).expr,
"tried multiplyExponentiationBySquaring(57, 179, 7)" "tried multiplyExponentiationBySquaring(57, 179, 7)"
) )
assertEquals( assertEquals(
"(((57 * (1 / 179)) * ((1 / 179) * (1 / 179))) * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))))", "(((57 * (1 / 179)) * ((1 / 179) * (1 / 179))) * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), -7).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), -7).expr,
"tried multiplyExponentiationBySquaring(57, 179, -7)" "tried multiplyExponentiationBySquaring(57, 179, -7)"
) )
assertEquals( assertEquals(
"(57 * (((179 * 179) * (179 * 179)) * ((179 * 179) * (179 * 179))))", "(57 * (((179 * 179) * (179 * 179)) * ((179 * 179) * (179 * 179))))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), 8).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), 8).expr,
"tried multiplyExponentiationBySquaring(57, 179, 8)" "tried multiplyExponentiationBySquaring(57, 179, 8)"
) )
assertEquals( assertEquals(
"(57 * ((((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))) * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179)))))", "(57 * ((((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179))) * (((1 / 179) * (1 / 179)) * ((1 / 179) * (1 / 179)))))",
multiplyExponentiationBySquaring(Expr("57"), Expr("179"), -8).expr, multiplyExponentiatedBySquaring(Expr("57"), Expr("179"), -8).expr,
"tried multiplyExponentiationBySquaring(57, 179, -8)" "tried multiplyExponentiationBySquaring(57, 179, -8)"
) )
} }
@ -501,87 +501,87 @@ class AlgebraicStubTest {
ExprRing { ExprRing {
assertEquals( assertEquals(
"0", "0",
exponentiationBySquaring(Expr("57"), 0).expr, exponentiateBySquaring(Expr("57"), 0).expr,
"tried exponentiationBySquaring(57, 0)" "tried exponentiationBySquaring(57, 0)"
) )
assertEquals( assertEquals(
"57", "57",
exponentiationBySquaring(Expr("57"), 1).expr, exponentiateBySquaring(Expr("57"), 1).expr,
"tried exponentiationBySquaring(57, 1)" "tried exponentiationBySquaring(57, 1)"
) )
assertEquals( assertEquals(
"(1 / 57)", "(1 / 57)",
exponentiationBySquaring(Expr("57"), -1).expr, exponentiateBySquaring(Expr("57"), -1).expr,
"tried exponentiationBySquaring(57, -1)" "tried exponentiationBySquaring(57, -1)"
) )
assertEquals( assertEquals(
"(57 * 57)", "(57 * 57)",
exponentiationBySquaring(Expr("57"), 2).expr, exponentiateBySquaring(Expr("57"), 2).expr,
"tried exponentiationBySquaring(57, 2)" "tried exponentiationBySquaring(57, 2)"
) )
assertEquals( assertEquals(
"((1 / 57) * (1 / 57))", "((1 / 57) * (1 / 57))",
exponentiationBySquaring(Expr("57"), -2).expr, exponentiateBySquaring(Expr("57"), -2).expr,
"tried exponentiationBySquaring(57, -2)" "tried exponentiationBySquaring(57, -2)"
) )
assertEquals( assertEquals(
"(57 * (57 * 57))", "(57 * (57 * 57))",
exponentiationBySquaring(Expr("57"), 3).expr, exponentiateBySquaring(Expr("57"), 3).expr,
"tried exponentiationBySquaring(57, 3)" "tried exponentiationBySquaring(57, 3)"
) )
assertEquals( assertEquals(
"((1 / 57) * ((1 / 57) * (1 / 57)))", "((1 / 57) * ((1 / 57) * (1 / 57)))",
exponentiationBySquaring(Expr("57"), -3).expr, exponentiateBySquaring(Expr("57"), -3).expr,
"tried exponentiationBySquaring(57, -3)" "tried exponentiationBySquaring(57, -3)"
) )
assertEquals( assertEquals(
"((57 * 57) * (57 * 57))", "((57 * 57) * (57 * 57))",
exponentiationBySquaring(Expr("57"), 4).expr, exponentiateBySquaring(Expr("57"), 4).expr,
"tried exponentiationBySquaring(57, 4)" "tried exponentiationBySquaring(57, 4)"
) )
assertEquals( assertEquals(
"(((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57)))", "(((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57)))",
exponentiationBySquaring(Expr("57"), -4).expr, exponentiateBySquaring(Expr("57"), -4).expr,
"tried exponentiationBySquaring(57, -4)" "tried exponentiationBySquaring(57, -4)"
) )
assertEquals( assertEquals(
"(57 * ((57 * 57) * (57 * 57)))", "(57 * ((57 * 57) * (57 * 57)))",
exponentiationBySquaring(Expr("57"), 5).expr, exponentiateBySquaring(Expr("57"), 5).expr,
"tried exponentiationBySquaring(57, 5)" "tried exponentiationBySquaring(57, 5)"
) )
assertEquals( assertEquals(
"((1 / 57) * (((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))))", "((1 / 57) * (((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))))",
exponentiationBySquaring(Expr("57"), -5).expr, exponentiateBySquaring(Expr("57"), -5).expr,
"tried exponentiationBySquaring(57, -5)" "tried exponentiationBySquaring(57, -5)"
) )
assertEquals( assertEquals(
"((57 * 57) * ((57 * 57) * (57 * 57)))", "((57 * 57) * ((57 * 57) * (57 * 57)))",
exponentiationBySquaring(Expr("57"), 6).expr, exponentiateBySquaring(Expr("57"), 6).expr,
"tried exponentiationBySquaring(57, 6)" "tried exponentiationBySquaring(57, 6)"
) )
assertEquals( assertEquals(
"(((1 / 57) * (1 / 57)) * (((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))))", "(((1 / 57) * (1 / 57)) * (((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))))",
exponentiationBySquaring(Expr("57"), -6).expr, exponentiateBySquaring(Expr("57"), -6).expr,
"tried exponentiationBySquaring(57, -6)" "tried exponentiationBySquaring(57, -6)"
) )
assertEquals( assertEquals(
"((57 * (57 * 57)) * ((57 * 57) * (57 * 57)))", "((57 * (57 * 57)) * ((57 * 57) * (57 * 57)))",
exponentiationBySquaring(Expr("57"), 7).expr, exponentiateBySquaring(Expr("57"), 7).expr,
"tried exponentiationBySquaring(57, 7)" "tried exponentiationBySquaring(57, 7)"
) )
assertEquals( assertEquals(
"(((1 / 57) * ((1 / 57) * (1 / 57))) * (((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))))", "(((1 / 57) * ((1 / 57) * (1 / 57))) * (((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))))",
exponentiationBySquaring(Expr("57"), -7).expr, exponentiateBySquaring(Expr("57"), -7).expr,
"tried exponentiationBySquaring(57, -7)" "tried exponentiationBySquaring(57, -7)"
) )
assertEquals( assertEquals(
"(((57 * 57) * (57 * 57)) * ((57 * 57) * (57 * 57)))", "(((57 * 57) * (57 * 57)) * ((57 * 57) * (57 * 57)))",
exponentiationBySquaring(Expr("57"), 8).expr, exponentiateBySquaring(Expr("57"), 8).expr,
"tried exponentiationBySquaring(57, 8)" "tried exponentiationBySquaring(57, 8)"
) )
assertEquals( assertEquals(
"((((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))) * (((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))))", "((((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))) * (((1 / 57) * (1 / 57)) * ((1 / 57) * (1 / 57))))",
exponentiationBySquaring(Expr("57"), -8).expr, exponentiateBySquaring(Expr("57"), -8).expr,
"tried exponentiationBySquaring(57, -8)" "tried exponentiationBySquaring(57, -8)"
) )
} }