Robert Bradshaw wrote:
> The sage coercion model guarantees that when x.__add__(y) is called  
> (well, technically x._add_ or x._add_c_impl), the argument y is of  
> the same type and parent as x. For example
> 
> sage: R.<x> = ZZ[]
> sage: x+1/2
> x + 1/2
> sage: parent(x)
> Univariate Polynomial Ring in x over Integer Ring
> sage: parent(1/2)
> Rational Field
> sage: parent(x+1/2)
> Univariate Polynomial Ring in x over Rational Field
> 
> In your case, someone could type
> 
> sage: g = CompleteGraph(5)
> sage: g+1  # will call g.__add__(1)
> ???
> 
> which you have to deal with. Typically, just throw an error if it's  
> not a graph. But what about graph + digraph? Digraph + digraph? Etc.  
> Should graph + x be a new graph with a new (unconnected) vertex 'x'?

Thanks for the explanation of the coercion model.  That is a very nice
way to do things.

As for graphs, there isn't a standard definition for the "+" operation
that is agreed upon, even for graphs of the same type (e.g., should it
be disjoint union or union?).  That's why I was asking about custom
infix operators, so I could make a disjoint_union infix operator, which
was clearly different than the union operator, which was clearly
different than whatever else.  Another reason for custom infix operators
was to allow for all sorts of different kinds of products (just look at
the Graph class to see many examples), any of which could be represented
as "graph * graph".

The best I've come up with at this point is, given graphs A,B,C,D,E, the
union is:

A.union(B).union(C).union(D).union(E)

where the union function returns the modified graph each time so I can
keep chaining union function calls.  The union actually modifies the
graph A, so if you want A left alone and a new graph returned, you do:

newgraph=A.copy().union(B).union(C).union(D).union(E)

Comments?  Is there a better way to do things?

With time, I suppose the graph theory community will settle on a
commonly accepted meaning for "graph + graph", but as far as I
understand, that hasn't happened yet.

Thanks,

-Jason



--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@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-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to