f | from math import * | f | from math import * |
| | | |
| | | |
| def ADD(f, g): | | def ADD(f, g): |
n | def foo(i): | n | def foo(x): |
| if callable(f): | | if callable(f): |
n | a = f(i) | n | temp1 = f(x) |
| else: | | else: |
n | a = f | n | temp1 = f |
| if callable(g): | | if callable(g): |
n | b = g(i) | n | temp2 = g(x) |
| else: | | else: |
n | b = g | n | temp2 = g |
| return a + b | | return temp1 + temp2 |
| return foo | | return foo |
| | | |
| | | |
| def SUB(f, g): | | def SUB(f, g): |
n | def foo(i): | n | def foo(x): |
| if callable(f): | | if callable(f): |
n | a = f(i) | n | temp1 = f(x) |
| else: | | else: |
n | a = f | n | temp1 = f |
| if callable(g): | | if callable(g): |
n | b = g(i) | n | temp2 = g(x) |
| else: | | else: |
n | b = g | n | temp2 = g |
| return a - b | | return temp1 - temp2 |
| return foo | | return foo |
| | | |
| | | |
| def MUL(f, g): | | def MUL(f, g): |
n | def foo(i): | n | def foo(x): |
| if callable(f): | | if callable(f): |
n | a = f(i) | n | temp1 = f(x) |
| else: | | else: |
n | a = f | n | temp1 = f |
| if callable(g): | | if callable(g): |
n | b = g(i) | n | temp2 = g(x) |
| else: | | else: |
n | b = g | n | temp2 = g |
| return a * b | | return temp1 * temp2 |
| return foo | | return foo |
| | | |
| | | |
| def DIV(f, g): | | def DIV(f, g): |
n | def foo(i): | n | def foo(x): |
| if callable(f): | | if callable(f): |
n | a = f(i) | n | temp1 = f(x) |
| else: | | else: |
n | a = f | n | temp1 = f |
| if callable(g): | | if callable(g): |
n | b = g(i) | n | temp2 = g(x) |
| else: | | else: |
n | b = g | n | temp2 = g |
| return a / b | | return temp1 / temp2 |
| return foo | | return foo |
| | | |
t | | t | |
| | | #f = SUB(sin, cos) |
| | | #print(f(12), sin(12)-cos(12)) |
| | | |
| | | #g = DIV(sin, cos) |
| | | #print(g(pi/6), tan(pi/6)) |
| | | |
| | | #h = MUL(exp, 0.1) |
| | | #print(h(2), e**2/10) |
| | | |
| | | #t = ADD(lambda s: len(s), sum) |
| | | # print(t(range(5))) |
| | | |