Version 20 (modified by mvngu, 3 years ago) (diff)

functions for displaying graphs

Here is a list of graph operations included in the Mathematica  Combinatorica package , but not implemented in the Sage graph classes. This comparison was done using Mathematica version 7.

Attached is a spreadsheet listing the Sage graph library functions and the equivalent functions in Combinatorica. I've also put a few notes in about the implementation differences and other notes suggesting changes to Sage functions.

In the following list, I tried to make the functions link to the official documentation at the Wolfram website. I hope it all worked right.

## Construction and representations

### Graphs and components

• Edges
• Sage ---
• Mathematica ---  Edges[g] gives the list of edges in g.
• Graph
• Sage ---
• Mathematica ---  Graph[e, v, opts] represents a graph object where e is the list of edges annotated with graphics options, v is a list of vertices annotated with graphics options, and opts is a set of global graph options.
• Number of edges
• Sage ---
• Mathematica ---  M[g] gives the number of edges in the graph g.
• Number of vertices
• Sage ---
• Mathematica ---  V[g] gives the order or number of vertices of the graph g.
• Vertices
• Sage ---
• Mathematica ---  Vertices[g] gives the coordinates of each vertex of graph g embedded in a plane.

### Graph representations

• Sage ---
• Mathematica ---  FromAdjacencyLists[l] constructs an edge list representation for a graph from the given adjacency lists l, using a circular embedding.
• Sage ---
• Mathematica ---  FromAdjacencyMatrix[m] constructs a graph from a given adjacency matrix m, using a circular embedding.
• From ordered pairs
• Sage ---
• Mathematica ---  FromOrderedPairs[l] constructs an edge list representation from a list of ordered pairs l, using a circular embedding.

• From unordered pairs
• Sage ---
• Mathematica ---  FromUnorderedPairs[l] constructs an edge list representation from a list of unordered pairs l, using a circular embedding.
• Incidence matrix
• Sage ---
• Mathematica ---  IncidenceMatrix[g] returns the (0,1)-matrix of graph g, which has a row for each vertex and a column for each edge and (v,e)=1 if and only if vertex v is incident upon edge e. For a directed graph, (v,e)=1 if edge e is outgoing from v.
• Sage ---
• Mathematica ---  ToAdjacencyLists[g] constructs an adjacency list representation for graph g. It allows an option called Type that takes on values All or Simple. Type -> All is the default setting of the option, and this permits self-loops and multiple edges to be reported in the adjacency lists. Type -> Simple deletes self-loops and multiple edges from the constructed adjacency lists.  ToAdjacencyLists[g,  EdgeWeight] returns an adjacency list representation along with edge weights.
• Sage ---
• Mathematica ---  ToAdjacencyMatrix[g] constructs an adjacency matrix representation for graph g.
• To ordered pairs
• Sage ---
• Mathematica ---  ToOrderedPairs[g] constructs a list of ordered pairs representing the edges of the graph g. If g is undirected each edge is interpreted as two ordered pairs. An option called Type that takes on values Simple or All can be used to affect the constructed representation. Type -> Simple forces the removal of multiple edges and self-loops. Type -> All keeps all information and is the default option.
• To unordered pairs
• Sage ---
• Mathematica ---  ToUnorderedPairs[g] constructs a list of unordered pairs representing the edges of graph g. Each edge, directed or undirected, results in a pair in which the smaller vertex appears first. An option called Type that takes on values All or Simple can be used, and All is the default value. Type -> Simple ignores multiple edges and self-loops in g.

### Displaying graphs

• Animate graph
• Sage ---
• Mathematica ---  AnimateGraph[g, l] displays graph g with each element in the list l successively highlighted. Here l is a list containing vertices and edges of g. An optional flag, which takes on the values All and One, can be used to inform the function about whether objects highlighted earlier will continue to be highlighted or not. The default value of flag is All. All the options allowed by the function Highlight are permitted by  AnimateGraph, as well. See the usage message of Highlight for more details.
• Change edges
• Sage ---
• Mathematica ---  ChangeEdges[g, e] replaces the edges of graph g with the edges in e. e can have the form {{s1, t1}, {s2, t2}, ...} or the form { {{s1, t1}, gr1}, {{s2, t2}, gr2}, ...}, where {s1, t1}, {s2, t2}, ... are endpoints of edges and gr1, gr2, ... are graphics information associated with edges.
• Change vertices
• Sage ---
• Mathematica ---  ChangeVertices[g, v] replaces the vertices of graph g with the vertices in the given list v. v can have the form {{x1, y1}, {x2, y2}, ...} or the form {{{x1, y1}, gr1}, {{x2, y2}, gr2}, ...}, where {x1, y1}, {x2, y2}, ... are coordinates of points and gr1, gr2, ... are graphics information associated with vertices.
• Circular embedding
• Edge color
• Sage ---
• Mathematica ---  EdgeColor is an option that allows the user to associate colors with edges. Black is the default color. EdgeColor? can be set as part of the graph data structure or in ShowGraph?.
• Edge direction
• Sage ---
• Mathematica ---  EdgeDirection is an option that takes on values True or False allowing the user to specify whether the graph is directed or not. EdgeDirection? can be set as part of the graph data structure or in ShowGraph?.
• Edge label
• Sage ---
• Mathematica ---  EdgeLabel is an option that can take on values True or False, allowing the user to associate labels to edges. By default, there are no edge labels. The EdgeLabel? option can be set as part of the graph data structure or in ShowGraph?.
• Edge label color
• Sage ---
• Mathematica ---  EdgeLabelColor is an option that allows the user to associate different colors to edge labels. Black is the default color. EdgeLabelColor? can be set as part of the graph data structure or in ShowGraph?.
• Edge label position
• Sage ---
• Mathematica ---  EdgeLabelPosition is an option that allows the user to place an edge label in a certain position relative to the midpoint of the edge. LowerLeft? is the default value of this option. EdgeLabelPosition? can be set as part of the graph data structure or in ShowGraph?.
• Edge style
• Sage ---
• Mathematica ---  EdgeStyle is an option that allows the user to associate different sizes and shapes to edges. A line segment is the default edge. EdgeStyle? can be set as part of the graph data structure or in ShowGraph?.
• Edge weight
• Sage ---
• Mathematica ---  EdgeWeight is an option that allows the user to associate weights with edges. 1 is the default weight.  EdgeWeight can be set as part of the graph data structure.
• Graph options
• Sage ---
• Mathematica ---  GraphOptions[g] returns the display options associated with g.
• Highlighted edge colors
• Sage ---
• Mathematica ---  HighlightedEdgeColors is an option to Highlight that determines which colors are used for the highlighted edges.
• Highlighted edge style
• Sage ---
• Mathematica ---  HighlightedEdgeStyle is an option to Highlight that determines how the highlighted edges are drawn.
• Highlighted vertex colors
• Sage ---
• Mathematica ---  HighlightedVertexColors is an option to Highlight that determines which colors are used for the highlighted vertices.
• Highlighted vertex style
• Sage ---
• Mathematica ---  HighlightedVertexStyle is an option to Highlight that determines how the highlighted vertices are drawn.
• Ranked embedding
• Sage ---
• Mathematica ---  RankedEmbedding[l] takes a set partition l of vertices {1, 2,..., n} and returns an embedding of the vertices in the plane such that the vertices in each block occur on a vertical line with block 1 vertices on the leftmost line, block 2 vertices in the next line, and so on.  RankedEmbedding[g, l] takes a graph g and a set partition l of the vertices of g and returns the graph g with vertices embedded according to  RankedEmbedding[l].  RankedEmbedding[g, s] takes a graph g and a set s of vertices of g and returns a ranked embedding of g in which vertices in s are in block 1, vertices at distance 1 from any vertex in block 1 are in block 2, and so on.
• Sage ---
• Mathematica ---  RadialEmbedding[g, v] constructs a radial embedding of the graph g in which vertices are placed on concentric circles around v depending on their distance from v.  RadialEmbedding[g] constructs a radial embedding of graph g, radiating from the center of the graph.
• Rank graph
• Sage ---
• Mathematica ---  RankGraph[g, l] partitions the vertices into classes based on the shortest geodesic distance to a member of list l.
• Rooted embedding
• Sage ---
• Mathematica ---  RootedEmbedding[g, v] constructs a rooted embedding of graph g with vertex v as the root.  RootedEmbedding[g] constructs a rooted embedding with a center of g as the root.
• Rotate vertices
• Sage ---
• Mathematica ---  RotateVertices[v, theta] rotates each vertex position in list v by theta radians about the origin (0, 0).  RotateVertices[g, theta] rotates the embedding of the graph g by theta radians about the origin (0, 0).
• Set edge labels
• Sage ---
• Mathematica ---  SetEdgeLabels[g, l] assigns the labels in l to edges of g.
• Set edge weights
• Sage ---
• Mathematica ---  SetEdgeWeights[g] assigns random real weights in the range [0,1] to edges in g.
• Set graph options
• Sage ---
• Mathematica ---  SetGraphOptions[g, opts] returns g with the options opts set.  SetGraphOptions[g, {v1, v2, ..., vopts}, gopts] returns the graph with the options vopts set for vertices v1, v2, ... and the options gopts set for the graph g.  SetGraphOptions[g, {e1, e2,..., eopts}, gopts], with edges e1, e2,..., works similarly.  SetGraphOptions[g, {{elements1, opts1}, {elements2, opts2},...}, opts] returns g with the options opts1 set for the elements in the sequence elements1, the options opts2 set for the elements in the sequence elements2, and so on. Here, elements can be a sequence of edges or a sequence of vertices. A tag that takes on values One or All can also be passed in as an argument before any options. The default value of the tag is All and it is useful if the graph has multiple edges. It informs the function about whether all edges that connect a pair of vertices are to be affected or only one edge is affected.
• Set vertex labels
• Sage ---
• Mathematica ---  SetVertexLabels[g, l] assigns the labels in l to vertices of g. If l is shorter than the number of vertices in g, then labels get assigned cyclically. If l is longer than the number of vertices in g, then the extra labels are ignored."
• Shake graph
• Sage ---
• Mathematica ---  ShakeGraph[g, d] performs a random perturbation of the vertices of graph g, with each vertex moving, at most, a distance d from its original position.
• Show graph
• Sage ---
• Mathematica ---  ShowGraph[g] displays the graph g.
• Show graph array
• Sage ---
• Mathematica ---  ShowGraphArray[{g1, g2, ...}] displays a row of graphs.
• Show labeled graph
• Sage ---
• Mathematica ---  ShowLabeledGraph[g] displays graph g according to its embedding, with each vertex labeled with its vertex number.  ShowLabeledGraph[g, l] uses the ith element of list l as the label for vertex i.
• Spring embedding
• Sage ---
• Mathematica ---  SpringEmbedding[g] beautifies the embedding of graph g by modeling the embedding as a system of springs.  SpringEmbedding[g, step, increment] can be used to refine the algorithm. The value of step tells the function for how many iterations to run the algorithm. The value of increment tells the function the distance to move the vertices at each step. The default values are 10 and 0.15 for step and increment, respectively.
• Translate vertices
• Sage ---
• Mathematica ---  TranslateVertices[v, {x, y}] adds the vector {x, y} to the vertex embedding location of each vertex in list v.  TranslateVertices[g, {x, y}] translates the embedding of the graph g by the vector {x, y}.
• Vertex color
• Sage ---
• Mathematica ---  VertexColor is an option that allows the user to associate colors with vertices.
• Vertex label
• Sage ---
• Mathematica ---  VertexLabel is an option that can take on values True or False, allowing the user to set and display vertex labels.
• Vertex label color
• Sage ---
• Mathematica ---  VertexLabelColor is an option that allows the user to associate different colors to vertex labels.
• Vertex label position
• Sage ---
• Mathematica ---  VertexLabelPosition is an option that allows the user to place a vertex label in a certain position relative to the vertex.
• Vertex number
• Sage ---
• Mathematica ---  VertexNumber is an option that can take on values True or False. This can be used in ShowGraph? to display or suppress vertex numbers.
• Vertex number color
• Vertex number position
• Sage ---
• Mathematica ---  VertexNumberPosition is an option that can be used in ShowGraph? to display a vertex number in a certain position relative to the vertex.
• Vertex style
• Sage ---
• Mathematica ---  VertexStyle is an option that allows the user to associate different sizes and shapes to vertices.
• Vertex weight
• Sage ---
• Mathematica ---  VertexWeight is an option that allows the user to associate weights with vertices. 0 is the default weight.  VertexWeight can be set as part of the graph data structure.
• Zoom
• Sage ---
• Mathematica ---  Zoom[{i, j, k, ...}] is a value that the  PlotRange option can take on in  ShowGraph. Setting  PlotRange to this value zooms the display to contain the specified subset of vertices, i, j, k, ....

## Graph algorithms

### Shortest paths

• Bellman-Ford algorithm
• Sage --- #8714
• Mathematica ---  BellmanFord[g, v] gives a shortest-path spanning tree and associated distances from vertex v of graph g. The shortest-path spanning tree is given by a list in which element i is the predecessor of vertex i in the shortest-path spanning tree.  BellmanFord works correctly even when the edge weights are negative, provided there are no negative cycles.
• Diameter
• Sage ---
• Mathematica ---  Diameter[g] gives the diameter of graph g, the maximum length, among all pairs of vertices in g, of a shortest path between each pair.
• Dijkstra's algorithm
• Sage --- bidirectional_dijkstra
• Mathematica ---  Dijkstra[g, v] gives a shortest-path spanning tree and associated distances from vertex v of graph g. The shortest-path spanning tree is given by a list in which element i is the predecessor of vertex i in the shortest-path spanning tree. Dijkstra does not work correctly when the edge weights are negative;  BellmanFord should be used in this case.
• Eccentricity
• Sage ---
• Mathematica ---  Eccentricity[g] gives the eccentricity of each vertex v of graph g, the maximum length among all shortest paths from v.
• Girth
• Sage ---
• Mathematica ---  Girth[g] gives the length of a shortest cycle in a simple graph g.
• Graph center
• Sage ---
• Mathematica ---  GraphCenter[g] gives a list of the vertices of graph g with minimum eccentricity.
• Graph power
• Sage ---
• Mathematica ---  GraphPower[g, k] gives the kth power of graph g. This is the graph whose vertex set is identical to the vertex set of g and that contains an edge between vertices i and j for each path in g between vertices i and j of length at most k.
• Parents to paths
• Sage ---
• Mathematica ---  ParentsToPaths[l, i, j] takes a list of parents l and returns the path from i to j encoded in the parent list.  ParentsToPaths[l, i] returns the paths from i to all vertices.
• Sage ---
• Mathematica ---  Radius[g] gives the radius of graph g, the minimum eccentricity of any vertex of g.
• Shortest path

### Minimum spanning trees

• Cofactor
• Sage ---
• Mathematica ---  Cofactor[m, {i, j}] calculates the (i,j)^(th) cofactor of matrix m.
• Find set
• Sage ---
• Mathematica ---  FindSet[n, s] gives the root of the set containing n in union-find data structure s.
• Initialize union find
• Sage ---
• Mathematica ---  InitializeUnionFind[n] initializes a union-find data structure for n elements.

• Maximum spanning tree
• Sage ---
• Mathematica ---  MaximumSpanningTree[g] uses Kruskal's algorithm to find a maximum spanning tree of graph g.
• Number of spanning trees
• Shortest path spanning tree
• Sage ---
• Mathematica ---  ShortestPathSpanningTree[g, v] constructs a shortest-path spanning tree rooted at v, so that a shortest path in graph g from v to any other vertex is a path in the tree. An option Algorithm that takes on the values Automatic, Dijkstra, or  BellmanFord is provided. This allows a choice between Dijkstra's algorithm and the Bellman-Ford algorithm. The default is Algorithm -> Automatic. In this case, depending on whether edges have negative weights and depending on the density of the graph, the algorithm chooses between Bellman-Ford and Dijkstra.
• Union set
• Sage ---
• Mathematica ---  UnionSet[a, b, s] merges the sets containing a and b in union-find data structure s.

### Network flow

• Networkflow
• Sage ---
• Mathematica ---  NetworkFlow[g, source, sink] returns the value of a maximum flow through graph g from source to sink.  NetworkFlow[g, source, sink, Edge] returns the edges in g that have positive flow along with their flows in a maximum flow from source to sink.  NetworkFlow[g, source, sink, Cut] returns a minimum cut between source and sink.  NetworkFlow[g, source, sink, All] returns the adjacency list of g along with flows on each edge in a maximum flow from source to sink. g can be a directed or an undirected graph.
• Residual flow graph
• Sage ---
• Mathematica ---  ResidualFlowGraph[g, flow] returns the directed residual flow graph for graph g with respect to flow.

### Matching

• Alternating paths
• Sage ---
• Mathematica ---  AlternatingPaths[g, start, ME] returns the alternating paths in graph g with respect to the matching ME, starting at the vertices in the list start. The paths are returned in the form of a forest containing trees rooted at vertices in start.
• Bipartite matching
• Sage ---
• Mathematica ---  BipartiteMatching[g] gives the list of edges associated with a maximum matching in bipartite graph g. If the graph is edge weighted, then the function returns a matching with maximum total weight.
• Bipartite matching and cover
• Sage ---
• Mathematica ---  BipartiteMatchingAndCover[g] takes a bipartite graph g and returns a matching with maximum weight along with the dual vertex cover. If the graph is not weighted, it is assumed that all edge weights are 1.
• Maximal matching
• Sage ---
• Mathematica ---  MaximalMatching[g] gives the list of edges associated with a maximal matching of graph g.
• No perfect matching graph
• Sage ---
• Mathematica ---  NoPerfectMatchingGraph returns a connected graph with 16 vertices that contains no perfect matching.
• Stable marriange
• Sage ---
• Mathematica ---  StableMarriage[mpref, fpref] finds the male optimal stable marriage defined by lists of permutations describing male and female preferences.

### Graph traversals

• Depth-first search
• Sage --- depth_first_search
• Mathematica ---  DepthFirstTraversal[g, v] performs a depth-first traversal of graph g starting from vertex v, and gives a list of vertices in the order in which they were encountered.

### Partial orders

• Antisymmetric q
• Sage ---
• Mathematica ---  AntiSymmetricQ[g] yields True if the adjacency matrix of g represents an anti-symmetric binary relation.
• Boolean algebra
• Sage ---
• Mathematica ---  BooleanAlgebra[n] gives a Hasse diagram for the Boolean algebra on n elements. The function takes two options: Type and  VertexLabel, with default values Undirected and False, respectively. When Type is set to Directed, the function produces the underlying directed acyclic graph. When  VertexLabel is set to True, labels are produced for the vertices.
• Dominating integer partition q
• Sage ---
• Mathematica ---  DominatingIntegerPartitionQ[a, b] yields True if integer partition a dominates integer partition b, that is, the sum of a size-t prefix of a is no smaller than the sum of a size-t prefix of b for every t.
• Domination lattice
• Sage ---
• Mathematica ---  DominationLattice[n] returns a Hasse diagram of the partially ordered set on integer partitions of n in which p < q if q dominates p. The function takes two options: Type and  VertexLabel, with default values Undirected and False, respectively. When Type is set to Directed, the function produces the underlying directed acyclic graph. When  VertexLabel is set to True, labels are produced for the vertices.
• Equivalence classes
• Sage ---
• Mathematica ---  EquivalenceClasses[r] identifies the equivalence classes among the elements of matrix r.
• Equivalence relation q
• Hasse diagram
• Sage ---
• Mathematica ---  HasseDiagram[g] constructs a Hasse diagram of the relation defined by directed acyclic graph g.
• Inversion poset
• Sage ---
• Mathematica ---  InversionPoset[n] returns a Hasse diagram of the partially ordered set on size-n permutations in which p < q if q can be obtained from p by an adjacent transposition that places the larger element before the smaller. The function takes two options: Type and  VertexLabel, with default values Undirected and False, respectively. When Type is set to Directed, the function produces the underlying directed acyclic graph. When  VertexLabel is set to True, labels are produced for the vertices.
• Isomorphic q
• Sage ---
• Mathematica ---  IsomorphicQ[g, h] yields True if graphs g and h are isomorphic.
• Maximum antichain
• Sage ---
• Mathematica ---  MaximumAntichain[g] gives a largest set of unrelated vertices in partial order g.
• Minimum chain partition
• Partial order q
• Sage ---
• Mathematica ---  PartialOrderQ[g] yields True if the binary relation defined by edges of the graph g is a partial order, meaning it is transitive, reflexive, and antisymmetric.
• Partition lattice
• Sage ---
• Mathematica ---  PartitionLattice[n] returns a Hasse diagram of the partially ordered set on set partitions of 1 through n in which p < q if q is finer than p, that is, each block in q is contained in some block in p. The function takes two options: Type and  VertexLabel, with default values Undirected and False, respectively. When Type is set to Directed, the function produces the underlying directed acyclic graph. When  VertexLabel is set to True, labels are produced for the vertices.
• Symmetric q
• Sage ---
• Mathematica ---  SymmetricQ[r] tests if a given square matrix r represents a symmetric relation.  SymmetricQ[g] tests if the edges of a given graph represent a symmetric relation.
• Topological sort
• Sage ---
• Mathematica ---  TopologicalSort[g] gives a permutation of the vertices of the directed acyclic graph g such that an edge (i,j) implies that vertex i appears before vertex j.
• Transitive closure
• Sage ---
• Mathematica ---  TransitiveClosure[g] finds the transitive closure of graph g, the supergraph of g that contains edge {x, y} if and only if there is a path from x to y.
• Transitive reduction
• Sage ---
• Mathematica  TransitiveReduction[g] finds a smallest graph that has the same transitive closure as g.

### Graph isomorphism

• Degrees of 2-neighborhood
• Sage ---
• Mathematica ---  DegreesOf2Neighborhood[g, v] returns the sorted list of degrees of vertices of graph g within a distance of 2 from v.
• Distances
• Sage ---
• Mathematica ---  Distances[g, v] returns the distances in nondecreasing order from vertex v to all vertices in g, treating g as an unweighted graph.
• Equivalences
• Sage ---
• Mathematica --- Equivalences[g, h] lists the vertex equivalence classes between graphs g and h defined by their vertex degrees. Equivalences[g] lists the vertex equivalences for graph g defined by the vertex degrees. Equivalences[g, h, f1, f2, ...] and Equivalences[g, f1, f2, ...] can also be used, where f1, f2, ... are functions that compute other vertex invariants. It is expected that for each function fi, the call fi[g, v] returns the corresponding invariant at vertex v in graph g. The functions f1, f2, ... are evaluated in order, and the evaluation stops either when all functions have been evaluated or when an empty equivalence class is found. Three vertex invariants,  DegreesOf2Neighborhood,  NumberOf2Paths, and Distances are Combinatorica functions and can be used to refine the equivalences.
• Identical q
• Sage ---
• Mathematica ---  IdenticalQ[g, h] yields True if graphs g and h have identical edge lists, even though the associated graphics information need not be the same.
• Isomorphism
• Sage ---
• Mathematica --- Isomorphism[g, h] gives an isomorphism between graphs g and h if one exists. Isomorphism[g, h, All] gives all isomorphisms between graphs g and h. Isomorphism[g] gives the automorphism group of g. This function takes an option Invariants -> {f1, f2, ...}, where f1, f2, ... are functions that are used to compute vertex invariants. These functions are used in the order in which they are specified. The default value of Invariants is { DegreesOf2Neighborhood,  NumberOf2Paths, Distances}.
• Isomorphism q
• Sage ---
• Mathematica ---  IsomorphismQ[g, h, p] tests if permutation p defines an isomorphism between graphs g and h.
• Neighborhood
• Sage ---
• Mathematica ---  Neighborhood[g, v, k] returns the subset of vertices in g that are at a distance of k or less from vertex v.
• Number of 2-paths
• Sage ---
• Mathematica ---  NumberOf2Paths[g, v] returns a sorted list that contains the number of paths of length 2 to different vertices of g from v.
• Number of k-paths
• Sage ---
• Mathematica ---  NumberOfKPaths[g, v, k] returns a sorted list that contains the number of paths of length k to different vertices of g from v.  NumberOfKPaths[al, v, k] behaves identically, except that it takes an adjacency list al as input.
• Self-complementary q
• Sage ---
• Mathematica ---  SelfComplementaryQ[g] yields True if graph g is self-complementary, meaning it is isomorphic to its complement.

## Graph properties

### Degrees

• Degrees
• Sage ---
• Mathematica ---  Degrees[g] returns the degrees of vertex 1,2,3,... in that order.
• Degree sequence
• Sage ---
• Mathematica ---  DegreeSequence[g] gives the sorted degree sequence of graph g.
• Graphic q
• Sage ---
• Mathematica ---  GraphicQ[s] yields True if the list of integers s is a graphic sequence, and thus represents a degree sequence of some graph.
• Indegree
• Sage ---
• Mathematica ---  InDegree[g, n] returns the in-degree of vertex n in directed graph g.
• Outdegree
• Sage ---
• Mathematica ---  OutDegree[g, n] returns the out-degree of vertex n in directed graph g.
• Realize degree sequence
• Spectrum
• Sage ---
• Mathematica ---  Spectrum[g] gives the eigenvalues of graph g.

### Miscellaneous

• Graph polynomial
• Sage ---
• Mathematica ---  GraphPolynomial[n, x] returns a polynomial in x in which the coefficient of xm is the number of nonisomorphic graphs with n vertices and m edges.  GraphPolynomial[n, x, Directed] returns a polynomial in x in which the coefficient of xm is the number of nonisomorphic directed graphs with n vertices and m edges.
• List graphs
• Sage ---
• Mathematica ---  ListGraphs[n, m] returns all nonisomorphic undirected graphs with n vertices and m edges.  ListGraphs[n, m, Directed] returns all nonisomorphic directed graphs with n vertices and m edges.  ListGraphs[n] returns all nonisomorphic undirected graphs with n vertices.  ListGraphs[n, Directed] returns all nonisomorphic directed graphs with n vertices.
• List necklaces
• Sage ---
• Mathematica ---  ListNecklaces[n, c, Cyclic] returns all distinct necklaces whose beads are colored by colors from c. Here c is a list of n, not necessarily distinct colors, and two colored necklaces are considered equivalent if one can be obtained by rotating the other.
• Necklace polynomial
• Sage ---
• Mathematica ---  NecklacePolynomial[n, c, Cyclic] returns a polynomial in the colors in c whose coefficients represent numbers of ways of coloring an n-bead necklace with colors chosen from c, assuming that two colorings are equivalent if one can be obtained from the other by a rotation.
• Number of directed graphs
• Number of graphs
• Sage ---
• Mathematica ---  NumberOfGraphs[n] returns the number of nonisomorphic undirected graphs with n vertices.  NumberOfGraphs[n, m] returns the number of nonisomorphic undirected graphs with n vertices and m edges.
• Number of necklaces
• Sage ---
• Mathematica ---  NumberOfNecklaces [n, nc, Cyclic] returns the number of distinct ways in which an n-bead necklace can be colored with nc colors, assuming that two colorings are equivalent if one can be obtained from the other by a rotation.

### Cycles and connectivity

• Acyclic q
• Sage ---
• Mathematica ---  AcyclicQ[g] yields True if graph g is acyclic.
• Articulation vertices
• Sage ---
• Mathematica ---  ArticulationVertices[g] gives a list of all articulation vertices in graph g. These are vertices whose removal will disconnect the graph.
• Biconnected components
• Sage ---
• Mathematica ---  BiconnectedComponents[g] gives a list of the biconnected components of graph g. If g is directed, the underlying undirected graph is used.
• Biconnected q
• Sage ---
• Mathematica ---  BiconnectedQ[g] yields True if graph g is biconnected. If g is directed, the underlying undirected graph is used.
• Bridges
• Sage ---
• Mathematica --- Bridges[g] gives a list of the bridges of graph g, where each bridge is an edge whose removal disconnects the graph.
• Connected components
• Sage ---
• Mathematica ---  ConnectedComponents[g] gives the vertices of graph g partitioned into connected components.
• Connected q
• Sage ---
• Mathematica ---  ConnectedQ[g] yields True if undirected graph g is connected. If g is directed, the function returns True if the underlying undirected graph is connected.
• De Bruijn sequence
• Sage ---
• Mathematica ---  DeBruijnSequence[a, n] returns a De Bruijn sequence on the alphabet a, a shortest sequence in which every string of length n on alphabet a occurs as a contiguous subsequence.
• Edge connectivity
• Sage ---
• Mathematica ---  EdgeConnectivity[g] gives the minimum number of edges whose deletion from graph g disconnects it.  EdgeConnectivity[g, Cut] gives a set of edges of minimum size whose deletion disconnects the graph.
• Eulerian cycle
• Sage ---
• Mathematica ---  EulerianCycle[g] finds an Eulerian cycle of g if one exists.
• Eulerian q
• Sage ---
• Mathematica ---  EulerianQ[g] yields True if graph g is Eulerian, meaning there exists a tour that includes each edge exactly once.
• Extract cycles
• Sage ---
• Mathematica ---  ExtractCycles[g] gives a maximal list of edge-disjoint cycles in graph g.
• Find cycle
• Sage ---
• Mathematica ---  FindCycle[g] finds a list of vertices that define a cycle in graph g.
• Hamiltonian cycle
• Hamiltonian q
• Sage ---
• Mathematica ---  HamiltonianQ[g] yields True if there exists a Hamiltonian cycle in graph g, or in other words, if there exists a cycle that visits each vertex exactly once.
• Orient graph
• Sage ---
• Mathematica ---  OrientGraph[g] assigns a direction to each edge of a bridgeless, undirected graph g, so that the graph is strongly connected.
• Strongly connected components
• Traveling salesman
• Sage ---
• Mathematica ---  TravelingSalesman[g] finds an optimal traveling salesman tour in a Hamiltonian graph g.
• Traveling salesman bounds
• Sage ---
• Mathematica ---  TravelingSalesmanBounds[g] gives upper and lower bounds on a minimum cost traveling salesman tour of graph g.
• Vertex connectivity
• Sage ---
• Mathematica ---  VertexConnectivity[g] gives the minimum number of vertices whose deletion from graph g disconnects it.  VertexConnectivity[g, Cut] gives a set of vertices of minimum size, whose removal disconnects the graph.
• Vertex connectivity graph
• Sage ---
• Mathematica ---  VertexConnectivityGraph[g] returns a directed graph that contains an edge corresponding to each vertex in g and in which edge disjoint paths correspond to vertex disjoint paths in g.
• Weakly connected components
• Sage ---
• Mathematica ---  WeaklyConnectedComponents[g] gives the weakly connected components of directed graph g as lists of vertices.

### Graph coloring

• Backtrack
• Sage ---
• Mathematica ---  Backtrack[s, partialQ, solutionQ] performs a backtrack search of the state space s, expanding a partial solution so long as partialQ is True and returning the first complete solution, as identified by solutionQ.
• Bipartite q
• Sage ---
• Mathematica ---  BipartiteQ[g] yields True if graph g is bipartite.
• Brelaz coloring
• Sage ---
• Mathematica ---  BrelazColoring[g] returns a vertex coloring in which vertices are greedily colored with the smallest available color in decreasing order of vertex degree.
• Chromatic number
• Sage ---
• Mathematica ---  ChromaticNumber[g] gives the chromatic number of the graph, which is the fewest number of colors necessary to color the graph.
• Chromatic polynomial
• Sage ---
• Mathematica ---  ChromaticPolynomial[g, z] gives the chromatic polynomial P(z) of graph g, which counts the number of ways to color g with, at most, z colors.
• Edge chromatic number
• Sage ---
• Mathematica ---  EdgeChromaticNumber[g] gives the fewest number of colors necessary to color each edge of graph g, so that no two edges incident on the same vertex have the same color.
• Edge coloring
• Sage ---
• Mathematica ---  EdgeColoring[g] uses Brelaz's heuristic to find a good, but not necessarily minimal, edge coloring of graph g.
• Perfect q
• Sage ---
• Mathematica ---  PerfectQ[g] yields True if g is a perfect graph, meaning that for every induced subgraph of g the size of a largest clique equals the chromatic number.
• Two coloring
• Sage ---
• Mathematica ---  TwoColoring[g] finds a two-coloring of graph g if g is bipartite. It returns a list of the labels 1 and 2 corresponding to the vertices. This labeling is a valid coloring if and only the graph is bipartite.
• Vertex coloring
• Sage ---
• Mathematica ---  VertexColoring[g] uses Brelaz's heuristic to find a good, but not necessarily minimal, vertex coloring of graph g. An option Algorithm that can take on the values Brelaz or Optimum is allowed. The setting Algorithm -> Brelaz is the default, while the setting Algorithm -> Optimum forces the algorithm to do an exhaustive search to find an optimum vertex coloring.

### Graph predicates

• Clique q
• Sage ---
• Mathematica ---  CliqueQ[g, c] yields True if the list of vertices c defines a clique in graph g.
• Complete q
• Sage ---
• Mathematica ---  CompleteQ[g] yields True if graph g is complete. This means that between any pair of vertices there is an undirected edge or two directed edges going in opposite directions.
• Empty q
• Sage ---
• Mathematica ---  EmptyQ[g] yields True if graph g contains no edges.
• Multiple edges q
• Sage ---
• Mathematica ---  MultipleEdgesQ[g] yields True if g has multiple edges between pairs of vertices. It yields False otherwise.
• Planar q
• Sage ---
• Mathematica ---  PlanarQ[g] yields True if graph g is planar, meaning it can be drawn in the plane so no two edges cross.
• Pseudograph q
• Sage ---
• Mathematica ---  PseudographQ[g] yields True if graph g is a pseudograph, meaning it contains self-loops.
• Self-loops q
• Sage ---
• Mathematica ---  SelfLoopsQ[g] yields True if graph g has self-loops.
• Simple q
• Sage ---
• Mathematica ---  SimpleQ[g] yields True if g is a simple graph, meaning it has no multiple edges and contains no self-loops.
• Triangle inequality q
• Sage ---
• Mathematica ---  TriangleInequalityQ[g] yields True if the weights assigned to the edges of graph g satisfy the triangle inequality.
• Undirected q
• Sage ---
• Mathematica ---  UndirectedQ[g] yields True if graph g is undirected.
• Unweighted q
• Sage ---
• Mathematica ---  UnweightedQ[g] yields True if all edge weights are 1 and False otherwise.

## Others

•  ApproximateVertexCover[g] produces a vertex cover of graph g whose size is guaranteed to be within twice the optimal size.
•  ButterflyGraph[n] returns the n-dimensional butterfly graph, a directed graph whose vertices are pairs (w, i), where w is a binary string of length n and i is an integer in the range 0 through n and whose edges go from vertex (w, i) to (w', i+1), if w' is identical to w in all bits with the possible exception of the (i+1)th bit. Here bits are counted left to right. An option  VertexLabel, with default setting False, is allowed. When this option is set to True, vertices are labeled with strings (w, i).
•  CageGraph[k, r] gives a smallest k-regular graph of girth r for certain small values of k and r.  CageGraph[r] gives  CageGraph[3, r]. For k = 3, r can be 3, 4, 5, 6, 7, 8, or 10. For k = 4 or 5, r can be 3, 4, 5, or 6.
•  CirculantGraph[n, l] constructs a circulant graph on n vertices, meaning the ith vertex is adjacent to the (i+j)th and (i-j)th vertices, for each j in list l.  CirculantGraph[n, l], where l is an integer, returns the graph with n vertices in which each i is adjacent to (i+l) and (i-l).
•  CodeToLabeledTree[l] constructs the unique labeled tree on n vertices from the Prufer code l, which consists of a list of n-2 integers between 1 and n.
• Contract[g, {x, y}] gives the graph resulting from contracting the pair of vertices {x, y} of graph g.
•  CostOfPath[g, p] sums up the weights of the edges in graph g defined by the path p.
•  CoxeterGraph gives a non-Hamiltonian graph with a high degree of symmetry such that there is a graph automorphism taking any path of length 3 to any other.
•  CubeConnectedCycle[d] returns the graph obtained by replacing each vertex in a d-dimensional hypercube by a cycle of length d. Cube-connected cycles share many properties with hypercubes but have the additional desirable property that for d > 1 every vertex has degree 3.
•  DeBruijnGraph[m, n] constructs the n-dimensional De Bruijn graph with m symbols for integers m > 0 and n > 1.  DeBruijnGraph[alph, n] constructs the n-dimensional De Bruijn graph with symbols from alph. Here alph is nonempty and n > 1 is an integer. In the latter form, the function accepts an option  VertexLabel, with default value False, which can be set to True, if users want to associate strings on alph to the vertices as labels.
•  DeleteCycle[g, c] deletes a simple cycle c from graph g. c is specified as a sequence of vertices in which the first and last vertices are identical. g can be directed or undirected. If g does not contain c, it is returned unchanged; otherwise g is returned with c deleted."
•  DilateVertices[v, d] multiplies each coordinate of each vertex position in list v by d, thus dilating the embedding.  DilateVertices[g, d] dilates the embedding of graph g by the factor d.
•  ExactRandomGraph[n, e] constructs a random labeled graph of exactly e edges and n vertices.
•  FiniteGraphs produces a convenient list of all the interesting, finite, parameterless graphs built into Combinatorica.
•  FolkmanGraph returns a smallest graph that is edge-transitive but not vertex-transitive.
•  FranklinGraph returns a 12-vertex graph that represents a 6-chromatic map on the Klein bottle. It is the sole counterexample to Heawood's map coloring conjecture.
•  FunctionalGraph[f, v] takes a set v and a function f from v to v and constructs a directed graph with vertex set v and edges (x, f(x)) for each x in v.  FunctionalGraph[f, v], where f is a list of functions, constructs a graph with vertex set v and edge set (x, fi(x)) for every fi in f. An option called Type that takes on the values Directed and Undirected is allowed. Type -> Directed is the default, while Type -> Undirected returns the corresponding underlying undirected graph.  FunctionalGraph[f, n] takes a nonnegative integer n and a function f from {0,1,..., n-1} onto itself and produces the directed graph with vertex set {0, 1,..., n-1} and edge set {x, f(x)} for each vertex x."
•  GeneralizedPetersenGraph[n, k] returns the generalized Petersen graph, for integers n > 1 and k > 0, which is the graph with vertices {u1, u2, ..., un} and {v1, v2, ..., vn} and edges {ui, u(i+1)}, {vi, v(i+k)}, and {ui, vi}. The Petersen graph is identical to the generalized Petersen graph with n = 5 and k = 2.
•  GraphDifference[g, h] constructs the graph resulting from subtracting the edges of graph h from the edges of graph g.
•  GraphIntersection[g1, g2, ...] constructs the graph defined by the edges that are in all the graphs g1, g2, ....
•  GraphJoin[g1, g2, ...] constructs the join of graphs g1, g2, and so on. This is the graph obtained by adding all possible edges between different graphs to the graph union of g1, g2, ....
•  GraphSum[g1, g2, ...] constructs the graph resulting from joining the edge lists of graphs g1, g2, and so forth.
•  GrayGraph returns a 3-regular, 54-vertex graph that is edge-transitive but not vertex-transitive; the smallest known such example."
•  GreedyVertexCover[g] returns a vertex cover of graph g constructed using the greedy algorithm. This is a natural heuristic for constructing a vertex cover, but it can produce poor vertex covers.
• Harary[k, n] constructs the minimal k-connected graph on n vertices.
•  IndependentSetQ[g, i] yields True if the vertices in list i define an independent set in graph g.
•  IntervalGraph[l] constructs the interval graph defined by the list of intervals l.
•  KnightsTourGraph[m, n] returns a graph with m*n vertices in which each vertex represents a square in an m x n chessboard and each edge corresponds to a legal move by a knight from one square to another.
•  LeviGraph returns the unique (8, 3)-cage, a 3-regular graph whose girth is 8.
•  MakeGraph[v, f] constructs the graph whose vertices correspond to v and edges between pairs of vertices x and y in v for which the binary relation defined by the Boolean function f is True.  MakeGraph takes two options, Type and  VertexLabel. Type can be set to Directed or Undirected and this tells  MakeGraph whether to construct a directed or an undirected graph. The default setting is Directed.  VertexLabel can be set to True or False, with False being the default setting. Using  VertexLabel -> True assigns labels derived from v to the vertices of the graph.
•  MakeSimple[g] gives the undirected graph, free of multiple edges and self-loops derived from graph g.
•  McGeeGraph returns the unique (7, 3)-cage, a 3-regular graph with girth 7.
•  MeredithGraph returns a 4-regular, 4-connected graph that is not Hamiltonian, providing a counterexample to a conjecture by C. St. J. A. Nash-Williams.
•  MinimumChangePermutations[l] constructs all permutations of list l such that adjacent permutations differ by only one transposition.
•  MinimumVertexCover[g] finds a minimum vertex cover of graph g. For bipartite graphs, the function uses the polynomial-time Hungarian algorithm. For everything else, the function uses brute force.
•  MycielskiGraph[k] returns a triangle-free graph with chromatic number k, for any positive integer k.
•  NetworkFlowEdges[g, source, sink] returns the edges of the graph with positive flow, showing the distribution of a maximum flow from source to sink in graph g. This is obsolete, and  NetworkFlow[g, source, sink, Edge] should be used instead.
•  NonLineGraphs returns a graph whose connected components are the 9 graphs whose presence as a vertex-induced subgraph in a graph g makes g a nonline graph.
•  NormalizeVertices[v] gives a list of vertices with a similar embedding as v but with all coordinates of all points scaled to be between 0 and 1.
•  OddGraph[n] returns the graph whose vertices are the size-(n-1) subsets of a size-(2n-1) set and whose edges connect pairs of vertices that correspond to disjoint subsets.  OddGraph[3] is the Petersen graph.
•  PartialOrderQ[g] yields True if the binary relation defined by edges of the graph g is a partial order, meaning it is transitive, reflexive, and antisymmetric.  PartialOrderQ[r] yields True if the binary relation defined by the square matrix r is a partial order.
•  RandomTree[n] constructs a random labeled tree on n vertices.
•  ReadGraph[f] reads a graph represented as edge lists from file f and returns a graph object.
•  ReflexiveQ[g] yields True if the adjacency matrix of g represents a reflexive binary relation.
•  RegularGraph[k, n] constructs a semirandom k-regular graph on n vertices, if such a graph exists.
•  RegularQ[g] yields True if g is a regular graph.
•  RobertsonGraph returns a 19-vertex graph that is the unique (4, 5)-cage graph.
•  ShuffleExchangeGraph[n] returns the n-dimensional shuffle-exchange graph whose vertices are length n binary strings with an edge from w to w' if (i) w' differs from w in its last bit or (ii) w' is obtained from w by a cyclic shift left or a cyclic shift right. An option  VertexLabel is provided, with default setting False, which can be set to True, if the user wants to associate the binary strings to the vertices as labels."
•  ThomassenGraph returns a hypotraceable graph, a graph G that has no Hamiltonian path but whose subgraph G-v for every vertex v has a Hamiltonian path.
•  TreeIsomorphismQ[t1, t2] yields True if the trees t1 and t2 are isomorphic. It yields False otherwise.
•  TreeQ[g] yields True if graph g is a tree.
•  TreeToCertificate[t] returns a binary string that is a certificate for the tree t such that trees have the same certificate if and only if they are isomorphic.
• Turan[n, p] constructs the Turan graph, the extremal graph on n vertices that does not contain  CompleteGraph[p].
•  TutteGraph returns the Tutte graph, the first known example of a 3-connected, 3-regular, planar graph that is non-Hamiltonian.
•  UnitransitiveGraph returns a 20-vertex, 3-unitransitive graph discovered by Coxeter, that is not isomorphic to a 4-cage or a 5-cage.
•  VertexCover[g] returns a vertex cover of the graph g. An option Algorithm that can take on values Greedy, Approximate, or Optimum is allowed. The default setting is Algorithm -> Approximate. Different algorithms are used to compute a vertex cover depending on the setting of the option Algorithm.
•  VertexCoverQ[g, c] yields True if the vertices in list c define a vertex cover of graph g.
• Vertices[g] gives the embedding of graph g, that is, the coordinates of each vertex in the plane. Vertices[g, All] gives the embedding of the graph along with graphics options associated with each vertex.
•  WriteGraph[g, f] writes graph g to file f using an edge list representation.