(0) Obligation:

Clauses:

f(0, Y, Z) :- ','(!, eq(Z, 0)).
f(X, Y, Z) :- ','(p(X, P), ','(f(P, Y, U), f(U, Y, Z))).
p(0, 0).
p(s(X), X).
eq(X, X).

Query: f(g,a,a)

(1) PrologToTRSTransformerProof (SOUND transformation)

Transformed Prolog program to TRS.

(2) Obligation:

Q restricted rewrite system:
The TRS R consists of the following rules:

f3_in(0) → f3_out1(0)
f3_in(s(T31)) → U1(f41_in(T31), s(T31))
U1(f41_out1(X25, T27), s(T31)) → f3_out1(T27)
f47_in(0) → f47_out1(0)
f47_in(s(T52)) → U2(f87_in(T52), s(T52))
U2(f87_out1(X70, X71), s(T52)) → f47_out1(X71)
f41_in(T31) → U3(f47_in(T31), T31)
U3(f47_out1(T33), T31) → U4(f3_in(T33), T31, T33)
U4(f3_out1(T35), T31, T33) → f41_out1(T33, T35)
f87_in(T52) → U5(f47_in(T52), T52)
U5(f47_out1(T54), T52) → U6(f47_in(T54), T52, T54)
U6(f47_out1(X71), T52, T54) → f87_out1(T54, X71)

Q is empty.

(3) QTRSRRRProof (EQUIVALENT transformation)

Used ordering:
Combined order from the following AFS and order.
f3_in(x1)  =  f3_in(x1)
0  =  0
f3_out1(x1)  =  f3_out1(x1)
s(x1)  =  s(x1)
U1(x1, x2)  =  U1(x1, x2)
f41_in(x1)  =  f41_in(x1)
f41_out1(x1, x2)  =  f41_out1(x1, x2)
f47_in(x1)  =  f47_in(x1)
f47_out1(x1)  =  x1
U2(x1, x2)  =  U2(x1, x2)
f87_in(x1)  =  f87_in(x1)
f87_out1(x1, x2)  =  f87_out1(x1, x2)
U3(x1, x2)  =  U3(x1, x2)
U4(x1, x2, x3)  =  U4(x1, x2, x3)
U5(x1, x2)  =  U5(x1, x2)
U6(x1, x2, x3)  =  U6(x1, x2, x3)

Recursive path order with status [RPO].
Quasi-Precedence:
[s1, f41in1] > [f3in1, U32] > 0 > f87out12
[s1, f41in1] > [f3in1, U32] > [f3out11, U12] > f41out12 > f87out12
[s1, f41in1] > [f3in1, U32] > U43 > f41out12 > f87out12
[s1, f41in1] > f87in1 > U52 > [f47in1, U22] > f87out12
[s1, f41in1] > f87in1 > U52 > U63 > f87out12

Status:
f3in1: multiset
0: multiset
f3out11: multiset
s1: [1]
U12: multiset
f41in1: [1]
f41out12: multiset
f47in1: [1]
U22: [1,2]
f87in1: multiset
f87out12: [1,2]
U32: multiset
U43: multiset
U52: [1,2]
U63: [1,2,3]

With this ordering the following rules can be removed by the rule removal processor [LPAR04] because they are oriented strictly:

f3_in(0) → f3_out1(0)
f3_in(s(T31)) → U1(f41_in(T31), s(T31))
U1(f41_out1(X25, T27), s(T31)) → f3_out1(T27)
f47_in(0) → f47_out1(0)
f47_in(s(T52)) → U2(f87_in(T52), s(T52))
U2(f87_out1(X70, X71), s(T52)) → f47_out1(X71)
f41_in(T31) → U3(f47_in(T31), T31)
U3(f47_out1(T33), T31) → U4(f3_in(T33), T31, T33)
U4(f3_out1(T35), T31, T33) → f41_out1(T33, T35)
f87_in(T52) → U5(f47_in(T52), T52)
U5(f47_out1(T54), T52) → U6(f47_in(T54), T52, T54)
U6(f47_out1(X71), T52, T54) → f87_out1(T54, X71)


(4) Obligation:

Q restricted rewrite system:
R is empty.
Q is empty.

(5) RisEmptyProof (EQUIVALENT transformation)

The TRS R is empty. Hence, termination is trivially proven.

(6) YES