/* File: dfa3.pl System: SWI-Prolog 5.2.8 Author: Mihaela Malita Date: 10/02/2003 Title: Print the DFA. DFA accepts words that start with a. Alphabet={a,b}, States={0,1,2} Favorable={1} start is state 0. ?- start. A DFa that accepts only words starting with a Alphabet is [a, b] States are [0, 1, 2] Start state is 0 Favorable states are 1 Transition function is: delta(0, a, 1). delta(0, b, 2). delta(1, a, 1). delta(1, b, 1). delta(2, a, 2). delta(2, b, 2). *************************************************/ % The definition of your DFA in Prolog. delta(0,a,1). delta(0,b,2). delta(1,a,1). delta(1,b,1). delta(2,a,2). delta(2,b,2). start(0). % 0 is the starting state favorable(1). % 1 is a favorable state % A state appears in the delta function as argument 1 or 3. state(I):- delta(I,_,_) ; delta(_,_,I). % Make the list of the states list_states(Res):- findall(X,state(X),L),sort(L,Res). % A letter is something that appears on the arrows between states. letter(A):- delta(_,A,_). % Collecting all the letters you find the alphabet. alphabet(Alph):- findall(X,letter(X),L),sort(L,Alph). % Print the description of the DFA start:- write('\nA DFA that accepts only words starting with a\n'), alphabet(A),write('\nAlphabet is '),write(A), list_states(Q),write('\nStates are '),write(Q), start(S),write('\nStart state is '),write(S), favorable(F),write('\nFavorable states are '),write(F), write('\nTransition function is:'),listing(delta).