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)
(defun poly-mul (p q) (labels ( (mlt (t1 t2) (make-term :coef (* (term-coef t1)(term-coef t2)) :exp (+ (term-exp t1)(term-exp t2)))) (pml (t3 t4) (if (null t3) nil (cons (mapcar #'mlt (list (car t3)) t4) (pml (cdr t3) t4)))) ) (pml p q) ))
input: (poly-mul (list (make-term :coef 1 :exp 3) (make-term :coef 2 :exp 2))(list (make-term :coef 1 :exp 4) (make-term :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