YES

We show the termination of the TRS R:

  app(app(append(),nil()),ys) -> ys
  app(app(append(),app(app(cons(),x),xs)),ys) -> app(app(cons(),x),app(app(append(),xs),ys))
  app(app(flatwith(),f),app(leaf(),x)) -> app(app(cons(),app(f,x)),nil())
  app(app(flatwith(),f),app(node(),xs)) -> app(app(flatwithsub(),f),xs)
  app(app(flatwithsub(),f),nil()) -> nil()
  app(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app(app(append(),app(app(flatwith(),f),x)),app(app(flatwithsub(),f),xs))

-- SCC decomposition.

Consider the dependency pair problem (P, R), where P consists of

p1: app#(app(append(),app(app(cons(),x),xs)),ys) -> app#(app(cons(),x),app(app(append(),xs),ys))
p2: app#(app(append(),app(app(cons(),x),xs)),ys) -> app#(app(append(),xs),ys)
p3: app#(app(append(),app(app(cons(),x),xs)),ys) -> app#(append(),xs)
p4: app#(app(flatwith(),f),app(leaf(),x)) -> app#(app(cons(),app(f,x)),nil())
p5: app#(app(flatwith(),f),app(leaf(),x)) -> app#(cons(),app(f,x))
p6: app#(app(flatwith(),f),app(leaf(),x)) -> app#(f,x)
p7: app#(app(flatwith(),f),app(node(),xs)) -> app#(app(flatwithsub(),f),xs)
p8: app#(app(flatwith(),f),app(node(),xs)) -> app#(flatwithsub(),f)
p9: app#(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app#(app(append(),app(app(flatwith(),f),x)),app(app(flatwithsub(),f),xs))
p10: app#(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app#(append(),app(app(flatwith(),f),x))
p11: app#(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app#(app(flatwith(),f),x)
p12: app#(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app#(flatwith(),f)
p13: app#(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app#(app(flatwithsub(),f),xs)

and R consists of:

r1: app(app(append(),nil()),ys) -> ys
r2: app(app(append(),app(app(cons(),x),xs)),ys) -> app(app(cons(),x),app(app(append(),xs),ys))
r3: app(app(flatwith(),f),app(leaf(),x)) -> app(app(cons(),app(f,x)),nil())
r4: app(app(flatwith(),f),app(node(),xs)) -> app(app(flatwithsub(),f),xs)
r5: app(app(flatwithsub(),f),nil()) -> nil()
r6: app(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app(app(append(),app(app(flatwith(),f),x)),app(app(flatwithsub(),f),xs))

The estimated dependency graph contains the following SCCs:

  {p6, p7, p11, p13}
  {p2}


-- Reduction pair.

Consider the dependency pair problem (P, R), where P consists of

p1: app#(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app#(app(flatwithsub(),f),xs)
p2: app#(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app#(app(flatwith(),f),x)
p3: app#(app(flatwith(),f),app(node(),xs)) -> app#(app(flatwithsub(),f),xs)
p4: app#(app(flatwith(),f),app(leaf(),x)) -> app#(f,x)

and R consists of:

r1: app(app(append(),nil()),ys) -> ys
r2: app(app(append(),app(app(cons(),x),xs)),ys) -> app(app(cons(),x),app(app(append(),xs),ys))
r3: app(app(flatwith(),f),app(leaf(),x)) -> app(app(cons(),app(f,x)),nil())
r4: app(app(flatwith(),f),app(node(),xs)) -> app(app(flatwithsub(),f),xs)
r5: app(app(flatwithsub(),f),nil()) -> nil()
r6: app(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app(app(append(),app(app(flatwith(),f),x)),app(app(flatwithsub(),f),xs))

The set of usable rules consists of

  (no rules)

Take the reduction pair:

  matrix interpretations:
  
    carrier: N^2
    order: lexicographic order
    interpretations:
      app#_A(x1,x2) = ((1,0),(1,1)) x1 + x2
      app_A(x1,x2) = x1 + x2 + (0,1)
      flatwithsub_A() = (1,1)
      cons_A() = (2,0)
      flatwith_A() = (2,1)
      node_A() = (1,1)
      leaf_A() = (1,1)

The next rules are strictly ordered:

  p1, p2, p3, p4

We remove them from the problem.  Then no dependency pair remains.

-- Reduction pair.

Consider the dependency pair problem (P, R), where P consists of

p1: app#(app(append(),app(app(cons(),x),xs)),ys) -> app#(app(append(),xs),ys)

and R consists of:

r1: app(app(append(),nil()),ys) -> ys
r2: app(app(append(),app(app(cons(),x),xs)),ys) -> app(app(cons(),x),app(app(append(),xs),ys))
r3: app(app(flatwith(),f),app(leaf(),x)) -> app(app(cons(),app(f,x)),nil())
r4: app(app(flatwith(),f),app(node(),xs)) -> app(app(flatwithsub(),f),xs)
r5: app(app(flatwithsub(),f),nil()) -> nil()
r6: app(app(flatwithsub(),f),app(app(cons(),x),xs)) -> app(app(append(),app(app(flatwith(),f),x)),app(app(flatwithsub(),f),xs))

The set of usable rules consists of

  (no rules)

Take the reduction pair:

  matrix interpretations:
  
    carrier: N^2
    order: lexicographic order
    interpretations:
      app#_A(x1,x2) = x1
      app_A(x1,x2) = x2 + (1,1)
      append_A() = (1,1)
      cons_A() = (1,0)

The next rules are strictly ordered:

  p1

We remove them from the problem.  Then no dependency pair remains.