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 1 additions and 113 deletions
Showing only changes of commit 75fd920735 - Show all commits

View File

@ -48,21 +48,6 @@ internal constructor(
override fun toString(): String = "LabeledPolynomial$coefficients" override fun toString(): String = "LabeledPolynomial$coefficients"
} }
/**
* Represents internal [LabeledPolynomial] errors.
*/
internal class LabeledPolynomialError: Error {
constructor(): super()
constructor(message: String): super(message)
constructor(message: String?, cause: Throwable?): super(message, cause)
constructor(cause: Throwable?): super(cause)
}
/**
* Throws an [LabeledPolynomialError] with the given [message].
*/
internal fun labeledPolynomialError(message: Any): Nothing = throw LabeledPolynomialError(message.toString())
/** /**
* Returns the same degrees description of the monomial, but without zero degrees. * Returns the same degrees description of the monomial, but without zero degrees.
*/ */

View File

@ -17,21 +17,6 @@ public class LabeledRationalFunction<C>(
override fun toString(): String = "LabeledRationalFunction${numerator.coefficients}/${denominator.coefficients}" override fun toString(): String = "LabeledRationalFunction${numerator.coefficients}/${denominator.coefficients}"
} }
/**
* Represents internal [LabeledRationalFunction] errors.
*/
internal class LabeledRationalFunctionError : Error {
constructor(): super()
constructor(message: String): super(message)
constructor(message: String?, cause: Throwable?): super(message, cause)
constructor(cause: Throwable?): super(cause)
}
/**
* Throws an [LabeledRationalFunctionError] with the given [message].
*/
internal fun labeledRationalFunctionError(message: Any): Nothing = throw LabeledRationalFunctionError(message.toString())
// Waiting for context receivers :( TODO: Replace with context receivers when they will be available // Waiting for context receivers :( TODO: Replace with context receivers when they will be available
//context(RationalFunctionSpace<C, A>) //context(RationalFunctionSpace<C, A>)

View File

@ -48,22 +48,7 @@ internal constructor(
} }
/** /**
* Represents internal [Polynomial] errors. * Returns the same degrees' description of the monomial, but without extra zero degrees on the end.
*/
internal class NumberedPolynomialError : Error {
constructor(): super()
constructor(message: String): super(message)
constructor(message: String?, cause: Throwable?): super(message, cause)
constructor(cause: Throwable?): super(cause)
}
/**
* Throws an [PolynomialError] with the given [message].
*/
internal fun numberedPolynomialError(message: Any): Nothing = throw PolynomialError(message.toString())
/**
* Returns the same degrees description of the monomial, but without extra zero degrees on the end.
*/ */
internal fun List<UInt>.cleanUp() = subList(0, indexOfLast { it != 0U } + 1) internal fun List<UInt>.cleanUp() = subList(0, indexOfLast { it != 0U } + 1)

View File

@ -16,21 +16,6 @@ public class NumberedRationalFunction<C> internal constructor(
override fun toString(): String = "NumberedRationalFunction${numerator.coefficients}/${denominator.coefficients}" override fun toString(): String = "NumberedRationalFunction${numerator.coefficients}/${denominator.coefficients}"
} }
/**
* Represents internal [NumberedRationalFunction] errors.
*/
internal class NumberedRationalFunctionError : Error {
constructor(): super()
constructor(message: String): super(message)
constructor(message: String?, cause: Throwable?): super(message, cause)
constructor(cause: Throwable?): super(cause)
}
/**
* Throws an [NumberedRationalFunctionError] with the given [message].
*/
internal fun numberedRationalFunctionError(message: Any): Nothing = throw NumberedRationalFunctionError(message.toString())
// Waiting for context receivers :( TODO: Replace with context receivers when they will be available // Waiting for context receivers :( TODO: Replace with context receivers when they will be available
//context(RationalFunctionSpace<C, A>) //context(RationalFunctionSpace<C, A>)

View File

@ -43,27 +43,6 @@ public data class Polynomial<C>(
override fun toString(): String = "Polynomial$coefficients" override fun toString(): String = "Polynomial$coefficients"
} }
// region Internal utilities
/**
* Represents internal [Polynomial] errors.
*/
internal class PolynomialError : Error {
constructor(): super()
constructor(message: String): super(message)
constructor(message: String?, cause: Throwable?): super(message, cause)
constructor(cause: Throwable?): super(cause)
}
/**
* Throws an [PolynomialError] with the given [message].
*/
internal fun polynomialError(message: Any): Nothing = throw PolynomialError(message.toString())
// endregion
// region Constructors and converters
/** /**
* Returns a [Polynomial] instance with given [coefficients]. The collection of coefficients will be reversed if * Returns a [Polynomial] instance with given [coefficients]. The collection of coefficients will be reversed if
* [reverse] parameter is true. * [reverse] parameter is true.
@ -82,8 +61,6 @@ public fun <C> Polynomial(vararg coefficients: C, reverse: Boolean = false): Pol
public fun <C> C.asPolynomial() : Polynomial<C> = Polynomial(listOf(this)) public fun <C> C.asPolynomial() : Polynomial<C> = Polynomial(listOf(this))
// endregion
/** /**
* Space of univariate polynomials constructed over ring. * Space of univariate polynomials constructed over ring.
* *
@ -94,8 +71,6 @@ public fun <C> C.asPolynomial() : Polynomial<C> = Polynomial(listOf(this))
public open class PolynomialSpace<C, A : Ring<C>>( public open class PolynomialSpace<C, A : Ring<C>>(
public override val ring: A, public override val ring: A,
) : AbstractPolynomialSpaceOverRing<C, Polynomial<C>, A> { ) : AbstractPolynomialSpaceOverRing<C, Polynomial<C>, A> {
// region Polynomial-integer relation
/** /**
* Returns sum of the polynomial and the integer represented as polynomial. * Returns sum of the polynomial and the integer represented as polynomial.
* *
@ -152,9 +127,7 @@ public open class PolynomialSpace<C, A : Ring<C>>(
.subList(0, degree + 1) .subList(0, degree + 1)
.map { it * other } .map { it * other }
) )
// endregion
// region Integer-polynomial relation
/** /**
* Returns sum of the integer represented as polynomial and the polynomial. * Returns sum of the integer represented as polynomial and the polynomial.
* *
@ -213,9 +186,7 @@ public open class PolynomialSpace<C, A : Ring<C>>(
.subList(0, other.degree + 1) .subList(0, other.degree + 1)
.map { it * this } .map { it * this }
) )
// endregion
// region Constant-polynomial relation
/** /**
* Returns sum of the constant represented as polynomial and the polynomial. * Returns sum of the constant represented as polynomial and the polynomial.
*/ */
@ -270,9 +241,7 @@ public open class PolynomialSpace<C, A : Ring<C>>(
.subList(0, other.degree + 1) .subList(0, other.degree + 1)
.map { it * this } .map { it * this }
) )
// endregion
// region Polynomial-constant relation
/** /**
* Returns sum of the constant represented as polynomial and the polynomial. * Returns sum of the constant represented as polynomial and the polynomial.
*/ */
@ -325,9 +294,7 @@ public open class PolynomialSpace<C, A : Ring<C>>(
.subList(0, degree + 1) .subList(0, degree + 1)
.map { it * other } .map { it * other }
) )
// endregion
// region Polynomial-polynomial relation
/** /**
* Returns negation of the polynomial. * Returns negation of the polynomial.
*/ */
@ -425,9 +392,7 @@ public open class PolynomialSpace<C, A : Ring<C>>(
else false else false
} }
} }
// endregion
// region Polynomial properties
/** /**
* Degree of the polynomial, [see also](https://en.wikipedia.org/wiki/Degree_of_a_polynomial). If the polynomial is * Degree of the polynomial, [see also](https://en.wikipedia.org/wiki/Degree_of_a_polynomial). If the polynomial is
* zero, degree is -1. * zero, degree is -1.
@ -466,8 +431,6 @@ public open class PolynomialSpace<C, A : Ring<C>>(
public inline operator fun Polynomial<C>.invoke(argument: C): C = this.substitute(ring, argument) public inline operator fun Polynomial<C>.invoke(argument: C): C = this.substitute(ring, argument)
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
public inline operator fun Polynomial<C>.invoke(argument: Polynomial<C>): Polynomial<C> = this.substitute(ring, argument) public inline operator fun Polynomial<C>.invoke(argument: Polynomial<C>): Polynomial<C> = this.substitute(ring, argument)
// endregion
} }
/** /**

View File

@ -18,21 +18,6 @@ public data class RationalFunction<C> internal constructor (
override fun toString(): String = "RationalFunction${numerator.coefficients}/${denominator.coefficients}" override fun toString(): String = "RationalFunction${numerator.coefficients}/${denominator.coefficients}"
} }
/**
* Represents internal [RationalFunction] errors.
*/
internal class RationalFunctionError : Error {
constructor(): super()
constructor(message: String): super(message)
constructor(message: String?, cause: Throwable?): super(message, cause)
constructor(cause: Throwable?): super(cause)
}
/**
* Throws an [RationalFunction] with the given [message].
*/
internal fun rationalFunctionError(message: Any): Nothing = throw RationalFunctionError(message.toString())
// Waiting for context receivers :( TODO: Replace with context receivers when they will be available // Waiting for context receivers :( TODO: Replace with context receivers when they will be available
//context(RationalFunctionSpace<C, A>) //context(RationalFunctionSpace<C, A>)