We consider the system Applicative_05__Ex7Sorting. Alphabet: 0 : [] --> a asort : [b] --> b cons : [a * b] --> b dsort : [b] --> b insert : [a -> a -> a * a -> a -> a * b * a] --> b max : [] --> a -> a -> a min : [] --> a -> a -> a nil : [] --> b s : [a] --> a sort : [a -> a -> a * a -> a -> a * b] --> b Rules: sort(f, g, nil) => nil sort(f, g, cons(x, y)) => insert(f, g, sort(f, g, y), x) insert(f, g, nil, x) => cons(x, nil) insert(f, g, cons(x, y), z) => cons(f x z, insert(f, g, y, g x z)) max 0 x => x max x 0 => x max s(x) s(y) => max x y min 0 x => 0 min x 0 => 0 min s(x) s(y) => min x y asort(x) => sort(min, max, x) dsort(x) => sort(max, min, x) This AFS is converted to an AFSM simply by replacing all free variables by meta-variables (with arity 0). We observe that the rules contain a first-order subset: max 0 X => X max X 0 => X max s(X) s(Y) => max X Y min 0 X => 0 min X 0 => 0 min s(X) s(Y) => min X Y Moreover, the system is finitely branching. Thus, by [Kop12, Thm. 7.55], we may omit all first-order dependency pairs from the dependency pair problem (DP(R), R) if this first-order part is Ce-terminating when seen as a many-sorted first-order TRS. According to the external first-order termination prover, this system is indeed Ce-terminating: || proof of resources/system.trs || # AProVE Commit ID: d84c10301d352dfd14de2104819581f4682260f5 fuhs 20130616 || || || Termination w.r.t. Q of the given QTRS could be proven: || || (0) QTRS || (1) QTRSRRRProof [EQUIVALENT] || (2) QTRS || (3) RisEmptyProof [EQUIVALENT] || (4) YES || || || ---------------------------------------- || || (0) || Obligation: || Q restricted rewrite system: || The TRS R consists of the following rules: || || max(0, %X) -> %X || max(%X, 0) -> %X || max(s(%X), s(%Y)) -> max(%X, %Y) || min(0, %X) -> 0 || min(%X, 0) -> 0 || min(s(%X), s(%Y)) -> min(%X, %Y) || ~PAIR(%X, %Y) -> %X || ~PAIR(%X, %Y) -> %Y || || Q is empty. || || ---------------------------------------- || || (1) QTRSRRRProof (EQUIVALENT) || Used ordering: || Polynomial interpretation [POLO]: || || POL(0) = 0 || POL(max(x_1, x_2)) = 2 + 2*x_1 + x_2 || POL(min(x_1, x_2)) = 1 + x_1 + x_2 || POL(s(x_1)) = 1 + 2*x_1 || POL(~PAIR(x_1, x_2)) = 2 + x_1 + x_2 || With this ordering the following rules can be removed by the rule removal processor [LPAR04] because they are oriented strictly: || || max(0, %X) -> %X || max(%X, 0) -> %X || max(s(%X), s(%Y)) -> max(%X, %Y) || min(0, %X) -> 0 || min(%X, 0) -> 0 || min(s(%X), s(%Y)) -> min(%X, %Y) || ~PAIR(%X, %Y) -> %X || ~PAIR(%X, %Y) -> %Y || || || || || ---------------------------------------- || || (2) || Obligation: || Q restricted rewrite system: || R is empty. || Q is empty. || || ---------------------------------------- || || (3) RisEmptyProof (EQUIVALENT) || The TRS R is empty. Hence, termination is trivially proven. || ---------------------------------------- || || (4) || YES || 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] sort#(F, G, cons(X, Y)) =#> insert#(F, G, sort(F, G, Y), X) 1] sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) 2] insert#(F, G, cons(X, Y), Z) =#> F(X, Z) 3] insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G X Z) 4] insert#(F, G, cons(X, Y), Z) =#> G(X, Z) 5] asort#(X) =#> sort#(min, max, X) 6] asort#(X) =#> min# 7] asort#(X) =#> max# 8] dsort#(X) =#> sort#(max, min, X) 9] dsort#(X) =#> max# 10] dsort#(X) =#> min# Rules R_0: sort(F, G, nil) => nil sort(F, G, cons(X, Y)) => insert(F, G, sort(F, G, Y), X) insert(F, G, nil, X) => cons(X, nil) insert(F, G, cons(X, Y), Z) => cons(F X Z, insert(F, G, Y, G X Z)) max 0 X => X max X 0 => X max s(X) s(Y) => max X Y min 0 X => 0 min X 0 => 0 min s(X) s(Y) => min X Y asort(X) => sort(min, max, X) dsort(X) => sort(max, min, X) 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 : 2, 3, 4 * 1 : 0, 1 * 2 : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 * 3 : 2, 3, 4 * 4 : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 * 5 : 0, 1 * 6 : * 7 : * 8 : 0, 1 * 9 : * 10 : This graph has the following strongly connected components: P_1: sort#(F, G, cons(X, Y)) =#> insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) insert#(F, G, cons(X, Y), Z) =#> F(X, Z) insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G X Z) insert#(F, G, cons(X, Y), Z) =#> G(X, Z) asort#(X) =#> sort#(min, max, X) dsort#(X) =#> sort#(max, min, X) 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). 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). The formative rules of (P_1, R_0) are R_1 ::= sort(F, G, nil) => nil sort(F, G, cons(X, Y)) => insert(F, G, sort(F, G, Y), X) insert(F, G, nil, X) => cons(X, nil) insert(F, G, cons(X, Y), Z) => cons(F X Z, insert(F, G, Y, G X Z)) asort(X) => sort(min, max, X) dsort(X) => sort(max, min, X) By [Kop12, Thm. 7.17], we may replace the dependency pair problem (P_1, R_0, minimal, formative) by (P_1, R_1, minimal, formative). Thus, the original system is terminating if (P_1, R_1, minimal, formative) is finite. We consider the dependency pair problem (P_1, 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: sort#(F, G, cons(X, Y)) >? insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) >? sort#(F, G, Y) insert#(F, G, cons(X, Y), Z) >? F(X, Z) insert#(F, G, cons(X, Y), Z) >? insert#(F, G, Y, G X Z) insert#(F, G, cons(X, Y), Z) >? G(X, Z) asort#(X) >? sort#(min, max, X) dsort#(X) >? sort#(max, min, X) sort(F, G, nil) >= nil sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) insert(F, G, nil, X) >= cons(X, nil) insert(F, G, cons(X, Y), Z) >= cons(F X Z, insert(F, G, Y, G X Z)) asort(X) >= sort(min, max, X) dsort(X) >= sort(max, min, X) We apply [Kop12, Thm. 6.75] and use the following argument functions: pi( asort(X) ) = #argfun-asort#(sort(min, max, X)) pi( asort#(X) ) = #argfun-asort##(sort#(min, max, X)) pi( dsort(X) ) = #argfun-dsort#(sort(max, min, X)) pi( dsort#(X) ) = #argfun-dsort##(sort#(max, min, X)) Since this representation is not advantageous for the higher-order recursive path ordering, we present the strict requirements in their unextended form, which is not problematic since for any F, s and substituion gamma: (F s)gamma beta-reduces to F(s)gamma.) We use a recursive path ordering as defined in [Kop12, Chapter 5]. Argument functions: [[#argfun-dsort##(x_1)]] = x_1 [[asort(x_1)]] = x_1 [[asort#(x_1)]] = x_1 [[dsort(x_1)]] = x_1 [[dsort#(x_1)]] = x_1 [[insert(x_1, x_2, x_3, x_4)]] = insert(x_2, x_1, x_3, x_4) [[max]] = _|_ We choose Lex = {insert, insert#} and Mul = {#argfun-asort#, #argfun-asort##, #argfun-dsort#, @_{o -> o -> o}, @_{o -> o}, cons, min, nil, sort, sort#}, and the following precedence: #argfun-asort# > #argfun-asort## > sort# > insert# > #argfun-dsort# > nil = sort > insert > min > cons > @_{o -> o -> o} > @_{o -> o} Taking the argument function into account, and fixing the greater / greater equal choices, the constraints can be denoted as follows: sort#(F, G, cons(X, Y)) > insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) >= sort#(F, G, Y) insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(F, X), Z) insert#(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z)) insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(G, X), Z) #argfun-asort##(sort#(min, _|_, X)) > sort#(min, _|_, X) sort#(_|_, min, X) >= sort#(_|_, min, X) sort(F, G, nil) >= nil sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) insert(F, G, nil, X) >= cons(X, nil) insert(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, X), Z), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z))) #argfun-asort#(sort(min, _|_, X)) >= sort(min, _|_, X) #argfun-dsort#(sort(_|_, min, X)) >= sort(_|_, min, X) With these choices, we have: 1] sort#(F, G, cons(X, Y)) > insert#(F, G, sort(F, G, Y), X) because [2], by definition 2] sort#*(F, G, cons(X, Y)) >= insert#(F, G, sort(F, G, Y), X) because sort# > insert#, [3], [5], [7] and [12], by (Copy) 3] sort#*(F, G, cons(X, Y)) >= F because [4], by (Select) 4] F >= F by (Meta) 5] sort#*(F, G, cons(X, Y)) >= G because [6], by (Select) 6] G >= G by (Meta) 7] sort#*(F, G, cons(X, Y)) >= sort(F, G, Y) because sort# > sort, [3], [5] and [8], by (Copy) 8] sort#*(F, G, cons(X, Y)) >= Y because [9], by (Select) 9] cons(X, Y) >= Y because [10], by (Star) 10] cons*(X, Y) >= Y because [11], by (Select) 11] Y >= Y by (Meta) 12] sort#*(F, G, cons(X, Y)) >= X because [13], by (Select) 13] cons(X, Y) >= X because [14], by (Star) 14] cons*(X, Y) >= X because [15], by (Select) 15] X >= X by (Meta) 16] sort#(F, G, cons(X, Y)) >= sort#(F, G, Y) because [17], by (Star) 17] sort#*(F, G, cons(X, Y)) >= sort#(F, G, Y) because sort# in Mul, [18], [19] and [20], by (Stat) 18] F >= F by (Meta) 19] G >= G by (Meta) 20] cons(X, Y) > Y because [21], by definition 21] cons*(X, Y) >= Y because [11], by (Select) 22] insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(F, X), Z) because [23], by definition 23] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, X), Z) because insert# > @_{o -> o}, [24] and [31], by (Copy) 24] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, X) because insert# > @_{o -> o -> o}, [25] and [27], by (Copy) 25] insert#*(F, G, cons(X, Y), Z) >= F because [26], by (Select) 26] F >= F by (Meta) 27] insert#*(F, G, cons(X, Y), Z) >= X because [28], by (Select) 28] cons(X, Y) >= X because [29], by (Star) 29] cons*(X, Y) >= X because [30], by (Select) 30] X >= X by (Meta) 31] insert#*(F, G, cons(X, Y), Z) >= Z because [32], by (Select) 32] Z >= Z by (Meta) 33] insert#(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z)) because [34], by (Star) 34] insert#*(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z)) because [35], [36], [37], [25], [40], [41] and [43], by (Stat) 35] F >= F by (Meta) 36] G >= G by (Meta) 37] cons(X, Y) > Y because [38], by definition 38] cons*(X, Y) >= Y because [39], by (Select) 39] Y >= Y by (Meta) 40] insert#*(F, G, cons(X, Y), Z) >= G because [36], by (Select) 41] insert#*(F, G, cons(X, Y), Z) >= Y because [42], by (Select) 42] cons(X, Y) >= Y because [38], by (Star) 43] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, X), Z) because insert# > @_{o -> o}, [44] and [31], by (Copy) 44] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, X) because insert# > @_{o -> o -> o}, [40] and [27], by (Copy) 45] insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(G, X), Z) because [46], by definition 46] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, X), Z) because insert# > @_{o -> o}, [44] and [31], by (Copy) 47] #argfun-asort##(sort#(min, _|_, X)) > sort#(min, _|_, X) because [48], by definition 48] #argfun-asort##*(sort#(min, _|_, X)) >= sort#(min, _|_, X) because #argfun-asort## > sort#, [49], [50] and [51], by (Copy) 49] #argfun-asort##*(sort#(min, _|_, X)) >= min because #argfun-asort## > min, by (Copy) 50] #argfun-asort##*(sort#(min, _|_, X)) >= _|_ by (Bot) 51] #argfun-asort##*(sort#(min, _|_, X)) >= X because [52], by (Select) 52] sort#(min, _|_, X) >= X because [53], by (Star) 53] sort#*(min, _|_, X) >= X because [54], by (Select) 54] X >= X by (Meta) 55] sort#(_|_, min, X) >= sort#(_|_, min, X) because sort# in Mul, [56], [57] and [58], by (Fun) 56] _|_ >= _|_ by (Bot) 57] min >= min by (Fun) 58] X >= X by (Meta) 59] sort(F, G, nil) >= nil because [60], by (Star) 60] sort*(F, G, nil) >= nil because sort = nil and sort in Mul, by (Stat) 61] sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because [62], by (Star) 62] sort*(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because sort > insert, [63], [64], [65] and [66], by (Copy) 63] sort*(F, G, cons(X, Y)) >= F because [18], by (Select) 64] sort*(F, G, cons(X, Y)) >= G because [19], by (Select) 65] sort*(F, G, cons(X, Y)) >= sort(F, G, Y) because sort in Mul, [18], [19] and [20], by (Stat) 66] sort*(F, G, cons(X, Y)) >= X because [13], by (Select) 67] insert(F, G, nil, X) >= cons(X, nil) because [68], by (Star) 68] insert*(F, G, nil, X) >= cons(X, nil) because insert > cons, [69] and [71], by (Copy) 69] insert*(F, G, nil, X) >= X because [70], by (Select) 70] X >= X by (Meta) 71] insert*(F, G, nil, X) >= nil because [72], by (Select) 72] nil >= nil by (Fun) 73] insert(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, X), Z), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z))) because [74], by (Star) 74] insert*(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, X), Z), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z))) because insert > cons, [75] and [80], by (Copy) 75] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, X), Z) because insert > @_{o -> o}, [76] and [79], by (Copy) 76] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, X) because insert > @_{o -> o -> o}, [77] and [78], by (Copy) 77] insert*(F, G, cons(X, Y), Z) >= F because [35], by (Select) 78] insert*(F, G, cons(X, Y), Z) >= X because [28], by (Select) 79] insert*(F, G, cons(X, Y), Z) >= Z because [32], by (Select) 80] insert*(F, G, cons(X, Y), Z) >= insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z)) because [35], [36], [37], [77], [81], [82] and [83], by (Stat) 81] insert*(F, G, cons(X, Y), Z) >= G because [36], by (Select) 82] insert*(F, G, cons(X, Y), Z) >= Y because [42], by (Select) 83] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, X), Z) because insert > @_{o -> o}, [84] and [79], by (Copy) 84] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, X) because insert > @_{o -> o -> o}, [81] and [78], by (Copy) 85] #argfun-asort#(sort(min, _|_, X)) >= sort(min, _|_, X) because [86], by (Star) 86] #argfun-asort#*(sort(min, _|_, X)) >= sort(min, _|_, X) because #argfun-asort# > sort, [87], [88] and [89], by (Copy) 87] #argfun-asort#*(sort(min, _|_, X)) >= min because #argfun-asort# > min, by (Copy) 88] #argfun-asort#*(sort(min, _|_, X)) >= _|_ by (Bot) 89] #argfun-asort#*(sort(min, _|_, X)) >= X because [90], by (Select) 90] sort(min, _|_, X) >= X because [91], by (Star) 91] sort*(min, _|_, X) >= X because [54], by (Select) 92] #argfun-dsort#(sort(_|_, min, X)) >= sort(_|_, min, X) because [93], by (Star) 93] #argfun-dsort#*(sort(_|_, min, X)) >= sort(_|_, min, X) because #argfun-dsort# > sort, [94], [95] and [96], by (Copy) 94] #argfun-dsort#*(sort(_|_, min, X)) >= _|_ by (Bot) 95] #argfun-dsort#*(sort(_|_, min, X)) >= min because #argfun-dsort# > min, by (Copy) 96] #argfun-dsort#*(sort(_|_, min, X)) >= X because [97], by (Select) 97] sort(_|_, min, X) >= X because [98], by (Star) 98] sort*(_|_, min, X) >= X because [58], by (Select) By the observations in [Kop12, Sec. 6.6], this reduction pair suffices; we may thus replace the dependency pair problem (P_1, R_1, minimal, formative) by (P_2, R_1, minimal, formative), where P_2 consists of: sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G X Z) dsort#(X) =#> sort#(max, min, X) Thus, the original system is terminating if (P_2, R_1, minimal, formative) is finite. We consider the dependency pair problem (P_2, R_1, 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 : 0 This graph has the following strongly connected components: P_3: sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) P_4: insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G X Z) By [Kop12, Thm. 7.31], we may replace any dependency pair problem (P_2, R_1, m, f) by (P_3, R_1, m, f) and (P_4, R_1, m, f). Thus, the original system is terminating if each of (P_3, R_1, minimal, formative) and (P_4, R_1, minimal, formative) is finite. We consider the dependency pair problem (P_4, R_1, minimal, formative). We apply the subterm criterion with the following projection function: nu(insert#) = 3 Thus, we can orient the dependency pairs as follows: nu(insert#(F, G, cons(X, Y), Z)) = cons(X, Y) |> Y = nu(insert#(F, G, Y, G X Z)) By [Kop12, Thm. 7.35], we may replace a dependency pair problem (P_4, 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 (P_3, R_1, minimal, formative) is finite. We consider the dependency pair problem (P_3, R_1, minimal, formative). We apply the subterm criterion with the following projection function: nu(sort#) = 3 Thus, we can orient the dependency pairs as follows: nu(sort#(F, G, cons(X, Y))) = cons(X, Y) |> Y = nu(sort#(F, G, Y)) By [Kop12, Thm. 7.35], we may replace a dependency pair problem (P_3, R_1, minimal, f) by ({}, R_1, 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.