~ubuntu-branches/debian/squeeze/maxima/squeeze

« back to all changes in this revision

Viewing changes to src/ratmac.lisp

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-10-18 14:52:42 UTC
  • mto: (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061018145242-vzyrm5hmxr8kiosf
ImportĀ upstreamĀ versionĀ 5.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
;;;     (c) Copyright 1980 Massachusetts Institute of Technology         ;;;
9
9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
10
 
11
 
(in-package "MAXIMA")
 
11
(in-package :maxima)
12
12
(macsyma-module ratmac macro)
13
13
 
14
14
;; Macros for manipulating rational functions.
15
15
 
16
 
(DEFMACRO PCOEFP (E) `(ATOM ,E))
17
 
 
18
 
 
19
 
 
20
 
#-CL
21
 
(DEFMACRO PZEROP (X) `(SIGNP E ,X))                     ;TRUE FOR 0 OR 0.0
 
16
(defmacro pcoefp (e) `(atom ,e))
 
17
 
 
18
 
 
19
 
 
20
#-cl
 
21
(defmacro pzerop (x) `(signp e ,x))     ;TRUE FOR 0 OR 0.0
22
22
;;;(DEFMACRO PZEROP (X) `(LET ((gg1032 ,X)) (AND (NUMBERP gg1032) (ZEROP gg1032))))
23
23
 
24
24
(proclaim '(inline pzerop))
25
 
#+CL
 
25
#+cl
26
26
(defun pzerop (x) (if (fixnump x) (zerop (the fixnum x))
27
 
                    (if (consp x) nil
28
 
                      (and (floatp x) (zerop x)))))
29
 
 
30
 
#+CL
31
 
(DEFMACRO PZERO () 0)
32
 
(DEFMACRO PTZEROP (TERMS) `(NULL ,TERMS))               ;for poly terms
33
 
(DEFMACRO PTZERO () '())
34
 
 
35
 
#-CL
36
 
(DEFMACRO CZEROP (C) `(SIGNP E ,C))
37
 
#+CL
 
27
                      (if (consp x) nil
 
28
                          (and (floatp x) (zerop x)))))
 
29
 
 
30
#+cl
 
31
(defmacro pzero () 0)
 
32
(defmacro ptzerop (terms) `(null ,terms)) ;for poly terms
 
33
(defmacro ptzero () '())
 
34
 
 
35
#-cl
 
36
(defmacro czerop (c) `(signp e ,c))
 
37
#+cl
38
38
(defmacro czerop (c) `(pzerop ,c))
39
39
 
40
 
(DEFMACRO CMINUS (C) `(MINUS ,C))
41
 
(DEFMACRO CMINUSP (C) `(MINUSP ,C))
42
 
(DEFMACRO CDERIVATIVE (ign ign1)ign ign1 0)
 
40
(defmacro cminus (c) `(minus ,c))
 
41
(defmacro cminusp (c) `(minusp ,c))
 
42
(defmacro cderivative (ign ign1)ign ign1 0)
43
43
 
44
44
;; Similar to REMOVE on the Lisp Machine
45
 
(DEFMACRO DELET (ITEM LLIST) `(ZL-DELETE ,ITEM (COPY-TOP-LEVEL ,LLIST )))
 
45
(defmacro delet (item llist) `(zl-delete ,item (copy-top-level ,llist )))
46
46
 
47
47
;; the rational function package uses GENSYM's to represent variables.
48
48
;; The PDP-10 implementation used to use the PRINTNAME of the gensym
51
51
;; to use the property list, as thats a lot cheaper than creating a value
52
52
;; cell. Actually, better to use the PACKAGE slot, a kludge is a kludge right?
53
53
 
54
 
(DEFMACRO VALGET (ITEM)
55
 
  #+NIL `(GET ,ITEM 'GENSYMVAL)
56
 
  #-NIL `(SYMBOL-VALUE ,ITEM))
57
 
 
58
 
(DEFMACRO VALPUT (ITEM VAL)
59
 
  `(SETF (VALGET ,ITEM) ,VAL))
60
 
 
 
54
(defmacro valget (item)
 
55
  #+nil `(get ,item 'gensymval)
 
56
  #-nil `(symbol-value ,item))
 
57
 
 
58
(defmacro valput (item val)
 
59
  `(setf (valget ,item) ,val))
 
60
 
 
61
;; A historical note from Richard Fateman, on the maxima list,
 
62
;; 2006/03/17:
 
63
;;
 
64
;; "The name pointerp comes from the original hack when we wanted a
 
65
;; bunch of atoms that could be ordered fast, we just generated, say,
 
66
;; 10 gensyms.  Then we sorted them by the addresses of the symbols in
 
67
;; memory.  Then we associated them with x,y,z,....  This meant that
 
68
;; pointergp was one or two instructions on a PDP-10, in assembler."
 
69
;; 
 
70
;; "That version of pointergp turned out to be more trouble than it was
 
71
;; worth because we sometimes had to interpolate between two gensym
 
72
;; "addresses" and to do that we had to kind of renumber too much of
 
73
;; the universe.  Or maybe we just weren't clever enough to do it
 
74
;; without introducing bugs."
 
75
;;
 
76
;; Richard Fateman also says pointergp needs to be fast because it's
 
77
;; called a lot.  So if you get an error from pointergp, it's probably
 
78
;; because someone forgot to initialize things correctly.
61
79
(proclaim '(inline pointergp))
62
 
(DEFun POINTERGP (A B) (f> (valget A) (VALGET B)))
 
80
(defun pointergp (a b)
 
81
  (f> (valget a) (valget b)))
63
82
 
64
 
;(macro ALGV (L) `(AND $ALGEBRAIC (GET ,(CADR L) 'TELLRAT)))
 
83
;;(macro ALGV (L) `(AND $ALGEBRAIC (GET ,(CADR L) 'TELLRAT)))
65
84
(defmacro algv (v)
66
85
  `(and $algebraic (get ,v 'tellrat)))
67
86
 
68
87
 
69
 
(DEFMACRO EQN (&REST L) `(EQUAL . ,L))
70
 
 
71
 
(DEFMACRO RZERO () ''(0 . 1))
72
 
(DEFMACRO RZEROP (A) `(PZEROP (CAR ,A)))
73
 
 
74
 
(defmacro PRIMPART (p) `(cadr (oldcontent ,p)))
 
88
(defmacro eqn (&rest l) `(equal . ,l))
 
89
 
 
90
(defmacro rzero () ''(0 . 1))
 
91
(defmacro rzerop (a) `(pzerop (car ,a)))
 
92
 
 
93
(defmacro primpart (p) `(cadr (oldcontent ,p)))
75
94
 
76
95
;;poly constructor
77
96
 
78
97
(defmacro make-poly (var &optional (terms-or-e nil options?) (c nil e-c?)
79
 
                         (terms nil terms?))
 
98
                     (terms nil terms?))
80
99
  (cond ((null options?) `(cons ,var '(1 1)))
81
100
        ((null e-c?) `(psimp ,var ,terms-or-e))
82
101
        ((null terms?) `(list ,var ,terms-or-e ,c))
84
103
 
85
104
;;Poly selector functions
86
105
 
87
 
(defmacro P-VAR (p) `(car ,p))
88
 
 
89
 
(defmacro P-TERMS (p) `(cdr ,p))
90
 
 
91
 
(defmacro P-LC (p) `(caddr ,p))                 ;leading coefficient
92
 
 
93
 
(defmacro P-LE (p) `(cadr ,p))
94
 
 
95
 
(defmacro P-RED (p) `(cdddr ,p))
 
106
(defmacro p-var (p) `(car ,p))
 
107
 
 
108
(defmacro p-terms (p) `(cdr ,p))
 
109
 
 
110
(defmacro p-lc (p) `(caddr ,p))         ;leading coefficient
 
111
 
 
112
(defmacro p-le (p) `(cadr ,p))
 
113
 
 
114
(defmacro p-red (p) `(cdddr ,p))
96
115
 
97
116
;;poly terms selectors
98
117
 
99
 
(defmacro PT-LC (terms) `(cadr ,terms))
100
 
 
101
 
(defmacro PT-LE (terms) `(car ,terms))
102
 
 
103
 
(defmacro PT-RED (terms) `(cddr ,terms))
 
118
(defmacro pt-lc (terms) `(cadr ,terms))
 
119
 
 
120
(defmacro pt-le (terms) `(car ,terms))
 
121
 
 
122
(defmacro pt-red (terms) `(cddr ,terms))
104
123
 
105
124
;; Taken from SININT and RISCH.  Somebody document these please.
106
125
 
107
 
(DEFMACRO R+ (R . L)
108
 
          (COND ((NULL L) R)
109
 
                (T `(RATPL ,R (R+ ,@L)))))
110
 
 
111
 
(DEFMACRO R* (R . L)
112
 
          (COND ((NULL L) R)
113
 
                (T `(RATTI ,R (R* ,@L) T))))
114
 
 
115
 
(DEFMACRO R- (R . L)
116
 
          (COND ((NULL L) `(RATMINUS (RATFIX ,R)))
117
 
                (T `(RATDIF (RATFIX ,R) (R+ ,@L)))))
 
126
(defmacro r+ (r . l)
 
127
  (cond ((null l) r)
 
128
        (t `(ratpl ,r (r+ ,@l)))))
 
129
 
 
130
(defmacro r* (r . l)
 
131
  (cond ((null l) r)
 
132
        (t `(ratti ,r (r* ,@l) t))))
 
133
 
 
134
(defmacro r- (r . l)
 
135
  (cond ((null l) `(ratminus (ratfix ,r)))
 
136
        (t `(ratdif (ratfix ,r) (r+ ,@l)))))
118
137
 
119
138
 
120
139
(defvar $ratvarswitch t)
121
140
 
122
 
;(defvar *rational-function-files* '(
123
 
;ratmac
124
 
;rat3a
125
 
;rat3b
126
 
;rat3c
127
 
;rat3e
128
 
;nrat4
129
 
;ratout
130
 
;lesfac
131
 
;factor
132
 
;algfac
133
 
;nalgfa
134
 
;newfac
135
 
;ufact
136
 
;result
137
 
;spgcd))
 
141
;;(defvar *rational-function-files* '(
 
142
;;ratmac
 
143
;;rat3a
 
144
;;rat3b
 
145
;;rat3c
 
146
;;rat3e
 
147
;;nrat4
 
148
;;ratout
 
149
;;lesfac
 
150
;;factor
 
151
;;algfac
 
152
;;nalgfa
 
153
;;newfac
 
154
;;ufact
 
155
;;result
 
156
;;spgcd))