## 1.7 Practical Session

We will start out with a couple of simple keyboard exercises so make sure that you understand how the Prolog programs that we saw in this section work.

1. Start Prolog and consult `recognise1.pl`, `recognise2.pl`, and `haha1.pl`. Using both `test1` (which calls `recognise1`) and `test2` (which calls `recognise2`) see whether various strings are accepted e.g

`    test1([h,a,!]).    test2([h,a,!]).    test1([h,a,h,a,h,a,!]).`

Make sure you understand why these strings are accepted. That is, use trace to step through the execution so that you understand exactly what is going on.

2. Restart Prolog and consult `recognize1.pl`, `recognize1.pl`, and `haha5.pl`. The difference between `haha1` and `haha5` is that `haha5` is not deterministic. Try giving the following queries.

`    test1([h,a,!]).    test2([h,a,!]).    test1([h,a,h,a,h,a,!]).`

Make sure you understand why these strings are accepted. That is, use trace to step through the execution so that you understand exactly what is going on.

3. Now restart Prolog and consult `recognize1.pl`, `recognize2.pl`, and `haha2.pl`. The big difference between `haha1` and `haha2` is that `haha2` contains a jump arc `#`. Now, `recognizer1` does not handle jump arcs so it should not be able to handle `haha2` correctly. Try out the following experiments, and make sure you understand why recognize1 gives the responses it gives:

`| ?- test1([h,a,!]). yes | ?- test1([h,a,h,a,!]). no | ?- test1([h,a,h,a,h,a,!]). no`

Now try these examples with `test2`. Again, carry out traces. Try using `generate1` to generate using `haha2`. Now try using `generate2` with `haha2`. Why does `generate1` give a wrong response?

4. Finally, make sure that you understand how the generate predicates are defined. In particular, make sure you understand what the `fail' in the generate3 predicates does.

Now, you are able to write your own automata. You can then use the `recognize` and `generate` predicates to test them. So, here is a task which is a bit more interesting: Write an FSA (First, as a graph and, then, in Prolog notation!) that recognizes English noun phrases constructed from the following words: a, the, witch, wizard, Harry, Ron, Hermione, broomstick, brave, fast, with, rat. E.g.

• the brave wizard

• the fast broomstick

• the wizard with the rat

• Ron

• ...

Patrick Blackburn and Kristina Striegnitz
Version 1.2.4 (20020829)