Sindbad~EG File Manager
/* M. Beeson, for Mathpert */
/* macros, globals, and typedefs to go with arith.c */
/*
7.23.90 file created
1.27.95 last modified
2.15.95 added complexpowers field to aflag
history in arithh.his
*/
/*_____________________________________________________________________*/
/* What kind of operations are performed by arith is controlled by
the parameter 'arithflag', as follows. Note that arith ALWAYS evaluates
+, -, and / . */
/* If new fields are added here, be sure that init_default_model initializes
them in model.c */
typedef struct{
unsigned
fract:1, /* evaluate arithmetic compound fractions? */
varadd:1, /* do addition and mult. on non-adjacent terms, e.g. a+3+x+4=a+7+x */
intexp:1, /* exponentiation with positive integer exponents */
negexp:1, /* if zero, don't evaluate negative integer exponents */
ratexp:1, /* exponentiation with rational exponents */
roots:1, /* evaluate exact (integer and rational) roots */
pure:1, /* if one, work only on terms that have a numerical value */
/* and STOP as soon as you find a term without numerical value */
gcd:1, /* evaluate 'gcd', 'mod', 'floor' */
abs:1, /* evaluate ABS */
relop:1, /* evaluate numerical inequalities and equalities
to true to false */
factorial:1, /* evaluate factorials and binomial coefficients */
matrix:1, /* use matrix arithmetic on matrices whose entries have values*/
/* and evaluate determinants if possible */
inverse:1, /* evaluate matrix inverse if entries have values */
functions:1, /* evaluate exact values of functions when possible */
sums:1, /* evaluate indexed sums and products when possible */
flt:1, /* evaluate roots and powers as well as other functions to
double values using deval when exact value can't be found */
complex:1, /* use complex addition, multiplication, and subtraction. */
/* Note this affects the evaluation of roots and fractional
powers of negative numbers, eg. (-1)^(1/3) */
complexpowers:1, /* also evaluate complex exponentials */
comdenom:1, /* if zero, don't add fractions unless they have the same denom */
mod: 1; /* if nonzero, perform arithmetic modulo 'modulus', which is
a static term in value.c. Be sure to call set_modulus
before using this feature, as 'modulus' could be set in
one document and not in another. */
} aflag; /* "arithmetic control flag " */
void set_arithflag(aflag);
aflag get_arithflag(void); /* value.c */
/*_____________________________________________________________________*/
/* The following macros work on terms representing positive or negative integers */
#define ODD(t) ((NEGATIVE(t)) ? (INTDATA(ARG(0,t)) & 1) : (INTDATA(t) & 1))
#define EVEN(t) !ODD(t)
/* The following two macros work on terms representing bignums */
#define BIGODD(t) ((NEGATIVE(t)) ? (BIGNUMDATA(ARG(0,t)).val[0] & 1) \
: (BIGNUMDATA(t).val[0] & 1))
#define BIGEVEN(t) !BIGODD(t)
/* The following macros works on positive integers or bignums */
#define ISODD(t) (OBJECT(t) && ((TYPE(t)==INTEGER && (INTDATA(t) & 1)) || (TYPE(t)==BIGNUM && (BIGNUMDATA(t).val[0] & 1))))
#define ISEVEN(t) !ISODD(t)
extern unsigned doing_indexedsum;
extern long sumvar;
/* prototypes of public functions in arith.c, roots.c, some in pda.c */
term conjugate(term); /* compute complex conjugate of a number */
int arithmetic(term, term, term *, char *); /* an operator callable from the menus */
int value(term, term *); /* arith using global variable arithflag */
int arith(term, term *, aflag); /* the main public function */
long intgcd(long,long);
long euclid(long,long,long *, long *);
int gcd(term,term,term *);
unsigned long fastexp(unsigned long, unsigned long ); /* doesn't detect overflow */
int complexfastexp(term, term, unsigned, term *);
int lcm(term,term,term *, term *, term *);
int introot(unsigned long index, unsigned long arg, unsigned long *ans);
/* returns 1 if root(index,arg) isn't an integer */
/* following public functions perform basic arithmetic operations on terms
and return answers in fresh space: */
int add( term, term, term *); /* add two terms */
int mult(term,term,term *); /* add, mult, divide do not assume args are arithmetic */
int divide(term,term,term *); /* so that in future they can work on polynomials */
int intdivide(term,term,term*,term*); /* quo and rem for ints or bignums */
void negate(term, term*); /* re-uses space unlike add etc. */
int tcompare(term x,term y, short *ans);
int cadd( term, term, term *); /* add two complex or real terms */
int cmult(term,term,term *); /* multiply two complex terms */
int cdivide(term,term,term *); /* divide two complex terms */
void cnegate(term,term*); /* negate a complex term */
int exponentiate(unsigned,term,term,term *); /* assumes args are arithmetic expressions */
int take_root(term,term,term *); /* assumes args are arithmetic expressions */
int take_complex_root(unsigned,term,term,term*);
int eval_indexedsum(term,term *,aflag); /* assumes upper and lower limits
are arithmetic expressions */
int bitlength(unsigned long); /* how many bits to the right of and including the leftmost nonzero bit? */
int tmod(term, term, term *);
int tfloor(term,term *);
int factorial(term, term *);
int binomial(term, term,term *);
/* return -1 if x < y , 0 if x=y, or 1 if x > y */
void qr(unsigned,unsigned,unsigned *, unsigned *);
void lqr(long, long, long *, long *);
int factor_gaussian_integer(term, unsigned *, term *);
int tmodexp(term m, term u, term x, term *ans); /* compute u^x mod m */
long intmodexp(unsigned long m, long a, unsigned long b); /* a^b mod m */
int nsquarefree(term); /* return 1 if apparently squarefree, 0 if not */
int rootfree(term,unsigned); /* free of n-th roots? */
void parts(term, term *, term *); /* arith.c */
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists