Rule preprocessor - axkr/symja_android_library GitHub Wiki
Translate rewriting rules
The RulePreprocessor.java can be used to translate files with term rewriting rules from the /rules folder into Java interfaces in the package org.matheclipse.core.reflection.system.rules
For example for the Cos function the rules can be added like this:
...
import org.matheclipse.core.reflection.system.rules.CosRules;
...
private final static class Cos extends ... implements ..., CosRules {
...
...
@Override
public IAST getRuleAST() {
return RULES;
}
@Override
public void setUp(final ISymbol newSymbol) {
newSymbol.setAttributes(ISymbol.LISTABLE | ISymbol.NUMERICFUNCTION);
// call AbstractFunctionEvaluator#setUp() to initialize rules
super.setUp(newSymbol);
}
}
Using embedded rules
With the ExprPreprocessor.java tool you can convert embedded math expressions into Java source code.
In the example from the TrigToExp
function the Symja expression 2/(E^x-E^(-x))
MATCHER.caseOf(Csch(x_), //
x -> // [$ 2/(E^x-E^(-x)) $]
F.Null); // $$);
will be converted into the Symja Java source code
MATCHER.caseOf(Csch(x_), //
x -> // [$ 2/(E^x-E^(-x)) $]
F.Times(F.C2, F.Power(F.Plus(F.Negate(F.Power(F.E, F.Negate(x))), F.Power(F.E, x)), -1))); // $$);
Note: the );
characters behind the closing // $$
tag will be appended to the generated source code.
After running the ExprPreprocessor
you can use the Eclipse menu "Copy qualified name" for the file which you would like to convert. Input the qualified Java file name for converting the expressions into Java source and refresh the file in the Eclipse editor.
▶ /java_codegen/src/main/java/org/matheclipse/core/reflection/system/TrigToExp.java