Professional Documents
Culture Documents
Ruler Folding Problem Paper
Ruler Folding Problem Paper
Abstract
A carpenter’s ruler is a ruler divided into pieces of different lengths which are hinged where the
pieces meet, which makes it possible to fold the ruler. The carpenter’s ruler folding problem, origi-
nally posed by Hopcroft, Joseph and Whitesides, is to determine the smallest case (or interval on the
line) into which the ruler fits when folded. The problem is known to be NP-complete. The best pre-
vious approximation ratio achieved — from 1985 — is 2. We improve this result and provide a fully
polynomial-time approximation scheme for this problem. In contrast, in the plane, there exists a simple
linear-time algorithm which computes an exact (optimal) folding of the ruler in some convex case of
minimum diameter. This brings up the interesting problem of finding the minimum area of a convex
universal case (of unit diameter) for all rulers whose maximum link length is one.
Keywords: approximation scheme, carpenter’s ruler, folding problems, universal case.
1 Introduction
The carpenter’s ruler folding problem is: given a sequence of rigid rods (links) of various integral lengths
connected end-to-end by hinges, to fold it so that its overall folded length is minimum. It was posed by
Hopcroft et. al. in [6]. They proved the problem is NP-complete using a reduction from the NP-complete
2
problem PARTITION (see [4, 2]). A simple linear-time factor approximation algorithm, as well as a
( )
pseudo-polynomial O L2 n time dynamic programming algorithm, where L is the maximum link length,
where presented in [6] (see also [12]). A physical ruler is idealized in the problem, so that the ruler is
allowed to fold onto itself and lie along a line segment whose length is the size of the case, and thus no
thickness results from the segments which lie on top of each other.
The decision problem can be stated as follows. Given a ruler whose links have lengths l1 ; l2 ; : : : ; ln ,
can it be folded so that its overall folded length is at most k ? Note that different orderings of the links can
66 3
result in different minimum case lengths. For example if the ruler has links of lengths , and in this
6 63 6
order, the ruler can be folded into a case of length , but if the links occur in the order , and , then the
optimal case-length is . 9
19
Our first result (Section 2) improves the -year old factor approximation: 2
Theorem 1 There exists a fully polynomial-time approximation scheme for the carpenter’s ruler folding
problem.
A fully polynomial-time approximation scheme (FPTAS) for a minimization problem is a family of algo-
0
rithms A , for all > , such that A has running time polynomial in the size of the instance and =, and 1
the output of A is at most (1 + )
times the optimum [4].
Department of Computer Science, Illinois Institute of Technology, Chicago, IL 60616, USA. Email: calinesc@iit.edu.
y
Computer Science, University of Wisconsin–Milwaukee, 3200 N. Cramer Street, Milwaukee, WI 53211, USA. Email:
ad@cs.uwm.edu
1
In Section 3, we study a natural, related question: the condition that the folding must lie on a line is
relaxed, by considering foldings in the plane with the objective of minimizing the diameter of a convex
case containing the folded ruler. Here foldings allow for a free reconfiguration of the joint angles, with the
proviso that each link of the ruler maintains its length (the shape of the case is unconstrained). In contrast
with the problem on the line, this variant admits an easy exact (optimal) solution which can be computed
in linear time, using exact arithmetic.
This brings up the interesting problem of finding the minimum area of a convex case (of unit diameter)
for all rulers whose maximum link length is one. A closed curve of unit diameter in the plane is said to be
a universal case for all rulers whose maximum link length is one, if each such ruler admits a planar folding
inside the curve. Our results are summarized in:
()
Theorem 2 There exists an O n algorithm for the carpenter’s ruler folding problem in the plane with
= max(
lengths l1 ; l2 ; : : : ; ln , which computes a folding in a convex case of minimum diameter L l1 ; : : : ; ln .)
The minimum area A of a convex universal case (of unit diameter) for all rulers whose maximum link length
is one satisfies p
3 A 3
8 3 4:
The lower bound is = 3 8 = 0 375 0 614
: and the upper bound is : . We believe the latter is closer to the
truth.
Other folding problems with links allowed to cross have been studied, for example in [5, 8, 9, 10, 14],
while linkage folding problems for non-crossing links have been investigated for example in [1, 13]. For
other universal cover problems, e.g., the worm problem, see [3, 11] and the references therein.
2 Proof of Theorem 1
We present two approximation schemes: one based on trimming the solution space and one based on
rounding and scaling. We start with notation and observations which apply to both algorithms.
A folding F of the ruler can be specified by the position on the line of the first (free) endpoint of the
ruler (i.e., the free endpoint of the first link) and a binary string of length n in which the i-th bit is 1
1
(resp. ) if the i-th segment is folded to the left (resp. right) of its fixed endpoint (view this as a sequential
process). We call this binary string the folding vector.
For a given folding F , let the interval IF =[ ℄
aF ; bF be the smallest closed interval which contains it
(i.e., it contains all the segments of the ruler). We refer to it as the folding interval. See also Figure 1.
132 4
Figure 1: A carpenter’s ruler with segments of length , , and folded so that it fits into a case of length
5 ( 1 1 1 1)
(left). Its folding vector is ; ; . Another folding into a case of same length (right). Its folding
(1 1 1 1)
vector is ; ; .
Denote by OP T the minimum folded length for a ruler with lengths l1 ; l2 ; : : : ; ln . A trivial lower
2
bound — on which the -approximation algorithm is based — is OP T L, where L is the maximum rod
length: L = max( ) 2
l1 ; l2 ; : : : ; ln . We further exploit this observation and the -approximation algorithm
given in [6].
2
Observation 1 An optimal solution can be computed by fixing the first segment at ; l1 (with the free [0 ℄
0
endpoint of the first link at ), and then computing all foldings that extend it, whose intervals have length
2
at most L (thus are included in the interval [ 2 + 2 ℄
L l1 ; L ).
Proof. Consider an optimal solution. Clearly the first segment can be fixed at any given position of its
free endpoint and at any of the two possible orientations. Since there exist approximate solutions whose
2
folding intervals have length at most L, foldings with larger intervals do not need to be considered (are
not optimal). 2
One can also see that the observation can be somewhat strengthened, since in fact, any of the links can
be fixed at a given position and orientation.
Observation 2 An optimal solution can be computed by first fixing one segment of length L (if more exist,
[0 ℄
select one arbitrarily) at ; L and then computing all foldings that extend it, whose intervals have length
2
at most L (thus are included in the interval L; L ). [ 2 ℄
( )
Consider a folding F , whose vector is 1 ; : : : ; n , for a given ruler l1 ; l2 ; : : : ; ln . For i =1
; : : : ; n,
( )
let the partial folding Fi of the ruler l1 ; l2 ; : : : ; li be that whose folding vector is 1 ; : : : ; i .
[ ℄
For a folding F whose interval is a; b , clearly the endpoint x of the last segment also lies in the same
[ ℄
interval, i.e., x 2 a; b . We say that F has parameters a, b and x, or that F is given by a, b and x.
3
(
Let now F be an optimal folding as specified in Observation 1, whose vector is 1 ; : : : ; n . We have )
1=1 . For i =1 [
; : : : ; n, let the partial folding Fi have the (folding) interval ai ; bi and the ℄
Piendpoint of
[ ℄
the last segment at xi 2 ai ; bi . We have a1 =0
, b1 =
l1 and x1 l1 , and also xi = =
j =1 j lj , for
=1
i ; : : : ; n.
Lemma 1 For i = 1; : : : ; n, the algorithm computes a partial folding F 0 2 F i of the ruler l1 ; l2 ; : : : ; li ,
[a0 ; b0 ℄ and the endpoint of the last segment is at x0 , so that
i
whose interval is i i i
ai = min(a 1 ; x 1 + l );
i i i i
bi = max(b 1; x 1 + l );
i i i i
xi = x 1+ l :
i i i
Consider the partial folding Fi00 obtained from Fi0 1 (i.e., which extends Fi0 1 ) so that its i-th bit in the
folding vector is i (the same as in Fi ). Note that the algorithm computes Fi00 in the first part of iteration i
(before trimming). Its parameters are
= min(a0 1 ; x0 1 + l );
a00i i i i i
= max(b0 1 ; x0 1 + l );
b00i i i i i
= x0 1 + l :
x00i i i i
Let the interval triplet which contains F 00 be (I ; I ; I ). The algorithm discards all but one partial folding
i a b x
in this interval triplet, say Fi0 , with parameters a0i ; b0i ; x0i . This implies that
ja0i a00i j Æ;
jb0i b00i j Æ;
jx0i x00i j Æ:
The lemma follows once we show
Remark. Using Observation 2, one can modify the algorithm so that m = 6n= (versus m = 8n=),
which leads to maintaining a somewhat smaller number of interval triplets.
length of F is bF aF . Define xi , aF and bF in the same way using the length function l instead of l. Let
F
:= 4 4 0 1
=( + )
qi lLi n 1 b lLi n 1
. Note that qi < and li li qi 4Ln .
Let A be any folding for the original instance and B be an optimum folding for the reduced instance.
We have:
X X L X
= 4Ln (x +
i i i
xBi = Bi li = Bi (li + qi ) B
Bi qi):
j =1 j =1 4n i
j =1
Using 0 q < 1, we obtain:
i
L B L L
xBi
4n (
xi + n) xBi + ;
4n 4
6
and therefore
L L
bB bB + :
4n 4
Similarly we have:
L B L
xBi
4n xi 4;
and consequently
L L
aB
4n aB 4:
Using the fact that B has optimum length for l, and the inequality bA aA L, we get:
L L L
bB aB
4n (b B aB ) +
2 4n (b A aA ) +
2 (b A aA ): (1)
Further on:
X X li 1 4n x X 4n x + n;
Aili =
i i i
xAi = Ai ( 4n qi ) = A
Ai qi A
j =1 j =1 L L i
j =1 L i
and therefore
b 4n b + n: (2)
A
L A
Similarly we have:
4n
x = x
A A
X
i
Ai qi
4n x A
n;
L
i i
j =1 L i
and consequently
aA
4n a n: (3)
L A
Plugging Equations 2 and 3 in Equation 1 and using again the inequality bA aA L, we obtain:
L 4n
bB aB
4n L bA + n ( 4Ln a A n) + 2 (b A aA ) (bA aA )(1 + ):
If we now let A be an optimal folding for the original instance, we find that bB aB (1 + )OP T ; this
completes the second proof of Theorem 1.
7
3 Folding in the plane: proof of Theorem 2
For the purpose of this section, a folding of the ruler is a polygonal chain of n segments (links), numbered
1
from to n, lying in the plane. Let q0 be the free endpoint of the first link, and q1 be its other endpoint.
Call v1 = 1
q0 q1 the vector of link . Inductively define (q2 ; : : : ; qn and) v2 ; : : : ; vn , the vectors of links
2; : : : ; n. The joint angle between links i and i +1 [0 ℄
is the angle 2 ; between vi and vi+1 . The angle is
0
counterclockwise (resp. clockwise) if it describes a left (resp. right) turn. Angles of and are considered
both left and right turns.
It is obvious that the diameter of any convex case in which the ruler is folded is at least L, where L is
the maximum link length. The following simple linear-time algorithm computes a folding of the ruler, so
(0 ℄
that all joint angles 2 ; are clockwise (or counterclockwise). The algorithm is certainly implicit in [6],
where an extensive analysis of reconfiguration problems for rulers confined in discs is made.
Fix arbitrarily a disk D of diameter L, whose boundary is the circle C . Fix the first free endpoint of
the ruler (i.e., the free endpoint of the first link) at some point p0 of C . For i =1 ; : : : ; n, iteratively fix the
next point of the ruler (i.e., the next endpoint of its i-th link) at one of the at most two intersection points
of C with the circle with center at pi 1 and radius li . One can also select the appropriate intersection point
(0 ℄
at each step, so that all joint angles 2 ; are clockwise (or counterclockwise). An illustration appears
in Figure 2. Consider now the closed convex curve R, of unit diameter, obtained from a Reuleaux triangle,
l5
l3
l4 l2
l1
p
0
Figure 2: A carpenter’s ruler with five links folded so that it fits in a circular case of diameter L, where
=
L l3 is the maximum link-length. All joint angles in this folding are counterclockwise (i.e., left turns).
by replacing one of the circular arcs with a straight segment, as in Figure 3. (A Reuleaux triangle can
be obtained from an equilateral triangle ABC by joining each pair of its vertices by a circular arc whose
center is at the third vertex [15].) The above algorithm can be modified to compute a folding of a ruler with
1
maximum link length inside R: Fix the first free endpoint of the ruler at some point p0 of the circular
arc AB . Iteratively fix the next point of the ruler at some intersection point (it exists!) with the open curve
BAC . The area of R is p
3 0:614;
3 4
as claimed.
It remains to prove the lower bound in Theorem 2. Consider a 3-link p ruler ABCD with lengths AB =
1 , BC = 1
x < and CD =1
, where the choice of the length x = ( 7 1) 2 0 8229
= : of the middle
38
link is explained below. We will show that the area of any convex case for it is at least = . In any folding
in which the unit length links do not intersect, the diameter of the case exceeds one. Assume therefore that
they intersect (see Figure 4). The area of BCAD (i.e., the convex hull of the four endpoints of the links) is
8
A
l4
l3 l
2
l1
B C
Figure 3: The closed curve R obtained from a Reuleaux triangle, and a ruler with four links folded inside;
1
the length of l3 is .
D
A
1-b 1-a
a O b
x
B C
9
References
[1] R. Connelly, E. D. Demaine and G. Rote, Straightening polygonal arcs and convexifying polygonal
cycles, Discrete & Computational Geometry, 30(2) (2003), 205–239.
[3] H. T. Croft, K. J. Falconer and R. K. Guy, Unsolved Problems in Geometry, Springer-Verlag, New
York, 1991.
[4] M. Garey and D. Johnson, Computers and Intractability: A Guide to the Theory of NP-Completeness.,
W.H. Freeman and Company, 1979.
2
[5] J. E. Hopcroft, D. A. Joseph and S. H. Whitesides, Movement problems for -dimensional linkages,
SIAM Journal on Computing, 13 (1984), 610–629.
2
[6] J. E. Hopcroft, D. A. Joseph and S. H. Whitesides, On the movement of robot arms in -dimensional
bounded regions, SIAM Journal on Computing, 14 (1985), 315–333.
[7] O. H. Ibarra and C. E. Kim, Fast approximation algorithms for the knapsack and sum of subset prob-
lems, Journal of the ACM, 22(4) (1975), 463–468.
[8] V. Kantabutra, Motions of a short-linked robot arm in a square, Discrete & Computational Geometry,
7 (1992), 69–76.
[9] V. Kantabutra, Reaching a point with an unanchored robot arm in a square, International Journal of
Computational Geometry & Applications, 7 (1997), 539–550.
[10] V. Kantabutra and S. R. Kosaraju, New algorithms for multilink robot arms, Journal of Computer and
System Sciences, 32 (1986), 136–153.
[11] V. Klee and S. Wagon, Old and New Unsolved Problems in Plane Geometry and Number Theory,
Mathematical Association of America, Washington, 1991.
[12] D. Kozen, The Design and Analysis of Algorithms, Springer-Verlag, New York, 1993.
[13] I. Streinu, A combinatorial approach to planar non-colliding robot arm motion planning, Proceedings
of the 41-st Annual Symposium on Foundations of Computer Science, Redondo Beach, CA, November
2000, 443-453.
[14] Van Kreveld, J. Snoeyink and S. Whitesides, Folding rulers inside triangles, Discrete & Computa-
tional Geometry, 15 (1996), 265–285.
[15] I. M. Yaglom and V. G. Boltyanskiĭ, Convex Figures, Holt, Rinehart and Winston, 1961 (English
translation).
10
Case 1: max(b0 i 1 ; xi 1 + i li ) = bi 1 and max(bi 1 ; xi 1 + i li ) = bi 1 . Then
0 0
= jb0i 1 bi 1j (i 1)Æ:
Case 2: max(b0 i 1 ; xi 1 + i li ) = xi 1 + i li and max(bi 1 ; xi 1 + i li ) = xi 1 + i li . Then
0 0
= jx0i 1 xi 1j (i 1)Æ:
Case 3: max(b0i 1 ; xi 1 + i li ) = bi 1 and max(bi 1 ; xi 1 + i li ) = xi 1 + li . Note that i = 1. We
0 0
have two subcases.
Case 3.1: xi 1 + li b0i 1 . Since bi 1 xi 1 + li , Then
= jb0 i 1 (x 1 + l )j jb0
i i i 1 bi 1 j (i 1)Æ:
Case 3.2: b0i 1 xi 1 + li . Since x0i 1 + li b0i 1 ,
= jx 1 + l i i b0i 1 j jxi 1 + li (x0 1 + l )j (i 1)Æ:
i i
11