[package] [Java implementation] [Execution output]


TranscendentalDerivativeTest


import church.util.Entry;
import church.util.HashMap;

import Expression;
import Derivative;

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);

funNameToDerivative(name) = {
    t1 = multiplicative_identity; // 1 or 1.0 or ...
    t2 = t1 + t1;                 // 2 or 2.0 or ...
    e1 = const(t1);               // const(1) or const(1.0) or ...
    e2 = const(t2);               // const(2) or const(2.0) or ...
    {
        "log"  −> (x −> e1/x),
        "exp"  −> (x −> exp(x)),
        "sqrt" −> (x −> e1 / (e2 * sqrt(x))),

        "sin"  −> (x −>  cos(x)),
        "cos"  −> (x −> -sin(x)),
        "tan"  −> (x −>  e1 / cos(x)^t2),

        "asin" −> (x −>  e1 / sqrt(e1 - x^t2)),
        "acos" −> (x −> -e1 / sqrt(e1 - x^t2)),
        "atan" −> (x −>  e1 / (e1 + x^t2))
    }.get(name);
}

//foo(x) = x * x + (x * x + const(1.0)) / x + const(2.0) * x + const(3.0);
//foo(x) = acos(x * sin(x) + multiplicative_identity);
//foo(x) = tan(x) + const(1.0);
//foo(x) = x * x + const(1.0);
foo(x) = cos(x ^ 2.0 + const(1.0));
//foo(x) = x * x + multiplicative_identity;
//foo(x) = x^3.0 + const(2.0) * x^2.0 + const(3.0) * x + const(4.0);

void: main(String[]: args) = {
    DerivativeTest.test(funNameToFunction, funNameToDerivative, foo, 1.0, -1.8185948536513634)
}