MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Find minimum number of operations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112961] Re: Find minimum number of operations
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Thu, 7 Oct 2010 03:39:29 -0400 (EDT)

brien colwell wrote:
> Hi all,
> 
> I have a set of expressions composed of literals, multiplications,
> additions, and powers. For example,
> 
> -(-3 Bx (Ax^2 + Ay^2 - 2 Ax Bx + Bx^2 - 2 Ay By + By^2)^(3/2) +
>     3 Ax^2 Ay k + 3 Ay^3 k - 8 Ax Ay Bx k + 5 Ay Bx^2 k - Ax^2 By k -
>     9 Ay^2 By k + 4 Ax Bx By k - 3 Bx^2 By k + 9 Ay By^2 k -
>     3 By^3 k + 2 Ax Ay Cx k - 2 Ay Bx Cx k - 2 Ax By Cx k +
>     2 Bx By Cx k - 2 Ax^2 Cy k + 4 Ax Bx Cy k -
>     2 Bx^2 Cy k)/(3 (Ax^2 + Ay^2 - 2 Ax Bx + Bx^2 - 2 Ay By + By^2)^(
>    3/2))
> 
> I would like to find the form for each that minimizes the number of
> operations, where each operation is either a multiplication, addition, or
> power. Is this easily done in Mathematica (7)? Also, just curious, what
> criteria does FullSimplify use to evaluate the "simplest form"?
> 
> Thanks,
> Brien

OptimizeExpression (in Experimental` context) will typically do  a good 
job of this. It does some amount of common subexpression elimination.

ee = -(-3*Bx*(Ax^2 + Ay^2 - 2*Ax*Bx + Bx^2 - 2*Ay*By + By^2)^(3/2) + 
3*Ax^2*Ay*k +
    3*Ay^3*k - 8*Ax*Ay*Bx*k + 5*Ay*Bx^2*k - Ax^2*By*k - 9*Ay^2*By*k +
    4*Ax*Bx*By*k - 3*Bx^2*By*k + 9*Ay*By^2*k - 3*By^3*k + 2*Ax*Ay*Cx*k -
    2*Ay*Bx*Cx*k - 2*Ax*By*Cx*k + 2*Bx*By*Cx*k - 2*Ax^2*Cy*k + 
4*Ax*Bx*Cy*k -
    2*Bx^2*Cy*k)/(3*(Ax^2 + Ay^2 - 2*Ax*Bx + Bx^2 - 2*Ay*By + By^2)^(3/2));

InputForm[ff = Experimental`OptimizeExpression[ee]]

Out[22]//InputForm=
Experimental`OptimizedExpression[Block[{Compile`$8, Compile`$9, 
Compile`$10,
    Compile`$11, Compile`$12, Compile`$13, Compile`$14},
   Compile`$8 = Ax^2; Compile`$9 = Ay^2; Compile`$10 = -2*Ax*Bx;
    Compile`$11 = Bx^2; Compile`$12 = -2*Ay*By; Compile`$13 = By^2;
    Compile`$14 = Compile`$8 + Compile`$9 + Compile`$10 + Compile`$11 +
      Compile`$12 + Compile`$13;
    -(-3*Bx*Compile`$14^(3/2) + 3*Compile`$8*Ay*k + 3*Ay^3*k - 
8*Ax*Ay*Bx*k +
       5*Ay*Compile`$11*k - Compile`$8*By*k - 9*Compile`$9*By*k +
       4*Ax*Bx*By*k - 3*Compile`$11*By*k + 9*Ay*Compile`$13*k - 3*By^3*k +
       2*Ax*Ay*Cx*k - 2*Ay*Bx*Cx*k - 2*Ax*By*Cx*k + 2*Bx*By*Cx*k -
       2*Compile`$8*Cy*k + 4*Ax*Bx*Cy*k - 2*Compile`$11*Cy*k)/
     (3*Compile`$14^(3/2))]]

Daniel Lichtblau
Wolfram Research


  • Prev by Date: F Mathematica crashes
  • Next by Date: Re: A list based table join?
  • Previous by thread: Re: Find minimum number of operations
  • Next by thread: Mathematica crashes