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