:- use_module(library(lists),[member/2]).

:- dynamic symbol/1.

alphabet :-
        retractall(symbol(_)),
        assert_symbols.

assert_symbols :- 
        function_symbol(F/N),
        functor(Template,F,N),
        (   symbol(Template) 
        ->  true;
            assert(symbol(Template))
        ),
        fail.
assert_symbols.


function_symbol(F/N) :-
    my_clause(H,B),
    member(Atom,[H|B]),
    Atom =.. [_PredicateSymbol|Args],
    member(Arg,Args),
    subterm(T,Arg),
    nonvar(T),
    functor(T,F,N).

subterm(Term,Term).
subterm(Sub,Term) :- 
    nonvar(Term),
    Term =.. [_FunctionSymbol|Args],
    member(Arg,Args),
    subterm(Sub,Arg).



