Умножение многочленов
(defmethod mul2 ((p1 polynom) (p2 polynom))
(if (same-variable-p (var p1) (var p2))
(make-instance 'polynom
:var (var p1)
:terms (mul-terms (terms p1)
(terms p2)))
(error "Многочлены от разных переменных: ~s и ~s"
p1 p2)))
(defun mul-terms (tl1 tl2)
(if (null tl1)
()
(add-terms (mul-term-by-all-terms (first tl1) tl2)
(mul-terms (rest tl1) tl2))))
(defun mul-term-by-all-terms (t1 term-list)
(if (null term-list)
()
(let ((t2 (first term-list)))
(adjoin-term (make-term :coeff (mul2 (coeff t1) (coeff t2))
:order (+ (order t1) (order t2)))
(mul-term-by-all-terms t1 (rest term-list))))))
(mul2 p1 p2)
[МЧ (X) +5X^5+3.3X^4+3X^3+11.6X^2-10.7X-7]