Partial Cartesian Graph Product

05/18/2018 ∙ by Moez A. AbdelGawad, et al. ∙ Rice University 0

In this paper we define a new product-like binary operation on directed graphs, and we discuss some of its properties. We also briefly discuss its application in constructing the subtyping relation in generic nominally-typed object-oriented programming languages.

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Computer science is one of the many fields in which graph products are becoming commonplace [Hammack2011, ]

, where graph products are often viewed as a convenient language with which to describe structures. The notion of a product in any mathematical science enables the combination or decomposition of its elemental structures. In graph theory there are four main products: the Cartesian product, the direct/tensor/categorical product, the strong product and the lexicographic product, each with its own set of applications and theoretical interpretations.

The applications of graph theory and graph products in researching programming languages, in particular, are numerous111As revealed, for example, by doing an online search on ‘graph theory and programming languages research’.. In this paper we present a notion of a partial Cartesian graph product and discuss some of its properties.

We conjecture partial Cartesian graph products may have a number of applications and uses in computer science, mathematics, and elsewhere. In particular, we briefly demonstrate how the notion of a partial Cartesian graph product we present in this paper can be applied to accurately construct the subtyping relation in generic nominally-typed object-oriented (OO) programming languages such as Java [JLS14, ], C# [CSharp2015, ], C++ [CPP2011, ], Scala [Odersky14, ] and Kotlin [Kotlin18, ].

As such, this paper is structured as follows. In Section 2 we present the definition of the partial Cartesian graph product of two graphs and the intuition behind it (we present two equivalent views of the partial product), then in Section 3 we present examples for partial Cartesian graph products that illustrate our definition (in Appendix A we present SageMath code implementations of our definition/intuitions). In Section 4 we then discuss some of the basic properties of partial Cartesian graph products.

The, in Section 5, we discuss some earlier work similar to ours, and discuss the similarities and differences between their properties. In Section 6 we then discuss, in brief, how the partial Cartesian graph product operation can be used to construct the subtyping relation in Java222We discuss this application in much more detail in [AbdelGawad2018b, ; AbdelGawad2018c, ].. We conclude in Section 7 with some final remarks and a brief discussion of some research that can possibly extend the theoretical and practical reach of the research presented in this paper.

2 Partial Cartesian Graph Product

Definition 1.

(Partial Cartesian Graph Product, ). For two directed graphs and where

  • such that and partition (i.e., and ),

  • such that , , , and partition ,

  • and are two disjoint subgraphs of (the ones induced by and , respectively, which guarantees that edges of connect only vertices of and edges of connect only vertices of ), and and connect vertices from to and vice versa, respectively, and

  • is any directed graph (i.e., , unlike , need not have some partitioning of its vertices and edges),

we define the partial Cartesian graph product of and relative to the set of vertices as

(1)

where

  • ( and are the standard Cartesian set product and disjoint union operations),

  • is the standard Cartesian graph product [Hammack2011, ] of and , and,

  • for defining , the operator is defined (implicitly relative to ) such that we have333We may call a “Cartesian disjoint union” (hence the addition-like symbol ), since effects adding or attaching subgraph to the Cartesian product , using edges between and (in ) in the same way as these edges are used to define edges in the Cartesian product .

Notes:

  • As expressed by the definition of the partial Cartesian graph product, each edge in falls under exactly one of four cases: either comes from , or connects to , or connects to , or comes from .

  • The vertices in set are called the product vertices (of ), i.e., vertices that participate in the product , while vertices in its complement, (which we sometimes also write as ), are called the non-product vertices (of ) since these vertices are not paired with vertices of in the construction of .

  • We call a partial graph product since, in comparison with the standard (full/total) Cartesian graph product , the main component of (namely, the component ) is typically the Cartesian product of a proper subgraph (namely, ) of with .

  • Sometimes we omit the subscript and write , assuming is constant and implicit in the definition of (as is the case, for example, when using to model generic OO subtyping).

  • In the partial graph product , if we have then we will have and will be the empty graph, and in this case we have . If, on the other hand, we have then will be the empty graph and we will have , and in this case we have .
    In other words, in case all vertices of are product vertices then, as might be expected, will be the standard Cartesian product of and , while in case all vertices of are non-product vertices then will be just (i.e., graph is disregarded).

Intuition

The intuition behind the definition of is simple. The partial product of two graphs and can be equivalently viewed as either:

  • A graph that is based on the Cartesian product of the subgraph (of ) with that further includes while appropriately respecting how is connected to in (which is the view reflected in our definition of above444It is also the view reflected in our standard SageMath [Stein2017, ] implementation of . (See Appendix A.)), or as

  • Some sort of a special “subgraph” of the graph , the standard Cartesian product of and , where some specified set of vertices of (namely those of ) gets “coalesced” into a smaller set (one isomorphic to ), i.e., where some vertices of (namely, vertices of , i.e., members of ) do not fully participate in the product graph (participate only with their edges)555This was the view reflected in our initial SageMath implementation of . (See Appendix A.).

  • The equivalence of these two informal views of can be proven by showing that the product graphs resulting from the two views are always isomorphic.

3 Partial Graph Product Examples

We illustrate the definition of by presenting the partial Cartesian product of some sample graphs.

(a)
(b)
(c)
Figure 1: Graphs for illustrating

Consider the graphs , and depicted in Figure 1. Figures 2 and 3 present the graphs of some partial products of , and . The reader should ensure he or she sees the product graphs in Figures 2 and 3 as intuitively clear666Even though some better layout of the graphs could make their task even easier..

(a)
(b)
(c)
(d)
(e)
Figure 2: Partial product graphs (layout by GraphViz)
(a)
(b)
(c)
(d)
Figure 3: Partial product graphs (layout by GraphViz)

Appendix A presents the SageMath code we used to help generate the diagrams in Figures 2 and 3.

4 Basic Properties of

In this section we discuss some of the fundamental properties of partial Cartesian graph products, particularly the size and order of constructed graphs.

To calculate the number of vertices and number of edges in partial product graphs, let denote the size (i.e., cardinality) of a set , and for a graph let denote the number of vertices in (usually also called the size of ) and let denote the number of edges (usually called the order of ).

Then, for a graph with size and order , a graph with size and order , and for a set with size and a complement with size that induces a partitioning of such that , (as in Definition 1) and (i.e., ), the number of vertices of the partial Cartesian product graph is expressed by the equation

(2)

while the number of edges is expressed by the equation

(3)

Note that we also have

which could be a more intuitive equation for given that it indicates that edges of the partial product connecting vertices of the product corresponding to get “coalesced” into one edge (i.e., multiedges are disallowed).

For the sake of comparison, for the standard Cartesian product (which is a commutative operation, up to graph isomorphism) we have

As we briefly illustrate in Section 6, the fact that the size of can be smaller than the multiplication of the sizes of and (as in the standard Cartesian graph product) makes perfectly suited for modeling generic OO subtyping.

Note that, in the equations above, we intentionally depart from the more common notation for graph sizes where is used to denote the size of a graph and is used to denote its order, so as to make the equations for sizes and orders of product graphs, particularly Equations (2) and (3), readily memorizable and reminiscent of the graph equations defining the product graphs themselves (e.g., Equation (1)1).

5 Related Work

The closest work to our work in this paper seems to be that of [Yero2015, ]. In [Yero2015, ] a definition of another partial Cartesian graph product operation, denoted , is presented.777We had not known this work existed until after we defined and named it. Driven by our use of the partial Cartesian graph product in constructing the generic OO subtyping relation, our definition of differs from that of presented in [Yero2015, ], as we present below.

5.1 A Comparison of and

First, it should be noted that the order of the factors and in the partial products and is reversed (due to the set being a subset of the vertices of graph , compared to graph graph has a special status in the products, and thus both partial products are non-commutative operations. For both operations, the order of the factors of the products matters).

More significantly, as we explain using equations in the sequel, while and can have the same number of edges, typically has less vertices than .

Using the same notation as that of Section 4, the number of vertices of a partial product graph is expressed by the equation

while the number of its edges is expressed by the equation

Note also that if multiedges were allowed for we would have

and the order of will then be the same as that of (which, when multiedges are disallowed, happens only if has no edges, i.e., when none of the vertices of is connected to another vertex of , sometimes called a discrete graph).

Also it should be noted that the full (i.e., standard) Cartesian graph product can be obtained using either of the two partial Cartesian graph products by setting . This illustrates that, compared to the standard Cartesian graph product, if then the partial product operation decreases both the vertices and the edges of the product while the partial product operation decreases only the edges of the product.

To visually illustrate the difference between and we adapt the example presented in [Yero2015, ] for illustrating . The graph diagrams presented in Figure 4 help illustrate the differences between the two operations we discussed above.

(a)
(b)
(c)
(d)
(e)
Figure 4: Comparing to (layout by SageMath)

Further adding to the differences between and , the main motivation for defining is to apply it in modeling generic OO subtyping, while the motivation behind defining — as presented in [Yero2015, ]—seems to be a purely theoretical motivation, namely, studying Vizing’s conjecture (a famous conjecture in graph theory, relating the domination number of a product graph to the domination number of its factors).

Finally, our choice of the symbol for denoting the partial product operation allows for making implicit while indicating that the product operation is partial. For the notation doing this is not possible, given that the symbol —which will result if is dropped from the notation—is the symbol for the standard Cartesian graph product, i.e., for a different operation.

6 An Application of : Modeling Generic OO Subtyping

Generic types [JLS05, ; JLS14, ; GenericsFAQWebsite, ; AbdelGawad2016a, ; AbdelGawad2016c, ; AbdelGawad2017b, ] add to the expressiveness and type safety of industrial-strength object-oriented programming (OOP) languages such as Java, C#, Scala, Kotlin and other nominally-typed OO programming languages [AbdelGawad2015, ]. As we detail in [AbdelGawad2016c, ; AbdelGawad2017b, ], many models for generics have been proposed, particularly for modeling features such as wildcard types [Torgersen2004, ; MadsTorgersen2005, ; Cameron2007, ; Cameron2008, ; Summers2010, ; Tate2011, ; Tate2013, ; Greenman2014, ]. However, as expressed by their authors, none of these models seem to be a fully satisfactory model.

This situation, in our opinion, is due to these models and the mathematical foundations they build upon distancing themselves (unnecessarily) from the nominal-typing of generic OOP languages and, accordingly, them being unware of the far-reaching implications nominal-typing has on the type systems of these languages and on analyzing and understanding them, which—again, in our opinion—includes analyzing and understanding generics and generic variance annotations (of which wildcard types are instances).

To demonstrate the direct effect of nominal-typing on the Java type system and on generics in particular, we illustrate how the generic subtyping relation in Java can be constructed, using and the subclassing relation (which is an inherently nominal relation, in Java and in all OO languages) based on the nominality of the subtyping relation in Java (i.e., due to the nominal typing and nominal subtyping of Java, the subclassing relation is the basis for defining the subtyping relation).

In brief, with some simplifying assumptions that we detail in [AbdelGawad2017a, ; AbdelGawad2018b, ], the generic subtyping relation in Java can be constructed iteratively using the nominal subclassing relation and the partial Cartesian graph product , as follows.

Let be the graph of the subclassing relation in some Java program. Let be the generic classes subset of classes in. Then the graph of the subtyping relation in the Java program (typically is infinite, if there is at least one generic class in ) can be constructed as the limit of the sequence of graphs of subtyping relations constructed iteratively using the equation

(4)

where is the graph of the containment relation between wildcard type arguments derived from (as explained in [AbdelGawad2018b, ]) and is the one-vertex graph having the default wildcard type argument, ‘?’, as its only vertex and no containment relation edges (again as explained in [AbdelGawad2018b, ]).

It should be noted that Equation (4) tells us that in the construction of the graph of the subtyping relation the generic classes in (i.e., ) correspond to product vertices, while the non-generic classes in correspond to non-product vertices in the partial product graph of each approximation of .888This observation has been a main motivation behind our definition of . This property of preserves non-generic types (and the subtyping relations between them) during the construction of , meaning that non-generic types in remain as non-generic types in , and thus, ultimately, are non-generic types in as well.

6.1 Java Subtyping Example

Figure 5 illustrates the use of to construct the Java subtyping relation. To decrease clutter, given that OO subtyping is a transitive relation, we present the transitive reduction of the subtyping graphs in Figure 5.

The three graphs in Figure 5 illustrate the construction of the subtyping relation of a Java program that only has the generic class definition

class C<T> {}

As defined by Equation (4), the graph of in Figure 5 is constructed as the partial product of the graph of the subclassing/inheritance relation and the graph of (of wildcard types over , ordered by containment) relative to the set of generic classes in .

(a)
(b)
(c)
Figure 5: A simple illustration of the use of to model generic OO subtyping (manual layout using yEd)

More details and examples on the use of to construct the generic OO subtyping relation can be found in [AbdelGawad2018b, ; AbdelGawad2018c, ].

7 Concluding Remarks and Future Work

In this paper we defined a new binary operation on graphs that constructs a partial product of its two input graphs, we presented few examples that illustrate the definition of , and we discussed some of the basic properties of the operation. We also compared the operation to the closest similar work. Finally, we also discussed how the partial graph product operation may be used in understanding the subtyping relation in generic nominally-typed OO programming languages.

As of the time of this writing, we do not know of any other application of the new graph operation we present. Nevertheless, in this paper we presented the partial product operation over graphs in abstract mathematical terms, in the hope that the operation may prove to be useful in other mathematical contexts and domains.

Although we have not done so here, we believe the notion of partial Cartesian graph products, as presented here, can be easily adapted to apply to other mathematical notions such as sets, partial orders, groups (or even categories, more generally). To model infinite self-similar graphs (or groups or categories) we also believe partial products, over graphs, groups, or categories, can in some way be modeled by operads, which are category-theoretic tools that have proved to be useful in modeling self-similar phenomena [spivak2014category, ; AbdelGawad2017a, ].

Finally, studying in more depth properties of partial Cartesian graph products such as the size, order (as we hinted at in Section 5) and rank of elements of the products and of infinite applications of them, is work that can build on work we presented in this paper, and which can be of both theoretical and practical significance, particularly in computer science graph theoretic applications. Also, we believe a notion of ‘degree of partialness’ of a partial product graph999For example, the degree of partialness can be a value (a real number) between 0 and 1, defined possibly as the size of the set of product vertices, , divided by size of the set of all vertices of the first factor graph, (i.e., the degree of partialness of a partial product will be . In this case a degree of partialness with value 1 means the standard Cartesian product, while a value of 0 means no product.) can be a useful notion, even though we do not immediately see an application of this notion.

References

Appendix A SageMath Code

To generate the graph examples presented in this paper we implemented the definition of (as presented in Section 2) in SageMath 8.1 [Stein2017, ]. For those interested, we present in this appendix our SageMath implementation code. The code presented here is not optimized for speed of execution but rather for clarity and simplicity of implementation.

# PCGP
def comp(pv,g):
  """Computesthecomplementofpvrelativeto
␣␣␣␣␣␣verticesofg
␣␣"""
  return filter(lambda v: v not in pv,
                g.vertices())
def PCGP(g1,pv,g2):
  """Computesthepartialcartesianproductof
␣␣␣␣␣␣graphsg1andg2.
␣␣INPUT:
␣␣-“pv”(list)isthelistofproduct
␣␣␣␣verticesing1.
␣␣"""
  # 1st step
  gp = g1.subgraph(pv)
  g = gp.cartesian_product(g2)
  # 2nd step
  npv = comp(pv,g1)
  gn = g1.subgraph(npv)
  g = g.union(gn)
  # 3rd step
  gpn = g1.subgraph(edge_property=
            (lambda e: e[0] in pv and e[1] in npv))
  for u1,u2 in gpn.edge_iterator(labels=None):
    for v in g2:
      g.add_edge((u1,v),u2)
  # 4th step
  gnp = g1.subgraph(edge_property=
            (lambda e: e[1] in pv and e[0] in npv))
  for u1,u2 in gnp.edge_iterator(labels=None):
    for v in g2:
      g.add_edge(u1,(u2,v))
  return g

For convenience, our initial shorter (but equivalent) implementation code for (where GSP stands for ‘Generic Subtyping Product’) is as follows. The code corresponds to the second informal view of the partial Cartesian graph product we presented in Section 2.

# GSP
def GSP(g1, pv, g2):
  g=DiGraph.cartesian_product(g1,g2) # main step
  lnpvc = map(lambda npv: filter(lambda(v,_):
              v==npv, g.vertices()), comp(pv,g1))
  # lnpvc is list of non-product vertex clusters
  # merge the clusters
  map(lambda vc: g.merge_vertices(vc), lnpvc)
  return g

For any two graphs g1, g2 and any list pv (listing the product vertices subset of the vertices of g1) we have

  GSP(g1,pv,g2).is_isomorphic(PCGP(g1,pv,g2))