ideas: refactored products into common subexpression.

Closes #4039