[package]
[Java implementation]
[Execution output]
ExpressionTest
import church.util.Entry;
import church.util.HashMap;
import Expression;
import church.math.operators.Transcendental;
log(Expression: a) = app("log", a);
exp(Expression: a) = app("exp", a);
sqrt(Expression: a) = app("sqrt", a);
sin(Expression: a) = app("sin", a);
cos(Expression: a) = app("cos", a);
tan(Expression: a) = app("tan", a);
asin(Expression: a) = app("asin", a);
acos(Expression: a) = app("acos", a);
atan(Expression: a) = app("atan", a);
funNameToFunction(name) = {
"log" −> log,
"exp" −> exp,
"sqrt" −> sqrt,
"sin" −> sin,
"cos" −> cos,
"tan" −> tan,
"asin" −> asin,
"acos" −> acos,
"atan" −> atan
}.get(name);foo(x) = cos(x ^ 2.0 + const(1.0));test(funNameToFunction, fn, x0, expectedFp0) = {
varName = "x";
varNameToValue = name −> if name == varName then x0 else error("Undefined variable");
x = var(varName);f = fn(x);
output << "f(x) = " << f << "\n";
f0 = evaluate(funNameToFunction, f, varNameToValue);
output << "f(1) = " << f0 << "\n";
output << "\n";
}
void: main(String[]: args) = {
test(funNameToFunction, foo, 1.0, -1.8185948536513634)
}