REGULARTM is defined as below:
REGULARTM ={〈M〉| M is a TM and L(M)is a regular language}.
I am trying to understand the proof of REGULARTM being undecidable from Sipser's book "Introduction to the Theory of Computation". The book says:
We let R to be a TM that decides REGULARTM and construct TM S to decide ATM. Then S works in the following manner.
S = “On input〈M,w〉, where M is a TM and w is a string:
1.Construct the following TM M2.
M2=“On input x:
1.If x has the form 0^n1^n,accept.
2.If x does not have this form, run M on input w and accept if M.”
2.Run R on input〈M2〉.
3.If R accepts,accept; if R rejects,reject.”
The problem that I am facing is in the 2nd substep of the 1st step which says:
If x does not have this form, run M on input w and accept if M.
What if M does not halt on w? Then the decider S that we are building would not halt.