Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I often run into long expressions in the process of solving equations. To go forward I need to be able to eye-ball the expressions to make some substitutions or use some existing relations I know to cancel stuff out etc to reduce the expression to as small as possible so I can prove certain properties about the expressions, such as positivity, monotonicity etc. However, many times I am not able to do much because I can't even see the expression properly.

Is there a way to present the expression in some rational fraction or something that would make it easy to see..

So something like this:

$ \frac{F(x,y,z)}{G(x,y,z)+H(x,y,z)}+\frac{F_2(x,y,z)+G_2(x,y,z)}{G_3(x,y,z)+H_4(x,y,z)}+...\\ $

instead of something that just spills across lines so it's hard to track what the thing looks like:

$ (( x + ((f(x) +g(y)/(......\\ ..... ))))+ ...\\ ....\\ (((((....\\ ...))$

Below is an actual expression that I have:

x->-(-((2 H0D^p (-1+p) p)/(-2 delta p+2 p r-2 rho+(-1+p) p sigma^2))+(H0D^((2 delta-2   r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((F (c0-rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 ((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))+(H0D^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((F (c0-rho) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 (-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))))/(H0D^2 ((H0S^(-1-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (H0D^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))-H0D^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) ((F (-c0+rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(4 rho σ^4)-(2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)+(H0S (r-rho) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)) (-((2 H0D^p (-1+p) p)/(-2 delta p+2 p r-2 rho+(-1+p) p sigma^2))+(H0D^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((F (c0-rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 ((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))+(H0D^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((F (c0-rho) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 (-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))))/(H0D^2 ((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))-(H0S^(-1-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((H0D^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 σ^2)-(H0D^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 σ^2)) (delta/(delta-r+rho)-(2 H0D^(-1+p) p)/(-2 delta p+2 p r-2 rho+(-1+p) p sigma^2)+(H0D^(-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) ((F (c0-rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 ((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))+(H0D^(-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) ((F (c0-rho) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 (-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))) (-((2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 delta p+2 p r-2 rho+(-1+p) p sigma^2))+1/(rho (delta-r+rho))(-((c0 F (delta-r+rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(4 σ^4))+rho ((delta F (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(4 σ^4)+(r-rho) (-((F (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(4 σ^4))+H0S (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))))))/(H0D (-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))))

I tried to copy as Latex and compile it but Latex is giving me something that goes off the page. I guess I can break it into many lines at random places and see what that gives me. I was wondering if there is some automatic way of accomplishing this.

share|improve this question
2  
Does expr //TraditionalForm or expr //Row[#,TraditionalForm]& give what you need? –  kguler Dec 11 '12 at 3:51
1  
.. or SetOptions[EvaluationNotebook[], CommonDefaultFormatTypes -> {"Output" -> TraditionalForm}]? –  kguler Dec 11 '12 at 3:58
1  
You could also try exp /. rho -> \[Rho] /. delta -> \[Delta] /. sigma -> \[Sigma] /. H0D -> Subscript[H, D] /. H0S -> Subscript[H, s] and get a large screen ;-) –  chris Dec 11 '12 at 10:58
    
Thanks @kguler and Chris. Your suggestions helped a lot. Next stop: large screen. –  Amatya Dec 12 '12 at 3:16
add comment

1 Answer 1

up vote 2 down vote accepted

Another technique can be added to that of Chris. That is to substitute single symbols for repeated extended expressions. I stored the right hand side of the initial expression above as:

compressedExpression=<<Long Example Test>>;

Then by picking out various repeated expressions I defined the following rules.

rule1 = (-2 r + 2 δ + σ^2 + Sqrt[8 ρ σ^2 + (2 r - 2 δ - σ^2)^2]) -> e1;
rule2 = (-2 r + 2 δ + σ^2 - Sqrt[8 ρ σ^2 + (2 r - 2 δ - σ^2)^2]) -> e2;
rule3 = (2 p r - 2 p δ - 2 ρ + (-1 + p) p σ^2) -> e3;
rule4 = (-2 (-p r + p δ + ρ) + (-1 + p) p σ^2) -> e4;
rule5 = (-r + δ + ρ) -> e5;
rule6 = k_. (1/( e4 e5 ρ )) -> k e6;

Then I did the following substitutions, starting with Chris's substitutions. Remember that the starting expression is just the right hand side of Amatya's expression.

step1 = Uncompress[compressedExpression] /. rho -> ρ /. 
      delta -> δ /. sigma -> σ /. 
    H0D -> Subscript[H, D] /. H0S -> Subscript[H, s];
step2 = step1 /. rule1 /. rule2 /. rule3 /. rule4;
step3 = step2 /. rule5 /. Minus /@ rule5 // Simplify;
step4 = step3 /. rule6 /. rule5

enter image description here

I don't know if that is much of a help. The process is a bit of an art. You can reverse substitute simply by reversing most of the rules. For example:

e1 - e2 /. Reverse[rule1] /. Reverse[rule2]
(* 2 Sqrt[8 ρ σ^2 + (2 r - 2 δ - σ^2)^2] *)
share|improve this answer
    
Thanks David! That helps a lot. It is difficult, maybe unfeasible, to make sense by eyeballing some of the expressions I have. –  Amatya Aug 30 '13 at 19:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.