(0) Obligation:

Clauses:

balance(T, TB) :- balance(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])).
balance(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)).
balance(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) :- ','(balance(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)), balance(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))).

Queries:

balance(g,a).

(1) PrologToPiTRSProof (SOUND transformation)

We use the technique of [LOPSTR]. With regard to the inferred argument filtering the predicates were used in the following modes:
balance_in: (b,f)
balance_in: (b,f,f,f,f)
Transforming Prolog into the following Term Rewriting System:
Pi-finite rewrite system:
The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x1, x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x1, x2, x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x1, x2, x3, x18)
balance_out_ga(x1, x2)  =  balance_out_ga(x1)

Infinitary Constructor Rewriting Termination of PiTRS implies Termination of Prolog

(2) Obligation:

Pi-finite rewrite system:
The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x1, x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x1, x2, x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x1, x2, x3, x18)
balance_out_ga(x1, x2)  =  balance_out_ga(x1)

(3) DependencyPairsProof (EQUIVALENT transformation)

Using Dependency Pairs [AG00,LOPSTR] we result in the following initial DP problem:
Pi DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GA(T, TB) → U1_GA(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
BALANCE_IN_GA(T, TB) → BALANCE_IN_GAAAA(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GAAAA(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))
U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GAAAA(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x1, x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x1, x2, x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x1, x2, x3, x18)
balance_out_ga(x1, x2)  =  balance_out_ga(x1)
BALANCE_IN_GA(x1, x2)  =  BALANCE_IN_GA(x1)
U1_GA(x1, x2, x3)  =  U1_GA(x1, x3)
BALANCE_IN_GAAAA(x1, x2, x3, x4, x5)  =  BALANCE_IN_GAAAA(x1)
U2_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GAAAA(x1, x2, x3, x18)
U3_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_GAAAA(x1, x2, x3, x18)

We have to consider all (P,R,Pi)-chains

(4) Obligation:

Pi DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GA(T, TB) → U1_GA(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
BALANCE_IN_GA(T, TB) → BALANCE_IN_GAAAA(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GAAAA(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))
U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GAAAA(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x1, x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x1, x2, x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x1, x2, x3, x18)
balance_out_ga(x1, x2)  =  balance_out_ga(x1)
BALANCE_IN_GA(x1, x2)  =  BALANCE_IN_GA(x1)
U1_GA(x1, x2, x3)  =  U1_GA(x1, x3)
BALANCE_IN_GAAAA(x1, x2, x3, x4, x5)  =  BALANCE_IN_GAAAA(x1)
U2_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GAAAA(x1, x2, x3, x18)
U3_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_GAAAA(x1, x2, x3, x18)

We have to consider all (P,R,Pi)-chains

(5) DependencyGraphProof (EQUIVALENT transformation)

The approximation of the Dependency Graph [LOPSTR] contains 1 SCC with 3 less nodes.

(6) Obligation:

Pi DP problem:
The TRS P consists of the following rules:

U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GAAAA(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GAAAA(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x1, x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x1, x2, x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x1, x2, x3, x18)
balance_out_ga(x1, x2)  =  balance_out_ga(x1)
BALANCE_IN_GAAAA(x1, x2, x3, x4, x5)  =  BALANCE_IN_GAAAA(x1)
U2_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GAAAA(x1, x2, x3, x18)

We have to consider all (P,R,Pi)-chains

(7) UsableRulesProof (EQUIVALENT transformation)

For (infinitary) constructor rewriting [LOPSTR] we can delete all non-usable rules from R.

(8) Obligation:

Pi DP problem:
The TRS P consists of the following rules:

U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GAAAA(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GAAAA(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))

The TRS R consists of the following rules:

balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))

The argument filtering Pi contains the following mapping:
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x1, x2, x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x1, x2, x3, x18)
BALANCE_IN_GAAAA(x1, x2, x3, x4, x5)  =  BALANCE_IN_GAAAA(x1)
U2_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GAAAA(x1, x2, x3, x18)

We have to consider all (P,R,Pi)-chains

(9) PiDPToQDPProof (SOUND transformation)

Transforming (infinitary) constructor rewriting Pi-DP problem [LOPSTR] into ordinary QDP problem [LPAR04] by application of Pi.

(10) Obligation:

Q DP problem:
The TRS P consists of the following rules:

U2_GAAAA(L, V, R, balance_out_gaaaa(L)) → BALANCE_IN_GAAAA(R)
BALANCE_IN_GAAAA(tree(L, V, R)) → U2_GAAAA(L, V, R, balance_in_gaaaa(L))
BALANCE_IN_GAAAA(tree(L, V, R)) → BALANCE_IN_GAAAA(L)

The TRS R consists of the following rules:

balance_in_gaaaa(nil) → balance_out_gaaaa(nil)
balance_in_gaaaa(tree(L, V, R)) → U2_gaaaa(L, V, R, balance_in_gaaaa(L))
U2_gaaaa(L, V, R, balance_out_gaaaa(L)) → U3_gaaaa(L, V, R, balance_in_gaaaa(R))
U3_gaaaa(L, V, R, balance_out_gaaaa(R)) → balance_out_gaaaa(tree(L, V, R))

The set Q consists of the following terms:

balance_in_gaaaa(x0)
U2_gaaaa(x0, x1, x2, x3)
U3_gaaaa(x0, x1, x2, x3)

We have to consider all (P,Q,R)-chains.

(11) PrologToPiTRSProof (SOUND transformation)

We use the technique of [LOPSTR]. With regard to the inferred argument filtering the predicates were used in the following modes:
balance_in: (b,f)
balance_in: (b,f,f,f,f)
Transforming Prolog into the following Term Rewriting System:
Pi-finite rewrite system:
The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x18)
balance_out_ga(x1, x2)  =  balance_out_ga

Infinitary Constructor Rewriting Termination of PiTRS implies Termination of Prolog

(12) Obligation:

Pi-finite rewrite system:
The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x18)
balance_out_ga(x1, x2)  =  balance_out_ga

(13) DependencyPairsProof (EQUIVALENT transformation)

Using Dependency Pairs [AG00,LOPSTR] we result in the following initial DP problem:
Pi DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GA(T, TB) → U1_GA(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
BALANCE_IN_GA(T, TB) → BALANCE_IN_GAAAA(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GAAAA(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))
U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GAAAA(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x18)
balance_out_ga(x1, x2)  =  balance_out_ga
BALANCE_IN_GA(x1, x2)  =  BALANCE_IN_GA(x1)
U1_GA(x1, x2, x3)  =  U1_GA(x3)
BALANCE_IN_GAAAA(x1, x2, x3, x4, x5)  =  BALANCE_IN_GAAAA(x1)
U2_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GAAAA(x3, x18)
U3_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_GAAAA(x18)

We have to consider all (P,R,Pi)-chains

(14) Obligation:

Pi DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GA(T, TB) → U1_GA(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
BALANCE_IN_GA(T, TB) → BALANCE_IN_GAAAA(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GAAAA(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))
U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GAAAA(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x18)
balance_out_ga(x1, x2)  =  balance_out_ga
BALANCE_IN_GA(x1, x2)  =  BALANCE_IN_GA(x1)
U1_GA(x1, x2, x3)  =  U1_GA(x3)
BALANCE_IN_GAAAA(x1, x2, x3, x4, x5)  =  BALANCE_IN_GAAAA(x1)
U2_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GAAAA(x3, x18)
U3_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_GAAAA(x18)

We have to consider all (P,R,Pi)-chains

(15) DependencyGraphProof (EQUIVALENT transformation)

The approximation of the Dependency Graph [LOPSTR] contains 1 SCC with 3 less nodes.

(16) Obligation:

Pi DP problem:
The TRS P consists of the following rules:

U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GAAAA(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GAAAA(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_gaaaa(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x18)
balance_out_ga(x1, x2)  =  balance_out_ga
BALANCE_IN_GAAAA(x1, x2, x3, x4, x5)  =  BALANCE_IN_GAAAA(x1)
U2_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GAAAA(x3, x18)

We have to consider all (P,R,Pi)-chains

(17) UsableRulesProof (EQUIVALENT transformation)

For (infinitary) constructor rewriting [LOPSTR] we can delete all non-usable rules from R.

(18) Obligation:

Pi DP problem:
The TRS P consists of the following rules:

U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GAAAA(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GAAAA(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GAAAA(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GAAAA(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))

The TRS R consists of the following rules:

balance_in_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_gaaaa(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_gaaaa(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_gaaaa(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_gaaaa(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))

The argument filtering Pi contains the following mapping:
balance_in_gaaaa(x1, x2, x3, x4, x5)  =  balance_in_gaaaa(x1)
nil  =  nil
balance_out_gaaaa(x1, x2, x3, x4, x5)  =  balance_out_gaaaa
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_gaaaa(x3, x18)
U3_gaaaa(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_gaaaa(x18)
BALANCE_IN_GAAAA(x1, x2, x3, x4, x5)  =  BALANCE_IN_GAAAA(x1)
U2_GAAAA(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GAAAA(x3, x18)

We have to consider all (P,R,Pi)-chains

(19) PiDPToQDPProof (SOUND transformation)

Transforming (infinitary) constructor rewriting Pi-DP problem [LOPSTR] into ordinary QDP problem [LPAR04] by application of Pi.

(20) Obligation:

Q DP problem:
The TRS P consists of the following rules:

U2_GAAAA(R, balance_out_gaaaa) → BALANCE_IN_GAAAA(R)
BALANCE_IN_GAAAA(tree(L, V, R)) → U2_GAAAA(R, balance_in_gaaaa(L))
BALANCE_IN_GAAAA(tree(L, V, R)) → BALANCE_IN_GAAAA(L)

The TRS R consists of the following rules:

balance_in_gaaaa(nil) → balance_out_gaaaa
balance_in_gaaaa(tree(L, V, R)) → U2_gaaaa(R, balance_in_gaaaa(L))
U2_gaaaa(R, balance_out_gaaaa) → U3_gaaaa(balance_in_gaaaa(R))
U3_gaaaa(balance_out_gaaaa) → balance_out_gaaaa

The set Q consists of the following terms:

balance_in_gaaaa(x0)
U2_gaaaa(x0, x1)
U3_gaaaa(x0)

We have to consider all (P,Q,R)-chains.

(21) QDPSizeChangeProof (EQUIVALENT transformation)

By using the subterm criterion [SUBTERM_CRITERION] together with the size-change analysis [AAECC05] we have proven that there are no infinite chains for this DP problem.

From the DPs we obtained the following set of size-change graphs:

  • BALANCE_IN_GAAAA(tree(L, V, R)) → U2_GAAAA(R, balance_in_gaaaa(L))
    The graph contains the following edges 1 > 1

  • BALANCE_IN_GAAAA(tree(L, V, R)) → BALANCE_IN_GAAAA(L)
    The graph contains the following edges 1 > 1

  • U2_GAAAA(R, balance_out_gaaaa) → BALANCE_IN_GAAAA(R)
    The graph contains the following edges 1 >= 1

(22) TRUE