On Dec 11, 2007 8:34 AM, Rishikesh <[EMAIL PROTECTED]> wrote: > I have couple of versions of computing the same function below > f is a polynomial. g is function which returns the same value as f > for given number. g is 10 times faster. Can it be made closer?
Make your function f be a polynomial ** over the real field ** RR and it will be significantly faster than even your function g: {{{id=133| def g(y): return y^24+34*y^12+45*y^3+9*y^18 +34*y^10+ 32*y^21 R.<x> = RR[] f=x^24+34*x^12+45*x^3+9*x^18 +34*x^10+ 32*x^21 }}} {{{id=134| %time for i in range(10000): a=f(x=RR.random_element()) /// CPU time: 0.35 s, Wall time: 0.35 s }}} {{{id=135| %time for i in range(10000): a=g(y=RR.random_element()) /// CPU time: 1.00 s, Wall time: 1.00 s }}} NOTE: Don't use RDF for this, evidently, since it seem to be VERY VERY slow, probably because of something not being rewriting in Cython: {{{ R.<z> = RDF[] h = R(f) }}} {{{id=137| %time for i in range(1000): a=h(x=RDF.random_element()) /// CPU time: 4.58 s, Wall time: 4.58 s }}} > See code below > > Rishi > > {{{id=133| > var('x') > > f=x^24+34*x^12+45*x^3+9*x^18 +34*x^10+ 32*x^21 > > def g(y): > return y^24+34*y^12+45*y^3+9*y^18 +34*y^10+ 32*y^21 > }}} > > {{{id=134| > %time > for i in range(10000): > a=f(x=RR.random_element()) > /// > CPU time: 14.69 s, Wall time: 14.99 s > }}} > > {{{id=135| > %time > for i in range(10000): > a=g(y=RR.random_element()) > /// > CPU time: 1.66 s, Wall time: 1.68 s > > > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~----------~----~----~----~------~----~------~--~---