Last cosmetic changes.

This commit is contained in:
Gleb Minaev 2022-07-16 22:21:13 +03:00
parent 2d86cf1cc7
commit f48e4483cc
2 changed files with 39 additions and 46 deletions

View File

@ -50,7 +50,7 @@ public data class Polynomial<out C>(
*/
public val coefficients: List<C>
) {
override fun toString(): String = "ListPolynomial$coefficients"
override fun toString(): String = "Polynomial$coefficients"
}
/**
@ -63,7 +63,7 @@ public data class Polynomial<out C>(
*/
public open class PolynomialSpace<C, A>(
/**
* Underlying ring of constants. Its operations on constants are inherited by local operations on constants.
* Underlying ring of constants. Its operations on constants are used by local operations on constants and polynomials.
*/
public val ring: A,
) : Ring<Polynomial<C>>, ScaleOperations<Polynomial<C>> where A : Ring<C>, A : ScaleOperations<C> {
@ -191,15 +191,13 @@ public open class PolynomialSpace<C, A>(
/**
* Returns negation of the polynomial.
*/
public override operator fun Polynomial<C>.unaryMinus(): Polynomial<C> =
with(ring) {
public override operator fun Polynomial<C>.unaryMinus(): Polynomial<C> = ring {
Polynomial(coefficients.map { -it })
}
/**
* Returns sum of the polynomials.
*/
public override operator fun Polynomial<C>.plus(other: Polynomial<C>): Polynomial<C> {
with(ring) {
public override operator fun Polynomial<C>.plus(other: Polynomial<C>): Polynomial<C> = ring {
val thisDegree = degree
val otherDegree = other.degree
return Polynomial(
@ -212,12 +210,10 @@ public open class PolynomialSpace<C, A>(
}
)
}
}
/**
* Returns difference of the polynomials.
*/
public override operator fun Polynomial<C>.minus(other: Polynomial<C>): Polynomial<C> {
with(ring) {
public override operator fun Polynomial<C>.minus(other: Polynomial<C>): Polynomial<C> = ring {
val thisDegree = degree
val otherDegree = other.degree
return Polynomial(
@ -230,12 +226,10 @@ public open class PolynomialSpace<C, A>(
}
)
}
}
/**
* Returns product of the polynomials.
*/
public override operator fun Polynomial<C>.times(other: Polynomial<C>): Polynomial<C> {
with(ring) {
public override operator fun Polynomial<C>.times(other: Polynomial<C>): Polynomial<C> = ring {
val thisDegree = degree
val otherDegree = other.degree
return Polynomial(
@ -246,7 +240,6 @@ public open class PolynomialSpace<C, A>(
}
)
}
}
/**
* Instance of zero polynomial (zero of the polynomial ring).

View File

@ -91,7 +91,7 @@ public fun <C, A> Polynomial<C>.integrate(
public fun <C : Comparable<C>> Polynomial<C>.integrate(
ring: Field<C>,
range: ClosedRange<C>,
): C {
): C = ring {
val antiderivative = integrate(ring)
return ring { antiderivative.value(ring, range.endInclusive) - antiderivative.value(ring, range.start) }
return antiderivative.value(ring, range.endInclusive) - antiderivative.value(ring, range.start)
}