Guest User

Example

a guest
Jan 31st, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.82 KB | None | 0 0
  1. (defun mulpoly (p1 p2)
  2.   "p1, p2 - lists with coeff"
  3.   (let* ((l1 (length p1))
  4.     (l2 (length p2))
  5.     (res (make-list (* l1 l2) :initial-element 0)))
  6.     (loop for n1 below (length p1) do
  7.       (loop for n2 below (length p2) do
  8.         (incf (nth (+ n1 n2) res) (* (nth n1 p1) (nth n2 p2)))))
  9.     res))
  10.  
  11. (defun product (x)
  12.   (if (= x 0) 1
  13.     (* x (product (1- x)))))
  14.  
  15. (defun c (a b)
  16.   (/ (product a) (* (product b) (product (- a b)))))
  17.  
  18. (defun newton (a b n)
  19.   "(a*x+b)^n to poly"
  20.   (let ((res (make-list (1+ n) :initial-element 0)))
  21.     (loop for k from 0 to n do
  22.       (setf (nth k res)
  23.         (* (expt a k) (c n k) (expt b (- n k)))))
  24.     res))
  25.  
  26. (defun intpoly (p1)
  27.   (let ((res (make-list (1+ (length p1)) :initial-element 0)))
  28.     (loop for i below (length p1) do
  29.       (setf (nth (1+ i) res) (/ (nth i p1) (length p1))))
  30.     res))
Advertisement
Add Comment
Please, Sign In to add comment