f | def ADD(f, g): | f | def ADD(f, g): |
| if callable(f) and callable(g): | | if callable(f) and callable(g): |
n | def NEWADD(x): | n | def f1(x): |
| return f(x) + g(x) | | return f(x) + g(x) |
n | return NEWADD | n | return f1 |
| elif callable(f): | | elif callable(f): |
n | def NEWADD(x): | n | def f2(x): |
| return f(x) + g | | return f(x) + g |
n | return NEWADD | n | return f2 |
| elif callable(g): | | elif callable(g): |
n | def NEWADD(x): | n | def f3(x): |
| return f + g(x) | | return f + g(x) |
n | return NEWADD | n | return f3 |
| else: | | else: |
n | def NEWADD(x): | n | def f4(x): |
| return f + g | | return f + g |
n | return NEWADD | n | return f4 |
| | | |
| | | |
| def SUB(f, g): | | def SUB(f, g): |
| if callable(f) and callable(g): | | if callable(f) and callable(g): |
n | def NEWSUB(x): | n | def f1(x): |
| return f(x) - g(x) | | return f(x) - g(x) |
n | return NEWSUB | n | return f1 |
| elif callable(f): | | elif callable(f): |
n | def NEWSUB(x): | n | def f2(x): |
| return f(x) - g | | return f(x) - g |
n | return NEWSUB | n | return f2 |
| elif callable(g): | | elif callable(g): |
n | def NEWSUB(x): | n | def f3(x): |
| return f - g(x) | | return f - g(x) |
n | return NEWSUB | n | return f3 |
| else: | | else: |
n | def NEWSUB(x): | n | def f4(x): |
| return f - g | | return f - g |
n | return NEWSUB | n | return f4 |
| | | |
| | | |
| def MUL(f, g): | | def MUL(f, g): |
| if callable(f) and callable(g): | | if callable(f) and callable(g): |
n | def NEWMUL(x): | n | def f1(x): |
| return f(x) * g(x) | | return f(x) * g(x) |
n | return NEWMUL | n | return f1 |
| elif callable(f): | | elif callable(f): |
n | def NEWMUL(x): | n | def f2(x): |
| return f(x) * g | | return f(x) * g |
n | return NEWMUL | n | return f2 |
| elif callable(g): | | elif callable(g): |
n | def NEWMUL(x): | n | def f3(x): |
| return f * g(x) | | return f * g(x) |
n | return NEWMUL | n | return f3 |
| else: | | else: |
n | def NEWMUL(x): | n | def f4(x): |
| return f * g | | return f * g |
n | return NEWMUL | n | return f4 |
| | | |
| | | |
| def DIV(f, g): | | def DIV(f, g): |
| if callable(f) and callable(g): | | if callable(f) and callable(g): |
n | def NEWDIV(x): | n | def f1(x): |
| return f(x) / g(x) | | return f(x) / g(x) |
n | return NEWDIV | n | return f1 |
| elif callable(f): | | elif callable(f): |
n | def NEWDIV(x): | n | def f2(x): |
| return f(x) / g | | return f(x) / g |
n | return NEWDIV | n | return f2 |
| elif callable(g): | | elif callable(g): |
n | def NEWDIV(x): | n | def f3(x): |
| return f / g(x) | | return f / g(x) |
n | return NEWDIV | n | return f3 |
| else: | | else: |
n | def NEWMUL(x): | n | def f4(x): |
| return f / g | | return f / g |
n | return NEWMUL | n | return f4 |
| | | |
t | | t | |
| | | '''from math import * |
| | | |
| | | 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)))''' |
| | | |