CS154
Chris Pollett
Apr. 3, 2013
Here is a machine which when started with a string `w` on the tape halts with `w\square w` on the tape.
`q_{mbox{start}}bcd`
`q_{mbox{done L rewind}}\square bcd`
`\square q_{mbox{done R}}bcd`
`\square q_{mbox{read }b mbox{ wrote space}} cd`
`\square \square cd \square q_{mbox{right two spaces wrote b}} b`
`\square q_{mbox{left two spaces wrote b}}bcd \square b`
`\square b q_{mbox{done R}}cd \square b`
`\square b q_{mbox{read }c mbox{ wrote space}}\square d \square b`
`\square b \square d \square b q_{mbox{right two spaces wrote c}}c`
`\square b q_{mbox{left two spaces wrote c}}c d \square b c`
`\square b c q_{mbox{read }d mbox{ wrote space}} \square \square b c`
`\square b c\square \square b c q_{mbox{right two spaces wrote d}}d `
`\square b cq_{mbox{left two spaces wrote d}} d \square b c d `
`\square b c d q_{mbox{done R}} \square b c d `
`\square b c d \square b c d q_{mbox{done advance right space and halted}} \square`
Problem 1. Show step-by-step how the string 0001010001 would be compressed by the SEQUITUR algorithm.
Answer. The following table shows the state of `mbox(Aux)` and the productions table after each letter is read:
Letter | `mbox(Aux)` | Production Table | `mbox(Hash)` |
---|---|---|---|
0 | 0 | `{}` | `{}` |
0 | 00 | `{}` | `{00}` |
0 | 000 becomes 0A | `{A->00}` | {0A} |
1 | 0A1 | `{A->00}` | `{0A, A1}` |
0 | 0A10 | `{A->00}` | `{0A, A1, 10}` |
1 | 0A101 | `{A->00}` | `{0A, A1, 10, 01}` |
0 | 0A1010 becomes 0ABB | `{A->00, B->10}` | `{0A, \B\B}` |
0 | 0ABB0 | `{A->00, B->10}` | `{0A, \B\B, \B0}` |
0 | 0ABB00 becomes 0ABBA | `{A->00` marked, `B->10}` | `{0A, \B\B, \B\A}` |
1 | 0ABBA1 | `{A->00` marked, `B->10}` | `{0A, \B\B, \B\A, A1}` |
We next remove any rule used only once (an unmarked rule), and add a rule `S -> mbox(Aux)`. This gives the grammar. `{S->0A0101A1, A->00}`. This could be represented as the string R\0\0R\0#0\0\1\0\1#0\1.
Problem 2. Draw a PDA for the language L over `{0,1}` consisting of strings with an equal number of 0's and 1's. So 010011 would be in this language. Next draw a DFA recognizing `0^\star1^\star`. Use the algorithm from class to draw a PDA for the intersection of these two languages.
Here is an image of the relevant diagrams and resulting construction: