[Date Index]
[Thread Index]
[Author Index]
OptimizeExpression
*To*: mathgroup at smc.vnet.net
*Subject*: [mg86170] OptimizeExpression
*From*: Evan Drumwright <edrumwri at hotmail.com>
*Date*: Tue, 4 Mar 2008 02:09:44 -0500 (EST)
Hi everyone,
I'm trying to send a very large (200+MB) expression to a C file using CForm, which, as you might imagine, crashes my compiler. From other discussions on this list, I have seen that you can use the OptimizeExpression[] function to eliminate common subexpressions, and I think that this will work. However, I don't understand how to process the resulting compound expression. For instance:
Experimental`OptimizeExpression[(3+3*a^2 + Sqrt[5 + 6*a + 5*a^2] + a*(4 + Sqrt[5 + 6*a + 5*a^2]))/6]
generates
Out[1]= Experimental`OptimizedExpression[Block[{$$11, $$13, $$14, $$15,
2
> $$16}, $$11 = a ; $$13 = 6 a; $$14 = 5 $$11; $$15 = 5 + $$13 + $$14;
3 + 3 $$11 + $$16 + a (4 + $$16)
> $$16 = Sqrt[$$15]; --------------------------------]]
6
Now, I'd like to get out the individual set of statements:
$$11 = a;
$$13 = 6a;
$$14 = 5 $$11;
$$15 = 5 + $$13 + $$14;
$$16 = Sqrt[$$15];
(3 + 3$$11 + $$16 + a(4+$$16)/6
But, if I were to look at the function in the optimized expression, I get the original function:
In[2]:= %[[1]]
2 2 2
3 + 3 a + Sqrt[5 + 6 a + 5 a ] + a (4 + Sqrt[5 + 6 a + 5 a ])
Out[2]= --------------------------------------------------------------
6
I suppose part of the difficulty is that I don't see a way to treat a CompoundExpression as a list of statements to be CForm'd. Can anyone tell me how I'd do this?
Thanks,
Evan
Prev by Date:
**Re: Drawing Tools in 6.0.2**
Next by Date:
**Re: Efficiency and ReplacePart?**
Previous by thread:
**Re: How do I reformulate my NDSolve program**
Next by thread:
**Re: OptimizeExpression**
| |