Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun mulpoly (p1 p2)
- "p1, p2 - lists with coeff"
- (let* ((l1 (length p1))
- (l2 (length p2))
- (res (make-list (* l1 l2) :initial-element 0)))
- (loop for n1 below (length p1) do
- (loop for n2 below (length p2) do
- (incf (nth (+ n1 n2) res) (* (nth n1 p1) (nth n2 p2)))))
- res))
- (defun product (x)
- (if (= x 0) 1
- (* x (product (1- x)))))
- (defun c (a b)
- (/ (product a) (* (product b) (product (- a b)))))
- (defun newton (a b n)
- "(a*x+b)^n to poly"
- (let ((res (make-list (1+ n) :initial-element 0)))
- (loop for k from 0 to n do
- (setf (nth k res)
- (* (expt a k) (c n k) (expt b (- n k)))))
- res))
- (defun intpoly (p1)
- (let ((res (make-list (1+ (length p1)) :initial-element 0)))
- (loop for i below (length p1) do
- (setf (nth (1+ i) res) (/ (nth i p1) (length p1))))
- res))
Advertisement
Add Comment
Please, Sign In to add comment