Re: error message and speed

*To*: mathgroup at smc.vnet.net*Subject*: [mg8813] Re: [mg8792] error message and speed*From*: David Withoff <withoff>*Date*: Fri, 26 Sep 1997 00:33:38 -0400*Sender*: owner-wri-mathgroup at wolfram.com

> Hi, > > I have two questions about Mma 3.0 and its comparison with > V.2.2.2, and I'd appreciate very much if someone can give me a hint > of what's going on. (operating system: Win95) > > The first question is that when I evaluated the following in > Mma 3.0 with the two lines in the same cell and next to each other, I > got a warning message that doesn't make sense. > > =============================================== > In[1]:= > <<Statistics`ContinuousDistributions`; > ldist = LogNormalDistribution[m,s]; > > LogNormalDistribution::"shdw": > Symbol LogNormalDistribution appears in multiple contexts > {Statistics`ContinuousDistributions`, Global`}; > definitions in context > Statistics`ContinuousDistributions` may shadow or > be shadowed by other definitions. > ================================================= > > As a consequence the statistical properties of LogNormal are not > available, and functions such as PDF[ldist,W] does not return the > density function. This erroneous behavior does not happen when the > two lines are separated into two individual cells. > > WHY DOES THIS HAPPEN? This happens because, in StandardForm (the default) and TraditionalForm input cells, the entire cell is treated as a single input, rather than as two separate inputs. For this input to do what you want, it is necessary to treat <<Statistics`ContinuousDistributions`; as one input, so that the Statistics`ContinuousDistributions` package is loaded, which creates the symbol LogNormalDistribution, and only then to process the input that uses LogNormalDistribution. When these lines are treated as one input, Mathematica processes the entire input, identifying symbols in the input and constructing an expression, and then it evaluates that expression. Evaluating the input loads the Statistics`ContinuousDistributions` package, but by then the symbol LogNormalDistribution has already been created. You can avoid this behavior by either using InputForm input cells (which was the only type of input available in Version 2.2) or by putting these types of inputs in separate cells. > My second question is about the speed. I evaluated the > following > commands in Mma 3.0 and 2.2.2, and found 3.0 is very, very slow in > evaluating the last function involving an integral. Indeed, it took > Mma 3.0 85.14 seconds to finish while took only 2.294 seconds for > V.2.2.2. Since I use this type of functions frequently, I'd like to > know why this happens and how to improve it. > > Thanks in advance! > > H.J. Wang > > ========================== > <<Statistics`ContinuousDistributions`; > > ldist = LogNormalDistribution[m,s]; > > logpdf[W_] = PDF[ldist, W]; > > A1 = (e + b (1+r) - (1-ei) Y2 )/(1+c); > > U[X_,L_] = Log[X] - ua L^ub; > > funEU[e_,b_,r_,c_,i_,rho_,n1_,n2_,ei_,w_,m_,s_,Integrate_]= > Integrate[ U[ W (1-c)+ei Y2,n2] logpdf[W], {W,0,e}]; > ================================= I don't think there is anything that you can do to speed up this particular calculation. Neither Version 2.2 nor Version 3.0 know how to do this integral (I don't see how to do it either), but Version 3.0 tries a lot harder before it gives up, and that takes time. Unlike many other operations, the speed of symbolic integration is usually of less concern than being able to do the integral, so Integrate is programmed to be able to do lots of integrals, sometimes at the cost of being able to do them quickly. Usually it is desirable to arrange your programs so that it isn't necessary to do the same or similar integrals over and over. I didn't observe nearly the speed difference that you reported. When I tried this, Version 3.0 was only about three times slower than Version 2.2. Dave Withoff Wolfram Research