Left Termination of the query pattern flat(b,f) w.r.t. the given Prolog program could successfully be proven:



PROLOG
  ↳ PrologToPiTRSProof

flat2(niltree0, nil0).
flat2(tree3(X, niltree0, T), cons2(X, Xs)) :- flat2(T, Xs).
flat2(tree3(X, tree3(Y, T1, T2), T3), Xs) :- flat2(tree3(Y, T1, tree3(X, T2, T3)), Xs).


With regard to the inferred argument filtering the predicates were used in the following modes:
flat2: (b,f)
Transforming PROLOG into the following Term Rewriting System:
Pi-finite rewrite system:
The TRS R consists of the following rules:


flat_2_in_ga2(niltree_0, nil_0) -> flat_2_out_ga2(niltree_0, nil_0)
flat_2_in_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> if_flat_2_in_1_ga4(X, T, Xs, flat_2_in_ga2(T, Xs))
flat_2_in_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_in_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs))
if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_out_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)) -> flat_2_out_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs)
if_flat_2_in_1_ga4(X, T, Xs, flat_2_out_ga2(T, Xs)) -> flat_2_out_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs))

The argument filtering Pi contains the following mapping:
flat_2_in_ga2(x1, x2)  =  flat_2_in_ga1(x1)
niltree_0  =  niltree_0
nil_0  =  nil_0
tree_33(x1, x2, x3)  =  tree_33(x1, x2, x3)
cons_22(x1, x2)  =  cons_22(x1, x2)
flat_2_out_ga2(x1, x2)  =  flat_2_out_ga1(x2)
if_flat_2_in_1_ga4(x1, x2, x3, x4)  =  if_flat_2_in_1_ga2(x1, x4)
if_flat_2_in_2_ga7(x1, x2, x3, x4, x5, x6, x7)  =  if_flat_2_in_2_ga1(x7)

Infinitary Constructor Rewriting Termination of PiTRS implies Termination of PROLOG



↳ PROLOG
  ↳ PrologToPiTRSProof
PiTRS
      ↳ DependencyPairsProof

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

flat_2_in_ga2(niltree_0, nil_0) -> flat_2_out_ga2(niltree_0, nil_0)
flat_2_in_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> if_flat_2_in_1_ga4(X, T, Xs, flat_2_in_ga2(T, Xs))
flat_2_in_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_in_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs))
if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_out_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)) -> flat_2_out_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs)
if_flat_2_in_1_ga4(X, T, Xs, flat_2_out_ga2(T, Xs)) -> flat_2_out_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs))

The argument filtering Pi contains the following mapping:
flat_2_in_ga2(x1, x2)  =  flat_2_in_ga1(x1)
niltree_0  =  niltree_0
nil_0  =  nil_0
tree_33(x1, x2, x3)  =  tree_33(x1, x2, x3)
cons_22(x1, x2)  =  cons_22(x1, x2)
flat_2_out_ga2(x1, x2)  =  flat_2_out_ga1(x2)
if_flat_2_in_1_ga4(x1, x2, x3, x4)  =  if_flat_2_in_1_ga2(x1, x4)
if_flat_2_in_2_ga7(x1, x2, x3, x4, x5, x6, x7)  =  if_flat_2_in_2_ga1(x7)


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

FLAT_2_IN_GA2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> IF_FLAT_2_IN_1_GA4(X, T, Xs, flat_2_in_ga2(T, Xs))
FLAT_2_IN_GA2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> FLAT_2_IN_GA2(T, Xs)
FLAT_2_IN_GA2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> IF_FLAT_2_IN_2_GA7(X, Y, T1, T2, T3, Xs, flat_2_in_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs))
FLAT_2_IN_GA2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> FLAT_2_IN_GA2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)

The TRS R consists of the following rules:

flat_2_in_ga2(niltree_0, nil_0) -> flat_2_out_ga2(niltree_0, nil_0)
flat_2_in_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> if_flat_2_in_1_ga4(X, T, Xs, flat_2_in_ga2(T, Xs))
flat_2_in_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_in_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs))
if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_out_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)) -> flat_2_out_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs)
if_flat_2_in_1_ga4(X, T, Xs, flat_2_out_ga2(T, Xs)) -> flat_2_out_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs))

The argument filtering Pi contains the following mapping:
flat_2_in_ga2(x1, x2)  =  flat_2_in_ga1(x1)
niltree_0  =  niltree_0
nil_0  =  nil_0
tree_33(x1, x2, x3)  =  tree_33(x1, x2, x3)
cons_22(x1, x2)  =  cons_22(x1, x2)
flat_2_out_ga2(x1, x2)  =  flat_2_out_ga1(x2)
if_flat_2_in_1_ga4(x1, x2, x3, x4)  =  if_flat_2_in_1_ga2(x1, x4)
if_flat_2_in_2_ga7(x1, x2, x3, x4, x5, x6, x7)  =  if_flat_2_in_2_ga1(x7)
FLAT_2_IN_GA2(x1, x2)  =  FLAT_2_IN_GA1(x1)
IF_FLAT_2_IN_1_GA4(x1, x2, x3, x4)  =  IF_FLAT_2_IN_1_GA2(x1, x4)
IF_FLAT_2_IN_2_GA7(x1, x2, x3, x4, x5, x6, x7)  =  IF_FLAT_2_IN_2_GA1(x7)

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

↳ PROLOG
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
PiDP
          ↳ DependencyGraphProof

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

FLAT_2_IN_GA2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> IF_FLAT_2_IN_1_GA4(X, T, Xs, flat_2_in_ga2(T, Xs))
FLAT_2_IN_GA2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> FLAT_2_IN_GA2(T, Xs)
FLAT_2_IN_GA2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> IF_FLAT_2_IN_2_GA7(X, Y, T1, T2, T3, Xs, flat_2_in_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs))
FLAT_2_IN_GA2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> FLAT_2_IN_GA2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)

The TRS R consists of the following rules:

flat_2_in_ga2(niltree_0, nil_0) -> flat_2_out_ga2(niltree_0, nil_0)
flat_2_in_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> if_flat_2_in_1_ga4(X, T, Xs, flat_2_in_ga2(T, Xs))
flat_2_in_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_in_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs))
if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_out_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)) -> flat_2_out_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs)
if_flat_2_in_1_ga4(X, T, Xs, flat_2_out_ga2(T, Xs)) -> flat_2_out_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs))

The argument filtering Pi contains the following mapping:
flat_2_in_ga2(x1, x2)  =  flat_2_in_ga1(x1)
niltree_0  =  niltree_0
nil_0  =  nil_0
tree_33(x1, x2, x3)  =  tree_33(x1, x2, x3)
cons_22(x1, x2)  =  cons_22(x1, x2)
flat_2_out_ga2(x1, x2)  =  flat_2_out_ga1(x2)
if_flat_2_in_1_ga4(x1, x2, x3, x4)  =  if_flat_2_in_1_ga2(x1, x4)
if_flat_2_in_2_ga7(x1, x2, x3, x4, x5, x6, x7)  =  if_flat_2_in_2_ga1(x7)
FLAT_2_IN_GA2(x1, x2)  =  FLAT_2_IN_GA1(x1)
IF_FLAT_2_IN_1_GA4(x1, x2, x3, x4)  =  IF_FLAT_2_IN_1_GA2(x1, x4)
IF_FLAT_2_IN_2_GA7(x1, x2, x3, x4, x5, x6, x7)  =  IF_FLAT_2_IN_2_GA1(x7)

We have to consider all (P,R,Pi)-chains
The approximation of the Dependency Graph contains 1 SCC with 2 less nodes.

↳ PROLOG
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
PiDP
              ↳ UsableRulesProof

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

FLAT_2_IN_GA2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> FLAT_2_IN_GA2(T, Xs)
FLAT_2_IN_GA2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> FLAT_2_IN_GA2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)

The TRS R consists of the following rules:

flat_2_in_ga2(niltree_0, nil_0) -> flat_2_out_ga2(niltree_0, nil_0)
flat_2_in_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> if_flat_2_in_1_ga4(X, T, Xs, flat_2_in_ga2(T, Xs))
flat_2_in_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_in_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs))
if_flat_2_in_2_ga7(X, Y, T1, T2, T3, Xs, flat_2_out_ga2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)) -> flat_2_out_ga2(tree_33(X, tree_33(Y, T1, T2), T3), Xs)
if_flat_2_in_1_ga4(X, T, Xs, flat_2_out_ga2(T, Xs)) -> flat_2_out_ga2(tree_33(X, niltree_0, T), cons_22(X, Xs))

The argument filtering Pi contains the following mapping:
flat_2_in_ga2(x1, x2)  =  flat_2_in_ga1(x1)
niltree_0  =  niltree_0
nil_0  =  nil_0
tree_33(x1, x2, x3)  =  tree_33(x1, x2, x3)
cons_22(x1, x2)  =  cons_22(x1, x2)
flat_2_out_ga2(x1, x2)  =  flat_2_out_ga1(x2)
if_flat_2_in_1_ga4(x1, x2, x3, x4)  =  if_flat_2_in_1_ga2(x1, x4)
if_flat_2_in_2_ga7(x1, x2, x3, x4, x5, x6, x7)  =  if_flat_2_in_2_ga1(x7)
FLAT_2_IN_GA2(x1, x2)  =  FLAT_2_IN_GA1(x1)

We have to consider all (P,R,Pi)-chains
For (infinitary) constructor rewriting we can delete all non-usable rules from R.

↳ PROLOG
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
PiDP
                  ↳ PiDPToQDPProof

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

FLAT_2_IN_GA2(tree_33(X, niltree_0, T), cons_22(X, Xs)) -> FLAT_2_IN_GA2(T, Xs)
FLAT_2_IN_GA2(tree_33(X, tree_33(Y, T1, T2), T3), Xs) -> FLAT_2_IN_GA2(tree_33(Y, T1, tree_33(X, T2, T3)), Xs)

R is empty.
The argument filtering Pi contains the following mapping:
niltree_0  =  niltree_0
tree_33(x1, x2, x3)  =  tree_33(x1, x2, x3)
cons_22(x1, x2)  =  cons_22(x1, x2)
FLAT_2_IN_GA2(x1, x2)  =  FLAT_2_IN_GA1(x1)

We have to consider all (P,R,Pi)-chains
Transforming (infinitary) constructor rewriting Pi-DP problem into ordinary QDP problem by application of Pi.

↳ PROLOG
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
QDP
                      ↳ RuleRemovalProof

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

FLAT_2_IN_GA1(tree_33(X, niltree_0, T)) -> FLAT_2_IN_GA1(T)
FLAT_2_IN_GA1(tree_33(X, tree_33(Y, T1, T2), T3)) -> FLAT_2_IN_GA1(tree_33(Y, T1, tree_33(X, T2, T3)))

R is empty.
Q is empty.
We have to consider all (P,Q,R)-chains.
The head symbols of this DP problem are {FLAT_2_IN_GA1}.
By using a polynomial ordering, at least one Dependency Pair or term rewrite system rule of this QDP problem can be strictly oriented.
Strictly oriented dependency pairs:

FLAT_2_IN_GA1(tree_33(X, niltree_0, T)) -> FLAT_2_IN_GA1(T)


Used ordering: POLO with Polynomial interpretation:

POL(niltree_0) = 1   
POL(FLAT_2_IN_GA1(x1)) = 1 + x1   
POL(tree_33(x1, x2, x3)) = x1 + x2 + x3   



↳ PROLOG
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
                    ↳ QDP
                      ↳ RuleRemovalProof
QDP
                          ↳ QDPSizeChangeProof

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

FLAT_2_IN_GA1(tree_33(X, tree_33(Y, T1, T2), T3)) -> FLAT_2_IN_GA1(tree_33(Y, T1, tree_33(X, T2, T3)))

R is empty.
Q is empty.
We have to consider all (P,Q,R)-chains.
The head symbols of this DP problem are {FLAT_2_IN_GA1}.
We used the following order and afs together with the size-change analysis to show that there are no infinite chains for this DP problem.

Order:Homeomorphic Embedding Order

AFS:
tree_33(x1, x2, x3)  =  tree_31(x2)

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

We oriented the following set of usable rules. none