
commonMain.space.kscience.kmath.operations.AlgebraElements.kt Maven / Gradle / Ivy
package space.kscience.kmath.operations
import space.kscience.kmath.misc.UnstableKMathAPI
/**
* The generic mathematics elements which is able to store its context
*
* @param C the type of mathematical context for this element.
* @param T the type wrapped by this wrapper.
*/
public interface AlgebraElement> {
/**
* The context this element belongs to.
*/
public val context: C
}
/**
* Divides this element by number.
*
* @param k the divisor.
* @return the quotient.
*/
public operator fun , S : Space> T.div(k: Number): T =
context.multiply(this, 1.0 / k.toDouble())
/**
* Multiplies this element by number.
*
* @param k the multiplicand.
* @return the product.
*/
public operator fun , S : Space> T.times(k: Number): T =
context.multiply(this, k.toDouble())
/**
* Subtracts element from this one.
*
* @param b the subtrahend.
* @return the difference.
*/
public operator fun , S : Space> T.minus(b: T): T =
context.add(this, context.multiply(b, -1.0))
/**
* Adds element to this one.
*
* @param b the augend.
* @return the sum.
*/
public operator fun , S : Space> T.plus(b: T): T =
context.add(this, b)
/**
* Number times element
*/
public operator fun , S : Space> Number.times(element: T): T =
element.times(this)
/**
* Multiplies this element by another one.
*
* @param b the multiplicand.
* @return the product.
*/
public operator fun , R : Ring> T.times(b: T): T =
context.multiply(this, b)
/**
* Divides this element by another one.
*
* @param b the divisor.
* @return the quotient.
*/
public operator fun , F : Field> T.div(b: T): T =
context.divide(this, b)
/**
* The element of [Space].
*
* @param T the type of space operation results.
* @param I self type of the element. Needed for static type checking.
* @param S the type of space.
*/
@UnstableKMathAPI
public interface SpaceElement, S : Space> : AlgebraElement
/**
* The element of [Ring].
*
* @param T the type of ring operation results.
* @param I self type of the element. Needed for static type checking.
* @param R the type of ring.
*/
@UnstableKMathAPI
public interface RingElement, R : Ring> : SpaceElement
/**
* The element of [Field].
*
* @param T the type of field operation results.
* @param I self type of the element. Needed for static type checking.
* @param F the type of field.
*/
@UnstableKMathAPI
public interface FieldElement, F : Field> : RingElement
© 2015 - 2025 Weber Informatics LLC | Privacy Policy