CS2333/Assignment 7.ipynb

136 lines
3.5 KiB
Plaintext
Raw Normal View History

2024-04-06 23:15:11 -03:00
{
"cells": [
{
"cell_type": "markdown",
"id": "a90ef9f8022df10e",
"metadata": {
"collapsed": false
},
"source": [
"# Question 42\n",
"## c.\n",
"$$S \\rightarrow 0S0 | 0S1 | 1S0 | 1S1 | 1$$\n",
"\n",
"## d.\n",
"$$S \\rightarrow X | \\epsilon$$\n",
"$$X \\rightarrow aXdd | Y$$\n",
"$$Y \\rightarrow bYd | Z$$\n",
"$$Z \\rightarrow cZ | \\epsilon$$\n",
"\n",
"## e.\n",
"$$S \\rightarrow 0S | 1S | 00S | 01S | 10S | 11S | 000S | 001S | 010S | 011S| 100S | 101S | 111S | \\epsilon$$"
]
},
{
"cell_type": "markdown",
"id": "2d1690ef",
"metadata": {},
"source": [
"$\\pagebreak$"
]
},
{
"cell_type": "markdown",
"id": "9a7c595f",
"metadata": {},
"source": [
"# Question 43\n",
"## a.\n",
"$$B = \\{ w \\in \\{a, b, c\\}^* | |w| = 4n+1, n \\in \\mathbb{Z}^{\\text{nonneg}} \\}$$\n",
"\n",
"## b.\n",
"$$B = \\{ 0^2x1^3y+2 | x, y \\in \\mathbb{Z}^{\\text{nonneg}} \\}$$\n",
"\n",
"## c.\n",
"$$B = \\{ 0^x1^y | x \\neq y \\text{ and } x, y \\in \\mathbb{Z}^{\\text{nonneg}} \\}$$"
]
},
{
"cell_type": "markdown",
"id": "c8d0ce5a",
"metadata": {},
"source": [
"$\\pagebreak$"
]
},
{
"cell_type": "markdown",
"id": "8d439d76",
"metadata": {},
"source": [
"# Question 44\n",
"## a.\n",
"$$B = \\{ 0^x1^y | y = x + 1 \\text{ and } x, y \\in \\mathbb{Z}^{\\text{nonneg}} \\}$$\n",
"\n",
"## c.\n",
"$$B = \\{ 0^x1^y | y = 3x \\text{ and } x, y \\in \\mathbb{Z}^{\\text{nonneg}} \\}$$"
]
},
{
"cell_type": "markdown",
"id": "323bea35",
"metadata": {},
"source": [
"$\\pagebreak$"
]
},
{
"cell_type": "markdown",
"id": "56466c7f",
"metadata": {},
"source": [
"# Question 45\n",
"1. First the machine should move left to right looking for a \"b\". If it does not find one it moves to the reject state and if it finds one it will:\n",
" - Erase the \"b\"\n",
" - Move back to the start\n",
" - Look for an \"a\". If it finds one it will repeat step 1. If it does not find one, it will move to the accept state"
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "$\\pagebreak$",
"id": "e9fba2ef63041f08"
},
{
"metadata": {},
"cell_type": "markdown",
"source": [
"# Question 47\n",
"1. First the machine should check if the length of the string is at least 6 and if not, reject\n",
"2. Copy 0 or more symbols to tape 2 from tape 1\n",
"3. Erase all of tape 2\n",
"4. Copy 3 symbols to tape 2 from tape 1\n",
"5. Copy 0 or more symbols to tape 3 from tape 1\n",
"6. Erase of all of tape 3\n",
"7. Copy 3 symbols to tape 3 from tape 1\n",
"8. Compare tapes 2 and 3 and if they match, accept, otherwise reject\n",
"\n",
"The nondeterminism of this machine is the copying 0 or more symbols, as this accounts for strings u and x, as they can be any length including 0, and the machine can make a choice of 0 or more."
],
"id": "7b6c771c1004546f"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}