YES

We show the termination of the TRS R:

  f(f(x,y,z),u,f(x,y,v)) -> f(x,y,f(z,u,v))
  f(x,y,y) -> y
  f(x,y,g(y)) -> x
  f(x,x,y) -> x
  f(g(x),x,y) -> y

-- SCC decomposition.

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

p1: f#(f(x,y,z),u,f(x,y,v)) -> f#(x,y,f(z,u,v))
p2: f#(f(x,y,z),u,f(x,y,v)) -> f#(z,u,v)

and R consists of:

r1: f(f(x,y,z),u,f(x,y,v)) -> f(x,y,f(z,u,v))
r2: f(x,y,y) -> y
r3: f(x,y,g(y)) -> x
r4: f(x,x,y) -> x
r5: f(g(x),x,y) -> y

The estimated dependency graph contains the following SCCs:

  {p1, p2}


-- Reduction pair.

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

p1: f#(f(x,y,z),u,f(x,y,v)) -> f#(x,y,f(z,u,v))
p2: f#(f(x,y,z),u,f(x,y,v)) -> f#(z,u,v)

and R consists of:

r1: f(f(x,y,z),u,f(x,y,v)) -> f(x,y,f(z,u,v))
r2: f(x,y,y) -> y
r3: f(x,y,g(y)) -> x
r4: f(x,x,y) -> x
r5: f(g(x),x,y) -> y

The set of usable rules consists of

  r1, r2, r3, r4, r5

Take the reduction pair:

  lexicographic combination of reduction pairs:
  
    1. matrix interpretations:
    
      carrier: N^1
      order: standard order
      interpretations:
        f#_A(x1,x2,x3) = x1 + x2
        f_A(x1,x2,x3) = x1 + x2 + x3 + 1
        g_A(x1) = 0
    
    2. lexicographic path order with precedence:
    
      precedence:
      
        f# > g > f
      
      argument filter:
    
        pi(f#) = [1]
        pi(f) = 2
        pi(g) = []
    

The next rules are strictly ordered:

  p1, p2

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