I am learning Turing machine in automata. Following problem might be simple, as that's the first question on Turing machines in my textbook, however I am not sure if I am doing it efficiently.
Give Turing machine with input alphabet {a} that on input $a^m$ halts with $a^{m^2}$ written on its tape.
My approach: The machine will first move right seeing an a on each position on tape. So there will be $m+1$ states $q_0$ to $q_m$ defined, on which the machine will move sequentially seeing an $a$. If machine meets the end of the string seeing an empty position at state $q_m$, it will move left $\sqrt{m}$ times, and halt.
The problems,
- $m$ is not given here, so m can be anything, $1,4,9,25,..$, infinite possibilities. How many states shall I define then?
- As the Turing machine can not calculate $\sqrt{m}$, I am defining newer states like $q_{41},q_{42}$ etc (If the Turing machine sees end of string at state $q_4$, then it moves left to state $q_{41}$, then to $q_{42}$, then it halts). This way also, many numbers of states to be defined, as $\sqrt{m}$ increases with $m$. So my transition table is becoming huge and infinite.
Can someone suggest a better way to define this Turing machine?