Hi Nathann! On Nov 26, 8:18 am, Nathann Cohen <nathann.co...@gmail.com> wrote: [...] > To understand my problem, just try this code : > > X.<x> = InfinitePolynomialRing(RR) > sum([x[i] for i in range(200)]) > > Don't you think it is a bit long just to generate a sum ? I have to > admit I do not know how this class is coded, and the slowness may be > required for applications different from mine.. But wouldn't there be > a way to speed this up ?
InfinitePolynomialRing has an underlying *finite* polynomial ring, that changes whenever you need a variable that is not in the finite ring. Therefore, sum([x[199-i] for i in range(200)]) is much faster. Reason: InfinitePolynomialRing has a dense and a sparse implementation, that both have advantages and disadvantages. The default is "dense". It means: If x[199] is called, then a polynomial ring with all variables ranging from x0 to x199 is created. So, if you start the sum with x [199] then the ring can be kept. In the sparse implementation, both summation orders would be slow. The advantage of the sparse implementation is that you can have x[100000] without creating a ring with 100000 generators. > If not, do you know of any way to generate > many symbolic variables ( they do not need to be polynomial, just > linear in my case ) ? Well, you know that InfinitePolynomialRing does not yield symbolic variables. I would consider creating the variable names that you need, and create symbolic variables explicitely: sum([var('x'+str(i)) for i in range(200)]) is fast enough, I guess. Cheers, Simon -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org