Re: [sage-devel] Re: Vector space sum very slow

2012-11-11 Thread Nicolas M. Thiery
On Fri, Nov 09, 2012 at 08:44:15AM -0800, Nils Bruin wrote: > Yes, this is odd. python's sum really does start with adding zero, > even if no initial value is given. This indeed looks like a natural spot for optimization. However it would change the semantic: sage: sum([1,2], 0.0) 3.0

Re: [sage-devel] Re: Vector space sum very slow

2012-11-11 Thread Nicolas M. Thiery
Hi Nils! On Fri, Nov 09, 2012 at 08:44:15AM -0800, Nils Bruin wrote: > On Nov 9, 2:11 am, "Nicolas M. Thiery" > wrote: > > The main point is that writing V.sum(args) gives more information to > > the system than sum(args, self.zero()): this is making a promise that > > all elements in arg

Re: [sage-devel] Re: Vector space sum very slow

2012-11-11 Thread Nicolas M. Thiery
On Sat, Nov 10, 2012 at 11:21:54AM +0100, Florent Hivert wrote: > On Fri, Nov 09, 2012 at 09:53:49AM -0800, John H Palmieri wrote: > > > > > > On Friday, November 9, 2012 4:42:42 AM UTC-8, Nicolas M. Thiéry wrote: > > > > > > More precisely: QQ^3 should be in the category of finite dimensional

Re: [sage-devel] Re: Vector space sum very slow

2012-11-10 Thread Florent Hivert
On Fri, Nov 09, 2012 at 09:41:01AM -0800, Volker Braun wrote: > Thanks, looks good. > > Maybe one could factor out the Enumerated (=canonical enumeration) part? Or > is every parent with __iter__ supposed to be in EnumeratedSets and, > therefore, have a rank() methods etc? The element order is o

Re: [sage-devel] Re: Vector space sum very slow

2012-11-10 Thread Florent Hivert
On Fri, Nov 09, 2012 at 09:53:49AM -0800, John H Palmieri wrote: > > > On Friday, November 9, 2012 4:42:42 AM UTC-8, Nicolas M. Thiéry wrote: > > > > More precisely: QQ^3 should be in the category of finite dimensional > > modules with basis, and a finite dimensional module with basis over an

Re: [sage-devel] Re: Vector space sum very slow

2012-11-09 Thread John H Palmieri
On Friday, November 9, 2012 4:42:42 AM UTC-8, Nicolas M. Thiéry wrote: > > More precisely: QQ^3 should be in the category of finite dimensional > modules with basis, and a finite dimensional module with basis over an > infinite field should be in the category of infinite enumerated sets. > >

Re: [sage-devel] Re: Vector space sum very slow

2012-11-09 Thread Volker Braun
Thanks, looks good. Maybe one could factor out the Enumerated (=canonical enumeration) part? Or is every parent with __iter__ supposed to be in EnumeratedSets and, therefore, have a rank() methods etc? The element order is often just arbitrary... Also, I dislike .list() returning a Python list

[sage-devel] Re: Vector space sum very slow

2012-11-09 Thread Nils Bruin
On Nov 9, 2:11 am, "Nicolas M. Thiery" wrote: > The main point is that writing V.sum(args) gives more information to > the system than sum(args, self.zero()): this is making a promise that > all elements in args are elements of V. In python's call dispatch system, it does not. It says something a

Re: [sage-devel] Re: Vector space sum very slow

2012-11-09 Thread Nicolas M. Thiery
On Fri, Nov 09, 2012 at 05:58:48AM +, Simon King wrote: > On 2012-11-09, Robert Bradshaw wrote: > > __len__ must return a (machine-sized) int, not elements of ZZ let > > alone infinity. > > Sorry, I didn't know that. Then one should probably go the other way, > implement cardinality() for mor

Re: [sage-devel] Re: Vector space sum very slow

2012-11-09 Thread Nicolas M. Thiery
Hi Volker, On Thu, Nov 08, 2012 at 08:02:49AM -0800, Volker Braun wrote: >This occurred to me before, its nice to have iterators/generators but >there should be a mechanism to say that the iterator is over a finite or >infinite set. >Just to avoid doing exhaustive searches

Re: [sage-devel] Re: Vector space sum very slow

2012-11-09 Thread Nicolas M. Thiery
On Thu, Nov 08, 2012 at 10:56:26PM +, Simon King wrote: > why not make __len__ an alias for the cardinality? It can't be a plain alias: __len__ is only allowed to return an `int`, whereas cardinality should return an Integer or +infinity. Cheers, Nicolas -- Nic

Re: [sage-devel] Re: Vector space sum very slow

2012-11-09 Thread Nicolas M. Thiery
On Thu, Nov 08, 2012 at 10:16:36AM -0600, Jason Grout wrote: > On 11/8/12 6:26 AM, Simon King wrote: > >Hi David and John, > > > >On 2012-11-08, David Loeffler wrote: > >>It is *really awful* that V.sum(W) attempts to sum all the elements of > >>W! I don't know what general design decision underli

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Nils Bruin
On Nov 8, 9:20 pm, Robert Bradshaw wrote: > However, I agree with the sentiment that V.sum(W) grossly violates the > principle of least surprise as well as being of dubious merit over the > builtin sum(...). And note that python's builtin sum is in sage shadowed by sum=sage.misc.functional.symb

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Simon King
Hi Robert, On 2012-11-09, Robert Bradshaw wrote: > __len__ must return a (machine-sized) int, not elements of ZZ let > alone infinity. Sorry, I didn't know that. Then one should probably go the other way, implement cardinality() for more parents, and use it in "sum". Cheers, Simon -- You rec

Re: [sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Robert Bradshaw
On Thu, Nov 8, 2012 at 2:56 PM, Simon King wrote: > On 2012-11-08, Nils Bruin wrote: >> On Nov 8, 1:17 pm, Simon King wrote: >>> Hi Volker, >>> >>> On 2012-11-08, Volker Braun wrote: >>> >>> > But then you'd always have to write a lot of >>> > boilerplate to return an iterator. Its much easier

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Simon King
On 2012-11-08, Nils Bruin wrote: > On Nov 8, 1:17 pm, Simon King wrote: >> Hi Volker, >> >> On 2012-11-08, Volker Braun wrote: >> >> > But then you'd always have to write a lot of >> > boilerplate to return an iterator. Its much easier to use yield, but then >> > you can't return any additional

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Nils Bruin
On Nov 8, 1:17 pm, Simon King wrote: > Hi Volker, > > On 2012-11-08, Volker Braun wrote: > > > But then you'd always have to write a lot of > > boilerplate to return an iterator. Its much easier to use yield, but then > > you can't return any additional information about finiteness. > > No? What'

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Simon King
Hi Volker, On 2012-11-08, Volker Braun wrote: > But then you'd always have to write a lot of > boilerplate to return an iterator. Its much easier to use yield, but then > you can't return any additional information about finiteness. No? What's wrong with __len__? Cheers, Simon -- You recei

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread P Purkayastha
On 11/09/2012 12:16 AM, Jason Grout wrote: On 11/8/12 6:26 AM, Simon King wrote: Hi David and John, On 2012-11-08, David Loeffler wrote: It is *really awful* that V.sum(W) attempts to sum all the elements of W! I don't know what general design decision underlies this but I don't like it. Th

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Jason Grout
On 11/8/12 6:26 AM, Simon King wrote: Hi David and John, On 2012-11-08, David Loeffler wrote: It is *really awful* that V.sum(W) attempts to sum all the elements of W! I don't know what general design decision underlies this but I don't like it. That's easy to explain. All additive semigroup

Re: [sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Volker Braun
This occurred to me before, its nice to have iterators/generators but there should be a mechanism to say that the iterator is over a finite or infinite set. Just to avoid doing exhaustive searches over infinite sets. Similar to C++ iterator traits, I guess. Of course if you were to manually impl

Re: [sage-devel] Re: Vector space sum very slow

2012-11-08 Thread John Cremona
I don't think anyone is objecting to being able to add a list of vectors (or any other objects which can be added). But in my example, V.sum(W) is taking the (infinite) list of elements of W and adding them up, which has nothing at all to do with V. Just replace QQ by a finite field in my examp

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Simon King
Hi David and John, On 2012-11-08, David Loeffler wrote: > It is *really awful* that V.sum(W) attempts to sum all the elements of > W! I don't know what general design decision underlies this but I > don't like it. That's easy to explain. All additive semigroups should be able to sum up a list of

Re: [sage-devel] Re: Vector space sum very slow

2012-11-08 Thread John Cremona
Thanks to all. The machine is still up, as I was able to stop the computation with Crtl-C. Now I see it, of course that's what V.sum(W) says that it does, except that it in fact makes no sense, since adding up the (infinitely many) elements of W has nothing to do with V. I don't quite know how I

Re: [sage-devel] Re: Vector space sum very slow

2012-11-08 Thread David Loeffler
I suspect that what John wants is the sum of V and W as subspaces of a common ambient space (not the direct sum embedded in the direct sum of two copies of the ambient space, as Francis suggests). This can be obtained (very quickly) by doing sage: time V + W Vector space of degree 100 and dimensio

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread P Purkayastha
On 11/08/2012 05:36 PM, John Cremona wrote: Either I am doing something wrong or a simple operation which should be fast is in fact very slow, but I do not know why. If V,W are vector spaces over QQ, subspaces of the same ambient space, then V.sum(W) should return their sum, with an echelon bas

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Timo Kluck
Op donderdag 8 november 2012 10:36:51 UTC+1 schreef John Cremona het volgende: > > Either I am doing something wrong or a simple operation which should > be fast is in fact very slow, but I do not know why. > > If V,W are vector spaces over QQ, subspaces of the same ambient > space, then V.sum

[sage-devel] Re: Vector space sum very slow

2012-11-08 Thread Francis Clarke
I think you want sage: V.direct_sum(W) Vector space of degree 200 and dimension 2 over Rational Field Basis matrix: 2 x 200 dense matrix over Rational Field Francis -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To post to this group, send em