-2

People, help me with this lisp function. There is a list with polynomial coefficients. This function needs to calculate value of polynomial.

Pol (x list)

for example (Pol 2 '(3 5 2)) => 17

sds
  • 58,617
  • 29
  • 161
  • 278
  • Is this homework for a class, or legitimate question? – atconway Mar 11 '13 at 20:34
  • This is for a class. I solved many other problems but i can't believe i can't solve this one. Problem is that we can't use exp function. I tried to find another solution but recursion always makes a problem with first parameter. (defun pol (x list) (cond ((null list) '0) (t (+ (* x (car list)) (pol (* x x) (cdr list)))) ) ) (defun polynom (x list) (+ (car list) (pol x (cdr list))) ) this is my try – user1973035 Mar 11 '13 at 20:45
  • @user, can you post your try as formatted code in your question? (We could try to copy it from your comment, but we have no hope of indenting it properly without the source.) – Frédéric Hamidi Mar 11 '13 at 20:49

1 Answers1

1

You need to use the Horner's method.

sds
  • 58,617
  • 29
  • 161
  • 278
  • (defun polynom (x list) (cond ((null list) '0) (t (+ (car list) (* x (polynom x (cdr list))))) ) ) Thanks man for the link. I solved it. – user1973035 Mar 11 '13 at 21:03