(0) Obligation:

Clauses:

countstack(empty, X) :- ','(!, eq(X, 0)).
countstack(S, X) :- ','(pop(S, nil), ','(!, ','(popped(S, Pd), countstack(Pd, X)))).
countstack(S, s(X)) :- ','(pop(S, P), ','(head(P, H), ','(tail(P, T), ','(popped(S, Pd), countstack(push(H, push(T, Pd)), X))))).
pop(empty, X1).
pop(push(P, X2), P).
popped(empty, empty).
popped(push(X3, Pd), Pd).
head(nil, X4).
head(cons(H, X5), H).
tail(nil, nil).
tail(cons(X6, T), T).
eq(X, X).

Query: countstack(g,a)

(1) PrologDeterminacyProcessorProof (EQUIVALENT transformation)

The root node satisfies the determinacy criterion.

(2) YES