import jscl.math.Generic;
static import jscl.math.Predef.*;

manager = new javax.script.ScriptEngineManager();
engine = manager.getEngineByName("jscl");
importObject(engine);

x = variable("x");
y = variable("y");

assert(eval("groebner({x^2 + y^2 - 4, x*y - 1}, {x, y})")
.equals(14x2x44xx3y));

a = matrix("a", 2);
b = vector("b", 2);
x = vector("x", 2);

assert(eval("matrix({{a[0][0], a[0][1]},"+
                    "{a[1][0], a[1][1]}}, {x[0],"+
                                          "x[1]})-{b[0],"+
                                                  "b[1]}")
.equals(b0a00x0a01x1b1a10x0a11x1));

a = variable("a");
b = variable("b");
c = variable("c");
x = variable("x");

assert(eval("solve(c+b*x+a*x^2,x)")
.equals(root0cba));

assert(eval("subst(1/x^2,x,a)")
.equals(1a2));

assert(eval("simplify(exp(sqrt(-1)*pi))")
.equals(-1));

assert(eval("simplify(elementary(cos(x)^2+sin(x)^2))")
.equals(1));

assert(eval("numeric(exp(1))")
.equals(2.718281828459045));

f = function("f", 0);
f_ = function("f", 1);

assert(eval("d(cos(f(x)),x)")
.equals(f′xfx));

z = variable("z");
f = function("f", new int[] {0,0,0});
f_1_0_0 = function("f", new int[] {1,0,0});
f_0_1_0 = function("f", new int[] {0,1,0});
f_0_0_1 = function("f", new int[] {0,0,1});

assert(eval("curl(grad(f(x,y,z),{x,y,z}),{x,y,z})")
.equals(000));

assert(eval("taylor(exp(x),x,0,4)")
.equals(1x12x216x3124x4));

assert(eval("integral(1/(1+x^2),x)")
.equals(root010412xroot0104root110412xroot1104));

assert(eval("quote(integral(1/(1+x^2),x))")
.equals(x11x2));

man = variable("man");
mortal = variable("mortal");
sokrates = variable("sokrates");

assert(eval("groebner({sokrates*(1+man), man*(1+mortal)}, {man, mortal, sokrates}, lex, 2)")
.equals(manmanmortalsokratesmansokratessokratesmortalsokrates));

assert(eval("factorize(sokrates+mortal*sokrates)").expand()
.equals(sokrates1mortal));