How do I replace an algebraic expression with a symbol? I'm trying to replace repeated terms such as $(a+b)$ with c, for example, so that $x(4a + 4b) + x^2(6a + 6b)$ becomes $x4c + x^26c$ .
Asked
Active
Viewed 67 times
1 Answers
1
fun = x (4 a + 4 b) + x^2 (6 a + 6 b);
Collect[fun, {a, b}]/2 /. a | b :> c
c*(4x + 6x^2)
Expand[%]
4cx + 6cx^2
eldo
- 67,911
- 5
- 60
- 168
-
(+1) I think it is direct if you apply:
Collect[fun, {x}, Factor] /. a + b -> c– E. Chan-López Jan 09 '24 at 19:33 -
1
-
You're welcome, @eldo, it's a pleasure to interact with you and provide feedback! :-) – E. Chan-López Jan 09 '24 at 23:28
4 x (a + b) + 6 x^2 (a + b) /. {(a + b) -> c}– martin Jan 09 '24 at 18:30Expand[Simplify[fun,a+b==c]]– Bill Jan 09 '24 at 19:16x (4 a + 4 b) + x^2 (6 a + 6 b) /. a -> c - b // Simplify– Bob Hanlon Jan 09 '24 at 20:14