arXiv:1910.09791v3 [cs.CC] 28 Jun 2021 hoetreewidth choose h ogs ahpolmi As admeg egh,FPT lengths, edge random DAGs, in problem longest the Keywords: ya most at by eut.I aeteeg egh bytemtal needn st independent ((6 a mutually exists the there obey that lengths show we edge distribution, the exponential case In results. nfrl itiue,tepolmo optn h itiuinfun distribution the computing of problem Pr[ the distributed, uniformly | sbcuePr[ because is eso htteei a is there that show we one yaconstant a by bounded xc loih.W loso,frrno delntsstsyn c satisfying lengths edge random Pr[ for computing show, that also conditions, We algorithm. exact an oaheeamlilctv prxmto ai + 1 ratio approximation multiplicative a achieve to cee(PA)frcmuigPr[ computing for (FPTAS) scheme u PA,w hwafnaetlfruata ersnsPr[ represents that formula fundamental a show we FPTAS, our hsppri bu h length the about is paper This Abstract rp (DAG) graph rpitsbitdt arXiv to submitted Preprint in E h itiuinFnto fteLnetPt Length Path Longest the of Function Distribution The | ⋆ G X m h rlmnr eut fti ae perdi 1 3]. [1, in appeared paper address: this Email of results preliminary The = esuUiest,211 iah-ia aaK,Kawasak Tama-Ku, Higashi-Mita, 2-1-1, University, Senshu h unn ieo u loih is algorithm our of time running The . nCntn reit Aswt admEdge Random with DAGs Constant in MAX dmninlui yecb rnae yahlsae nti pap this In halfspace. a by truncated hypercube unit -dimensional m seily hnteeg egh r uulyidpnetand independent mutually are lengths edge the when Especially, . ≤ n x Phrns,dtriitcFTS ihdmninlvolume, dimensional high FPTAS, deterministic #P-hardness, skont e#-adee ncase in even #P-hard be to known is ] − G X MAX eeiino ent nerl.Ti lolasu omore to us leads also This integrals. definite of repetition 1 ( = [email protected] k h diieerror additive the , ,E V, ≤ k x hthv admeg egh,where lengths, edge random have that ) hr hr a eepnnilymany exponentially be may there where , seult h oueo h npakpolytope, knapsack the of volume the to equal is ] deterministic X X Length MAX MAX iAndo Ei X ≤ MAX ftelnetpt ndrce acyclic directed in path longest the of ǫ ul oyoiltm approximation time polynomial fully ′ x and sfie aaee rcal fwe if tractable parameter fixed is ] ⋆ ≤ O E Ando) (Ei x x ((3 ncs h reit of treewidth the case in ] steparameters. the as k 2) + G ǫ sadrce ah This path. directed a is ntewyt show to way the On . 2 n ,2488,Japan. 214-8580, i, ( k (6 4) + k +6) ǫ mn mn ue2,2021 29, June | V X ) s ) 9 | MAX − O k = 2 ( andard +15 t k ) ertain n paths ction ≤ time G k and +6 er, x is ) ] 1. Introduction

We consider the longest path length XMAX of a (DAG) G where the edge lengths of G are mutually independent random variables. It is well known that the in DAGs with static edge lengths can be solved in linear time with respect to the graph size [10]. In this paper, however, we introduce random edge lengths. There are at least two reasons. Firstly, there are a lot of uncertain quantities in industry. Therefore, it is often meaningful to consider the behavior of a model where the uncertain quantities are modeled by certain random vari- ables. Secondly, from the viewpoint of computational complexity, we expect that the probability of a complex event involved with a graph may lead to the difference of computational performance between a randomized algorithm and a deterministic algorithm. Especially, though it is widely believed that BPP=P [4], randomized computation still seems to have some advantages in approximation [16]. Thus, we are interested in the difference in the compu- tational performance caused by the randomness especially in computing the probability, or the high dimensional volume. In this paper, we show a funda- mental formula for the distribution function of the longest path length in G with random edge lengths. Then, we describe three deterministic algorithms, including a deterministic fully polynomial time approximation scheme (FP- TAS) for a #P-hard problem. As far as the author is aware, the longest path problem in DAGs with ran- dom edge lengths is proposed by Malcolm et al. [25] in the field of operations research. Here, some deterministic and exact polynomial time algorithm for limited class of DAGs, such as series-parallel graphs, is known as a folk- lore (see e.g., [8]). This approach does not scale to the general DAG. At first, some deterministic exponential time algorithms are proposed (see, e.g.,[26]). The longest path problem in DAGs with random edge lengths has been well studied in the field of VLSI design (see e.g., [6, 8]). The time differ- ence (signal delay) between the input and the output of each logical circuit product may be different among in mass produced semiconductor chips even though they are produced in the same line of the same design. The sig- nal delay fluctuates because the signal delay of each logical gate fluctuates, which is inevitable to some extent. Therefore, before they start costly mass- production, the VLSI makers would like to know whether or not sufficient

2 number of their new chips are going to perform as expected. To estimate the signal delay of a logical circuit, we consider the longest path length in a DAG by considering each of gates and lines as an edge and each fluctuating signal delay as a random edge length. Then, the signal delay in the entire circuit is given as the longest path length in the DAG. To model the gate delay fluctuation, we consider random edge lengths, which implies that the longest path may change according to the random edge lengths. To estimate how many products are going to satisfy the performance constraint, we would like to know the probability (the distribution function) that the length of the longest path is at most a certain value.

1.1. Formal Description of the Problem The longest path problem in DAG G with random edge lengths is for- malized as follows. We consider a DAG G = (V, E) with vertex set V = 1,...,n and edge set E V V where E = m. When an edge e goes { } ⊆ × | | from u V to v V , we write e = uv = (u, v). For any graph G, we write V (G) and∈ E(G) to∈ mean the vertex set and the edge set of G, respectively. We assume that the vertex set V = 1,...,n are topologically ordered. Then, we consider m mutually independent{ random} variables.

Definition 1. For a DAG G,we define a source of G as a vertex that has no incoming edge. Also, a terminal of G is a vertex that has no outgoing edge. The set of all sources (resp. terminals) in G is denoted by S(G) = 1,..., S(G) (resp. T (G) = n T (G) + 1,...,n ). When a vertex {v V (|G) is|} neither a source nor{ a−| terminal,| v is an} internal vertex and I(G∈)= V (G) (S(G) T (G)) is the set of all internal vertices. A (directed) \ ∪ s t path π in G is a subgraph of G where V (π)= u ,u ,...,u V (G) − { 1 2 p} ⊆ and E(π)= uiui+1 i =1,...,p 1 . We write Π(G) to mean the set of all paths from the{ sources| to the terminals− } in G.

Let Y for e = uv E be mutually independent random variables. uv ∈ We are to compute the probability that the longest path length XMAX = max Y is at most a certain value x R . Note that π∈Π(G) uv∈E(π) uv ∈ ≥0 computingn Pr[XMAX xo] and finding out a path that is the “longest” in P ≤ some sense are different problems in case of random edge lengths. This may seem counter-intuitive because these two problems are almost the same if edge lengths are static values. However, any s t path in G can be the longest − with certain positive probability when we assume some natural distributions

3 for the random edge lengths such as the uniform distribution over [0, 1] or the exponential distribution. Throughout this paper, we focus on the problem of estimating the probability distribution function Pr[XMAX x]. We do not consider the problem of finding out any kind of path. ≤ In case we consider that each edge uv E is uniformly distributed over ∈ [0, auv] where each component auv of a is given for each edge uv E, we additionally have a vector a Zm as the input of the problem. Let a∈ random ∈ >0 vector X be uniformly distributed over [0, 1]m. For each edge uv E, ∈ random variable Yuv = auvXuv is the random edge length with its distribution function F (x) = Pr[a X x]. In this case, the distribution function uv uv uv ≤ Pr[X x] of the longest path length is equal to the volume of a polytope MAX ≤

K (a, x) def= x [0, 1]m a x x , G  ∈ uv uv ≤  π∈Π(G) uv∈E(π)  ^ X  where each component x of x R m is related to an edge uv E. If G uv ∈ ∈ is a directed path, KG(a, x) is a 0 1 knapsack polytope. Computing the − 1 volume of KG(a, x) is #P-hard even if G is a directed path (see [14]) . The different assumptions of the edge length distributions give us com- pletely different problems. For example, If the edge lengths are normally dis- tributed and G is a directed path, then we can efficiently compute Pr[X MAX ≤ x]. Also, in case edge lengths are exponentially distributed and G is a di- rected path, then it can be shown that we can compute the exact value of Pr[X x] efficiently. If the edge lengths are discrete random variables MAX ≤ that can take only two values, Hagstrom [20] proved that the problem is #P-hard in DAGs where any s t path has at most three edges. − 1.2. Results about Computing High Dimensional Volume Consider uniformly distributed edge lengths. Then, the problem of com- puting the value of the distribution function of the longest path length is equivalent to computing the volume of a polytope KG(a, x). Here, we briefly introduce some results about randomized approximation algorithms, hard- ness results and deterministic approximation algorithms.

1 Intuitively, the breakpoints of the function F (x) = Vol(KG(a, x)) increases exponen- tially with respect to n. For example, consider the case where each component ai,i+1 of a i is ai,i+1 =2 for edge (i,i + 1) i =1,...,n 1. −

4 There are efficient randomized algorithms for estimating n-dimensional convex volumes. Dyer, et al. [15] showed the first FPRAS (fully polynomial time randomized approximation scheme) that finishes in O∗(n23) time for volume of the general n-dimensional convex body. Here O∗ ignores the factor of poly(log n) and 1/ǫ factor. There are faster FPRASs [24, 12]. The current fastest FPRAS[12] runs in O∗(n3) time for well-rounded convex bodies. In general, computing the n-dimensional volume of a polytope exactly is hard. Elekes [16] considered an n-dimensional convex body that is ac- cessible by membership oracle, and proved that no deterministic polynomial time algorithm can achieve the approximation ratio of 1.999n. The bound is updated by B´ar´any and F¨uredi [5] up to (cn/ log n)n/2, where c does not depend on n. Dyer and Frieze [14] proved that computing the volume of the 0 1 knapsack polytope K is #P-hard. −Recently, there are some deterministic approximation algorithms for the volume of the knapsack polytope. Li and Shi [23] showed a fully polynomial time approximation scheme (FPTAS) for distribution function of the sum of the discrete random variables. Their algorithm can be used to approximate Vol(KG(a, x)) if G is a directed path. Their algorithm is based on some ideas due to Stefankoviˇcetˇ al. [28] (see also [17],[18]), that is a kind of . Ando and Kijima [2], motivated by the deterministic approximation technique of the above results, showed another FPTAS that is based on the approximate convolution integral. Their algorithm runs in O(n3/ǫ) time. They extended the FPTAS to problem of computing the volume of the multiple constraint knapsack polytope. Given m n matrix A Zmn and a vector b Zm , the multiple constraint knapsack× polytope ∈ ≥0 ∈ ≥0 def n Km(A, b) is Km(A, b) = x [0, 1] Ax b . Their algorithm finishes in 2 −1 m+1 { ∈ | ≤ } O((n ǫ ) nm log m) time. Thus, there is an FPTAS for Vol(Km(A, b)) if the number of constraints m is bounded by a constant.

1.3. Treewidth and Related Results The notion of the treewidth was first defined by Robertson and Sey- mour [27]. Bodlaender [7] found an algorithm that finds the decom- position of an undirected graph G in linear time with respect to the graph size if the treewidth of G is bounded by a constant k. There are so many NP-hard and #P-hard problems on graphs solvable in polynomial time when the treewidth k is bounded (See [13] for classic results). Courcelle and En- gelfriet [11] proved that there is a linear time algorithm for any graph op- timization problem that can be described by Monadic Second Order Logic

5 (MSOL) if the treewidth of G is constant. Johnson et al. [21] defined the directed treewidth. They proved that various NP-hard problems, including computing the directed treewidth, can be solved in polynomial time on the directed graphs with at most constant directed treewidth. We may expect that computing the distribution function Pr[X x] MAX ≤ of the longest path length in a DAG G with random lengths can also be solved when the treewidth of G in some sense is bounded by a constant. Previously, however, it has not been clear how to do it. This is probably because the problem lies at the junction between the continuous analysis and the combinatorial optimization. In this paper, we develop the techniques for this kind of problems. In [1], Ando et al. considered the problem of computing Pr[X x] MAX ≤ in DAGs with random edge lengths. They showed a formula that repre- sents Pr[XMAX x] with n 1 repetitions of definite integrals and presented some results in≤ case there− is a bounding constant on the antichain size of the incidence graph G. In that setting, they proved that exact computation of Pr[XMAX x] finishes in polynomial time if the edge lengths are expo- nentially distributed≤ with parameter 1 (standard exponential distribution). They also considered the Taylor approximation of Pr[XMAX x] assuming the random edge lengths may not be exponentially distributed≤ but the edge lengths obey some implicit distributions satisfying certain conditions.

1.4. Contribution

The first contribution of this paper is a formula that represents Pr[XMAX x] by n T (G) repetitions of definite integrals. Then, the formula leads us≤ −| | to an FPTAS for computing the value of Pr[XMAX x] = Vol(KG(a, x)) for DAG G whose underlying undirected graph of G has≤ treewidth bounded by a constant k and the edge lengths obey the uniform distribution. We will show the following theorem. Theorem 1. Suppose that the treewidth of the underlying undirected graph of DAG G is bounded by a constant k. There is an algorithm that approxi- 9k2+15k+6 2 (6k+6)mn mates Vol(KG(a, x)) in O (3k + 2) n ǫ time satisfying 1 V ′/Vol(K (a, x)) 1+ ǫ, where V′ is the output of the algorithm. ≤ G ≤ By showing how to deal with multiple subtrees in the , the above theorem extends the results in [3], in which an FPTAS for G with constant was shown.

6 Moreover, we show other examples where the edge lengths obey some other distributions. If the edge lengths are mutually independent and obey the standard exponential distribution, we show how to compute the exact value of Pr[XMAX x]. Previously, this have not been known that there is an algorithm that≤ finishes in polynomial time with respect to the size of G even when the treewidth of G is bounded by a constant. We next consider more general continuous distribution for the random edge lengths, where we can obtain the value of Pr[Xuv x] and its derivative of arbitrary order for uv E by an oracle. In case we≤ can assume that edge length distributions satisfy∈ certain conditions, we can use the Taylor approximation for Pr[X uv ≤ x]. Then, we show that the problem of computing Pr[XMAX x] is fixed parameter tractable if we choose treewidth k, additive error ǫ′ ≤and x as the parameter, where x is the bound of the longest path length. These are the examples showing that our technique can be applied to the standard exponentially distributed edge lengths and the Taylor approximation. We here extend the result of [1] to the graphs with constant treewidth. Note that the maximum antichain size of the incidence graph can be Ω(n) even if G has constant treewidth.

1.5. Organization

In Section 2, we show a fundamental formula that represents Pr[XMAX x] by n T (G) repetitions of definite integrals. In Section 3, we show≤ − | | our for the volume of KG(a, x). Then, we prove the approximation ratio and the running time so that our algorithm is an FPTAS. In Section 4, we show the cases where the edge lengths obey other distributions. There, we present an exact ((6k + 4)mn)O(k)-time algorithm for the case where edge lengths obey the standard exponential distribution. Then, we prove that, in case we assume abstract distributions for the edge lengths satisfying certain conditions, the problem of computing Pr[XMAX x] is fixed parameter tractable if we choose k, x and the additive error ǫ′ as≤ the parameters. Section 5 concludes this paper.

2. Integrals that Give Pr[XMAX ≤ x] In this section, we prove a fundamental formula for Pr[X x]. The MAX ≤ formula includes definite integrals repeated n T (G) times. This implies that we deal with n T (G) dummy variables−| of integrals.| We will see that −| | each of these dummy variables are associated with a vertex of G. Then,

7 we show how to compute Pr[XMAX x] by computing the longest path length distribution function in each bag≤ of the tree decomposition and then by putting them together. To exploit the advantage of tree decomposition, we need to introduce our notation for vectors.

2.1. Dummy Variable Vectors Note that our problem lies at the junction between the continuous analysis and the combinatorial optimization. We need to arrange a set of notations so that we can concisely argue the combinations of many (partial) derivatives and integrals. Here, we define notations of the vectors of dummy variables using an element or a set as its subscript of a component or a sub-vector. Let W be a subset of V or a subset of E where G = (V, E). We consider a vector z R|W |. Each component of z is specified by an element of W . ∈ That is, z[v] is a component of z for v W , where we call v a subscript and W the subscript set of z. In the following,∈ we write z RW . To make the ∈ description simpler, we define z[v] =0 for any v W . For the conciseness, we pack the dummy variables6∈ of the integrals of the ongoing computation as a vector. In the following, we use z as an n- dimensional vector of variables z =(z1,...,zn), where each component zv is associated to v V (i.e., z[v] = zv). We write u = z[W ] for some W V . Here, u is a vector∈ with W components where u[v] = z[v] for v W⊆. We | | ∈ use the same notation for constant vectors 0 and 1, where 0[v] = 0 and 1[v] = 1 for any v. Consider the definite integrals with W dummy variables | | of W -variable function F (z[W ]), We write | |

F (z[W ])dz[W ]= F (z) dz[v|W |] dz[v1], z∈RW z[v ]∈R ··· z[v ]∈R ··· Z Z 1 Z |W | W for W = v1,...,v|W | . By arguments of F (z[W ]), we mean z[W ] R for the W -variable{ function} F (z[W ]). Since we also deal with partial∈ deriva- | | tives with respect to many variables, we save some space by writing ∂ D = F (z) def= F (z). W ∂z[W ]

Let fU (z[W ]) = DU F (z[W ]) (U W ). Consider the inverse operation of D ⊆ U . For zv1 ,...,zv|U| , clearly we have

z[v1] z[v|U|] F (z[W ]) = f (z[W ])dz[v ] dz[v ]. ··· U |U| ··· 1 Z−∞ Z−∞

8 For short, we write

f (z[W ]) = f (z[W ])dz[U], ( , z[U]) def= x RU x z . U U −∞ { ∈ | ≤ } Z(−∞,z[U])

In this paper, we use convolutions extensively. Let Fv(x) and fv(x) be the probability distribution function and the probability density function of random variable Xv for v = 1, 2. The distribution function of X1 + X2 is given by Pr[X + X x]= f (z)F (x z)dz. Also, the density function 1 2 ≤ R 1 2 − of X + X is given by d Pr[X + X x] = f (z)f (x z)dz. We call 1 2 dx R 1 2 R 1 2 these integration operations as convolutions≤ . − R

2.2. Repetition of Definite Integrals for the Distribution Function of XMAX Here, we prove that Pr[X x] can be given by computing n T (G) MAX ≤ −| | repetitions of definite integrals. In the proof, we decompose the paths into parts so that we avoid the dependencies between path lengths. Then, we associate a value to each of the sources and the terminals so that we can shift the longest path length between specific source and terminal. One difficulty about considering the distribution function Pr[X x] MAX ≤ of the longest path length is that the path lengths may be dependent on each other due to the shared edges. In our proof, we consider the longest def path length Zv from one vertex v. Let Suc(v) = w V vw E . Though Z depends on X and Z for w Suc(v), it helps{ ∈ to consider| ∈ Z} because v vw w ∈ v the edge lengths from any topologically earlier vertex u and Zv are mutually independent. We define Zv as follows.

Definition 2. For u V , we set Z def= max X + Z , where Z for ∈ u v∈Suc(u){ uv v} t any t T (G) is equal to a static value z R. ∈ t ∈ We define the conditional distribution function and the density function of Zv assuming Zw = zw for all successors w of v. Later, these zw’s work as the dummy variables of the convolution.

Definition 3. Let F (x) = Pr[X x] for uv E. We define uv uv ≤ ∈ F (z[ u Suc(u)]) def= Pr[Z z Z = z , v Suc(u)] = F (z z ), and u { }| u ≤ u| v v ∀ ∈ uv u − v v∈YSuc(u) def ∂ fu(z[ u Suc(u)]) = Fu(z[ zu Suc(u)]). { }| ∂zu { }|

9 If we assume that Zw is equal to a fixed value zw for all w Suc(v), we can see that the distribution function of the longest path length∈ from v to the terminal is Fv(v) where v[v] = x and v[w] = zw for w Suc(v). Then, we define S(G) T (G) -variable functions Φ and φ. ∈ | ∪ | Definition 4. For an s t path π in G, let s(π) and t(π) be the source and − the terminal of π. Remember that Π(G) is the set of all s t paths. Then, −

Φ(G; z[S(G)] z[T (G)]) def= Pr X z[s(π)] z[t(π)] , and |  uv ≤ −  π∈^Π(G) uvX∈E(π) def   φ(G; z[S(G)] z[T (G)]) = D Φ(G; z[S(G)] z[T (G)]). | S(G) |

Remember that DS(G) represents partial differentiation with respect to all z ’s for s S(G). Here, z[S(G) T (G)] specifies the “shifts” of the s ∈ ∪ longest path length at sources and terminals. That is, z[s] for s S(G) is the limit of the length of the paths starting from s if z[t] = 0 for all∈t T (G). When z[t] = 0, any path ending at t T (G) must be shorter by z∈[t] than 6 ∈ z[s]. We note that z[S(G) T (G)] works as a kind of glue to the other ∪ graphs later. For short, we write Φ (z[S T ]) def= Φ(G; z[S(G)] z[T (G)]) and G | | φ (z[S T ]) def= φ(G; z[S(G)] z[T (G)]). Let σ be a vector satisfying σ[s]=1 G | | for s S(G) and σ[v] = 0 otherwise. Then, ∈

Pr[XMAX x] = ΦG(xσ[S T ]) = φG(xσ[S T ])dz[S(G)]. ≤ | S(G) | Z(−∞,x) Theorem 2 shows the exact computation of φ (z[S T ]). G | Theorem 2. Assuming that there is no isolated vertex in G, we have ∂ φG(z[S T ]) = Fuv(zu zv)dz[I(G)]. | RI(G) ∂zu − Z u∈S(YG)∪I(G) v∈YSuc(u) Proof. Let Π(G; u, v) be the set of all paths in G from u to v. We claim:

X Z Z X + Z Z . (1) vw ≤ u − t ⇔ pq q ≤ p u∈^V (G) t∈^T (G) π∈Π(^G;u,t) vwX∈E(π) p∈^V (G) q∈Suc(^ p) After proving this, we apply the backward induction from the terminal to the source of G so that we obtain the claim of the Theorem.

10 Let us prove (1). ( ) By the definition of Zv for v V (G), we have X Z Z for any⇐vw E. Then, we take the sum of∈X and Z Z vw ≤ v − w ∈ pq p − q for all pq E(π). Since these Zp’s cancel for all vertices except for the source and the terminal,∈ we have X Z Z . ( ) Since Z Z is the pq∈E(π) pq ≤ u − t ⇒ u − t longest path length from u to t T , we have that Zu Zv is an upper bound P ∈ − on any edge length Xuv. The above argument implies (1). Since Pr X + Z Z Z z is equal u∈S(G)∪I(G) v∈Suc(u) uv v ≤ u ∧ s∈S(G) s ≤ s to ΦG(z[S Th]) by (1) where Zt = zt for t T (G), we next consider thei back- | V V ∈ V ward induction. Let w be the topologically last vertex in I(G). Then, let A(w)= S(G) I(G) w , and Φ (z[S T ]) is equal to ∪ \{ } G |

Pr X + Z Z Z z Z = z f (z[ w Suc(w)])dz ,  uv v ≤ u ∧ s ≤ s w w w { }| w ZR u∈A(w) v∈Suc(u) s∈S(G) ^ ^ ^   ∂ where fw(z[ w Suc(w)]) = Pr Xwt + zt zw dzw. That is, { }| ∂zw t∈Suc(w) ≤ we aggregate all possible values of Z by introducing an integral. This is hVw i possible because X ’s for wt E(G) are independent from the lengths of wt ∈ topologically earlier edges. ′ Though Zvs for v A(w) are dependent on Zw, we can repeat this to the integrand of the resulting∈ form for all w I(G) in reverse topological order, ∈ which ends up with P (z) f (z[ w Suc(w)])dz[I(G)], where RI(G) w∈I(G) w { } ∪ R Q P (z)=Pr X + Z Z Z z w I(G),Z = z .  sv v ≤ s ∧ s ≤ s ∀ ∈ w w s∈S(G) v∈Suc(s) s∈S(G) ^ ^ ^   Since P (z)= F (z[ s Suc(s)]), we obtain the theorem. s∈S(G) s { }| Q 2.3. Tree Decomposition The followings are the definitions of the treewidth and related terms. For any set W , W is the family of subsets U of W with cardinality U = k. k | | Definition 5.A tree decomposition of G is a pair (G)=( , ), where T BB A = B0, B1,...,Bb−1 is a family of subsets of V and 2 is an edge setB so{ that (G) is a tree} satisfying the following three conditions.A ⊆ T  1. B∈B B = V ; S 11 BBBBB01 2 3 4

Figure 1: An example of a DAG and its tree decomposition. Bags B1,B2 and B3 are visited three times by a path. By the ancestor-first rule, the edges between the vertices in B0 B1 belong to bag-subgraph G0. The bag-subgraph is defined in Section 2.4. ∩

2. uv E B s.t. u, v B; ∈ ⇒ ∃ ∈ B { } ⊆ 3. for all Bh, Bi, Bj , if Bi is on a path from Bh to Bj in (G), then B B B . ∈ B T h ∩ j ⊆ i We call B a bag. The width of (G) is maxB∈B B 1. The treewidth of G is the∈ minimum B of the width ofT all possible (G|)’s.| − T Fig.1 shows an example of a DAG and its tree decomposition. In the tree decomposition, we call B0 the root of (G). Let Ch(i) be the index set of the children of bag B ∈in B (G). LetT Sub(i) be the index i ∈ B T set of bags in the subtree of (G) rooted at Bi. We may expect an efficientT algorithm if G has small treewidth. Small treewidth allow us in the brute-force manner to process a bag. Then, if we can properly process the leaves first and then “glue” the subtrees together, we expect that our algorithm run efficiently. We use the following binary tree decomposition for bounding the running time of our algorithm. It is well known that we can obtain a binary tree decomposition from a tree decomposition.

Proposition 1. (Lemma 13.1.3 of [22]) Given a tree decomposition (G) of G of width at most k, it is possible to transform (G) in time O(n)Tinto a binary tree decomposition ′(G) of G of width k andT with at most 4n bags, T where for each bag B in ′(G) we have Ch(i) 2. i T | | ≤ Throughout this paper, we assume that G has n vertices and that the treewidth of G is bounded by a constant k. We assume that the number b of bags is at most O(n), and that the number of the children of a bag is at most two. In the following, we set Ch(i)= r, ℓ when Ch(i) = 2. { } | |

12 2.4. Bag-Subgraph We here define a bag-subgraph G for each bag B . Notice that we i i ∈ B do not define Gi to be the with vertex set Bi. This is because the pair of vertices corresponding to a single edge may belong to multiple bags. See e.g., B B of Fig. 1. Under such definition, it is hard to 0 ∩ 1 construct an algorithm that computes the integrals in Theorem 2. Instead, we need a handy definition of Gi so that each edge belongs to exactly one bag-subgraph. Here, the vertex set V (Gi) of Gi is Bi. We set

E(G ) def= uv E u, v B and h Anc(i), u, v B , i { ∈ |{ } ⊆ i ∀ ∈ { } 6⊆ h} where Anc(i) is the index set of the ancestors of Bi in (G). Since each edge is given to bag-subgraph in ancestor-first manner, weT call this as the ancestor-first rule. The following is necessary for the later proof.

Proposition 2. For any three bags Bh, Bi where i Ch(h) and j Sub(i) i , we have uv,vu E(G) if u B B and v ∈B B . ∈ \ { } 6∈ ∈ h \ i ∈ j \ i Proof. Assume for contradiction that uv E(G) so that u B B and v ∈ ∈ h \ i ∈ Bj Bi (j Sub(i) i ). By the second condition of the tree decomposition, there\ exists∈ B∗ such\{ that} u, v B∗. Then, by the third condition of the ∗ { } ⊆ ∗ tree decomposition, B is not an ancestor of Bi since if B is an ancestor of Bi, ∗ ∗ then v B Bj Bi, contradiction. Similarly, B is not a descendant of Bi since, if∈B∗ is∩ a descendant⊆ of B , then u B∗ B B a contradiction. i ∈ ∩ h ⊆ i We consider union and intersection of subgraphs.

Definition 6. Let G′ and G′′ be two subgraphs of G. The union graph of G′ and G′′ is G′ G′′ =(V (G′) V (G′′), E(G′) E(G′′)). The of G′ and G∪′′ is G′ G′′ =(∪ V (G′) V (G′′∪), E(G′) E(G′′)). ∩ ∩ ∩ By the union graph, we merge the computational results about the bag- subgraphs into Pr[XMAX x]. By the intersection graph, we define the source and the terminal of≤ subgraphs. We define the sources and the terminals of subgraph G′ of G as follows; they are not determined just by in/out degrees but also by means of the incoming/outgoing paths from/to the outside of G′.

Definition 7. Let G′ be a subgraph of G. Then, a vertex v V (G′) is a source of G′ if there exists an s t path π of G such that v has∈ no incoming − 13 edge and one outgoing edge in graph G′ π. Similarly, v is a terminal of G′ if there exists an s t path π of G such∩ that v has no outgoing edge and − one incoming edge in G′ π. If a vertex v V (G′) is neither a source nor a terminal, we say that v is∩ an internal vertex∈ of G′. The reason why we define sources (resp. terminals) in this way is that we specify the “shifts” on the vertices with incoming paths from (resp. outgo- ing paths to) the outside of the bag-subgraph. This enables us describe all possible cases of the combinations of adjacant bag-subgraphs’ longest path lengths; these shifts work as a kind of glue. The sources and the terminals are defined not just for bag-subgraphs but for subgraphs of G. This is because we consider the union of multiple bag-subgraphs. For convenience, Si = S(Gi) and Ti = T (Gi) are the sets of the sources and the terminals of Gi, respectively. It is possible that there exists a vertex v Si Ti. In this case, v is an isolated vertex in G or v is connected to some∈ paths∩ from/to some adjacent bag-subgraphs. Such v S T needs ∈ i ∩ i additional treatment. We will explain this case later. Furthermore, we define the following.

Definition 8. The subtree-subgraph Di of Bi is the union of all bag-subgraphs for j Sub(i). That is, D = G . The uncapped subtree-subgraph ∈ i j∈Sub(i) j U of B is the union of all bag-subgraphs for j Sub(i) i . That is, i i S ∈ \ { } Ui = j∈Sub(i)\{i} Gj.

TheS following is an important property of Ui. Proposition 3. Let Ch(i)= ℓ,r . Then, for any s S(D ) and t T (D ), { } ∈ ℓ ∈ ℓ we have s T (D ) and t S(D ). 6∈ r 6∈ r Proof. We claim that, for any s t path π of G, D π and D π are − ℓ ∩ r ∩ not connected to each other. Suppose for contradiction that there exists an edge uv E(Dℓ π) such that u V (Dℓ) and v V (Dr), by the definition we have ∈V (D ) ∩V (D ) B and∈ any edge uv ∈or vu for u V (D ) and ℓ ∩ r ⊆ i ∈ ℓ v V (Dr) must be exclusively taken by E(Gi) by the ancestor-first rule. By the∈ definition of the separated tree decomposition, we avoid the case where D π and D π are connected at one vertex v B . ℓ ∩ r ∩ ∈ i 2.5. Definite Integrals in Tree Decomposition

We here describe the longest path length distribution function in Gi and then how to put Gi’s longest path length distribution functions together

14 for all Bi’s. For v V , let G[ v Suc(v)] be the graph with vertex set v Suc(v) and edge∈ set vw w { Suc(}| w) . The idea used here shares some { } ∪ { | ∈ } commonalities with the proof of Theorem 2, where we joined G[ v Suc(v)] to the rest of the graph by the union of subgraphs. That is, we{ con}|sidered a convolution of φ (z[S T ]) and φ (z[S T ]). We do this for G G\{v} | G[{v}|Suc(v)] | i and the subtree-subgraphs rooted at the children of Bi. Consider the union of Gi and Ui. Later, Proposition 5 shows that the following is the set of new internal vertices.

′ Definition 9. Let Bh be the parent of Bi and j Ch(i). We define S (Gi)= S T (U ) B and T ′(G )= T S(U ) B . For∈ short, we set S′ = S′(G ), i ∩ i \ h i i ∩ i \ h i i T ′ = T ′(G ), and J = S′ T ′. i i i i ∪ i

We do not include the vertices in Bh because there may be some more incoming/outgoing edges connecting to/from the vertices. We postpone pro- cessing the vertices v Bh until there is no ancestor bag that includes v. This is because, if v B∈ , then z[v] do not appear in the computation of the 6∈ h ancestor bags of Bi. This can be exploited for efficient computation. We prove the propositions and lemmas assuming that, for all Bi , S T = and Suc(u) B V (U ) = , where u T ′. We call∈ such B i ∩ i ∅ ∩ i \ i ∅ ∈ i a tree decomposition as a separated tree decomposition. To construct the tree decomposition, we transform G into G∗ as follows. For each v B , ∈ i we replace v by three vertices v−, v∗, v+ with length 0 edges v−v∗ and v∗v+. Then, each incoming edges of uv are replaced by uv−. The outgoing edges are distributed to these three vertices as follows: (1) Edge vt for t Ti V (Ui) ∗ ∈ ∩ ∗ is replaced by v t; (2) Edge vw for w Bi V (Ui) is replaced by v w; (3) Edge vu to u U B is replaced by∈ v+u\. Clearly, G∗ satisfies that ∈ i \ i i S(G∗) T (G∗) = and Suc(u) B V (U ) = for u T ′. Here, G∗ i ∩ i ∅ ∩ i \ i ∅ ∈ i i has 3k + 3 vertices (remember that Bi k +1) and the width of the tree decomposition is at most 3k + 2 when| we| ≤ use G∗ instead of G. Therefore, we can deal with the general treewidth k graph by increasing the treewidth to at most 3k + 2. Then, the following is necessary in the later proof.

Proposition 4. Given a separated tree decomposition, we have S S(U )= i ∩ i T T (U )= . i ∩ i ∅ Proof. Assume for contradiction v S S(U ) and that there exists an edge ∈ i ∩ i vw E(G). We show a contradiction by proving that v Ti or v T (Ui). Firstly,∈ consider the case where w B V (U ). Here,∈ vw must∈ be in ∈ i ∩ i

15 E(Gi) by the ancestor-first rule. Hence, if v does not have any outgoing edge connecting to V (U ) B , we have v T (U ) because the outdegree of v is 0 i \ i ∈ i in U π for any s t path π of G, which is a contradiction to S T = . i ∩ − i ∩ i ∅ Secondly, suppose that w V (Ui) Bi. Then, by definition, v Ti, which is a contradiction. Thus, v∈ T or\v T (U ), implying a contradiction∈ to ∈ i ∈ i S T = . We can prove T T (U )= by symmetry. i ∩ i ∅ i ∩ i ∅ ′ ′ As intended when we defined Si and Ti , we have the following. Proposition 5. J = S′ T ′ is the set of new internal vertices. That is, i i ∪ i J = I(D ) (I(G ) I(U )). i i \ i ∪ i Proof. Notice that, even if Ch(i)= ℓ,r , the union of graphs U = D D { } i ℓ ∪ r does not make a new internal vertex by Proposition 3. Consider a vertex ′ v Si. By definition, v is a source of Gi and also, v is a terminal of Ui. Let B∈be the parent of B . By Proposition 2 and that v B B , we have that h i ∈ i \ h there is no edge between v and u B for any g Anc(i). By definition, v ∈ g ∈ has at least one incoming edge from a vertex in Ui and one outgoing edge to a vertex in G . Since v B , any edge vw E is in D . By Definition 7, i 6∈ h ∈ i v is an internal vertex of D . We can prove that a vertex v T ′ is also an i ∈ i internal vertex of Di by symmetry. The longest path length distribution function is Φ (xσ[S T ]), where D0 | σ[s] = 1 for s S(G) and σ[v] = 0 otherwise. For the computation of Φ (z[S T ]), we∈ have the following lemma. Di | Lemma 1. Given a separated tree decomposition, we have

φDi (z[S T ]) = φGi (z[S T ])φUi (z[S T ])dz[Ji], (2) | RJi | | Z where Φ (z[S T ]) = Φ (z[S T ]). Ui | j∈Ch(i) Dj | Proof. Notice that Φ Q(z[S T ]) = Φ (z[S T ]) by Proposition 3. Ui | j∈Ch(i) Dj | We apply Theorem 2 to Di by a small modification. For each source s Q (resp. terminal t), consider a new source vertex vs (resp. a new terminal vertex vt) with edge vss (resp. tvt) with static length 0. Then, we have ∂ φDi (z[S T ]) = Fuv(zv zu)dz[I(Di)]. | RI(Di) ∂zv − Z v∈S(DYi)∪I(Di) u∈Pred(Y v)

16 ′ We have Suc(u) Bi V (Ui)= for u Ti by the definition of the separated ∩ \ ∅ ∈ ′ tree decomposition. We also have Suc(v) V (Ui)= for v T (Ui) because ′ ∩ ∅ ∈ any edge vw from v T (Ui) to w Bi must be taken by Gi by the ancestor- first rule. we can separate∈ the factors∈ of the integrand into two groups using ∂ Q(z, W )= Fuv(zu zv); that is u∈W ∂zu v∈Suc(u) − Q Q φDi (z[S T ]) = Q(z, W1)Q(z, W2)dz[I(Di)], | RI(Di) Z where W1 = Si (S(Di) I(Di)) and W2 = S(Ui) (S(Di) I(Di)). Notice that W S and∩ W ∪S(U ) are distinct by Proposition∩ 4.∪ 1 ⊆ i 2 ⊆ i Then, by Theorem 2, we have φ (z[S T ]) = I(G ) Q(z, W )dz[I(G )] Gi | R i 1 i and φ (z[S T ]) = I(U ) Q(z, W )dz[I(U )]. Now we have that Ui | R i 2 i R R φDi (z[S T ]) = φGi (z[S T ])φUi (z[S T ])dz[I(Di)] | RI(Di)\(I(Gi)∪I(Ui)) | | Z Since I(D ) (I(G ) I(U )) = J by Proposition 5, we have (2). i \ i ∪ i i

The form of Lemma 1 a generalized convolution. Since, for probability distribution functions Φ(x) and Ψ(x) whose derivatives are φ(x) and ψ(x) respectively, it is well known that R Φ(s)ψ(x s)ds = R φ(s)Ψ(x s)dx using integration by parts, we extend this idea to− our generalized convolution.− R R Proposition 6. Given a separated tree decomposition, we have

′ |Ti | D ΦDi (z[S T ]) = ( 1) ( Ji ΦGi (z[S T ])) ΦUi (z[S T ])dz[Ji] (3) | RJi − | | Z ′ |Si| D = ΦGi (z[S T ]) ( 1) ( Ji ΦUi (z[S T ])) dz[Ji]. (4) RJi | − | Z Proof. To prove (3), we execute the integration with respect to z[S(Di)] and

z D ′ z D ′ z z ΦDi ( [S T ]) = ( Si ΦGi ( [S T ])) Ti ΦUi ( [S T ])d [Ji], | RJi | | Z Thus, integration by parts with respect to z[t] for t T ′ leads to ∈ i

D ′ z D ′ z z ( Si∪{t}ΦGi ( [S T ])) Ti \{t}ΦUi ( [S T ])d [Ji], − RJi | | Z since (D ′ ΦG (z[S T ])) D ′ ΦU (z[S T ]) converges to 0 by definition when Si i | Ti \{t} i | z[t] . Now, we repeat the integration by parts with respect to all → ±∞ ′ components of z[Ti ], which leads to (3). The proof for (4) is symmetry.

17 3. Approximation for DAGs with Uniformly Distributed Edge Lengths The computation in the previous section may be slow when the edge lengths are uniformly distributed. This is because there may be exponen- tially many breakpoints in the derivative of some order of ΦD0 (xσ[S T ]) with respect to x, where σ[s] = 1 for s S(G) and σ[v] = 0 otherwise.| ∈ E Let G = (V, E) be a DAG. Each component of a vector a Z≥0 is a pa- rameter of a uniform distribution for e E. By considering∈ a uniform random vector X [0, 1]E, the random edge∈ length of edge e E is given ∈ ∈ by a[e]X[e]. Then, we consider computing the probability Pr[X x]= MAX ≤ ΦG(xσ[S T ]) = Vol(KG(a, x)). Though the problem of computing the exact value is a| #P-hard problem under this definition of the edge lengths, we show that there is a deterministic FPTAS. We in a sense generalize the algorithm in [2] for the volume of multiple constraint knapsack polytope so that we can deal with the case where we compute the volume of the hypercube [0, 1]m truncated by exponentially many halfspaces.

3.1. Idea of Our Algorithm The key idea of our approximation algorithm is that we discretize the dummy variables so that the integrals are considered to be discrete summa- tion as in [2]. Intuitively, the hardness of the exact computation is due to the exponentially many breakpoints of Pr[X x]. We consider a kind MAX ≤ of rounding technique. We pick up relatively small number of values as a stairway function (i.e., a piecewise constant function). This is possible at the leaves of the tree decomposition. Our algorithm then compute the union of the subtrees at a cost of mildly increasing the error. Staircase functions has an advantage in analysis. By setting the staircase size constant, we bound the approximation by a translation of ΦDi (z[S T ]). This is done from the leaves to the root. We call the quantity we| shift

ΦDi (z[S T ]) as “horizontal error”. That is, since ΦDi (z[S T ]) is a lower bound on| our approximation function, we estimate how much| we need to in- crease z[S(G)] (or, decrease z[T (G)]) so that Φ (z[S T ]) is an upper bound Di | on our approximation. Then, we can prove that the horizontal error increases only additively as our approximation advances from the leaves toward the root. In the analysis of the horizontal error, we further introduce the idea of vertex discount, which is the horizontal error defined at every source of Gi. When we bound the horizontal error at the root, then we at last can bound the multiplicative error by examining Pr[X x] as an m-dimensional MAX ≤

18 volume. Later, we call the multiplicative error ratio as “vertical” approxima- tion ratio in order to distinguish from the horizontal error in the above. The notion of horizontal and vertical error is analogous to plotting Pr[XMAX x] and its approximation in two dimensional space; the horizontal axis corre-≤ sponds to the argument x R and the vertical axis corresponds to the value ∈ of Pr[X x]. MAX ≤ 3.2. Detail of Our Algorithm We first approximate Φ (z[S T ])) by a staircase function Λ (z[S T ]; M) Gi | Gi | using parameter M. Since we can construct a separated tree decomposition by increasing k to at most 3k + 2, assuming a width k separated tree decom- position. In this setting, we prove that M = 2mn(k + 1)/ǫ is sufficient to bound the approximation ratio at most 1+ ǫ.⌈ Then, as an approximation⌉ of φ (z[S T ]), we compute the discrete difference of Λ (z[S T ]; M). We com- Gi | Gi | pute an extended form of the convolution of the differences for i =0,...,b 1 − so that we have the approximation of ΦD0 (z[S T ]). For any value of z[S T ], we compute Λ (|z[S T ]; M) by counting cells, i ∪ i Gi | def E(Gi) small orthogonal hypercubes in a hypercube Pi = [0, 1] satisfying certain |E(Gi)| conditions. We divide Pi into M cells whose diagonal vertices are given 1 1 E(Gi) by M gE and M (gE + 1) for gE 0, 1,...,M 1 . Given a value of z[S T ], we count the number N∈ {(z[S T ]; M)− of} cells intersecting i ∪ i Gi |

K′ (z[S T ]) def= x P a[uv]x[uv] z[s(π)] z[t(π)] . Gi |  ∈ i ≤ −  π∈Π(Gi) uv∈E(π)  ^ X 

To achieve this, we consider the following static longest path problem in + + + + Gi. We make another DAG Gi from Gi where V (Gi ) = Bi s , t and + + + ∪{ } E(G ) = E(Gi) s s tt . The length of uv E(Gi) is i s∈S(Gi){ } t∈T (Gi){ } ∈ x[uv]. For s S(G ), the length of s+s is z[s]. Similarly for t T (G ), ∈ S i S − ∈ i the length of tt+ is z[t]. Then, N (xg/M[S T ]; M) is the number of cells Gi | in Pi where the longest path length for some x in the cell is at most 0. By solving the static longest path problem in Gi, we can decide whether or not x P is in K′ (z[S T ]). We compute the number N (xg/M[S T ]; M) by ∈ i Gi | Gi | counting the number of gridpoints x = gE/M. To solve a static longest path problem in a DAG, see e.g., [10]. We approximate Φ (z[S T ]) by Gi | def Λ (z[S T ]; M) = N (xg/M[S T ]; M)M −|E(Gi)|, (5) Gi | Gi |

19 M where g is the discretized vector g[v] = x z[v] for v Si and g[v] = M z[v] for v T ; x is the longest path length bound of∈ the whole graph x ∈ i   G. Here, z (resp. z ) is a vector each of whose components is the ceiling   (resp. the⌈ floor)⌉ of the⌊ ⌋ corresponding component of z. By assuming a separated tree decompostion, we have that Λ (z[S T ]; M) Gi | is an upper bound of ΦGi (z[S T ]) because we count all the intersecting cells in P , and Φ (z[S T ])) is monotonically| increasing (resp. decreasing) with i Gi | respect to the components of z[Si] (resp. z[Ti]). x Consider the running time to compute NGi ( M g[S T ]; M) for all g Si∪Ti + | ∈+ 0, 1,...,M . The longest path problem in Gi can be solved in O( V (Gi ) + { + } 2 ||E(Gi)| | E(Gi ) ) = O(k ) time, where k is the treewidth of G. There are M | | |E(Gi)| cells of Pi and the number of grid points in Pi(x) is at most (M +1) 2 ≤ (M + 1)k(k+1) = O(M k +k). We have the following observation. Observation 1. Given M and a separated tree decomposition of G with width k, we can obtain an array of ΛGi (z[S T ]; M) for all possible input 2 | z [0, x]Si∪Ti in O(k2M k +k) time. ∈ We put Λ (z[S T ]; M)’s together for B into the approximation of Gi | i ∈ B Φ (z[S T ]) as follows. We define operator ∆(z ) for z = z[v] (v S ) D0 | v v ∈ i as, ∆(z )Λ (z[S T ]; M) def= Λ (z(v)[S T ]; M) Λ (z[S T ]; M) M , where v Gi | Gi | − Gi | x z(v)[v] = z[v]+ x/M and z(v)[w] = z for any w = v. We multiply M/x in  order to make the difference operator approximates6 the derivative. When u this is applied twice, ∆(zu)∆(zv)ΛGi (z[S T ]; M) = (∆(zv)ΛGi (z [S T ]; M) M | | − ∆(zu)ΛGi (z[S T ]; M)) x . Let Si = u1,...,u|Si| . The difference with re- | { def } spect to z[Si] is ∆(z[Si])ΛG (z[S T ]; M) = ∆(zu ) ∆(zu )ΛG (z[S T ]; M). i | 1 ··· |Si| i | ′ def ′ For any subgraph G of G, we set λ ′ (z[S T ]; M) = ∆(z[S(G )])Λ ′ (z[S T ]; M). G | G | We approximate the form in Lemma 1 using this difference. To obtain the values of λ (z[S T ]; M), we first compute the values of Λ (z[S T ]; M) Gi | Gi | at the gridpoints z[S T ]= x g for g 0,...,M Si∪Ti . Then, we compute i ∪ i M ∈{ } ∆(z )Λ ( x g[S T ]; M) for all g 0,...,M Si∪Ti . We store the values in v1 Gi M | ∈ { } an array with (M+1)|Si∪Ti| elements and compute ∆(z )∆(z )Λ ( x g[S T ]; M) v2 v1 Gi M | similarly for v S . We repeat computing this differences for v , v ,...,v v2 ∈ i 1 2 |Si| ∈ S . When we obtain the values of λ ( x g[S T ]; M) for g 0,...,M Si∪Ti , i Gi M | ∈{ } we will have S arrays with (M + 1)|Si∪Ti| elements each. We have the | i| following observation. Observation 2. Given a separated tree decomposition, an array of all pos- sible values of λ (z[S T ]; M) can be computed in O(M k+1) time. Gi | 20 Here, λ (z[S T ]; M) and then define Λ (z[S T ]; M) as an approxima- Di | Di | tion of Φ (z[S T ]). For each leaf bag B , we set λ (z[S T ]; M) def= Di | c ∈ B Dc | λ (z[S T ]; M). Asfor U , we set Λ (z[S T ]; M) def= Λ (z[S T ]; M). Gc | i Ui | j∈Ch(i) Dj | Then, we define λ (z[S T ]; M) as Di | Q λ (z[S T ]; M) def= λ (u[S T ]; M)λ (u[S T ]; M), (6) Di | Gi | Ui | g∈{0,...,M}Ji X where we set u[v] = x g[v] if v J , and u[v] = z[v] otherwise. Let v[s] = M ∈ i x g[s] for s S(D ) and v[v]= z[v] otherwise. Here, Λ (z[S T ]; M) is M ∈ i Di | x |S(Di)| Λ (z[S T ]; M) def= λ (v[S T ]; M) . (7) Di | Di | M 0≤g[XS(Di)]≤z  

By considering the following w, we save the memory space. Let Bh is (S(Di)∪T (Di))∩Bh the parent of Bi and g 0,...,M . We compute (6) and (7) setting w[v] = x g[v∈] for { v (S}(D ) T (D )) B ; w[s] = x for s M ∈ i ∪ i ∩ h ∈ S(Di) Bh and w[t]=0 for t T (Di) Bh. Observe that, by Proposition 2, s S(\D ) B and t T (D∈) B are\ not going to be connected to any ∈ i \ h ∈ i \ h vertex in the ancestor bag of Bi. Therefore, these w[s]’s and w[t]’s will never be used as the dummy variables of the integrals. We put w[S(Di) Bh] = x1 and w[T (D ) B ] = 0. By reducing the number of variables\ using i \ h this replacement, we can store λDi (w[S T ]; M) as an array with at most |(Si∪Ti)\Ji| k+1 | (M +1) (M +1) elements since λDi (w[S T ]; M) is a staircase function. In an execution≤ of Step 09 of Algorithm 1 for|λ (w[S T ]; M), we Di | compute a sum of at most (M + 1)k+1 = O(M k+1) values for each value of x g for g 0, 1,...,M Ji . We have the following observation. M ∈{ } Observation 3. Assume a separated tree decomposition with width k. Given

λGi (z[S T ]; M) and λUi (z[S T ]; M), we can compute an array of all possible values of| λ (w[S T ]; M) in| O(M 2k+2) time. Di | The following pseudocode shows our algorithm Approx-DAG. Algorithm 1. Approx-DAG(G, a, x, ) T ZE R Input: DAG G, edge lengths parameter a >0, x , and binary tree decomposition with bags∈ B ,...,B∈ ; T 0 b−1 ∈ B Output: Approximate value of Pr[XMAX x]; 01. For each bag B do ≤ i ∈ B 21 02. Compute Λ ( x g[S T ]; M) for all g 0,...,M Si∪Ti by (5); Gi M | ∈{ } 03. Compute λ ( x g[S T ]; M) for all g 0,...,M Si∪Ti ; Gi M | ∈{ } 04. done; 05. For each leaf bag Bc do 06. Set λ ( x g[S T ]; M∈) B := λ (w[S T ]; M) for all possible w; Dc M | Gc | 07. done; 08. For each bag Bi from the leaves to the root B0 do 09. Compute λ (w[S T ]; M) by (6) for all possible w; Di | 10. Compute ΛDi (w[S T ]; M) by (7) for all possible w; 11. done; | 12. Output Λ (xσ[S T ]; M). D0 | Remember that we construct a separated tree decomposition by increas- ing the treewidth to at most 3k + 2. Taking the sum of the running time in Observations 1,2 and 3, we have

Observation 4. The running time of Approx-DAG is O(k2bM 9k2+15k+6).

3.3. Analysis In this section, we bound the approximation ratio and prove the following theorem. In this section, we use σ for conciseness, where σ[s] = 1 for s S(G) and σ[v] = 0 otherwise. ∈ Theorem 3. Let G be a DAG whose underlying undirected graph has a separated tree decomposition with width k. Our algorithm outputs V ′ = ′ ΛD0 (xσ[S T ]; M) satisfying 1 V /ΦD0 (xσ[S T ]) 1+ ǫ. The running | ≤ k2+k| ≤ 2 2(k+1)mn time of our algorithm is O k n ǫ .     We prove M 2(k +1)mn/ǫ is sufficient. Instead of directly evaluating the approximation≥ ⌈ ratio Λ (xσ⌉[S T ]; M)/Φ (xσ[S T ])), we first seek an D0 | D0 | upper bound of ΛD0 (xσ[S T ]; M) given in the form of ΦD0 ((x + h)σ[S T ]) for some value h, which later| will be shown as a polynomial of k, n, m, x |and 1/ǫ. We show that Λ (xσ[S T ]; M) is bounded by Φ (xσ[S T ]) and its D0 | D0 | translation ΦD0 ((x + h)σ[S T ]) from below and from above. We call this h as the “horizontal error” because| we translate the plot of Pr[X x] = MAX ≤ Φ (xσ[S T ]) horizontally. Then, we prove the “vertical” approximation D0 | ratio as ΦD0 ((x+h)σ[S T ])/ΦD0 (xσ[S T ]), by showing that the upper bound and the lower bound are| not too far away| from each other.

22 To evaluate the “horizontal error”, we introduce the idea of vertex dis- count. We produce the approximation error in approximating Φ (z[S T ])) Gi | by a staircase function ΛGi (z[S T ]; M). Then, we must be careful about that an s t path π may be or may| not be affected by the approximation error − depending on how many times π goes through bag Bi (Remember Fig.1). We can explain the effect of such paths by associating the vertex discount to the sources of the corresponding bag-subgraph. We here define the vertex discount vector d of each bag-subgraph G for bag B as follows. i i i ∈ B def Definition 10. Let di be given for each bag Bi . We set di[s] = x def ∈ B M ( I(Gi) + 2)g[s] for s Si and di[v] = 0 otherwise. For any leaf bag | ˆ | ∈ Bc, dc = dc. To consider the parent bags, we define our max-merge as follows.

Definition 11. Let W and W be two sets. Let u RW1 and u RW2 be 1 2 1 ∈ 2 ∈ two vectors. Then, we write w = u u meaning that w is a max-merge of 1 ⊕ 2 u and u . That is, w RW1∪W2 so that w[v]= u [v] for v W and w[v]= 1 2 ∈ 1 ∈ 1 u [v] for v W . When W W = , we set w[v] = max u [v], u [v] . 2 ∈ 2 1 ∩ 2 6 ∅ { 1 2 } ˆ ˆ def For any internal bag Bi, di is the max-merge of vectors, where di = d dˆ . The max operation is necessary when Ch(i) = ℓ,r and i j∈Ch(i) j { } there is vertex s such that s S(G ) S(G ). In the following, we consider L ℓ r these vertex discounts as the∈ argument∩ of the related functions. Though we do not compute the vertex discount in the algorithm, we can prove the error bound by considering this vertex discount like a value related to each vertex in a kind of dynamic programming.

Definition 12. Let G = (V, E) be a DAG. Let d RV be a vector of ∈ ≥0 vertex discounts. For a dummy variable vector z = z1,...,z|V | , a constant ZE { } vector a ≥0 given as a part of the input and a uniform random vector X [0, 1]∈E. An event L (z[S T ]; d[V ]) occurs if and only if ∈ G | a[uv]X[uv] z[s(π)] z[t(π)] + d[v]. (8) ≤ − π∈^Π(G) uvX∈E(π) v∈XV (π) Therefore, the positive vertex discounts reduces the effect of the path lengths, which makes the probability Pr[L (z[S T ]; d[V ])] larger. G |

23 Definition 13.

Φ (z[S T ]; d [B ]) def= Pr[L (z[S T ]; d [B ])], Gi | i i Gi | i i φ (z[S T ]; d [B ]) def= D Φ (z, d [B ]), Gi | i i Si i i i Φ (z[S T ]; dˆ [V (D )]) def= Pr[L (z[S T ]; d [V (D )])], Di | i i Di | i i φ (z[S T ]; dˆ [V (D )]) def= D Φ (z[S T ]; dˆ [V (D )]). Di | i i S(Di) Di | i i Lemma 2 shows the rule about the max-merge of the vertex discount vectors when we join Φ (z[S T ]; d ) and Φ (z[S T ]; dˆ ). Gi | i Ui | i

Lemma 2. Assume a separated tree decomposition with width k. Let di, dˆi 0. Then, ≥

ˆ ˆ ΦDi (z[S T ]; di) φGi (z[S T ]; di[Bi])φUi (z[S T ]; di)dz[Ji]dz[S(Di)], | ≥ RJi | | ZR(Di) Z where R(D )= x RS(Di) x z[S(D )] . i { ∈ | ≤ i } Proof. By Lemma 1, the right hand side of the claim is clearly the longest path length distribution function in a graph where the sources and the termi- ˆ ˆ nals of Gi and Ui are connected and the vertex discount is di = di j∈Ch(i) dj. Notice that S S(U )= by Proposition 4. Since, for vertices v S(D ), i i Lj∈Ch(i) j that our max-merge∩ takes∅ the larger value as the component corr∈ esponding to v. This implies the inequality of the claim since Φ (z[S T ]; dˆT) is mono- Di | i tonically increasing with respect to all components of dˆi. We introduce the vertex discount to the other functions; N (z[S T ]; M, d ) Gi | i is the number of cells in P = [0, 1]E(Gi) intersecting K′ (z[S T ]; d ), where i Gi | i

K′ (z[S T ]; d ) def= x P a[e]x[e] z[s(π)] z[t(π)] + d [v] . Gi | i  ∈ i ≤ − i  π∈Π(Gi)e∈E(π) v∈V (π)  ^ X X 

 −|E(Gi)|  Then, ΛGi (z[S T ]; M, di) = NGi (xg/M[S T ]; M, di)M where g[s] = | | Mz[s]/x for s Si and g[t]= Mz[t]/x for t Ti. ⌈ To bound⌉ the∈ (horizontal) approximation⌊ ⌋ error∈ as the form of vertex dis- counts, we prove the following lemmas.

24 Lemma 3. Assume a separated tree decomposition with width k. Let z+[s]= z[s]+ x for s S and z+[v]= z[v] otherwise. We have M ∈ i Φ (z[S T ]; 0) Λ (z+[S T ]; M, 0) Φ (z[S T ]; d ). Gi | ≤ Gi | ≤ Gi | i Proof. Since the earlier inequality is obvious by the definition, we focus on the latter inequality. Let C P be any cell of P intersecting K′ (z[S T ]; d ). ⊆ i i Gi | i The latter inequality ΛGi (z[S T ]; M, 0) ΦGi (z[S T ]; di) is clear if we have ′ z d | ≤ | C KGi ( [S T ]; i). This implies that all counted cells in Pi intersect ′ ⊆z d | z d KGi ( [S T ]; i), whose volume is equal to ΦGi ( [S T ]; i). To prove| C K′ (z[S T ]; d ), let p, q C be| two extreme points of C ⊆ Gi | i ∈ so that p K′ (z[S T ]; 0) and q K′ (z[S T ]; 0). Remember that each ∈ Gi | 6∈ Gi | component of a point in C [0, 1]E(Gi) give the edge length of an edge in ⊆ 1 Gi. Since the edge lengths are nonnegative, the case where p = M gE and 1 E(G ) q = (gE + 1) for g 0, 1,...,M 1 i gives the maximum difference M E ∈{ − } of all path lengths in Gi. By definition of p and q, we have, for any fixed z[S T ], that p and q yields the same longest path π Π(G ) satisfying i ∪ i ∈ i x x x x p[e] z[s(π)] + z[t(π)] q[e]+ = p[e]+ + ≤ M − ≤ M M M e∈E(π) e∈E(π) e∈E(π)   X x X X z[s(π)] + ( I(G ) + 2) z[t(π)]. ≤ M | i | − Thus, we have q K′ (z, d ), implying C K′ (z, d ). ∈ Gi i ⊆ Gi i ˆ ˆ We define λDi (z[S T ]; M, di) and ΛDi (z[S T ]; M, di) by (6, 7) replacing Λ (z[S T ]; M) by Λ | (z[S T ]; M, d ) where,| for leaf bag B , we set Gi | Gi | i c ∈ B λDc (z[S T ]; M, dc)=ΛGc (z[S T ]; M, dc). Though| Λ (z[S T ]; M, d )| is a stairway function, we consider the deriva- Di | i tive of ΛDi (z[S T ]; M, di) with respect to continuous variables in vector z. This is done by| introducing Dirac delta function δ(x). We have the following. Lemma 4. Given a separated tree decomposition with width k, let

Υ (z[S T ]; M, dˆ )def= D Λ (z[S T ]; M, dˆ ), and Ui | i S(Ui) Ui | i Γ (z[S T ]; M, dˆ )def= φ (z[S T ]; d )Υ (z[S T ]; M, dˆ )dz[J ]dz[S(D )], Di | i Gi | i Ui | i i i J R(ZDi)ZR i where R(D )= x RS(Di) x z[S(D )] . Then, i { ∈ | ≤ i } Λ (z[S T ]; M, 0) Γ (z[S T ]; M, d ). Di | ≤ Di | i 25 Proof. We execute integrals with respect to z[S(Di)] in the definition of Γ (z[S T ]; M, dˆ ). By Proposition 6, we have Di | i

′ ˆ |Si|D ˆ ΓDi (z[S T ]; M, di)= ΦGi (z[S T ]; di))( 1) Ji ΛUi (z[S T ]; M, di)dz[Ji]. | RJi | − | Z This is equal to

′ Φ (u[S T ]; d ))( 1)|Si|∆(z[J ])Λ (u[S T ]; M, dˆ ), Gi | i − i Ui | i g∈{0,...,M}Ji X by the property of Dirac delta function δ(x). On the left hand side of the claim, consider executing the summation of the definition of ΛDi (z[S T ]; M, 0) with respect to z[Si]. By considering the discrete analogy of Proposition| 6, we have

′ Λ (z[S T ]; M, 0)= Λ (u+[S T ]; M, 0)( 1)|Si|∆(z[J ])Λ (u[S T ]; M, 0), Di | Gi | − i Ui | g∈{0,...,M}Ji X + x ′ + x ′ + where u [s]= M (g[s]+1) for s Si, u [t]= M g[t] for t Ti and u [v]= z[v] otherwise. Here, we executed∈ the “summation by parts”∈ instead of the integration by parts. See [19]. The claim is now clear from Lemma 3. The following lemma proves the total vertex discount for the entire graph. Lemma 5. Assume a width k separated tree decomposition. For the root bag B , we have Φ (z[S T ]; 0) Λ (z[S T ]; M, 0) Φ (z[S T ]; dˆ ). 0 ∈ B D0 | ≤ D0 | ≤ D0 | 0 Proof. Since the inequality on the left is obvious by the definition, we prove the inequality on the right in the following. By induction on i, we prove ˆ that ΛDi (z[S T ]; M, 0) ΦDi (z[S T ]; d0). As for the base case, for any leaf bag B |and s =≤z[S ] and| t = z[T ], we have Λ (z[S T ]; M) = c ∈ B c c c c Dc | ΛGc (z[S T ]; M, 0) ΦDc (z[S T ]; dc) by Lemma 3. | ≤ | ˆ We assume that ΛDj (z[S T ]; M) ΦDj (z[S T ]; dj) for j Ch(i) as the induction hypothesis. Consider| the≤ middle part| Λ (z[S T∈]; M, 0) of the Di | claim. This is is at most Γ (z[S T ]; M, dˆ ) by Lemma 4. By executing the Di | i integrals with respect to z[S(U )], we have Γ (z[S T ]; M, dˆ ) equal to i Di | i D ˆ ( Ji ΦGi (z[S T ]; di)) ΛUi (z[S T ]; M, di)dz[Ji], RJi | | Z

26 by Proposition 6. Remember that S(Di) Ji = by Proposition 5. By induction hypothesis, this is at most ∩ ∅

′ |Ti | D ˆ ˆ ( 1) ( Ji ΦGi (z[S T ]; di)) ΦUi (z[S T ]; di)dz[Ji] ΦDi (z[S T ]; di). RJi − | | ≤ | Z The last inequality is due to Proposition 6 and Lemma 2, implying the lemma.

Now, we transform the total vertex discounts into the horizontal error (k+1)nx h = M . Lemma 6. Φ (xσ[S T ]; dˆ ) Φ ((x +(k + 1)nx/M)σ[S T ]; 0) D0 | 0 ≤ D0 | Proof. By the definition, we have dˆ [v] (k+1)x for any v V . Therefore, 0 ≤ M ∈ the static longest path length using dˆ0 as the vertex discount is at most (k+1)nx M . Now, by adding this value to xσ[S(G)], we get the claim. The following shows the “vertical” approximation ratio of our algorithm. By using the notion of the vertex discounts, we can apply the similar argu- ments as in [2]. Remember that n = V and m = E . | | | | Lemma 7. Assume a width k separated tree decomposition. Let M = 2(k + ΛD (xσ[S|T ];M,0) ⌈ 1)mn/ǫ . Then, 1 0 1+ ǫ. Φ (x [S|T ]; ) ⌉ ≤ D0 σ 0 ≤ Proof. Since the earlier inequality is clear by the definition, we prove the lat- ter inequality. Let η = 1+(k+1)n/M. Since we have that ΛD0 (xσ[S T ]; M, 0) ˆ | is at most ΦD0 (xσ[S T ]; d0) ΦD0 (ηxσ[S T ]; 0) by Lemma 5 and 6, we |Φ (xσ[≤S T ]; 0) Φ| (xσ[S T ]; 0) bound, from below, D0 | D0 | . ΛD0 (xσ[S T ]; M, 0) ≥ ΦD0 (ηxσ[S T ]; 0) Φ |(xσ[S T ]; 0) | ǫ −m Then, we claim that D0 | η−m = 1+ . This ΦD0 (ηxσ[S T ]; 0) ≥ 2m |   claim is verified as follows. By definition, ΦD0 (xσ[S T ]; 0) is the volume of K (a, x) = K′ (xσ[S T ]; 0). Consider another polytope| K˜ (a, x) that is G G | G obtained by scaling KG(a, x) by η. That is,

K˜ (a, x) def= x Rm y K (a, x) s.t. x = ηy G { ∈ |∃ ∈ G } Then, it is clear that K (a, ηx) K˜ (a, x). This implies that G ⊆ G Φ (xσ[S T ]; 0) Vol(K (a, x)) Vol(K (a, x)) D0 | = G G . ΦD0 (ηxσ[S T ]; 0) Vol(KG(a, ηx)) ≥ Vol(K˜ (a, x)) | G

27 −m ǫ −m This is equal to η 1+ 2m , implying the claim. ≥ −m m Now, we have 1+ ǫ 1 ǫ 1 mǫ = 1 ǫ . The first 2m  2m 2m 2 inequality is because ((1 + ǫ )(1≥ ǫ −))m 1.≥ Then,− we have,− for 0 ǫ 1, 2m 2m  Φ (ηxσ[S T ]; 0)/Φ (xσ[S T ]; 0−) 1/(1≤ ǫ/2) 1+ ǫ, which implies≤ ≤ the D0 | D0 | ≤ − ≤ lemma. The restriction ǫ 1 is not essential. We set ǫ = 1 instead of larger approximation ratio. ≤ Remember that we increase the treewidth to at most 3k + 2 construct a separated tree decomposition. Theorem 1 is clear from Theorem 3.

4. Other Edge Length Distributions Remember that the edge lengths that obey another distribution giveusa similar, but different problem. If we assume some well-behaved edge length distribution and the input graph G has constant treewidth, sometimes it is possible to compute the exact value of Pr[XMAX x]. In this section, we first explain some technique about processing the≤ integrals. Then, we show two results. The first result is about the case where the edge lengths obey the standard exponential distribution. The second result is about the case we have edge lengths obey some abstract distributions where the Taylor approximation is applicable. As in the previous section, we first assume a separated tree decomposition with width k. Then, we replace the treewidth k by 3k + 2 to construct the separated tree decomposition.

4.1. Integration of Step Functions Before considering the actual problems, we need some preliminaries about the integrals using step functions. Here, we first define the following ‘equality almost everywhere’. Then, we next explain how long the resulting form can be in case we have many step functions as the factors of the integrand.

Definition 14. Let F (x) and F˜(x) be two piecewise polynomial functions for x Rk. If F (x)= F˜(x) for x Rk I where the k-dimensional measure of I is∈ 0, then we write F (x) a=.e. F˜∈(x).\ If F (x) a=.e. F˜(x), we say F (x) and F˜(x) are equal almost everywhere.

The following is convenient for describing the function with cases.

Definition 15. Let H(x) be Heaviside step function, where H(x)=0 for x< 0 and H(x)=1 for x 0. ≥

28 In case F (x) = 1 for any x R, we have F (x) a=.e. H(x)+ H( x) where the equality does not hold for ∈x = 0. Though we may have some− wrong values at the breakpoints, the wrong values at the breakpoints do not matter when we execute another integral that has F (x) as the integrand. We use H(x) in describing the functions with cases even though they may be only equal almost everywhere to the original function. This is space-efficient. Executing an integral of a step function needs some attention. Let f(x) R x be a function of x such that limx→−∞ f(x) = 0 and F (x)= −∞ f(x)dx converges to a finite∈ value. For any y, z Rn, we have ∈ R H(x y[i]) H(z[i] x) f(x)dx = H(z y)(F (z) F (y)), x∈R − − ! − − Z i=1Y,...,k i=1Y,...,k where z = min z[i] , y = max y[i] . For convenience, we replace 1≤i≤k{ } 1≤i≤k{ } H(z y), F (z) and F (y) by a sum of k! terms of step function products by using− the idea of the equality almost everywhere. That is, F (z)= P (z, 1) and F (y) = P (y,k) using P (x, i) a=.e. F (x[p ]) H(x[p ] p∈Perm(k) i 1≤j≤k−1 j+1 − x[p ]). Here, Perm(k) is the set of all k! permutations of 1,...,k. Each j P Q element p of Perm(k) is given by a k-tuple p = (p1,...,pk). Though the right hand side may have wrong values at points where any two variables are equal (e.g., z[pj]= z[pj+1] or y[pj]= y[pj+1]), the space of the wrong values has measure 0. Since, if F (z) is well behaved like exponential distribution function, we can recover the values F (z) at any point z where z[pi]= z[pi+1] by using the continuity. That is, we may compute the value of limt→+0 F (z + th), as long as we have an expression of F (z) which is exact in a continuous region including z + th and there is no breakpoint of step function factors between z and z + h.

4.2. Exact Computation for Exponentially Distributed Edge Lengths Here, we consider the case where the edge lengths are mutually indepen- dent and obey the standard exponential distribution. By the direct compu- tation of the integrals, we obtain Pr[X x] exactly. MAX ≤ The following is the definition of the standard exponential distribution. Definition 16. A random variable X obeys the standard exponential distri- bution if the random edge lengths X satisfies Pr[X x]= H(x)(1 e−x). ≤ − We here consider an edge length Xuv obeys the standard exponential distribution if uv E. Assuming that the Napier’s constant e and its power can be computed∈ in O(1) time, we have the following theorem.

29 Theorem 4. Let G = (V, E) be a DAG with treewidth at most k. As- sume that the edge lengths are mutually independent and obey the stan- dard exponential distribution. There is an algorithm that exactly computes Pr[X x] in ((6k + 4)mn)O(k) time. MAX ≤ Given a DAG G and its tree decomposition, our algorithm is the following.

We first compute φGi (z[S T ]) exactly for each bag Bi by Theorem 2. Then, we put φ (z[S T ])’s| together starting from the leaf∈ bags B to the root so Gi | that we have φDi (z[S T ]) for each Bi as shown by Lemma 1. In the ongoing computation, the integrand| can be transformed into a sum of terms where each term is a product of the powers of zi’s and the exponential functions of zi’s. Thus, we can store the resulting form of the ongoing computation in a 2k-dimensional array. In order to save some memory space, we consider w defined as follows. Let Bh be the parent of Bi. In executing Step 08, we put w[v] = z[v] for v (S(D ) T (D )) B , w[s] = x and for s S(D ) B w[t] = 0 for ∈ i ∪ i ∩ h ∈ i \ h t T (Di) Bh. ∈ The following\ is the algorithm for computing the value of Pr[X x]. MAX ≤ Algorithm 2. Exact-Exponential(G, (G), x): T Input: DAG G, binary tree decomposition (G) of G with bags B0,...,Bb−1, and longest path length x R; T ∈ Output: Value of Pr[X x]; MAX ≤ 01. For each Bi do: 02. Compute φ∈ B(z[S T ]) by Theorem 2; Gi | 03. done; 04. For each leaf bag B of (G) do: c ∈ B T 05. Set φDc (w[S T ]) := φGc (w[S T ]); 06. done; | | 07. For each bag B from the leaves to the root B do: i ∈ B 0 08. Compute φDi (w[S T ]) by Lemma 1; 09. done; | 10. Compute and Output Φ (xσ[S T ]). D0 | The proof of Theorem 4 is by a direct estimation of the amount of space and time for storing and computing φ (z[S T ]) and φ (z[S T ]). Since, in Gi | Di | the proof, we consider the time and space for generating and storing the ongoing computation, we first briefly describe what we consider is a form.

30 Definition 17. We consider the following as a unit of a form: a real num- ber, a variable and its power, a step function and an exponential function. What we call a form is a unit in the above or a combination of these units by arithmetic operations: addition, subtraction, multiplication and division. Each arithmetic operation have on its each side a unit or a parenthesized form. The sum of products is a form where the parenthesized forms in it consists of a product of some units. A term in a form is a group of units that are connected continuously by products or division. A coefficient of a term is a number that is obtained by executing all multiplications and the division of numbers in the term.

Proof. (of Theorem 4) To estimate the running time of the algorithm, we first bound the number of terms appears in the form of φ (z[S T ]). We Gi | first assume a separated tree decomposition with width k. Then, the number of terms is bounded by using the number of variables, which is at most k. At the last of the proof we replace the treewidth by 3k + 2 to construct a separated tree decomposition. We note that

∂ −(zu−zv) φGi (z[S T ])= H(zu zv)(1 e )dz[I(Gi)]. | RI(Gi) ∂zu − − Z u∈YI(Gi) v∈YSuc(u) Since the standard exponential density function is H(x)e−x, all formulas that appear in the ongoing computation can be written by the combinations of the step function H(x), the polynomial and the exponential function. We first consider the step function factors in the integral. Though one integral using step functions can produce many cases for the resulting form, we can break down each of these cases as a sum of step function products. Then, we execute the integral for all possible permutations of zv’s for v Bi. Therefore, the number of possible step function products in φ (z[S T∈]) is Gi | at most (k + 1)!. We show that at most nk+1(2m + 1)k+1 polynomial-exponential product terms are possible to appear in φ (z[S T ]) for each permutation of z ’s for Gi | v v B . Observe that each term is a product of zαv and exp(β z ), where α ’s ∈ i v v v v and βv’s are integers. Let us first expand the integrand in the form of Lemma 1 into the sum of products. We can see that the βv of exp(zv) can increase or decrease at most by one in taking a product of two distribution 2 2 functions and hence βv’s are integers between k and k . Consider executing αv βvzv − αv αv +1 the indefinite integral zv e dzv. In case βv = 0, zv dzv = zv /(αv + R R 31 1)+c, where we may set c = 0 here. In case βv = 0, integration by parts leads αv 6 to zαv eβvzv dz = β−1zαv eβvzv + ( 1)i(α !/(α i)!)β−i−1zαv −ieβvzv . v v v v i=1 − v v − v v The degree αv of zv that appear in the terms in the formula of φG (z[S T ]) R P i | can increase at most by one in one integral (in case βv = 0) and hence αv’s are at most k non-negative integers. This implies that, for each permutation of the at most k + 1 argument variables φGi (z[S T ]) consists of at most (k +1)k(2k2 +1)k terms, when we expand the resulting| form into the sum of products. Therefore, we need an array of O((k+1)!(k+1)k(2k2 +1)k) kO(k) ≤ real numbers for the coefficients of the terms in φGi (z[S T ])). By the similar argument, we bound the number of| array elements to store φDi (z[S T ]). Since the subtree graph is connected to the rest of the other parts only| by the vertices at the root of the subtree, we have at most k + 1 variables (z for v S(G )) in φ (z[S T ]). In the similar way v ∈ i Di | as φGi (z[S T ]), we expand φDi (z[S T ]) into the sum of products of step functions and| polynomials and exponential| functions. The difference be- tween φGi (z[S T ]) and φDi (z[S T ]) is that the degree αv of each dummy variable z is| nonnegative and| is at most V (D ) ; the absolute value of v | i | degree βv of exp(zv) is at most E(Di) . Therefore, we need an array of k k | O(k)| (k + 1)!n (2m + 1) (k + 1)!(2mn) real numbers to store φDi (z[S T ]). Then, we bound≤ the time to compute φ (z[S T ]) from φ (z[S T ])| and Di | Gi | φDj (z[S T ])’s for j Ch(i). To expand the integrand into the sum of products,| it takes running∈ time proportional to the size of array to store φ (z[S T ]) multiplied by the size of arrays to store φ (z[S T ]) for j Gi | Dj | ∈ Ch(i). Since we assume the binary tree decomposition, we have Ch(i) 2 by our assumption. This implies that we can bound the running| time| ≤ of the part of expanding the integrand by kO(k)(2mn)O(k) from above. Since α we can compute the antiderivative of zv exp(βzv) in O(α) time for posi- tive integer α n using integration by parts, the time to integrate each ≤ O(k) term in φDi (z[S T ]) is k O(n). We can compute the entire integration by computing the| integral of every possible terms. The running time for computing φ (z[S T ]) from φ (z[S T ]) and φ (z[S T ])’s for j Ch(i) is Di | Gi | Dj | ∈ kO(k)O(n)(2mn)O(k) (2kmn)O(k). Now, we repeat this computation for all ≤ Bi . We obtain the running time in the claim by replacing the treewidth k by∈ 3Bk + 2 in order to construct a separated tree decomposition.

4.3. Taylor Approximation of the Edge Length Distribution Function In case we can use the Taylor approximation, we have an approximation scheme for Pr[X x] with additive error ǫ′. Now the definition of the MAX ≤ 32 distribution function Fij(x) is given as an abstract way. As a part of the input, we assume that we have an oracle that computes Fuv(x) for each edge uv E. Let τ be a parameter of our algorithm. We also assume ∈ (d) that the oracle computes the exact value of Fuv (t) for d 0, 1,...,τ and (d) ∈ t [0, x] in O(1) time, where Fuv (x) is the derivative of order d of Fuv(x). For∈ F (x) = Pr[X x], we assume following three conditions: uv uv ≤ • The length X of each edge uv E is nonnegative; uv ∈ • For any edge uv E, the distribution function Fuv(x) satisfies that (d) ∈ Fuv (t) 1 for any d 0, 1,...,τ and t [0, x]; | | ≤ ∈{ } ∈ • The Taylor series of Fuv(x) converges to Fuv(x) itself. Our approximation algorithm takes ǫ′ (0 < ǫ′ 1) and x > 0 as its inputs and it gives a polynomial F˜ (x) that approximates≤ Pr[X x]. the MAX MAX ≤ constraint ǫ′ 1 is because we approximate the probability that is at most 1. We have the≤ following theorem. Theorem 5. Let G be a DAG whose underlying undirected graph has treewidth at most k. Given the binary tree decomposition (G) with b = O(n) bags and the distribution function F (x) of the lengthsT of each edge uv E de- uv ∈ scribed as above. There exists an algorithm that computes F˜MAX(x) in time O(k2) O(k2) ′ O(n(3k + 2) τ ) satisfying F˜MAX(x) Pr[XMAX x] ǫ , where τ = (e2 + 1)(3k + 3)x + 2 ln b + ln(1| /ǫ′) +1−. ≤ | ≤ ⌈ ⌉ Since it is easy to see that F (x) = 0 for x 0, we concentrate on MAX ≤ the case x 0. By the Taylor approximation of f(z), we mean the Taylor approximation≥ that is generated by f(z) at the origin z = 0. We call the following as the Taylor approximation (see e.g., [9]).

Definition 18. Let z =(z1,...,zk). Let F (z) be a k-variable function. The i order τ Taylor approximation of F (z) is F˜(z) def= τ 1 k z ∂ F (0). i=0 i! j=1 j ∂zj   Here, F˜(z) approximates F (z) well for sufficientlyP largeP (but not very large) τ. It is well known that the additive error of the approximation is bounded by the following. k Proposition 7. Let z = (z1,...,zk) R . For a k-variable function F (z) τ+1 ∈ satisfying k ∂ F (z) kτ+1, for any 0 z x1, we have j=1 ∂zj ≤ ≤ ≤ τ+1 ˜ z zP (kx)  F ( ) F ( ) (τ+1)! . | − | ≤ 33 The proof of this proposition can be done by a straightforward extension of the proof for the remainder of two variables function in [9]. Our algorithm is as follows. For each bag Bi , we compute the ˜ ∈ B order τ Taylor approximation φGi (z[S T ]) of φGi (z[S T ]). In computing φ˜ (z[S T ])), we compute the order τ Taylor| approximation| of the integrand Gi | of the form in Theorem 2. Note that the integrand and its derivatives can be computed exactly by our assumption. Then, as φ˜ (z[S T ]), we compute Gi | the order τ Taylor approximation of the resulting form after executing all integrals. For each leaf bags B , we set φ˜ (z[S T ]) def= φ˜ (z[S T ])). Let c ∈ B Dc | Gc | Φ˜ (z[S T ]) = Φ˜ (z[S T ]) and φ˜ (z[S T ]) = D Φ˜ (z[S T ]). Ui | j∈Ch(i) Dj | Ui | S(Ui) Ui | Then, φ˜ (z[S T ]) is an approximation of Di | Q def ˜ ˜ ψDi (z[S T ]) = φGi (z[S T ])φUi (z[S T ])dz[Ji], (9) | Ji | | Zz∈[0,x] which is analogous to Lemma 1. In approximating (9), every time we execute an integral with respect to a variable zv for v Ji, we compute the order τ ∈ ˜ Taylor approximation of the resulting form. Then, we have φDi (z[S T ]) as the order τ Taylor approximation of the resulting form after executing| all in- def tegrals in (9). Now, we put Φ˜ D (z[S T ]) = φ˜D (z[S T ])dz[S(Di)], i | (0,z[S(Di)]) i | where (0, z[S(D ]) = x RS(Di) 0 x z . i { ∈ | ≤ ≤ R} In order to save some memory space, we define w as follows. Let Bh be the parent of B . We put w[v] = z[v] for v (S(D ) T (D )) B , i ∈ B ∈ i ∪ i ∩ h w[s]= x for s S(Di) Bh and w[t]=0 for t T (Di) Bh. The following∈ is our\ algorithm. ∈ \

Algorithm 3. Approx-Taylor(G, (G), x, ǫ′) Input: DAG G, binary tree decompositionT (G), longest path length x R, T ∈ and the additive error ǫ′; Output: Approximate value of Pr[XMAX x]; 01. Set τ := (e2 + 1)(k + 1)x + 2 ln b + ln(1≤ /ǫ′); 02. For each Bi do 03. Compute φ˜∈( Bz[S T ]) as the order τ Taylor approximation of φ (z[S T ]); Gi | Gi | 04. done; 05. For each leaf bag Bc of (G) do: 06. Set φ˜ (z[S T ]) :=∈φ˜ B (z[ST T ]); Dc | Gc | 07. done; 08. For each B from the leaf to the root do i ∈ B 34 ˜ 09. Compute φDi (w[S T ]) as the order τ Taylor approximation of (9); 10. done; | 11. Compute and output Φ˜ (xσ[S T ]). D0 | Proof. (of Theorem 5) At first, we prove the theorem assuming a separated tree decomposition with width k. In the proof, we assume that all forms are expanded into the sum of products. We store a form on memory as an array of coefficients of terms. In addition to Definition 17, the edge length distribution functions and its derivatives are also the units of the form. Consider the array size for storing Φ˜ (z[S T ]) and Φ˜ (z[S T ]). Since Gi | Di | the integration of step function factors is processed exactly the same way as in the proof of Theorem 4, the number of possible combination of step function ˜ factors is at most (k + 1)!. Since the polynomial factors of φGi (z[S T ]) and ˜ | φDj (z[S T ]) are degree τ polynomials of at most k +1 variables, there are at most τ k+1| polynomial factors. Thus, an array of (k + 1)!τ k+1 real values is ˜ ˜ sufficient to store φGi (z[S T ]) and φDi (z[S T ]). | | ˜ Consider the running time for computing φGi (z[S T ]). For computing φ˜ (z[S T ]), consider expanding the integrand of the form| in Theorem 2 into Gi | a sum of products. By ignoring the step function factors, we have

∂ fuv(zu zv) Fuv(zu zv)= − Fuw(zu zw). ∂zu − Fuv(zu zv) − u∈YI(Gi) v∈YSuc(u) u∈YI(Gi) v∈XSuc(u) − w∈YSuc(u) Then, each term is a product of the order at most 1 derivatives of at most k(k 1) edge length distribution functions. Since we compute the Taylor − approximation of order τ we claim that we have (τ + 1)k(k−1) terms in com- puting the order τ + 1 derivative of the integrand. To verify this, consider the following. For each d = 0,...,τ E(Gi), the integrand omitting the step function factors is, { }

τ! (duv) Fuv (zu zv) uv∈E(Gi) duv! − d∈{0,...,pX}E(Gi) (u,v)Y∈E(Gi) Q where d = d[uv] 0, 1,...,τ for uv E(G ) and d satisfies that uv ∈ { } ∈ i uv∈|E(Gi)| duv = τ, implying that the number of the terms is at most τ |E(Gi)| τ k(k−1). Since each term can be computed in O(k(k 1)) time, the P running≤ time to obtain the order τ Taylor approximation is O−(k(k 1)(τ + 2 − 1)k(k−1)) O(k2τ k ). Since we have at most (k + 1)! combinations of the step function≤ factors, the running time is O(kk2 τ k2 ).

35 By the assumption that we have a binary tree decomposition as the input ˜ and by the definition of φDi (z[S T ]), the most time consuming part of the ˜ | ˜ ongoing computation of φDi (z[S T ]) is the multiplication of φGi (z[S T ]) and ˜ | k+1 3 | φUi (z[S T ]). Here, we need ((k + 1)!τ ) arithmetic operations to compute the coefficients| of all terms of the integrand of φ˜ (z[S T ]). Since executing Di | the integrals for each polynomial term can be done in O(1) time, it takes 3k 3k+3 ˜ at most (k + 1) τ time to obtain φDi (z[S T ]). Therefore, we compute ˜ O(k) O(k) | ΦD0 (z[S T ]) in bk τ time since we repeat the above procedure for each vertices of| each bags, where b = O(n) by our assumption. Next, we prove that τ (e2 + 1)(k + 1)x + 2 ln b + ln(1/ǫ′) + ln 4 1 is ≥ ˜ ′ − sufficient to bound the additive error of ΦD0 (z[S T ]) at most ǫ , using the assumption of the separated tree decomposition. | ′ ˜ ˜ Let ǫj(z) be the additive error of ΦDj (z[S T ]) so that ΦDj (z[S T ]) = ′ ′ | ′ Si∪|Ji ΦDj (z[S T ]) + ǫj(z). Let ǫi be the maximum of ǫi(z) for z [0, x] . We have | | | ∈

τ+1 ′ ((k + 1)x) ǫi ψDi (z[S T ])dz[S(Di)] ΦDi (z[S T ]) + , ≤ S(Di) | − | (τ + 1)! Z[0,x] (A) (B) | {z } | {z } where ψDi (z[S T ]) is defined by (9). The earlier part (A) is due to the additive error produced| in the approximation before Step 09. By Proposition 7, the latter part (B) is due to the additive error produced in computing the order τ Taylor approximation in Step 09. def ′ Let ξ˜ (z[S T ]) = ( 1)|Ti |D Φ˜ (z[S T ]). In case Ch(i) = ℓ,r , part Gi | − Ji Gi | { } (A) is equal to

˜ ˜ (A) = ξGi (z[S T ])ΦUi (z[S T ])dz[Ji] ΦDi (z[S T ]), RJi | | − | Z by executing the integral with respect to s S(Di) and then executing the integral by parts with respect to t T ′.∈ Let δ be the additive error of ∈ i i ˜ S T ˜ ξGi (z[S T ]) so that δi = maxz∈[0,x] i∪ i ξGi (z[S T ]) ξGi (z[S T ]) , where | ′ | | − | | ξ (z[S T ]) = ( 1)|Ti |D Φ (z[S T ]). We assume that ǫ′ ǫ′ without loss Gi | − Ji Gi | ℓ ≥ r of generality. Then, we have

′ (A) (ξGi (z[S T ]) + δi) (ΦDj (z[S T ]) + ǫj)dz[Ji] ΦDi (z[S T ]). ≤ RJi | | − | Z j∈YCh(i)

36 By canceling Φ (z[S T ]) using Proposition 6, the right hand side is at most Di |

′ ′ (ΦDℓ (z[S T ])ǫrξGi (z[S T ]) + ǫℓΦDr (z[S T ])ξGi (z[S T ])) dz[Ji] RJi | | | | Z

′ ′ ′ + ǫℓǫrξGi (z[S T ]) + δi (ΦDj (z[S T ]) + ǫj) dz[Ji] RJi  | |  Z j∈YCh(i)  ′ ′  ((ǫℓ +2ǫr)ξGi (z[S T ]) + 4δi) dz[Ji]. ≤ RJi | Z We have the last inequality because of that Φ (z[S T ]), Φ (z[S T ]) 1 Dℓ | Dr | ≤ and ǫ′ ǫ′ 1. Also, by executing the integrals with respect to z[J ], we r ≤ ℓ ≤ i have RJi ξGi (z[S T ])dz[Ji] = limz[Ji]→∞ ΦGi (z[S T ]) 1. After all, part (A) is bounded from| above by ǫ′ +2ǫ′ +4xk+1δ . | ≤ R ℓ r i Consider the bound of δi. By the assumption, we can compute the inte- grand (and its derivatives) of Theorem 2 can be computed exactly for each bag-subgraph Gi. Then, we compute the order τ Taylor approximation of the integrand that produces the additive error δi given in Proposition 7, where we have k + 1 variable function. Let R(k,τ,x) def= ((k + 1)x)τ+1/(τ +1)! be the upper bound on δi. Since we execute the integral with respect to at most k+1 k + 1 variables in interval (0, x), we have that δi x R(k,τ,x). ′ ′ ≤ ′ k+1 Since the above arguments imply that ǫi ǫℓ +2ǫr +(4x +1)R(k,τ,x), ′ ≤ ′ we consider the total additive error ǫ0. Since we simply set ǫr = 0 in case Ch(i) = 1, the worst is the case in which tree decomposition (G) is a | | ′ ′ T complete binary tree where ǫℓ = ǫr. We bound the additive error from the leaf to the root. For leaf bag B , we have ǫ′ = δ′ R(k,τ,x). c ∈ B c c ≤ Every time we go up, the error at the children is multiplied by 3 and added k+1 ′ ⌈log2 b⌉ k+1 by (4x + 1)R(k,τ,x). Thus, ǫ0 log2 b 3 (4x + 1)R(k,τ,x) b2(4xk+1 + 1)R(k,τ,x). ≤ ⌈ ⌉ ≤ Let us estimate sufficiently large τ to achieve ǫ′ ǫ′. Then, 0 ≤ ((k + 1)x)τ+1 ln ǫ′ ln ǫ′ ln(1/ǫ′) ln b2(4xk+1 + 1) ln . − 0 ≥ − − − (τ + 1)!

This is at least ln(1/ǫ′) 2 ln b ln 4 (k +1) ln(x+1)+(τ +1) ln τ+1 − − − − e(k+1)x by Stirling’s approximation n! √2πn n n n n, where e is the Napier’s ∼ e ≥ e constant. To make this lower bound positive, τ +1 max e2(k +1)x, 2 ln b+   (k + 1) ln(x + 1) + ln(1/ǫ′) + ln 4 is sufficient. Remember≥ that{ we replace the } 37 tree width k by 3k + 2 to construct a separated tree decomposition. Since ln 4 = 1.386... we have the theorem, where we take the sum rather than taking the max.

5. Further Discussion In this paper, we considered the problem of computing the distribution function of the longest path length of a DAG G with random edge lengths. Though another assumption of the edge lengths gives another problem, it seems that the larger treewidth make our algorithms slow in a similar manner. Since it is well known that there is an FPRAS even for the large treewidth DAGs, we conclude that if the randomness really give some computational ability in the volume computation, the difference may lie in the problem of graph with large treewidth.

Acknowledgment This work was partly supported by JSPS KAKENHI Grant Number 19K11832. The author is grateful to the anonymous reviewers for the useful advice and comments.

References [1] Ando, E., Ono, H., Sadakane, K., and Yamashita, M.: Computing the Exact Distribution Function of the Stochastic Longest Path Length in a DAG. In: Chen, J., Cooper, B.S.(eds.) Theory and Applications of Models of Computation 2009. LNCS, vol. 5532, pp. 98–107. Springer, Heidelberg (2009)

[2] Ando, E., Kijima, S.: An FPTAS for the Volume Computation of 0 1 Knapsack Polytopes Based on Approximate Convolution. Algo- − rithmica 76, 1245–1263 (2016)

[3] Ando, E., An FPTAS for Computing the Distribution Function of the Longest Path Length in DAGs with Uniformly Distributed Edge Lengths, Proc. of WALCOM2017, LNCS 10167, pp.421–432, 2017.

[4] Arora, S., Barak, B.: Computational Complexity A Modern Ap- proach, Cambridge University Press, (2009)

38 [5] B´ar´any, I., F¨uredi, Z.: Computing the volume is difficult. Discrete Comput. Geom. 2, 319–326 (1987) [6] Blaauw, D., Chopra, K., Srivastava, A., Scheffer, L.: Statistical Tim- ing Analysis: From Basic Principles to State of the Art. IEEE Trans- actions on Computer-Aided Design of Integrated Circuits and Systems 27, 589–606 (2008) [7] Bodlaender, H.: A Linear-time Algorithm for Finding Tree- decompositions of Small Treewidth. SIAM J. Comput. 25, 1305–1317 (1996) [8] Canon, L.-C., Jeannot, E., Correlation-Aware Heuristics for Evalu- ating the Distribution of the Longest Path Length of a DAG with Random Weights, IEEE Transactions on Parallel and Distributed Sys- tems, Institute of Electrical and Electronics Engineers, 27 (11), 3158– 3171 (2016) [9] Courant, R., John, F., Introduction to Calculus and Analysis, Springer, New York (1989) [10] Cormen, T, Leiserson, C., Rivest, R., Stein, C., Introduction to Algo- rithms, MIT press (2009) [11] Courcelle, B., and Engelfriet, J., Graph Structure and Monadic Second-Order Logic, Cambridge University Press (2012) [12] Cousins, B., Vempala, S.: Bypassing KLS: Gaussian cooling and an O∗(n3) volume algorithm. In: 47th Annual ACM Symposium on the Theory of Computing, 539–548. ACM, New York (2015) [13] Downey, R., Fellows, M.: , Springer (1999) [14] Dyer, M., and Frieze, A.: On the complexity of computing the volume of a polyhedron. SIAM J. Comput. 17, 967–974 (1988) [15] Dyer, M., Frieze, A., Kannan, R.: A random polynomial-time algo- rithm for approximating the volume of convex bodies. J. of the ACM 38, 1–17 (1991). [16] Elekes, G.: A geometric inequality and the complexity of computing volume. Discrete Comput. Geom. 1, 289–292 (1986)

39 [17] Gopalan, P., Klivans, A., and Meka, R.: Polynomial-time approx- imation schemes for knapsack and related counting problems using branching programs. arXiv:1008.3187v1 (2010)

[18] Gopalan, P., Klivans, A., Meka, R., Stefankoviˇc,ˇ D., Vempala, S., Vigoda, E.: An FPTAS for #knapsack and related counting prob- lems. In: 52nd Annual IEEE Symposium on Foundations of Computer Science, 817–826. IEEE Publications, New York (2011)

[19] Graham, R., Knuth, D., Patashnik, O.: Concrete Mathematics Sec- ond Edition, Addison-Wesley (1989)

[20] Hagstrom,. J. Computational complexity of PERT problems, Net- works, Vol. 18, No.2, 139–147 (1988)

[21] Johnson, T., Robertson, N., Seymour, P.D., Thomas, R.: Directed Tree-Width. J. Combin. Theory Ser. B 82. 138–155 (2001)

[22] Kloks, T.: Treewidth, Computations and Approximations, Lecture Notes in Computer Sciences, 842, Springer (1994)

[23] Li, J., Shi, T.: A fully polynomial-time approximation scheme for approximating a sum of random variables. Oper. Res. Lett. 42, 197– 202 (2014)

[24] Lov´asz, L., Vempala, S.: Simulated annealing in convex bodies and an O∗(n4) volume algorithm. J. Comput. Syst. Sci. 72. 392–417 (2006)

[25] Malcolm, D., Roseboom, J., Clark, C., Fazar, W., Application of a Technique for Research and Development Program Evaluation, Oper- ations Research, Vol. 7, No.5, 646–669 (1959)

[26] Martin, J., Distribution of the Time through a Directed, Acyclic Net- work, Operations Research, Vol. 13, No. 1, 46–66 (1965)

[27] Robertson, N., Seymour, P.: Graph Minors. V. Excluding a , Journal of Combinatorial Theory, Series B 41, 92-114 (1986)

[28] Stefankoviˇc,ˇ D., Vempala, S., Vigoda, E.: A deterministic polynomial- time approximation scheme for counting knapsack solutions. SIAM J. Comput. 41, 356–366 (2012)

40