diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/AlgebraElements.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/AlgebraElements.kt index 9b430af39..0de2109c4 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/AlgebraElements.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/AlgebraElements.kt @@ -24,9 +24,36 @@ interface MathWrapper { * @param S the type of space */ interface SpaceElement, S : Space> : MathElement, MathWrapper { + /** + * Adds element to this one. + * + * @param b the augend. + * @return the sum. + */ operator fun plus(b: T): I = context.add(unwrap(), b).wrap() + + /** + * Subtracts element from this one. + * + * @param b the subtrahend. + * @return the difference. + */ operator fun minus(b: T): I = context.add(unwrap(), context.multiply(b, -1.0)).wrap() + + /** + * Multiplies this element by number. + * + * @param k the multiplicand. + * @return the product. + */ operator fun times(k: Number): I = context.multiply(unwrap(), k.toDouble()).wrap() + + /** + * Divides this element by number. + * + * @param k the divisor. + * @return the quotient. + */ operator fun div(k: Number): I = context.multiply(unwrap(), 1.0 / k.toDouble()).wrap() } @@ -34,6 +61,12 @@ interface SpaceElement, S : Space> : MathElement * Ring element */ interface RingElement, R : Ring> : SpaceElement { + /** + * Multiplies this element by another one. + * + * @param b the multiplicand. + * @return the product. + */ operator fun times(b: T): I = context.multiply(unwrap(), b).wrap() } @@ -42,5 +75,12 @@ interface RingElement, R : Ring> : SpaceElement, F : Field> : RingElement { override val context: F + + /** + * Divides this element by another one. + * + * @param b the divisor. + * @return the quotient. + */ operator fun div(b: T): I = context.divide(unwrap(), b).wrap() }