I'm new in Prolog and I was trying to solve sucha problem so i wish if anybody could help.
I want to implement a ternary predicate flatten_term(Term, Function_symbol, Flattened_term)
that succeeds if Flattened_term is obtained from Term by flattening out all
nested occurrences of Function_symbol. It is assumed that Term contains no
Prolog variables and no lists without checking the list.
?- flatten_term(f(f(x)), f, Flattened_term).
Flattened_term = f(x).
?- flatten_term(f(x), f, Flattened_term).
Flattened_term = f(x).
?- flatten_term(a, f, Flattened_term).
Flattened_term = a.
?- flatten_term(g(f(x)), f, Flattened_term).
Flattened_term = g(f(x)).
?- flatten_term(g(f(f(x))), f, Flattened_term).
Flattened_term = g(f(x)).
f(f(g(f(a))))? Or might they look likef(f(b),g(f(f(a)))? If they're single arity, you can solve your problem using a simple recursive approach. You might need to use a term processing predicate. - lurkerfmeans. One argument? Two arguments? Any number? In any case, this is not a good start. - false