Is it possible to make a halting function if you don't call it on itself?

白昼怎懂夜的黑 提交于 2019-12-12 14:24:57

问题


The standard proof of of the impossibility of solving the halting problem is usually something like this

//does_halt() takes a function as input and returns true if it will ever finish computing

function paradox()
    {if does_halt(paradox())
        {
          while(true){}
        }
    }        

This proof requires that you call the halting function recursively, but is it possible to make a halting function that always computes the correct result as long as it isn't called on itself?


回答1:


That proof does not require recursion. You are missing the point! You don't call paradox, but pass it like a higher order function. Take this function in Scheme and it's usage:

;; does operation passed as x to 2 and 5
(define (do2by5 x)
  (x 2 5))

;; examples    
(do2by5 +)    ; ==> 7
(do2by5 *)    ; ==> 10
(do2by5 expt) ; ==> 32

As you see I'm not applying +, * or expt in my examples. I'm just passing it as an argument. It's do2by5 that uses it. In your paradox it seems like you call paradox since you added () to the name. This is wrong since does_halt is supposed to take a function argument just like my do2by5. Here is how I would have written it in Scheme:

;; this procedure does not halt!
(define (forever)
  (forever))

(define (paradox x)
 (if (halt? paradox) ; see I'm not calling it but passing it
     (forever)
     'im-finished))

Now the real juice is of course halt? and it's of course impossible to implement and paradox is the proof you cannot make such a function.

Halting problem tvivia: What many don't get is that you can actually make halt? for finite sized code living in finite sized memory if the resources you have to investigate it is reasonable larger than the minimum machine that can hold the analyzed program. eg. As an example here is one for all 3 bytes BrainFuck programs reduced to only be Turing complete (eg. without , and .):

(define (bf3halt? x)
  (not (member x '("+[]" "-[]"))))

For a larger example you can run the program in a virtual environment hashing memory state and program counter. If you ever encounter the same memory and program counter again you have an infinite loop and can return false. (now you see the memory requirements of the halt? can be up to code size of argument times memory consumption of argument when run)




回答2:


Certainly, but you have to recall that compuation-theory is theoretical and works in infinites and physical impossibilities.

function paradox1() {
   if (does_halt(paradox2())
       return true;
   else
       return false;
}
function paradox2() {
   if (does_halt(paradox3())
       return true;
   else
       return false;
}
function paradox3() {
   if (does_halt(paradox4())
       return true;
   else
       return false;
}
function paradox4() {
   if (does_halt(paradox5())
       return true;
   else
       return false;
}
etc etc etc _infinitely_

This is a valid Turing Machine-ish program, and makes it clearer how it's impossible to tell what will happen infinitely in the future.



来源:https://stackoverflow.com/questions/24088336/is-it-possible-to-make-a-halting-function-if-you-dont-call-it-on-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!