Commit e1b2c21b authored by Stefan Monnier's avatar Stefan Monnier

* lisp/calc/calc-alg.el: Use lexical-binding and silence warnings

* lisp/calc/calc-alg.el: Use lexical-binding and silence warnings.
(math-defsimplify): Let-bind 'expr' instead of math-simplify-expr.
Adjust all users.
(math-simplify-expr): Don't declare any more.
(math--simplify-divide-expr): New dynbound var.
(math-simplify-divide): Bind it when needed.
(math-simplify-divisor): Use it instead of math-simplify-expr.
(math-simplify-divisor): Only bind math-simplify-divisor-[nd]over
around the calls to math-simplify-one-divisor.
(math-expr-subst, math-is-polynomial): Don't use dynbound vars as
formal arguments.
(math-polynomial-base): Move binding of math-poly-base-pred.
Don't bind math-poly-base-top-expr any more...
* lisp/calc/calc-poly.el (math-total-polynomial-base): Bind it here instead!

* lisp/calc/calc-units.el: Use lexical-binding and silence warnings.
Adjust to the new 'expr' name in math-defsimplify.
(math-find-base-units, math-to-standard-units, math-convert-units):
Don't use dynbound vars as formal arguments.
(math-simplify-expr): Don't declare any more.
parent 5007c23a
Pipeline #100 failed with stage
in 21 minutes and 47 seconds
;;; calc-alg.el --- algebraic functions for Calc
;;; calc-alg.el --- algebraic functions for Calc -*- lexical-binding:t -*-
;; Copyright (C) 1990-1993, 2001-2018 Free Software Foundation, Inc.
......@@ -308,7 +308,7 @@
(let ((math-living-dangerously t))
(math-simplify a)))
(defalias 'calcFunc-esimplify 'math-simplify-extended)
(defalias 'calcFunc-esimplify #'math-simplify-extended)
;;; Rewrite the trig functions in a form easier to simplify.
(defun math-trig-rewrite (fn)
......@@ -329,7 +329,7 @@
(list '/ (cons 'calcFunc-cos newfn)
(cons 'calcFunc-sin newfn))))
(t
(mapcar 'math-trig-rewrite fn))))
(mapcar #'math-trig-rewrite fn))))
(defun math-hyperbolic-trig-rewrite (fn)
"Rewrite hyperbolic functions in terms of sinhs and coshs."
......@@ -349,7 +349,7 @@
(list '/ (cons 'calcFunc-cosh newfn)
(cons 'calcFunc-sinh newfn))))
(t
(mapcar 'math-hyperbolic-trig-rewrite fn))))
(mapcar #'math-hyperbolic-trig-rewrite fn))))
;; math-top-only is local to math-simplify, but is used by
;; math-simplify-step, which is called by math-simplify.
......@@ -402,11 +402,11 @@
(setq top-expr res)))))
top-expr)
(defalias 'calcFunc-simplify 'math-simplify)
(defalias 'calcFunc-simplify #'math-simplify)
;;; The following has a "bug" in that if any recursive simplifications
;;; occur only the first handler will be tried; this doesn't really
;;; matter, since math-simplify-step is iterated to a fixed point anyway.
;; The following has a "bug" in that if any recursive simplifications
;; occur only the first handler will be tried; this doesn't really
;; matter, since math-simplify-step is iterated to a fixed point anyway.
(defun math-simplify-step (a)
(if (Math-primp a)
a
......@@ -414,7 +414,7 @@
(memq (car a) '(calcFunc-quote calcFunc-condition
calcFunc-evalto)))
a
(cons (car a) (mapcar 'math-simplify-step (cdr a))))))
(cons (car a) (mapcar #'math-simplify-step (cdr a))))))
(and (symbolp (car aa))
(let ((handler (get (car aa) 'math-simplify)))
(and handler
......@@ -427,159 +427,155 @@
(defmacro math-defsimplify (funcs &rest code)
"Define the simplification code for functions FUNCS.
Code can refer to the expression to simplify via lexical variable `expr'
and should return the simplified expression to use (or nil)."
(declare (indent 1) (debug (sexp body)))
(cons 'progn
(mapcar #'(lambda (func)
`(put ',func 'math-simplify
(nconc
(get ',func 'math-simplify)
(list
#'(lambda (math-simplify-expr) ,@code)))))
#'(lambda (expr) ,@code)))))
(if (symbolp funcs) (list funcs) funcs))))
(put 'math-defsimplify 'lisp-indent-hook 1)
;; The function created by math-defsimplify uses the variable
;; math-simplify-expr, and so is used by functions in math-defsimplify
(defvar math-simplify-expr)
(math-defsimplify (+ -)
(math-simplify-plus))
(defun math-simplify-plus ()
(cond ((and (memq (car-safe (nth 1 math-simplify-expr)) '(+ -))
(Math-numberp (nth 2 (nth 1 math-simplify-expr)))
(not (Math-numberp (nth 2 math-simplify-expr))))
(let ((x (nth 2 math-simplify-expr))
(op (car math-simplify-expr)))
(setcar (cdr (cdr math-simplify-expr)) (nth 2 (nth 1 math-simplify-expr)))
(setcar math-simplify-expr (car (nth 1 math-simplify-expr)))
(setcar (cdr (cdr (nth 1 math-simplify-expr))) x)
(setcar (nth 1 math-simplify-expr) op)))
((and (eq (car math-simplify-expr) '+)
(Math-numberp (nth 1 math-simplify-expr))
(not (Math-numberp (nth 2 math-simplify-expr))))
(let ((x (nth 2 math-simplify-expr)))
(setcar (cdr (cdr math-simplify-expr)) (nth 1 math-simplify-expr))
(setcar (cdr math-simplify-expr) x))))
(let ((aa math-simplify-expr)
(cond ((and (memq (car-safe (nth 1 expr)) '(+ -))
(Math-numberp (nth 2 (nth 1 expr)))
(not (Math-numberp (nth 2 expr))))
(let ((x (nth 2 expr))
(op (car expr)))
(setcar (cdr (cdr expr)) (nth 2 (nth 1 expr)))
(setcar expr (car (nth 1 expr)))
(setcar (cdr (cdr (nth 1 expr))) x)
(setcar (nth 1 expr) op)))
((and (eq (car expr) '+)
(Math-numberp (nth 1 expr))
(not (Math-numberp (nth 2 expr))))
(let ((x (nth 2 expr)))
(setcar (cdr (cdr expr)) (nth 1 expr))
(setcar (cdr expr) x))))
(let ((aa expr)
aaa temp)
(while (memq (car-safe (setq aaa (nth 1 aa))) '(+ -))
(if (setq temp (math-combine-sum (nth 2 aaa) (nth 2 math-simplify-expr)
(if (setq temp (math-combine-sum (nth 2 aaa) (nth 2 expr)
(eq (car aaa) '-)
(eq (car math-simplify-expr) '-) t))
(eq (car expr) '-) t))
(progn
(setcar (cdr (cdr math-simplify-expr)) temp)
(setcar math-simplify-expr '+)
(setcar (cdr (cdr expr)) temp)
(setcar expr '+)
(setcar (cdr (cdr aaa)) 0)))
(setq aa (nth 1 aa)))
(if (setq temp (math-combine-sum aaa (nth 2 math-simplify-expr)
nil (eq (car math-simplify-expr) '-) t))
(if (setq temp (math-combine-sum aaa (nth 2 expr)
nil (eq (car expr) '-) t))
(progn
(setcar (cdr (cdr math-simplify-expr)) temp)
(setcar math-simplify-expr '+)
(setcar (cdr (cdr expr)) temp)
(setcar expr '+)
(setcar (cdr aa) 0)))
math-simplify-expr))
expr))
(math-defsimplify *
(math-simplify-times))
(defun math-simplify-times ()
(if (eq (car-safe (nth 2 math-simplify-expr)) '*)
(and (math-beforep (nth 1 (nth 2 math-simplify-expr)) (nth 1 math-simplify-expr))
(or (math-known-scalarp (nth 1 math-simplify-expr) t)
(math-known-scalarp (nth 1 (nth 2 math-simplify-expr)) t))
(let ((x (nth 1 math-simplify-expr)))
(setcar (cdr math-simplify-expr) (nth 1 (nth 2 math-simplify-expr)))
(setcar (cdr (nth 2 math-simplify-expr)) x)))
(and (math-beforep (nth 2 math-simplify-expr) (nth 1 math-simplify-expr))
(or (math-known-scalarp (nth 1 math-simplify-expr) t)
(math-known-scalarp (nth 2 math-simplify-expr) t))
(let ((x (nth 2 math-simplify-expr)))
(setcar (cdr (cdr math-simplify-expr)) (nth 1 math-simplify-expr))
(setcar (cdr math-simplify-expr) x))))
(let ((aa math-simplify-expr)
(if (eq (car-safe (nth 2 expr)) '*)
(and (math-beforep (nth 1 (nth 2 expr)) (nth 1 expr))
(or (math-known-scalarp (nth 1 expr) t)
(math-known-scalarp (nth 1 (nth 2 expr)) t))
(let ((x (nth 1 expr)))
(setcar (cdr expr) (nth 1 (nth 2 expr)))
(setcar (cdr (nth 2 expr)) x)))
(and (math-beforep (nth 2 expr) (nth 1 expr))
(or (math-known-scalarp (nth 1 expr) t)
(math-known-scalarp (nth 2 expr) t))
(let ((x (nth 2 expr)))
(setcar (cdr (cdr expr)) (nth 1 expr))
(setcar (cdr expr) x))))
(let ((aa expr)
aaa temp
(safe t) (scalar (math-known-scalarp (nth 1 math-simplify-expr))))
(if (and (Math-ratp (nth 1 math-simplify-expr))
(setq temp (math-common-constant-factor (nth 2 math-simplify-expr))))
(safe t) (scalar (math-known-scalarp (nth 1 expr))))
(if (and (Math-ratp (nth 1 expr))
(setq temp (math-common-constant-factor (nth 2 expr))))
(progn
(setcar (cdr (cdr math-simplify-expr))
(math-cancel-common-factor (nth 2 math-simplify-expr) temp))
(setcar (cdr math-simplify-expr) (math-mul (nth 1 math-simplify-expr) temp))))
(setcar (cdr (cdr expr))
(math-cancel-common-factor (nth 2 expr) temp))
(setcar (cdr expr) (math-mul (nth 1 expr) temp))))
(while (and (eq (car-safe (setq aaa (nth 2 aa))) '*)
safe)
(if (setq temp (math-combine-prod (nth 1 math-simplify-expr)
(if (setq temp (math-combine-prod (nth 1 expr)
(nth 1 aaa) nil nil t))
(progn
(setcar (cdr math-simplify-expr) temp)
(setcar (cdr expr) temp)
(setcar (cdr aaa) 1)))
(setq safe (or scalar (math-known-scalarp (nth 1 aaa) t))
aa (nth 2 aa)))
(if (and (setq temp (math-combine-prod aaa (nth 1 math-simplify-expr) nil nil t))
(if (and (setq temp (math-combine-prod aaa (nth 1 expr) nil nil t))
safe)
(progn
(setcar (cdr math-simplify-expr) temp)
(setcar (cdr expr) temp)
(setcar (cdr (cdr aa)) 1)))
(if (and (eq (car-safe (nth 1 math-simplify-expr)) 'frac)
(memq (nth 1 (nth 1 math-simplify-expr)) '(1 -1)))
(math-div (math-mul (nth 2 math-simplify-expr)
(nth 1 (nth 1 math-simplify-expr)))
(nth 2 (nth 1 math-simplify-expr)))
math-simplify-expr)))
(if (and (eq (car-safe (nth 1 expr)) 'frac)
(memq (nth 1 (nth 1 expr)) '(1 -1)))
(math-div (math-mul (nth 2 expr)
(nth 1 (nth 1 expr)))
(nth 2 (nth 1 expr)))
expr)))
(math-defsimplify /
(math-simplify-divide))
(math-simplify-divide expr))
(defun math-simplify-divide ()
(let ((np (cdr math-simplify-expr))
(defvar math--simplify-divide-expr)
(defun math-simplify-divide (expr)
(let ((np (cdr expr))
(nover nil)
(nn (and (or (eq (car math-simplify-expr) '/)
(not (Math-realp (nth 2 math-simplify-expr))))
(math-common-constant-factor (nth 2 math-simplify-expr))))
(nn (and (or (eq (car expr) '/)
(not (Math-realp (nth 2 expr))))
(math-common-constant-factor (nth 2 expr))))
n op)
(if nn
(progn
(setq n (and (or (eq (car math-simplify-expr) '/)
(not (Math-realp (nth 1 math-simplify-expr))))
(math-common-constant-factor (nth 1 math-simplify-expr))))
(setq n (and (or (eq (car expr) '/)
(not (Math-realp (nth 1 expr))))
(math-common-constant-factor (nth 1 expr))))
(if (and (eq (car-safe nn) 'frac) (eq (nth 1 nn) 1) (not n))
(unless (and (eq (car-safe math-simplify-expr) 'calcFunc-eq)
(eq (car-safe (nth 1 math-simplify-expr)) 'var)
(not (math-expr-contains (nth 2 math-simplify-expr)
(nth 1 math-simplify-expr))))
(setcar (cdr math-simplify-expr)
(math-mul (nth 2 nn) (nth 1 math-simplify-expr)))
(setcar (cdr (cdr math-simplify-expr))
(math-cancel-common-factor (nth 2 math-simplify-expr) nn))
(unless (and (eq (car-safe expr) 'calcFunc-eq)
(eq (car-safe (nth 1 expr)) 'var)
(not (math-expr-contains (nth 2 expr)
(nth 1 expr))))
(setcar (cdr expr)
(math-mul (nth 2 nn) (nth 1 expr)))
(setcar (cdr (cdr expr))
(math-cancel-common-factor (nth 2 expr) nn))
(if (and (math-negp nn)
(setq op (assq (car math-simplify-expr) calc-tweak-eqn-table)))
(setcar math-simplify-expr (nth 1 op))))
(setq op (assq (car expr) calc-tweak-eqn-table)))
(setcar expr (nth 1 op))))
(if (and n (not (eq (setq n (math-frac-gcd n nn)) 1)))
(progn
(setcar (cdr math-simplify-expr)
(math-cancel-common-factor (nth 1 math-simplify-expr) n))
(setcar (cdr (cdr math-simplify-expr))
(math-cancel-common-factor (nth 2 math-simplify-expr) n))
(setcar (cdr expr)
(math-cancel-common-factor (nth 1 expr) n))
(setcar (cdr (cdr expr))
(math-cancel-common-factor (nth 2 expr) n))
(if (and (math-negp n)
(setq op (assq (car math-simplify-expr)
(setq op (assq (car expr)
calc-tweak-eqn-table)))
(setcar math-simplify-expr (nth 1 op))))))))
(if (and (eq (car-safe (car np)) '/)
(math-known-scalarp (nth 2 math-simplify-expr) t))
(progn
(setq np (cdr (nth 1 math-simplify-expr)))
(while (eq (car-safe (setq n (car np))) '*)
(and (math-known-scalarp (nth 2 n) t)
(math-simplify-divisor (cdr n) (cdr (cdr math-simplify-expr)) nil t))
(setq np (cdr (cdr n))))
(math-simplify-divisor np (cdr (cdr math-simplify-expr)) nil t)
(setq nover t
np (cdr (cdr (nth 1 math-simplify-expr))))))
(while (eq (car-safe (setq n (car np))) '*)
(and (math-known-scalarp (nth 2 n) t)
(math-simplify-divisor (cdr n) (cdr (cdr math-simplify-expr)) nover t))
(setq np (cdr (cdr n))))
(math-simplify-divisor np (cdr (cdr math-simplify-expr)) nover t)
math-simplify-expr))
(setcar expr (nth 1 op))))))))
(let ((math--simplify-divide-expr expr)) ;For use in math-simplify-divisor
(if (and (eq (car-safe (car np)) '/)
(math-known-scalarp (nth 2 expr) t))
(progn
(setq np (cdr (nth 1 expr)))
(while (eq (car-safe (setq n (car np))) '*)
(and (math-known-scalarp (nth 2 n) t)
(math-simplify-divisor (cdr n) (cdr (cdr expr)) nil t))
(setq np (cdr (cdr n))))
(math-simplify-divisor np (cdr (cdr expr)) nil t)
(setq nover t
np (cdr (cdr (nth 1 expr))))))
(while (eq (car-safe (setq n (car np))) '*)
(and (math-known-scalarp (nth 2 n) t)
(math-simplify-divisor (cdr n) (cdr (cdr expr)) nover t))
(setq np (cdr (cdr n))))
(math-simplify-divisor np (cdr (cdr expr)) nover t)
expr)))
;; The variables math-simplify-divisor-nover and math-simplify-divisor-dover
;; are local variables for math-simplify-divisor, but are used by
......@@ -587,25 +583,25 @@
(defvar math-simplify-divisor-nover)
(defvar math-simplify-divisor-dover)
(defun math-simplify-divisor (np dp math-simplify-divisor-nover
math-simplify-divisor-dover)
(defun math-simplify-divisor (np dp nover dover)
(cond ((eq (car-safe (car dp)) '/)
(math-simplify-divisor np (cdr (car dp))
math-simplify-divisor-nover
math-simplify-divisor-dover)
nover dover)
(and (math-known-scalarp (nth 1 (car dp)) t)
(math-simplify-divisor np (cdr (cdr (car dp)))
math-simplify-divisor-nover
(not math-simplify-divisor-dover))))
((or (or (eq (car math-simplify-expr) '/)
nover (not dover))))
((or (or (eq (car math--simplify-divide-expr) '/)
(let ((signs (math-possible-signs (car np))))
(or (memq signs '(1 4))
(and (memq (car math-simplify-expr) '(calcFunc-eq calcFunc-neq))
(and (memq (car math--simplify-divide-expr)
'(calcFunc-eq calcFunc-neq))
(eq signs 5))
math-living-dangerously)))
(math-numberp (car np)))
(let (d
(safe t)
(math-simplify-divisor-nover nover)
(math-simplify-divisor-dover dover)
(scalar (math-known-scalarp (car np))))
(while (and (eq (car-safe (setq d (car dp))) '*)
safe)
......@@ -621,14 +617,16 @@
op)
(if temp
(progn
(and (not (memq (car math-simplify-expr) '(/ calcFunc-eq calcFunc-neq)))
(and (not (memq (car math--simplify-divide-expr)
'(/ calcFunc-eq calcFunc-neq)))
(math-known-negp (car dp))
(setq op (assq (car math-simplify-expr) calc-tweak-eqn-table))
(setcar math-simplify-expr (nth 1 op)))
(setq op (assq (car math--simplify-divide-expr)
calc-tweak-eqn-table))
(setcar math--simplify-divide-expr (nth 1 op)))
(setcar np (if math-simplify-divisor-nover (math-div 1 temp) temp))
(setcar dp 1))
(and math-simplify-divisor-dover (not math-simplify-divisor-nover)
(eq (car math-simplify-expr) '/)
(eq (car math--simplify-divide-expr) '/)
(eq (car-safe (car dp)) 'calcFunc-sqrt)
(Math-integerp (nth 1 (car dp)))
(progn
......@@ -680,26 +678,23 @@
(math-gcd (nth 2 a) (nth 2 b)))))))
(math-defsimplify %
(math-simplify-mod))
(defun math-simplify-mod ()
(and (Math-realp (nth 2 math-simplify-expr))
(Math-posp (nth 2 math-simplify-expr))
(let ((lin (math-is-linear (nth 1 math-simplify-expr)))
t1 t2 t3)
(and (Math-realp (nth 2 expr))
(Math-posp (nth 2 expr))
(let ((lin (math-is-linear (nth 1 expr)))
t1)
(or (and lin
(or (math-negp (car lin))
(not (Math-lessp (car lin) (nth 2 math-simplify-expr))))
(not (Math-lessp (car lin) (nth 2 expr))))
(list '%
(list '+
(math-mul (nth 1 lin) (nth 2 lin))
(math-mod (car lin) (nth 2 math-simplify-expr)))
(nth 2 math-simplify-expr)))
(math-mod (car lin) (nth 2 expr)))
(nth 2 expr)))
(and lin
(not (math-equal-int (nth 1 lin) 1))
(math-num-integerp (nth 1 lin))
(math-num-integerp (nth 2 math-simplify-expr))
(setq t1 (calcFunc-gcd (nth 1 lin) (nth 2 math-simplify-expr)))
(math-num-integerp (nth 2 expr))
(setq t1 (calcFunc-gcd (nth 1 lin) (nth 2 expr)))
(not (math-equal-int t1 1))
(list '*
t1
......@@ -709,53 +704,53 @@
(nth 2 lin))
(let ((calc-prefer-frac t))
(math-div (car lin) t1)))
(math-div (nth 2 math-simplify-expr) t1))))
(and (math-equal-int (nth 2 math-simplify-expr) 1)
(math-div (nth 2 expr) t1))))
(and (math-equal-int (nth 2 expr) 1)
(math-known-integerp (if lin
(math-mul (nth 1 lin) (nth 2 lin))
(nth 1 math-simplify-expr)))
(nth 1 expr)))
(if lin (math-mod (car lin) 1) 0))))))
(math-defsimplify (calcFunc-eq calcFunc-neq calcFunc-lt
calcFunc-gt calcFunc-leq calcFunc-geq)
(if (= (length math-simplify-expr) 3)
(math-simplify-ineq)))
(if (= (length expr) 3)
(math-simplify-ineq expr)))
(defun math-simplify-ineq ()
(let ((np (cdr math-simplify-expr))
(defun math-simplify-ineq (expr)
(let ((np (cdr expr))
n)
(while (memq (car-safe (setq n (car np))) '(+ -))
(math-simplify-add-term (cdr (cdr n)) (cdr (cdr math-simplify-expr))
(math-simplify-add-term (cdr (cdr n)) (cdr (cdr expr))
(eq (car n) '-) nil)
(setq np (cdr n)))
(math-simplify-add-term np (cdr (cdr math-simplify-expr)) nil
(eq np (cdr math-simplify-expr)))
(math-simplify-divide)
(let ((signs (math-possible-signs (cons '- (cdr math-simplify-expr)))))
(or (cond ((eq (car math-simplify-expr) 'calcFunc-eq)
(math-simplify-add-term np (cdr (cdr expr)) nil
(eq np (cdr expr)))
(math-simplify-divide expr)
(let ((signs (math-possible-signs (cons '- (cdr expr)))))
(or (cond ((eq (car expr) 'calcFunc-eq)
(or (and (eq signs 2) 1)
(and (memq signs '(1 4 5)) 0)))
((eq (car math-simplify-expr) 'calcFunc-neq)
((eq (car expr) 'calcFunc-neq)
(or (and (eq signs 2) 0)
(and (memq signs '(1 4 5)) 1)))
((eq (car math-simplify-expr) 'calcFunc-lt)
((eq (car expr) 'calcFunc-lt)
(or (and (eq signs 1) 1)
(and (memq signs '(2 4 6)) 0)))
((eq (car math-simplify-expr) 'calcFunc-gt)
((eq (car expr) 'calcFunc-gt)
(or (and (eq signs 4) 1)
(and (memq signs '(1 2 3)) 0)))
((eq (car math-simplify-expr) 'calcFunc-leq)
((eq (car expr) 'calcFunc-leq)
(or (and (eq signs 4) 0)
(and (memq signs '(1 2 3)) 1)))
((eq (car math-simplify-expr) 'calcFunc-geq)
((eq (car expr) 'calcFunc-geq)
(or (and (eq signs 1) 0)
(and (memq signs '(2 4 6)) 1))))
math-simplify-expr))))
expr))))
(defun math-simplify-add-term (np dp minus lplain)
(or (math-vectorp (car np))
(let ((rplain t)
n d dd temp)
n d temp)
(while (memq (car-safe (setq n (car np) d (car dp))) '(+ -))
(setq rplain nil)
(if (setq temp (math-combine-sum n (nth 2 d)
......@@ -782,27 +777,27 @@
(setcar dp (setq n (math-neg temp)))))))))
(math-defsimplify calcFunc-sin
(or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(nth 1 (nth 1 math-simplify-expr)))
(and (math-looks-negp (nth 1 math-simplify-expr))
(math-neg (list 'calcFunc-sin (math-neg (nth 1 math-simplify-expr)))))
(or (and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsin)
(nth 1 (nth 1 expr)))
(and (math-looks-negp (nth 1 expr))
(math-neg (list 'calcFunc-sin (math-neg (nth 1 expr)))))
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(let ((n (math-linear-in (nth 1 expr) '(var pi var-pi))))
(and n
(math-known-sin (car n) (nth 1 n) 120 0))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(let ((n (math-integer-plus (nth 1 expr))))
(and n
(math-known-sin (car n) (nth 1 n) '(frac 2 3) 0))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
(and (eq (car-safe (nth 1 expr)) 'calcFunc-arccos)
(list 'calcFunc-sqrt (math-sub 1 (math-sqr
(nth 1 (nth 1 math-simplify-expr))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
(math-div (nth 1 (nth 1 math-simplify-expr))
(nth 1 (nth 1 expr))))))
(and (eq (car-safe (nth 1 expr)) 'calcFunc-arctan)
(math-div (nth 1 (nth 1 expr))
(list 'calcFunc-sqrt
(math-add 1 (math-sqr
(nth 1 (nth 1 math-simplify-expr)))))))
(let ((m (math-should-expand-trig (nth 1 math-simplify-expr))))
(nth 1 (nth 1 expr)))))))
(let ((m (math-should-expand-trig (nth 1 expr))))
(and m (integerp (car m))
(let ((n (car m)) (a (nth 1 m)))
(list '+
......@@ -812,27 +807,27 @@
(list 'calcFunc-sin a))))))))
(math-defsimplify calcFunc-cos
(or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
(nth 1 (nth 1 math-simplify-expr)))
(and (math-looks-negp (nth 1 math-simplify-expr))
(list 'calcFunc-cos (math-neg (nth 1 math-simplify-expr))))
(or (and (eq (car-safe (nth 1 expr)) 'calcFunc-arccos)
(nth 1 (nth 1 expr)))
(and (math-looks-negp (nth 1 expr))
(list 'calcFunc-cos (math-neg (nth 1 expr))))
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(let ((n (math-linear-in (nth 1 expr) '(var pi var-pi))))
(and n
(math-known-sin (car n) (nth 1 n) 120 300))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(let ((n (math-integer-plus (nth 1 expr))))
(and n
(math-known-sin (car n) (nth 1 n) '(frac 2 3) 300))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsin)
(list 'calcFunc-sqrt
(math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
(math-sub 1 (math-sqr (nth 1 (nth 1 expr))))))
(and (eq (car-safe (nth 1 expr)) 'calcFunc-arctan)
(math-div 1
(list 'calcFunc-sqrt
(math-add 1
(math-sqr (nth 1 (nth 1 math-simplify-expr)))))))
(let ((m (math-should-expand-trig (nth 1 math-simplify-expr))))
(math-sqr (nth 1 (nth 1 expr)))))))
(let ((m (math-should-expand-trig (nth 1 expr))))
(and m (integerp (car m))
(let ((n (car m)) (a (nth 1 m)))
(list '-
......@@ -842,53 +837,53 @@
(list 'calcFunc-sin a))))))))
(math-defsimplify calcFunc-sec
(or (and (math-looks-negp (nth 1 math-simplify-expr))
(list 'calcFunc-sec (math-neg (nth 1 math-simplify-expr))))
(or (and (math-looks-negp (nth 1 expr))
(list 'calcFunc-sec (math-neg (nth 1 expr))))
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(let ((n (math-linear-in (nth 1 expr) '(var pi var-pi))))
(and n
(math-div 1 (math-known-sin (car n) (nth 1 n) 120 300)))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(let ((n (math-integer-plus (nth 1 expr))))
(and n
(math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300)))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsin)
(math-div
1
(list 'calcFunc-sqrt
(math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
(math-sub 1 (math-sqr (nth 1 (nth 1 expr)))))))
(and (eq (car-safe (nth 1 expr)) 'calcFunc-arccos)
(math-div
1
(nth 1 (nth 1 math-simplify-expr))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
(nth 1 (nth 1 expr))))
(and (eq (car-safe (nth 1 expr)) 'calcFunc-arctan)
(list 'calcFunc-sqrt
(math-add 1
(math-sqr (nth 1 (nth 1 math-simplify-expr))))))))
(math-sqr (nth 1 (nth 1 expr))))))))
(math-defsimplify calcFunc-csc
(or (and (math-looks-negp (nth 1 math-simplify-expr))
(math-neg (list 'calcFunc-csc (math-neg (nth 1 math-simplify-expr)))))
(or (and (math-looks-negp (nth 1 expr))
(math-neg (list 'calcFunc-csc (math-neg (nth 1 expr)))))
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(let ((n (math-linear-in (nth