#8395: degree() reports the degree of a self-loop vertex as contributing 1 to
total degree
----------------------------+-----------------------------------------------
Reporter: mvngu | Owner: rlm
Type: defect | Status: new
Priority: minor | Milestone: sage-4.4
Component: graph theory | Keywords:
Author: | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
----------------------------+-----------------------------------------------
Changes (by mvngu):
* cc: jason, ncohen (added)
Old description:
> From [http://groups.google.com/group/sage-
> devel/browse_thread/thread/42110dbb598d11d2 sage-devel]:
> {{{
> [mv...@sage mvngu]$ sage
> ----------------------------------------------------------------------
> | Sage Version 4.3.3, Release Date: 2010-02-21 |
> | Type notebook() for the GUI, and license() for information. |
> ----------------------------------------------------------------------
> sage: G = Graph({1:[1]}); G
> Looped graph on 1 vertex
> sage: sum(G.degree())
> 1
> sage: G.size()
> 0
> sage: G = Graph({1:[1]}, loops=True); G
> Looped graph on 1 vertex
> sage: sum(G.degree())
> 1
> sage: G.size()
> 0
> sage: G = Graph({1:[1]}, loops=True, multiedges=True); G
> Looped multi-graph on 1 vertex
> sage: sum(G.degree())
> 1
> sage: G.size()
> 0
>
> The size of G is 1 because there is one edge, i.e. the single
> self-loop. As shown by the above session, Sage reports the size of G
> as 0. I believe this is a bug.
> }}}
New description:
From [http://groups.google.com/group/sage-
devel/browse_thread/thread/42110dbb598d11d2 sage-devel]:
{{{
[mv...@sage mvngu]$ sage
----------------------------------------------------------------------
| Sage Version 4.3.3, Release Date: 2010-02-21 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: G = Graph({1:[1]}); G
Looped graph on 1 vertex
sage: sum(G.degree())
1
sage: G.size()
0
sage: G = Graph({1:[1]}, loops=True); G
Looped graph on 1 vertex
sage: sum(G.degree())
1
sage: G.size()
0
sage: G = Graph({1:[1]}, loops=True, multiedges=True); G
Looped multi-graph on 1 vertex
sage: sum(G.degree())
1
sage: G.size()
0
The size of G is 1 because there is one edge, i.e. the single
self-loop. As shown by the above session, Sage reports the size of G
as 0. I believe this is a bug.
}}}
See also the discussion at this [http://groups.google.com/group/sage-
devel/browse_thread/thread/63b3c775da0421a8 other sage-devel] thread. This
also happens in the C graph backends for sparse and dense graphs:
{{{
[mv...@sage ~]$ sage
----------------------------------------------------------------------
| Sage Version 4.3.5, Release Date: 2010-03-28 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: from sage.graphs.base.sparse_graph import SparseGraphBackend
sage: S = SparseGraphBackend(7)
sage: S.loops(True)
sage: S.add_edge(1, 1, None, directed=False)
sage: S.has_edge(1, 1, None)
True
sage: list(S.iterator_edges(range(7), None))
[(1, 1)]
sage: S.degree(1, directed=False)
1
sage:
sage: reset()
sage:
sage:
sage: from sage.graphs.base.dense_graph import DenseGraphBackend
sage: D = DenseGraphBackend(78)
sage: D = DenseGraphBackend(7)
sage: D.loops(True)
sage: D.add_edge(1, 1, None, directed=False)
sage: D.has_edge(1, 1, None)
True
sage: list(D.iterator_edges(range(7), None))
[(1, 1)]
sage: D.degree(1, directed=False)
1
}}}
Notice that `degree()` reports the degree of a self-loop as one, when in
fact it should be 2. That's because both `SparseGraphBackend` and
`DenseGraphBackend` inherit the same `degree()` function from
`CGraphBackend`. I think the implementation of `degree()` in
`CGraphBackend` needs to take into account the existence of self-loops.
--
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8395#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.