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