/******************************************************** File: dfa0.pl System: SWI-Prolog 5.2.8 Author: Mihaela Malita Date: 10/02/2003 Title: Describe a DFA that accepts words that start with a. Alphabet={a,b}, States={0,1,2} Favorable={1} start is state 0. 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 First load the file from folder C:/swimm ?- ['C://swimm/dfa0.pl']. Yes List facts from your file (except comments). ?- listing. favorable(1). start(0). delta(0, a, 1). delta(0, b, 2). delta(1, a, 1). delta(1, b, 1). delta(2, a, 2). delta(2, b, 2). What is the start state? ?- start(S). S=0 Yes What is/are the favorable state(s)/ ?- favorable(F). F=1 How does delta/3 look like (your transition function)? ?- delta(X,Let,Y). X = 0 Let = a Y = 1 ; % YOU type ; for more solutions X = 0 Let = b Y = 2 ; X = 1 Let = a Y = 1 % You type and it does not look for more Yes Is there any state that has a loop on itself? ?- delta(S,_,S). S = 1 % You type Yes Is the start state also favorable? ?- start(X),favorable(X). No For a certain state print all the arrows that go out. ?- delta(0,X,Q). ?- delta(0,X,Q). X = a Q = 1 ; % You type ; X = b Q = 2 ; % You type ; It is a request for MORE No % it means "I" cannot find MORE For a certain state print all the states where you can go from it. ?- delta(0,_,X). X = 1 ; % You type ; asking for MORE X = 2 ; No Find the alphabet. ?- delta(_,X,_). X = a ; X = b ; No ?- delta(0,X,Q),write([X,Q]),fail. [a, 1][b, 2] No *************************************************/ /* This is 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). favorable(1).