1 // Evaluate an expression, for example...
55 // evaluate symbol's binding
66 if (!issymbol(car(p1
)))
69 switch (symnum(car(p1
))) {
70 case ABS
: eval_abs(); break;
71 case ADD
: eval_add(); break;
72 case ADJ
: eval_adj(); break;
73 case AND
: eval_and(); break;
74 case ARCCOS
: eval_arccos(); break;
75 case ARCCOSH
: eval_arccosh(); break;
76 case ARCSIN
: eval_arcsin(); break;
77 case ARCSINH
: eval_arcsinh(); break;
78 case ARCTAN
: eval_arctan(); break;
79 case ARCTANH
: eval_arctanh(); break;
80 case ARG
: eval_arg(); break;
81 case ATOMIZE
: eval_atomize(); break;
82 //case BESSELJ: eval_besselj(); break;
83 //case BESSELY: eval_bessely(); break;
84 case BINDING
: eval_binding(); break;
85 case BINOMIAL
: eval_binomial(); break;
86 case CEILING
: eval_ceiling(); break;
87 case CHECK
: eval_check(); break;
88 case CHOOSE
: eval_choose(); break;
89 case CIRCEXP
: eval_circexp(); break;
90 case CLEAR
: eval_clear(); break;
91 case CLOCK
: eval_clock(); break;
92 case COEFF
: eval_coeff(); break;
93 case COFACTOR
: eval_cofactor(); break;
94 case CONDENSE
: eval_condense(); break;
95 case CONJ
: eval_conj(); break;
96 case CONTRACT
: eval_contract(); break;
97 case COS
: eval_cos(); break;
98 case COSH
: eval_cosh(); break;
99 case DECOMP
: eval_decomp(); break;
100 case DEGREE
: eval_degree(); break;
101 case DEFINT
: eval_defint(); break;
102 case DENOMINATOR
: eval_denominator(); break;
103 case DERIVATIVE
: eval_derivative(); break;
104 case DET
: eval_det(); break;
105 case DIM
: eval_dim(); break;
106 case DIRAC
: eval_dirac(); break;
107 //case DISPLAY: eval_display(); break;
108 case DIVISORS
: eval_divisors(); break;
109 case DO
: eval_do(); break;
110 case DOT
: eval_inner(); break;
111 //case DRAW: eval_draw(); break;
112 case DSOLVE
: eval_dsolve(); break;
113 case EIGEN
: eval_eigen(); break;
114 case EIGENVAL
: eval_eigenval(); break;
115 case EIGENVEC
: eval_eigenvec(); break;
116 case ERF
: eval_erf(); break;
117 case ERFC
: eval_erfc(); break;
118 case EVAL
: eval_eval(); break;
119 case EXP
: eval_exp(); break;
120 case EXPAND
: eval_expand(); break;
121 case EXPCOS
: eval_expcos(); break;
122 case EXPSIN
: eval_expsin(); break;
123 case FACTOR
: eval_factor(); break;
124 case FACTORIAL
: eval_factorial(); break;
125 case FACTORPOLY
: eval_factorpoly(); break;
126 case FILTER
: eval_filter(); break;
127 case FLOATF
: eval_float(); break;
128 case FLOOR
: eval_floor(); break;
129 case FOR
: eval_for(); break;
130 case GAMMA
: eval_gamma(); break;
131 case GCD
: eval_gcd(); break;
132 case HERMITE
: eval_hermite(); break;
133 case HILBERT
: eval_hilbert(); break;
134 case IMAG
: eval_imag(); break;
135 case INDEX
: eval_index(); break;
136 case INNER
: eval_inner(); break;
137 case INTEGRAL
: eval_integral(); break;
138 case INV
: eval_inv(); break;
139 case INVG
: eval_invg(); break;
140 case ISINTEGER
: eval_isinteger(); break;
141 case ISPRIME
: eval_isprime(); break;
142 case LAGUERRE
: eval_laguerre(); break;
143 // case LAPLACE: eval_laplace(); break;
144 case LCM
: eval_lcm(); break;
145 case LEADING
: eval_leading(); break;
146 case LEGENDRE
: eval_legendre(); break;
147 case LOG
: eval_log(); break;
148 case MAG
: eval_mag(); break;
149 case MOD
: eval_mod(); break;
150 case MULTIPLY
: eval_multiply(); break;
151 case NOT
: eval_not(); break;
152 case NROOTS
: eval_nroots(); break;
153 case NUMBER
: eval_number(); break;
154 case NUMERATOR
: eval_numerator(); break;
155 case OPERATOR
: eval_operator(); break;
156 case OR
: eval_or(); break;
157 case OUTER
: eval_outer(); break;
158 case POLAR
: eval_polar(); break;
159 case POWER
: eval_power(); break;
160 case PRIME
: eval_prime(); break;
161 case PRINT
: eval_display(); break;
162 case PRODUCT
: eval_product(); break;
163 case QUOTE
: eval_quote(); break;
164 case QUOTIENT
: eval_quotient(); break;
165 // case RANDOM: eval_random(); break; // by gbl08ma
166 case RANK
: eval_rank(); break;
167 case RATIONALIZE
: eval_rationalize(); break;
168 case REAL
: eval_real(); break;
169 case YYRECT
: eval_rect(); break;
170 case ROOTS
: eval_roots(); break;
171 case SETQ
: eval_setq(); break;
172 case SGN
: eval_sgn(); break;
173 case SIMPLIFY
: eval_simplify(); break;
174 case SIN
: eval_sin(); break;
175 case SINH
: eval_sinh(); break;
176 case SQRT
: eval_sqrt(); break;
177 case STOP
: eval_stop(); break;
178 case SUBST
: eval_subst(); break;
179 case SUM
: eval_sum(); break;
180 case TAN
: eval_tan(); break;
181 case TANH
: eval_tanh(); break;
182 case TAYLOR
: eval_taylor(); break;
183 case TEST
: eval_test(); break;
184 case TESTEQ
: eval_testeq(); break;
185 case TESTGE
: eval_testge(); break;
186 case TESTGT
: eval_testgt(); break;
187 case TESTLE
: eval_testle(); break;
188 case TESTLT
: eval_testlt(); break;
189 case TRANSPOSE
: eval_transpose(); break;
190 case UNIT
: eval_unit(); break;
191 case ZERO
: eval_zero(); break;
192 default: eval_user_function(); break;
199 push(get_binding(cadr(p1
)));
202 // checks a predicate, i.e. check(A = B)
211 stop("check(arg): arg is zero");
212 push(symbol(NIL
)); // no result is printed
230 if (iscons(cddr(p1
))) {
237 push_integer(1); // dim of scalar is 1
238 else if (n
< 1 || n
> p2
->u
.tensor
->ndim
)
241 push_integer(p2
->u
.tensor
->dim
[n
- 1]);
277 // for example, eval(f,x,2)
313 eval_factorpoly(void)
360 index_function(tos
- h
);
386 if (isrational(p1
)) {
401 push_symbol(ISINTEGER
);
426 if (p1
->k
== NUM
|| p1
->k
== DOUBLE
)
436 push_symbol(OPERATOR
);
453 if (equaln(get_binding(symbol(TTY
)), 1))
475 push_integer(p1
->u
.tensor
->ndim
);
480 //-----------------------------------------------------------------------------
484 // p1 *-------*-----------------------*
486 // setq *-------*-------* b
492 //-----------------------------------------------------------------------------
500 stop("indexed assignment: error in symbol");
510 set_component(tos
- h
);
519 if (caadr(p1
) == symbol(INDEX
)) {
524 if (iscons(cadr(p1
))) {
525 define_user_function();
529 if (!issymbol(cadr(p1
)))
530 stop("symbol assignment: error in symbol");
535 set_binding(cadr(p1
), p2
);
579 p1
= alloc_tensor(n
* n
);
580 p1
->u
.tensor
->ndim
= 2;
581 p1
->u
.tensor
->dim
[0] = n
;
582 p1
->u
.tensor
->dim
[1] = n
;
583 for (i
= 0; i
< n
; i
++)
584 p1
->u
.tensor
->elem
[n
* i
+ i
] = one
;
597 // like eval() except "=" is evaluated as "=="
604 if (car(p1
) == symbol(SETQ
))