2009/12/29 Nathann Cohen <nathann.co...@gmail.com>:
> Excellent ! Then
>
> __builtin__.sum([g,h],Graph())
>
> does the job.. Thank you :-)
>
> Nathann
>

This also works with out the __builtin__., in which case sum is
synonymous to sage.misc.functional.symbolic_sum which (at least in
this case) calls the builtin version.

sage: g = graphs.PetersenGraph()
sage: h = graphs.PetersenGraph()
sage: sum([g,h],Graph())
 disjoint_union Petersen graph disjoint_union Petersen graph: Graph on
20 vertices


I wonder if, for a type which implements the call method in such a way
that 0 get coerces automatically to the zero object of the type (with
respect to sum), then it would not be necessary to add the extra
parameter Graph()?  For example, this works:

 sage: sum([g,h],type(g)())
 disjoint_union Petersen graph disjoint_union Petersen graph: Graph on
20 vertices

and there must be other situations where the same would work;  another
possibility is shown by this example:

sage: P,Q = EllipticCurve('389a1').gens()
sage: sum([P,Q])
(4 : 8 : 1)

which works because Sage knows how to coerce the integer 0 to the 0
point on an elliptic curve.

John

-- 
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

Reply via email to