# Ticket #12123(new defect)

Opened 18 months ago

## Bug in convolution

Reported by: Owned by: kcrisman burcin major sage-5.10 calculus wdj N/A

### Description

```sage: x = PolynomialRing(QQ,'x').gen()
sage: f = Piecewise([[(-2, 2), 2 * x^0]])
sage: g = Piecewise([[(0, 2), 3/4 * x^0]])
sage: n = f.convolution(g)

sage: n
Piecewise defined function with 3 parts, [[(-2, 0), 3/2*x + 3], [(0, 2), 6], [(2, 4), -3/2*x + 6]]
```

But the middle piece should be 3, not 6, apparently.

See the original report at  this ask.sagemath.org question.

## Change History

### comment:1 Changed 18 months ago by kcrisman

The fix is to fix the following

```    cmd1 = "integrate((%s)*(%s),%s,%s,%s)"%(i1,i2, uu, a1,    tt-b1)    ## if a1+b1 < tt < a2+b1
cmd2 = "integrate((%s)*(%s),%s,%s,%s)"%(i1,i2, uu, tt-b2, tt-b1)    ## if a1+b2 < tt < a2+b1
cmd3 = "integrate((%s)*(%s),%s,%s,%s)"%(i1,i2, uu, tt-b2, a2)       ## if a1+b2 < tt < a2+b2
cmd4 = "integrate((%s)*(%s),%s,%s,%s)"%(i1,i2, uu, a1, a2)          ## if a2+b1 < tt < a1+b2
<snip>
if a1-b1<a2-b2:
if a2+b1!=a1+b2:
h = Piecewise([[(a1+b1,a1+b2),fg1],[(a1+b2,a2+b1),fg4],[(a2+b1,a2+b2),fg3]])
```

to have f2 instead of f4. There is a parallel part as well in the other branch of the if, where fg2 should be fg4, it appears.

This should be fixed quickly, but should also be checked to make sure it really does do the right thing! The code is not really commented enough to show what is going on with all these different mini-convolutions, one has to really think about it.

Note: See TracTickets for help on using tickets.