Function: math-normalize-fancy

math-normalize-fancy is a byte-compiled function defined in calc-ext.el.gz.

Signature

(math-normalize-fancy A)

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc-ext.el.gz
(defun math-normalize-fancy (a)
  (cond ((eq (car a) 'frac)
	 (math-make-frac (math-normalize (nth 1 a))
			 (math-normalize (nth 2 a))))
	((eq (car a) 'cplx)
	 (let ((real (math-normalize (nth 1 a)))
	       (imag (math-normalize (nth 2 a))))
	   (if (and (math-zerop imag)
		    (not math-simplify-only))   ; oh, what a kludge!
	       real
	     (list 'cplx real imag))))
	((eq (car a) 'polar)
	 (math-normalize-polar a))
	((eq (car a) 'hms)
	 (math-normalize-hms a))
	((eq (car a) 'date)
	 (list 'date (math-normalize (nth 1 a))))
	((eq (car a) 'mod)
	 (math-normalize-mod a))
	((eq (car a) 'sdev)
	 (let ((x (math-normalize (nth 1 a)))
	       (s (math-normalize (nth 2 a))))
	   (if (or (and (Math-objectp x) (not (Math-scalarp x)))
		   (and (Math-objectp s) (not (Math-scalarp s))))
	       (list 'calcFunc-sdev x s)
	     (math-make-sdev x s))))
	((eq (car a) 'intv)
	 (let ((mask (math-normalize (nth 1 a)))
	       (lo (math-normalize (nth 2 a)))
	       (hi (math-normalize (nth 3 a))))
	   (if (if (eq (car-safe lo) 'date)
		   (not (eq (car-safe hi) 'date))
		 (or (and (Math-objectp lo) (not (Math-anglep lo)))
		     (and (Math-objectp hi) (not (Math-anglep hi)))))
	       (list 'calcFunc-intv mask lo hi)
	     (math-make-intv mask lo hi))))
	((eq (car a) 'vec)
	 (cons 'vec (mapcar #'math-normalize (cdr a))))
	((eq (car a) 'quote)
	 (math-normalize (nth 1 a)))
	((eq (car a) 'special-const)
	 (calc-with-default-simplification
	  (math-normalize (nth 1 a))))
	((eq (car a) 'var)
	 (cons 'var (cdr a)))   ; need to re-cons for selection routines
	((eq (car a) 'calcFunc-if)
	 (math-normalize-logical-op a))
	((memq (car a) '(calcFunc-lambda calcFunc-quote calcFunc-condition))
	 (let ((calc-simplify-mode 'none))
	   (cons (car a) (mapcar #'math-normalize (cdr a)))))
	((eq (car a) 'calcFunc-evalto)
	 (setq a (or (nth 1 a) 0))
	 (or calc-refreshing-evaltos
	     (setq a (let ((calc-simplify-mode 'none)) (math-normalize a))))
	 (let ((b (if (and (eq (car-safe a) 'calcFunc-assign)
			   (= (length a) 3))
		      (nth 2 a)
		    a)))
	   (list 'calcFunc-evalto
		 a
		 (if (eq calc-simplify-mode 'none)
		     (math-normalize b)
		   (calc-with-default-simplification
		    (math-evaluate-expr b))))))
	((or (integerp (car a)) (consp (car a)))
	 (if (null (cdr a))
	     (math-normalize (car a))
	   (error "Can't use multi-valued function in an expression")))))