|
@@ -56,6 +56,45 @@
|
|
|
(loop for (name test expander) in *rules*
|
|
|
do (if (apply test function)
|
|
|
(setf expansion-function expander)))
|
|
|
- (apply expansion-function (rest function)))))))
|
|
|
+ (if (functionp expansion-function)
|
|
|
+ (apply expansion-function (rest function))
|
|
|
+ (error "Undefined expansion: ~a" op)))))))
|
|
|
+
|
|
|
+(defun csc (x)
|
|
|
+ "csc -- (csc x)
|
|
|
+Calculate the cosecant of x"
|
|
|
+ (/ (sin x)))
|
|
|
+
|
|
|
+(defun sec (x)
|
|
|
+ "sec -- (sec x)
|
|
|
+Calculate the secant of x"
|
|
|
+ (/ (cos x)))
|
|
|
+
|
|
|
+(def-expansion mult/2 (* 2) (first second)
|
|
|
+ (cond
|
|
|
+ ((numberp first)
|
|
|
+ `(* ,first ,(derive (if (listp second) second (list second)))))
|
|
|
+ ((numberp second)
|
|
|
+ `(* ,second ,(derive (if (listp first) first (list second)))))
|
|
|
+ (t
|
|
|
+ `(+ (* ,first ,(derive (if (listp second) second (list second))))
|
|
|
+ (* ,second ,(derive (if (listp first) first (list first))))))))
|
|
|
+
|
|
|
+(def-expansion exp/1 (exp 1) (expression)
|
|
|
+ (if (listp expression)
|
|
|
+ `(* (expt ,expression) ,(derive expression))
|
|
|
+ (if (numberp expression)
|
|
|
+ 0
|
|
|
+ `(expt ,expression))))
|
|
|
+
|
|
|
+(def-expansion expt/2 (expt 2) (base exponent)
|
|
|
+ (if (listp base)
|
|
|
+ `(* ,exponent (expt ,base (1- ,exponent)) ,(derive base))
|
|
|
+ `(* ,exponent (expt ,base (1- ,exponent)))))
|
|
|
+
|
|
|
+(def-expansion log/1 (log 1) (expression)
|
|
|
+ `(/ ,(derive (if (listp expression) expression (list expression))) ,expression))
|
|
|
+
|
|
|
+(def-expansion log/2 (log 2) (number base))
|
|
|
|
|
|
;;; End derive2
|