I've just finished testing new symbolic API for km...
# mathematics
a
I've just finished testing new symbolic API for kmath and would like to have a feedback. The API was inspired by https://github.com/mipt-npm/kmath/issues/149 and other discussions with @breandan. Most of the code is available here: https://github.com/mipt-npm/kmath/blob/feature/diff-api/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt. The example usage is here: https://github.com/mipt-npm/kmath/blob/feature/diff-api/kmath-core/src/commonTest/kotlin/kscience/kmath/expressions/SimpleAutoDiffTest.kt and here: https://github.com/mipt-npm/kmath/blob/feature/diff-api/kmath-commons/src/test/kotlin/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt. The API is based on two concepts:
Symbol
and
Expression
. The symbol is just a symbol - some object with a string identity. Two symbols with the same identity are considered to be the same even if they are two different instances. The symbol in general does not store any value. When we need to use a Symbol inside some kmath context (for example different flavors of autodiff), we need to bind this symbol to the context (in autodiff it is done via
bind
method). Some symbold could not be bound to a context and binding will throw a runtime exception (in theory it could be done in a type-safe way, but I am not sure I want to do it now). The binding is unavoidable since many operations (like autodiffs) require forward variable declaration. The second part of the API is the
Expression
. Basically it is just a function that takes bindings (
Map<Symbol, T>
) and produces a result. In case of Autodiff, Expression solves the problem of forward variable declaration since it allows to do late-binding of Symbols (binding is done when the expression is called, not when it is created). I expect to use the same symbols for fitting API.
👍 3