eigenmath/defs.h

347 lines
6.2 KiB
C
Raw Permalink Normal View History

2004-07-24 20:20:56 +02:00
// Symbolic expressions are built by connecting U structs.
//
// For example, (a b + c) is built like this:
//
// _______ _______ _______
2005-06-25 21:29:07 +02:00
// |CONS |--->|CONS |----------------------------->|CONS |
2004-07-24 20:20:56 +02:00
// | | | | | |
// |_______| |_______| |_______|
// | | |
// ___v___ ___v___ _______ _______ ___v___
// |ADD | |CONS |--->|CONS |--->|CONS | |SYM c |
// | | | | | | | | | |
// |_______| |_______| |_______| |_______| |_______|
// | | |
// ___v___ ___v___ ___v___
// |MUL | |SYM a | |SYM b |
// | | | | | |
// |_______| |_______| |_______|
typedef struct U {
union {
struct {
struct U *car; // pointing down
struct U *cdr; // pointing right
} cons;
struct {
struct U *binding; // symbol's value binding
struct U *binding2; // symbol's function binding
} sym;
char *str;
struct tensor *tensor;
struct {
unsigned int *a, *b; // rational number a over b
} q;
double d;
} u;
2005-08-06 22:57:37 +02:00
unsigned char k, tag;
2004-07-24 20:20:56 +02:00
} U;
2005-08-07 16:42:42 +02:00
// the following enum is for struct U, member k
2004-07-24 20:20:56 +02:00
enum {
CONS,
NUM,
DOUBLE,
STR,
TENSOR,
SYM,
2005-08-06 22:57:37 +02:00
};
// the following enum is for indexing the symbol table
enum {
// standard functions first, then nil, then everything else
2004-07-24 20:20:56 +02:00
ABS,
ADD,
ADJ,
2005-09-02 21:41:19 +02:00
AND,
2004-07-24 20:20:56 +02:00
ARCCOS,
ARCCOSH,
ARCSIN,
ARCSINH,
ARCTAN,
ARCTANH,
2005-10-08 04:20:34 +02:00
ARG,
2004-07-24 20:20:56 +02:00
ATOMIZE,
2005-07-30 21:37:29 +02:00
BESSELJ,
BESSELY,
2004-07-24 20:20:56 +02:00
BINDING2,
BINOMIAL,
BREAK,
2005-07-30 21:37:29 +02:00
CARAC,
2004-07-24 20:20:56 +02:00
CEILING,
CHECK,
2006-05-06 01:27:26 +02:00
CIRCEXP,
2004-07-24 20:20:56 +02:00
CLEAR,
CLS,
COEFF,
2006-01-06 04:13:23 +01:00
COFACTOR,
2004-07-24 20:20:56 +02:00
CONDENSE,
CONJ,
CONTRACT,
2005-07-30 21:37:29 +02:00
CONVOLUTION,
2004-07-24 20:20:56 +02:00
COS,
COSH,
2006-05-12 22:17:48 +02:00
DECOMP,
2004-07-24 20:20:56 +02:00
DEGREE,
2005-06-25 21:29:07 +02:00
DENOMINATOR,
2004-07-24 20:20:56 +02:00
DERIVATIVE,
DET,
DIM,
2005-07-30 21:37:29 +02:00
DIRAC,
2004-07-24 20:20:56 +02:00
DISPLAY,
DIVISORS,
DO,
DOT,
DRAW,
DSOLVE,
EIGEN,
EIGENVAL,
EIGENVEC,
2005-07-30 21:37:29 +02:00
ERF,
ERFC,
2004-07-24 20:20:56 +02:00
EVAL,
EXP,
EXPAND,
EXPCOS,
EXPSIN,
FACTOR,
FACTORIAL,
FACTORPOLY,
FILTER,
FLOATF,
FLOOR,
FOR,
2005-07-30 21:37:29 +02:00
FOURIER,
GAMMA,
2004-07-24 20:20:56 +02:00
GCD,
2005-07-30 21:37:29 +02:00
HEAVISIDE,
2004-07-24 20:20:56 +02:00
HERMITE,
HILBERT,
2005-10-08 04:20:34 +02:00
IMAG,
2004-07-24 20:20:56 +02:00
INDEX,
INNER,
INTEGRAL,
INV,
2005-07-30 21:37:29 +02:00
INVFOURIER,
2004-07-24 20:20:56 +02:00
INVG,
ISINTEGER,
ISPRIME,
LAGUERRE,
LCM,
LEGENDRE,
LOG,
2005-10-08 04:20:34 +02:00
MAG,
2004-07-24 20:20:56 +02:00
MOD,
MULTIPLY,
2005-09-02 21:41:19 +02:00
NOT,
2006-01-13 21:52:59 +01:00
NUMBER,
2005-06-25 21:29:07 +02:00
NUMERATOR,
2004-07-24 20:20:56 +02:00
OPERATOR,
2005-09-02 21:41:19 +02:00
OR,
2004-07-24 20:20:56 +02:00
OUTER,
2006-02-10 20:24:36 +01:00
POLAR,
2004-07-24 20:20:56 +02:00
POWER,
PRIME,
PRINT,
PRODUCT,
PROG,
QUOTE,
2006-02-10 01:55:47 +01:00
QUOTIENT,
2004-07-24 20:20:56 +02:00
RANK,
RATIONALIZE,
2005-10-08 04:20:34 +02:00
REAL,
YYRECT,
2004-07-24 20:20:56 +02:00
RETURN,
ROOTS,
SETQ,
2005-07-30 21:37:29 +02:00
SGN,
2005-07-25 22:08:00 +02:00
SIMFAC,
2004-07-24 20:20:56 +02:00
SIMPLIFY,
SIN,
SINH,
SQRT,
STOP,
SUBST,
SUM,
2005-12-15 18:34:38 +01:00
SUMMARIZE,
2004-07-24 20:20:56 +02:00
TAB,
TAN,
TANH,
TAYLOR,
2005-07-30 21:37:29 +02:00
TCHEBYCHEVT,
TCHEBYCHEVU,
2004-07-24 20:20:56 +02:00
TEST,
TESTEQ,
TESTGE,
TESTGT,
TESTLE,
TESTLT,
TRACE,
TRANSPOSE,
UNIT,
ZERO,
2004-03-03 21:24:06 +01:00
2005-08-07 16:42:42 +02:00
NIL, // nil goes here, after standard functions
2004-06-25 02:11:40 +02:00
2005-08-06 22:57:37 +02:00
AUTOEXPAND,
2006-02-10 18:01:28 +01:00
BAKE,
2004-06-25 02:11:40 +02:00
LAST,
2005-08-07 16:42:42 +02:00
TTY,
2005-08-07 19:45:09 +02:00
YYE,
2005-08-07 16:42:42 +02:00
YYLAST,
2006-01-17 01:52:35 +01:00
SECRETX,
2006-05-12 22:17:48 +02:00
METAA,
METAB,
METAX,
2005-08-07 16:42:42 +02:00
// symbols appearing above are printed in roman type
// the following symbols are printed in italic type
2004-06-25 02:11:40 +02:00
PI,
2004-07-22 01:30:24 +02:00
SYMBOL_A,
SYMBOL_B,
2005-07-30 21:37:29 +02:00
SYMBOL_C,
2004-06-25 02:11:40 +02:00
SYMBOL_D,
2005-07-30 21:37:29 +02:00
SYMBOL_N,
2004-06-25 02:11:40 +02:00
SYMBOL_R,
SYMBOL_T,
SYMBOL_X,
SYMBOL_Y,
SYMBOL_Z,
2005-08-06 22:57:37 +02:00
2005-12-15 18:34:38 +01:00
C1,
C2,
C3,
C4,
C5,
C6,
2005-08-07 16:42:42 +02:00
USR_SYMBOLS, // this must be last
2004-06-25 02:11:40 +02:00
};
2005-08-07 19:45:09 +02:00
#define E YYE
2005-08-06 22:57:37 +02:00
#define TOS 1000000
#define BUF 10000
#define MAX_PROGRAM_SIZE 100001
#define MAXPRIMETAB 10000
#define _USE_MATH_DEFINES // for MS C++
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <fcntl.h>
#include <string.h>
#include <setjmp.h>
#include <math.h>
#include <errno.h>
2004-03-03 21:24:06 +01:00
#define MAXDIM 24
typedef struct tensor {
int ndim;
int dim[MAXDIM];
int nelem;
U *elem[1];
} T;
struct display {
int h, w, n;
struct {
int c, x, y;
} a[1]; // a for array
};
2005-09-02 21:41:19 +02:00
struct text_metric {
int ascent, descent, width;
};
2006-05-12 22:17:48 +02:00
#define bind(x,y) symbol(x)->u.sym.binding = y
#define push_binding(p) push((p)->u.sym.binding)
#define pop_binding(p) (p)->u.sym.binding = pop()
2006-01-16 20:37:31 +01:00
#define symbol(x) (symtab + (x))
2004-03-03 21:24:06 +01:00
#define iscons(p) ((p)->k == CONS)
2005-08-06 22:57:37 +02:00
#define isrational(p) ((p)->k == NUM)
#define isdouble(p) ((p)->k == DOUBLE)
#define isnum(p) (isrational(p) || isdouble(p))
2004-03-03 21:24:06 +01:00
#define isstr(p) ((p)->k == STR)
#define istensor(p) ((p)->k == TENSOR)
#define issymbol(p) ((p)->k == SYM)
2005-08-07 16:42:42 +02:00
#define iskeyword(p) (issymbol(p) && symbol_index(p) < NIL)
2004-03-03 21:24:06 +01:00
2006-01-16 20:37:31 +01:00
#define car(p) (iscons(p) ? (p)->u.cons.car : symbol(NIL))
#define cdr(p) (iscons(p) ? (p)->u.cons.cdr : symbol(NIL))
2004-03-03 21:24:06 +01:00
#define caar(p) car(car(p))
#define cadr(p) car(cdr(p))
#define cdar(p) cdr(car(p))
#define cddr(p) cdr(cdr(p))
#define caadr(p) car(car(cdr(p)))
#define caddr(p) car(cdr(cdr(p)))
#define cadar(p) car(cdr(car(p)))
#define cdadr(p) cdr(car(cdr(p)))
#define cddar(p) cdr(cdr(car(p)))
#define cdddr(p) cdr(cdr(cdr(p)))
#define caaddr(p) car(car(cdr(cdr(p))))
#define cadadr(p) car(cdr(car(cdr(p))))
#define caddar(p) car(cdr(cdr(car(p))))
#define cdaddr(p) cdr(car(cdr(cdr(p))))
#define cadddr(p) car(cdr(cdr(cdr(p))))
#define cddddr(p) cdr(cdr(cdr(cdr(p))))
#define caddddr(p) car(cdr(cdr(cdr(cdr(p)))))
#define cadaddr(p) car(cdr(car(cdr(cdr(p)))))
#define cddaddr(p) cdr(cdr(car(cdr(cdr(p)))))
2005-07-30 21:37:29 +02:00
#define caddadr(p) car(cdr(cdr(car(cdr(p)))))
2004-03-03 21:24:06 +01:00
#define cdddaddr(p) cdr(cdr(cdr(car(cdr(cdr(p))))))
#define caddaddr(p) car(cdr(cdr(car(cdr(cdr(p))))))
#define isadd(p) (car(p) == symbol(ADD))
#define ispower(p) (car(p) == symbol(POWER))
#define isfactorial(p) (car(p) == symbol(FACTORIAL))
2005-10-27 19:39:15 +02:00
#define MSIGN(p) (((int *) (p))[-2])
#define MLENGTH(p) (((int *) (p))[-1])
2004-03-03 21:24:06 +01:00
2005-10-27 19:39:15 +02:00
#define MZERO(p) (MLENGTH(p) == 1 && (p)[0] == 0)
#define MEQUAL(p, n) (MLENGTH(p) == 1 && (long long) MSIGN(p) * (p)[0] == (n))
2004-03-03 21:24:06 +01:00
extern int tos;
extern int expanding;
2006-05-06 01:27:26 +02:00
extern int exp_flag;
2004-03-03 21:24:06 +01:00
extern int conjugating;
extern int fmt_x;
extern int fmt_index;
extern int fmt_level;
extern int verbosing;
extern int floating;
extern int primetab[MAXPRIMETAB];
2004-08-28 00:38:58 +02:00
extern int esc_flag;
2005-10-27 19:39:15 +02:00
extern int mtotal;
2005-12-16 02:09:51 +01:00
extern int little_endian;
2006-01-06 23:41:24 +01:00
extern int nsym;
2006-05-31 02:20:57 +02:00
extern int trigmode;
2005-10-27 19:39:15 +02:00
extern char logbuf[];
extern char program_buf[];
2006-01-17 00:48:00 +01:00
extern U symtab[];
2004-03-03 21:24:06 +01:00
extern U *stack[];
2006-01-17 00:48:00 +01:00
extern U **frame;
2004-03-03 21:24:06 +01:00
extern U *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8;
2004-05-14 17:22:08 +02:00
extern U *formal_arg[6];
2004-07-22 01:30:24 +02:00
extern U *zero, *one, *imaginaryunit;
2005-07-30 21:37:29 +02:00
extern U *table_of_fourier;
extern U *meta_a;
extern U *meta_b;
extern U *meta_c;
extern U *meta_n;
extern U *meta_x;
2006-01-06 23:41:24 +01:00
extern U *varlist;
extern U symtab[];
2004-03-03 21:24:06 +01:00
2005-10-27 19:39:15 +02:00
#include "prototypes.h"