Multiply Two Integer Polynomials












11












$begingroup$


Your task is to take two single-variable integer polynomial expressions and multiply them into their unsimplified first-term-major left-to-right expansion (A.K.A. FOIL in the case of binomials). Do not combine like terms or reorder the result. To be more explicit about the expansion, multiply the first term in the first expression by each term in the second, in order, and continue in the first expression until all terms have been multiplied by all other terms. Expressions will be given in a simplified LaTeX variant.



Each expression will be a sequence of terms separated by + (with exactly one space on each side) Each term will conform to the following regular expression: (PCRE notation)



-?d+x^d+


In plain English, the term is an optional leading - followed by one or more digits followed by x and a nonnegative integer power (with ^)



An example of a full expression:



6x^3 + 1337x^2 + -4x^1 + 2x^0


When plugged into LaTeX, you get $6x^3 + 1337x^2 + -4x^1 + 2x^0$



The output should also conform to this format.



Since brackets do not surround exponents in this format, LaTeX will actually render multi-digit exponents incorrectly. (e.g. 4x^3 + -2x^14 + 54x^28 + -4x^5 renders as $4x^3 + -2x^14 + 54x^28 + -4x^5$) You do not need to account for this and you should not include the brackets in your output.



Example Test Cases



5x^4
3x^23

15x^27




6x^2 + 7x^1 + -2x^0
1x^2 + -2x^3

6x^4 + -12x^5 + 7x^3 + -14x^4 + -2x^2 + 4x^3




3x^1 + 5x^2 + 2x^4 + 3x^0
3x^0

9x^1 + 15x^2 + 6x^4 + 9x^0




4x^3 + -2x^14 + 54x^28 + -4x^5
-0x^7

0x^10 + 0x^21 + 0x^35 + 0x^12




4x^3 + -2x^4 + 0x^255 + -4x^5
-3x^4 + 2x^2

-12x^7 + 8x^5 + 6x^8 + -4x^6 + 0x^259 + 0x^257 + 12x^9 + -8x^7


Rules and Assumptions




  • You may assume that all inputs conform to this exact format. Behavior for any other format is undefined for the purposes of this challenge.


    • It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format.



  • The order of the polynomials matters due to the expected order of the product expansion.

  • You must support input coefficients between $-128$ and $127$ and input exponents up to $255$.


    • Output coefficents between $-16,256$ and $16,384$ and exponents up to $510$ must therefore be supported.



  • You may assume each input polynomial contains no more than 16 terms


    • Therefore you must (at minimum) support up to 256 terms in the output



  • Terms with zero coefficients should be left as is, with exponents being properly combined

  • Negative zero is allowed in the input, but is indistinguishable from positive zero semantically. Always output positive zero. Do not omit zero terms.


Happy Golfing! Good luck!










share|improve this question









$endgroup$












  • $begingroup$
    related
    $endgroup$
    – H.PWiz
    13 hours ago






  • 1




    $begingroup$
    @LuisfelipeDejesusMunoz I imagine not. Parsing is an integral part of the challenge and the OP says -- "It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format." (emphasis added)
    $endgroup$
    – Giuseppe
    12 hours ago










  • $begingroup$
    Your regex is wrong: ^ should be ^.
    $endgroup$
    – Erik the Outgolfer
    12 hours ago
















11












$begingroup$


Your task is to take two single-variable integer polynomial expressions and multiply them into their unsimplified first-term-major left-to-right expansion (A.K.A. FOIL in the case of binomials). Do not combine like terms or reorder the result. To be more explicit about the expansion, multiply the first term in the first expression by each term in the second, in order, and continue in the first expression until all terms have been multiplied by all other terms. Expressions will be given in a simplified LaTeX variant.



Each expression will be a sequence of terms separated by + (with exactly one space on each side) Each term will conform to the following regular expression: (PCRE notation)



-?d+x^d+


In plain English, the term is an optional leading - followed by one or more digits followed by x and a nonnegative integer power (with ^)



An example of a full expression:



6x^3 + 1337x^2 + -4x^1 + 2x^0


When plugged into LaTeX, you get $6x^3 + 1337x^2 + -4x^1 + 2x^0$



The output should also conform to this format.



Since brackets do not surround exponents in this format, LaTeX will actually render multi-digit exponents incorrectly. (e.g. 4x^3 + -2x^14 + 54x^28 + -4x^5 renders as $4x^3 + -2x^14 + 54x^28 + -4x^5$) You do not need to account for this and you should not include the brackets in your output.



Example Test Cases



5x^4
3x^23

15x^27




6x^2 + 7x^1 + -2x^0
1x^2 + -2x^3

6x^4 + -12x^5 + 7x^3 + -14x^4 + -2x^2 + 4x^3




3x^1 + 5x^2 + 2x^4 + 3x^0
3x^0

9x^1 + 15x^2 + 6x^4 + 9x^0




4x^3 + -2x^14 + 54x^28 + -4x^5
-0x^7

0x^10 + 0x^21 + 0x^35 + 0x^12




4x^3 + -2x^4 + 0x^255 + -4x^5
-3x^4 + 2x^2

-12x^7 + 8x^5 + 6x^8 + -4x^6 + 0x^259 + 0x^257 + 12x^9 + -8x^7


Rules and Assumptions




  • You may assume that all inputs conform to this exact format. Behavior for any other format is undefined for the purposes of this challenge.


    • It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format.



  • The order of the polynomials matters due to the expected order of the product expansion.

  • You must support input coefficients between $-128$ and $127$ and input exponents up to $255$.


    • Output coefficents between $-16,256$ and $16,384$ and exponents up to $510$ must therefore be supported.



  • You may assume each input polynomial contains no more than 16 terms


    • Therefore you must (at minimum) support up to 256 terms in the output



  • Terms with zero coefficients should be left as is, with exponents being properly combined

  • Negative zero is allowed in the input, but is indistinguishable from positive zero semantically. Always output positive zero. Do not omit zero terms.


Happy Golfing! Good luck!










share|improve this question









$endgroup$












  • $begingroup$
    related
    $endgroup$
    – H.PWiz
    13 hours ago






  • 1




    $begingroup$
    @LuisfelipeDejesusMunoz I imagine not. Parsing is an integral part of the challenge and the OP says -- "It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format." (emphasis added)
    $endgroup$
    – Giuseppe
    12 hours ago










  • $begingroup$
    Your regex is wrong: ^ should be ^.
    $endgroup$
    – Erik the Outgolfer
    12 hours ago














11












11








11





$begingroup$


Your task is to take two single-variable integer polynomial expressions and multiply them into their unsimplified first-term-major left-to-right expansion (A.K.A. FOIL in the case of binomials). Do not combine like terms or reorder the result. To be more explicit about the expansion, multiply the first term in the first expression by each term in the second, in order, and continue in the first expression until all terms have been multiplied by all other terms. Expressions will be given in a simplified LaTeX variant.



Each expression will be a sequence of terms separated by + (with exactly one space on each side) Each term will conform to the following regular expression: (PCRE notation)



-?d+x^d+


In plain English, the term is an optional leading - followed by one or more digits followed by x and a nonnegative integer power (with ^)



An example of a full expression:



6x^3 + 1337x^2 + -4x^1 + 2x^0


When plugged into LaTeX, you get $6x^3 + 1337x^2 + -4x^1 + 2x^0$



The output should also conform to this format.



Since brackets do not surround exponents in this format, LaTeX will actually render multi-digit exponents incorrectly. (e.g. 4x^3 + -2x^14 + 54x^28 + -4x^5 renders as $4x^3 + -2x^14 + 54x^28 + -4x^5$) You do not need to account for this and you should not include the brackets in your output.



Example Test Cases



5x^4
3x^23

15x^27




6x^2 + 7x^1 + -2x^0
1x^2 + -2x^3

6x^4 + -12x^5 + 7x^3 + -14x^4 + -2x^2 + 4x^3




3x^1 + 5x^2 + 2x^4 + 3x^0
3x^0

9x^1 + 15x^2 + 6x^4 + 9x^0




4x^3 + -2x^14 + 54x^28 + -4x^5
-0x^7

0x^10 + 0x^21 + 0x^35 + 0x^12




4x^3 + -2x^4 + 0x^255 + -4x^5
-3x^4 + 2x^2

-12x^7 + 8x^5 + 6x^8 + -4x^6 + 0x^259 + 0x^257 + 12x^9 + -8x^7


Rules and Assumptions




  • You may assume that all inputs conform to this exact format. Behavior for any other format is undefined for the purposes of this challenge.


    • It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format.



  • The order of the polynomials matters due to the expected order of the product expansion.

  • You must support input coefficients between $-128$ and $127$ and input exponents up to $255$.


    • Output coefficents between $-16,256$ and $16,384$ and exponents up to $510$ must therefore be supported.



  • You may assume each input polynomial contains no more than 16 terms


    • Therefore you must (at minimum) support up to 256 terms in the output



  • Terms with zero coefficients should be left as is, with exponents being properly combined

  • Negative zero is allowed in the input, but is indistinguishable from positive zero semantically. Always output positive zero. Do not omit zero terms.


Happy Golfing! Good luck!










share|improve this question









$endgroup$




Your task is to take two single-variable integer polynomial expressions and multiply them into their unsimplified first-term-major left-to-right expansion (A.K.A. FOIL in the case of binomials). Do not combine like terms or reorder the result. To be more explicit about the expansion, multiply the first term in the first expression by each term in the second, in order, and continue in the first expression until all terms have been multiplied by all other terms. Expressions will be given in a simplified LaTeX variant.



Each expression will be a sequence of terms separated by + (with exactly one space on each side) Each term will conform to the following regular expression: (PCRE notation)



-?d+x^d+


In plain English, the term is an optional leading - followed by one or more digits followed by x and a nonnegative integer power (with ^)



An example of a full expression:



6x^3 + 1337x^2 + -4x^1 + 2x^0


When plugged into LaTeX, you get $6x^3 + 1337x^2 + -4x^1 + 2x^0$



The output should also conform to this format.



Since brackets do not surround exponents in this format, LaTeX will actually render multi-digit exponents incorrectly. (e.g. 4x^3 + -2x^14 + 54x^28 + -4x^5 renders as $4x^3 + -2x^14 + 54x^28 + -4x^5$) You do not need to account for this and you should not include the brackets in your output.



Example Test Cases



5x^4
3x^23

15x^27




6x^2 + 7x^1 + -2x^0
1x^2 + -2x^3

6x^4 + -12x^5 + 7x^3 + -14x^4 + -2x^2 + 4x^3




3x^1 + 5x^2 + 2x^4 + 3x^0
3x^0

9x^1 + 15x^2 + 6x^4 + 9x^0




4x^3 + -2x^14 + 54x^28 + -4x^5
-0x^7

0x^10 + 0x^21 + 0x^35 + 0x^12




4x^3 + -2x^4 + 0x^255 + -4x^5
-3x^4 + 2x^2

-12x^7 + 8x^5 + 6x^8 + -4x^6 + 0x^259 + 0x^257 + 12x^9 + -8x^7


Rules and Assumptions




  • You may assume that all inputs conform to this exact format. Behavior for any other format is undefined for the purposes of this challenge.


    • It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format.



  • The order of the polynomials matters due to the expected order of the product expansion.

  • You must support input coefficients between $-128$ and $127$ and input exponents up to $255$.


    • Output coefficents between $-16,256$ and $16,384$ and exponents up to $510$ must therefore be supported.



  • You may assume each input polynomial contains no more than 16 terms


    • Therefore you must (at minimum) support up to 256 terms in the output



  • Terms with zero coefficients should be left as is, with exponents being properly combined

  • Negative zero is allowed in the input, but is indistinguishable from positive zero semantically. Always output positive zero. Do not omit zero terms.


Happy Golfing! Good luck!







code-golf math parsing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 13 hours ago









BeefsterBeefster

2,6351244




2,6351244












  • $begingroup$
    related
    $endgroup$
    – H.PWiz
    13 hours ago






  • 1




    $begingroup$
    @LuisfelipeDejesusMunoz I imagine not. Parsing is an integral part of the challenge and the OP says -- "It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format." (emphasis added)
    $endgroup$
    – Giuseppe
    12 hours ago










  • $begingroup$
    Your regex is wrong: ^ should be ^.
    $endgroup$
    – Erik the Outgolfer
    12 hours ago


















  • $begingroup$
    related
    $endgroup$
    – H.PWiz
    13 hours ago






  • 1




    $begingroup$
    @LuisfelipeDejesusMunoz I imagine not. Parsing is an integral part of the challenge and the OP says -- "It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format." (emphasis added)
    $endgroup$
    – Giuseppe
    12 hours ago










  • $begingroup$
    Your regex is wrong: ^ should be ^.
    $endgroup$
    – Erik the Outgolfer
    12 hours ago
















$begingroup$
related
$endgroup$
– H.PWiz
13 hours ago




$begingroup$
related
$endgroup$
– H.PWiz
13 hours ago




1




1




$begingroup$
@LuisfelipeDejesusMunoz I imagine not. Parsing is an integral part of the challenge and the OP says -- "It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format." (emphasis added)
$endgroup$
– Giuseppe
12 hours ago




$begingroup$
@LuisfelipeDejesusMunoz I imagine not. Parsing is an integral part of the challenge and the OP says -- "It should be noted that any method of taking in the two polynomials is valid, provided that both are read in as strings conforming to the above format." (emphasis added)
$endgroup$
– Giuseppe
12 hours ago












$begingroup$
Your regex is wrong: ^ should be ^.
$endgroup$
– Erik the Outgolfer
12 hours ago




$begingroup$
Your regex is wrong: ^ should be ^.
$endgroup$
– Erik the Outgolfer
12 hours ago










14 Answers
14






active

oldest

votes


















4












$begingroup$


R, 159 153 bytes





function(P,Q,a=h(P),b=h(Q))paste0(b[1,]%o%a[1,],"x^",outer(b[2,],a[2,],"+"),collapse=" + ")
h=function(s,`/`=strsplit)sapply(el(s/" \+ ")/"x\^",strtoi)


Try it online!



I really wanted to use outer, so there's almost surely a more efficient approach.






share|improve this answer











$endgroup$





















    1












    $begingroup$

    Pyth - 39 bytes



    LmsMcdK"x^"%2cb)j" + "m++*FhdKsedCM*FyM


    Try it online.






    share|improve this answer









    $endgroup$





















      1












      $begingroup$

      Haskell, 124 bytes



      import Data.Lists
      s=splitOn
      z=map(map read.s"x^").s"+"
      a#b=intercalate" + "[shows(u*p)"x^"++show(v+q)|[u,v]<-z a,[p,q]<-z b]


      Note: TIO lacks Data.Lists, so I import Data.Lists.Split and Data.List: Try it online!






      share|improve this answer









      $endgroup$





















        1












        $begingroup$


        Ruby, 102 bytes





        ->a,b{a.scan(w=/(-?d+)x.(d+)/).product(b.scan w).map{|x,y|(eval"[%s*(z=%s;%s),z+%s]"%x+=y)*"x^"}*?+}


        Try it online!






        share|improve this answer











        $endgroup$





















          1












          $begingroup$

          JavaScript, 112 bytes



          I found three alternatives with the same length. Call with currying syntax.



          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `





          f=
          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `

          console.log( f('5x^4')('3x^23') )
          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `





          f=
          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `

          console.log( f('5x^4')('3x^23') )
          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `





          f=
          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `

          console.log( f('5x^4')('3x^23') )
          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )








          share|improve this answer











          $endgroup$













          • $begingroup$
            split' + ' => split'+' to save 2 bytes
            $endgroup$
            – Luis felipe De jesus Munoz
            10 hours ago












          • $begingroup$
            @Arnauld Seems fine without them
            $endgroup$
            – Embodiment of Ignorance
            8 hours ago










          • $begingroup$
            @EmbodimentofIgnorance My bad, I misread Luis' comment. I thought it was about the join.
            $endgroup$
            – Arnauld
            8 hours ago



















          1












          $begingroup$


          Jelly, 28 bytes



          ṣ”+ṣ”xV$€)p/ZPSƭ€j⁾x^Ʋ€j“ + 


          Try it online!



          Full program. Takes the two polynomials as a list of two strings.






          share|improve this answer









          $endgroup$





















            1












            $begingroup$


            C# (Visual C# Interactive Compiler), 192 190 188 bytes





            n=>m=>string.Join(g="+",from a in n.Split(g)from b in m.Split(g)select f(a.Split(p="x^")[0])*f(b.Split(p)[0])+p+(f(a.Split(p)[1])+f(b.Split(p)[1])));Func<string,int>f=int.Parse;string p,g;


            Query syntax seems to be a byte shorter than method syntax.



            At least I beat SNOBOL.



            Try it online!






            share|improve this answer











            $endgroup$





















              1












              $begingroup$


              SNOBOL4 (CSNOBOL4), 192 176 bytes



              	P =INPUT
              Q =INPUT
              D =SPAN(-1234567890)
              P P D . K ARB D . W REM . P :F(O)
              B =Q
              B B D . C ARB D . E REM . B :F(P)
              O =O ' + ' K * C 'x^' W + E :(B)
              O O ' + ' REM . OUTPUT
              END


              Try it online!



              	P =INPUT				;* read P
              Q =INPUT ;* read Q
              D =SPAN(-1234567890) ;* save PATTERN for Digits (or a - sign); equivalent to [0-9\-]+
              P P D . K ARB D . W REM . P :F(O) ;* save the Koefficient and the poWer, saving the REMainder as P, or if no match, goto O
              B =Q ;* set B = Q
              B B D . C ARB D . E REM . B :F(P) ;* save the Coefficient and the powEr, saving the REMainder as B, or if no match, goto P
              O =O ' + ' K * C 'x^' W + E :(B) ;* accumulate the output
              O O ' + ' REM . OUTPUT ;* match ' + ' and OUTPUT the REMainder
              END





              share|improve this answer











              $endgroup$





















                1












                $begingroup$


                Python 2, 130 bytes





                lambda a,b:' + '.join([`v*V`+'x^'+`k+K`for V,K in g(a)for v,k in g(b)])
                g=lambda s:[map(int,t.split('x^'))for t in s.split(' + ')]


                Try it online!






                share|improve this answer









                $endgroup$





















                  0












                  $begingroup$


                  JavaScript (Babel Node), 118 bytes



                  Takes input as (a)(b).





                  a=>b=>(g=s=>[...s.matchAll(/(-?d+)x.(d+)/g)])(a).flatMap(([_,x,p])=>g(b).map(([_,X,P])=>x*X+'x^'+-(-p-P))).join` + `


                  Try it online!






                  share|improve this answer









                  $endgroup$





















                    0












                    $begingroup$


                    Haskell, 133 bytes





                    f""=
                    f t|[(a,_:_:u)]<-reads t,[(i,v)]<-reads u=(a,i):f(drop 3v)
                    p!q=drop 3$do(a,i)<-f p;(b,j)<-f q;" + "++shows(a*b)"x^"++show(i+j)


                    Try it online!



                    f parses a polynomial from a string, ! multiplies two of them and formats the result.






                    share|improve this answer









                    $endgroup$





















                      0












                      $begingroup$


                      Python 2, 193 bytes





                      import re
                      f=re.finditer
                      lambda a,b:' + '.join(' + '.join(`int(m.group(1))*int(n.group(1))`+'x^'+`int(m.group(2))+int(n.group(2))`for n in f('(-?d+)x^(d+)',b))for m in f('(-?d+)x^(d+)',a))


                      Try it online!



                      Side note: First time doing a code golf challenge, so sorry if the attempt sucks haha






                      share|improve this answer








                      New contributor




                      GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.






                      $endgroup$









                      • 2




                        $begingroup$
                        Welcome to PPCG! I'm not much of a python programmer, but if your submission is longer than a SNOBOL one, there's probably room for improvement, heheh. Perhaps you can find help at Tips for Golfing in Python or Tips for Golfing in <all languages>! Hope you enjoy the time you spend here :-)
                        $endgroup$
                        – Giuseppe
                        10 hours ago





















                      0












                      $begingroup$


                      Retina, 110 bytes



                      SS+(?=.*n(.+))
                      $1#$&
                      |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                      $1$4$.($2*$5*)x^$.($3*_$6*
                      --|-(0)
                      $1


                      Try it online! Explanation:



                      SS+(?=.*n(.+))
                      $1#$&


                      Prefix each term in the first input with a #, a copy of the second input, and a space. This means that all of the terms in copies of the second input are preceded by a space and none of the terms from the first input are.



                      |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                      $1$4$.($2*$5*)x^$.($3*_$6*


                      Match all of the copies of terms in the second input and their corresponding term from the first input. Concatenate any - signs, multiply the coefficients, and add the indices. Finally join all of the resulting substitutions with the string  + .



                      --|-(0)
                      $1


                      Delete any pairs of -s and convert -0 to 0.






                      share|improve this answer









                      $endgroup$





















                        0












                        $begingroup$


                        Perl 6, 114 bytes





                        {my&g=*.match(/(-?d+)x^(d+)/,:g)».caps».Map;join " + ",map {"{[*] $_»{0}}x^{[+] $_»{1}}"},(g($^a)X g $^b)}


                        Try it online!






                        share|improve this answer









                        $endgroup$














                          Your Answer





                          StackExchange.ifUsing("editor", function () {
                          return StackExchange.using("mathjaxEditing", function () {
                          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                          });
                          });
                          }, "mathjax-editing");

                          StackExchange.ifUsing("editor", function () {
                          StackExchange.using("externalEditor", function () {
                          StackExchange.using("snippets", function () {
                          StackExchange.snippets.init();
                          });
                          });
                          }, "code-snippets");

                          StackExchange.ready(function() {
                          var channelOptions = {
                          tags: "".split(" "),
                          id: "200"
                          };
                          initTagRenderer("".split(" "), "".split(" "), channelOptions);

                          StackExchange.using("externalEditor", function() {
                          // Have to fire editor after snippets, if snippets enabled
                          if (StackExchange.settings.snippets.snippetsEnabled) {
                          StackExchange.using("snippets", function() {
                          createEditor();
                          });
                          }
                          else {
                          createEditor();
                          }
                          });

                          function createEditor() {
                          StackExchange.prepareEditor({
                          heartbeatType: 'answer',
                          autoActivateHeartbeat: false,
                          convertImagesToLinks: false,
                          noModals: true,
                          showLowRepImageUploadWarning: true,
                          reputationToPostImages: null,
                          bindNavPrevention: true,
                          postfix: "",
                          imageUploader: {
                          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                          allowUrls: true
                          },
                          onDemand: true,
                          discardSelector: ".discard-answer"
                          ,immediatelyShowMarkdownHelp:true
                          });


                          }
                          });














                          draft saved

                          draft discarded


















                          StackExchange.ready(
                          function () {
                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182972%2fmultiply-two-integer-polynomials%23new-answer', 'question_page');
                          }
                          );

                          Post as a guest















                          Required, but never shown

























                          14 Answers
                          14






                          active

                          oldest

                          votes








                          14 Answers
                          14






                          active

                          oldest

                          votes









                          active

                          oldest

                          votes






                          active

                          oldest

                          votes









                          4












                          $begingroup$


                          R, 159 153 bytes





                          function(P,Q,a=h(P),b=h(Q))paste0(b[1,]%o%a[1,],"x^",outer(b[2,],a[2,],"+"),collapse=" + ")
                          h=function(s,`/`=strsplit)sapply(el(s/" \+ ")/"x\^",strtoi)


                          Try it online!



                          I really wanted to use outer, so there's almost surely a more efficient approach.






                          share|improve this answer











                          $endgroup$


















                            4












                            $begingroup$


                            R, 159 153 bytes





                            function(P,Q,a=h(P),b=h(Q))paste0(b[1,]%o%a[1,],"x^",outer(b[2,],a[2,],"+"),collapse=" + ")
                            h=function(s,`/`=strsplit)sapply(el(s/" \+ ")/"x\^",strtoi)


                            Try it online!



                            I really wanted to use outer, so there's almost surely a more efficient approach.






                            share|improve this answer











                            $endgroup$
















                              4












                              4








                              4





                              $begingroup$


                              R, 159 153 bytes





                              function(P,Q,a=h(P),b=h(Q))paste0(b[1,]%o%a[1,],"x^",outer(b[2,],a[2,],"+"),collapse=" + ")
                              h=function(s,`/`=strsplit)sapply(el(s/" \+ ")/"x\^",strtoi)


                              Try it online!



                              I really wanted to use outer, so there's almost surely a more efficient approach.






                              share|improve this answer











                              $endgroup$




                              R, 159 153 bytes





                              function(P,Q,a=h(P),b=h(Q))paste0(b[1,]%o%a[1,],"x^",outer(b[2,],a[2,],"+"),collapse=" + ")
                              h=function(s,`/`=strsplit)sapply(el(s/" \+ ")/"x\^",strtoi)


                              Try it online!



                              I really wanted to use outer, so there's almost surely a more efficient approach.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 12 hours ago

























                              answered 12 hours ago









                              GiuseppeGiuseppe

                              17.7k31153




                              17.7k31153























                                  1












                                  $begingroup$

                                  Pyth - 39 bytes



                                  LmsMcdK"x^"%2cb)j" + "m++*FhdKsedCM*FyM


                                  Try it online.






                                  share|improve this answer









                                  $endgroup$


















                                    1












                                    $begingroup$

                                    Pyth - 39 bytes



                                    LmsMcdK"x^"%2cb)j" + "m++*FhdKsedCM*FyM


                                    Try it online.






                                    share|improve this answer









                                    $endgroup$
















                                      1












                                      1








                                      1





                                      $begingroup$

                                      Pyth - 39 bytes



                                      LmsMcdK"x^"%2cb)j" + "m++*FhdKsedCM*FyM


                                      Try it online.






                                      share|improve this answer









                                      $endgroup$



                                      Pyth - 39 bytes



                                      LmsMcdK"x^"%2cb)j" + "m++*FhdKsedCM*FyM


                                      Try it online.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 13 hours ago









                                      MaltysenMaltysen

                                      21.3k445116




                                      21.3k445116























                                          1












                                          $begingroup$

                                          Haskell, 124 bytes



                                          import Data.Lists
                                          s=splitOn
                                          z=map(map read.s"x^").s"+"
                                          a#b=intercalate" + "[shows(u*p)"x^"++show(v+q)|[u,v]<-z a,[p,q]<-z b]


                                          Note: TIO lacks Data.Lists, so I import Data.Lists.Split and Data.List: Try it online!






                                          share|improve this answer









                                          $endgroup$


















                                            1












                                            $begingroup$

                                            Haskell, 124 bytes



                                            import Data.Lists
                                            s=splitOn
                                            z=map(map read.s"x^").s"+"
                                            a#b=intercalate" + "[shows(u*p)"x^"++show(v+q)|[u,v]<-z a,[p,q]<-z b]


                                            Note: TIO lacks Data.Lists, so I import Data.Lists.Split and Data.List: Try it online!






                                            share|improve this answer









                                            $endgroup$
















                                              1












                                              1








                                              1





                                              $begingroup$

                                              Haskell, 124 bytes



                                              import Data.Lists
                                              s=splitOn
                                              z=map(map read.s"x^").s"+"
                                              a#b=intercalate" + "[shows(u*p)"x^"++show(v+q)|[u,v]<-z a,[p,q]<-z b]


                                              Note: TIO lacks Data.Lists, so I import Data.Lists.Split and Data.List: Try it online!






                                              share|improve this answer









                                              $endgroup$



                                              Haskell, 124 bytes



                                              import Data.Lists
                                              s=splitOn
                                              z=map(map read.s"x^").s"+"
                                              a#b=intercalate" + "[shows(u*p)"x^"++show(v+q)|[u,v]<-z a,[p,q]<-z b]


                                              Note: TIO lacks Data.Lists, so I import Data.Lists.Split and Data.List: Try it online!







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 13 hours ago









                                              niminimi

                                              32.7k32489




                                              32.7k32489























                                                  1












                                                  $begingroup$


                                                  Ruby, 102 bytes





                                                  ->a,b{a.scan(w=/(-?d+)x.(d+)/).product(b.scan w).map{|x,y|(eval"[%s*(z=%s;%s),z+%s]"%x+=y)*"x^"}*?+}


                                                  Try it online!






                                                  share|improve this answer











                                                  $endgroup$


















                                                    1












                                                    $begingroup$


                                                    Ruby, 102 bytes





                                                    ->a,b{a.scan(w=/(-?d+)x.(d+)/).product(b.scan w).map{|x,y|(eval"[%s*(z=%s;%s),z+%s]"%x+=y)*"x^"}*?+}


                                                    Try it online!






                                                    share|improve this answer











                                                    $endgroup$
















                                                      1












                                                      1








                                                      1





                                                      $begingroup$


                                                      Ruby, 102 bytes





                                                      ->a,b{a.scan(w=/(-?d+)x.(d+)/).product(b.scan w).map{|x,y|(eval"[%s*(z=%s;%s),z+%s]"%x+=y)*"x^"}*?+}


                                                      Try it online!






                                                      share|improve this answer











                                                      $endgroup$




                                                      Ruby, 102 bytes





                                                      ->a,b{a.scan(w=/(-?d+)x.(d+)/).product(b.scan w).map{|x,y|(eval"[%s*(z=%s;%s),z+%s]"%x+=y)*"x^"}*?+}


                                                      Try it online!







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited 12 hours ago

























                                                      answered 13 hours ago









                                                      G BG B

                                                      8,2661429




                                                      8,2661429























                                                          1












                                                          $begingroup$

                                                          JavaScript, 112 bytes



                                                          I found three alternatives with the same length. Call with currying syntax.



                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )








                                                          share|improve this answer











                                                          $endgroup$













                                                          • $begingroup$
                                                            split' + ' => split'+' to save 2 bytes
                                                            $endgroup$
                                                            – Luis felipe De jesus Munoz
                                                            10 hours ago












                                                          • $begingroup$
                                                            @Arnauld Seems fine without them
                                                            $endgroup$
                                                            – Embodiment of Ignorance
                                                            8 hours ago










                                                          • $begingroup$
                                                            @EmbodimentofIgnorance My bad, I misread Luis' comment. I thought it was about the join.
                                                            $endgroup$
                                                            – Arnauld
                                                            8 hours ago
















                                                          1












                                                          $begingroup$

                                                          JavaScript, 112 bytes



                                                          I found three alternatives with the same length. Call with currying syntax.



                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )








                                                          share|improve this answer











                                                          $endgroup$













                                                          • $begingroup$
                                                            split' + ' => split'+' to save 2 bytes
                                                            $endgroup$
                                                            – Luis felipe De jesus Munoz
                                                            10 hours ago












                                                          • $begingroup$
                                                            @Arnauld Seems fine without them
                                                            $endgroup$
                                                            – Embodiment of Ignorance
                                                            8 hours ago










                                                          • $begingroup$
                                                            @EmbodimentofIgnorance My bad, I misread Luis' comment. I thought it was about the join.
                                                            $endgroup$
                                                            – Arnauld
                                                            8 hours ago














                                                          1












                                                          1








                                                          1





                                                          $begingroup$

                                                          JavaScript, 112 bytes



                                                          I found three alternatives with the same length. Call with currying syntax.



                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )








                                                          share|improve this answer











                                                          $endgroup$



                                                          JavaScript, 112 bytes



                                                          I found three alternatives with the same length. Call with currying syntax.



                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )







                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `





                                                          f=
                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )








                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(a=>P(B).map(b=>a[0]*b[0]+'x^'+(a[1]- -b[1]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )





                                                          f=
                                                          A=>B=>(P=x=>x.split` + `.map(x=>x.split`x^`))(A).flatMap(([c,e])=>P(B).map(([C,E])=>c*C+'x^'+(e- -E))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )





                                                          f=
                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )





                                                          f=
                                                          A=>B=>(P=x=>[...x.matchAll(/(S+)x.(S+)/g)])(A).flatMap(a=>P(B).map(b=>a[1]*b[1]+'x^'+(a[2]- -b[2]))).join` + `

                                                          console.log( f('5x^4')('3x^23') )
                                                          console.log( f('6x^2 + 7x^1 + -2x^0')('1x^2 + -2x^3') )
                                                          console.log( f('3x^1 + 5x^2 + 2x^4 + 3x^0')('3x^0') )
                                                          console.log( f('4x^3 + -2x^14 + 54x^28 + -4x^5')('-0x^7') )
                                                          console.log( f('4x^3 + -2x^4 + 0x^255 + -4x^5')('-3x^4 + 2x^2') )






                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited 11 hours ago

























                                                          answered 11 hours ago









                                                          darrylyeodarrylyeo

                                                          5,2641034




                                                          5,2641034












                                                          • $begingroup$
                                                            split' + ' => split'+' to save 2 bytes
                                                            $endgroup$
                                                            – Luis felipe De jesus Munoz
                                                            10 hours ago












                                                          • $begingroup$
                                                            @Arnauld Seems fine without them
                                                            $endgroup$
                                                            – Embodiment of Ignorance
                                                            8 hours ago










                                                          • $begingroup$
                                                            @EmbodimentofIgnorance My bad, I misread Luis' comment. I thought it was about the join.
                                                            $endgroup$
                                                            – Arnauld
                                                            8 hours ago


















                                                          • $begingroup$
                                                            split' + ' => split'+' to save 2 bytes
                                                            $endgroup$
                                                            – Luis felipe De jesus Munoz
                                                            10 hours ago












                                                          • $begingroup$
                                                            @Arnauld Seems fine without them
                                                            $endgroup$
                                                            – Embodiment of Ignorance
                                                            8 hours ago










                                                          • $begingroup$
                                                            @EmbodimentofIgnorance My bad, I misread Luis' comment. I thought it was about the join.
                                                            $endgroup$
                                                            – Arnauld
                                                            8 hours ago
















                                                          $begingroup$
                                                          split' + ' => split'+' to save 2 bytes
                                                          $endgroup$
                                                          – Luis felipe De jesus Munoz
                                                          10 hours ago






                                                          $begingroup$
                                                          split' + ' => split'+' to save 2 bytes
                                                          $endgroup$
                                                          – Luis felipe De jesus Munoz
                                                          10 hours ago














                                                          $begingroup$
                                                          @Arnauld Seems fine without them
                                                          $endgroup$
                                                          – Embodiment of Ignorance
                                                          8 hours ago




                                                          $begingroup$
                                                          @Arnauld Seems fine without them
                                                          $endgroup$
                                                          – Embodiment of Ignorance
                                                          8 hours ago












                                                          $begingroup$
                                                          @EmbodimentofIgnorance My bad, I misread Luis' comment. I thought it was about the join.
                                                          $endgroup$
                                                          – Arnauld
                                                          8 hours ago




                                                          $begingroup$
                                                          @EmbodimentofIgnorance My bad, I misread Luis' comment. I thought it was about the join.
                                                          $endgroup$
                                                          – Arnauld
                                                          8 hours ago











                                                          1












                                                          $begingroup$


                                                          Jelly, 28 bytes



                                                          ṣ”+ṣ”xV$€)p/ZPSƭ€j⁾x^Ʋ€j“ + 


                                                          Try it online!



                                                          Full program. Takes the two polynomials as a list of two strings.






                                                          share|improve this answer









                                                          $endgroup$


















                                                            1












                                                            $begingroup$


                                                            Jelly, 28 bytes



                                                            ṣ”+ṣ”xV$€)p/ZPSƭ€j⁾x^Ʋ€j“ + 


                                                            Try it online!



                                                            Full program. Takes the two polynomials as a list of two strings.






                                                            share|improve this answer









                                                            $endgroup$
















                                                              1












                                                              1








                                                              1





                                                              $begingroup$


                                                              Jelly, 28 bytes



                                                              ṣ”+ṣ”xV$€)p/ZPSƭ€j⁾x^Ʋ€j“ + 


                                                              Try it online!



                                                              Full program. Takes the two polynomials as a list of two strings.






                                                              share|improve this answer









                                                              $endgroup$




                                                              Jelly, 28 bytes



                                                              ṣ”+ṣ”xV$€)p/ZPSƭ€j⁾x^Ʋ€j“ + 


                                                              Try it online!



                                                              Full program. Takes the two polynomials as a list of two strings.







                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered 8 hours ago









                                                              Erik the OutgolferErik the Outgolfer

                                                              33k429106




                                                              33k429106























                                                                  1












                                                                  $begingroup$


                                                                  C# (Visual C# Interactive Compiler), 192 190 188 bytes





                                                                  n=>m=>string.Join(g="+",from a in n.Split(g)from b in m.Split(g)select f(a.Split(p="x^")[0])*f(b.Split(p)[0])+p+(f(a.Split(p)[1])+f(b.Split(p)[1])));Func<string,int>f=int.Parse;string p,g;


                                                                  Query syntax seems to be a byte shorter than method syntax.



                                                                  At least I beat SNOBOL.



                                                                  Try it online!






                                                                  share|improve this answer











                                                                  $endgroup$


















                                                                    1












                                                                    $begingroup$


                                                                    C# (Visual C# Interactive Compiler), 192 190 188 bytes





                                                                    n=>m=>string.Join(g="+",from a in n.Split(g)from b in m.Split(g)select f(a.Split(p="x^")[0])*f(b.Split(p)[0])+p+(f(a.Split(p)[1])+f(b.Split(p)[1])));Func<string,int>f=int.Parse;string p,g;


                                                                    Query syntax seems to be a byte shorter than method syntax.



                                                                    At least I beat SNOBOL.



                                                                    Try it online!






                                                                    share|improve this answer











                                                                    $endgroup$
















                                                                      1












                                                                      1








                                                                      1





                                                                      $begingroup$


                                                                      C# (Visual C# Interactive Compiler), 192 190 188 bytes





                                                                      n=>m=>string.Join(g="+",from a in n.Split(g)from b in m.Split(g)select f(a.Split(p="x^")[0])*f(b.Split(p)[0])+p+(f(a.Split(p)[1])+f(b.Split(p)[1])));Func<string,int>f=int.Parse;string p,g;


                                                                      Query syntax seems to be a byte shorter than method syntax.



                                                                      At least I beat SNOBOL.



                                                                      Try it online!






                                                                      share|improve this answer











                                                                      $endgroup$




                                                                      C# (Visual C# Interactive Compiler), 192 190 188 bytes





                                                                      n=>m=>string.Join(g="+",from a in n.Split(g)from b in m.Split(g)select f(a.Split(p="x^")[0])*f(b.Split(p)[0])+p+(f(a.Split(p)[1])+f(b.Split(p)[1])));Func<string,int>f=int.Parse;string p,g;


                                                                      Query syntax seems to be a byte shorter than method syntax.



                                                                      At least I beat SNOBOL.



                                                                      Try it online!







                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited 5 hours ago

























                                                                      answered 8 hours ago









                                                                      Embodiment of IgnoranceEmbodiment of Ignorance

                                                                      2,926127




                                                                      2,926127























                                                                          1












                                                                          $begingroup$


                                                                          SNOBOL4 (CSNOBOL4), 192 176 bytes



                                                                          	P =INPUT
                                                                          Q =INPUT
                                                                          D =SPAN(-1234567890)
                                                                          P P D . K ARB D . W REM . P :F(O)
                                                                          B =Q
                                                                          B B D . C ARB D . E REM . B :F(P)
                                                                          O =O ' + ' K * C 'x^' W + E :(B)
                                                                          O O ' + ' REM . OUTPUT
                                                                          END


                                                                          Try it online!



                                                                          	P =INPUT				;* read P
                                                                          Q =INPUT ;* read Q
                                                                          D =SPAN(-1234567890) ;* save PATTERN for Digits (or a - sign); equivalent to [0-9\-]+
                                                                          P P D . K ARB D . W REM . P :F(O) ;* save the Koefficient and the poWer, saving the REMainder as P, or if no match, goto O
                                                                          B =Q ;* set B = Q
                                                                          B B D . C ARB D . E REM . B :F(P) ;* save the Coefficient and the powEr, saving the REMainder as B, or if no match, goto P
                                                                          O =O ' + ' K * C 'x^' W + E :(B) ;* accumulate the output
                                                                          O O ' + ' REM . OUTPUT ;* match ' + ' and OUTPUT the REMainder
                                                                          END





                                                                          share|improve this answer











                                                                          $endgroup$


















                                                                            1












                                                                            $begingroup$


                                                                            SNOBOL4 (CSNOBOL4), 192 176 bytes



                                                                            	P =INPUT
                                                                            Q =INPUT
                                                                            D =SPAN(-1234567890)
                                                                            P P D . K ARB D . W REM . P :F(O)
                                                                            B =Q
                                                                            B B D . C ARB D . E REM . B :F(P)
                                                                            O =O ' + ' K * C 'x^' W + E :(B)
                                                                            O O ' + ' REM . OUTPUT
                                                                            END


                                                                            Try it online!



                                                                            	P =INPUT				;* read P
                                                                            Q =INPUT ;* read Q
                                                                            D =SPAN(-1234567890) ;* save PATTERN for Digits (or a - sign); equivalent to [0-9\-]+
                                                                            P P D . K ARB D . W REM . P :F(O) ;* save the Koefficient and the poWer, saving the REMainder as P, or if no match, goto O
                                                                            B =Q ;* set B = Q
                                                                            B B D . C ARB D . E REM . B :F(P) ;* save the Coefficient and the powEr, saving the REMainder as B, or if no match, goto P
                                                                            O =O ' + ' K * C 'x^' W + E :(B) ;* accumulate the output
                                                                            O O ' + ' REM . OUTPUT ;* match ' + ' and OUTPUT the REMainder
                                                                            END





                                                                            share|improve this answer











                                                                            $endgroup$
















                                                                              1












                                                                              1








                                                                              1





                                                                              $begingroup$


                                                                              SNOBOL4 (CSNOBOL4), 192 176 bytes



                                                                              	P =INPUT
                                                                              Q =INPUT
                                                                              D =SPAN(-1234567890)
                                                                              P P D . K ARB D . W REM . P :F(O)
                                                                              B =Q
                                                                              B B D . C ARB D . E REM . B :F(P)
                                                                              O =O ' + ' K * C 'x^' W + E :(B)
                                                                              O O ' + ' REM . OUTPUT
                                                                              END


                                                                              Try it online!



                                                                              	P =INPUT				;* read P
                                                                              Q =INPUT ;* read Q
                                                                              D =SPAN(-1234567890) ;* save PATTERN for Digits (or a - sign); equivalent to [0-9\-]+
                                                                              P P D . K ARB D . W REM . P :F(O) ;* save the Koefficient and the poWer, saving the REMainder as P, or if no match, goto O
                                                                              B =Q ;* set B = Q
                                                                              B B D . C ARB D . E REM . B :F(P) ;* save the Coefficient and the powEr, saving the REMainder as B, or if no match, goto P
                                                                              O =O ' + ' K * C 'x^' W + E :(B) ;* accumulate the output
                                                                              O O ' + ' REM . OUTPUT ;* match ' + ' and OUTPUT the REMainder
                                                                              END





                                                                              share|improve this answer











                                                                              $endgroup$




                                                                              SNOBOL4 (CSNOBOL4), 192 176 bytes



                                                                              	P =INPUT
                                                                              Q =INPUT
                                                                              D =SPAN(-1234567890)
                                                                              P P D . K ARB D . W REM . P :F(O)
                                                                              B =Q
                                                                              B B D . C ARB D . E REM . B :F(P)
                                                                              O =O ' + ' K * C 'x^' W + E :(B)
                                                                              O O ' + ' REM . OUTPUT
                                                                              END


                                                                              Try it online!



                                                                              	P =INPUT				;* read P
                                                                              Q =INPUT ;* read Q
                                                                              D =SPAN(-1234567890) ;* save PATTERN for Digits (or a - sign); equivalent to [0-9\-]+
                                                                              P P D . K ARB D . W REM . P :F(O) ;* save the Koefficient and the poWer, saving the REMainder as P, or if no match, goto O
                                                                              B =Q ;* set B = Q
                                                                              B B D . C ARB D . E REM . B :F(P) ;* save the Coefficient and the powEr, saving the REMainder as B, or if no match, goto P
                                                                              O =O ' + ' K * C 'x^' W + E :(B) ;* accumulate the output
                                                                              O O ' + ' REM . OUTPUT ;* match ' + ' and OUTPUT the REMainder
                                                                              END






                                                                              share|improve this answer














                                                                              share|improve this answer



                                                                              share|improve this answer








                                                                              edited 5 hours ago

























                                                                              answered 12 hours ago









                                                                              GiuseppeGiuseppe

                                                                              17.7k31153




                                                                              17.7k31153























                                                                                  1












                                                                                  $begingroup$


                                                                                  Python 2, 130 bytes





                                                                                  lambda a,b:' + '.join([`v*V`+'x^'+`k+K`for V,K in g(a)for v,k in g(b)])
                                                                                  g=lambda s:[map(int,t.split('x^'))for t in s.split(' + ')]


                                                                                  Try it online!






                                                                                  share|improve this answer









                                                                                  $endgroup$


















                                                                                    1












                                                                                    $begingroup$


                                                                                    Python 2, 130 bytes





                                                                                    lambda a,b:' + '.join([`v*V`+'x^'+`k+K`for V,K in g(a)for v,k in g(b)])
                                                                                    g=lambda s:[map(int,t.split('x^'))for t in s.split(' + ')]


                                                                                    Try it online!






                                                                                    share|improve this answer









                                                                                    $endgroup$
















                                                                                      1












                                                                                      1








                                                                                      1





                                                                                      $begingroup$


                                                                                      Python 2, 130 bytes





                                                                                      lambda a,b:' + '.join([`v*V`+'x^'+`k+K`for V,K in g(a)for v,k in g(b)])
                                                                                      g=lambda s:[map(int,t.split('x^'))for t in s.split(' + ')]


                                                                                      Try it online!






                                                                                      share|improve this answer









                                                                                      $endgroup$




                                                                                      Python 2, 130 bytes





                                                                                      lambda a,b:' + '.join([`v*V`+'x^'+`k+K`for V,K in g(a)for v,k in g(b)])
                                                                                      g=lambda s:[map(int,t.split('x^'))for t in s.split(' + ')]


                                                                                      Try it online!







                                                                                      share|improve this answer












                                                                                      share|improve this answer



                                                                                      share|improve this answer










                                                                                      answered 2 hours ago









                                                                                      Chas BrownChas Brown

                                                                                      5,2291523




                                                                                      5,2291523























                                                                                          0












                                                                                          $begingroup$


                                                                                          JavaScript (Babel Node), 118 bytes



                                                                                          Takes input as (a)(b).





                                                                                          a=>b=>(g=s=>[...s.matchAll(/(-?d+)x.(d+)/g)])(a).flatMap(([_,x,p])=>g(b).map(([_,X,P])=>x*X+'x^'+-(-p-P))).join` + `


                                                                                          Try it online!






                                                                                          share|improve this answer









                                                                                          $endgroup$


















                                                                                            0












                                                                                            $begingroup$


                                                                                            JavaScript (Babel Node), 118 bytes



                                                                                            Takes input as (a)(b).





                                                                                            a=>b=>(g=s=>[...s.matchAll(/(-?d+)x.(d+)/g)])(a).flatMap(([_,x,p])=>g(b).map(([_,X,P])=>x*X+'x^'+-(-p-P))).join` + `


                                                                                            Try it online!






                                                                                            share|improve this answer









                                                                                            $endgroup$
















                                                                                              0












                                                                                              0








                                                                                              0





                                                                                              $begingroup$


                                                                                              JavaScript (Babel Node), 118 bytes



                                                                                              Takes input as (a)(b).





                                                                                              a=>b=>(g=s=>[...s.matchAll(/(-?d+)x.(d+)/g)])(a).flatMap(([_,x,p])=>g(b).map(([_,X,P])=>x*X+'x^'+-(-p-P))).join` + `


                                                                                              Try it online!






                                                                                              share|improve this answer









                                                                                              $endgroup$




                                                                                              JavaScript (Babel Node), 118 bytes



                                                                                              Takes input as (a)(b).





                                                                                              a=>b=>(g=s=>[...s.matchAll(/(-?d+)x.(d+)/g)])(a).flatMap(([_,x,p])=>g(b).map(([_,X,P])=>x*X+'x^'+-(-p-P))).join` + `


                                                                                              Try it online!







                                                                                              share|improve this answer












                                                                                              share|improve this answer



                                                                                              share|improve this answer










                                                                                              answered 12 hours ago









                                                                                              ArnauldArnauld

                                                                                              80.8k797334




                                                                                              80.8k797334























                                                                                                  0












                                                                                                  $begingroup$


                                                                                                  Haskell, 133 bytes





                                                                                                  f""=
                                                                                                  f t|[(a,_:_:u)]<-reads t,[(i,v)]<-reads u=(a,i):f(drop 3v)
                                                                                                  p!q=drop 3$do(a,i)<-f p;(b,j)<-f q;" + "++shows(a*b)"x^"++show(i+j)


                                                                                                  Try it online!



                                                                                                  f parses a polynomial from a string, ! multiplies two of them and formats the result.






                                                                                                  share|improve this answer









                                                                                                  $endgroup$


















                                                                                                    0












                                                                                                    $begingroup$


                                                                                                    Haskell, 133 bytes





                                                                                                    f""=
                                                                                                    f t|[(a,_:_:u)]<-reads t,[(i,v)]<-reads u=(a,i):f(drop 3v)
                                                                                                    p!q=drop 3$do(a,i)<-f p;(b,j)<-f q;" + "++shows(a*b)"x^"++show(i+j)


                                                                                                    Try it online!



                                                                                                    f parses a polynomial from a string, ! multiplies two of them and formats the result.






                                                                                                    share|improve this answer









                                                                                                    $endgroup$
















                                                                                                      0












                                                                                                      0








                                                                                                      0





                                                                                                      $begingroup$


                                                                                                      Haskell, 133 bytes





                                                                                                      f""=
                                                                                                      f t|[(a,_:_:u)]<-reads t,[(i,v)]<-reads u=(a,i):f(drop 3v)
                                                                                                      p!q=drop 3$do(a,i)<-f p;(b,j)<-f q;" + "++shows(a*b)"x^"++show(i+j)


                                                                                                      Try it online!



                                                                                                      f parses a polynomial from a string, ! multiplies two of them and formats the result.






                                                                                                      share|improve this answer









                                                                                                      $endgroup$




                                                                                                      Haskell, 133 bytes





                                                                                                      f""=
                                                                                                      f t|[(a,_:_:u)]<-reads t,[(i,v)]<-reads u=(a,i):f(drop 3v)
                                                                                                      p!q=drop 3$do(a,i)<-f p;(b,j)<-f q;" + "++shows(a*b)"x^"++show(i+j)


                                                                                                      Try it online!



                                                                                                      f parses a polynomial from a string, ! multiplies two of them and formats the result.







                                                                                                      share|improve this answer












                                                                                                      share|improve this answer



                                                                                                      share|improve this answer










                                                                                                      answered 11 hours ago









                                                                                                      LynnLynn

                                                                                                      50.8k899233




                                                                                                      50.8k899233























                                                                                                          0












                                                                                                          $begingroup$


                                                                                                          Python 2, 193 bytes





                                                                                                          import re
                                                                                                          f=re.finditer
                                                                                                          lambda a,b:' + '.join(' + '.join(`int(m.group(1))*int(n.group(1))`+'x^'+`int(m.group(2))+int(n.group(2))`for n in f('(-?d+)x^(d+)',b))for m in f('(-?d+)x^(d+)',a))


                                                                                                          Try it online!



                                                                                                          Side note: First time doing a code golf challenge, so sorry if the attempt sucks haha






                                                                                                          share|improve this answer








                                                                                                          New contributor




                                                                                                          GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                          Check out our Code of Conduct.






                                                                                                          $endgroup$









                                                                                                          • 2




                                                                                                            $begingroup$
                                                                                                            Welcome to PPCG! I'm not much of a python programmer, but if your submission is longer than a SNOBOL one, there's probably room for improvement, heheh. Perhaps you can find help at Tips for Golfing in Python or Tips for Golfing in <all languages>! Hope you enjoy the time you spend here :-)
                                                                                                            $endgroup$
                                                                                                            – Giuseppe
                                                                                                            10 hours ago


















                                                                                                          0












                                                                                                          $begingroup$


                                                                                                          Python 2, 193 bytes





                                                                                                          import re
                                                                                                          f=re.finditer
                                                                                                          lambda a,b:' + '.join(' + '.join(`int(m.group(1))*int(n.group(1))`+'x^'+`int(m.group(2))+int(n.group(2))`for n in f('(-?d+)x^(d+)',b))for m in f('(-?d+)x^(d+)',a))


                                                                                                          Try it online!



                                                                                                          Side note: First time doing a code golf challenge, so sorry if the attempt sucks haha






                                                                                                          share|improve this answer








                                                                                                          New contributor




                                                                                                          GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                          Check out our Code of Conduct.






                                                                                                          $endgroup$









                                                                                                          • 2




                                                                                                            $begingroup$
                                                                                                            Welcome to PPCG! I'm not much of a python programmer, but if your submission is longer than a SNOBOL one, there's probably room for improvement, heheh. Perhaps you can find help at Tips for Golfing in Python or Tips for Golfing in <all languages>! Hope you enjoy the time you spend here :-)
                                                                                                            $endgroup$
                                                                                                            – Giuseppe
                                                                                                            10 hours ago
















                                                                                                          0












                                                                                                          0








                                                                                                          0





                                                                                                          $begingroup$


                                                                                                          Python 2, 193 bytes





                                                                                                          import re
                                                                                                          f=re.finditer
                                                                                                          lambda a,b:' + '.join(' + '.join(`int(m.group(1))*int(n.group(1))`+'x^'+`int(m.group(2))+int(n.group(2))`for n in f('(-?d+)x^(d+)',b))for m in f('(-?d+)x^(d+)',a))


                                                                                                          Try it online!



                                                                                                          Side note: First time doing a code golf challenge, so sorry if the attempt sucks haha






                                                                                                          share|improve this answer








                                                                                                          New contributor




                                                                                                          GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                          Check out our Code of Conduct.






                                                                                                          $endgroup$




                                                                                                          Python 2, 193 bytes





                                                                                                          import re
                                                                                                          f=re.finditer
                                                                                                          lambda a,b:' + '.join(' + '.join(`int(m.group(1))*int(n.group(1))`+'x^'+`int(m.group(2))+int(n.group(2))`for n in f('(-?d+)x^(d+)',b))for m in f('(-?d+)x^(d+)',a))


                                                                                                          Try it online!



                                                                                                          Side note: First time doing a code golf challenge, so sorry if the attempt sucks haha







                                                                                                          share|improve this answer








                                                                                                          New contributor




                                                                                                          GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                          Check out our Code of Conduct.









                                                                                                          share|improve this answer



                                                                                                          share|improve this answer






                                                                                                          New contributor




                                                                                                          GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                          Check out our Code of Conduct.









                                                                                                          answered 10 hours ago









                                                                                                          GotCubesGotCubes

                                                                                                          1




                                                                                                          1




                                                                                                          New contributor




                                                                                                          GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                          Check out our Code of Conduct.





                                                                                                          New contributor





                                                                                                          GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                          Check out our Code of Conduct.






                                                                                                          GotCubes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                          Check out our Code of Conduct.








                                                                                                          • 2




                                                                                                            $begingroup$
                                                                                                            Welcome to PPCG! I'm not much of a python programmer, but if your submission is longer than a SNOBOL one, there's probably room for improvement, heheh. Perhaps you can find help at Tips for Golfing in Python or Tips for Golfing in <all languages>! Hope you enjoy the time you spend here :-)
                                                                                                            $endgroup$
                                                                                                            – Giuseppe
                                                                                                            10 hours ago
















                                                                                                          • 2




                                                                                                            $begingroup$
                                                                                                            Welcome to PPCG! I'm not much of a python programmer, but if your submission is longer than a SNOBOL one, there's probably room for improvement, heheh. Perhaps you can find help at Tips for Golfing in Python or Tips for Golfing in <all languages>! Hope you enjoy the time you spend here :-)
                                                                                                            $endgroup$
                                                                                                            – Giuseppe
                                                                                                            10 hours ago










                                                                                                          2




                                                                                                          2




                                                                                                          $begingroup$
                                                                                                          Welcome to PPCG! I'm not much of a python programmer, but if your submission is longer than a SNOBOL one, there's probably room for improvement, heheh. Perhaps you can find help at Tips for Golfing in Python or Tips for Golfing in <all languages>! Hope you enjoy the time you spend here :-)
                                                                                                          $endgroup$
                                                                                                          – Giuseppe
                                                                                                          10 hours ago






                                                                                                          $begingroup$
                                                                                                          Welcome to PPCG! I'm not much of a python programmer, but if your submission is longer than a SNOBOL one, there's probably room for improvement, heheh. Perhaps you can find help at Tips for Golfing in Python or Tips for Golfing in <all languages>! Hope you enjoy the time you spend here :-)
                                                                                                          $endgroup$
                                                                                                          – Giuseppe
                                                                                                          10 hours ago













                                                                                                          0












                                                                                                          $begingroup$


                                                                                                          Retina, 110 bytes



                                                                                                          SS+(?=.*n(.+))
                                                                                                          $1#$&
                                                                                                          |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                                                                                                          $1$4$.($2*$5*)x^$.($3*_$6*
                                                                                                          --|-(0)
                                                                                                          $1


                                                                                                          Try it online! Explanation:



                                                                                                          SS+(?=.*n(.+))
                                                                                                          $1#$&


                                                                                                          Prefix each term in the first input with a #, a copy of the second input, and a space. This means that all of the terms in copies of the second input are preceded by a space and none of the terms from the first input are.



                                                                                                          |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                                                                                                          $1$4$.($2*$5*)x^$.($3*_$6*


                                                                                                          Match all of the copies of terms in the second input and their corresponding term from the first input. Concatenate any - signs, multiply the coefficients, and add the indices. Finally join all of the resulting substitutions with the string  + .



                                                                                                          --|-(0)
                                                                                                          $1


                                                                                                          Delete any pairs of -s and convert -0 to 0.






                                                                                                          share|improve this answer









                                                                                                          $endgroup$


















                                                                                                            0












                                                                                                            $begingroup$


                                                                                                            Retina, 110 bytes



                                                                                                            SS+(?=.*n(.+))
                                                                                                            $1#$&
                                                                                                            |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                                                                                                            $1$4$.($2*$5*)x^$.($3*_$6*
                                                                                                            --|-(0)
                                                                                                            $1


                                                                                                            Try it online! Explanation:



                                                                                                            SS+(?=.*n(.+))
                                                                                                            $1#$&


                                                                                                            Prefix each term in the first input with a #, a copy of the second input, and a space. This means that all of the terms in copies of the second input are preceded by a space and none of the terms from the first input are.



                                                                                                            |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                                                                                                            $1$4$.($2*$5*)x^$.($3*_$6*


                                                                                                            Match all of the copies of terms in the second input and their corresponding term from the first input. Concatenate any - signs, multiply the coefficients, and add the indices. Finally join all of the resulting substitutions with the string  + .



                                                                                                            --|-(0)
                                                                                                            $1


                                                                                                            Delete any pairs of -s and convert -0 to 0.






                                                                                                            share|improve this answer









                                                                                                            $endgroup$
















                                                                                                              0












                                                                                                              0








                                                                                                              0





                                                                                                              $begingroup$


                                                                                                              Retina, 110 bytes



                                                                                                              SS+(?=.*n(.+))
                                                                                                              $1#$&
                                                                                                              |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                                                                                                              $1$4$.($2*$5*)x^$.($3*_$6*
                                                                                                              --|-(0)
                                                                                                              $1


                                                                                                              Try it online! Explanation:



                                                                                                              SS+(?=.*n(.+))
                                                                                                              $1#$&


                                                                                                              Prefix each term in the first input with a #, a copy of the second input, and a space. This means that all of the terms in copies of the second input are preceded by a space and none of the terms from the first input are.



                                                                                                              |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                                                                                                              $1$4$.($2*$5*)x^$.($3*_$6*


                                                                                                              Match all of the copies of terms in the second input and their corresponding term from the first input. Concatenate any - signs, multiply the coefficients, and add the indices. Finally join all of the resulting substitutions with the string  + .



                                                                                                              --|-(0)
                                                                                                              $1


                                                                                                              Delete any pairs of -s and convert -0 to 0.






                                                                                                              share|improve this answer









                                                                                                              $endgroup$




                                                                                                              Retina, 110 bytes



                                                                                                              SS+(?=.*n(.+))
                                                                                                              $1#$&
                                                                                                              |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                                                                                                              $1$4$.($2*$5*)x^$.($3*_$6*
                                                                                                              --|-(0)
                                                                                                              $1


                                                                                                              Try it online! Explanation:



                                                                                                              SS+(?=.*n(.+))
                                                                                                              $1#$&


                                                                                                              Prefix each term in the first input with a #, a copy of the second input, and a space. This means that all of the terms in copies of the second input are preceded by a space and none of the terms from the first input are.



                                                                                                              |" + "L$v` (-?)(d+)x.(d+).*?#(-?)(d+)x.(d+)
                                                                                                              $1$4$.($2*$5*)x^$.($3*_$6*


                                                                                                              Match all of the copies of terms in the second input and their corresponding term from the first input. Concatenate any - signs, multiply the coefficients, and add the indices. Finally join all of the resulting substitutions with the string  + .



                                                                                                              --|-(0)
                                                                                                              $1


                                                                                                              Delete any pairs of -s and convert -0 to 0.







                                                                                                              share|improve this answer












                                                                                                              share|improve this answer



                                                                                                              share|improve this answer










                                                                                                              answered 10 hours ago









                                                                                                              NeilNeil

                                                                                                              82.7k745179




                                                                                                              82.7k745179























                                                                                                                  0












                                                                                                                  $begingroup$


                                                                                                                  Perl 6, 114 bytes





                                                                                                                  {my&g=*.match(/(-?d+)x^(d+)/,:g)».caps».Map;join " + ",map {"{[*] $_»{0}}x^{[+] $_»{1}}"},(g($^a)X g $^b)}


                                                                                                                  Try it online!






                                                                                                                  share|improve this answer









                                                                                                                  $endgroup$


















                                                                                                                    0












                                                                                                                    $begingroup$


                                                                                                                    Perl 6, 114 bytes





                                                                                                                    {my&g=*.match(/(-?d+)x^(d+)/,:g)».caps».Map;join " + ",map {"{[*] $_»{0}}x^{[+] $_»{1}}"},(g($^a)X g $^b)}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$
















                                                                                                                      0












                                                                                                                      0








                                                                                                                      0





                                                                                                                      $begingroup$


                                                                                                                      Perl 6, 114 bytes





                                                                                                                      {my&g=*.match(/(-?d+)x^(d+)/,:g)».caps».Map;join " + ",map {"{[*] $_»{0}}x^{[+] $_»{1}}"},(g($^a)X g $^b)}


                                                                                                                      Try it online!






                                                                                                                      share|improve this answer









                                                                                                                      $endgroup$




                                                                                                                      Perl 6, 114 bytes





                                                                                                                      {my&g=*.match(/(-?d+)x^(d+)/,:g)».caps».Map;join " + ",map {"{[*] $_»{0}}x^{[+] $_»{1}}"},(g($^a)X g $^b)}


                                                                                                                      Try it online!







                                                                                                                      share|improve this answer












                                                                                                                      share|improve this answer



                                                                                                                      share|improve this answer










                                                                                                                      answered 3 hours ago









                                                                                                                      bb94bb94

                                                                                                                      1,045611




                                                                                                                      1,045611






























                                                                                                                          draft saved

                                                                                                                          draft discarded




















































                                                                                                                          If this is an answer to a challenge…




                                                                                                                          • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                                          • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                                            Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                                          • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                                          More generally…




                                                                                                                          • …Please make sure to answer the question and provide sufficient detail.


                                                                                                                          • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                                                          draft saved


                                                                                                                          draft discarded














                                                                                                                          StackExchange.ready(
                                                                                                                          function () {
                                                                                                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182972%2fmultiply-two-integer-polynomials%23new-answer', 'question_page');
                                                                                                                          }
                                                                                                                          );

                                                                                                                          Post as a guest















                                                                                                                          Required, but never shown





















































                                                                                                                          Required, but never shown














                                                                                                                          Required, but never shown












                                                                                                                          Required, but never shown







                                                                                                                          Required, but never shown

































                                                                                                                          Required, but never shown














                                                                                                                          Required, but never shown












                                                                                                                          Required, but never shown







                                                                                                                          Required, but never shown







                                                                                                                          Popular posts from this blog

                                                                                                                          Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum

                                                                                                                          He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

                                                                                                                          Slayer Innehåll Historia | Stil, komposition och lyrik | Bandets betydelse och framgångar | Sidoprojekt och samarbeten | Kontroverser | Medlemmar | Utmärkelser och nomineringar | Turnéer och festivaler | Diskografi | Referenser | Externa länkar | Navigeringsmenywww.slayer.net”Metal Massacre vol. 1””Metal Massacre vol. 3””Metal Massacre Volume III””Show No Mercy””Haunting the Chapel””Live Undead””Hell Awaits””Reign in Blood””Reign in Blood””Gold & Platinum – Reign in Blood””Golden Gods Awards Winners”originalet”Kerrang! Hall Of Fame””Slayer Looks Back On 37-Year Career In New Video Series: Part Two””South of Heaven””Gold & Platinum – South of Heaven””Seasons in the Abyss””Gold & Platinum - Seasons in the Abyss””Divine Intervention””Divine Intervention - Release group by Slayer””Gold & Platinum - Divine Intervention””Live Intrusion””Undisputed Attitude””Abolish Government/Superficial Love””Release “Slatanic Slaughter: A Tribute to Slayer” by Various Artists””Diabolus in Musica””Soundtrack to the Apocalypse””God Hates Us All””Systematic - Relationships””War at the Warfield””Gold & Platinum - War at the Warfield””Soundtrack to the Apocalypse””Gold & Platinum - Still Reigning””Metallica, Slayer, Iron Mauden Among Winners At Metal Hammer Awards””Eternal Pyre””Eternal Pyre - Slayer release group””Eternal Pyre””Metal Storm Awards 2006””Kerrang! Hall Of Fame””Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Bullet-For My Valentine booed at Metal Hammer Golden Gods Awards””Unholy Aliance””The End Of Slayer?””Slayer: We Could Thrash Out Two More Albums If We're Fast Enough...””'The Unholy Alliance: Chapter III' UK Dates Added”originalet”Megadeth And Slayer To Co-Headline 'Canadian Carnage' Trek”originalet”World Painted Blood””Release “World Painted Blood” by Slayer””Metallica Heading To Cinemas””Slayer, Megadeth To Join Forces For 'European Carnage' Tour - Dec. 18, 2010”originalet”Slayer's Hanneman Contracts Acute Infection; Band To Bring In Guest Guitarist””Cannibal Corpse's Pat O'Brien Will Step In As Slayer's Guest Guitarist”originalet”Slayer’s Jeff Hanneman Dead at 49””Dave Lombardo Says He Made Only $67,000 In 2011 While Touring With Slayer””Slayer: We Do Not Agree With Dave Lombardo's Substance Or Timeline Of Events””Slayer Welcomes Drummer Paul Bostaph Back To The Fold””Slayer Hope to Unveil Never-Before-Heard Jeff Hanneman Material on Next Album””Slayer Debut New Song 'Implode' During Surprise Golden Gods Appearance””Release group Repentless by Slayer””Repentless - Slayer - Credits””Slayer””Metal Storm Awards 2015””Slayer - to release comic book "Repentless #1"””Slayer To Release 'Repentless' 6.66" Vinyl Box Set””BREAKING NEWS: Slayer Announce Farewell Tour””Slayer Recruit Lamb of God, Anthrax, Behemoth + Testament for Final Tour””Slayer lägger ner efter 37 år””Slayer Announces Second North American Leg Of 'Final' Tour””Final World Tour””Slayer Announces Final European Tour With Lamb of God, Anthrax And Obituary””Slayer To Tour Europe With Lamb of God, Anthrax And Obituary””Slayer To Play 'Last French Show Ever' At Next Year's Hellfst””Slayer's Final World Tour Will Extend Into 2019””Death Angel's Rob Cavestany On Slayer's 'Farewell' Tour: 'Some Of Us Could See This Coming'””Testament Has No Plans To Retire Anytime Soon, Says Chuck Billy””Anthrax's Scott Ian On Slayer's 'Farewell' Tour Plans: 'I Was Surprised And I Wasn't Surprised'””Slayer””Slayer's Morbid Schlock””Review/Rock; For Slayer, the Mania Is the Message””Slayer - Biography””Slayer - Reign In Blood”originalet”Dave Lombardo””An exclusive oral history of Slayer”originalet”Exclusive! Interview With Slayer Guitarist Jeff Hanneman”originalet”Thinking Out Loud: Slayer's Kerry King on hair metal, Satan and being polite””Slayer Lyrics””Slayer - Biography””Most influential artists for extreme metal music””Slayer - Reign in Blood””Slayer guitarist Jeff Hanneman dies aged 49””Slatanic Slaughter: A Tribute to Slayer””Gateway to Hell: A Tribute to Slayer””Covered In Blood””Slayer: The Origins of Thrash in San Francisco, CA.””Why They Rule - #6 Slayer”originalet”Guitar World's 100 Greatest Heavy Metal Guitarists Of All Time”originalet”The fans have spoken: Slayer comes out on top in readers' polls”originalet”Tribute to Jeff Hanneman (1964-2013)””Lamb Of God Frontman: We Sound Like A Slayer Rip-Off””BEHEMOTH Frontman Pays Tribute To SLAYER's JEFF HANNEMAN””Slayer, Hatebreed Doing Double Duty On This Year's Ozzfest””System of a Down””Lacuna Coil’s Andrea Ferro Talks Influences, Skateboarding, Band Origins + More””Slayer - Reign in Blood””Into The Lungs of Hell””Slayer rules - en utställning om fans””Slayer and Their Fans Slashed Through a No-Holds-Barred Night at Gas Monkey””Home””Slayer””Gold & Platinum - The Big 4 Live from Sofia, Bulgaria””Exclusive! Interview With Slayer Guitarist Kerry King””2008-02-23: Wiltern, Los Angeles, CA, USA””Slayer's Kerry King To Perform With Megadeth Tonight! - Oct. 21, 2010”originalet”Dave Lombardo - Biography”Slayer Case DismissedArkiveradUltimate Classic Rock: Slayer guitarist Jeff Hanneman dead at 49.”Slayer: "We could never do any thing like Some Kind Of Monster..."””Cannibal Corpse'S Pat O'Brien Will Step In As Slayer'S Guest Guitarist | The Official Slayer Site”originalet”Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Kerrang! Awards 2006 Blog: Kerrang! Hall Of Fame””Kerrang! Awards 2013: Kerrang! Legend”originalet”Metallica, Slayer, Iron Maien Among Winners At Metal Hammer Awards””Metal Hammer Golden Gods Awards””Bullet For My Valentine Booed At Metal Hammer Golden Gods Awards””Metal Storm Awards 2006””Metal Storm Awards 2015””Slayer's Concert History””Slayer - Relationships””Slayer - Releases”Slayers officiella webbplatsSlayer på MusicBrainzOfficiell webbplatsSlayerSlayerr1373445760000 0001 1540 47353068615-5086262726cb13906545x(data)6033143kn20030215029