Best way to store multiple polynomial variables in Lisp

I need to store polynomials in my lisp program for addition, subtraction and multiplication. But can not find a simple way to store it.

I examined the following path

(2x ^ 3 + 2x + 4y ^ 3 - 2z) in the list of lists, where each list is a list of the quantities of each capacity

= ((0 2 0 2) (0 0 0 4) (0 2))

But the indefinite length of each list and the potential length can be a problem.

Is there a generally accepted way to store them in lisp that can make it as simple as possible to add, subtract, and multiply them together?

+4
source share
3 answers

, , : (constant x-exponent y-exponent z-exponent ...). 5xy^2 (5 1 2 0), .

, ((constant 5) (a 0) (b 3) (z 23) (apple 13)).

, , .

+1

, . , , - , - . , 5 * x ^ 3 + 10 * x ^ 2 + 40x + 50 #(50 40 10 5). , , x ^ 100.

N- , N - .

+1

. , - .

- , .

12x ^ 2 + 11x + 10 ((2,12) (11,1) (10,0))

, . x ^ 200 ((200. 1)).

, :

12x ^ 2 11x + 10 (vector 10 11 12)

The length of the vector minus one gives the order of the polynomial.

If you need polynomials from more than one variable, then there are presentation options. In particular, you can watch the performance in Maxima:

http://maxima.sourceforge.net/docs/manual/maxima_14.html

If you come up with Peter Norwig's Artificial Intelligence Programming Paradigms: Examples from the Normal LISP, there is a good chapter on polynomials.

0
source

All Articles