<divclass="content sourceset-depenent-content"data-active=""data-togglable=":kmath-ast:dokkaHtmlPartial/commonMain"><pclass="paragraph">Extensions to MST API: transformations, dynamic compilation and visualization.</p><ul><li><pclass="paragraph">src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt : Expression language and its parser</p></li><li><pclass="paragraph">src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt : Dynamic MST to JVM bytecode compiler</p></li><li><pclass="paragraph">src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt : Dynamic MST to JS compiler</p></li><li><pclass="paragraph">src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt : Extendable MST rendering</p></li></ul><h2class=""> Artifact:</h2><pclass="paragraph">The Maven coordinates of this project are <codeclass="lang-kotlin">space.kscience:kmath-ast:0.3.0</code>.</p><pclass="paragraph"><strong>Gradle Groovy:</strong></p><divclass="sample-container"><pre><codeclass="block lang-groovy"theme="idea">repositories {<br> maven { url 'https://repo.kotlin.link' }<br> mavenCentral()<br>}<br><br>dependencies {<br> implementation 'space.kscience:kmath-ast:0.3.0'<br>}</code></pre><spanclass="top-right-position"><spanclass="copy-icon"></span><divclass="copy-popup-wrapper popup-to-left"><spanclass="copy-popup-icon"></span><span>Content copied to clipboard</span></div></span></div><pclass="paragraph"><strong>Gradle Kotlin DSL:</strong></p><divclass="sample-container"><pre><codeclass="block lang-kotlin"theme="idea">repositories {<br> maven("https://repo.kotlin.link")<br> mavenCentral()<br>}<br><br>dependencies {<br> implementation("space.kscience:kmath-ast:0.3.0")<br>}</code></pre><spanclass="top-right-position"><spanclass="copy-icon"></span><divclass="copy-popup-wrapper popup-to-left"><spanclass="copy-popup-icon"></span><span>Content copied to clipboard</span></div></span></div><h2class=""> Parsing expressions</h2><pclass="paragraph">In this module there is a parser from human-readable strings like <codeclass="lang-kotlin">"x^3-x+3"</code> (in the more specific reference/ArithmeticsEvaluator.g4) to MST instances.</p><pclass="paragraph">Supported literals:</p><ol><li><pclass="paragraph">Constants and variables (consist of latin letters, digits and underscores, can't start with digit): <codeclass="lang-kotlin">x</code>, <codeclass="lang-kotlin">_Abc2</code>.</p></li><li><pclass="paragraph">Numbers: <codeclass="lang-kotlin">123</code>, <codeclass="lang-kotlin">1.02</code>, <codeclass="lang-kotlin">1e10</code>, <codeclass="lang-kotlin">1e-10</code>, <codeclass="lang-kotlin">1.0e+3</code>—all parsed either as <codeclass="lang-kotlin">kotlin.Long</code> or <codeclass="lang-kotlin">kotlin.Double</code>.</p></li></ol><pclass="paragraph">Supported binary operators (from the highest precedence to the lowest one):</p><ol><li><pclass="paragraph"><codeclass="lang-kotlin">^</code></p></li><li><pclass="paragraph"><codeclass="lang-kotlin">*</code>, <codeclass="lang-kotlin">/</code></p></li><li><pclass="paragraph"><codeclass="lang-kotlin">+</code>, <codeclass="lang-kotlin">-</code></p></li></ol><pclass="paragraph">Supported unary operator:</p><ol><li><pclass="paragraph"><codeclass="lang-kotlin">-</code>, e. g. <codeclass="lang-kotlin">-x</code></p></li></ol><pclass="paragraph">Arbitrary unary and binary functions are also supported: names consist of latin letters, digits and underscores, can't start with digit. Examples:</p><ol><li><pclass="paragraph"><codeclass="lang-kotlin">sin(x)</code></p></li><li><pclass="paragraph"><codeclass="lang-kotlin">add(x, y)</code></p></li></ol><h2class=""> Dynamic expression code generation</h2><h3class=""> On JVM</h3><pclass="paragraph"><codeclass="lang-kotlin">kmath-ast</code> JVM module supports runtime code generation to eliminate overhead of tree traversal. Code generator builds a special implementation of <codeclass="lang-kotlin">Expression<T></code> with implemented <codeclass="lang-kotlin">invoke</code> function.</p>