Sunday, November 23, 2014

Will A Function Halt? (Week 10 sLOG)

In this week’s lecture, we have finished discussing about Big-O and Big-Omega, and started talking about wether a function is computable or not. The way we know if method will run or not is kind of interesting, we create another method to test if the function is computable.
With the method we talked about in class, halt(f, i), it’s the first time I have ever seen a method inside a method.

def initialized(g, v):
''' return True if g initialize v on every possible input'''
…

def halt(f, i):
      def f2(x):
            del (x)
            print(x)
      return not initialized(f2, x)


Basically, in these two methods, it tests if a given input is computable in a function. In the method, f2, after inputing the value x, it will delete the value, and since x is not defined anymore,  when it call ‘print(x)’, it will create an error and not able to print the value. Then initialized(f2, x) will return False since x is not defined, and the negation of False is True, so the method halt(f, i) will return True, meaning the function will stop running. I found that this is an interesting idea to test a function in a method, and negate the result. 

No comments:

Post a Comment