TransWikia.com

Replace small expressions in larger expressions?

Mathematica Asked on January 14, 2021

How can I replace small expressions in larger expressions?

Simple example

Replace[a^2 + b^2 + 2*a*b + x, (a + b)^2 -> c]

I want to get c + x but the output is a^2 + b^2 + 2*a*b + x.

One Answer

Try this.

First:

s = Solve[(a + b)^2 == c, a][[1, 1]]

(*  a -> -b - Sqrt[c]  *)

second:

a^2 + b^2 + 2*a*b + x /. s // Simplify

(*  c + x   *)

Have fun!

Answered by Alexei Boulbitch on January 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP