We consider the system Applicative_05__Ex5Sorting. Alphabet: 0 : [] --> a ascending!fac6220sort : [b] --> b cons : [a * b] --> b descending!fac6220sort : [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: 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 insert(f, g, nil, x) => cons(x, nil) insert(f, g, cons(x, y), z) => cons(f z x, insert(f, g, y, g z x)) sort(f, g, nil) => nil sort(f, g, cons(x, y)) => insert(f, g, sort(f, g, y), x) ascending!fac6220sort(x) => sort(min, max, x) descending!fac6220sort(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] insert#(F, G, cons(X, Y), Z) =#> F(Z, X) 1] insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G Z X) 2] insert#(F, G, cons(X, Y), Z) =#> G(Z, X) 3] sort#(F, G, cons(X, Y)) =#> insert#(F, G, sort(F, G, Y), X) 4] sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) 5] ascending!fac6220sort#(X) =#> sort#(min, max, X) 6] ascending!fac6220sort#(X) =#> min# 7] ascending!fac6220sort#(X) =#> max# 8] descending!fac6220sort#(X) =#> sort#(max, min, X) 9] descending!fac6220sort#(X) =#> max# 10] descending!fac6220sort#(X) =#> min# Rules R_0: 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 insert(F, G, nil, X) => cons(X, nil) insert(F, G, cons(X, Y), Z) => cons(F Z X, insert(F, G, Y, G Z X)) sort(F, G, nil) => nil sort(F, G, cons(X, Y)) => insert(F, G, sort(F, G, Y), X) ascending!fac6220sort(X) => sort(min, max, X) descending!fac6220sort(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 : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 * 1 : 0, 1, 2 * 2 : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 * 3 : 0, 1, 2 * 4 : 3, 4 * 5 : 3, 4 * 6 : * 7 : * 8 : 3, 4 * 9 : * 10 : This graph has the following strongly connected components: P_1: insert#(F, G, cons(X, Y), Z) =#> F(Z, X) insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G Z X) insert#(F, G, cons(X, Y), Z) =#> G(Z, X) sort#(F, G, cons(X, Y)) =#> insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) ascending!fac6220sort#(X) =#> sort#(min, max, X) descending!fac6220sort#(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 ::= insert(F, G, nil, X) => cons(X, nil) insert(F, G, cons(X, Y), Z) => cons(F Z X, insert(F, G, Y, G Z X)) sort(F, G, nil) => nil sort(F, G, cons(X, Y)) => insert(F, G, sort(F, G, Y), X) ascending!fac6220sort(X) => sort(min, max, X) descending!fac6220sort(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: insert#(F, G, cons(X, Y), Z) >? F(Z, X) insert#(F, G, cons(X, Y), Z) >? insert#(F, G, Y, G Z X) insert#(F, G, cons(X, Y), Z) >? G(Z, X) sort#(F, G, cons(X, Y)) >? insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) >? sort#(F, G, Y) ascending!fac6220sort#(X) >? sort#(min, max, X) descending!fac6220sort#(X) >? sort#(max, min, X) insert(F, G, nil, X) >= cons(X, nil) insert(F, G, cons(X, Y), Z) >= cons(F Z X, insert(F, G, Y, G Z X)) sort(F, G, nil) >= nil sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) ascending!fac6220sort(X) >= sort(min, max, X) descending!fac6220sort(X) >= sort(max, min, X) We apply [Kop12, Thm. 6.75] and use the following argument functions: pi( ascending!fac6220sort(X) ) = #argfun-ascending!fac6220sort#(sort(min, max, X)) pi( ascending!fac6220sort#(X) ) = #argfun-ascending!fac6220sort##(sort#(min, max, X)) pi( descending!fac6220sort(X) ) = #argfun-descending!fac6220sort#(sort(max, min, X)) pi( descending!fac6220sort#(X) ) = #argfun-descending!fac6220sort##(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: [[ascending!fac6220sort(x_1)]] = x_1 [[ascending!fac6220sort#(x_1)]] = x_1 [[descending!fac6220sort(x_1)]] = x_1 [[descending!fac6220sort#(x_1)]] = x_1 [[insert(x_1, x_2, x_3, x_4)]] = insert(x_3, x_1, x_2, x_4) [[insert#(x_1, x_2, x_3, x_4)]] = insert#(x_1, x_3, x_2, x_4) [[max]] = _|_ [[min]] = _|_ [[nil]] = _|_ We choose Lex = {insert, insert#} and Mul = {#argfun-ascending!fac6220sort#, #argfun-ascending!fac6220sort##, #argfun-descending!fac6220sort#, #argfun-descending!fac6220sort##, @_{o -> o -> o}, @_{o -> o}, cons, sort, sort#}, and the following precedence: #argfun-ascending!fac6220sort# > #argfun-ascending!fac6220sort## > #argfun-descending!fac6220sort# > #argfun-descending!fac6220sort## > sort = sort# > insert > cons > insert# > @_{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: insert#(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, Z), X) insert#(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(G, Z), X) sort#(F, G, cons(X, Y)) >= insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) >= sort#(F, G, Y) #argfun-ascending!fac6220sort##(sort#(_|_, _|_, X)) >= sort#(_|_, _|_, X) #argfun-descending!fac6220sort##(sort#(_|_, _|_, X)) >= sort#(_|_, _|_, X) insert(F, G, _|_, X) >= cons(X, _|_) insert(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, Z), X), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X))) sort(F, G, _|_) >= _|_ sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) #argfun-ascending!fac6220sort#(sort(_|_, _|_, X)) >= sort(_|_, _|_, X) #argfun-descending!fac6220sort#(sort(_|_, _|_, X)) >= sort(_|_, _|_, X) With these choices, we have: 1] insert#(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, Z), X) because [2], by (Star) 2] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, Z), X) because insert# > @_{o -> o}, [3] and [8], by (Copy) 3] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, Z) because insert# > @_{o -> o -> o}, [4] and [6], by (Copy) 4] insert#*(F, G, cons(X, Y), Z) >= F because [5], by (Select) 5] F >= F by (Meta) 6] insert#*(F, G, cons(X, Y), Z) >= Z because [7], by (Select) 7] Z >= Z by (Meta) 8] insert#*(F, G, cons(X, Y), Z) >= X because [9], by (Select) 9] cons(X, Y) >= X because [10], by (Star) 10] cons*(X, Y) >= X because [11], by (Select) 11] X >= X by (Meta) 12] insert#(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) because [13], by (Star) 13] insert#*(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) because [14], [15], [4], [18], [20] and [22], by (Stat) 14] F >= F by (Meta) 15] cons(X, Y) > Y because [16], by definition 16] cons*(X, Y) >= Y because [17], by (Select) 17] Y >= Y by (Meta) 18] insert#*(F, G, cons(X, Y), Z) >= G because [19], by (Select) 19] G >= G by (Meta) 20] insert#*(F, G, cons(X, Y), Z) >= Y because [21], by (Select) 21] cons(X, Y) >= Y because [16], by (Star) 22] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, Z), X) because insert# > @_{o -> o}, [23] and [8], by (Copy) 23] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, Z) because insert# > @_{o -> o -> o}, [18] and [6], by (Copy) 24] insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(G, Z), X) because [25], by definition 25] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, Z), X) because insert# > @_{o -> o}, [23] and [8], by (Copy) 26] sort#(F, G, cons(X, Y)) >= insert#(F, G, sort(F, G, Y), X) because [27], by (Star) 27] sort#*(F, G, cons(X, Y)) >= insert#(F, G, sort(F, G, Y), X) because sort# > insert#, [28], [30], [32] and [38], by (Copy) 28] sort#*(F, G, cons(X, Y)) >= F because [29], by (Select) 29] F >= F by (Meta) 30] sort#*(F, G, cons(X, Y)) >= G because [31], by (Select) 31] G >= G by (Meta) 32] sort#*(F, G, cons(X, Y)) >= sort(F, G, Y) because sort# = sort, sort# in Mul, [33], [34] and [35], by (Stat) 33] F >= F by (Meta) 34] G >= G by (Meta) 35] cons(X, Y) > Y because [36], by definition 36] cons*(X, Y) >= Y because [37], by (Select) 37] Y >= Y by (Meta) 38] sort#*(F, G, cons(X, Y)) >= X because [39], by (Select) 39] cons(X, Y) >= X because [40], by (Star) 40] cons*(X, Y) >= X because [41], by (Select) 41] X >= X by (Meta) 42] sort#(F, G, cons(X, Y)) >= sort#(F, G, Y) because sort# in Mul, [33], [34] and [43], by (Fun) 43] cons(X, Y) >= Y because [36], by (Star) 44] #argfun-ascending!fac6220sort##(sort#(_|_, _|_, X)) >= sort#(_|_, _|_, X) because [45], by (Star) 45] #argfun-ascending!fac6220sort##*(sort#(_|_, _|_, X)) >= sort#(_|_, _|_, X) because #argfun-ascending!fac6220sort## > sort#, [46], [47] and [48], by (Copy) 46] #argfun-ascending!fac6220sort##*(sort#(_|_, _|_, X)) >= _|_ by (Bot) 47] #argfun-ascending!fac6220sort##*(sort#(_|_, _|_, X)) >= _|_ by (Bot) 48] #argfun-ascending!fac6220sort##*(sort#(_|_, _|_, X)) >= X because [49], by (Select) 49] sort#(_|_, _|_, X) >= X because [50], by (Star) 50] sort#*(_|_, _|_, X) >= X because [51], by (Select) 51] X >= X by (Meta) 52] #argfun-descending!fac6220sort##(sort#(_|_, _|_, X)) >= sort#(_|_, _|_, X) because [53], by (Star) 53] #argfun-descending!fac6220sort##*(sort#(_|_, _|_, X)) >= sort#(_|_, _|_, X) because [54], by (Select) 54] sort#(_|_, _|_, X) >= sort#(_|_, _|_, X) because sort# in Mul, [55], [56] and [57], by (Fun) 55] _|_ >= _|_ by (Bot) 56] _|_ >= _|_ by (Bot) 57] X >= X by (Meta) 58] insert(F, G, _|_, X) >= cons(X, _|_) because [59], by (Star) 59] insert*(F, G, _|_, X) >= cons(X, _|_) because insert > cons, [60] and [62], by (Copy) 60] insert*(F, G, _|_, X) >= X because [61], by (Select) 61] X >= X by (Meta) 62] insert*(F, G, _|_, X) >= _|_ by (Bot) 63] insert(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, Z), X), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X))) because [64], by (Star) 64] insert*(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, Z), X), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X))) because insert > cons, [65] and [70], by (Copy) 65] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, Z), X) because insert > @_{o -> o}, [66] and [69], by (Copy) 66] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, Z) because insert > @_{o -> o -> o}, [67] and [68], by (Copy) 67] insert*(F, G, cons(X, Y), Z) >= F because [14], by (Select) 68] insert*(F, G, cons(X, Y), Z) >= Z because [7], by (Select) 69] insert*(F, G, cons(X, Y), Z) >= X because [9], by (Select) 70] insert*(F, G, cons(X, Y), Z) >= insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) because [15], [67], [71], [72] and [73], by (Stat) 71] insert*(F, G, cons(X, Y), Z) >= G because [19], by (Select) 72] insert*(F, G, cons(X, Y), Z) >= Y because [21], by (Select) 73] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, Z), X) because insert > @_{o -> o}, [74] and [69], by (Copy) 74] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, Z) because insert > @_{o -> o -> o}, [71] and [68], by (Copy) 75] sort(F, G, _|_) >= _|_ by (Bot) 76] sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because [77], by (Star) 77] sort*(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because sort > insert, [78], [79], [80] and [81], by (Copy) 78] sort*(F, G, cons(X, Y)) >= F because [33], by (Select) 79] sort*(F, G, cons(X, Y)) >= G because [34], by (Select) 80] sort*(F, G, cons(X, Y)) >= sort(F, G, Y) because sort in Mul, [33], [34] and [35], by (Stat) 81] sort*(F, G, cons(X, Y)) >= X because [39], by (Select) 82] #argfun-ascending!fac6220sort#(sort(_|_, _|_, X)) >= sort(_|_, _|_, X) because [83], by (Star) 83] #argfun-ascending!fac6220sort#*(sort(_|_, _|_, X)) >= sort(_|_, _|_, X) because #argfun-ascending!fac6220sort# > sort, [84], [85] and [86], by (Copy) 84] #argfun-ascending!fac6220sort#*(sort(_|_, _|_, X)) >= _|_ by (Bot) 85] #argfun-ascending!fac6220sort#*(sort(_|_, _|_, X)) >= _|_ by (Bot) 86] #argfun-ascending!fac6220sort#*(sort(_|_, _|_, X)) >= X because [87], by (Select) 87] sort(_|_, _|_, X) >= X because [88], by (Star) 88] sort*(_|_, _|_, X) >= X because [51], by (Select) 89] #argfun-descending!fac6220sort#(sort(_|_, _|_, X)) >= sort(_|_, _|_, X) because [90], by (Star) 90] #argfun-descending!fac6220sort#*(sort(_|_, _|_, X)) >= sort(_|_, _|_, X) because #argfun-descending!fac6220sort# > sort, [91], [92] and [93], by (Copy) 91] #argfun-descending!fac6220sort#*(sort(_|_, _|_, X)) >= _|_ by (Bot) 92] #argfun-descending!fac6220sort#*(sort(_|_, _|_, X)) >= _|_ by (Bot) 93] #argfun-descending!fac6220sort#*(sort(_|_, _|_, X)) >= X because [94], by (Select) 94] sort(_|_, _|_, X) >= X because [95], by (Star) 95] sort*(_|_, _|_, X) >= X because [57], 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: insert#(F, G, cons(X, Y), Z) =#> F(Z, X) insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G Z X) sort#(F, G, cons(X, Y)) =#> insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) ascending!fac6220sort#(X) =#> sort#(min, max, X) descending!fac6220sort#(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 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: insert#(F, G, cons(X, Y), Z) >? F(Z, X) insert#(F, G, cons(X, Y), Z) >? insert#(F, G, Y, G Z X) sort#(F, G, cons(X, Y)) >? insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) >? sort#(F, G, Y) ascending!fac6220sort#(X) >? sort#(min, max, X) descending!fac6220sort#(X) >? sort#(max, min, X) insert(F, G, nil, X) >= cons(X, nil) insert(F, G, cons(X, Y), Z) >= cons(F Z X, insert(F, G, Y, G Z X)) sort(F, G, nil) >= nil sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) ascending!fac6220sort(X) >= sort(min, max, X) descending!fac6220sort(X) >= sort(max, min, X) We apply [Kop12, Thm. 6.75] and use the following argument functions: pi( ascending!fac6220sort(X) ) = #argfun-ascending!fac6220sort#(sort(min, max, X)) pi( ascending!fac6220sort#(X) ) = #argfun-ascending!fac6220sort##(sort#(min, max, X)) pi( descending!fac6220sort(X) ) = #argfun-descending!fac6220sort#(sort(max, min, X)) pi( descending!fac6220sort#(X) ) = #argfun-descending!fac6220sort##(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-descending!fac6220sort#(x_1)]] = x_1 [[ascending!fac6220sort(x_1)]] = x_1 [[ascending!fac6220sort#(x_1)]] = x_1 [[descending!fac6220sort(x_1)]] = x_1 [[descending!fac6220sort#(x_1)]] = x_1 [[insert(x_1, x_2, x_3, x_4)]] = insert(x_2, x_1, x_3, x_4) [[insert#(x_1, x_2, x_3, x_4)]] = insert#(x_1, x_3, x_4, x_2) [[nil]] = _|_ We choose Lex = {insert, insert#} and Mul = {#argfun-ascending!fac6220sort#, #argfun-ascending!fac6220sort##, #argfun-descending!fac6220sort##, @_{o -> o -> o}, @_{o -> o}, cons, max, min, sort, sort#}, and the following precedence: #argfun-ascending!fac6220sort# > #argfun-ascending!fac6220sort## > #argfun-descending!fac6220sort## > max = min > sort# > insert# > sort > insert > @_{o -> o -> o} > @_{o -> o} > cons Taking the argument function into account, and fixing the greater / greater equal choices, the constraints can be denoted as follows: insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(F, Z), X) insert#(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) sort#(F, G, cons(X, Y)) >= insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) >= sort#(F, G, Y) #argfun-ascending!fac6220sort##(sort#(min, max, X)) >= sort#(min, max, X) #argfun-descending!fac6220sort##(sort#(max, min, X)) >= sort#(max, min, X) insert(F, G, _|_, X) >= cons(X, _|_) insert(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, Z), X), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X))) sort(F, G, _|_) >= _|_ sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) #argfun-ascending!fac6220sort#(sort(min, max, X)) >= sort(min, max, X) sort(max, min, X) >= sort(max, min, X) With these choices, we have: 1] insert#(F, G, cons(X, Y), Z) > @_{o -> o}(@_{o -> o -> o}(F, Z), X) because [2], by definition 2] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, Z), X) because insert# > @_{o -> o}, [3] and [8], by (Copy) 3] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, Z) because insert# > @_{o -> o -> o}, [4] and [6], by (Copy) 4] insert#*(F, G, cons(X, Y), Z) >= F because [5], by (Select) 5] F >= F by (Meta) 6] insert#*(F, G, cons(X, Y), Z) >= Z because [7], by (Select) 7] Z >= Z by (Meta) 8] insert#*(F, G, cons(X, Y), Z) >= X because [9], by (Select) 9] cons(X, Y) >= X because [10], by (Star) 10] cons*(X, Y) >= X because [11], by (Select) 11] X >= X by (Meta) 12] insert#(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) because [13], by (Star) 13] insert#*(F, G, cons(X, Y), Z) >= insert#(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) because [14], [15], [4], [18], [20] and [22], by (Stat) 14] F >= F by (Meta) 15] cons(X, Y) > Y because [16], by definition 16] cons*(X, Y) >= Y because [17], by (Select) 17] Y >= Y by (Meta) 18] insert#*(F, G, cons(X, Y), Z) >= G because [19], by (Select) 19] G >= G by (Meta) 20] insert#*(F, G, cons(X, Y), Z) >= Y because [21], by (Select) 21] cons(X, Y) >= Y because [16], by (Star) 22] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, Z), X) because insert# > @_{o -> o}, [23] and [8], by (Copy) 23] insert#*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, Z) because insert# > @_{o -> o -> o}, [18] and [6], by (Copy) 24] sort#(F, G, cons(X, Y)) >= insert#(F, G, sort(F, G, Y), X) because [25], by (Star) 25] sort#*(F, G, cons(X, Y)) >= insert#(F, G, sort(F, G, Y), X) because sort# > insert#, [26], [28], [30] and [35], by (Copy) 26] sort#*(F, G, cons(X, Y)) >= F because [27], by (Select) 27] F >= F by (Meta) 28] sort#*(F, G, cons(X, Y)) >= G because [29], by (Select) 29] G >= G by (Meta) 30] sort#*(F, G, cons(X, Y)) >= sort(F, G, Y) because sort# > sort, [26], [28] and [31], by (Copy) 31] sort#*(F, G, cons(X, Y)) >= Y because [32], by (Select) 32] cons(X, Y) >= Y because [33], by (Star) 33] cons*(X, Y) >= Y because [34], by (Select) 34] Y >= Y by (Meta) 35] sort#*(F, G, cons(X, Y)) >= X because [36], by (Select) 36] cons(X, Y) >= X because [37], by (Star) 37] cons*(X, Y) >= X because [38], by (Select) 38] X >= X by (Meta) 39] sort#(F, G, cons(X, Y)) >= sort#(F, G, Y) because [40], by (Star) 40] sort#*(F, G, cons(X, Y)) >= sort#(F, G, Y) because sort# in Mul, [41], [42] and [43], by (Stat) 41] F >= F by (Meta) 42] G >= G by (Meta) 43] cons(X, Y) > Y because [44], by definition 44] cons*(X, Y) >= Y because [34], by (Select) 45] #argfun-ascending!fac6220sort##(sort#(min, max, X)) >= sort#(min, max, X) because [46], by (Star) 46] #argfun-ascending!fac6220sort##*(sort#(min, max, X)) >= sort#(min, max, X) because [47], by (Select) 47] sort#(min, max, X) >= sort#(min, max, X) because sort# in Mul, [48], [49] and [50], by (Fun) 48] min >= max because min = max, by (Fun) 49] max >= min because max = min, by (Fun) 50] X >= X by (Meta) 51] #argfun-descending!fac6220sort##(sort#(max, min, X)) >= sort#(max, min, X) because [52], by (Star) 52] #argfun-descending!fac6220sort##*(sort#(max, min, X)) >= sort#(max, min, X) because #argfun-descending!fac6220sort## > sort#, [53], [54] and [55], by (Copy) 53] #argfun-descending!fac6220sort##*(sort#(max, min, X)) >= max because #argfun-descending!fac6220sort## > max, by (Copy) 54] #argfun-descending!fac6220sort##*(sort#(max, min, X)) >= min because #argfun-descending!fac6220sort## > min, by (Copy) 55] #argfun-descending!fac6220sort##*(sort#(max, min, X)) >= X because [56], by (Select) 56] sort#(max, min, X) >= X because [57], by (Star) 57] sort#*(max, min, X) >= X because [58], by (Select) 58] X >= X by (Meta) 59] insert(F, G, _|_, X) >= cons(X, _|_) because [60], by (Star) 60] insert*(F, G, _|_, X) >= cons(X, _|_) because insert > cons, [61] and [63], by (Copy) 61] insert*(F, G, _|_, X) >= X because [62], by (Select) 62] X >= X by (Meta) 63] insert*(F, G, _|_, X) >= _|_ by (Bot) 64] insert(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, Z), X), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X))) because [65], by (Star) 65] insert*(F, G, cons(X, Y), Z) >= cons(@_{o -> o}(@_{o -> o -> o}(F, Z), X), insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X))) because insert > cons, [66] and [71], by (Copy) 66] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, Z), X) because insert > @_{o -> o}, [67] and [70], by (Copy) 67] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, Z) because insert > @_{o -> o -> o}, [68] and [69], by (Copy) 68] insert*(F, G, cons(X, Y), Z) >= F because [14], by (Select) 69] insert*(F, G, cons(X, Y), Z) >= Z because [7], by (Select) 70] insert*(F, G, cons(X, Y), Z) >= X because [9], by (Select) 71] insert*(F, G, cons(X, Y), Z) >= insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) because [14], [72], [15], [68], [73], [74] and [75], by (Stat) 72] G >= G by (Meta) 73] insert*(F, G, cons(X, Y), Z) >= G because [72], by (Select) 74] insert*(F, G, cons(X, Y), Z) >= Y because [21], by (Select) 75] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, Z), X) because insert > @_{o -> o}, [76] and [70], by (Copy) 76] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, Z) because insert > @_{o -> o -> o}, [73] and [69], by (Copy) 77] sort(F, G, _|_) >= _|_ by (Bot) 78] sort(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because [79], by (Star) 79] sort*(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because sort > insert, [80], [81], [82] and [83], by (Copy) 80] sort*(F, G, cons(X, Y)) >= F because [41], by (Select) 81] sort*(F, G, cons(X, Y)) >= G because [42], by (Select) 82] sort*(F, G, cons(X, Y)) >= sort(F, G, Y) because sort in Mul, [41], [42] and [43], by (Stat) 83] sort*(F, G, cons(X, Y)) >= X because [36], by (Select) 84] #argfun-ascending!fac6220sort#(sort(min, max, X)) >= sort(min, max, X) because [85], by (Star) 85] #argfun-ascending!fac6220sort#*(sort(min, max, X)) >= sort(min, max, X) because #argfun-ascending!fac6220sort# > sort, [86], [87] and [88], by (Copy) 86] #argfun-ascending!fac6220sort#*(sort(min, max, X)) >= min because #argfun-ascending!fac6220sort# > min, by (Copy) 87] #argfun-ascending!fac6220sort#*(sort(min, max, X)) >= max because #argfun-ascending!fac6220sort# > max, by (Copy) 88] #argfun-ascending!fac6220sort#*(sort(min, max, X)) >= X because [89], by (Select) 89] sort(min, max, X) >= X because [90], by (Star) 90] sort*(min, max, X) >= X because [50], by (Select) 91] sort(max, min, X) >= sort(max, min, X) because sort in Mul, [49], [48] and [92], by (Fun) 92] X >= X by (Meta) By the observations in [Kop12, Sec. 6.6], this reduction pair suffices; we may thus replace the dependency pair problem (P_2, R_1, minimal, formative) by (P_3, R_1, minimal, formative), where P_3 consists of: insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G Z X) sort#(F, G, cons(X, Y)) =#> insert#(F, G, sort(F, G, Y), X) sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) ascending!fac6220sort#(X) =#> sort#(min, max, X) descending!fac6220sort#(X) =#> sort#(max, min, X) 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 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 : 0 * 2 : 1, 2 * 3 : 1, 2 * 4 : 1, 2 This graph has the following strongly connected components: P_4: insert#(F, G, cons(X, Y), Z) =#> insert#(F, G, Y, G Z X) P_5: sort#(F, G, cons(X, Y)) =#> sort#(F, G, Y) By [Kop12, Thm. 7.31], we may replace any dependency pair problem (P_3, R_1, m, f) by (P_4, R_1, m, f) and (P_5, R_1, m, f). Thus, the original system is terminating if each of (P_4, R_1, 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(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_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 (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 Z X)) By [FuhKop19, Thm. 61], 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. 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.