Generally speaking, I know how to use mapcar, but this particular situation has me stumped.
Assume that we have two terms, and two lists (each list has two terms)
you know how if you were to multiply a polynomial, you take the first term in the first list, and distribute it across every item in the second list, then goto the second item in the first list and multiply it to everything in the second list etc?
How would you do that in lisp?
I am using a structure that looks like:
(defstruct term coef exp)
the code:
(defun polymul (p q) (labels ( (mlt (t1 t2) (maketerm :coef (* (termcoef t1)(termcoef t2)) :exp (+ (termexp t1)(termexp t2)))) (pml (t3 t4) (if (null t3) nil (cons (mapcar #'mlt (list (car t3)) t4) (pml (cdr t3) t4)))) ) (pml p q) ))
input: (polymul (list (maketerm :coef 1 :exp 3) (maketerm :coef 2 :exp 2))(list (maketerm :coef 1 :exp 4) (maketerm :coef 2 :exp 3)))

output: ((#S(TERM :COEF 1 :EXP 7)) (#S(TERM :COEF 2 :EXP 6)))
the input in more readable terms is: p:(1^3,2^2) q:(1^4, 2^3)
what I expect is something like 1^7, 2^6, 2^6, 4^5 or (1^7, 2^6) (2^6, 4^5)
(I intentionally omitted #S(term :coef :exp) etc)
im not sure why my code doesnt goto the next term in the first list properly, hopefully someone can help
This post has been edited by NecroWinter: 05 February 2013  10:54 PM