[sage-support] Re: Why is f.inverse() so slow?
> > Maybe try to alter that via: > f = prod((1 - x^n + O(x^size))^a(n) for n in (1..size)) > Yes, that is the solution. Thank you so much! -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/d4b1447f-4d4e-49e7-9a06-30e9606b3965n%40googlegroups.com.
[sage-support] Re: Why is f.inverse() so slow?
Are you sure it's the inverse function which is slow? Just looking at the command f = prod((1 - x^n)^a(n) for n in (1..size)) + O(x^size) I would guess that first the gigantic product is computed, and only then would the resulting polynomial be truncated by the O(x^size) part. Maybe try to alter that via: f = prod((1 - x^n + O(x^size))^a(n) for n in (1..size)) On Tuesday, November 10, 2020 at 4:07:12 PM UTC-5 Peter Luschny wrote: > Hi all, > > I wanted to implement the Euler Transformation. > https://oeis.org/wiki/Euler_transform > My first attempt was: > > def EulerTransform(size, a): > R. = ZZ[[]] > f = prod((1 - x^n)^a(n) for n in (1..size)) + O(x^size) > return f.inverse().list() > > print(EulerTransform(6, lambda n: factorial(n))) > > Now try this with size = 30. I have no idea how long this > takes because after 3 years I turned the computer off. > > Am I doing something fundamentally wrong, or is f.inverse() > hopelessly slow? > > You can of course implement it differently, but that's not my > question. For those who are interested in the transformation > here the fast variant: > > def EulerTrans(a): > @cached_function > def b(n): > if n == 0: return 1 > s = sum(sum(d*a(d) for d in divisors(j))*b(n-j) for j in (1..n)) > return s//n > return b > > b = EulerTrans(lambda n: factorial(n)) > print([b(n) for n in range(30)]) > > Thanks > > > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/eb26f117-fe6c-4cbd-94c4-5b63f374500en%40googlegroups.com.
[sage-support] Re: why is this so slow?
On Thu, Oct 23, 2008 at 7:56 AM, John H Palmieri [EMAIL PROTECTED] wrote: The setup: sage: var('x y') sage: F = sin(x^2 + y^2) * cos(y) * exp(-0.5*(x^2+y^2)) sage: G=F.derivative(x,x); G -3.00*x^2*e^(-(0.500*(y^2 + x^2)))*cos(y)*sin(y^2 + x^2) - 1.00*e^(-(0.500*(y^2 + x^2)))*cos(y)*sin(y^2 + x^2) - 4.00*x^2*e^(-(0.500*(y^2 + x^2)))*cos(y)*cos(y^2 + x^2) + 2*e^(-(0.500*(y^2 + x^2)))*cos(y)*cos(y^2 + x^2) Then the following takes a long time, between 5 and 10 seconds on my 2.4 GHz Intel iMac. sage: G(1.2, 1.2) 0.193703001636676 (I tried using 'timeit(G(1.2, 1.2))' but got: AttributeError: 'SymbolicArithmetic' object has no attribute 'find'.) Why is it so slow, and are there any tricks I can use to speed it up? Because (the way Sage uses!?) Maxima sucks. For two months now several of us have been working on completely replacing Sage's use of Maxima for symbolic manipulation with reliance on a C++ library called Ginac. This will make its first appearance as a non-default option in Sage-3.2. William I'd like to use these calculations in a class (graphing the degree 2 Taylor approximation to a function in two variables), but if it takes minutes to compute all of the relevant first and second derivatives, it's annoying. (If a student says, Let's see what happens if we compute the Taylor polynomial at a different point, I'd like to be able to oblige them.) John -- 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: why is this so slow?
On Oct 23, 8:05 am, William Stein [EMAIL PROTECTED] wrote: On Thu, Oct 23, 2008 at 7:56 AM, John H Palmieri [EMAIL PROTECTED] wrote: The setup: sage: var('x y') sage: F = sin(x^2 + y^2) * cos(y) * exp(-0.5*(x^2+y^2)) sage: G=F.derivative(x,x); G -3.00*x^2*e^(-(0.500*(y^2 + x^2)))*cos(y)*sin(y^2 + x^2) - 1.00*e^(-(0.500*(y^2 + x^2)))*cos(y)*sin(y^2 + x^2) - 4.00*x^2*e^(-(0.500*(y^2 + x^2)))*cos(y)*cos(y^2 + x^2) + 2*e^(-(0.500*(y^2 + x^2)))*cos(y)*cos(y^2 + x^2) Then the following takes a long time, between 5 and 10 seconds on my 2.4 GHz Intel iMac. sage: G(1.2, 1.2) 0.193703001636676 (I tried using 'timeit(G(1.2, 1.2))' but got: AttributeError: 'SymbolicArithmetic' object has no attribute 'find'.) Why is it so slow, and are there any tricks I can use to speed it up? Because (the way Sage uses!?) Maxima sucks. For two months now several of us have been working on completely replacing Sage's use of Maxima for symbolic manipulation with reliance on a C++ library called Ginac. This will make its first appearance as a non-default option in Sage-3.2. William My impression is that Ginac is in 3.2-alpha0, which I just installed. Can I use it to do these computations? If so, how? John --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: why is this so slow?
On Thu, Oct 23, 2008 at 7:56 AM, John H Palmieri [EMAIL PROTECTED] wrote: The setup: sage: var('x y') sage: F = sin(x^2 + y^2) * cos(y) * exp(-0.5*(x^2+y^2)) sage: G=F.derivative(x,x); G -3.00*x^2*e^(-(0.500*(y^2 + x^2)))*cos(y)*sin(y^2 + x^2) - 1.00*e^(-(0.500*(y^2 + x^2)))*cos(y)*sin(y^2 + x^2) - 4.00*x^2*e^(-(0.500*(y^2 + x^2)))*cos(y)*cos(y^2 + x^2) + 2*e^(-(0.500*(y^2 + x^2)))*cos(y)*cos(y^2 + x^2) Then the following takes a long time, between 5 and 10 seconds on my 2.4 GHz Intel iMac. sage: G(1.2, 1.2) 0.193703001636676 (I tried using 'timeit(G(1.2, 1.2))' but got: AttributeError: 'SymbolicArithmetic' object has no attribute 'find'.) Quick note: You should have done timeit(G(1.2,1.2)) since timeit takes a string as input. My impression is that Ginac is in 3.2-alpha0, which I just installed. Can I use it to do these computations? If so, how? Here's me doing this in sage-3.2.alpha0. Note that not all the same commands and conventions as with Sage's usual symbolic variables are yet supported. However, the good thing is that the final substitution takes 1.81 ms on sage.math instead of 10 seconds. [EMAIL PROTECTED]:~/build/sage-3.2.alpha0$ ./sage -- | SAGE Version 3.2.alpha0, Release Date: 2008-10-20 | | Type notebook() for the GUI, and license() for information.| -- sage: var('x,y',ns=1)#note the ns=1, which will go away in the future... (x, y) sage: F = sin(x^2 + y^2) * cos(y) * exp(-0.5*(x^2+y^2)) sage: G=F.diff(x,1).diff(x,1); G -exp(-(0.500)*x^2 - (0.500)*y^2)*sin(x^2 + y^2)*cos(y) + 2*exp(-(0.500)*x^2 - (0.500)*y^2)*cos(x^2 + y^2)*cos(y) - (3.00)*exp(-(0.500)*x^2 - (0.500)*y^2)*sin(x^2 + y^2)*cos(y)*x^2 - (4.00)*exp(-(0.500)*x^2 - (0.500)*y^2)*cos(x^2 + y^2)*cos(y)*x^2 sage: G.subs(x=1.2).subs(y=1.2) 0.193703001636676 sage: timeit('G.subs(x=1.2).subs(y=1.2)') 125 loops, best of 3: 1.81 ms per loop William --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: why is this so slow?
On Oct 23, 8:56 am, William Stein [EMAIL PROTECTED] wrote: Here's me doing this in sage-3.2.alpha0. Note that not all the same commands and conventions as with Sage's usual symbolic variables are yet supported. However, the good thing is that the final substitution takes 1.81 ms on sage.math instead of 10 seconds. [EMAIL PROTECTED]:~/build/sage-3.2.alpha0$ ./sage -- | SAGE Version 3.2.alpha0, Release Date: 2008-10-20 | | Type notebook() for the GUI, and license() for information. | -- sage: var('x,y',ns=1) #note the ns=1, which will go away in the future... (x, y) sage: F = sin(x^2 + y^2) * cos(y) * exp(-0.5*(x^2+y^2)) sage: G=F.diff(x,1).diff(x,1); G or G=F.diff(x,2) -exp(-(0.500)*x^2 - (0.500)*y^2)*sin(x^2 + y^2)*cos(y) + 2*exp(-(0.500)*x^2 - (0.500)*y^2)*cos(x^2 + y^2)*cos(y) - (3.00)*exp(-(0.500)*x^2 - (0.500)*y^2)*sin(x^2 + y^2)*cos(y)*x^2 - (4.00)*exp(-(0.500)*x^2 - (0.500)*y^2)*cos(x^2 + y^2)*cos(y)*x^2 sage: G.subs(x=1.2).subs(y=1.2) 0.193703001636676 sage: timeit('G.subs(x=1.2).subs(y=1.2)') 125 loops, best of 3: 1.81 ms per loop William Great! That's much better. John --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: why is this so slow?
Okay, using what William said, I produced this an 'interact' example, showing the linear and quadratic Taylor approximations to a certain function in two variables. Right now it's using a combo of the old and new symbolic stuff, because that seems to be the best way to get things done... var('x y') F = sin(x^2 + y^2) * cos(y) * exp(-0.5*(x^2+y^2)) plotF = plot3d(F, (x, 0.4, 2), (y, 0.4, 2), adaptive=True, color='blue') var('xx yy', ns=1) G = sin(xx^2 + yy^2) * cos(yy) * exp(-0.5*(xx^2+yy^2)) @interact def _(x0=(0.8,1.6), y0=(0.8, 1.6), show_plane=(Show linear approximation, False), show_quad=(Show quadratic approximation, False)): F0 = float(G.subs(xx=x0).subs(yy=y0)) F1 = float(G.diff(xx).subs(xx=x0).subs(yy=y0)) F2 = float(G.diff(yy).subs(xx=x0).subs(yy=y0)) F11 = float(G.diff(xx, 2).subs(xx=x0).subs(yy=y0)) F12 = float(G.diff(xx).diff(yy).subs(xx=x0).subs(yy=y0)) F22 = float(G.diff(yy, 2).subs(xx=x0).subs(yy=y0)) P = (x0, y0, F0) dot = point3d(P, size=15, color='red') plane = F0 + F1 * (x-x0) + F2 * (y-y0) quad = plane + 1/2 * (F11 * (x-x0)^2 + 2 * F12 * (x-x0) * (y-y0) + F22 * (y-y0)^2) plane_string = 'z = %.2f + %.2f(x-x_0)+%.2f(y-y_0)'%(F0, F1, F2) quad_string = plane_string + '+ \\frac{1}{2} \\left((%.2f) (x- x_0)^2 + 2(%.2f) (x-x_0)(y-y_0) + (%.2f)(y-y_0)^2\\right)'%(F11, F12, F22) plot1 = plot3d(plane, (x, 0.4, 2), (y, 0.4, 2), color='green') plot2 = plot3d(quad, (x, max(0.4, x0-0.5), min(2.0, x0+0.5)), (y, max(0.4, y0-0.5), min(2.0, y0+0.5)), color='purple') plot = dot + plotF if show_plane: plot += plot1 if show_quad: plot += plot2 html('$F(x,y) = e^{-(x^2+y^2)/2} \\cos(y) \\sin(x^2+y^2)$') if show_plane: html('tangent plane: $%s$'%plane_string) if show_quad: html('quad approx: $%s$'%quad_string) show(plot) --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---