Fix a bug in _times_gen and add the cast to polynom