Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to know if two python functions are functionally equivalent?

Let's say I have two python functions f and g:

def f(x):
    y = x**2 + 1
    return y

def g(x):
    a = x**2
    b = a + 1
    return b

These two functions are clearly functionally equivalent (both return x**2 + 1).

My definition of functionally equivalent is as follows:

If two functions f and g always produce the same output given the same input, then f and g are functionally equivalent.

Further, let's say no global variables are involved in f and g.

Is it possible to automatically determine (without human inspection) if python functions f and g are functionally equivalent?

like image 678
applecider Avatar asked Apr 25 '16 23:04

applecider


People also ask

Can you define two functions in Python?

We define two functions. The first function prints the module documentation string. The second returns the path of the module. Function may or may not return a value.

How do you identify a function in Python?

Basic Syntax for Defining a Function in Python In Python, you define a function with the def keyword, then write the function identifier (name) followed by parentheses and a colon. The next thing you have to do is make sure you indent with a tab or 4 spaces, and then specify what you want the function to do for you.

What does check function do in Python?

all functionIt returns True if all boolean values are True in the sequence; otherwise, it returns False .


1 Answers

By Rice's Theorem, no. If you could do this, you could solve the halting problem. (This is true even if f and g are always guaranteed to halt.)

like image 164
user2357112 supports Monica Avatar answered Oct 21 '22 05:10

user2357112 supports Monica