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 [[#argfun-dsort##(x_1)]] = x_1 [[asort(x_1)]] = x_1 [[asort#(x_1)]] = x_1 [[dsort(x_1)]] = x_1 [[insert(x_1, x_2, x_3, x_4)]] = insert(x_3, x_2, x_1, x_4) [[insert#(x_1, x_2, x_3, x_4)]] = insert#(x_3, x_1, x_2, x_4) [[nil]] = _|_ We choose Lex = {insert, insert#} and Mul = {#argfun-asort#, #argfun-asort##, @_{o -> o -> o}, @_{o -> o}, cons, dsort#, max, min, sort, sort#}, and the following precedence: #argfun-asort# > #argfun-asort## > dsort# > min > max > sort = sort# > insert# > insert > @_{o -> o -> o} > cons > @_{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, max, X)) > sort#(min, max, X) sort#(max, min, X) >= sort#(max, min, X) sort(F, G, _|_) >= _|_ sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) insert(F, G, _|_, X) >= cons(X, _|_) 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, max, X)) >= sort(min, max, X) sort(max, min, X) >= sort(max, 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 (Star) 2] sort#*(F, G, cons(X, Y)) >= insert#(F, G, sort(F, G, Y), X) because sort# > insert#, [3], [5], [7] and [13], 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, sort# in Mul, [8], [9] and [10], by (Stat) 8] F >= F by (Meta) 9] G >= G by (Meta) 10] cons(X, Y) > Y because [11], by definition 11] cons*(X, Y) >= Y because [12], by (Select) 12] Y >= Y by (Meta) 13] sort#*(F, G, cons(X, Y)) >= X because [14], by (Select) 14] cons(X, Y) >= X because [15], by (Star) 15] cons*(X, Y) >= X because [16], by (Select) 16] X >= X by (Meta) 17] sort#(F, G, cons(X, Y)) >= sort#(F, G, Y) because [18], by (Star) 18] sort#*(F, G, cons(X, Y)) >= sort#(F, G, Y) because sort# in Mul, [8], [9] and [10], by (Stat) 19] insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(F, X), Z) because [20], by definition 20] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, X), Z) because insert# > @_{o -> o}, [21] and [28], by (Copy) 21] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, X) because insert# > @_{o -> o -> o}, [22] and [24], by (Copy) 22] insert#*(F, G, cons(X, Y), Z) >= F because [23], by (Select) 23] F >= F by (Meta) 24] insert#*(F, G, cons(X, Y), Z) >= X because [25], by (Select) 25] cons(X, Y) >= X because [26], by (Star) 26] cons*(X, Y) >= X because [27], by (Select) 27] X >= X by (Meta) 28] insert#*(F, G, cons(X, Y), Z) >= Z because [29], by (Select) 29] Z >= Z by (Meta) 30] insert#(F, G, cons(X, Y), Z) > insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z)) because [31], by definition 31] insert#*(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z)) because [32], [22], [35], [37] and [39], by (Stat) 32] cons(X, Y) > Y because [33], by definition 33] cons*(X, Y) >= Y because [34], by (Select) 34] Y >= Y by (Meta) 35] insert#*(F, G, cons(X, Y), Z) >= G because [36], by (Select) 36] G >= G by (Meta) 37] insert#*(F, G, cons(X, Y), Z) >= Y because [38], by (Select) 38] cons(X, Y) >= Y because [33], by (Star) 39] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, X), Z) because insert# > @_{o -> o}, [40] and [28], by (Copy) 40] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, X) because insert# > @_{o -> o -> o}, [35] and [24], by (Copy) 41] insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(G, X), Z) because [42], by definition 42] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, X), Z) because insert# > @_{o -> o}, [40] and [28], by (Copy) 43] #argfun-asort##(sort#(min, max, X)) > sort#(min, max, X) because [44], by definition 44] #argfun-asort##*(sort#(min, max, X)) >= sort#(min, max, X) because #argfun-asort## > sort#, [45], [46] and [47], by (Copy) 45] #argfun-asort##*(sort#(min, max, X)) >= min because #argfun-asort## > min, by (Copy) 46] #argfun-asort##*(sort#(min, max, X)) >= max because #argfun-asort## > max, by (Copy) 47] #argfun-asort##*(sort#(min, max, X)) >= X because [48], by (Select) 48] sort#(min, max, X) >= X because [49], by (Star) 49] sort#*(min, max, X) >= X because [50], by (Select) 50] X >= X by (Meta) 51] sort#(max, min, X) >= sort#(max, min, X) because sort# in Mul, [52], [53] and [54], by (Fun) 52] max >= max by (Fun) 53] min >= min by (Fun) 54] X >= X by (Meta) 55] sort(F, G, _|_) >= _|_ by (Bot) 56] sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because [57], by (Star) 57] sort*(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because sort > insert, [58], [59], [60] and [61], by (Copy) 58] sort*(F, G, cons(X, Y)) >= F because [8], by (Select) 59] sort*(F, G, cons(X, Y)) >= G because [9], by (Select) 60] sort*(F, G, cons(X, Y)) >= sort(F, G, Y) because sort in Mul, [8], [9] and [10], by (Stat) 61] sort*(F, G, cons(X, Y)) >= X because [14], by (Select) 62] insert(F, G, _|_, X) >= cons(X, _|_) because [63], by (Star) 63] insert*(F, G, _|_, X) >= cons(X, _|_) because insert > cons, [64] and [66], by (Copy) 64] insert*(F, G, _|_, X) >= X because [65], by (Select) 65] X >= X by (Meta) 66] insert*(F, G, _|_, X) >= _|_ by (Bot) 67] 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 [68], by (Star) 68] 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, [69] and [74], by (Copy) 69] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, X), Z) because insert > @_{o -> o}, [70] and [73], by (Copy) 70] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, X) because insert > @_{o -> o -> o}, [71] and [72], by (Copy) 71] insert*(F, G, cons(X, Y), Z) >= F because [23], by (Select) 72] insert*(F, G, cons(X, Y), Z) >= X because [25], by (Select) 73] insert*(F, G, cons(X, Y), Z) >= Z because [29], by (Select) 74] insert*(F, G, cons(X, Y), Z) >= insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, X), Z)) because [32], [71], [75], [76] and [77], by (Stat) 75] insert*(F, G, cons(X, Y), Z) >= G because [36], by (Select) 76] insert*(F, G, cons(X, Y), Z) >= Y because [38], by (Select) 77] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, X), Z) because insert > @_{o -> o}, [78] and [73], by (Copy) 78] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, X) because insert > @_{o -> o -> o}, [75] and [72], by (Copy) 79] #argfun-asort#(sort(min, max, X)) >= sort(min, max, X) because [80], by (Star) 80] #argfun-asort#*(sort(min, max, X)) >= sort(min, max, X) because #argfun-asort# > sort, [81], [82] and [83], by (Copy) 81] #argfun-asort#*(sort(min, max, X)) >= min because #argfun-asort# > min, by (Copy) 82] #argfun-asort#*(sort(min, max, X)) >= max because #argfun-asort# > max, by (Copy) 83] #argfun-asort#*(sort(min, max, X)) >= X because [84], by (Select) 84] sort(min, max, X) >= X because [85], by (Star) 85] sort*(min, max, X) >= X because [50], by (Select) 86] sort(max, min, X) >= sort(max, min, X) because sort in Mul, [52], [53] and [54], by (Fun) 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)) =#> insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) 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 : * 1 : 0, 1 * 2 : 0, 1 This graph has the following strongly connected components: P_3: sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) 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). 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 [FuhKop19, Thm. 61], 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 +++ [FuhKop19] C. Fuhs, and C. Kop. A static higher-order dependency pair framework. In Proceedings of ESOP 2019, 2019. [Kop12] C. Kop. Higher Order Termination. PhD Thesis, 2012.