COMPSCI 61A Lecture Notes - Currying, Cube Root
zogo39484755 and 6 others unlocked
22
COMPSCI 61A Full Course Notes
Verified Note
22 documents
Document Summary
Def square = lambda x : x * x -- > return body. ^ formal parameters square = lambda x: x*x vs def square(x) Both create function with same domain, range, behavior. Both function have as parent the environment in which defined. Function currying def curry2(f): def g(x): def h(y): return f(x, y) return h return g. Currying: transform a multiargument function into a single argument, higher-order function. Quickly find accurate approximations to zeroes of differentiable functions. Application: method for compute square root, cube root. Positive zero of f(x) = x^2 - a, = sqrt(a) (x^2 = a) Given a function f and initial guess x: Repeatedly improve x: compute value of f at guess: f(x, compute derivative of f at guess: f"(x, update guess x to: x - f(x) / f"(x) Find sqrt ( 2 ) f = lambda x: x*x - 2 --> f(x) = x^2 - 2 df = lambda x: 2x --> f"(x) = 2x.