Repository: sympy/sympy

Issue:
Incorrect result when doing multiplication of polynomials in SymPy
```
import sympy

x = sympy.symbols('x')
e = sympy.poly(18786186952704.0*x**391 + 607420044804096.0*x**390 + 1.00192653483704e+16*x**389 + 1.12340813861618e+17*x**388 + 9.62398129745822e+17*x**387 + 6.71245471589807e+18*x**386 + 3.96638528291356e+19*x**385 + 2.04022369386301e+20*x**384 + 9.31645053399718e+20*x**383 + 3.83300315791215e+21*x**382 + 1.43731755825706e+22*x**381 + 4.9579170438376e+22*x**380 + 1.58510523198181e+23*x**379 + 4.72677246134559e+23*x**378 + 1.32172534702695e+24*x**377 + 3.48170338234977e+24*x**376 + 8.67508667977031e+24*x**375 + 2.05188548716969e+25*x**374 + 4.62217891489198e+25*x**373 + 9.94620611226133e+25*x**372 + 2.05022259222962e+26*x**371 + 4.05908315644194e+26*x**370 + 7.73820136814458e+26*x**369 + 1.42397337632569e+27*x**368 + 2.53540660922645e+27*x**367 + 4.37807004799877e+27*x**366 + 7.34819956155604e+27*x**365 + 1.20137214778114e+28*x**364 + 1.91716468432695e+28*x**363 + 2.9919487946825e+28*x**362 + 4.5742546781703e+28*x**361 + 6.86184291643935e+28*x**360 + 1.01139401836376e+29*x**359 + 1.46652441620162e+29*x**358 + 2.09416284080091e+29*x**357 + 2.94774606786176e+29*x**356 + 4.09344545520338e+29*x**355 + 5.61219599549279e+29*x**354 + 7.60185071357956e+29*x**353 + 1.01794218645138e+30*x**352 + 1.34833422466908e+30*x**351 + 1.7675653090294e+30*x**350 + 2.29440117371239e+30*x**349 + 2.9503420548127e+30*x**348 + 3.75976046156287e+30*x**347 + 4.74999937073871e+30*x**346 + 5.95142719009883e+30*x**345 + 7.39744333715976e+30*x**344 + 9.12442320361216e+30*x**343 + 1.11715865398631e+31*x**342 + 1.35807726405611e+31*x**341 + 1.6396111359939e+31*x**340 + 1.96635896889856e+31*x**339 + 2.34305246185014e+31*x**338 + 2.77449583729775e+31*x**337 + 3.26549884864953e+31*x**336 + 3.82080346521502e+31*x**335 + 4.44500339884872e+31*x**334 + 5.14245548133296e+31*x**333 + 5.9171830506378e+31*x**332 + 6.77277360121932e+31*x**331 + 7.7122749480933e+31*x**330 + 8.73809487670393e+31*x**329 + 9.85190815750957e+31*x**328 + 1.10545724219769e+32*x**327 + 1.23460521197106e+32*x**326 + 1.37253490695579e+32*x**325 + 1.51904395757882e+32*x**324 + 1.67382209506145e+32*x**323 + 1.83644728118423e+32*x**322 + 2.00638389805687e+32*x**321 + 2.18298335862547e+32*x**320 + 2.36548710870913e+32*x**319 + 2.55303164068604e+32*x**318 + 2.74465502057376e+32*x**317 + 2.93930460272433e+32*x**316 + 3.13584595246087e+32*x**315 + 3.33307329029845e+32*x**314 + 3.52972181242525e+32*x**313 + 3.7244819808164e+32*x**312 + 3.91601544485273e+32*x**311 + 4.10297189098036e+32*x**310 + 4.28400601723887e+32*x**309 + 4.45779404000103e+32*x**308 + 4.6230495269906e+32*x**307 + 4.77853868383823e+32*x**306 + 4.92309531273987e+32*x**305 + 5.05563547223298e+32*x**304 + 5.17517152342847e+32*x**303 + 5.28082496187536e+32*x**302 + 5.37183737651272e+32*x**301 + 5.44757908299232e+32*x**300 + 5.50755533567183e+32*x**299 + 5.55141034358678e+32*x**298 + 5.57892944810279e+32*x**297 + 5.5900397271145e+32*x**296 + 5.58480906204685e+32*x**295 + 5.56344349448449e+32*x**294 + 5.52628263849091e+32*x**293 + 5.47379303835558e+32*x**292 + 5.40655960133798e+32*x**291 + 5.32527546572947e+32*x**290 + 5.23073077683624e+32*x**289 + 5.12380080005117e+32*x**288 + 5.0054336473724e+32*x**287 + 4.87663772724559e+32*x**286 + 4.73846893635791e+32*x**285 + 4.59201763250845e+32*x**284 + 4.43839553177586e+32*x**283 + 4.27872279128691e+32*x**282 + 4.11411560166392e+32*x**281 + 3.94567458771032e+32*x**280 + 3.77447421763255e+32*x**279 + 3.60155329959775e+32*x**278 + 3.42790655320098e+32*x**277 + 3.25447721236868e+32*x**276 + 3.08215064031296e+32*x**275 + 2.91174898459487e+32*x**274 + 2.74402693317065e+32*x**273 + 2.57966862663438e+32*x**272 + 2.41928573783986e+32*x**271 + 2.26341666779407e+32*x**270 + 2.11252675290002e+32*x**269 + 1.9670093522436e+32*x**268 + 1.82718768785443e+32*x**267 + 1.69331733442125e+32*x**266 + 1.56558928024408e+32*x**265 + 1.44413349419411e+32*x**264 + 1.32902292973695e+32*x**263 + 1.22027788212924e+32*x**262 + 1.11787059936967e+32*x**261 + 1.02173004087736e+32*x**260 + 9.31746684052255e+31*x**259 + 8.47777295239818e+31*x**258 + 7.69649601580008e+31*x**257 + 6.97166817091038e+31*x**256 + 6.30111986490116e+31*x**255 + 5.68252114106536e+31*x**254 + 5.11342046105023e+31*x**253 + 4.59128076016368e+31*x**252 + 4.11351248709378e+31*x**251 + 3.67750346516565e+31*x**250 + 3.280645514238e+31*x**249 + 2.92035786596398e+31*x**248 + 2.59410747247874e+31*x**247 + 2.29942634518776e+31*x**246 + 2.03392607416766e+31*x**245 + 1.79530968342324e+31*x**244 + 1.58138098451387e+31*x**243 + 1.39005160563051e+31*x**242 + 1.21934589258332e+31*x**241 + 1.06740389580791e+31*x**240 + 9.32482667165709e+30*x**239 + 8.1295608916701e+30*x**238 + 7.07313448617111e+30*x**237 + 6.1415695063951e+30*x**236 + 5.32198352029589e+30*x**235 + 4.602548778383e+30*x**234 + 3.97244572596053e+30*x**233 + 3.42181226502325e+30*x**232 + 2.94169005481941e+30*x**231 + 2.52396901031627e+30*x**230 + 2.16133101142353e+30*x**229 + 1.84719368145017e+30*x**228 + 1.5756549435175e+30*x**227 + 1.34143892913845e+30*x**226 + 1.13984369843053e+30*x**225 + 9.66691135076816e+29*x**224 + 8.18279296212723e+29*x**223 + 6.91337422766721e+29*x**222 + 5.82983746453424e+29*x**221 + 4.90686165535244e+29*x**220 + 4.12225804367941e+29*x**219 + 3.4566342372779e+29*x**218 + 2.89308611068738e+29*x**217 + 2.41691651708124e+29*x**216 + 2.0153796190433e+29*x**215 + 1.67744950765163e+29*x**214 + 1.39361168169125e+29*x**213 + 1.15567589314061e+29*x**212 + 9.56608827143122e+28*x**211 + 7.90385074249973e+28*x**210 + 6.51854869552611e+28*x**209 + 5.36627114870467e+28*x**208 + 4.40966261989531e+28*x**207 + 3.61701710225607e+28*x**206 + 2.96148454683881e+28*x**205 + 2.42037807632271e+28*x**204 + 1.97457101717268e+28*x**203 + 1.6079736918933e+28*x**202 + 1.30708075344097e+28*x**201 + 1.06058066598448e+28*x**200 + 8.59019735266542e+27*x**199 + 6.94513855589117e+27*x**198 + 5.60501861937276e+27*x**197 + 4.51535044872758e+27*x**196 + 3.63098001128394e+27*x**195 + 2.91456552715732e+27*x**194 + 2.33528975814278e+27*x**193 + 1.86777240689401e+27*x**192 + 1.49115379140818e+27*x**191 + 1.188324688484e+27*x**190 + 9.45280579391412e+26*x**189 + 7.50581492553531e+26*x**188 + 5.94901241401661e+26*x**187 + 4.70652152586838e+26*x**186 + 3.71673370989202e+26*x**185 + 2.92972569731752e+26*x**184 + 2.30512401872165e+26*x**183 + 1.81034340676203e+26*x**182 + 1.41913687033006e+26*x**181 + 1.11040492005887e+26*x**180 + 8.67219796721523e+25*x**179 + 6.76027631408076e+25*x**178 + 5.25997556818479e+25*x**177 + 4.08491829759755e+25*x**176 + 3.16635446647424e+25*x**175 + 2.44967304875125e+25*x**174 + 1.89158054889391e+25*x**173 + 1.45782414732817e+25*x**172 + 1.12135791467499e+25*x**171 + 8.60869197122726e+24*x**170 + 6.59597006043051e+24*x**169 + 5.0438634649684e+24*x**168 + 3.84933227879042e+24*x**167 + 2.93183152367596e+24*x**166 + 2.22852706967105e+24*x**165 + 1.69050194946342e+24*x**164 + 1.27975122104309e+24*x**163 + 9.6680881289861e+23*x**162 + 7.28875829238494e+23*x**161 + 5.48348800710694e+23*x**160 + 4.11663955183463e+23*x**159 + 3.08392351664647e+23*x**158 + 2.30531741539953e+23*x**157 + 1.7195533162247e+23*x**156 + 1.27982334666812e+23*x**155 + 9.50438312503859e+22*x**154 + 7.04253447662509e+22*x**153 + 5.20660666190957e+22*x**152 + 3.84053327419543e+22*x**151 + 2.82637478194694e+22*x**150 + 2.07519363919927e+22*x**149 + 1.52008380464323e+22*x**148 + 1.11082481827257e+22*x**147 + 8.09807989309473e+21*x**146 + 5.88931041753267e+21*x**145 + 4.27250564717805e+21*x**144 + 3.09188307656375e+21*x**143 + 2.23190051864519e+21*x**142 + 1.60703144783557e+21*x**141 + 1.15414058643475e+21*x**140 + 8.26734051209549e+20*x**139 + 5.906526391579e+20*x**138 + 4.20866452815223e+20*x**137 + 2.99080554595048e+20*x**136 + 2.11957904907271e+20*x**135 + 1.49800754528007e+20*x**134 + 1.055762803507e+20*x**133 + 7.4197863666214e+19*x**132 + 5.19964435311348e+19*x**131 + 3.6332674072111e+19*x**130 + 2.5313174369628e+19*x**129 + 1.75834913998358e+19*x**128 + 1.21774422135393e+19*x**127 + 8.40779420386497e+18*x**126 + 5.78715428446679e+18*x**125 + 3.970875524594e+18*x**124 + 2.71597982386884e+18*x**123 + 1.85168214872764e+18*x**122 + 1.25830615369268e+18*x**121 + 8.52248961334998e+17*x**120 + 5.75289976644556e+17*x**119 + 3.87013642816788e+17*x**118 + 2.5945547266754e+17*x**117 + 1.73329658702463e+17*x**116 + 1.15380239021783e+17*x**115 + 7.65266794627435e+16*x**114 + 5.05697395733019e+16*x**113 + 3.32919678677403e+16*x**112 + 2.18340096225946e+16*x**111 + 1.42641771653066e+16*x**110 + 9.28222858958434e+15*x**109 + 6.01617039744338e+15*x**108 + 3.88344180735753e+15*x**107 + 2.49635298837213e+15*x**106 + 1.59789587032747e+15*x**105 + 1.01837064242638e+15*x**104 + 646162735416304.0*x**103 + 408151660246024.0*x**102 + 256632997920088.0*x**101 + 160611666154064.0*x**100 + 100039649901592.0*x**99 + 62007636538464.0*x**98 + 38241146390736.0*x**97 + 23461909088736.0*x**96 + 14317876797656.0*x**95 + 8689992463568.0*x**94 + 5245001129704.0*x**93 + 3147872937568.0*x**92 + 1878373224984.0*x**91 + 1114227943432.0*x**90 + 656870360848.0*x**89 + 384733888736.0*x**88 + 223811972808.0*x**87 + 129272278504.0*x**86 + 74125358696.0*x**85 + 42193679544.0*x**84 + 23840311096.0*x**83 + 13370176224.0*x**82 + 7439064432.0*x**81 + 4103093072.0*x**80 + 2241521448.0*x**79 + 1211545984.0*x**78 + 647642728.0*x**77 + 342538808.0*x**76 + 179304800.0*x**75 + 92964480.0*x**74 + 47694992.0*x**73 + 24132760.0*x**72 + 12008720.0*x**71 + 5853392.0*x**70 + 2792792.0*x**69 + 1311320.0*x**68 + 607200.0*x**67 + 279200.0*x**66 + 128520.0*x**65 + 60232.0*x**64 + 31536.0*x**63 + 20472.0*x**62 + 17060.0*x**61 + 16848.0*x**60 + 17700.0*x**59 + 19528.0*x**58 + 21624.0*x**57 + 23688.0*x**56 + 24700.0*x**55 + 24392.0*x**54 + 23892.0*x**53 + 22464.0*x**52 + 21360.0*x**51 + 21192.0*x**50 + 19836.0*x**49 + 18988.0*x**48 + 18484.0*x**47 + 16136.0*x**46 + 14968.0*x**45 + 13928.0*x**44 + 11460.0*x**43 + 10520.0*x**42 + 8992.0*x**41 + 7028.0*x**40 + 6548.0*x**39 + 5104.0*x**38 + 3940.0*x**37 + 3466.0*x**36 + 2492.0*x**35 + 2174.0*x**34 + 1716.0*x**33 + 1188.0*x**32 + 1204.0*x**31 + 856.0*x**30 + 560.0*x**29 + 512.0*x**28 + 316.0*x**27 + 230.0*x**26 + 176.0*x**25 + 86.0*x**24 + 86.0*x**23 + 54.0*x**22 + 12.0*x**21 + 38.0*x**20 + 20.0*x**19 + 4.0*x**18 + 12.0*x**17 + 4.0*x**16 + 4.0*x**15 + 2.0*x**14 + 2.0*x**11 + 4.0*x**9 + 2.0*x**8)
print(e*x)
```


I was doing a simple multiplication calculation, but I got an incorrect result:

> Poly(-1.02749361615667e+15*x**392 + 1.00759245569393e+16*x**391 - 1.9300277358166e+16*x**390 + 1.32156899612164e+17*x**389 + 9.38136306167316e+17*x**388 + 6.73247311178813e+18*x**387 + 3.96574788227904e+19*x**386 + 2.04057697794413e+20*x**385 + 9.31648654918774e+20*x**384 + 3.83296743594759e+21*x**383 ...........

 The version I am using is 1.13.3

Discussion:

Patch:
diff --git a/sympy/polys/densearith.py b/sympy/polys/densearith.py
index 30bf9553b0..1088691ca3 100644
--- a/sympy/polys/densearith.py
+++ b/sympy/polys/densearith.py
@@ -757,7 +757,7 @@ def dup_mul(f, g, K):
 
     n = max(df, dg) + 1
 
-    if n < 100:
+    if n < 100 or not K.is_Exact:
         h = []
 
         for i in range(0, df + dg + 1):


Test patch:
diff --git a/sympy/polys/tests/test_densearith.py b/sympy/polys/tests/test_densearith.py
index ea626f1fea..ebb29d5086 100644
--- a/sympy/polys/tests/test_densearith.py
+++ b/sympy/polys/tests/test_densearith.py
@@ -41,11 +41,13 @@
     ExactQuotientFailed,
 )
 
-from sympy.polys.specialpolys import f_polys
-from sympy.polys.domains import FF, ZZ, QQ
+from sympy.polys.specialpolys import f_polys, Symbol, Poly
+from sympy.polys.domains import FF, ZZ, QQ, CC
 
 from sympy.testing.pytest import raises
 
+x = Symbol('x')
+
 f_0, f_1, f_2, f_3, f_4, f_5, f_6 = [ f.to_dense() for f in f_polys() ]
 F_0 = dmp_mul_ground(dmp_normal(f_0, 2, QQ), QQ(1, 7), 2, QQ)
 
@@ -995,3 +997,11 @@ def test_dmp_expand():
     assert dmp_expand(([[1], [2], [3]], [[1], [2]], [[7], [5], [4], [3]]), 1, ZZ) == \
         dmp_mul([[1], [2], [3]], dmp_mul([[1], [2]], [[7], [5], [
                 4], [3]], 1, ZZ), 1, ZZ)
+
+def test_dup_mul_poly():
+    p = Poly(18786186952704.0*x**165 + 9.31746684052255e+31*x**82, x, domain='RR')
+    px = Poly(18786186952704.0*x**166 + 9.31746684052255e+31*x**83, x, domain='RR')
+
+    assert p * x == px
+    assert p.set_domain(QQ) * x == px.set_domain(QQ)
+    assert p.set_domain(CC) * x == px.set_domain(CC)