We consider the system zipWith. Alphabet: 0 : [] --> nat cons : [nat * list] --> list false : [] --> bool gcd : [nat * nat] --> nat gcdlists : [list * list] --> list if : [bool * nat * nat] --> nat le : [nat * nat] --> bool minus : [nat * nat] --> nat nil : [] --> list s : [nat] --> nat true : [] --> bool zipWith : [nat -> nat -> nat * list * list] --> list Rules: le(0, x) => true le(s(x), 0) => false le(s(x), s(y)) => le(x, y) minus(x, 0) => x minus(s(x), s(y)) => minus(x, y) gcd(0, x) => 0 gcd(s(x), 0) => 0 gcd(s(x), s(y)) => if(le(y, x), s(x), s(y)) if(true, s(x), s(y)) => gcd(minus(x, y), s(y)) if(false, s(x), s(y)) => gcd(minus(y, x), s(x)) zipWith(f, x, nil) => nil zipWith(f, nil, x) => nil zipWith(f, cons(x, y), cons(z, u)) => cons(f x z, zipWith(f, y, u)) gcdlists(x, y) => zipWith(/\z./\u.gcd(z, u), x, y) This AFS is converted to an AFSM simply by replacing all free variables by meta-variables (with arity 0). We use the dependency pair framework as described in [Kop12, Ch. 6/7], with dynamic dependency pairs. After applying [Kop12, Thm. 7.22] to denote collapsing dependency pairs in an extended form, we thus obtain the following dependency pair problem (P_0, R_0, minimal, formative): Dependency Pairs P_0: 0] le#(s(X), s(Y)) =#> le#(X, Y) 1] minus#(s(X), s(Y)) =#> minus#(X, Y) 2] gcd#(s(X), s(Y)) =#> if#(le(Y, X), s(X), s(Y)) 3] gcd#(s(X), s(Y)) =#> le#(Y, X) 4] if#(true, s(X), s(Y)) =#> gcd#(minus(X, Y), s(Y)) 5] if#(true, s(X), s(Y)) =#> minus#(X, Y) 6] if#(false, s(X), s(Y)) =#> gcd#(minus(Y, X), s(X)) 7] if#(false, s(X), s(Y)) =#> minus#(Y, X) 8] zipWith#(F, cons(X, Y), cons(Z, U)) =#> F(X, Z) 9] zipWith#(F, cons(X, Y), cons(Z, U)) =#> zipWith#(F, Y, U) 10] gcdlists#(X, Y) =#> zipWith#(/\x./\y.gcd(x, y), X, Y) 11] gcdlists#(X, Y) =#> gcd#(x, y) Rules R_0: le(0, X) => true le(s(X), 0) => false le(s(X), s(Y)) => le(X, Y) minus(X, 0) => X minus(s(X), s(Y)) => minus(X, Y) gcd(0, X) => 0 gcd(s(X), 0) => 0 gcd(s(X), s(Y)) => if(le(Y, X), s(X), s(Y)) if(true, s(X), s(Y)) => gcd(minus(X, Y), s(Y)) if(false, s(X), s(Y)) => gcd(minus(Y, X), s(X)) zipWith(F, X, nil) => nil zipWith(F, nil, X) => nil zipWith(F, cons(X, Y), cons(Z, U)) => cons(F X Z, zipWith(F, Y, U)) gcdlists(X, Y) => zipWith(/\x./\y.gcd(x, y), X, Y) Thus, the original system is terminating if (P_0, R_0, minimal, formative) is finite. We consider the dependency pair problem (P_0, R_0, minimal, formative). We place the elements of P in a dependency graph approximation G (see e.g. [Kop12, Thm. 7.27, 7.29], as follows: * 0 : 0 * 1 : 1 * 2 : 4, 5, 6, 7 * 3 : 0 * 4 : 2, 3 * 5 : 1 * 6 : 2, 3 * 7 : 1 * 8 : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 * 9 : 8, 9 * 10 : 8, 9 * 11 : This graph has the following strongly connected components: P_1: le#(s(X), s(Y)) =#> le#(X, Y) P_2: minus#(s(X), s(Y)) =#> minus#(X, Y) P_3: gcd#(s(X), s(Y)) =#> if#(le(Y, X), s(X), s(Y)) if#(true, s(X), s(Y)) =#> gcd#(minus(X, Y), s(Y)) if#(false, s(X), s(Y)) =#> gcd#(minus(Y, X), s(X)) P_4: zipWith#(F, cons(X, Y), cons(Z, U)) =#> F(X, Z) zipWith#(F, cons(X, Y), cons(Z, U)) =#> zipWith#(F, Y, U) gcdlists#(X, Y) =#> zipWith#(/\x./\y.gcd(x, y), X, Y) By [Kop12, Thm. 7.31], we may replace any dependency pair problem (P_0, R_0, m, f) by (P_1, R_0, m, f), (P_2, R_0, m, f), (P_3, R_0, m, f) and (P_4, R_0, m, f). Thus, the original system is terminating if each of (P_1, R_0, minimal, formative), (P_2, R_0, minimal, formative), (P_3, R_0, minimal, formative) and (P_4, R_0, minimal, formative) is finite. We consider the dependency pair problem (P_4, R_0, minimal, formative). The formative rules of (P_4, R_0) are R_1 ::= zipWith(F, cons(X, Y), cons(Z, U)) => cons(F X Z, zipWith(F, Y, U)) gcdlists(X, Y) => zipWith(/\x./\y.gcd(x, y), X, Y) By [Kop12, Thm. 7.17], we may replace the dependency pair problem (P_4, R_0, minimal, formative) by (P_4, R_1, minimal, formative). Thus, the original system is terminating if each of (P_1, R_0, minimal, formative), (P_2, R_0, minimal, formative), (P_3, R_0, minimal, formative) and (P_4, R_1, minimal, formative) is finite. We consider the dependency pair problem (P_4, R_1, minimal, formative). We will use the reduction pair processor [Kop12, Thm. 7.16]. As the system is abstraction-simple and the formative flag is set, it suffices to find a tagged reduction pair [Kop12, Def. 6.70]. Thus, we must orient: zipWith#(F, cons(X, Y), cons(Z, U)) >? F(X, Z) zipWith#(F, cons(X, Y), cons(Z, U)) >? zipWith#(F, Y, U) gcdlists#(X, Y) >? zipWith#(/\x./\y.gcd-(x, y), X, Y) zipWith(F, cons(X, Y), cons(Z, U)) >= cons(F X Z, zipWith(F, Y, U)) gcdlists(X, Y) >= zipWith(/\x./\y.gcd-(x, y), X, Y) gcd-(X, Y) >= gcd(X, Y) We apply [Kop12, Thm. 6.75] and use the following argument functions: pi( gcdlists(X, Y) ) = #argfun-gcdlists#(zipWith(/\x./\y.gcd-(x, y), X, Y)) pi( gcdlists#(X, Y) ) = #argfun-gcdlists##(zipWith#(/\x./\y.gcd-(x, y), X, Y)) We orient these requirements with a polynomial interpretation in the natural numbers. The following interpretation satisfies the requirements: #argfun-gcdlists# = \y0.3 + y0 #argfun-gcdlists## = \y0.3 + y0 cons = \y0y1.1 + y0 + y1 gcd = \y0y1.0 gcd- = \y0y1.3 + 3y0 + 3y1 gcdlists = \y0y1.0 gcdlists# = \y0y1.0 zipWith = \G0y1y2.y1 + 2y2 + 2y1y2G0(y1,y2) + 2G0(y1,y2) zipWith# = \G0y1y2.3 + G0(y1,y2) Using this interpretation, the requirements translate to: [[zipWith#(_F0, cons(_x1, _x2), cons(_x3, _x4))]] = 3 + F0(1 + x1 + x2,1 + x3 + x4) > F0(x1,x3) = [[_F0(_x1, _x3)]] [[zipWith#(_F0, cons(_x1, _x2), cons(_x3, _x4))]] = 3 + F0(1 + x1 + x2,1 + x3 + x4) >= 3 + F0(x2,x4) = [[zipWith#(_F0, _x2, _x4)]] [[#argfun-gcdlists##(zipWith#(/\x./\y.gcd-(x, y), _x0, _x1))]] = 9 + 3x0 + 3x1 > 6 + 3x0 + 3x1 = [[zipWith#(/\x./\y.gcd-(x, y), _x0, _x1)]] [[zipWith(_F0, cons(_x1, _x2), cons(_x3, _x4))]] = 3 + x1 + x2 + 2x3 + 2x4 + 2x1x3F0(1 + x1 + x2,1 + x3 + x4) + 2x1x4F0(1 + x1 + x2,1 + x3 + x4) + 2x1F0(1 + x1 + x2,1 + x3 + x4) + 2x2x3F0(1 + x1 + x2,1 + x3 + x4) + 2x2x4F0(1 + x1 + x2,1 + x3 + x4) + 2x2F0(1 + x1 + x2,1 + x3 + x4) + 2x3F0(1 + x1 + x2,1 + x3 + x4) + 2x4F0(1 + x1 + x2,1 + x3 + x4) + 4F0(1 + x1 + x2,1 + x3 + x4) >= 1 + x2 + 2x4 + 2x2x4F0(x2,x4) + 2F0(x2,x4) + max(x1, x3, F0(x1,x3)) = [[cons(_F0 _x1 _x3, zipWith(_F0, _x2, _x4))]] [[#argfun-gcdlists#(zipWith(/\x./\y.gcd-(x, y), _x0, _x1))]] = 9 + 6x0x0x1 + 6x0x1 + 6x0x1x1 + 7x0 + 8x1 >= 6 + 6x0x0x1 + 6x0x1 + 6x0x1x1 + 7x0 + 8x1 = [[zipWith(/\x./\y.gcd-(x, y), _x0, _x1)]] [[gcd-(_x0, _x1)]] = 3 + 3x0 + 3x1 >= 0 = [[gcd(_x0, _x1)]] By the observations in [Kop12, Sec. 6.6], this reduction pair suffices; we may thus replace the dependency pair problem (P_4, R_1, minimal, formative) by (P_5, R_1, minimal, formative), where P_5 consists of: zipWith#(F, cons(X, Y), cons(Z, U)) =#> zipWith#(F, Y, U) Thus, the original system is terminating if each of (P_1, R_0, minimal, formative), (P_2, R_0, minimal, formative), (P_3, R_0, minimal, formative) and (P_5, R_1, minimal, formative) is finite. We consider the dependency pair problem (P_5, R_1, minimal, formative). We apply the subterm criterion with the following projection function: nu(zipWith#) = 2 Thus, we can orient the dependency pairs as follows: nu(zipWith#(F, cons(X, Y), cons(Z, U))) = cons(X, Y) |> Y = nu(zipWith#(F, Y, U)) By [Kop12, Thm. 7.35], we may replace a dependency pair problem (P_5, R_1, minimal, f) by ({}, R_1, minimal, f). By the empty set processor [Kop12, Thm. 7.15] this problem may be immediately removed. Thus, the original system is terminating if each of (P_1, R_0, minimal, formative), (P_2, R_0, minimal, formative) and (P_3, R_0, minimal, formative) is finite. We consider the dependency pair problem (P_3, R_0, minimal, formative). The formative rules of (P_3, R_0) are R_2 ::= le(0, X) => true le(s(X), 0) => false le(s(X), s(Y)) => le(X, Y) minus(X, 0) => X minus(s(X), s(Y)) => minus(X, Y) gcd(0, X) => 0 gcd(s(X), 0) => 0 gcd(s(X), s(Y)) => if(le(Y, X), s(X), s(Y)) if(true, s(X), s(Y)) => gcd(minus(X, Y), s(Y)) if(false, s(X), s(Y)) => gcd(minus(Y, X), s(X)) By [Kop12, Thm. 7.17], we may replace the dependency pair problem (P_3, R_0, minimal, formative) by (P_3, R_2, minimal, formative). Thus, the original system is terminating if each of (P_1, R_0, minimal, formative), (P_2, R_0, minimal, formative) and (P_3, R_2, minimal, formative) is finite. We consider the dependency pair problem (P_3, R_2, minimal, formative). We will use the reduction pair processor with usable rules [Kop12, Thm. 7.44]. The usable rules of (P_3, R_2) are: le(0, X) => true le(s(X), 0) => false le(s(X), s(Y)) => le(X, Y) minus(X, 0) => X minus(s(X), s(Y)) => minus(X, Y) It suffices to find a standard reduction pair [Kop12, Def. 6.69]. Thus, we must orient: gcd#(s(X), s(Y)) >? if#(le(Y, X), s(X), s(Y)) if#(true, s(X), s(Y)) >? gcd#(minus(X, Y), s(Y)) if#(false, s(X), s(Y)) >? gcd#(minus(Y, X), s(X)) le(0, X) >= true le(s(X), 0) >= false le(s(X), s(Y)) >= le(X, Y) minus(X, 0) >= X minus(s(X), s(Y)) >= minus(X, Y) We orient these requirements with a polynomial interpretation in the natural numbers. The following interpretation satisfies the requirements: 0 = 3 false = 0 gcd# = \y0y1.3 + 2y1 + 3y0 if# = \y0y1y2.3 + 2y2 + 3y1 le = \y0y1.2y1 minus = \y0y1.y0 s = \y0.3 + 3y0 true = 0 Using this interpretation, the requirements translate to: [[gcd#(s(_x0), s(_x1))]] = 18 + 6x1 + 9x0 >= 18 + 6x1 + 9x0 = [[if#(le(_x1, _x0), s(_x0), s(_x1))]] [[if#(true, s(_x0), s(_x1))]] = 18 + 6x1 + 9x0 > 9 + 3x0 + 6x1 = [[gcd#(minus(_x0, _x1), s(_x1))]] [[if#(false, s(_x0), s(_x1))]] = 18 + 6x1 + 9x0 > 9 + 3x1 + 6x0 = [[gcd#(minus(_x1, _x0), s(_x0))]] [[le(0, _x0)]] = 2x0 >= 0 = [[true]] [[le(s(_x0), 0)]] = 6 >= 0 = [[false]] [[le(s(_x0), s(_x1))]] = 6 + 6x1 >= 2x1 = [[le(_x0, _x1)]] [[minus(_x0, 0)]] = x0 >= x0 = [[_x0]] [[minus(s(_x0), s(_x1))]] = 3 + 3x0 >= x0 = [[minus(_x0, _x1)]] By the observations in [Kop12, Sec. 6.6], this reduction pair suffices; we may thus replace the dependency pair problem (P_3, R_2, minimal, formative) by (P_6, R_2, minimal, formative), where P_6 consists of: gcd#(s(X), s(Y)) =#> if#(le(Y, X), s(X), s(Y)) Thus, the original system is terminating if each of (P_1, R_0, minimal, formative), (P_2, R_0, minimal, formative) and (P_6, R_2, minimal, formative) is finite. We consider the dependency pair problem (P_6, R_2, minimal, formative). We place the elements of P in a dependency graph approximation G (see e.g. [Kop12, Thm. 7.27, 7.29], as follows: * 0 : This graph has no strongly connected components. By [Kop12, Thm. 7.31], this implies finiteness of the dependency pair problem. Thus, the original system is terminating if each of (P_1, R_0, minimal, formative) and (P_2, R_0, minimal, formative) is finite. We consider the dependency pair problem (P_2, R_0, minimal, formative). We apply the subterm criterion with the following projection function: nu(minus#) = 1 Thus, we can orient the dependency pairs as follows: nu(minus#(s(X), s(Y))) = s(X) |> X = nu(minus#(X, Y)) By [Kop12, Thm. 7.35], we may replace a dependency pair problem (P_2, R_0, minimal, f) by ({}, R_0, minimal, f). By the empty set processor [Kop12, Thm. 7.15] this problem may be immediately removed. Thus, the original system is terminating if (P_1, R_0, minimal, formative) is finite. We consider the dependency pair problem (P_1, R_0, minimal, formative). We apply the subterm criterion with the following projection function: nu(le#) = 1 Thus, we can orient the dependency pairs as follows: nu(le#(s(X), s(Y))) = s(X) |> X = nu(le#(X, Y)) By [Kop12, Thm. 7.35], we may replace a dependency pair problem (P_1, R_0, minimal, f) by ({}, R_0, minimal, f). By the empty set processor [Kop12, Thm. 7.15] this problem may be immediately removed. As all dependency pair problems were succesfully simplified with sound (and complete) processors until nothing remained, we conclude termination. +++ Citations +++ [Kop12] C. Kop. Higher Order Termination. PhD Thesis, 2012.