<strong>Type</strong> <strong>Graph</strong>s 16Lemma 1 If G ∼ G ′ and a −→ n ∈ G, there exists a −→ n ′ ∈ G ′ and G n ∼ G ′ n ′ .Proof. By induction on the length of a.□We extend the transitive closure of the ⊲ relation to type equivalent rooted graphs.Definition 7 (Subclass) A rooted graph G ′ is a subclass of a rooted graph G, denoted as G ′ G, if∃ ⊲ −→ ∗ n ∈ G ′ • G ′ n ∼ G.3.4 Checking <strong>Type</strong> EquivalenceGiven two rooted graphs X and Y , we check if X and Y are equivalent by using the functiont-eq(X, Y ). The function traverses the two graphs and generates a set Q = (s, t) of pairs. Each(s, t) of the pairs consists of two sets s and t of nodes of X and Y , respectively. Starting with({X.}, {Y.}), each next step checks the targets of the outgoing edges, that have identicallabels, of nodes in each pair of sets already generated. If the node of X (or Y ) being visitedwas visited be<strong>for</strong>e in step i, the corresponding nodes of Y (or X, respectively) being visited areadded to the set of nodes of Y (or X, respectively) in the pair generated in step i; otherwise, anew pair of sets containing these nodes respectively is generated. The traverse terminates whenthere exists a pair (s, t) <strong>for</strong> that the set of labels of the outgoing edges of s is different from thatof t. In this case, the checking function returns false. Otherwise, the checking terminates whenall nodes are visited and the checking function returns true along with the generated set Q ofpairs, if and only if, <strong>for</strong> any pair (s, t) in Q, s and t contain only structural nodes, or are bothsingletons and equal.Table 2 shows the definition of the auxiliary function t-eq 0 . The definition is given by a list ofinference rules, evaluated from the first one. If, <strong>for</strong> a rule, all the conditions above the line hold,the evaluation reduces to the part of the rule below the line, otherwise the next rule is furtherevaluated. We define the t-eq function based on t-eq 0 ast-eq(X, Y ) ̂= t-eq 0 (X, Y, {({X.}, {Y.})}) .If t-eq(X, Y ) returns (Q, true), X and Y are equivalent and we can construct the graph G r fromQ that both X and Y are reducible to. For a pair ({C}, {C}) in Q, where C is nominal, G r hasnode C. And <strong>for</strong> a pair of sets (s, t) of structural nodes in Q, G r has a corresponding structuralnode n that represents all the equivalent nodes in the pair. The outgoing edges of n correspondto the outgoing edges of the equivalent nodes in s and t.Report No. 448, June 2011UNU-IIST, P.O. Box 3058, Macao
<strong>Type</strong> Operations 17Table 2: <strong>Type</strong> Equivalencet-eq 0 (X, Y, Q) ̂=(s, t) ∈ Q x ∈ s y ∈ t x −→ a x ′ ∈ X x ′ /∈ Q.sy −→ a y ′ ∈ Y y ′ ∈ t ′ (s ′ , t ′ ) ∈ Q y −→ a y ′ ∈ Y y ′ /∈ Q.tt-eq 0 (X, Y, Q {(s ′ , t ′ )} ∪ {(s ′ ∪ {x ′ }, t ′ )} t-eq 0 (X, Y, Q ∪ {({x ′ }, {y ′ })})false(s, t) ∈ Q x ∈ s y ∈ t y a −→ y ′ ∈ Y y ′ /∈ Q.tt-eq 0 (Y, X, {(v, u) | (u, v) ∈ Q})(s, t), (s ′ 1, t ′ 1), (s ′ 2, t ′ 2) ∈ Q(s ′ 1, t ′ 1) ≠ (s ′ 2, t ′ 2) x 1 , x 2 ∈ s x 1a−→ x′1 , x 2a−→ x′2 ∈ X x ′ 1 ∈ s ′ 1 x ′ 2 ∈ s ′ 2t-eq 0 (X, Y, Q {(s ′ 1, t ′ 1)} {(s ′ 2, t ′ 2)} ∪ {(s ′ 1 ∪ s ′ 2, t ′ 1 ∪ t ′ 2)})(s, t), (s ′ 1, t ′ 1), (s ′ 2, t ′ 2) ∈ Q(s ′ 1, t ′ 1) ≠ (s ′ 2, t ′ 2) y 1 , y 2 ∈ t y 1a−→ y′1 , y 2a−→ y′2 ∈ Y y ′ 1 ∈ t ′ 1 y ′ 2 ∈ t ′ 2t-eq 0 (X, Y, Q {(s ′ 1, t ′ 1)} {(s ′ 2, t ′ 2)} ∪ {(s ′ 1 ∪ s ′ 2, t ′ 1 ∪ t ′ 2)})(s, t) ∈ Qn 1 ≠ n 2n 1 , n 2 ∈ s ∪ t{n 1 , n 2 } Sfalse(s, t) ∈ Q x ∈ s y ∈ t{a | x a −→ · ∈ X} ≠ {b | y b −→ · ∈ Y }false (Q, true) ,where Q is a set of pairs and each pair consists of two sets of equivalent nodes, Q.s = ⋃ (s,t)∈Q s andQ.t = ⋃ (s,t)∈Q t.4 <strong>Type</strong> OperationsIn an rcos/g program, types are specified by type expressions. Besides atomic type expressions,such as primitive types, classes and type variables, a type expression also consists of typeoperations.We have two type operations, class conjunction and class instantiation. Since types are representedby rooted graphs, type operations are defined in terms of graph operations. In thissection, we define conjunction graphs and instantiation graphs <strong>for</strong> class conjunctions and classinstantiations, respectively.The graph operations share a common idea — the result graph is constructed by introducing newstructural nodes and new edges pointing into the operand graphs without changing any existingrooted graphs.Report No. 448, June 2011UNU-IIST, P.O. Box 3058, Macao