2004-05-14 17:22:08 +02:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
init(void)
|
|
|
|
{
|
2007-06-29 00:34:34 +02:00
|
|
|
int i;
|
2006-01-16 20:37:31 +01:00
|
|
|
static int flag;
|
|
|
|
|
2008-05-18 21:34:03 +02:00
|
|
|
tos = 0;
|
2007-08-04 02:51:53 +02:00
|
|
|
esc_flag = 0;
|
|
|
|
draw_flag = 0;
|
|
|
|
frame = stack + TOS;
|
|
|
|
|
2008-04-14 02:20:00 +02:00
|
|
|
p0 = symbol(NIL);
|
2006-01-16 20:37:31 +01:00
|
|
|
p1 = symbol(NIL);
|
|
|
|
p2 = symbol(NIL);
|
|
|
|
p3 = symbol(NIL);
|
|
|
|
p4 = symbol(NIL);
|
|
|
|
p5 = symbol(NIL);
|
|
|
|
p6 = symbol(NIL);
|
|
|
|
p7 = symbol(NIL);
|
|
|
|
p8 = symbol(NIL);
|
2008-04-14 02:20:00 +02:00
|
|
|
p9 = symbol(NIL);
|
2004-05-14 17:22:08 +02:00
|
|
|
|
2008-05-18 18:38:17 +02:00
|
|
|
if (flag)
|
|
|
|
return; // already initted
|
|
|
|
|
|
|
|
flag = 1;
|
|
|
|
|
2007-06-29 00:34:34 +02:00
|
|
|
for (i = 0; i < NSYM; i++) {
|
|
|
|
symtab[i].k = SYM;
|
|
|
|
binding[i] = symtab + i;
|
|
|
|
arglist[i] = symbol(NIL);
|
|
|
|
}
|
2005-07-30 21:37:29 +02:00
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("abs", ABS);
|
|
|
|
std_symbol("add", ADD);
|
|
|
|
std_symbol("adj", ADJ);
|
2005-09-02 21:41:19 +02:00
|
|
|
std_symbol("and", AND);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("arccos", ARCCOS);
|
|
|
|
std_symbol("arccosh", ARCCOSH);
|
|
|
|
std_symbol("arcsin", ARCSIN);
|
|
|
|
std_symbol("arcsinh", ARCSINH);
|
|
|
|
std_symbol("arctan", ARCTAN);
|
|
|
|
std_symbol("arctanh", ARCTANH);
|
2005-10-08 04:20:34 +02:00
|
|
|
std_symbol("arg", ARG);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("besselj", BESSELJ);
|
|
|
|
std_symbol("bessely", BESSELY);
|
2008-08-10 21:06:41 +02:00
|
|
|
std_symbol("binding", BINDING);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("binomial", BINOMIAL);
|
|
|
|
std_symbol("ceiling", CEILING);
|
|
|
|
std_symbol("check", CHECK);
|
2006-10-13 17:43:11 +02:00
|
|
|
std_symbol("choose", CHOOSE);
|
2006-05-06 01:27:26 +02:00
|
|
|
std_symbol("circexp", CIRCEXP);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("clear", CLEAR);
|
2007-05-09 02:06:24 +02:00
|
|
|
std_symbol("clock", CLOCK);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("coeff", COEFF);
|
2006-01-06 04:13:23 +01:00
|
|
|
std_symbol("cofactor", COFACTOR);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("condense", CONDENSE);
|
|
|
|
std_symbol("conj", CONJ);
|
|
|
|
std_symbol("contract", CONTRACT);
|
|
|
|
std_symbol("cos", COS);
|
|
|
|
std_symbol("cosh", COSH);
|
2006-05-12 22:17:48 +02:00
|
|
|
std_symbol("decomp", DECOMP);
|
2007-05-15 18:20:30 +02:00
|
|
|
std_symbol("defint", DEFINT);
|
2006-02-11 00:39:56 +01:00
|
|
|
std_symbol("deg", DEGREE);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("denominator", DENOMINATOR);
|
|
|
|
std_symbol("det", DET);
|
|
|
|
std_symbol("derivative", DERIVATIVE);
|
|
|
|
std_symbol("dim", DIM);
|
|
|
|
std_symbol("dirac", DIRAC);
|
|
|
|
std_symbol("display", DISPLAY);
|
|
|
|
std_symbol("divisors", DIVISORS);
|
|
|
|
std_symbol("do", DO);
|
|
|
|
std_symbol("dot", DOT);
|
|
|
|
std_symbol("draw", DRAW);
|
|
|
|
std_symbol("dsolve", DSOLVE);
|
|
|
|
std_symbol("erf", ERF);
|
|
|
|
std_symbol("erfc", ERFC);
|
|
|
|
std_symbol("eigen", EIGEN);
|
|
|
|
std_symbol("eigenval", EIGENVAL);
|
|
|
|
std_symbol("eigenvec", EIGENVEC);
|
|
|
|
std_symbol("eval", EVAL);
|
|
|
|
std_symbol("exp", EXP);
|
|
|
|
std_symbol("expand", EXPAND);
|
|
|
|
std_symbol("expcos", EXPCOS);
|
|
|
|
std_symbol("expsin", EXPSIN);
|
|
|
|
std_symbol("factor", FACTOR);
|
|
|
|
std_symbol("factorial", FACTORIAL);
|
|
|
|
std_symbol("factorpoly", FACTORPOLY);
|
|
|
|
std_symbol("filter", FILTER);
|
|
|
|
std_symbol("float", FLOATF);
|
|
|
|
std_symbol("floor", FLOOR);
|
|
|
|
std_symbol("for", FOR);
|
|
|
|
std_symbol("Gamma", GAMMA);
|
|
|
|
std_symbol("gcd", GCD);
|
|
|
|
std_symbol("hermite", HERMITE);
|
|
|
|
std_symbol("hilbert", HILBERT);
|
2005-10-08 04:20:34 +02:00
|
|
|
std_symbol("imag", IMAG);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("component", INDEX);
|
|
|
|
std_symbol("inner", INNER);
|
|
|
|
std_symbol("integral", INTEGRAL);
|
|
|
|
std_symbol("inv", INV);
|
|
|
|
std_symbol("invg", INVG);
|
|
|
|
std_symbol("isinteger", ISINTEGER);
|
|
|
|
std_symbol("isprime", ISPRIME);
|
|
|
|
std_symbol("laguerre", LAGUERRE);
|
2008-08-23 22:30:37 +02:00
|
|
|
// std_symbol("laplace", LAPLACE);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("lcm", LCM);
|
2008-05-03 07:23:17 +02:00
|
|
|
std_symbol("leading", LEADING);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("legendre", LEGENDRE);
|
|
|
|
std_symbol("log", LOG);
|
2005-10-08 04:20:34 +02:00
|
|
|
std_symbol("mag", MAG);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("mod", MOD);
|
|
|
|
std_symbol("multiply", MULTIPLY);
|
2005-09-02 21:41:19 +02:00
|
|
|
std_symbol("not", NOT);
|
2007-11-18 02:08:12 +01:00
|
|
|
std_symbol("nroots", NROOTS);
|
2006-01-13 21:52:59 +01:00
|
|
|
std_symbol("number", NUMBER);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("numerator", NUMERATOR);
|
|
|
|
std_symbol("operator", OPERATOR);
|
2005-09-02 21:41:19 +02:00
|
|
|
std_symbol("or", OR);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("outer", OUTER);
|
2006-02-10 20:24:36 +01:00
|
|
|
std_symbol("polar", POLAR);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("power", POWER);
|
|
|
|
std_symbol("prime", PRIME);
|
|
|
|
std_symbol("print", PRINT);
|
|
|
|
std_symbol("product", PRODUCT);
|
|
|
|
std_symbol("quote", QUOTE);
|
2006-02-10 01:55:47 +01:00
|
|
|
std_symbol("quotient", QUOTIENT);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("rank", RANK);
|
|
|
|
std_symbol("rationalize", RATIONALIZE);
|
2005-10-08 04:20:34 +02:00
|
|
|
std_symbol("real", REAL);
|
|
|
|
std_symbol("rect", YYRECT);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("roots", ROOTS);
|
|
|
|
std_symbol("equals", SETQ);
|
|
|
|
std_symbol("sgn", SGN);
|
|
|
|
std_symbol("simplify", SIMPLIFY);
|
|
|
|
std_symbol("sin", SIN);
|
|
|
|
std_symbol("sinh", SINH);
|
|
|
|
std_symbol("sqrt", SQRT);
|
|
|
|
std_symbol("stop", STOP);
|
|
|
|
std_symbol("subst", SUBST);
|
|
|
|
std_symbol("sum", SUM);
|
|
|
|
std_symbol("tan", TAN);
|
|
|
|
std_symbol("tanh", TANH);
|
|
|
|
std_symbol("taylor", TAYLOR);
|
|
|
|
std_symbol("test", TEST);
|
|
|
|
std_symbol("testeq", TESTEQ);
|
|
|
|
std_symbol("testge", TESTGE);
|
|
|
|
std_symbol("testgt", TESTGT);
|
|
|
|
std_symbol("testle", TESTLE);
|
|
|
|
std_symbol("testlt", TESTLT);
|
|
|
|
std_symbol("transpose", TRANSPOSE);
|
|
|
|
std_symbol("unit", UNIT);
|
|
|
|
std_symbol("zero", ZERO);
|
2004-05-14 17:22:08 +02:00
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("nil", NIL);
|
2004-05-14 17:22:08 +02:00
|
|
|
|
2006-05-12 22:17:48 +02:00
|
|
|
// each symbol needs a unique name because equal() compares printnames
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("autoexpand", AUTOEXPAND);
|
2006-02-10 18:01:28 +01:00
|
|
|
std_symbol("bake", BAKE);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("last", LAST);
|
2007-07-21 22:30:51 +02:00
|
|
|
std_symbol("trace", TRACE);
|
2005-08-07 16:42:42 +02:00
|
|
|
std_symbol("tty", TTY);
|
2008-05-23 18:16:15 +02:00
|
|
|
|
|
|
|
std_symbol("~", YYE); // tilde so sort puts it after other symbols
|
|
|
|
|
|
|
|
std_symbol("$DRAWX", DRAWX); // special purpose internal symbols
|
|
|
|
std_symbol("$METAA", METAA);
|
|
|
|
std_symbol("$METAB", METAB);
|
|
|
|
std_symbol("$METAX", METAX);
|
|
|
|
std_symbol("$SECRETX", SECRETX);
|
2005-08-07 16:42:42 +02:00
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("pi", PI);
|
|
|
|
std_symbol("a", SYMBOL_A);
|
|
|
|
std_symbol("b", SYMBOL_B);
|
|
|
|
std_symbol("c", SYMBOL_C);
|
|
|
|
std_symbol("d", SYMBOL_D);
|
2007-05-02 21:54:17 +02:00
|
|
|
std_symbol("i", SYMBOL_I);
|
|
|
|
std_symbol("j", SYMBOL_J);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("n", SYMBOL_N);
|
|
|
|
std_symbol("r", SYMBOL_R);
|
2008-04-20 00:36:37 +02:00
|
|
|
std_symbol("s", SYMBOL_S);
|
2005-08-06 22:57:37 +02:00
|
|
|
std_symbol("t", SYMBOL_T);
|
|
|
|
std_symbol("x", SYMBOL_X);
|
|
|
|
std_symbol("y", SYMBOL_Y);
|
|
|
|
std_symbol("z", SYMBOL_Z);
|
2004-06-25 22:45:15 +02:00
|
|
|
|
2005-12-15 18:34:38 +01:00
|
|
|
std_symbol("$C1", C1);
|
|
|
|
std_symbol("$C2", C2);
|
|
|
|
std_symbol("$C3", C3);
|
|
|
|
std_symbol("$C4", C4);
|
|
|
|
std_symbol("$C5", C5);
|
|
|
|
std_symbol("$C6", C6);
|
|
|
|
|
2004-05-14 17:22:08 +02:00
|
|
|
push_integer(0);
|
2005-08-07 19:45:09 +02:00
|
|
|
zero = pop(); // must be untagged in gc
|
2004-05-14 17:22:08 +02:00
|
|
|
|
|
|
|
push_integer(1);
|
2005-08-07 19:45:09 +02:00
|
|
|
one = pop(); // must be untagged in gc
|
2004-05-14 17:22:08 +02:00
|
|
|
|
|
|
|
push_symbol(POWER);
|
|
|
|
push_integer(-1);
|
|
|
|
push_rational(1, 2);
|
|
|
|
list(3);
|
2005-08-07 19:45:09 +02:00
|
|
|
imaginaryunit = pop(); // must be untagged in gc
|
2004-05-14 17:22:08 +02:00
|
|
|
|
2004-06-19 19:37:23 +02:00
|
|
|
defn();
|
2004-05-14 17:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *defn_str[] = {
|
2006-08-19 04:23:53 +02:00
|
|
|
"e=exp(1)",
|
2004-06-25 22:45:15 +02:00
|
|
|
"i=sqrt(-1)",
|
2004-05-14 17:22:08 +02:00
|
|
|
"autoexpand=1",
|
|
|
|
"trange=(-pi,pi)",
|
|
|
|
"xrange=(-10,10)",
|
|
|
|
"yrange=(-10,10)",
|
2006-06-02 18:03:42 +02:00
|
|
|
"last=0",
|
2007-07-21 22:30:51 +02:00
|
|
|
"trace=0",
|
2004-05-14 17:22:08 +02:00
|
|
|
"tty=0",
|
2007-05-02 16:20:26 +02:00
|
|
|
"cross(u,v)=(u[2]*v[3]-u[3]*v[2],u[3]*v[1]-u[1]*v[3],u[1]*v[2]-u[2]*v[1])",
|
2004-08-13 17:35:57 +02:00
|
|
|
"curl(v)=(d(v[3],y)-d(v[2],z),d(v[1],z)-d(v[3],x),d(v[2],x)-d(v[1],y))",
|
|
|
|
"div(v)=d(v[1],x)+d(v[2],y)+d(v[3],z)",
|
2006-10-13 18:45:28 +02:00
|
|
|
"ln(x)=log(x)",
|
2004-05-14 17:22:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
defn(void)
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
n = sizeof defn_str / sizeof (char *);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
scan(defn_str[i]);
|
|
|
|
eval();
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
}
|