On Nov 26, 2009, at 12:35 AM, Florent Hivert wrote: > Hi Nathann, > >> For Linear Programming, I need to create plenty of symbolic variables >> which I use to represent linear functions.... To do it, I use the >> class InfinitePolynomialRing which lets me create them easily ( and >> it >> is really needed, as my colleagues often have to create Linear >> Programs using 1000~2000 variables. This is not a problem for the >> solvers, but Sage does not like it : >> 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 ? 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 ) ? > > This is indeed a problem. I think I know the cause... Each time a > new variable > is created, the ring itself is somehow changed. Therefore for each new > variable in your sum, there is a big computation which convert the > former sum > to the new ring. Though this could be improved by using a similar > trick than > doubling the size of a list when appending element, I'm not sure > that's what > we want.
I think this makes perfect sense...I'm actually surprised it's not implemented that way already. > In the mean time. I have the following workaround: Just start by > declaring your last variable: If one knows how many variables one needs ahead of time, than what's the advantage of using the InfinitePolynomialRing over a finite one of the right size? - Robert -- 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