Ticket #13699: trac_13699.patch
File trac_13699.patch, 4.6 KB (added by , 8 years ago) 


sage/graphs/generic_graph.py
# HG changeset patch # User Nathann Cohen <nathann.cohen@gmail.com> # Date 1352598337 3600 # Node ID b3ae6f0441dd0c927aeaab04d2d25e65bbbc09f1 # Parent e2adf5f80f790f6b019f8ff6a879228c5fa46fc4 Another bug in graph products.... diff git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
a b 13606 13606 Returns the lexicographic product of self and other. 13607 13607 13608 13608 The lexicographic product of `G` and `H` is the graph `L` with vertex 13609 set `V(L)` equal to the Cartesian product of the vertices `V(G)` and 13610 `V(H)`, and `((u,v), (w,x))` is an edge iff  `(u, w)` is an edge of 13611 self, or  `u = w` and `(v, x)` is an edge of other. 13609 set `V(L)=V(G)\times V(H)`, and `((u,v), (w,x))` is an edge iff : 13610 13611 * `(u, w)` is an edge of `G`, or 13612 * `u = w` and `(v, x)` is an edge of `H`. 13612 13613 13613 13614 EXAMPLES:: 13614 13615 … … 13671 13672 Returns the strong product of self and other. 13672 13673 13673 13674 The strong product of `G` and `H` is the graph `L` with vertex set 13674 `V(L)` equal to the Cartesian product of the vertices `V(G)` and `V(H)`, 13675 and `((u,v), (w,x))` is an edge iff either  `(u, w)` is an edge of self 13676 and `v = x`, or  `(v, x)` is an edge of other and `u = w`, or  `(u, 13677 w)` is an edge of self and `(v, x)` is an edge of other. In other words, 13678 the edges of the strong product is the union of the edges of the tensor 13679 and Cartesian products. 13675 `V(L)=V(G)\times V(H)`, and `((u,v), (w,x))` is an edge of `L` iff 13676 either : 13677 13678 * `(u, w)` is an edge of `G` and `v = x`, or 13679 * `(v, x)` is an edge of `H` and `u = w`, or 13680 * `(u, w)` is an edge of `G` and `(v, x)` is an edge of `H`. 13681 13682 In other words, the edges of the strong product is the union of the 13683 edges of the tensor and Cartesian products. 13680 13684 13681 13685 EXAMPLES:: 13682 13686 … … 13696 13700 13697 13701 TESTS: 13698 13702 13699 Strong product of graphs ::13703 Strong product of graphs is commutative:: 13700 13704 13701 13705 sage: G = Graph([(0,1), (1,2)]) 13702 13706 sage: H = Graph([('a','b')]) 13703 13707 sage: T = G.strong_product(H) 13704 sage: T.edges(labels=None)13705 [((0, 'a'), (0, 'b')), ((0, 'a'), (1, 'a')), ((0, 'a'), (1, 'b')), ((0, 'b'), (1, 'b')), ((1, 'a'), (1, 'b')), ((1, 'a'), (2, 'a')), ((1, 'a'), (2, 'b')), ((1, 'b'), (2, 'b')), ((2, 'a'), (2, 'b'))]13706 13708 sage: T.is_isomorphic( H.strong_product(G) ) 13707 13709 True 13708 13710 13709 Strong product of digraphs ::13711 Strong product of digraphs is commutative:: 13710 13712 13711 13713 sage: I = DiGraph([(0,1), (1,2)]) 13712 13714 sage: J = DiGraph([('a','b')]) 13713 13715 sage: T = I.strong_product(J) 13714 sage: T.edges(labels=None)13715 [((0, 'a'), (0, 'b')), ((0, 'a'), (1, 'a')), ((0, 'a'), (1, 'b')), ((0, 'b'), (1, 'b')), ((1, 'a'), (1, 'b')), ((1, 'a'), (2, 'a')), ((1, 'a'), (2, 'b')), ((1, 'b'), (2, 'b')), ((2, 'a'), (2, 'b'))]13716 13716 sage: T.is_isomorphic( J.strong_product(I) ) 13717 13717 True 13718 13719 Counting the edges (see :trac:`13699`):: 13720 13721 sage: g = graphs.RandomGNP(5,.5) 13722 sage: gn,gm = g.order(), g.size() 13723 sage: h = graphs.RandomGNP(5,.5) 13724 sage: hn,hm = h.order(), h.size() 13725 sage: product_size = g.strong_product(h).size() 13726 sage: expected = gm*hn + hm*gn + 2*gm*hm 13727 sage: if product_size != expected: 13728 ... print "Something is really wrong here...", product_size, "!=", expected 13718 13729 """ 13719 13730 if self._directed and other._directed: 13720 13731 from sage.graphs.all import DiGraph … … 13731 13742 G.add_edge((u,v), (w,v)) 13732 13743 for v,x in other.edges(labels=None): 13733 13744 G.add_edge((u,v), (w,x)) 13745 if not self._directed: 13746 G.add_edge((w,v), (u,x)) 13734 13747 for v,x in other.edges(labels=None): 13735 13748 for u in self: 13736 13749 G.add_edge((u,v), (u,x)) … … 13741 13754 Returns the disjunctive product of self and other. 13742 13755 13743 13756 The disjunctive product of `G` and `H` is the graph `L` with vertex set 13744 `V(L)` equal to the Cartesian product of the vertices `V(G)` and `V(H)`, 13745 and `((u,v), (w,x))` is an edge iff either  `(u, w)` is an edge of 13746 self, or  `(v, x)` is an edge of other. 13757 `V(L)=V(G)\times V(H)`, and `((u,v), (w,x))` is an edge iff either : 13758 13759 * `(u, w)` is an edge of `G`, or 13760 * `(v, x)` is an edge of `H`. 13747 13761 13748 13762 EXAMPLES:: 13749 13763