Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

trying to "simplify" very large output

160 views
Skip to first unread message

Basjsmit

unread,
Nov 9, 2007, 5:14:07 AM11/9/07
to
Dear Reader,

When I used Mathematica to solve a certain expression, the output was
extremely large, somewhere around 10 000 characters. When I looked more
closely at the output, I noticed certain frases kept repeating. I havent
found anything in the help, but Im wondering if there is a function that can
replace those frases with a variable and set that variable once. An example:

t-> -(y z-v x Cos[k]^2-v x Sin[k]^2)/(z^2-x^2 Cos[k]^2-x^2 Sin[k]^2)-1/2
\[Sqrt]((4 (y z-v x Cos[k]^2-v x Sin[k]^2) ........

becomes:

A = y z-v x Cos[k]^2-v x Sin[k]^2
B = z^2-x^2 Cos[k]^2-x^2 Sin[k]^2
t-> -A / B -1/2 \[Sqrt]((4 A ........

Thanks in advance, Bas

PS: just curious, is there a name for the proces I described above?

Jean-Marc Gulliet

unread,
Nov 10, 2007, 3:50:53 AM11/10/07
to
Basjsmit wrote:

Transformation rules and replacement operators are your friends here.
You should familiarize yourself with the following set of tutorials,
available in the documentation center

tutorial/TransformationRulesAndDefinitionsOverview

or online at

http://reference.wolfram.com/mathematica/tutorial/TransformationRulesAndDefinitionsOverview.html

Regards,
--
Jean-Marc

Daniel Lichtblau

unread,
Nov 10, 2007, 3:54:57 AM11/10/07
to
Basjsmit wrote:
> Dear Reader,

>
> When I used Mathematica to solve a certain expression, the output was
> extremely large, somewhere around 10 000 characters. When I looked more
> closely at the output, I noticed certain frases kept repeating. I havent
> found anything in the help, but Im wondering if there is a function that can
> replace those frases with a variable and set that variable once. An example:
>
> t-> -(y z-v x Cos[k]^2-v x Sin[k]^2)/(z^2-x^2 Cos[k]^2-x^2 Sin[k]^2)-1/2
> \[Sqrt]((4 (y z-v x Cos[k]^2-v x Sin[k]^2) ........
>
> becomes:
>
> A = y z-v x Cos[k]^2-v x Sin[k]^2
> B = z^2-x^2 Cos[k]^2-x^2 Sin[k]^2
> t-> -A / B -1/2 \[Sqrt]((4 A ........
>
> Thanks in advance, Bas
>
> PS: just curious, is there a name for the proces I described above?
>

It is usually referred to as common subexpression elimination (cse).
Quite coincidently this same question came my way yesterday. Mathematica
has some functionality for this in Experimental` context, thus it is a
bit hidden (unfortunately, I should add). Here are some URLs to prior
threads that indicate usage.

http://forums.wolfram.com/mathgroup/archive/2006/Sep/msg00300.html
http://forums.wolfram.com/mathgroup/archive/2005/Jan/msg00387.html
http://forums.wolfram.com/mathgroup/archive/2002/Jan/msg00369.htm

Whether the functionality in Experimental`OptimizeExpression will help
for your particular type of examples might depend on option settings,
etc. so you'll probably need to experiment.

Daniel Lichtblau
Wolfram Research

0 new messages