(0) Obligation:

Clauses:

countstack(empty, 0).
countstack(S, X) :- ','(no(empty_stack(S)), ','(pop(S, nil), ','(popped(S, Pd), countstack(Pd, X)))).
countstack(S, s(X)) :- ','(no(empty_stack(S)), ','(pop(S, P), ','(no(empty_list(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).
empty_stack(empty).
empty_list(nil).
no(X) :- ','(X, ','(!, failure(a))).
no(X7).
failure(b).

Queries:

countstack(g,a).

(1) CutEliminatorProof (SOUND transformation)

Eliminated all cuts by simply ignoring them[PROLOG].

(2) Obligation:

Clauses:

countstack(empty, 0).
countstack(S, X) :- ','(no(empty_stack(S)), ','(pop(S, nil), ','(popped(S, Pd), countstack(Pd, X)))).
countstack(S, s(X)) :- ','(no(empty_stack(S)), ','(pop(S, P), ','(no(empty_list(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).
empty_stack(empty).
empty_list(nil).
no(X) :- ','(X, failure(a)).
no(X7).
failure(b).

Queries:

countstack(g,a).