From 8a26a61b6f1aea0307ba3ad7b8ecf4ae56369d40 Mon Sep 17 00:00:00 2001 From: pingu Date: Mon, 8 Dec 2025 15:21:50 +0100 Subject: [PATCH] Ow --- 3or4or6/6.org | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 3or4or6/6.org diff --git a/3or4or6/6.org b/3or4or6/6.org new file mode 100644 index 0000000..bc81647 --- /dev/null +++ b/3or4or6/6.org @@ -0,0 +1,64 @@ +#+title: Assignment 6 +#+options: toc:nil +#+latex_header: \usepackage{parskip} +#+latex_header: \usepackage{stmaryrd} +#+latex_header: \usepackage{bussproofs} + +In order to pass this assignment you have to get at least two points. + +* (2p) +The following string represents a Turing machine, using the encoding presented in the lectures: + +\[ 1001100 1 0 10 10 10 1 1 0 110 10 110 1 1 10 10 0 0 1 1 10 110 0 0 1 0 \] + +The following string is an encoding, using the encoding presented in the lectures, of some input to the Turing machine: + +\[ 110110111011011100 \] + +What Turing machine and what input do the strings represent? And what is the result of running the Turing machine with the given input? + +** Answer + +The Turing machine is the one described by the following: + +- States: $S = \{ s_0, s_1 \}$ +- Initial state: $s_0$ +- Input alphabet: $\{c_1,c_2\}$ +- Tape alphabet: $\{\text{\textvisiblespace}},c_1,c_2\}$ +- Transition function: + + $\delta (s_0, c_1) = (s_1,c_1,R)$ + + $\delta (s_0, c_2) = (s_1,c_2,R)$ + + $\delta (s_1, c_1) = (s_0,\text{\textvisiblespace},R)$ + + $\delta (s_1, c_2) = (s_0,\text{\textvisiblespace},R)$ + +Running the machine on the given input, results in erasing every other character. + +* (2p) + +Implement a Turing machine interpreter using $\chi$. + +The interpreter should be a closed $\chi$ expression. If we denote this expression by run, then it should satisfy the following property (but you do not have to prove that it does): ++ For every Turing machine tm and input string $xs \in \text{List}\ \{0, 1\}$ the following equation should hold: + \[ \llbracket \text{apply}\ (\text{apply}\ \text{\textit{run}}\ \ulcorner \text{tm} \urcorner) \ulcorner xs \urcorner \rrbracket = \ulcorner \llbracket \text{tm} \rrbracket \text{xs} \urcorner \] +(The $\llbracket \_ \rrbracket$ brackets to the left stand for the $\chi$ semantics, and the $\llbracket \_ \rrbracket$ brackets to the right stand for the Turing machine semantics.) + +Turing machines should be represented in the following way: ++ States are represented as natural numbers, represented in the usual way. ++ The set of states is not represented explicitly, but defined implicitly by the states that are mentioned in the definition. ++ The input alphabet is $\{0, 1\}$, with $0$ represented by $Zero()$ and $1$ by $Suc(Zero())$. ++ The tape alphabet is not represented explicitly, but contains the blank character ($Blank()$), 0, 1 and a finite number of other natural numbers (represented in the usual way). ++ The transition function is specified by a list of rules (using the usual list constructors). Each rule has the form $Rule(s_1, x_1, s_2, x_2, d)$, where $s_1$ and $s_2$ are states, $x_1$ and $x_2$ are tape alphabet symbols, and $d$ is a direction (left is represented by $L()$ and right by $R()$). ++ For a given state $s_1$ and symbol $x_1$ there must be at most one rule with $s_1$ as the first component and $x_1$ as the second component. Furthermore the list of rules must be sorted lexicographically based on these two components: entries with smaller states must precede entries with larger states, and entries with equal states must be sorted based on the symbols (with blanks sorted before the natural numbers). ++ The value of the transition function for a given state $s$ and symbol $x$ is given by the rule with $s = s_1$ and $x = x_1$, if any: if there is no such rule, then the transition function is undefined for the given input. If there is a matching rule $Rule(s_1, x_1, s_2, x_2, d)$, then the new state is $s_2$, the symbol written is $x_2$, and the head is moved in the direction $d$ (if possible). ++ Finally a Turing machine is represented by $TM(s_0, \delta)$, where $s_0$ is the initial state and $\delta$ is the transition function. + +The input and output strings should use the usual representation of lists, with the representation specified above for the input and tape symbols. + +Please test that addition, implemented as in Tutorial 5, Exercise 6 (with 0 instead of #), works as it should when run on your Turing machine interpreter. A testing procedure that you can use is included in the wrapper module (documentation). + +** Answer + +* (2p) +Prove that every Turing-computable partial function in $\mathbb{N} \rightharpoonup \mathbb{N}$ is also $\chi$ computable. You can assume that the definition of “Turing-computable” uses Turing machines of the kind used in the previous exercise. + +Hint: Use the interpreter from the previous exercise. Do not forget to convert the input and output to the right formats.