Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Effect of Simplify on numeric vs symbolic

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55971] Effect of Simplify on numeric vs symbolic
  • From: carlos at colorado.edu
  • Date: Tue, 12 Apr 2005 05:26:32 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In my previous example of FEM symbolic vs numeric speed all
computations were with numbers.  No variables were involved.
The difference (minutes vs seconds) due largely due to Simplify.

Here is a simpler example that illustrates the point, also taken from
the same course.  LineGaussRuleInfo returns weights and abcissae of 1D
Gauss-Legendre quadrature rules of 1 to 5 points. Argument numer asks
for exact information if False; if True it returns N[information].
All computations involve nunbers only.

Results of calls (at end of post) on a Mac laptop:

numer rule   n  Eval time  Simplify time
True    4   50   0.00 sec     0.00 sec
False   4   50   0.00 sec    78.01 sec  (* Note: FullSimplify needed *)
False   4   50   0.00 sec     0.00 sec  (* found result in cache *)

LineGaussRuleInfo[{rule_,numer_},point_]:= Module[
  {g2={-1,1}/Sqrt[3],w3={5/9,8/9,5/9},
   g3={-Sqrt[3/5],0,Sqrt[3/5]},
   w4={(1/2)-Sqrt[5/6]/6, (1/2)+Sqrt[5/6]/6,
       (1/2)+Sqrt[5/6]/6, (1/2)-Sqrt[5/6]/6},
   g4={-Sqrt[(3+2*Sqrt[6/5])/7],-Sqrt[(3-2*Sqrt[6/5])/7],
        Sqrt[(3-2*Sqrt[6/5])/7], Sqrt[(3+2*Sqrt[6/5])/7]},
   g5={-Sqrt[5+2*Sqrt[10/7]],-Sqrt[5-2*Sqrt[10/7]],0,
        Sqrt[5-2*Sqrt[10/7]], Sqrt[5+2*Sqrt[10/7]]}/3,
   w5={322-13*Sqrt[70],322+13*Sqrt[70],512,
       322+13*Sqrt[70],322-13*Sqrt[70]}/900,
   i=point,p=rule,info={{Null,Null},0}},
  If [p==1, info={0,2}];
  If [p==2, info={g2[[i]],1}];
  If [p==3, info={g3[[i]],w3[[i]]}];
  If [p==4, info={g4[[i]],w4[[i]]}];
  If [p==5, info={g5[[i]],w5[[i]]}];
  If [numer, Return[N[info]], Return[info] ];
];

PerverseExpression[rule_,n_,numer_]:=Module[{xw,tEval,tSymb,x},
  xw=Table[LineGaussRuleInfo[{rule,numer},i],{i,1,rule}];
  {tEval,x}=Timing[Product[(i+2)*xw[[i,1]]^n,{i,1,rule}]];
  {tSymp,x}=Timing[FullSimplify[x]];
  Return[{tEval,tSymp,x}]];

Print[PerverseExpression[4,50,True ]];
Print[PerverseExpression[4,50,False]];
Print[PerverseExpression[4,50,False]]; (* Cached *)


  • Prev by Date: Re: Mathematica graphs in WORD
  • Next by Date: Re: cannot evaluate in HelpBrowser (Win XP)
  • Previous by thread: Re: Re: Numerical Optimization involving equation solving
  • Next by thread: Re: Effect of Simplify on numeric vs symbolic