Proofs: Boyer-Myrvold planarity test
These are the human proofs of Boyer-Myrvold planarity test, at full length.
Correctness of the Boyer-Myrvold planarity test sketch
This proof shows: correctness, termination.
Line numbers refer to the pseudocode on the main page. Vertices are their preorder numbers in the search of line L2. Soundness (an output rotation system is planar) and the main invariant are proved in full. Completeness (if line L7 fails, the graph is not planar) is proved for the Minors A, B and C below; for the remaining cases the proof follows the case analysis of Boyer and Myrvold (2004) and only states it, so this file has the status of a sketch.
Setting
The embedded graph is the set of tree edges and of back edges embedded so far, with each component stored as a rotation system: a cyclic list of edges at each node, read in one direction for the component. A node is a vertex or a root copy . Step means one round of lines L5 to L7. A component is a connected part of that is joined to the rest only through root copies, so its root copy is the only node of it that stands for a vertex outside the subtree .
Fact 1. At the start of step , every back edge with is embedded, and none with is. Every component has the form: a root copy , and a set of vertices of that includes .
Proof. Line L3 creates one component per tree edge. A step embeds only back edges (line L17 with a copy of ), and by line L7 it embeds all of them or the run ends. A merge (line L25) puts a component with root copy , where is a child of a vertex of the component, into the component of , and .
Soundness
Lemma 1. Every component of is a plane embedding at all times, and its external face is the face that lines L12, L15, L19 and L21 walk along.
Proof. By induction over the operations. A new component is one edge, which is planar, and its external face holds both nodes.
Embedding an edge (line L17). When is embedded on side , the walk has reached from along side of the external face, through components that were merged into one just before (the stack is emptied first). So and are both on the external face of one component, and the new edge is drawn in the external face, next to the part of the boundary that the walk went along. A curve in the outer face between two points of its boundary crosses nothing, so the result is plane. The new external face is the old one with the walked part between and replaced by the new edge.
Merging (lines L24 and L25). The root copy is a copy of , and is on the external face of its component. Putting the whole component of into the corner of the external face at , between the edge by which the walk came and the next one, and then identifying with , glues two plane embeddings at one point of their outer faces; this is plane. Its external face is the old external face with the boundary of the component of inserted at .
Flipping (line L24). Reversing every list of a component gives the mirror image of its embedding, which is plane and has the same faces. The code reverses only the list of and records ; the lists of the other vertices of the component are taken as reversed. The walk reads lists from both ends and keeps the side by which it entered each node, so it reads the external face of the true embedding in both cases.
The final join and orientation (lines L8 and L9). Line L8 glues the remaining components at their root copies, as in a merge, which is plane. In the end, a vertex lies in the component that was flipped by every flip on its tree path, and only those: a flip of the component of flips the vertices of that were in it, and later merges carry them along. So the true list of is the stored list reversed exactly when the product of signs from the root to is , which is what line L9 does.
Theorem 1 (soundness). If BM-PLANAR returns a rotation system, then it is a planar embedding of .
Proof. All tree edges are embedded by line L3, and every back edge by line L7 (a back edge is checked at step ). No other edge is ever added, and each edge is added once. By Lemma 1, the result is a plane embedding with every edge of .
The main invariant
Being pertinent or externally active with respect to a step means that has a path to a vertex that is an ancestor of , made of edges that are not embedded yet, apart from tree edges into the subtree of a separate child of .
Lemma 2 (invariant). After step , every vertex that is pertinent or externally active with respect to is on the external face of its component.
Proof. Being active with respect to means having a connection to a vertex , so it implies being externally active with respect to . Activity only goes down as the steps go on, because embedded edges are not counted and the threshold goes down. Before step every component is a single edge, so the claim holds. Assume it holds before step .
A vertex leaves the external face only when an edge is embedded at line L17: the nodes on the walked part of the boundary between the previous point and go inside. Each of these nodes was passed by the walk of this step. The walk passes a node only in three ways: at line L21, which requires it to be not externally active; through line L20, where every node between and the choice is inactive by the definition of "first active node"; or after the node has had its pertinent edges handled and is not externally active (lines L17 to L21 in order). In the last case of line L20, the walk goes down into a child component of ; then stays on the external face, because the merge inserts the boundary of the component of at , and the walked side ends at while the other side comes back to . So every node closed in at step is not externally active with respect to , and so not active with respect to . Nodes in the components that are not touched keep their place.
Lemma 2 also justifies WALKUP: at step , a pertinent vertex is active with respect to , so by Lemma 2 for step it is on the external face of its component, and walking along that face from it reaches the root copy.
Termination
The outer loop has rounds. WALKUP stops at the first node marked in the same step, and every round of its loop marks a new node. In WALKDOWN, every round of line L16 either embeds an edge, merges components, moves to a new node of the external face, or leaves the loop; the walk never passes the root , and a component can be entered from a root copy only while that root copy is in a list of pertinent roots, from which line L25 removes it. Every list operation is bounded by the number of edges. So the run ends.
Completeness
Assume line L7 fails at step : a back edge with for a child of is not embedded after WALKDOWN. For each of the cases below we find a subdivision of or in , so is not planar by Kuratowski's theorem (only the easy direction is used: such a subgraph cannot be drawn without crossings).
Connections. Three kinds of paths outside the current component are used. If is externally active, there is a path from to a vertex that is a proper ancestor of : a back edge from , or a path into the subtree of a separate child of and then a back edge. If is pertinent, there is such a path from to . These paths leave the component only through the subtree of a separate child, or by a single back edge, so paths from different vertices of a component are disjoint except at their ends in the ancestors of . Let be the tree path between the smallest and the largest of the ends ; all of it is below , and the tree path from up to the largest end joins to . In the subdivisions below, is one branch vertex: take the largest end as the vertex and the rest of as parts of the paths into it.
Lemma 3 (end state). One of the following holds.
- (Blocked in a child.) WALKDOWN returned at line L23. Then there is a component whose root copy is a copy of a vertex , two nodes on its external face that are externally active and not pertinent, and a pertinent vertex on the part of the external face of from to that does not contain .
- (Blocked at the root.) Both walks of line L14 stopped at line L22, at for side 0 and at for side 1, with . The component of has a pertinent vertex on the part of its external face from to that does not contain , and all nodes strictly between and , and strictly between and , are inactive.
Proof. In case 1, let be the component of the last entry pushed on . After that push, the walk went to the choice of line L20 and stopped there with not empty. If the choice were pertinent, line L17 would embed an edge and empty , or line L18 would push again. So the choice is not pertinent, and by the choice rule neither is the other first active node; both are active, so both are externally active. The root copy was in a list of pertinent roots, so WALKUP of this step passed through from a pertinent node on its external face (Lemma 2), and was not changed since. That node is not inactive, so it is not between and or between and ; it is not or either. If , every other node on the external face is between and on one side, which is impossible, so . The root copy is a copy of the vertex whose entry was pushed; is in the subtree of , so .
In case 2, the last edge embedded on side 0 closes in everything walked before it, and every node walked after it was passed at line L21, so it is inactive. The walk stopped at , which is externally active and, after its edges were handled, not pertinent; the same holds for side 1. The edge was recorded by WALKUP through a node on the external face of that is pertinent and was never reached by either walk, so it lies on the part from to , and as in case 1.
Minor A. In case 1, contains a subdivision of with parts and .
Proof. has at least 3 nodes, because its external face has , , and , so it is biconnected and its external face is a cycle with the nodes in the order . The nine paths are: and along through , which stands for ; and along ; by ; by the tree path from up to , which is outside except at ; by and by ; and by the tree path. The paths in use disjoint parts of . , and leave through different subtrees or single edges and end below , at , or at ancestors of . The two tree paths use ancestors of that are at least , and ancestors of below it, which are not in . So the paths are internally disjoint.
Minor B. In case 2, if has a pertinent child component that is also externally active, then contains a subdivision of with parts and , where is a vertex in that child's subtree.
Proof. Let be the child of with the pertinent, externally active component. In there is a path to (pertinence) and a path to an ancestor of below (external activity, since ). Both start in , which is connected, so they have a common first part from to a vertex after which they split. The nine paths are: and along , the external face cycle of , through ; and along ; in ; and ; by ; by . They are internally disjoint for the same reasons as in Minor A.
The x-y path. In case 2 without Minor B, Boyer and Myrvold show that has a path between a node on the external face between and (with allowed) and a node between and , with its inner nodes inside , that separates from in . It comes from the boundary of the faces of at , all of whose nodes were walked in step . This is the place where the argument here is a sketch.
Minor C. If (or, the same with and swapped, ), then contains a subdivision of with parts and .
Proof. On the order is , with strictly between and . The paths are: along ; along ; by and then along from to ; , along ; by ; , by , ; and by the tree path. The parts of used are disjoint, is inside , and the other paths are outside .
Minors D and E. If and , Boyer and Myrvold consider a vertex inside . If there is a path inside from to the part of from to , it gives a (Minor D). Otherwise they use the external activity of the vertices on the lower part of and of : if is also externally active the result is a , and in the remaining subcases a (Minor E and its variants). These cases are not reproduced here.
Theorem 2. BM-PLANAR returns a rotation system if and only if is planar. If is not planar it returns nil, and every graph rejected at line L1 is non-planar by the edge bound.
Proof. If it returns a rotation system, is planar by Theorem 1. If is planar, line L1 does not reject it, and line L7 never fails because a failure gives a Kuratowski subgraph by Lemma 3 and the minors.