;;;;;;;;;;;;;;;;;;; -*- Mode: Lisp; Package: Macsyma -*- ;;;;;;;;;;;;;;;;;;; ;;; (c) Copyright 1980 Massachusetts Institute of Technology ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (macsyma-module ops) ;;; mathematical ops to call from translated code. ;;; this is to replace maxsrc;opers, thus simplifying things, ;;; and removing extra symbols from the environment. ;;; With the OPEXPRP switch set these will also speed up ;;; macsyma arithmetic. (DEFMACRO DEF-MARITH-NARY (MPLUS ZERO ZEROP PLUS) `(DEFUN ,MPLUS N (LET ((SUM ,ZERO) (PUNT ()) (ARG)) (DO ((J 1 (1+ J))) ((> J N) (IF (NULL PUNT) SUM (SIMPLIFY `((,',MPLUS) ,.(IF (,ZEROP SUM) NIL (LIST SUM)) ,.PUNT)))) (SETQ ARG (ARG J)) (IF (NUMBERP ARG) (SETQ SUM (,PLUS SUM ARG)) (PUSH ARG PUNT)))))) (DEF-MARITH-NARY MPLUS 0 ZEROP PLUS) (DEF-MARITH-NARY MTIMES 1 ONEP TIMES) (DEFMACRO DEF-MARITH-BINARY (MEXPT EXPT) `(DEFUN ,MEXPT (X Y) (IF (AND (NUMBERP X) (NUMBERP Y)) (,EXPT X Y) (SIMPLIFY `((,',MEXPT) ,X ,Y))))) (DEF-MARITH-BINARY MEXPT EXPT) (DEF-MARITH-BINARY MQUOTIENT QUOTIENT) (DEFMACRO DEF-MARITH-UNARY (MMINUS MINUS) `(DEFUN ,MMINUS (X) (IF (NUMBERP X) (,MINUS X) (SIMPLIFY `((,',MMINUS) ,X))))) (DEF-MARITH-UNARY MMINUS MINUS)