algebrite
Version:
Computer Algebra System in Coffeescript
1,882 lines (1,250 loc) • 798 kB
JavaScript
// Generated by CoffeeScript 2.5.1
(function() {
/* arg =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
z
General description
-------------------
Returns the angle of complex z.
*/
/*
Argument (angle) of complex z
z arg(z)
- ------
a 0
-a -pi See note 3 below
(-1)^a a pi
exp(a + i b) b
a b arg(a) + arg(b)
a + i b arctan(b/a)
Result by quadrant
z arg(z)
- ------
1 + i 1/4 pi
1 - i -1/4 pi
-1 + i 3/4 pi
-1 - i -3/4 pi
Notes
1. Handles mixed polar and rectangular forms, e.g. 1 + exp(i pi/3)
2. Symbols in z are assumed to be positive and real.
3. Negative direction adds -pi to angle.
Example: z = (-1)^(1/3), abs(z) = 1/3 pi, abs(-z) = -2/3 pi
4. jean-francois.debroux reports that when z=(a+i*b)/(c+i*d) then
arg(numerator(z)) - arg(denominator(z))
must be used to get the correct answer. Now the operation is
automatic.
*/
/*
Returns the coefficient of the imaginary part of complex z
z imag(z)
- -------
a + i b b
exp(i a) sin(a)
*/
/* Power function
Input: push Base
push Exponent
Output: Result on stack
*/
/*
Convert complex z to rectangular form
Input: push z
Output: Result on stack
*/
/* det =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
m
General description
-------------------
Returns the determinant of matrix m.
Uses Gaussian elimination for numerical matrices.
Example:
det(((1,2),(3,4)))
> -2
*/
/* adj =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
m
General description
-------------------
Returns the adjunct of matrix m. The inverse of m is equal to adj(m) divided by det(m).
*/
/*
Guesses a rational for each float in the passed expression
*/
/* arccos =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the inverse cosine of x.
*/
/* arccosh =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the inverse hyperbolic cosine of x.
*/
/* arcsin =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the inverse sine of x.
*/
/* arcsinh =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the inverse hyperbolic sine of x.
*/
/* arctan =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the inverse tangent of x.
*/
/* arctanh =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the inverse hyperbolic tangent of x.
*/
/* besselj =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x,n
General description
-------------------
Returns a solution to the Bessel differential equation (Bessel function of first kind).
Recurrence relation:
besselj(x,n) = (2/x) (n-1) besselj(x,n-1) - besselj(x,n-2)
besselj(x,1/2) = sqrt(2/pi/x) sin(x)
besselj(x,-1/2) = sqrt(2/pi/x) cos(x)
For negative n, reorder the recurrence relation as:
besselj(x,n-2) = (2/x) (n-1) besselj(x,n-1) - besselj(x,n)
Substitute n+2 for n to obtain
besselj(x,n) = (2/x) (n+1) besselj(x,n+1) - besselj(x,n+2)
Examples:
besselj(x,3/2) = (1/x) besselj(x,1/2) - besselj(x,-1/2)
besselj(x,-3/2) = -(1/x) besselj(x,-1/2) - besselj(x,1/2)
*/
/* bessely =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x,n
General description
-------------------
Bessel function of second kind.
*/
/* ceiling =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the smallest integer not less than x.
*/
/* check =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
p
General description
-------------------
Returns whether the predicate p is true/false or unknown:
0 if false, 1 if true or remains unevaluated if unknown.
Note that if "check" is passed an assignment, it turns it into a test,
i.e. check(a = b) is turned into check(a==b)
so "a" is not assigned anything.
Like in many programming languages, "check" also gives truthyness/falsyness
for numeric values. In which case, "true" is returned for non-zero values.
Potential improvements: "check" can't evaluate strings yet.
*/
/* choose =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
n,k
General description
-------------------
Returns the number of combinations of n items taken k at a time.
For example, the number of five card hands is choose(52,5)
```
n!
choose(n,k) = -------------
k! (n - k)!
```
*/
/* circexp =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns expression x with circular and hyperbolic functions converted to exponential forms. Sometimes this will simplify an expression.
*/
/* clear =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Completely wipes a variable from the environment (while doing x = quote(x) just unassigns it).
*/
/* clearall =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
General description
-------------------
Completely wipes all variables from the environment.
*/
/* cofactor =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
m,i,j
General description
-------------------
Cofactor of a matrix component.
Let c be the cofactor matrix of matrix m, i.e. tranpose(c) = adj(m).
This function returns c[i,j].
*/
/* conj =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
z
General description
-------------------
Returns the complex conjugate of z.
*/
/* contract =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
a,i,j
General description
-------------------
Contract across tensor indices i.e. returns "a" summed over indices i and j.
If i and j are omitted then 1 and 2 are used.
contract(m) is equivalent to the trace of matrix m.
*/
/* cosh =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the hyperbolic cosine of x
```
exp(x) + exp(-x)
cosh(x) = ----------------
2
```
*/
/* deg =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
p,x
General description
-------------------
Returns the degree of polynomial p(x).
*/
/* denominator =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns the denominator of expression x.
*/
/* dim =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
m,n
General description
-------------------
Returns the cardinality of the nth index of tensor "m".
*/
/* do =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
a,b,...
General description
-------------------
Evaluates each argument from left to right. Returns the result of the last argument.
*/
/* eigenval =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
m
General description
-------------------
Compute eigenvalues of m. See "eigen" for more info.
*/
/* eigenvec =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
m
General description
-------------------
Compute eigenvectors of m. See "eigen" for more info.
*/
/* erf =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Authors
-------
philippe.billet@noos.fr
Parameters
----------
x
General description
-------------------
Error function erf(x).
erf(-x)=erf(x)
*/
/*
Remove terms that involve a given symbol or expression. For example...
filter(x^2 + x + 1, x) => 1
filter(x^2 + x + 1, x^2) => x + 1
*/
/* dot =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
a,b,...
General description
-------------------
The inner (or dot) operator gives products of vectors,
matrices, and tensors.
Note that for Algebrite, the elements of a vector/matrix
can only be scalars. This allows for example to flesh out
matrix multiplication using the usual multiplication.
So for example block-representations are not allowed.
There is an aweful lot of confusion between sw packages on
what dot and inner do.
First off, the "dot" operator is different from the
mathematical notion of dot product, which can be
slightly confusing.
The mathematical notion of dot product is here:
http://mathworld.wolfram.com/DotProduct.html
However, "dot" does that and a bunch of other things,
i.e. in Algebrite
dot/inner does what the dot of Mathematica does, i.e.:
scalar product of vectors:
inner((a, b, c), (x, y, z))
> a x + b y + c z
products of matrices and vectors:
inner(((a, b), (c,d)), (x, y))
> (a x + b y,c x + d y)
inner((x, y), ((a, b), (c,d)))
> (a x + c y,b x + d y)
inner((x, y), ((a, b), (c,d)), (r, s))
> a r x + b s x + c r y + d s y
matrix product:
inner(((a,b),(c,d)),((r,s),(t,u)))
> ((a r + b t,a s + b u),(c r + d t,c s + d u))
the "dot/inner" operator is associative and
distributive but not commutative.
In Mathematica, Inner is a generalisation of Dot where
the user can specify the multiplication and the addition
operators.
But here in Algebrite they do the same thing.
https://reference.wolfram.com/language/ref/Dot.html
https://reference.wolfram.com/language/ref/Inner.html
http://uk.mathworks.com/help/matlab/ref/dot.html
http://uk.mathworks.com/help/matlab/ref/mtimes.html
*/
/*
Laguerre function
Example
laguerre(x,3)
Result
1 3 3 2
- --- x + --- x - 3 x + 1
6 2
The computation uses the following recurrence relation.
L(x,0,k) = 1
L(x,1,k) = -x + k + 1
n*L(x,n,k) = (2*(n-1)+1-x+k)*L(x,n-1,k) - (n-1+k)*L(x,n-2,k)
In the "for" loop i = n-1 so the recurrence relation becomes
(i+1)*L(x,n,k) = (2*i+1-x+k)*L(x,n-1,k) - (i+k)*L(x,n-2,k)
*/
/*
Return the leading coefficient of a polynomial.
Example
leading(5x^2+x+1,x)
Result
5
The result is undefined if P is not a polynomial.
*/
/*
Legendre function
Example
legendre(x,3,0)
Result
5 3 3
--- x - --- x
2 2
The computation uses the following recurrence relation.
P(x,0) = 1
P(x,1) = x
n*P(x,n) = (2*(n-1)+1)*x*P(x,n-1) - (n-1)*P(x,n-2)
In the "for" loop we have i = n-1 so the recurrence relation becomes
(i+1)*P(x,n) = (2*i+1)*x*P(x,n-1) - i*P(x,n-2)
For m > 0
P(x,n,m) = (-1)^m * (1-x^2)^(m/2) * d^m/dx^m P(x,n)
*/
/*
Convert complex z to polar form
Input: push z
Output: Result on stack
polar(z) = abs(z) * exp(i * arg(z))
*/
/*
Returns the real part of complex z
z real(z)
- -------
a + i b a
exp(i a) cos(a)
*/
/*
Taylor expansion of a function
push(F)
push(X)
push(N)
push(A)
taylor()
*/
/*
// up to 100 blocks of 100,000 atoms
#define M 100
#define N 100000
U *mem[M]
int mcount
U *free_list
int free_count
U *
alloc(void)
{
U *p
if (free_count == 0) {
if (mcount == 0)
alloc_mem()
else {
gc()
if (free_count < N * mcount / 2)
alloc_mem()
}
if (free_count == 0)
stop("atom space exhausted")
}
p = free_list
free_list = free_list->u.cons.cdr
free_count--
return p
}
*/
/*
Compare adjacent terms in s[] and combine if possible.
Returns the number of terms remaining in s[].
n number of terms in s[] initially
*/
/* cross =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept, script_defined
Parameters
----------
u,v
General description
-------------------
Returns the cross product of vectors u and v.
*/
/* curl =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept, script_defined
Parameters
----------
u
General description
-------------------
Returns the curl of vector u.
*/
/*
Clear all patterns
*/
/*
if 0
* left brace
for (i = 0; i < h; i++) {
if (yindex == YMAX)
break
chartab[yindex].c = '|'
chartab[yindex].x = x - 2
chartab[yindex].y = y + i
yindex++
}
* right brace
emit_x++
for (i = 0; i < h; i++) {
if (yindex == YMAX)
break
chartab[yindex].c = '|'
chartab[yindex].x = emit_x
chartab[yindex].y = y + i
yindex++
}
emit_x++
endif
*/
/*
For example...
push(F)
push(X)
filter()
F = pop()
*/
/*
Symbolic addition
Terms in a sum are combined if they are identical modulo rational
coefficients.
For example, A + 2A becomes 3A.
However, the sum A + sqrt(2) A is not modified.
Combining terms can lead to second-order effects.
For example, consider the case of
1/sqrt(2) A + 3/sqrt(2) A + sqrt(2) A
The first two terms are combined to yield 2 sqrt(2) A.
This result can now be combined with the third term to yield
3 sqrt(2) A
*/
/*
Table of integrals
The symbol f is just a dummy symbol for creating a list f(A,B,C,C,...) where
A is the template expression
B is the result expression
C is an optional list of conditional expressions
*/
/*
Partition a term
Input stack:
term (factor or product of factors)
free variable
Output stack:
constant expression
variable expression
*/
/*
Substitute new expr for old expr in expr.
Input: push expr
push old expr
push new expr
Output: Result on stack
*/
var $, ABS, ADD, ADJ, AND, APPROXRATIO, ARCCOS, ARCCOSH, ARCSIN, ARCSINH, ARCTAN, ARCTANH, ARG, ASSUME_REAL_VARIABLES, ATOMIZE, AUTOEXPAND, BAKE, BESSELJ, BESSELY, BINDING, BINOMIAL, BINOM_check_args, BUF, C1, C2, C3, C4, C5, C6, CEILING, CHECK, CHOOSE, CIRCEXP, CLEAR, CLEARALL, CLEARPATTERNS, CLOCK, COEFF, COFACTOR, CONDENSE, CONJ, CONS, CONTRACT, COS, COSH, Condense, DEBUG, DEBUG_ABS, DEBUG_ARG, DEBUG_CLOCKFORM, DEBUG_IMAG, DEBUG_IS, DEBUG_MULTIPLY, DEBUG_POWER, DEBUG_RATIONALIZE, DEBUG_RECT, DEBUG_SIMPLIFY, DECOMP, DEFINT, DEGREE, DENOMINATOR, DERIVATIVE, DET, DET_check_arg, DIM, DIRAC, DIVISORS, DO, DOT, DOUBLE, DRAW, DRAWX, DSOLVE, E, EIGEN, EIGENVAL, EIGENVEC, EIG_N, EIG_check_arg, EIG_yydd, EIG_yyqq, ERF, ERFC, EVAL, EXP, EXPAND, EXPCOS, EXPSIN, Eval, Eval_Eval, Eval_abs, Eval_add, Eval_adj, Eval_and, Eval_approxratio, Eval_arccos, Eval_arccosh, Eval_arcsin, Eval_arcsinh, Eval_arctan, Eval_arctanh, Eval_arg, Eval_besselj, Eval_bessely, Eval_binding, Eval_binomial, Eval_ceiling, Eval_check, Eval_choose, Eval_circexp, Eval_clear, Eval_clearall, Eval_clearpatterns, Eval_clock, Eval_coeff, Eval_cofactor, Eval_condense, Eval_conj, Eval_cons, Eval_contract, Eval_cos, Eval_cosh, Eval_decomp, Eval_defint, Eval_degree, Eval_denominator, Eval_derivative, Eval_det, Eval_dim, Eval_dirac, Eval_divisors, Eval_do, Eval_dsolve, Eval_eigen, Eval_eigenval, Eval_eigenvec, Eval_erf, Eval_erfc, Eval_exp, Eval_expand, Eval_expcos, Eval_expsin, Eval_factor, Eval_factorial, Eval_factorpoly, Eval_filter, Eval_float, Eval_floor, Eval_for, Eval_function_reference, Eval_gamma, Eval_gcd, Eval_hermite, Eval_hilbert, Eval_imag, Eval_index, Eval_inner, Eval_integral, Eval_inv, Eval_invg, Eval_isinteger, Eval_isprime, Eval_laguerre, Eval_lcm, Eval_leading, Eval_legendre, Eval_log, Eval_lookup, Eval_mod, Eval_multiply, Eval_noexpand, Eval_not, Eval_nroots, Eval_number, Eval_numerator, Eval_operator, Eval_or, Eval_outer, Eval_pattern, Eval_patternsinfo, Eval_polar, Eval_power, Eval_predicate, Eval_prime, Eval_print, Eval_print2dascii, Eval_printcomputer, Eval_printhuman, Eval_printlatex, Eval_printlist, Eval_product, Eval_quote, Eval_quotient, Eval_rank, Eval_rationalize, Eval_real, Eval_rect, Eval_roots, Eval_round, Eval_setq, Eval_sgn, Eval_shape, Eval_silentpattern, Eval_simfac, Eval_simplify, Eval_sin, Eval_sinh, Eval_sqrt, Eval_stop, Eval_subst, Eval_sum, Eval_sym, Eval_symbolsinfo, Eval_tan, Eval_tanh, Eval_taylor, Eval_tensor, Eval_test, Eval_testeq, Eval_testge, Eval_testgt, Eval_testle, Eval_testlt, Eval_transpose, Eval_unit, Eval_user_function, Eval_zero, Evalpoly, FACTOR, FACTORIAL, FACTORPOLY, FILTER, FLOATF, FLOOR, FOR, FORCE_FIXED_PRINTOUT, FUNCTION, Find, GAMMA, GCD, HERMITE, HILBERT, IMAG, INDEX, INNER, INTEGRAL, INV, INVG, INV_check_arg, INV_decomp, ISINTEGER, ISPRIME, LAGUERRE, LAST, LAST_2DASCII_PRINT, LAST_FULL_PRINT, LAST_LATEX_PRINT, LAST_LIST_PRINT, LAST_PLAIN_PRINT, LAST_PRINT, LCM, LEADING, LEGENDRE, LOG, LOOKUP, M, MAXDIM, MAXPRIMETAB, MAX_CONSECUTIVE_APPLICATIONS_OF_ALL_RULES, MAX_CONSECUTIVE_APPLICATIONS_OF_SINGLE_RULE, MAX_FIXED_PRINTOUT_DIGITS, MAX_PROGRAM_SIZE, MEQUAL, METAA, METAB, METAX, MLENGTH, MOD, MSIGN, MULTIPLY, MZERO, N, NIL, NOT, NROOTS, NROOTS_ABS, NROOTS_DELTA, NROOTS_EPSILON, NROOTS_RANDOM, NROOTS_YMAX, NROOTS_divpoly, NSYM, NUM, NUMBER, NUMERATOR, OPERATOR, OR, OUTER, PATTERN, PATTERNSINFO, PI, POLAR, POWER, PRIME, PRINT, PRINT2DASCII, PRINTFULL, PRINTLATEX, PRINTLIST, PRINTMODE_2DASCII, PRINTMODE_COMPUTER, PRINTMODE_HUMAN, PRINTMODE_LATEX, PRINTMODE_LIST, PRINTOUTRESULT, PRINTPLAIN, PRINT_LEAVE_E_ALONE, PRINT_LEAVE_X_ALONE, PRODUCT, QUOTE, QUOTIENT, RANK, RATIONALIZE, REAL, ROOTS, ROUND, SECRETX, SELFTEST, SETQ, SGN, SHAPE, SILENTPATTERN, SIMPLIFY, SIN, SINH, SPACE_BETWEEN_COLUMNS, SPACE_BETWEEN_ROWS, SQRT, STOP, STR, SUBST, SUM, SYM, SYMBOLSINFO, SYMBOL_A, SYMBOL_A_UNDERSCORE, SYMBOL_B, SYMBOL_B_UNDERSCORE, SYMBOL_C, SYMBOL_D, SYMBOL_I, SYMBOL_IDENTITY_MATRIX, SYMBOL_J, SYMBOL_N, SYMBOL_R, SYMBOL_S, SYMBOL_T, SYMBOL_X, SYMBOL_X_UNDERSCORE, SYMBOL_Y, SYMBOL_Z, TAN, TANH, TAYLOR, TENSOR, TEST, TESTEQ, TESTGE, TESTGT, TESTLE, TESTLT, TIMING_DEBUGS, TOS, TRACE, TRANSPOSE, T_DOUBLE, T_EQ, T_FUNCTION, T_GTEQ, T_INTEGER, T_LTEQ, T_NEQ, T_NEWLINE, T_QUOTASSIGN, T_STRING, T_SYMBOL, U, UNIT, USR_SYMBOLS, VERSION, YMAX, YYE, YYRECT, ZERO, __emit_char, __emit_str, __factor_add, __factorial, __is_negative, __is_radical_number, __lcm, __legendre, __legendre2, __legendre3, __normalize_radical_factors, __rationalize_tensor, _print, abs, absValFloat, absval, absval_tensor, add, addSymbolLeftOfAssignment, addSymbolRightOfAssignment, add_all, add_factor_to_accumulator, add_numbers, add_terms, addf, adj, alloc_tensor, allocatedId, any_denominators, approxAll, approxLogs, approxLogsOfRationals, approxOneRatioOnly, approxRadicals, approxRadicalsOfRationals, approxRationalsOfLogs, approxRationalsOfPowersOfE, approxRationalsOfPowersOfPI, approxRationalsOfRadicals, approxSineOfRationalMultiplesOfPI, approxSineOfRationals, approxTrigonometric, approx_just_an_integer, approx_logarithmsOfRationals, approx_nothingUseful, approx_radicalOfRatio, approx_ratioOfRadical, approx_rationalOfE, approx_rationalOfPi, approx_rationalsOfLogarithms, approx_sine_of_pi_times_rational, approx_sine_of_rational, approxratioRecursive, arccos, arccosh, arcsin, arcsinh, arctan, arctanh, areunivarpolysfactoredorexpandedform, arg, arglist, assignmentFound, avoidCalculatingPowersIntoArctans, bake, bake_poly, bake_poly_term, besselj, bessely, bigInt, bignum_factorial, bignum_float, bignum_power_number, bignum_scan_float, bignum_scan_integer, bignum_truncate, binding, binomial, buffer, build_tensor, caaddr, caadr, caar, cadaddr, cadadr, cadar, caddaddr, caddadr, caddar, caddddr, cadddr, caddr, cadr, called_from_Algebra_block, car, cdaddr, cdadr, cdar, cddaddr, cddar, cdddaddr, cddddr, cdddr, cddr, cdr, ceiling, chainOfUserSymbolsNotFunctionsBeingEvaluated, charTabIndex, chartab, checkFloatHasWorkedOutCompletely, check_esc_flag, check_stack, check_tensor_dimensions, choose, choose_check_args, circexp, clearAlgebraEnvironment, clearRenamedVariablesToAvoidBindingToExternalScope, clear_symbols, clear_term, clearall, clockform, cmpGlyphs, cmp_args, cmp_expr, cmp_terms, cmp_terms_count, codeGen, coeff, cofactor, collectLatexStringFromReturnValue, collectUserSymbols, combine_factors, combine_gammas, combine_terms, compareState, compare_numbers, compare_rationals, compare_tensors, compatible, computeDependenciesFromAlgebra, computeResultsAndJavaScriptFromAlgebra, compute_fa, conjugate, cons, consCount, contract, convert_bignum_to_double, convert_rational_to_double, copy_tensor, cosine, cosine_of_angle, cosine_of_angle_sum, count, countOccurrencesOfSymbol, count_denominators, counter, countsize, d_scalar_scalar, d_scalar_scalar_1, d_scalar_tensor, d_tensor_scalar, d_tensor_tensor, dabs, darccos, darccosh, darcsin, darcsinh, darctan, darctanh, dbesselj0, dbesseljn, dbessely0, dbesselyn, dcos, dcosh, dd, decomp, decomp_product, decomp_sum, defineSomeHandyConstants, define_user_function, defn, defn_str, degree, denominator, derf, derfc, derivative, derivative_of_integral, det, determinant, detg, dfunction, dhermite, dirac, display, display_flag, displaychar, divide, divide_numbers, divisors, divisors_onstack, divpoly, dlog, do_clearPatterns, do_clearall, do_simplify_nested_radicals, dontCreateNewRadicalsInDenominatorWhenEvalingMultiplication, dotprod_unicode, doubleToReasonableString, dpow, dpower, dproduct, draw_flag, draw_stop_return, dsgn, dsin, dsinh, dsum, dtan, dtanh, dupl, eigen, elelmIndex, elem, emit_denominator, emit_denominators, emit_expr, emit_factor, emit_factorial_function, emit_flat_tensor, emit_fraction, emit_function, emit_index_function, emit_multiply, emit_number, emit_numerators, emit_numerical_fraction, emit_power, emit_string, emit_subexpr, emit_symbol, emit_tensor, emit_tensor_inner, emit_term, emit_top_expr, emit_unsigned_expr, emit_x, equal, equaln, equalq, erfc, errorMessage, esc_flag, evaluatingAsFloats, evaluatingPolar, exec, expand, expand_get_A, expand_get_AF, expand_get_B, expand_get_C, expand_get_CF, expand_tensor, expanding, expcos, exponential, expr_level, expsin, f1, f10, f2, f3, f4, f5, f9, f_equals_a, factor, factor_a, factor_again, factor_b, factor_number, factor_small_number, factor_term, factorial, factorpoly, factors, fill_buf, filter, filter_main, filter_sum, filter_tensor, findDependenciesInScript, findPossibleClockForm, findPossibleExponentialForm, findroot, fixup_fraction, fixup_power, flag, floatToRatioRoutine, fmt_index, fmt_level, fmt_x, frame, freeze, functionInvokationsScanningStack, gamma, gamma_of_sum, gammaf, gcd, gcd_main, gcd_numbers, gcd_polys, gcd_powers_with_same_base, gcd_product_product, gcd_product_sum, gcd_sum, gcd_sum_product, gcd_sum_sum, gen, getSimpleRoots, getStateHash, get_binding, get_factor_from_complex_root, get_factor_from_real_root, get_innerprod_factors, get_next_token, get_printname, get_size, get_token, getdisplaystr, glyph, gp, guess, hasImaginaryCoeff, hasNegativeRationalExponent, hash_addition, hash_function, hash_multiplication, hash_power, hashcode_values, hashed_itab, hermite, hilbert, i1, imag, imaginaryunit, index_function, init, initNRoots, inited, inner, inner_f, input_str, integral, integral_of_form, integral_of_product, integral_of_sum, inv, inverse, invert_number, invg, isNumberOneOverSomething, isNumericAtom, isNumericAtomOrTensor, isSimpleRoot, isSmall, isSymbolLeftOfAssignment, isSymbolReclaimable, isZeroAtom, isZeroAtomOrTensor, isZeroLikeOrNonZeroLikeOrUndetermined, isZeroTensor, is_denominator, is_factor, is_small_integer, is_square_matrix, is_usr_symbol, isadd, isalnumorunderscore, isalpha, isalphaOrUnderscore, iscomplexnumber, iscomplexnumberdouble, iscons, isdenominator, isdigit, isdouble, iseveninteger, isfactor, isfactorial, isfloating, isfraction, isidentitymatrix, isimaginarynumber, isimaginarynumberdouble, isimaginaryunit, isinnerordot, isinteger, isintegerfactor, isintegerorintegerfloat, isinv, iskeyword, isminusone, isminusoneoversqrttwo, isminusoneovertwo, isminussqrtthreeovertwo, ismultiply, isnegative, isnegativenumber, isnegativeterm, isnonnegativeinteger, isnpi, isone, isoneover, isoneoversqrttwo, isoneovertwo, isplusone, isplustwo, ispolyexpandedform, ispolyexpandedform_expr, ispolyexpandedform_factor, ispolyexpandedform_term, ispolyfactoredorexpandedform, ispolyfactoredorexpandedform_factor, ispolyfactoredorexpandedform_power, isposint, ispositivenumber, ispower, isquarterturn, isrational, isspace, issqrtthree, issqrtthreeovertwo, isstr, issymbol, issymbolic, istensor, istranspose, isunderscore, isunivarpolyfactoredorexpandedform, itab, italu_hashcode, j1, laguerre, laguerre2, lastFoundSymbol, latexErrorSign, lcm, leading, legendre, length, lessp, level, list, listLength, logarithm, logbuf, lookupsTotal, lu_decomp, madd, makePositive, makeSignSameAs, make_hashed_itab, mask, mcmp, mcmpint, mdiv, mdivrem, meta_mode, mgcd, mini_solve, mint, mmod, mmul, mod, monic, move, moveTos, mp_clr_bit, mp_denominator, mp_numerator, mp_set_bit, mpow, mprime, mroot, mshiftright, msub, mtotal, multinomial_sum, multiply, multiply_all, multiply_all_noexpand, multiply_consecutive_constants, multiply_denominators, multiply_denominators_factor, multiply_denominators_term, multiply_noexpand, multiply_numbers, n_factor_number, negate, negate_expand, negate_noexpand, negate_number, new_integer, new_string, newline_flag, nil_symbols, normaliseDots, normalisedCoeff, normalize_angle, nroots_a, nroots_b, nroots_c, nroots_df, nroots_dx, nroots_fa, nroots_fb, nroots_x, nroots_y, nterms, nthCadr, numerator, numericRootOfPolynomial, o, one, oneElement, one_as_double, out_buf, out_count, out_of_memory, outer, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, parse, parse_internal, parse_p1, parse_p2, parse_time_simplifications, partition, patternHasBeenFound, patternsinfo, performing_roots, polar, polarRectAMinusOneBase, polyform, pop, pop_double, pop_frame, pop_integer, power, power_str, power_sum, power_tensor, predefinedSymbolsInGlobalScope_doNotTrackInDependencies, prime, primetab, print2dascii, printMode, print_ABS_latex, print_ARCCOS_codegen, print_ARCSIN_codegen, print_ARCTAN_codegen, print_BINOMIAL_latex, print_COS_codegen, print_DEFINT_latex, print_DOT_codegen, print_DOT_latex, print_DO_codegen, print_FOR_codegen, print_INV_codegen, print_INV_latex, print_PRODUCT_codegen, print_PRODUCT_latex, print_SETQ_codegen, print_SIN_codegen, print_SQRT_latex, print_SUM_codegen, print_SUM_latex, print_TAN_codegen, print_TESTEQ_latex, print_TESTGE_latex, print_TESTGT_latex, print_TESTLE_latex, print_TESTLT_latex, print_TEST_codegen, print_TEST_latex, print_TRANSPOSE_codegen, print_TRANSPOSE_latex, print_UNIT_codegen, print_a_over_b, print_base, print_base_of_denom, print_char, print_denom, print_double, print_expo_of_denom, print_exponent, print_expr, print_factor, print_factorial_function, print_glyphs, print_index_function, print_list, print_multiply_sign, print_number, print_power, print_str, print_subexpr, print_tensor, print_tensor_inner, print_tensor_inner_latex, print_tensor_latex, print_term, printchar, printchar_nowrap, printline, program_buf, promote_tensor, push, pushTryNotToDuplicate, push_cars, push_double, push_factor, push_frame, push_identity_matrix, push_integer, push_rational, push_symbol, push_term_factors, push_terms, push_zero_matrix, qadd, qdiv, qmul, qpow, qpowf, quickfactor, quickpower, rational, rationalize, rationalize_coefficients, real, reciprocate, rect, recursionLevelNestedRadicalsRemoval, recursiveDependencies, ref, ref1, rememberPrint, remove_negative_exponents, reset_after_error, restore, restoreMetaBindings, rewrite_args, rewrite_args_tensor, roots, roots2, roots3, run, runUserDefinedSimplifications, save, saveMetaBindings, scalar_times_tensor, scan, scan_error, scan_expression, scan_factor, scan_function_call_with_function_name, scan_function_call_without_function_name, scan_index, scan_meta, scan_power, scan_relation, scan_stmt, scan_str, scan_string, scan_subexpr, scan_symbol, scan_tensor, scan_term, scanned, scanningParameters, setM, setSignTo, set_binding, set_component, setq_indexed, sfac_product, sfac_product_f, sgn, shape, show_power_debug, sign, sign_of_term, simfac, simfac_term, simpleComplexityMeasure, simplify, simplifyForCodeGeneration, simplify_1_in_products, simplify_main, simplify_nested_radicals, simplify_polar, simplify_polarRect, simplify_rational_expressions, simplify_rectToClock, simplify_tensor, simplify_trig, simplifyfactorials, sine, sine_of_angle, sine_of_angle_sum, skipRootVariableToBeSolved, sort_stack, square, ssqrt, stack, stackAddsCount, std_symbol, step, step2, stop, strcmp, stringsEmittedByUserPrintouts, subf, subst, subtract, subtract_numbers, swap, symbol, symbolsDependencies, symbolsHavingReassignments, symbolsInExpressionsWithoutAssignments, symbolsLeftOfAssignment, symbolsRightOfAssignment, symbolsinfo, symnum, symtab, take_care_of_nested_radicals, tangent, taylor, tensor, tensor_plus_tensor, tensor_times_scalar, testApprox, test_flag, text_metric, theRandom, token, token_buf, token_str, top, top_level_eval, tos, transform, transpose, transpose_unicode, trigmode, trivial_divide, try_kth_prime, turnErrorMessageToLatex, ucmp, unfreeze, unique, unique_f, update_token_buf, userSimplificationsInListForm, userSimplificationsInStringForm, usr_symbol, verbosing, version, will_be_displayed_as_fraction, ybinomial, ycosh, ydirac, yerf, yerfc, yfloor, yindex, yround, ysinh, yyarg, yybesselj, yybessely, yyceiling, yycondense, yycontract, yycosh, yydegree, yydetg, yydivpoly, yyerf, yyerfc, yyexpand, yyfactorpoly, yyfloat, yyfloor, yyhermite, yyhermite2, yyinvg, yylcm, yylog, yymultiply, yyouter, yypower, yyrationalize, yyround, yysgn, yysimfac, yysinh, yytangent, zero, zzfloat,
hasProp = {}.hasOwnProperty;
bigInt = require('big-integer');
// also change the version in the package.json file
version = "1.4.0";
SELFTEST = 1;
// size of the symbol table
NSYM = 1000;
DEBUG = false;
PRINTOUTRESULT = false;
// printing-related constants
PRINTMODE_LATEX = "PRINTMODE_LATEX";
PRINTMODE_2DASCII = "PRINTMODE_2DASCII";
PRINTMODE_COMPUTER = "PRINTMODE_COMPUTER";
PRINTMODE_HUMAN = "PRINTMODE_HUMAN";
PRINTMODE_LIST = "PRINTMODE_LIST";
// when the user uses the generic "print" statement
// this setting kicks-in.
printMode = PRINTMODE_COMPUTER;
dontCreateNewRadicalsInDenominatorWhenEvalingMultiplication = true;
recursionLevelNestedRadicalsRemoval = 0;
do_simplify_nested_radicals = true;
avoidCalculatingPowersIntoArctans = true;
rational = (function() {
// Symbolic expressions are built by connecting U structs.
// For example, (a b + c) is built like this:
// _______ _______ _______
// |CONS |--->|CONS |----------------------------->|CONS |
// | | | | | |
// |_______| |_______| |_______|
// | | |
// ___v___ ___v___ _______ _______ ___v___
// |ADD | |CONS |--->|CONS |--->|CONS | |SYM c |
// | | | | | | | | | |
// |_______| |_______| |_______| |_______| |_______|
// | | |
// ___v___ ___v___ ___v___
// |MUL | |SYM a | |SYM b |
// | | | | | |
// |_______| |_______| |_______|
class rational {};
rational.prototype.a = null; // a bigInteger
rational.prototype.b = null; // a bigInteger
return rational;
}).call(this);
U = (function() {
class U {
toString() {
return print_expr(this);
}
toLatexString() {
return collectLatexStringFromReturnValue(this);
}
constructor() {
this.cons = {};
this.cons.car = null;
this.cons.cdr = null;
this.q = new rational();
}
};
U.prototype.cons = null; // will have a car and cdr
U.prototype.printname = "";
U.prototype.str = "";
U.prototype.tensor = null;
// rational number a over b
U.prototype.q = null; // will point to a rational
U.prototype.d = 0.0; // a double
U.prototype.k = 0;
U.prototype.tag = 0;
return U;
}).call(this);
errorMessage = "";
// the following enum is for struct U, member k
CONS = 0;
NUM = 1;
DOUBLE = 2;
STR = 3;
TENSOR = 4;
SYM = 5;
// the following enum is for indexing the symbol table
// standard functions first, then nil, then everything else
counter = 0;
ABS = counter++;
ADD = counter++;
ADJ = counter++;
AND = counter++;
APPROXRATIO = counter++;
ARCCOS = counter++;
ARCCOSH = counter++;
ARCSIN = counter++;
ARCSINH = counter++;
ARCTAN = counter++;
ARCTANH = counter++;
ARG = counter++;
ATOMIZE = counter++;
BESSELJ = counter++;
BESSELY = counter++;
BINDING = counter++;
BINOMIAL = counter++;
CEILING = counter++;
CHECK = counter++;
CHOOSE = counter++;
CIRCEXP = counter++;
CLEAR = counter++;
CLEARALL = counter++;
CLEARPATTERNS = counter++;
CLOCK = counter++;
COEFF = counter++;
COFACTOR = counter++;
CONDENSE = counter++;
CONJ = counter++;
CONTRACT = counter++;
COS = counter++;
COSH = counter++;
DECOMP = counter++;
DEFINT = counter++;
DEGREE = counter++;
DENOMINATOR = counter++;
DERIVATIVE = counter++;
DET = counter++;
DIM = counter++;
DIRAC = counter++;
DIVISORS = counter++;
DO = counter++;
DOT = counter++;
DRAW = counter++;
DSOLVE = counter++;
EIGEN = counter++;
EIGENVAL = counter++;
EIGENVEC = counter++;
ERF = counter++;
ERFC = counter++;
EVAL = counter++;
EXP = counter++;
EXPAND = counter++;
EXPCOS = counter++;
EXPSIN = counter++;
FACTOR = counter++;
FACTORIAL = counter++;
FACTORPOLY = counter++;
FILTER = counter++;
FLOATF = counter++;
FLOOR = counter++;
FOR = counter++;
FUNCTION = counter++;
GAMMA = counter++;
GCD = counter++;
HERMITE = counter++;
HILBERT = counter++;
IMAG = counter++;
INDEX = counter++;
INNER = counter++;
INTEGRAL = counter++;
INV = counter++;
INVG = counter++;
ISINTEGER = counter++;
ISPRIME = counter++;
LAGUERRE = counter++;
// LAPLACE = counter++
LCM = counter++;
LEADING = counter++;
LEGENDRE = counter++;
LOG = counter++;
LOOKUP = counter++;
MOD = counter++;
MULTIPLY = counter++;
NOT = counter++;
NROOTS = counter++;
NUMBER = counter++;
NUMERATOR = counter++;
OPERATOR = counter++;
OR = counter++;
OUTER = counter++;
PATTERN = counter++;
PATTERNSINFO = counter++;
POLAR = counter++;
POWER = counter++;
PRIME = counter++;
PRINT_LEAVE_E_ALONE = counter++;
PRINT_LEAVE_X_ALONE = counter++;
PRINT = counter++;
PRINT2DASCII = counter++;
PRINTFULL = counter++;
PRINTLATEX = counter++;
PRINTLIST = counter++;
PRINTPLAIN = counter++;
PRODUCT = counter++;
QUOTE = counter++;
QUOTIENT = counter++;
RANK = counter++;
RATIONALIZE = counter++;
REAL = counter++;
ROUND = counter++;
YYRECT = counter++;
ROOTS = counter++;
SETQ = counter++;
SGN = counter++;
SILENTPATTERN = counter++;
SIMPLIFY = counter++;
SIN = counter++;
SINH = counter++;
SHAPE = counter++;
SQRT = counter++;
STOP = counter++;
SUBST = counter++;
SUM = counter++;
SYMBOLSINFO = counter++;
TAN = counter++;
TANH = counter++;
TAYLOR = counter++;
TEST = counter++;
TESTEQ = counter++;
TESTGE = counter++;
TESTGT = counter++;
TESTLE = counter++;
TESTLT = counter++;
TRANSPOSE = counter++;
UNIT = counter++;
ZERO = counter++;
// ALL THE SYMBOLS ABOVE NIL ARE KEYWORDS,
// WHICH MEANS THAT USER CANNOT REDEFINE THEM
NIL = counter++; // nil goes here, after standard functions
LAST = counter++;
LAST_PRINT = counter++;
LAST_2DASCII_PRINT = counter++;
LAST_FULL_PRINT = counter++;
LAST_LATEX_PRINT = counter++;
LAST_LIST_PRINT = counter++;
LAST_PLAIN_PRINT = counter++;
AUTOEXPAND = counter++;
BAKE = counter++;
ASSUME_REAL_VARIABLES = counter++;
TRACE = counter++;
FORCE_FIXED_PRINTOUT = counter++;
MAX_FIXED_PRINTOUT_DIGITS = counter++;
YYE = counter++;
DRAWX = counter++; // special purpose internal symbols
METAA = counter++;
METAB = counter++;
METAX = counter++;
SECRETX = counter++;
VERSION = counter++;
PI = counter++;
SYMBOL_A = counter++;
SYMBOL_B = counter++;
SYMBOL_C = counter++;
SYMBOL_D = counter++;
SYMBOL_I = counter++;
SYMBOL_J = counter++;
SYMBOL_N = counter++;
SYMBOL_R = counter++;
SYMBOL_S = counter++;
SYMBOL_T = counter++;
SYMBOL_X = counter++;
SYMBOL_Y = counter++;
SYMBOL_Z = counter++;
SYMBOL_IDENTITY_MATRIX = counter++;
SYMBOL_A_UNDERSCORE = counter++;
SYMBOL_B_UNDERSCORE = counter++;
SYMBOL_X_UNDERSCORE = counter++;
C1 = counter++;
C2 = counter++;
C3 = counter++;
C4 = counter++;
C5 = counter++;
C6 = counter++;
USR_SYMBOLS = counter++; // this must be last
E = YYE;
// TOS cannot be arbitrarily large because the OS seg faults on deep recursion.
// For example, a circular evaluation like x=x+1 can cause a seg fault.
// At this setting (100,000) the evaluation stack overruns before seg fault.
TOS = 100000;
BUF = 10000;
MAX_PROGRAM_SIZE = 100001;
MAXPRIMETAB = 10000;
MAX_CONSECUTIVE_APPLICATIONS_OF_ALL_RULES = 5;
MAX_CONSECUTIVE_APPLICATIONS_OF_SINGLE_RULE = 10;
//define _USE_MATH_DEFINES // for MS C++
MAXDIM = 24;
// needed for the mechanism to
// find all dependencies between variables
// in a script
symbolsDependencies = {};
symbolsHavingReassignments = [];
symbolsInExpressionsWithoutAssignments = [];
patternHasBeenFound = false;
predefinedSymbolsInGlobalScope_doNotTrackInDependencies = ["rationalize", "abs", "e", "i", "pi", "sin", "ceiling", "cos", "roots", "integral", "derivative", "defint", "sqrt", "eig", "cov", "deig", "dcov", "float", "floor", "product", "root", "round", "sum", "test", "unit"];
// you can do some little simplifications
// at parse time, such as calculating away
// immediately simple operations on
// constants, removing 1s from products
// etc.
parse_time_simplifications = true;
chainOfUserSymbolsNotFunctionsBeingEvaluated = [];
stringsEmittedByUserPrintouts = "";
// flag use to potentially switch on/off some quirks "deep"
// in the code due to call from Algebra block.
// Currently not used.
called_from_Algebra_block = false;
tensor = (function() {
class tensor {
constructor() {
this.dim = (function() {
var o, ref, results;
results = [];
for (o = 0, ref = MAXDIM; (0 <= ref ? o <= ref : o >= ref); 0 <= ref ? o++ : o--) {
results.push(0);
}
return results;
})();
this.elem = [];
}
};
tensor.prototype.ndim = 0; // number of dimensions
tensor.prototype.dim = null; // dimension length, for each dimension
tensor.prototype.nelem = 0; // total number of elements
tensor.prototype.elem = null; // an array containing all the data
return tensor;
}).call(this);
display = (function() {
class display {};
display.prototype.h = 0;
display.prototype.w = 0;
display.prototype.n = 0;
display.prototype.a = []; // will contain an array of c,x,y (color,x,y)
return display;
}).call(this);
text_metric = (function() {
class text_metric {};
text_metric.prototype.ascent = 0;
text_metric.prototype.descent = 0;
text_metric.prototype.width = 0;
return text_metric;
}).call(this);
tos = 0; // top of stack
expanding = 0;
evaluatingAsFloats = 0;
evaluatingPolar = 0;
fmt_x = 0;
fmt_index = 0;
fmt_level = 0;
verbosing = 0;
primetab = (function() {
var ceil, i, j, primes;
primes = [2];
i = 3;
while (primes.length < MAXPRIMETAB) {
j = 0;
ceil = Math.sqrt(i);
while (j < primes.length && primes[j] <= ceil) {
if (i % primes[j] === 0) {
j = -1;
break;
}
j++;
}
if (j !== -1) {
primes.push(i);
}
i += 2;
}
primes[MAXPRIMETAB] = 0;
return primes;
})();
esc_flag = 0;
draw_flag = 0;
mtotal = 0;
trigmode = 0;
logbuf = "";
program_buf = "";
// will contain the variable names
symtab = [];
// will contain the contents of the variable
// in the corresponding position in symtab array
binding = [];
isSymbolReclaimable = [];
arglist = []; // will contain U
stack = []; // will contain *U
frame = 0;
p0 = null; // will contain U
p1 = null; // will contain U
p2 = null; // will contain U
p3 = null; // will contain U
p4 = null; // will contain U
p5 = null; // will contain U
p6 = null; // will contain U
p7 = null; // will contain U
p8 = null; // will contain U
p9 = null; // will contain U
zero = null; // will contain U
one = null; // will contain U
one_as_double = null;
imaginaryunit = null; // will contain U
out_buf = "";
out_count = 0;
test_flag = 0;
codeGen = false;
draw_stop_return = null; // extern jmp_buf ?????
userSimplificationsInListForm = [];
userSimplificationsInStringForm = [];
transpose_unicode = 7488;
dotprod_unicode = 183;
symbol = function(x) {
return symtab[x];
};
iscons = function(p) {
return p.k === CONS;
};
isrational = function(p) {
return p.k === NUM;
};
isdouble = function(p) {
return p.k === DOUBLE;
};
isNumericAtom = function(p) {
return isrational(p) || isdouble(p);
};
isstr = function(p) {
return p.k === STR;
};
istensor = function(p) {
if (p == null) {
debugger;
} else {
return p.k === TENSOR;
}
};
// because of recursion, we consider a scalar to be
// a tensor, so a numeric scalar will return true
isNumericAtomOrTensor = function(p) {
var a, i, n, o, ref;
if (isNumericAtom(p) || p === symbol(SYMBOL_IDENTITY_MATRIX)) {
return 1;
}
if (!istensor(p) && !isNumericAtom(p)) {
//console.log "p not an atom nor a tensor: " + p
return 0;
}
n = p.tensor.nelem;
a = p.tensor.elem;
for (i = o = 0, ref = n; (0 <= ref ? o < ref : o > ref); i = 0 <= ref ? ++o : --o) {
if (!isNumericAtomOrTensor(a[i])) {
//console.log "non-numeric element: " + a[i]
return 0;
}
}
return 1;
};
issymbol = function(p) {
return p.k === SYM;
};
iskeyword = function(p) {
return issymbol(p) && symnum(p) < NIL;
};
car = function(p) {
if (iscons(p)) {
return p.cons.car;
} else {
return symbol(NIL);
}
};
cdr = function(p) {
if (iscons(p)) {
return p.cons.cdr;
} else {
return symbol(NIL);
}
};
caar = function(p) {
return car(car(p));
};
cadr = function(p) {
return car(cdr(p));
};
cdar = function(p) {
return cdr(car(p));
};
cddr = function(p) {
return cdr(cdr(p));
};
caadr = function(p) {
return car(car(cdr(p)));
};
caddr = function(p) {
return car(cdr(cdr(p)));
};
cadar = function(p) {
return car(cdr(car(p)));
};
cdadr = function(p) {
return cdr(car(cdr(p)));
};
cddar = function(p) {
return cdr(cdr(car(p)));
};
cdddr = function(p) {
return cdr(cdr(cdr(p)));
};
caaddr = function(p) {
return car(car(cdr(cdr(p))));
};
cadadr = function(p) {
return car(cdr(car(cdr(p))));
};
caddar = function(p) {
return car(cdr(cdr(car(p))));
};
cdaddr = function(p) {
return cdr(car(cdr(cdr(p))));
};
cadddr = function(p) {
return car(cdr(cdr(cdr(p))));
};
cddddr = function(p) {
return cdr(cdr(cdr(cdr(p))));
};
caddddr = function(p) {
return car(cdr(cdr(cdr(cdr(p)))));
};
cadaddr = function(p) {
return car(cdr(car(cdr(cdr(p)))));
};
cddaddr = function(p) {
return cdr(cdr(car(cdr(cdr(p)))));
};
caddadr = function(p) {
return car(cdr(cdr(car(cdr(p)))));
};
cdddaddr = function(p) {
return cdr(cdr(cdr(car(cdr(cdr(p))))));
};
caddaddr = function(p) {
return car(cdr(cdr(car(cdr(cdr(p))))));
};
// not used yet
listLength = function(p) {
var startCount;
startCount = -1;
while (iscons(p)) {
p = cdr(p);
startCount++;
}
return startCount;
};
// not used yet
nthCadr = function(p, n) {
var startCount;
startCount = 0;
while (startCount <= n) {
p = cdr(p);
startCount++;
}
return car(p);
};
isadd = function(p) {
return car(p) === symbol(ADD);
};
ismultiply = function(p) {
return car(p) === symbol(MULTIPLY);
};
ispower = function(p) {
return car(p) === symbol(POWER);
};
isfactorial = function(p) {
return car(p) === symbol(FACTORIAL);
};
isinnerordot = function(p) {
return (car(p) === symbol(INNER)) || (car(p) === symbol(DOT));
};
istranspose = function(p) {
return car(p) === symbol(TRANSPOSE);
};
isinv = function(p) {
return car(p) === symbol(INV);
};
// TODO this is a bit of a shallow check, we should
// check when we are passed an actual tensor and possibly
// cache the test result.
isidentitymatrix = function(p) {
return p === symbol(SYMBOL_IDENTITY_MATRIX);
};
MSIGN = function(p) {
if (p.isPositive()) {
return 1;
} else if (p.isZero()) {
return 0;
} else {
return -1;
}
};
MLENGTH = function(p) {
return p.toString().length;
};
MZERO = function(p) {
return p.isZero();
};
MEQUAL = function(p, n) {
if (p == null) {
debugger;
}
return p.equals(n);
};
reset_after_error = function() {
moveTos(0);
esc_flag = 0;
draw_flag = 0;
frame = TOS;
evaluatingAsFloats = 0;
return evaluatingPolar = 0;
};
$ = typeof exports !== "undefined" && exports !== null ? exports : this;
$.version = version;
$.isadd = isadd;
$.ismultiply = ismultiply;