Manuscript Offprint
arXiv:2610.37018Linear-Time FPT Rectilinear Planarity Testing of Series-Parallel Graphs
Abstract
A planar graph is rectilinear planar if it admits a planar orthogonal drawing without bends. For series-parallel graphs in the variable embedding setting the best known testing algorithm takes time. We show that rectilinear planarity of a series-parallel graph with maximum degree four can be tested in time, where is the number of degree-4 vertices; the planar embedding is not fixed. In particular, the running time is subquadratic when . Each node of the SPQ*-tree stores the set of its admissible spiralities; we show that this set is a union of arithmetic progressions of step two. All proofs are in the paper and are additionally verified in Lean 4 with Mathlib.
1 Introduction
A graph is rectilinear planar if it admits a planar orthogonal drawing without bends; only graphs of maximum degree four (4-graphs) can be rectilinear planar. Rectilinear planarity testing is NP-hard [8]. For partial 2-trees in the variable embedding setting it can be solved in time, and in time when no two parallel components of a biconnected component share a pole [5]. Whether time is achievable for all series-parallel graphs is open.
Theorem 1. Let be a series-parallel 4-graph with vertices, having degree four. Whether is rectilinear planar, over all planar embeddings, can be tested in time.
In particular, if the running time is , which is subquadratic and improves on the bound of [5].
We follow the spirality approach of [5]: each node of the SPQ*-tree gets the set of spiralities its component can take. The bound of [5] comes from these sets not being intervals. Without degree-4 vertices the spirality sets are intervals; degree-4 vertices may break them into several maximal arithmetic progressions of step two (pieces). Our main technical result, the Key Lemma (Lemma 8), shows that a P2-node without degree-4 poles does not increase the number of pieces when the spirality set of one of its children has a single piece; as a consequence, every spirality set has at most pieces (Lemma 11). Storing each set as the list of its pieces, every node is then processed in time. All proofs are given in the paper. The Key Lemma, the combinatorial bounds, the correctness of the algorithm and its cost for a fixed root are additionally verified in Lean 4 with Mathlib (Section 5).
Outline. Section 2 recalls spiralities and the rules of [5]. Section 3 bounds the number of pieces of every spirality set. Section 4 gives the algorithm, first for a fixed root and then for all roots. Section 5 describes the formalization.
(b) SPQ -tree
(a) Graph

Figure 1: (a) A series-parallel 4-graph; u and v have degree four. (b) Its SPQ*-tree, rooted at the top chain: the P3-node with poles u, v is heavy (red), the P2-node with poles a, b is light (blue).
Spirality. Let be a rectilinear representation of and its restriction to . Intuitively, the spirality of measures how much is rolled up between its poles: it counts the right minus left turns along a path from one pole to the other, in units of . Formally [2, 5], for a pole let and be the numbers of edges at inside and outside . The alias vertices of are: itself if ; two dummy vertices subdividing the two edges at outside if ; one dummy vertex subdividing the edge at outside otherwise. A spine is a path from an alias vertex of to an alias vertex of formed by , a simple path in , and ; let be the number of right minus left turns along a spine . The spirality is if each pole has one alias vertex, and otherwise the average of over the two spines through the two alias vertices of a pole (if both poles have two alias vertices, over the two spines on the same side). It does not depend on the chosen path. A pole with two alias vertices contributes the average of two turns, so is half-integral when exactly one pole has two alias vertices, and integral otherwise. Figure 2 shows one example of each case.
Spirality sets. We use doubled spiralities, which are integers, and let be the set of doubled spiralities over all rectilinear representations of . Mirroring a representation exchanges right and left turns; since the embedding is not fixed, every is symmetric, i.e., . Clearly, is finite. For let , , and for let . For example, . The following is [5, Lemmas 1–3] in the doubled scale.
(a) One alias per pole
(b) Two aliases at one pole


Figure 2: A component with poles (solid and dashed edges); dotted edges lie outside and end at the alias vertices (squares); spines are drawn thick. (a) Each pole has two edges inside and one outside , hence one alias vertex: . (b) has two edges inside and two outside , hence two alias vertices: .
Definition 2. -node: .
S-node with children : .
P3-node: iff for some ordering of the children there are , , with .
P2-node with children : iff for one of the two orders of the children there are , and with for and
where whenever or .
Here if and otherwise (text before [5, Lemma 3]). A pole of degree three has , , hence coefficients 1; a pole of degree four has a coefficient , and there (paragraph before [4, Lemma 3]). So all coefficients of a P2-node equal 1 iff it has no pole of degree four. Both poles of a P3-node have degree four.
Test at the root. Let the root be a chain with edges and let be its child.
Lemma 3. G has a rectilinear representation with on the external face iff .
Proof. By [3, Lemma 6] the condition is , where is the number of right minus left turns along . The internal vertices of turn by -1, 0 or 1 each, so ranges over ; double and use the symmetry of Band.
Pieces. Throughout, intervals are intervals of integers: . A run is a set with even. For finite , a piece of is a maximal run contained in , and pieces is the number of pieces of . For example, has the three pieces , and , so pieces . Similarly, pieces is the number of maximal intervals contained in ; for example, pieces( ) = 2. In particular, pieces iff , and pieces iff is a nonempty interval. If all elements of are even, then pieces .
3 Bounding the Number of Pieces
Light and heavy P-nodes. A P2-node is light if all its coefficients are 1, i.e., it has no pole of degree four; all other P-nodes are heavy. In Figure 1, the P3-node with poles u, v is heavy and the P2-node with poles a, b is light. A subtree is light if it has no heavy P-node, and heavyP( ) is the number of heavy P-nodes in the subtree of . Heavy P-nodes are the only places where the number of pieces can grow by more than a constant; the next lemma bounds how many there are.
Lemma 4. heavyP(T) ≤ 2k, for every choice of the root.
Proof. Every heavy P-node has a pole of degree four, and a vertex w of degree four is a pole of at most two P-nodes. Indeed, a P-node with pole w contains at least two edges of w, and at least one edge of w lies outside it, since the root is a chain. Two P-nodes with pole w either contain disjoint sets of edges of w, or one contains the other, and then it contains strictly more edges of w, since it has a further child incident to w. Hence three P-nodes with pole w would give w degree at least five.
The Key Lemma (below) is a statement about the maximal intervals of sets of integers. To apply it to a light P2-node we halve the doubled spiralities of its children, which requires them to be even.
Lemma 5. If is a light P2-node with children , all elements of and are even.
Proof. Let be the poles of . Since is light, all its coefficients equal 1, that is, for each child and each pole . Hence, in , each pole has a single alias vertex, namely itself, and by the definition of spirality every spirality of is an integer.
The Key Lemma also requires one of the two children to have an interval as spirality set. This holds whenever the subtree of that child is light; P3-nodes need not be considered, since they are always heavy.
Lemma 6. If the subtree of is light, then or for some .
Proof. By induction on the subtree of , which contains no P3-node, since P3-nodes are heavy. For -nodes the claim is Definition 2, and for S-nodes it follows from . For a light P2-node whose children have spirality sets and , [4, Table 1], taking the union over the two orders of the children, gives with if , and otherwise.
The Key Lemma. The Key Lemma is a statement about finite sets of integers. Let . For , let be the set of values with , , , and angle variables as in Definition 2, and let . Thus is the spirality set of a light P2-node whose children have spirality sets 2A and 2B, and corresponds to one fixed order of the children. See Figure 3 for an example. The following lemma describes on intervals; it is the only place where the angle variables enter the proof of the Key Lemma.
Lemma 7. Let be an interval. Then if and only if some satisfies
Consequently, is an interval, and if , it contains 0.
Proof. The characterization is a direct check on the angle variables. Thus each yields an interval contained in , and consecutive values of yield overlapping intervals, so their union is an interval. If , some satisfies ; then satisfies the conditions above with , so .
Lemma 8 (Key Lemma). If A is finite and symmetric, then pieces( ) pieces(A).
Proof. The idea is to remove the two outermost maximal intervals of A, which are mirror images of each other, show that together they contribute at most two pieces to , and handle the rest by induction on pieces(A). We use two simple observations.
(i) If is symmetric, mirroring exchanges the two orders of the children: and .
(ii) Every value of comes from a single element of , so distributes over union; moreover, pieces .
Base cases. If pieces(A) = 0, then and . If pieces(A) = 1, with . By Lemma 7, is empty or an interval containing 0, and so is its mirror image; by (i), is their union, which has at most one piece.
Inductive step. Let pieces(A) ≥ 2 and assume the claim for every finite symmetric set with fewer pieces. Let be the maximal interval contained in A that contains ; by symmetry, is the maximal interval contained in A that contains . These two intervals are disjoint, as otherwise would have one piece. It immediately follows that . Since by maximality and by symmetry, the two outermost intervals are separated from the rest , which is symmetric. Hence and pieces(A) = pieces(A') + 2. By (i) and (ii),
where and collect the contribution of the two outermost intervals. We claim that is an interval. Both terms are intervals by Lemma 7. If the second term is nonempty, some satisfies in the characterization of Lemma 7, so ; then the characterization holds for and for , so both terms contain . Hence and contribute at most two pieces, and since pieces() = pieces() - 2, the inductive hypothesis applied to and (ii) give pieces() pieces() + 2 = pieces().
Corollary 9. Let be a light P2-node whose child roots a light subtree. Then pieces pieces .
Proof. The corollary rewrites the Key Lemma in terms of spirality sets. By Lemma 6, is either empty, and then so is , or equal to . By Lemma 5, for a symmetric . Hence . Doubling a set turns maximal intervals into pieces, i.e., pieces , so the claim is exactly Lemma 8.
Other compositions. For finite write . Outside the case covered by Corollary 9, we only need a crude bound on how much each rule can increase the number of pieces.
Lemma 10. Let be finite. Then pieces. Moreover, for any coefficients, the -rule applied to yields at most pieces, and the -rule applied to yields at most pieces.

3 pieces
Figure 3: A symmetric set A with three pieces (top) and (bottom), which also has three pieces, as guaranteed by the Key Lemma.
Proof. We use two simple facts: (i) a shift has the same number of pieces as ; (ii) pieces and pieces , since a piece of or of starts at some with missing from or from , so is the first element of a piece of or of .
S-rule. is the union of the sums of a piece of and a piece of . The sum of and is , so by (ii) has at most pieces.
P2-rule. Once the order of the two children and the values of the angle variables are fixed, the rule constrains the spirality of each child to be a fixed shift of the spirality of ; hence the admissible values form a set , which by (i) and (ii) has at most pieces. There are 9 admissible angle assignments and 2 orders, so by (ii) the P2-rule yields at most pieces.
P3-rule. For each of the 6 orderings of the children, the rule yields , which by (i) and (ii) has at most pieces; by (ii), the union over the orderings has at most pieces.
Global bound. We now combine the previous lemmas along the SPQ*-tree. A light subtree contributes at most one piece, and the number of pieces can grow only at the following nodes, which we call costly: heavy P-nodes, light P2-nodes whose two children both root non-light subtrees, and S-nodes with at least two children rooting non-light subtrees. Let costly( ) be the number of costly nodes in the subtree of .
Lemma 11. For every node , pieces .
Proof. First inequality. We proceed by induction on the subtree of . If the subtree of is light, then costly( ) = 0 and, by Lemma 6, is empty or Band( ) = 2B_c, which has one piece. Otherwise, for each child of write ; by induction, pieces .
-
If is an S-node, applying Lemma 10 repeatedly gives pieces .
-
If is a light P2-node with a child, say , rooting a light subtree, then is not costly and costly ; by Corollary 9, pieces .
-
Otherwise is a costly P-node, and Lemma 10 gives at most pieces for a P2-node and at most for a P3-node, using . In both cases the bound is .
Second inequality. We show costly( ) 2 heavyP( ) - 1 whenever the subtree of is not light; for light subtrees both counts are 0. Write and ; by induction,
for the children rooting non-light subtrees and for the others, so for all children.
-
At a heavy P-node, heavyP( ) = , so costly( ) = heavyP( ) - 1.
-
At a light P2-node with a child rooting a light subtree, both counts equal those of the other child.
-
At a light P2-node with two non-light children, costly( ) = heavyP( ) - 1.
-
At an S-node with non-light children, the node itself counts only if , so, summing over the non-light children only, costly( ) heavyP( ) - heavyP( ) - 1 when , and costly( ) heavyP( ) - 1 directly when .
Third inequality. It follows from heavyP( ) (Lemma 4).
4 The Algorithm
Representation. A finite is stored as the sorted list of its pieces, each piece being given by its endpoints and ; the list has length pieces. A shift of a set of this form, and the sum of two such sets, are again of this form, and the intersection of two such sets is of this form or empty; so every operation first computes the result as a union of such sets and then merges them into the list of pieces. The rules of Definition 2 are evaluated as in the proof of Lemma 10: S as iterated sums, P2 as the union over 2 orders and 9 admissible angle assignments of intersections of shifted lists, and P3 as the union over 6 orderings of .
Lemma 12. For every node , the computed list is the list of pieces of , and its length is at most heavyP( ).
Proof. Each operation is correct by the description above, and the length bound is Lemma 11. ☐
Running time for a fixed root. Operations on integers have unit cost. Let ; by Lemma 11, every set has at most pieces, so its list has at most elements. The rule of a P-node is a constant number of shifts, unions and intersections. The rule of an S-node with children computes sums; each partial sum has at most pieces, as in the S-node case of the proof of Lemma 11. All intermediate lists have length polynomial in , and each operation, including the final merge, takes time polynomial in the lengths of its inputs. Hence a node with children costs .
Lemma 13. For a fixed root of T, all lists are computed in time.
Proof. Summing over the nodes of , whose numbers of children add up to , gives .
Test at the root. By Lemma 3, the test for the root chain computes and checks whether it contains 8, in further time.
Variable root and external face. For a node of , let denote the spirality set of when is rooted at . Testing every root separately costs . To avoid this we use the reusability principle of [6], in the form of [7, Lemma 5.11], which we state for our setting.
Lemma 14. Let be nodes of . Assume that, for every node with children in the rooting at , the set is computed from the sets of its children with operations if , and with operations if . Then are computed with operations.
We apply it taking the operations on lists as elementary operations; since each of them costs , as shown below, this gives time.
A P-node has at most four neighbours in , since its poles have degree at most four; hence its set is recomputed with operations, and its coefficients, which depend only on the degrees of its poles, in time. For an S-node with children in the first rooting, the first traversal also stores the prefix sums and the suffix sums , with operations. When becomes the parent, the new set is the sum of the prefix up to , the suffix from , and the set on the side of the old parent: operations. Each prefix or suffix sum is a partial sum of an S-node, so it has at most pieces as in the running-time analysis, and the other sets are spirality sets , bounded by Lemma 11 in the rooting at . Hence each list has length at most , and each operation costs .
Proof of Theorem 1. Compute in time [9]. By Lemmas 13 and 14, the sets required by Lemma 3 for all root chains are computed in time. Every external face contains a chain, so all choices of the external face are covered.
5 Formal Verification
The formalization is a single Lean 4.35.0 file with Mathlib v4.35.0, available at
https://github.com/GiacomOrtali/rectilinear-sp-linearfpt-lean.
-trees are an inductive type (-nodes with their length, S-nodes with a list of children, P2-nodes with four integer coefficients , P3-nodes), and is defined by the rules of Definition 2. The file contains no sorry, and #print axioms reports only propext, Classical.choice, Quot.sound.
| Statement | Lean |
|---|---|
| Lemma 8 (Key Lemma) | KeyLemma.key_lemma |
| Symmetry and finiteness of | T1_1, T2_0 |
| Lemma 6 | T1_2, T1_3 |
| Corollary 9 | T2_1 |
| Lemma 10 | T3_1–T3_4 |
| Lemma 11 | T4_0–T4_3, T5_0–T5_2 |
| Lemma 12 | T6a_1–T6a_3, T6a’_1–T6a’_4 |
| Lemma 13 | T6b |
| Root test | T6d_1, T6d_2 |
Table 1: Paper statements and formal theorems.
Not formalized: that the rules of Definition 2 give exactly the spiralities of rectilinear representations, and the equivalence of Lemma 3 between rectilinear planarity and the test
, which Lean only evaluates; both are taken from [5, 3]; Lemma 5, which enters as the hypothesis WF; Lemma 4, the formal bounds being stated in terms of heavyP; the root chain of length , which reduces to T6d_1 on the S-node whose children are and a Q*-node of length ; the re-rooting step; the construction of T. The formal cost model counts unit-cost integer operations.
6 Conclusions and Open Problems
We showed that rectilinear planarity of series-parallel 4-graphs, in the variable embedding setting, can be tested in time, where is the number of degree-4 vertices. In particular, if the running time is , which is subquadratic and improves on the bound of [5]. The key ingredient is the Key Lemma: light P2-nodes with a light child do not increase the number of pieces of spirality sets. This fact and the other combinatorial bounds are verified in Lean.
Our analysis actually gives a running time of , where is the number of heavy P-nodes. It is natural to ask whether the parameter can be restricted to the number of P3-nodes alone. This would follow if P2-nodes with degree-4 poles did not increase the number of pieces, as light P2-nodes do by the Key Lemma; we do not know whether this holds. Another direction is to improve the running time: the factor comes from a crude bound on the P2- and P3-rules, and a finer analysis of how pieces merge may lead to a polynomial dependence on .
Two further extensions seem within reach of known techniques, but remain to be worked out. The first concerns partial 2-trees, which need not be biconnected: as in [5], one can combine the biconnected components along the block-cut tree, and the question is whether the bound on the number of pieces is preserved through this combination. The second is bend minimization: instead of a set of spiralities, each node stores the minimum number of bends for each spirality, as done in [4, 7], and one should check that the cost functions inherit a piecewise structure with pieces.
Declaration of AI Use
The author used ChatGPT (OpenAI) and Claude (Anthropic) as assistants in developing and checking proofs, in writing the Lean formalization, and in editing the text.
References
[1] Giuseppe Di Battista, Peter Eades, Roberto Tamassia, and Ioannis G. Tollis. Graph Drawing: Algorithms for the Visualization of Graphs. Prentice-Hall, 1999.
[2] Giuseppe Di Battista, Giuseppe Liotta, and Francesco Vargiu. Spirality and optimal orthogonal drawings. SIAM Journal on Computing, 27(6):1764–1811, 1998. doi:10.1137/S0097539794262847.
[3] Emilio Di Giacomo, Walter Didimo, Giuseppe Liotta, Fabrizio Montecchiani, and Giacomo Ortali. On the parameterized complexity of bend-minimum orthogonal planarity, 2023. Version 3; GD 2023. arXiv:2308.13665.
[4] Walter Didimo, Michael Kaufmann, Giuseppe Liotta, and Giacomo Ortali. Computing bend-minimum orthogonal drawings of plane series-parallel graphs in linear time, 2022. arXiv:2205.07500.
[5] Walter Didimo, Michael Kaufmann, Giuseppe Liotta, and Giacomo Ortali. Rectilinear planarity of partial 2-trees. Journal of Graph Algorithms and Applications, 27(8):679–719, 2023. arXiv:2208.12558, doi:10.7155/jgaa.00640.
[6] Walter Didimo, Giuseppe Liotta, Giacomo Ortali, and Maurizio Patrignani. Optimal orthogonal drawings of planar 3-graphs in linear time. In Proceedings of the 2020 ACM-SIAM Symposium on Discrete Algorithms (SODA 2020), pages 806–825. SIAM, 2020. doi:10.1137/1.9781611975994.49.
[7] Walter Didimo, Giuseppe Liotta, Giacomo Ortali, and Maurizio Patrignani. Optimal orthogonal drawings in linear time, 2025. Version 1. arXiv:2502.03309.
[8] Ashim Garg and Roberto Tamassia. On the computational complexity of upward and rectilinear planarity testing. SIAM Journal on Computing, 31(2):601–625, 2001. doi:10.1137/S0097539794277123.
[9] Carsten Gutwenger and Petra Mutzel. A linear time implementation of SPQR-trees. In Joe Marks, editor, Graph Drawing (GD 2000), volume 1984 of LNCS, pages 77–90. Springer, 2000. doi:10.1007/3-540-44541-2_8.