0

Is there a way to simplify an expression so that it's easy to use it in a program?

For example:

Return[3(x+Sqrt[y])^2+9(x+Sqrt[y])]

Would become:

temp1=x+Sqrt[y]; Return[3 temp1^2+9 temp1]

Basically if the same expression appears multiple times in a larger expression, is there a way to automatically extract it so that it only has to be calculated once?

  • It's certainly possible depending on the depth you're willing to go down to. Gathering things is easy with Cases. Replacing is easy with ReplaceAll. – b3m2a1 Sep 22 '17 at 21:29
  • I'm hoping for a way to do it that'll apply to most cases in an automated way, and will recognize equivalent expressions (like Simplify would) – Alecto Irene Perez Sep 22 '17 at 21:30
  • You do not need to use the Return function. Just evaluate the input cell and the result will be shown in an output cell. – Edmund Sep 23 '17 at 11:10

0 Answers0