浏览代码

Fixed a couple of polynomial functions

Samuel W. Flint 9 年之前
父节点
当前提交
dba42566e3
共有 1 个文件被更改,包括 6 次插入6 次删除
  1. 6 6
      manipulation.org

+ 6 - 6
manipulation.org

@@ -495,11 +495,11 @@ Foo
 #+BEGIN_SRC lisp
   (defun coefficient (term)
     (when (expression-type-p term 'polynomial-term)
-      (if (expression-type-p term 'multiplicative)
-          (second term)
-          (if (expression-type-p term 'variable)
-              1
-              term))))
+      (cond
+        ((expression-type-p term 'variable) 1)
+        ((expression-type-p term 'power) 1)
+        ((expression-type-p term 'multiplicative) (second term))
+        ((expression-type-p term 'numeric) term))))
 
   (defun term-variable (term)
     (when (expression-type-p term 'polynomial-term)
@@ -510,8 +510,8 @@ Foo
 
   (defun get-power (term)
     (cond
-      ((expression-type-p term 'polynomial-term) (third (third term)))
       ((expression-type-p term 'power) (third term))
+      ((expression-type-p term 'polynomial-term) (third (third term)))
       (t 0)))
 
   (defun same-order-p (term-a term-b)