%%% erem.pl
%%%
%%% Testing a solution to Uebung 2

%%% Removing empty transitions:

eremove( Aut0, Aut ):-
        setof( (Q1,S,Q2),
               e_reachable_s_trans(Aut0,Q1,S,Q2),
               NewDelta ),
        new_tag( Aut ),
        start( Aut0, Start ),
        assert( start(Aut,Start) ),
        finals( Aut0, Finals ),
        setof( Q, 
               e_reachable_final(Aut0,Q,Finals), 
               NewFs ),
        assert( finals(Aut,NewFs) ),
        assert_loop( NewDelta, Aut ),
        maxstate( Aut0, Max0 ),
        assert( maxstate(Aut,Max0) ).

e_reachable_s_trans( Aut, Q1, S, Q2 ):-
        etrans_star( Aut, Q1, Q3 ),
        ( Aut :: Q3, S , Q2 ),
        \+ S = [].

e_reachable_final( Aut, Q, Finals ):-
        etrans_star( Aut, Q, Qf ),
        member( Qf, Finals ).

etrans_star( _Aut, Q, Q ).
etrans_star( Aut, Q0, Q ):-
        empty_trans( Aut, Q0, Q1 ),
        etrans_star( Aut, Q1, Q ).

empty_trans( Aut, Q1, Q2 ):-
        ( Aut :: Q1, [] , Q2 ).



