# Separating product terms and keep a custom order in addition

Posted 8 months ago
1036 Views
|
5 Replies
|
1 Total Likes
|
 I would like to write equations in the form as following: 1/2y + 3/8 x == 2/5 z + wWhen this is evaluated it returns however I would like keep the product terms separated from the symbols and the order of addition as placed in the original equation i.e. I would like to keep the following format:My solution so far is to use this syntax: HoldForm[HoldForm[1/2]*y + HoldForm[3/8]*x] == HoldForm[HoldForm[2/5] *z + w] but I am not aware how I can generalize this in a programatic way or if there is any other more simple way to achive the same result. Any suggestion is welcome.
5 Replies
Sort By:
Posted 8 months ago
 You can try with a pattern replacement. For example (1/2 y + 3/8 x == 2/5 z + w) /. coeff_?NumberQ*v__Symbol :> Inactive[Times][coeff, v] 
Posted 8 months ago
 Thank you for your reply. This really works with the multiplication term, but how can I keep also the order of addition.
Posted 8 months ago
 I think for the addition order I cannot avoid the hard way: ClearAttributes[Plus, Orderless] while for the product terms: Replace[expression, Times[x_, y_] -> HoldForm[HoldForm[x]*y], Infinity] 
 Modifying the function Plus sounds dangerous. I would rather make it Inactive: (Inactive[Plus][1/2 y, 3/8 x] == Inactive[Plus][2/5 z, w]) /. coeff_?NumberQ*v__Symbol :> Inactive[Times][coeff, v]