Proofs: Doubly connected edge list
These are the human proofs of Doubly connected edge list, at full length.
The doubly connected edge list represents a connected plane graph and its faces full
This proof shows: correctness, termination.
We use the pseudocode of the page. A half-edge is live if it has not been freed. For a live half-edge , write . For a vertex with at least one edge, let be the map on the half-edges out of given by ; this is the rotation that line L8 reads. The structure is valid if:
- (I1) and restricted to the live half-edges are permutations, and for each live .
- (I2) for each live .
- (I3) exactly when and lie on the same cycle of , and lies on the cycle with label , for each face that exists.
- (I4) is a live half-edge with origin , or nil if has no edge.
- (I5) The graph is connected, and there is a drawing of it in the plane whose rotation at each vertex (the counterclockwise order of its edges) is and whose faces are, one for one, the cycles of , the face of a cycle being the face that lies to the left of its half-edges.
Lemma 1 (face tracing). Let be a rotation system of a graph, and let map the dart to , where is the neighbour just before in . Then is a permutation of the darts, and the inverse sends to where is the neighbour just after in . If is the rotation system of a drawing of a connected plane graph, the cycles of are exactly the boundary walks of the faces, each traversed with its face on the left.
Proof. Given , the dart with must have just before in , so is the unique neighbour just after . So is one-to-one on a finite set, hence a permutation. The second part is the face tracing theorem for rotation systems (Mohar and Thomassen, Chapter 3; see rotation system).
Lemma 2 (BUILD). If is the rotation system of a drawing of a connected plane graph with vertices and edges, BUILD stops after dictionary operations and returns a valid structure.
Proof. Lines L1 and L2 create one pair of half-edges for each edge, since a pair is created only when has none, and each edge appears as . Line L4 sets and , so (I1) holds by Lemma 1, and (I2) holds since starts at . Lines L5 and L6 label each cycle of : the walk of line L6 stops when it reaches again, which it does because is a permutation, and each step labels one half-edge that had no label, so the number of unlabeled half-edges drops by 1 at each step and lines L5 and L6 take steps in all. This gives (I3). The code sets to a half-edge out of , so (I4) holds. For (I5), take the drawing of . For a half-edge , where is just after in by Lemma 1, so is the next half-edge out of counterclockwise, and is the rotation of the drawing. The faces are the cycles of by Lemma 1.
Lemma 3 (walks). In a valid structure, NEIGHBOURS() outputs the neighbours of in counterclockwise order, each once, and stops after steps; FACE-BOUNDARY() outputs the cycle of and stops after steps.
Proof. By (I5), is a cyclic order of the half-edges out of , one cycle of length . Line L8 applies from , which starts at by (I4), and stops on its return, so it lists each half-edge out of once, and their targets in counterclockwise order. Line L9 follows from , which lies on the cycle of by (I3), and stops on its return, after one round of that cycle.
Lemma 4 (SPLIT-FACE). Let the structure be valid, with , , and not adjacent. After SPLIT-FACE(, ), the structure is valid, with one more edge and one more face.
Proof. Let the cycle of be , so and follows . Line L11 changes only at , , and , and sets , , , . So the new cycles through these half-edges are and . They partition the old cycle plus and , and all other cycles are unchanged. Line L11 sets at the same four places, so (I1) holds. For (I2): , , because was , and because was . Line L12 gives the cycle of the new label and the label ; the other half-edges of the cycle of keep , so (I3) holds. Vertex records are unchanged, so (I4) holds.
For (I5): by (I5) before the split, the face of the drawing that belongs to the cycle of has both and on its boundary. Since is an open connected set, there is a simple arc from to through that leaves in the angle of between the edge of and the edge of , and enters in the angle between the edge of and the edge of . Add it as the new edge. The value changes only for half-edges out of whose changed. These are , with and so , and the new , with and so , the old value of . So the new rotation at is the old one with inserted right after , in the angle between and , which is the corner of where the arc leaves . In the same way, and , so is inserted right after at . So the new drawing has rotation . The arc splits into two faces, by the Jordan curve theorem applied to the closed curve made of the arc and a boundary path of from back to , and the faces to the left of and of are bounded by the two new cycles. All other faces are unchanged. The graph stays connected.
Lemma 5 (ADD-LEAF). In a valid structure, after ADD-LEAF() the structure is valid, with one more vertex, one more edge and the same number of faces.
Proof. Let . Line L13 sets , , , so the cycle of gains between and and no other cycle changes; (I1) holds. (I2): , , . Both new half-edges get the face of , so (I3) holds, and the code sets of to and of to , so (I4) holds. In the drawing, put in the face of near and join them by a short arc in the angle between the edge of and the edge of ; as in Lemma 4, the rotation at gains next to , the rotation at is the single half-edge , and the face keeps one boundary walk, now with in it. The empty case ( nil, one vertex and no edge) makes the cycle , the drawing of one edge, with one face.
Lemma 6 (JOIN-FACES). Let the structure be valid and for . After JOIN-FACES(), the structure is valid, with one edge and one face fewer.
Proof. The cycles of and are different, so neither nor is or , and the same for . Write the cycles as and with , where , , and likewise for . Line L15 sets and , so the two cycles become the one cycle , and (I1) holds on the live half-edges. (I2): and . Line L14 gives all of the label of , and of that face becomes , so (I3) holds. If , it becomes , which starts at and is live because ; the same for , so (I4) holds.
For (I5), erase the edge of from the drawing. Its two sides are the faces of the two cycles, which are different, so the open arc of the edge joins two different faces into one, and the boundary walk of the union is the merged cycle. The rotation at loses . Before the deletion, and . After it, , so , and is cut out of the cycle of . In the same way, changes from to at , so is cut out there. These are the rotations of the drawing without the edge. It remains to see that the graph stays connected. Let have vertices, edges and faces, so . The drawing of has edges and faces, and if it has components, Euler's formula for several components gives , so .
Theorem. Starting from BUILD on the rotation system of a connected plane graph, or from the empty structure with one vertex, every sequence of operations whose preconditions hold keeps the structure valid, every walk outputs what its specification says, and every operation terminates. In particular after each operation.
Proof. The empty structure (one vertex, no half-edge, one face with no half-edge) is valid. By Lemmas 2, 4, 5 and 6, each operation keeps validity, and by Lemma 3 the walks are correct. Each loop walks along a cycle of a permutation of a finite set and stops at its start, so each loop runs at most once around that cycle. Euler's formula holds for the drawing of (I5), and its faces are the cycles of by (I5).