Weitere Methoden für Polynome

Die Funktion zum Bestimmen von Nullstellen eines Polynoms (siehe Nullstellen von Polynomen bestimmen) benötigt einige Hilfsfunktionen. Zum Einen handelt es sich dabei um einen Satz von Methoden, die ein Polynom anhand seines Grads klassifizieren.

(defmethod constant-polynomial? ((this polynomial))
  t
  (= (degree this) 0))

(defmethod linear-polynomial? ((this polynomial))
  t
  (= (degree this) 1))

(defmethod quadratic-polynomial? ((this polynomial))
  t
  (= (degree this) 2))

(defmethod cubic-polynomial? ((this polynomial))
  t
  (= (degree this) 3))

(defmethod quartic-polynomial? ((this polynomial))
  t
  (= (degree this) 4))

Zum anderen werden einige Methoden definiert, die auf häufig benötigte Koeffizienten von Polynomen zugreifen.

(defmethod second-coefficient ((this polynomial))
  (> (degree this) 0)
  (second (. this coefficients)))

(defmethod third-coefficient ((this polynomial))
  (> (degree this) 1)
  (third (. this coefficients)))

(defmethod fourth-coefficient ((this polynomial))
  (> (degree this) 2)
  (fourth (. this coefficients)))

(defmethod last-coefficient ((this polynomial))
  t
  (first (last (. this coefficients))))

Und schließlich erlaubt es eine Methode, einfach lineare Polynome, also Polynome mit Grad 1, anzulegen.

(defproc linear-polynomial (a b)
  (new polynomial (list a b)))


polynomial-utilities.sheet.xml