diff --git a/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt b/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt index 7b5e1565d..9b34426f7 100644 --- a/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt +++ b/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt @@ -4,6 +4,7 @@ import kscience.kmath.asm.compile import kscience.kmath.expressions.invoke import kscience.kmath.expressions.symbol import kscience.kmath.kotlingrad.DifferentiableMstExpression +import kscience.kmath.kotlingrad.derivative import kscience.kmath.operations.RealField /** @@ -14,7 +15,7 @@ fun main() { val x by symbol val actualDerivative = DifferentiableMstExpression(RealField, "x^2-4*x-44".parseMath()) - .derivativeOrNull(listOf(x)) + .derivative(x) .compile() val expectedDerivative = MstExpression(RealField, "2*x-4".parseMath()).compile() diff --git a/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt b/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt index 88cc20639..ddfc7cccb 100644 --- a/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt +++ b/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt @@ -5,6 +5,7 @@ import kscience.kmath.ast.MST import kscience.kmath.ast.MstAlgebra import kscience.kmath.ast.MstExpression import kscience.kmath.expressions.DifferentiableExpression +import kscience.kmath.expressions.StringSymbol import kscience.kmath.expressions.Symbol import kscience.kmath.operations.NumericAlgebra @@ -46,6 +47,15 @@ public inline class DifferentiableMstExpression(public val expr: MstExpres ) } +public fun > DifferentiableMstExpression.derivative(symbols: List): MstExpression = + derivativeOrNull(symbols) + +public fun > DifferentiableMstExpression.derivative(vararg symbols: Symbol): MstExpression = + derivative(symbols.toList()) + +public fun > DifferentiableMstExpression.derivative(name: String): MstExpression = + derivative(StringSymbol(name)) + /** * Wraps this [MstExpression] into [DifferentiableMstExpression]. */