Dev #280
@ -24,7 +24,6 @@ import space.kscience.kmath.misc.UnstableKMathAPI
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public interface DoubleDomain : Domain<Double> {
|
||||
|
||||
/**
|
||||
* Global lower edge
|
||||
* @param num axis number
|
||||
|
@ -3,7 +3,10 @@ package space.kscience.kmath.linear
|
||||
import space.kscience.kmath.nd.as1D
|
||||
|
||||
/**
|
||||
* A group of methods to resolve equation A dot X = B, where A and B are matrices or vectors
|
||||
* A group of methods to solve for *X* in equation *X = A <sup>-1</sup> · B*, where *A* and *B* are matrices or
|
||||
* vectors.
|
||||
*
|
||||
* @param T the type of items.
|
||||
*/
|
||||
public interface LinearSolver<T : Any> {
|
||||
/**
|
||||
@ -23,7 +26,7 @@ public interface LinearSolver<T : Any> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert matrix to vector if it is possible
|
||||
* Convert matrix to vector if it is possible.
|
||||
*/
|
||||
public fun <T : Any> Matrix<T>.asVector(): Point<T> =
|
||||
if (this.colNum == 1)
|
||||
@ -31,4 +34,11 @@ public fun <T : Any> Matrix<T>.asVector(): Point<T> =
|
||||
else
|
||||
error("Can't convert matrix with more than one column to vector")
|
||||
|
||||
/**
|
||||
* Creates an n × 1 [VirtualMatrix], where n is the size of the given buffer.
|
||||
*
|
||||
* @param T the type of elements contained in the buffer.
|
||||
* @receiver a buffer.
|
||||
* @return the new matrix.
|
||||
*/
|
||||
public fun <T : Any> Point<T>.asMatrix(): VirtualMatrix<T> = VirtualMatrix(size, 1) { i, _ -> get(i) }
|
||||
|
@ -17,6 +17,8 @@ public typealias Matrix<T> = Structure2D<T>
|
||||
|
||||
/**
|
||||
* Alias or using [Buffer] as a point/vector in a many-dimensional space.
|
||||
*
|
||||
* @param T the type of elements contained in the buffer.
|
||||
*/
|
||||
public typealias Point<T> = Buffer<T>
|
||||
|
||||
|
@ -100,8 +100,8 @@ public fun <T : Any> Algebra<T>.bindSymbol(symbol: Symbol): T = bindSymbol(symbo
|
||||
public inline operator fun <A : Algebra<*>, R> A.invoke(block: A.() -> R): R = run(block)
|
||||
|
||||
/**
|
||||
* Represents linear space without neutral element, i.e. algebraic structure with associative, binary operation [add]
|
||||
* and scalar multiplication [multiply].
|
||||
* Represents group without neutral element (also known as inverse semigroup), i.e. algebraic structure with
|
||||
* associative, binary operation [add].
|
||||
*
|
||||
* @param T the type of element of this semispace.
|
||||
*/
|
||||
@ -177,7 +177,7 @@ public interface GroupOperations<T> : Algebra<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents linear space with neutral element, i.e. algebraic structure with associative, binary operation [add].
|
||||
* Represents group, i.e. algebraic structure with associative, binary operation [add].
|
||||
*
|
||||
* @param T the type of element of this semispace.
|
||||
*/
|
||||
@ -189,8 +189,8 @@ public interface Group<T> : GroupOperations<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents rng, i.e. algebraic structure with associative, binary, commutative operation [add] and associative,
|
||||
* operation [multiply] distributive over [add].
|
||||
* Represents ring without multiplicative and additive identities, i.e. algebraic structure with
|
||||
* associative, binary, commutative operation [add] and associative, operation [multiply] distributive over [add].
|
||||
*
|
||||
* @param T the type of element of this semiring.
|
||||
*/
|
||||
@ -238,7 +238,7 @@ public interface Ring<T> : Group<T>, RingOperations<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents field without identity elements, i.e. algebraic structure with associative, binary, commutative operations
|
||||
* Represents field without without multiplicative and additive identities, i.e. algebraic structure with associative, binary, commutative operations
|
||||
* [add] and [multiply]; binary operation [divide] as multiplication of left operand by reciprocal of right one.
|
||||
*
|
||||
* @param T the type of element of this semifield.
|
||||
@ -276,10 +276,11 @@ public interface FieldOperations<T> : RingOperations<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents field, i.e. algebraic structure with three operations: associative "addition" and "multiplication",
|
||||
* and "division" and their neutral elements.
|
||||
* Represents field, i.e. algebraic structure with three operations: associative, commutative addition and
|
||||
* multiplication, and division. **This interface differs from the eponymous mathematical definition: fields in KMath
|
||||
* also support associative multiplication by scalar.**
|
||||
*
|
||||
* @param T the type of element of this semifield.
|
||||
* @param T the type of element of this field.
|
||||
*/
|
||||
public interface Field<T> : Ring<T>, FieldOperations<T>, ScaleOperations<T>, NumericAlgebra<T> {
|
||||
override fun number(value: Number): T = scale(one, value.toDouble())
|
||||
|
@ -12,8 +12,8 @@ import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sign
|
||||
|
||||
public typealias Magnitude = UIntArray
|
||||
public typealias TBase = ULong
|
||||
private typealias Magnitude = UIntArray
|
||||
private typealias TBase = ULong
|
||||
|
||||
/**
|
||||
* Kotlin Multiplatform implementation of Big Integer numbers (KBigInteger).
|
||||
@ -358,6 +358,9 @@ private fun stripLeadingZeros(mag: Magnitude): Magnitude {
|
||||
return mag.sliceArray(IntRange(0, resSize))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute value of the given value [x].
|
||||
*/
|
||||
public fun abs(x: BigInt): BigInt = x.abs()
|
||||
|
||||
/**
|
||||
|
@ -2,14 +2,28 @@ package space.kscience.kmath.functions
|
||||
|
||||
import space.kscience.kmath.operations.Ring
|
||||
|
||||
/**
|
||||
* Represents piecewise-defined function.
|
||||
*
|
||||
* @param T the piece key type.
|
||||
* @param R the sub-function type.
|
||||
*/
|
||||
public fun interface Piecewise<T, R> {
|
||||
/**
|
||||
* Returns the appropriate sub-function for given piece key.
|
||||
*/
|
||||
public fun findPiece(arg: T): R?
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents piecewise-defined function where all the sub-functions are polynomials.
|
||||
*/
|
||||
public fun interface PiecewisePolynomial<T : Any> : Piecewise<T, Polynomial<T>>
|
||||
|
||||
/**
|
||||
* Ordered list of pieces in piecewise function
|
||||
* Basic [Piecewise] implementation where all the pieces are ordered by the [Comparable] type instances.
|
||||
*
|
||||
* @param T the comparable piece key type.
|
||||
*/
|
||||
public class OrderedPiecewisePolynomial<T : Comparable<T>>(delimiter: T) :
|
||||
PiecewisePolynomial<T> {
|
||||
@ -17,8 +31,10 @@ public class OrderedPiecewisePolynomial<T : Comparable<T>>(delimiter: T) :
|
||||
private val pieces: MutableList<Polynomial<T>> = arrayListOf()
|
||||
|
||||
/**
|
||||
* Dynamically add a piece to the "right" side (beyond maximum argument value of previous piece)
|
||||
* @param right new rightmost position. If is less then current rightmost position, a error is thrown.
|
||||
* Dynamically adds a piece to the right side (beyond maximum argument value of previous piece)
|
||||
*
|
||||
* @param right new rightmost position. If is less then current rightmost position, an error is thrown.
|
||||
* @param piece the sub-function.
|
||||
*/
|
||||
public fun putRight(right: T, piece: Polynomial<T>) {
|
||||
require(right > delimiters.last()) { "New delimiter should be to the right of old one" }
|
||||
@ -26,13 +42,19 @@ public class OrderedPiecewisePolynomial<T : Comparable<T>>(delimiter: T) :
|
||||
pieces.add(piece)
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically adds a piece to the left side (beyond maximum argument value of previous piece)
|
||||
*
|
||||
* @param left the new leftmost position. If is less then current rightmost position, an error is thrown.
|
||||
* @param piece the sub-function.
|
||||
*/
|
||||
public fun putLeft(left: T, piece: Polynomial<T>) {
|
||||
require(left < delimiters.first()) { "New delimiter should be to the left of old one" }
|
||||
delimiters.add(0, left)
|
||||
pieces.add(0, piece)
|
||||
}
|
||||
|
||||
override fun findPiece(arg: T): Polynomial<T>? {
|
||||
public override fun findPiece(arg: T): Polynomial<T>? {
|
||||
if (arg < delimiters.first() || arg >= delimiters.last())
|
||||
return null
|
||||
else {
|
||||
@ -46,7 +68,8 @@ public class OrderedPiecewisePolynomial<T : Comparable<T>>(delimiter: T) :
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a value of polynomial function with given [ring] an given [arg] or null if argument is outside of piecewise definition.
|
||||
* Return a value of polynomial function with given [ring] an given [arg] or null if argument is outside of piecewise
|
||||
* definition.
|
||||
*/
|
||||
public fun <T : Comparable<T>, C : Ring<T>> PiecewisePolynomial<T>.value(ring: C, arg: T): T? =
|
||||
findPiece(arg)?.value(ring, arg)
|
||||
|
@ -15,6 +15,9 @@ import kotlin.math.pow
|
||||
*/
|
||||
public inline class Polynomial<T : Any>(public val coefficients: List<T>)
|
||||
|
||||
/**
|
||||
* Returns a [Polynomial] instance with given [coefficients].
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
public fun <T : Any> Polynomial(vararg coefficients: T): Polynomial<T> = Polynomial(coefficients.toList())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user