clisp - help with multiplying polynomials in lisp -


For example: (3x 2 - 5x + 2) (7x + 1) and you It's easy to like:

  ((3 2) (- 5 1) (2)) ((7 1) (0)) ((213) (3 2) (- 35 2) (- 5 1) (14 1) (2)) (21 3) (32 2) (9 1) (2)  

And you answer this Get: 21x 3 + 32x 2 + 9x + 2

I need this solution please lisp

< P>

For the first stage, you must add every LHS component with each RHS component; Cartesian products of two sets require a two-level map for this, after which the second-level lists of pairs are added to a top-level list (seems that (# Apply ... ') ).

The second step can be done with reducing the preparation of a union list, which is based on the exponent.

Edit: Let's solve the problem, and you can translate it Explain the way to solve your problem:

Compute (a + b + ... + k) * (l + m + ... + z) In the first couple By expanding and then summarizing products:

  (defun mul-sums (aa bb) (decrease # '+ (applicable #' append '(map' list # '(lambda (A) ( Map 'list #' (Lambda (B) (* AB)) BB)) AA)) compute (1 + 2 + 3) * (3 + 4). & Gt; (original formula '(1 2 3) ) '(3 4)) 42  

Comments