Isomorphism Classes of S-Decorated Simple Graphs
Edward Wibowo,
1. Introduction
This exploration will use the following definitions.
Using these definitions, we seek to explore the following question.
To aid our exploration, we define a way to categorize using ordered lists. We refer to these representations as the ordered list representation of .
For example, suppose and is a graph with vertices. If maps all vertices to , then the ordered list representation of is . If maps one vertex to and the other two to , then the ordered list representation of is . We note that the choice of which vertex is mapped to and which two are mapped to is irrelevant; any that maps one vertex to and the other two to is represented as .
Next, we observe that for any number of vertices and any , if is isomorphic to , then and share the same ordered list representation. This is formalized in the following lemma.
Proof. Suppose and are -decorated isomorphic. Then, there exists an isomorphism from to such that for all . Without loss of generality, suppose we enumerate and as and such that for all valid . Then, we write the following equalities:
Using the above equalities, the lists
must have the same elements in the same order. So, these lists must be identical. Hence, and must share the same ordered list representation.
2. Example Case
To achieve a better understanding of the problem, we count the number of isomorphism classes of -decorated simple graphs with vertices and . By Definition 2, an isomophism between two -decorated simple graphs and implies is isomorphic to . Contrapositively, if is not isomorphic to , then and are not -decorated isomorphic regardless of the choice of and . Hence, we will count the number of -decorated isomorphism classes for each of the isomorphism classes of simple graphs with vertices.
Figure 1. The four isomorphism classes of simple graphs with vertices.
Without loss of generality, let .
We start with the first isomorphism class, which consists of simple graphs with vertices and no edges. We can enumerate all possible ordered list representations of as follows:
We note that any graph with vertices and no edges are isomorphic, and the isomorphism can be any bijection between the two vertex sets. This means and should be -decorated isomorphic if and share the same ordered list representation as we can just pair up same-labelled vertices in and .
We capture this line of reasoning in the following lemma
Proof. Suppose and share the same ordered list representation. We shall construct an isomorphism such that for all .
Since and share the same ordered list representation, we can create distinct pair of vertices where and such that their labels match (so ). We can do this in a way such that no two pairs share the same vertex in or since and have the same ordered list representation and . Then, we can define to be the function that maps to for each pair .
We justify that is a bijection. Since no two pairs share the same vertex in or , pairs each element of with exactly one element of and vice versa. Hence, is a bijection.
Since and are defined to be simple graphs such that any bijection from to is a graph isomorphism, is also an isomorphism from to . Lastly, by construction, we have for all .
Therefore, and are -decorated isomorphic.
Using both Lemma 6 and Lemma 5, each of the four ordered list representations of corresponds to a unique isomorphism class of -decorated simple graphs. Thus, there are isomorphism classes of -decorated simple graphs with vertices and no edges.
We also note that for any graphs and in the isomorphism class consisting of graphs with vertices and edges (so the fourth one depicted in Figure 1), any bijection from to is a graph isomorphism. So, by Lemma 6 and Lemma 5, the number of isomorphism classes of -decorated simple graphs with vertices and edges is also .
Now, we need to count the -decorated isomorphism classes of simple graphs with vertices and or edges.
We analyze the second isomorphism class, which consists of simple graphs with vertices and edge. Lemmas 6 and 5 do not apply here since, for example, if the singular edge of maps to and the singular edge of maps to , then there is no -decorated isomorphism between and . We count by cases of the ordered list representation of by considering the possible labelling of the unique singular disconnected vertex.
-
Case : If both and map all vertices to , then any graph isomorphism between and will also preserve the -decoration. Thus, this case has isomorphism class.
-
Case : There would be isomorphism classes in this case. The first class is where the singular disconnected vertex maps to and the other two vertices map to . The second class is where the singular disconnected vertex maps to and the other two vertices map to and .
-
Case : Similar to the previous case, there would be isomorphism classes in this case. The first case is where the singular disconnected vertex maps to and the other two vertices map to . The second case is where the singular disconnected vertex maps to and the other two vertices map to and .
-
Case : This is equivalent to the first case, so there is isomorphism class.
So, in total, there are isomorphism classes of -decorated simple graphs with vertices and edge.
The same logic can be applied to the third isomorphism class, which consists of simple graphs with vertices and edges. In this case, the unique vertex would be the one with degree . Hence, there are isomorphism classes of -decorated simple graphs with vertices and edges.
Therefore, our results can be summarized as follows:
Number of edges | Number of -decorated isomorphism classes |
---|---|
Table 1. The number of isomorphism classes of -decorated simple graphs with vertices.
bringing the total number of isomorphism classes of -decorated simple graphs with vertices to .
3. Linear Graphs
We further the exploration by answering Question 3 for linear graphs (i.e. paths) with vertices. More formally,
By definition, a linear graph is a simple graph with vertices and edges whose vertices can be ordered in a linear sequence such that the edges are between consecutive vertices in the sequence.
Figure 2. A linear graph with vertices.
We define the notion of a label sequence of an -decorated linear graph.
We note that depending on the choice of which of the two endpoints is and which is , the label sequence of a linear graph can be either or . Using this definition, we provide and prove the following theorem about the label sequences of -decorated linear graphs.
Proof. Without loss of generality, suppose is a path and is a path . We note
We prove both directions of the biconditional statement.
Suppose and are -decorated isomorphic. Then, there exists an isomorphism from to such that for all .
Let be an arbitrary -deocrated isomorphism from to . Since is edge-preserving, it must map (an endpoint of ) to either endpoint of (so either or ). We consider the two cases separately.
-
Case: maps to : Since is an -decorated isomorphism, . Furthermore, since is edge-preserving, it forces , so we also know . We continue this reasoning for all pairs of vertices in and , allowing us to conclude .
-
Case: maps to : Similarly, since is an -decorated isomorphism, . This forces , so we also know . Continuing this reason, we find that the lists
are identical. Consequently, we have .
Thus, in both cases, we have or .
Suppose or . We argue by cases:
-
Case: : In this case, we shall construct an -decorated isomorphism from to . Let be the function that maps to for all valid .
is bijective by construction since it pairs each element of either or with exactly one element of the other set. Furthermore, since is defined as a path and is defined as a path , is also edge-preserving.
Since , we have for all valid . Since each , we also have for all valid . Thus, is an -decorated isomorphism from to .
-
Case: : Likewise, we construct an -decorated isomorphism from to . Let be the function that maps to for all valid .
is bijective by construction since it pairs each element of either or with exactly one element of the other set. Moreover, we can view as relabelling the vertices of from to . The resulting graph forms the path which is exactly , so is also edge-preserving.
Since , we have for all valid . Since each , we also have for all valid . Thus, is an -decorated isomorphism from to .
In both cases, we have constructed an -decorated isomorphism from to . Therefore, and are -decorated isomorphic.
Since both directions of the biconditional statement have been proven, the lemma is proven.
With Theorem 9, we have reduced the problem of counting the number of isomorphism classes of -decorated linear graphs to counting the number of label sequences, treating sequences that are reverses of each other as identical.
Each label sequence is a sequence of elements, where each element could possibly be any of the elements. So, there are possible label sequences.
Sequences that form a palindrome do not have a reverse that is distinct from itself. So each palindromic sequence contributes to a new isomorphism class of -decorated linear graphs. Sequences that do not form a palindrome have a reverse that is distinct from itself, so we must divide the number of sequences that do not form a palindrome by to avoid overcounting. Thus, the number of isomorphism classes of -decorated linear graphs with vertices is
We note that the number of non-palindromic sequences can be calculated as
Thus, we seek to count the number of palindromic sequences.
A palindrome is completely determined by the first half of the sequence. So for an even length sequence, the number of palindromic sequences is the same as the number of sequences of half the length. For an odd length, the number of palindromic sequences is the same as the number of sequences of half the length, except that the middle element can be any of the elements. To capture this line of reasoning, we have:
Therefore, the number of isomorphism classes of -decorated linear graphs with vertices is
Using this formula, we can tabulate the number of isomorphism classes of -decorated linear graphs with vertices for various and . Arbitrarily, we choose . The results are tabulated as follows:
|| | Number of -decorated isomorphism classes |
---|---|
Table 2. The number of isomorphism classes of -decorated linear graphs with vertices.
From Table 2, we can conclude that as increases, the number of isomorphism classes of -decorated linear graphs with vertices increases. Introducing more elements to increases the number of ways to label the vertices of the linear graph, which in turn increases the number of isomorphism classes of -decorated linear graphs.
3.1. Counting Isomorphism Classes through Ordered List Representations
Although we have already found that the number of isomorphism classes of -decorated linear graphs with vertices is
it would still be interesting to explore how the number of isomorphism classes can be counted through the ordered list representations of the labelling functions (as defined in Definition 4.
First, we note that finding the number of ordered list representations is equivalent to finding the number of ways to choose elements from a set of elements with repetition. Therefore, the number of ordered list representations for where is
Next, for each of these ordered list representations, we can apply Theorem 9 to determine whether the corresponding -decorated linear graph is in a new isomorphism class. This is equivalent to checking the number of palindromes and non-palindromes that can be made from each ordered list representation.
Thus, given an arbitrary labelling function , we seek to count the number of palindromes (which also would help us count the number of non-palindromes) that can be made from its ordered list representation. We consider two cases of the parity of the length of ‘s ordered list representation which is equal to :
-
Case: is even: For there to be a palindrome of even length, the first half of the sequence must be the reverse of the second half. This means the frequency of an element in the first half must be the same as the frequency of the same element in the second half. Thus, each distinct element in ‘s ordered list representation must have an even frequency for there to be at least one palindrome. Else, there would be no palindromes.
Further, since each palindrome is completely determined by the first half, the number of palindromes would be equal to the multinomial coefficient of half of the length and half of each frequency of the elements in ‘s ordered list representation. Symbolically,
where each is the frequency of the th element of in ‘s ordered list representation.
-
Case: is odd: The only way to form a palindrome from ‘s ordered list representation is if exactly one element has an odd frequency and the rest have even frequencies. The one element with odd frequency can be placed in the middle of the sequence. If there is either no element with an odd frequency or more than one element with an odd frequency, then there would be no palindromes.
If there is exactly one element with odd frequency in ‘s ordered list representation, then the number of palindromes can be calculated by the even-length case, where the length is and the frequency of the odd element is .
To summarize, the algorithm to count the number of palindromes by ordered list representation is as follows:
-
Iterate through each of the possible ordered list representations of .
-
For each ordered list representation calculate the number of palindromes:
- Count the frequency of each element in the ordered list representation.
- If is even: if there exists an element of odd frequency, the number of palindromes is . Else, the number of palindromes is where each is the frequency of the th element of in the ordered list representation.
- If is odd: if there is more than one element with odd frequency, or there is no element with odd frequency, the number of palindromes is . Else, consider the even-length case where the length is and the frequency of the odd element is .
-
For each ordered list representation: increment the running total by the number of palindromes added with the number of non-palindromes divided by .
- The total number of arrangements is where each is the frequency of the th element of in the ordered list representation. So, the number of non-palindromes would be equal to subtracted by the number of palindromes.
-
Return the running total.
This algorithm can be used to count the number of isomorphism classes of -decorated linear graphs with vertices. The implementation of this algorithm can be found in the appendix.
4. Literature: Weisfeiler-Lehman Algorithm
When given two -decorated graphs and , one might want to determine whether they are -decorated isomorphic in an efficient manner. We can observe that when , this problem reduces to the graph isomorphism problem.
When , all vertices are mapped to the same singleton element. So, any isomorphism between and will also preserve the -decoration. Thus, and are -decorated isomorphic if and only if and are isomorphic.
However, as stated in [2], there is no known efficient (polynomial time) algorithm for the graph isomorphism problem. If we could find an efficient polynomial time algorithm for the -decorated isomorphism problem, we would have also solved the graph isomorphism problem in polynomial time.
Although determining definitively whether two graphs are isomorphic is difficult, there are heuristic procedures that can be used to determine whether two graphs are not isomorphic or inconclusively isomorphic. One such example is the Weisfeiler-Lehman algorithm.
As described in [1], there are many variations of the algorithm, but in the simplest -dimensional form, the algorithm works as follows:
- Assign each vertex a color, initially based on its degree.
- At each subsequent iteration, update each vertex’s color based on its color in the previous iteration and the multiset of colors of its neighbors.
- Continue iterating until the colors stabilize, meaning that no vertex’s color changes from one iteration to the next.
Given two graphs, if the colors stabilize to different colorings, then the graphs are not isomorphic. However, if the colors stabilize to the same coloring, then the graphs may or may not be isomorphic; the answer is inconclusive. In this way, the algorithm does not completely solve the graph isomorphism problem, but it can be used as a heuristic to determine non-isomorphism.
Furthermore, this algorithm is generalizable as detailed in [1, 1.2] to higher dimensions, where higher dimensional Weisfeiler-Lehman algorithms can determine non-isomorphism for a larger class of graphs.
However, [1, 2.1] cites counterexamples to the Weisfeiler-Lehman algorithm, where the algorithm fails to determine non-isomorphism for certain classes of graphs. Hence, regardless of the dimension of the Weisfeiler-Lehman algorithm, there will always be non-isomorphic graphs for which the algorithm cannot determine non-isomorphism. This represents a fundamental limitation of the traditional Weisfeiler-Lehman algorithm.
To address this limitation, [1] introduces a recursive -dim Weisfeiler-Lehman algorithm. This modification refines the Weisfeiler-Lehman algorithm and is able to determine non-isomorphism for the aforementioned counterexamples.
4.1 Application to -Decorated Isomorphisms
The idea of finding efficient ways to determine non-isomorphism is intriguing and can be applied to the -decorated isomorphism problem. For example, suppose we seek to determine whether two -decorated graphs and are not -decorated isomorphic or inconclusively -decorated isomorphic. A potential approach is to first check whether and share the same ordered list representation as mentioned in Lemma 5. If they do not, we can safely conclude that and are not -decorated isomorphic. If and do share the same ordered list representation, then we can apply the recursive -dim Weisfeiler-Lehman algorithm to determine non-isomorphism.
Checking if two ordered lists are equal can be done efficiently. So, having this check as a preliminary step could save computation time in certain cases by avoiding the recursive -dim Weisfeiler-Lehman algorithm.
5. Appendix
The following is the implementation of the algorithm to count the number of isomorphism classes of -decorated linear graphs with vertices through the possible ordered list representations of the labelling functions. Comments have been added for additional explanation.
import itertools
import math
from typing import List
def multinomial_coefficient(n: int, k: List[int]) -> int:
"""
Compute the multinomial coefficient of n and k.
"""
assert sum(k) == n
return math.factorial(n) // math.prod(math.factorial(i) for i in k)
assert multinomial_coefficient(4, [2, 2]) == 6
assert multinomial_coefficient(4, [1, 1, 2]) == 12
assert multinomial_coefficient(4, [4]) == 1
assert multinomial_coefficient(7, [2, 1, 4]) == 105
def count_palindromes(k: List[int]) -> int:
"""
Count the number of palindromes in a list of integers.
"""
n = len(k)
freqs = {x: k.count(x) for x in k}
if n % 2 == 0:
# n is even
if any(x % 2 != 0 for x in freqs.values()):
# If any number appears an odd number of times, it would be impossible to form a palindrome.
# Since n is even, a given number should appear the same number of times on both halves of the palindrome.
# So, for there to be a palindrome, all numbers should appear an even number of times.
return 0
# A palindrome is completely determined by the structure of the first half.
# So, the number of palindromes would be the multinomial coefficient of n // 2 and half the frequency of each number.
return multinomial_coefficient(n // 2,
[x // 2 for x in freqs.values()])
# n is odd
odd_freqs = [x for x in freqs if freqs[x] % 2 != 0]
# If n is odd, the only way to form a palindrome is if exactly one number appears an odd number of times.
# We can put this number in the middle of the palindrome.
# Then, the number of palindromes would be the number of ways to form a palindrome with the remaining numbers
# (of which there are an even number of each).
if len(odd_freqs) != 1:
return 0
k.remove(odd_freqs[0])
return count_palindromes(k)
assert count_palindromes([1, 1, 1, 1]) == 1
assert count_palindromes([0, 0, 1, 1]) == 2
assert count_palindromes([0, 0, 0, 1]) == 0
assert count_palindromes([1, 1, 2, 2, 3, 3]) == 6
assert count_palindromes([1, 1, 1, 2, 2, 3, 3]) == 6
assert count_palindromes([1, 1, 1, 2, 2, 2, 3]) == 0
def count_linear_s_decorated_iso_classes(n: int, k: int) -> int:
"""
Count the number of linear S-decorated isomorphism classes of linear graphs with n vertices and |S| = k.
"""
ordered_list_representations = itertools.combinations_with_replacement(
range(k), n)
iso_classes = 0
for rep in ordered_list_representations:
# For each ordered list representation, count the number of arrangements, treating lists that are reverses of each other as the same.
total = multinomial_coefficient(n, [rep.count(x) for x in range(k)])
palindromes = count_palindromes(list(rep))
# Each arrangement is either a palindrome or non-palindrome.
# So, we can compute the number of non-palindromes by subtracting the number of palindromes from the total.
non_palindromes = total - palindromes
# Each non-palindrome arrangement can be grouped with its reverse to form an isomorphism class.
# So, the number of isomorphism classes is the sum of the number of palindromes and half the number of non-palindromes.
iso_classes += palindromes + non_palindromes // 2
return iso_classes
assert count_linear_s_decorated_iso_classes(4, 1) == 1
assert count_linear_s_decorated_iso_classes(11, 1) == 1
assert count_linear_s_decorated_iso_classes(4, 2) == 10
assert count_linear_s_decorated_iso_classes(3, 3) == 18
The following is a program that compares three implementations to count the number of -decorated isomorphism classes of linear graphs with vertices.
- Formulaic method using .
- Algorithmic method through considering possible ordered list representations using the above algorithm.
- Brute force method that lists through all possible lists and removes ones that are reverses of each other.
Running the code reveals that all three methods produce the same results. However, the formulaic method is the most efficient, followed by the algorithmic method, and then the brute force method.
import itertools
def remove_reversals(possible_lists):
iso = []
for l in possible_lists:
is_iso = True
for r in iso:
if l == r[::-1] or l == r:
is_iso = False
break
if is_iso:
iso.append(l)
return iso
def count_iso(n, k):
possible_lists = list(itertools.product(range(k), repeat=n))
# Remove lists that are reversals of each other
iso = remove_reversals(possible_lists)
return len(iso)
import algorithm
import math
n = 4
for s in range(1, 11):
formula_ans = (s**n + s**math.ceil(n / 2)) / 2
algorithm_ans = algorithm.count_linear_s_decorated_iso_classes(n, s)
brute_ans = count_iso(n, s)
print("n = ", n, "k = ", s)
print("Formula: ", int(formula_ans))
print("Algorithm: ", algorithm_ans)
print("Brute: ", brute_ans)
References
[1] B. L. Douglas. The weisfeiler-lehman method and graph isomorphism testing. 2011.
[2] S. Fortin. The Graph Isomorphism Problem. 1996.