Can an algorithm analyze the behaviour of a function and say if another function does exactly the same?

StackOverflow https://stackoverflow.com/questions/23487045

  •  16-07-2023
  •  | 
  •  

Can an algorithm analyze the behaviour of a function and say if another function does exactly the same? For example, I have a function that clean input data but I need to know if another function does the same thing in another way, using different code.

There exist such algorithm? Is this an undecidable problem?

有帮助吗?

解决方案

Yes, it is undecideable.

The reduction is simple, given an instance of halting problem (f,x) build a new function f' that does not stop for x. Produce (f,f',x) as input to the new algorithm.

Intuitively, if such a machine exists, you just solved halting problem because you'll be able to detect that f and f' have the same behavior, but you know that f' is in an infinite loop, so - so does f.

As a side note, if you are looking for an algorithm that checks ALL inputs, and not a single input - this is even harder, and this problem is not even in RE

其他提示

It is indeed undecidable.

It's at least as difficult as the halting problem.

Given the description of an arbitrary program and a finite input, decide whether the program finishes running or will run forever.

Part of determining whether 2 functions do the same for any given input would be to determine whether both actually halt for their respective inputs.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top