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 use rule removal, following [Kop12, Theorem 2.23]. This gives the following requirements (possibly using Theorems 2.25 and 2.26 in [Kop12]): 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) We use a recursive path ordering as defined in [Kop12, Chapter 5]. Argument functions: [[cons(x_1, x_2)]] = cons(x_2, x_1) [[insert(x_1, x_2, x_3, x_4)]] = insert(x_3, x_4, x_2, x_1) [[max]] = _|_ [[min]] = _|_ [[nil]] = _|_ We choose Lex = {cons, insert} and Mul = {0, @_{o -> o -> o}, @_{o -> o}, ascending!fac6220sort, descending!fac6220sort, s, sort}, and the following precedence: ascending!fac6220sort > descending!fac6220sort > s > sort > insert > 0 > @_{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: @_{o -> o}(@_{o -> o -> o}(_|_, 0), X) >= X @_{o -> o}(@_{o -> o -> o}(_|_, X), 0) > X @_{o -> o}(@_{o -> o -> o}(_|_, s(X)), s(Y)) >= @_{o -> o}(@_{o -> o -> o}(_|_, X), Y) @_{o -> o}(@_{o -> o -> o}(_|_, 0), X) > 0 @_{o -> o}(@_{o -> o -> o}(_|_, X), 0) > 0 @_{o -> o}(@_{o -> o -> o}(_|_, s(X)), s(Y)) >= @_{o -> o}(@_{o -> o -> o}(_|_, X), Y) 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) ascending!fac6220sort(X) >= sort(_|_, _|_, X) descending!fac6220sort(X) >= sort(_|_, _|_, X) With these choices, we have: 1] @_{o -> o}(@_{o -> o -> o}(_|_, 0), X) >= X because [2], by (Star) 2] @_{o -> o}*(@_{o -> o -> o}(_|_, 0), X) >= X because [3], by (Select) 3] X >= X by (Meta) 4] @_{o -> o}(@_{o -> o -> o}(_|_, X), 0) > X because [5], by definition 5] @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0) >= X because [6], by (Select) 6] @_{o -> o -> o}(_|_, X) @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0) >= X because [7] 7] @_{o -> o -> o}*(_|_, X, @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0)) >= X because [8], by (Select) 8] @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0) >= X because [9], by (Select) 9] @_{o -> o -> o}(_|_, X) @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0) >= X because [10] 10] @_{o -> o -> o}*(_|_, X, @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0)) >= X because [11], by (Select) 11] X >= X by (Meta) 12] @_{o -> o}(@_{o -> o -> o}(_|_, s(X)), s(Y)) >= @_{o -> o}(@_{o -> o -> o}(_|_, X), Y) because @_{o -> o} in Mul, [13] and [18], by (Fun) 13] @_{o -> o -> o}(_|_, s(X)) >= @_{o -> o -> o}(_|_, X) because @_{o -> o -> o} in Mul, [14] and [15], by (Fun) 14] _|_ >= _|_ by (Bot) 15] s(X) >= X because [16], by (Star) 16] s*(X) >= X because [17], by (Select) 17] X >= X by (Meta) 18] s(Y) >= Y because [19], by (Star) 19] s*(Y) >= Y because [20], by (Select) 20] Y >= Y by (Meta) 21] @_{o -> o}(@_{o -> o -> o}(_|_, 0), X) > 0 because [22], by definition 22] @_{o -> o}*(@_{o -> o -> o}(_|_, 0), X) >= 0 because [23], by (Select) 23] @_{o -> o -> o}(_|_, 0) @_{o -> o}*(@_{o -> o -> o}(_|_, 0), X) >= 0 because [24] 24] @_{o -> o -> o}*(_|_, 0, @_{o -> o}*(@_{o -> o -> o}(_|_, 0), X)) >= 0 because [25], by (Select) 25] 0 >= 0 by (Fun) 26] @_{o -> o}(@_{o -> o -> o}(_|_, X), 0) > 0 because [27], by definition 27] @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0) >= 0 because [28], by (Select) 28] @_{o -> o -> o}(_|_, X) @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0) >= 0 because [29] 29] @_{o -> o -> o}*(_|_, X, @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0)) >= 0 because [30], by (Select) 30] @_{o -> o}*(@_{o -> o -> o}(_|_, X), 0) >= 0 because [31], by (Select) 31] 0 >= 0 by (Fun) 32] @_{o -> o}(@_{o -> o -> o}(_|_, s(X)), s(Y)) >= @_{o -> o}(@_{o -> o -> o}(_|_, X), Y) because @_{o -> o} in Mul, [33] and [38], by (Fun) 33] @_{o -> o -> o}(_|_, s(X)) >= @_{o -> o -> o}(_|_, X) because @_{o -> o -> o} in Mul, [34] and [35], by (Fun) 34] _|_ >= _|_ by (Bot) 35] s(X) >= X because [36], by (Star) 36] s*(X) >= X because [37], by (Select) 37] X >= X by (Meta) 38] s(Y) >= Y because [39], by (Star) 39] s*(Y) >= Y because [40], by (Select) 40] Y >= Y by (Meta) 41] insert(F, G, _|_, X) > cons(X, _|_) because [42], by definition 42] insert*(F, G, _|_, X) >= cons(X, _|_) because insert > cons, [43] and [45], by (Copy) 43] insert*(F, G, _|_, X) >= X because [44], by (Select) 44] X >= X by (Meta) 45] insert*(F, G, _|_, X) >= _|_ by (Bot) 46] 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 [47], by definition 47] 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, [48] and [58], by (Copy) 48] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(F, Z), X) because insert > @_{o -> o}, [49] and [54], by (Copy) 49] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(F, Z) because insert > @_{o -> o -> o}, [50] and [52], by (Copy) 50] insert*(F, G, cons(X, Y), Z) >= F because [51], by (Select) 51] F >= F by (Meta) 52] insert*(F, G, cons(X, Y), Z) >= Z because [53], by (Select) 53] Z >= Z by (Meta) 54] insert*(F, G, cons(X, Y), Z) >= X because [55], by (Select) 55] cons(X, Y) >= X because [56], by (Star) 56] cons*(X, Y) >= X because [57], by (Select) 57] X >= X by (Meta) 58] insert*(F, G, cons(X, Y), Z) >= insert(F, G, Y, @_{o -> o}(@_{o -> o -> o}(G, Z), X)) because [59], [50], [62], [64], [66], [68] and [69], by (Stat) 59] cons(X, Y) > Y because [60], by definition 60] cons*(X, Y) >= Y because [61], by (Select) 61] Y >= Y by (Meta) 62] insert*(F, G, cons(X, Y), Z) >= G because [63], by (Select) 63] G >= G by (Meta) 64] insert*(F, G, cons(X, Y), Z) >= Y because [65], by (Select) 65] cons(X, Y) >= Y because [60], by (Star) 66] insert*(F, G, cons(X, Y), Z) >= @_{o -> o}(@_{o -> o -> o}(G, Z), X) because insert > @_{o -> o}, [67] and [54], by (Copy) 67] insert*(F, G, cons(X, Y), Z) >= @_{o -> o -> o}(G, Z) because insert > @_{o -> o -> o}, [62] and [52], by (Copy) 68] F >= F by (Meta) 69] G >= G by (Meta) 70] sort(F, G, _|_) > _|_ because [71], by definition 71] sort*(F, G, _|_) >= _|_ by (Bot) 72] sort(F, G, cons(X, Y)) > insert(F, G, sort(F, G, Y), X) because [73], by definition 73] sort*(F, G, cons(X, Y)) >= insert(F, G, sort(F, G, Y), X) because sort > insert, [74], [76], [78] and [84], by (Copy) 74] sort*(F, G, cons(X, Y)) >= F because [75], by (Select) 75] F >= F by (Meta) 76] sort*(F, G, cons(X, Y)) >= G because [77], by (Select) 77] G >= G by (Meta) 78] sort*(F, G, cons(X, Y)) >= sort(F, G, Y) because sort in Mul, [79], [80] and [81], by (Stat) 79] F >= F by (Meta) 80] G >= G by (Meta) 81] cons(X, Y) > Y because [82], by definition 82] cons*(X, Y) >= Y because [83], by (Select) 83] Y >= Y by (Meta) 84] sort*(F, G, cons(X, Y)) >= X because [85], by (Select) 85] cons(X, Y) >= X because [86], by (Star) 86] cons*(X, Y) >= X because [87], by (Select) 87] X >= X by (Meta) 88] ascending!fac6220sort(X) >= sort(_|_, _|_, X) because [89], by (Star) 89] ascending!fac6220sort*(X) >= sort(_|_, _|_, X) because ascending!fac6220sort > sort, [90], [91] and [92], by (Copy) 90] ascending!fac6220sort*(X) >= _|_ by (Bot) 91] ascending!fac6220sort*(X) >= _|_ by (Bot) 92] ascending!fac6220sort*(X) >= X because [93], by (Select) 93] X >= X by (Meta) 94] descending!fac6220sort(X) >= sort(_|_, _|_, X) because [95], by (Star) 95] descending!fac6220sort*(X) >= sort(_|_, _|_, X) because descending!fac6220sort > sort, [96], [97] and [98], by (Copy) 96] descending!fac6220sort*(X) >= _|_ by (Bot) 97] descending!fac6220sort*(X) >= _|_ by (Bot) 98] descending!fac6220sort*(X) >= X because [99], by (Select) 99] X >= X by (Meta) We can thus remove the following rules: max X 0 => X min 0 X => 0 min X 0 => 0 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) We use rule removal, following [Kop12, Theorem 2.23]. This gives the following requirements (possibly using Theorems 2.25 and 2.26 in [Kop12]): max 0 X >? X max s(X) s(Y) >? max X Y min s(X) s(Y) >? min X Y ascending!fac6220sort(X) >? sort(min, max, X) descending!fac6220sort(X) >? sort(max, min, X) We orient these requirements with a polynomial interpretation in the natural numbers. The following interpretation satisfies the requirements: 0 = 3 ascending!fac6220sort = Lam[y0].3 + 3*y0 descending!fac6220sort = Lam[y0].3 + 3*y0 max = Lam[y0;y1].0 min = Lam[y0;y1].0 s = Lam[y0].3 + 3*y0 sort = Lam[G0;G1;y2].y2 + 3*G0(0,0) + 3*G1(0,0) Using this interpretation, the requirements translate to: [[max 0 _x0]] = 3 + x0 > x0 = [[_x0]] [[max s(_x0) s(_x1)]] = 6 + 3*x0 + 3*x1 > x0 + x1 = [[max _x0 _x1]] [[min s(_x0) s(_x1)]] = 6 + 3*x0 + 3*x1 > x0 + x1 = [[min _x0 _x1]] [[ascending!fac6220sort(_x0)]] = 3 + 3*x0 > x0 = [[sort(min, max, _x0)]] [[descending!fac6220sort(_x0)]] = 3 + 3*x0 > x0 = [[sort(max, min, _x0)]] We can thus remove the following rules: max 0 X => X max s(X) s(Y) => max X Y min s(X) s(Y) => min X Y ascending!fac6220sort(X) => sort(min, max, X) descending!fac6220sort(X) => sort(max, min, X) All rules were succesfully removed. Thus, termination of the original system has been reduced to termination of the beta-rule, which is well-known to hold. +++ Citations +++ [Kop12] C. Kop. Higher Order Termination. PhD Thesis, 2012.