Ticket #13699: trac_13699.patch

File trac_13699.patch, 4.6 KB (added by ncohen, 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  
    1360613606        Returns the lexicographic product of self and other.
    1360713607
    1360813608        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`.
    1361213613
    1361313614        EXAMPLES::
    1361413615
     
    1367113672        Returns the strong product of self and other.
    1367213673
    1367313674        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.
    1368013684
    1368113685        EXAMPLES::
    1368213686
     
    1369613700
    1369713701        TESTS:
    1369813702
    13699         Strong product of graphs::
     13703        Strong product of graphs is commutative::
    1370013704
    1370113705            sage: G = Graph([(0,1), (1,2)])
    1370213706            sage: H = Graph([('a','b')])
    1370313707            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'))]
    1370613708            sage: T.is_isomorphic( H.strong_product(G) )
    1370713709            True
    1370813710
    13709         Strong product of digraphs::
     13711        Strong product of digraphs is commutative::
    1371013712
    1371113713            sage: I = DiGraph([(0,1), (1,2)])
    1371213714            sage: J = DiGraph([('a','b')])
    1371313715            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'))]
    1371613716            sage: T.is_isomorphic( J.strong_product(I) )
    1371713717            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
    1371813729        """
    1371913730        if self._directed and other._directed:
    1372013731            from sage.graphs.all import DiGraph
     
    1373113742                G.add_edge((u,v), (w,v))
    1373213743            for v,x in other.edges(labels=None):
    1373313744                G.add_edge((u,v), (w,x))
     13745                if not self._directed:
     13746                    G.add_edge((w,v), (u,x))
    1373413747        for v,x in other.edges(labels=None):
    1373513748            for u in self:
    1373613749                G.add_edge((u,v), (u,x))
     
    1374113754        Returns the disjunctive product of self and other.
    1374213755
    1374313756        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`.
    1374713761
    1374813762        EXAMPLES::
    1374913763