From: Stavros M. (Σ. Μ. <mac...@al...> - 2015-04-15 16:13:58
|
Interesting experiment. Even more interesting might be doing arithmetic *between* expressions. That's where I'd expect some speedup from preserving the varlist, at least if the same variables are involved. On Tue, Apr 14, 2015 at 4:44 PM, David Scherfgen <d.s...@go... > wrote: > Hi everyone, > > I have written a small test program and got some interesting results. > > What the program does is generate a number of random expressions > (compositions of integers, a variable x, +, *, ^, log and trigonometric > functions) and measure the time it takes to apply fullratsimp, ratexpand > and radcan to all these expressions. Two variants are compared: Variant 2 > clears ?genvar and ?varlist after each call, while variant 1 doesn't. The > results are also saved for comparison afterwards. > > Now the interesting result, which is exactly what I noticed in my larger > program, too: Variant 2 is about 5 to 10 times FASTER than variant 1. But > only if ratexpand is involved. If it's left out, variant 2 is slightly > slower than variant 1. For some expressions, the results differ, but so far > I found them to be equivalent, differing only in the ordering of terms. > > So, is there something wrong with ratexpand? Is it possible that it > creates a lot of "mess" that slows down everything? > > I attached the program to this mail so that you can try it yourself. > Please note that sometimes an expression might make either ratsimp, > ratexpand or radcan crash or loop forever, so in that case just try again, > and you will get different random expressions. This might also be a good > way to identify more bugs in Maxima. :-) > > Please excuse my non-functional programming style, which is probably > painful for you Lisp programmers. I grew up with C++. > > Best regards, > David > > 2015-04-14 18:52 GMT+02:00 Richard Fateman <fa...@be...>: > >> On 4/14/2015 9:41 AM, Stavros Macrakis (Σταῦρος Μακράκης) wrote: >> >> On the other thread, I suggested using ratsimp, but I'd forgotten that >> ratsimp in fact was having problems after a ratexpand. >> >> Robert, you said: >> >> The problem, as you guessed, is that ratexpand leaves some garbage behind, >> namely one or the other of the special (global) variables VAR and/or >> VARLIST. It's possible that these are handled or mishandled in a similar >> way in the other examples you gave. However, in a sense we are getting >> the intended effect of these specials -- one function is causing an >> effect on another. I'd like to get some guidance from the old timers (the >> really OLD old timers; I'm a n00b, I've been around for hardly more than >> a decade) on the intended use of VAR and VARLIST before I commit this as >> a bug fix. >> >> I took a look at varlist after ratexpand in a block, and it looks >> correct, not "garbage": >> >> >> (((MEXPT) ((MPLUS SIMP) -1 ((MEXPT SIMP) $X -1)) ((RAT) 1 2)) >> >> $X) >> >> >> >> >> But it's interesting that clearing varlist and genvar fixes the >> problem. >> >> The intent of having varlist/genvar as globals is that when the CRE >> package (rat and company) computes with expressions, it first has to >> convert them to have the same variables in the same order. Within a >> calculation, you probably want to use the same variable list to avoid >> constant conversions. So I guess that binding varlist/genvar to nil will at >> worst make computations slower -- see example below. >> >> In more detail: In CRE form, rat(x^2+y,x,y) is a polynomial in x >> whose coefficients are polynomials in y; but rat(x^2+y,y,x) is a >> polynomial in y whose coefficients are polynomials in x. To operate on the >> two of them (add, multiply, etc.), they need to be converted to polynomials >> in the same variables. >> >> RJF, please correct me if I've gotten something wrong here. >> >> -s >> >> >> This is exactly right. There is a cost in emptying the genvar list -- >> new gensyms are constructed for the >> internal names. If you keep on doing this without ever >> garbage-collecting these symbols, you might >> have problems. The initial implementation tried to re-use the gensyms, >> and also tried to make the >> comparison of ordering --- which gensym was more of a "main variable" >> than others by a clever scheme >> invented by William A. Martin. Generate a bunch of symbols. They can >> be sorted by their addresses >> in memory [this is NOT an operation supported by Lisp, but is easily >> done in certain implementations]. >> This becomes genvar. >> Then you can easily test in polynomial arithmetic which variable/gensym >> is "more main" by one machine instruction or so. >> >> This is the explanation for the function name pointergp, (for those >> reading the source code). This idea was >> abandoned quite some time ago for various reasons including portability >> and bugginess when other >> pieces were layered on top of the rational function package. (Like >> algebraic:true, I suspect). >> So pointergp doesn't compare pointers any more. >> >> RJF >> >> >> >> >> >> ------------------------------------------------------------------------------ >> BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT >> Develop your own process in accordance with the BPMN 2 standard >> Learn Process modeling best practices with Bonita BPM through live >> exercises >> http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- >> event?utm_ >> source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF >> _______________________________________________ >> Maxima-discuss mailing list >> Max...@li... >> https://lists.sourceforge.net/lists/listinfo/maxima-discuss >> >> > > > ------------------------------------------------------------------------------ > BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT > Develop your own process in accordance with the BPMN 2 standard > Learn Process modeling best practices with Bonita BPM through live > exercises > http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- > event?utm_ > source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > > |