Merge to update docs and contributions #504

Merged
altavir merged 199 commits from dev into master 2022-10-03 20:58:00 +03:00
2 changed files with 20 additions and 0 deletions
Showing only changes of commit 5b8d6b601e - Show all commits

View File

@ -471,6 +471,18 @@ public open class NumberedPolynomialSpace<C, A : Ring<C>>(
}
}
}
/**
* Counts degree of the polynomial by the specified [variable].
*/
public fun NumberedPolynomial<C>.degreeBy(variable: Int): UInt =
coefficients.entries.maxOfOrNull { (degs, c) -> if (c.isZero()) 0u else degs.getOrElse(variable) { 0u } } ?: 0u
/**
* Counts degree of the polynomial by the specified [variables].
*/
public fun NumberedPolynomial<C>.degreeBy(variables: Collection<Int>): UInt =
coefficients.entries.maxOfOrNull { (degs, c) ->
if (c.isZero()) 0u else degs.withIndex().filter { (index, _) -> index in variables }.sumOf { it.value }
} ?: 0u
/**
* Count of variables occurring in the polynomial with positive power. If there is no such variable,
* the result is `0`.

View File

@ -126,6 +126,14 @@ public class NumberedRationalFunctionSpace<C, A: Ring<C>> (
* And last index of the list is [lastVariable].
*/
public val NumberedPolynomial<C>.degrees: List<UInt> get() = polynomialRing { degrees }
/**
* Counts degree of the polynomial by the specified [variable].
*/
public fun NumberedPolynomial<C>.degreeBy(variable: Int): UInt = polynomialRing { degreeBy(variable) }
/**
* Counts degree of the polynomial by the specified [variables].
*/
public fun NumberedPolynomial<C>.degreeBy(variables: Collection<Int>): UInt = polynomialRing { degreeBy(variables) }
/**
* Count of variables occurring in the polynomial with positive power. If there is no such variable,
* the result is `0`.