# Wrestling with substitution rules

## Summary

I am struggling with substitution rules.

### Example

Here are several cases which are problematic:

Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}


Actual result:

{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}


Desired result:

{1 + α +  b, -α, 2 α, α^2}


## Question

Currently, the rule is permuted for every case, e.g.

2 a + 2 b -> 2α


Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?

• You mean: "One to rule them all"? ;) – Henrik Schumacher Nov 4 '18 at 18:38
• Use PolynomialReduce to obtain algebraic "substitutions". In:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out= {1 + alpha + b, -alpha, 2 alpha, alpha^2} – Daniel Lichtblau Nov 4 '18 at 19:14
• Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS. – Bob Hanlon Nov 4 '18 at 19:38

{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify

Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b,  a^2 + 2 a b + b^2}, {a + b == α}]