Ticket #13809: 13809.patch

File 13809.patch, 3.0 KB (added by jdemeyer, 7 years ago)
  • sage/graphs/generators/families.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1356732030 -3600
    # Node ID ac63e3e49a67771c4295a891ef0a6bc5c15151bd
    # Parent  36fba6c1a13fc3695bb19fb25ea69222f024a5b0
    A constructor for folded cube graphs
    
    diff --git a/sage/graphs/generators/families.py b/sage/graphs/generators/families.py
    a b  
    349349
    350350    return g
    351351
    352 
    353 ###########################################################################
    354 #   Families of Graphs
    355 ###########################################################################
    356 
    357352def BalancedTree(r, h):
    358353    r"""
    359354    Returns the perfectly balanced tree of height `h \geq 1`,
     
    713708
    714709    return r
    715710
     711def FoldedCubeGraph(n):
     712    r"""
     713    Returns the folded cube graph of order `2^{n-1}`.
     714
     715    The folded cube graph on `2^{n-1}` vertices can be obtained from a cube
     716    graph on `2^n` vertices by merging together opposed
     717    vertices. Alternatively, it can be obtained from a cube graph on
     718    `2^{n-1}` vertices by adding an edge between opposed vertices. This
     719    second construction is the one produced by this method.
     720
     721    For more information on folded cube graphs, see the corresponding
     722    :wikipedia:`Wikipedia page <Folded_cube_graph>`.
     723
     724    EXAMPLES:
     725
     726    The folded cube graph of order five is the Clebsch graph::
     727
     728        sage: fc = graphs.FoldedCubeGraph(5)
     729        sage: clebsch = graphs.ClebschGraph()
     730        sage: fc.is_isomorphic(clebsch)
     731        True
     732    """
     733
     734    if n < 1:
     735        raise ValueError("The value of n must be at least 2")
     736
     737    g = CubeGraph(n-1)
     738    g.name("Folded Cube Graph")
     739
     740    # Complementing the binary word
     741    def complement(x):
     742        x = x.replace('0','a')
     743        x = x.replace('1','0')
     744        x = x.replace('a','1')
     745        return x
     746
     747    for x in g:
     748        if x[0] == '0':
     749            g.add_edge(x,complement(x))
     750
     751    return g
     752
     753
    716754def FriendshipGraph(n):
    717755    r"""
    718756    Returns the friendship graph `F_n`.
  • sage/graphs/graph_generators.py

    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    145145     "CirculantGraph",
    146146     "CubeGraph",
    147147     "FibonacciTree",
     148     "FoldedCubeGraph",
    148149     "FriendshipGraph",
    149150     "FuzzyBallGraph",
    150151     "GeneralizedPetersenGraph",
     
    911912    BubbleSortGraph        = staticmethod(sage.graphs.generators.families.BubbleSortGraph)
    912913    CirculantGraph         = staticmethod(sage.graphs.generators.families.CirculantGraph)
    913914    CubeGraph              = staticmethod(sage.graphs.generators.families.CubeGraph)
     915    FoldedCubeGraph        = staticmethod(sage.graphs.generators.families.FoldedCubeGraph)
    914916    DorogovtsevGoltsevMendesGraph = staticmethod(sage.graphs.generators.families.DorogovtsevGoltsevMendesGraph)
    915917    FriendshipGraph        = staticmethod(sage.graphs.generators.families.FriendshipGraph)
    916918    FuzzyBallGraph         = staticmethod(sage.graphs.generators.families.FuzzyBallGraph)