> > Err. I think the way you implement that in reassoc is ad-hoc and not > related to reassoc at all. > > In fact what reassoc is missing is to handle > > -y * z * (-w) * x -> y * x * w * x > > thus optimize negates as if they were additional * -1 entries in a > multiplication chain. And > then optimize a single remaining * -1 in the result chain to a negate. > > Then match.pd handles x + (-y) -> x - y (independent of -frounding-math btw). > > So no, this isn't ok as-is, IMHO you want to expand the multiplication ops chain > pulling in the * -1 ops (if single-use, of course). > I agree. Here is the updated patch along what you suggested. Does this look better ? Thanks, Kugan