(f)
| 1674 | # Return a 'memoized' version of the function f, which caches its |
| 1675 | # arguments and return values so as never to compute the same thing twice. |
| 1676 | def memoize(f): |
| 1677 | f_memo_tab = {} |
| 1678 | |
| 1679 | def _mem(y=None): |
| 1680 | tab_val = f_memo_tab.get(y, None) |
| 1681 | if tab_val: |
| 1682 | return tab_val |
| 1683 | |
| 1684 | fy = f(y) |
| 1685 | f_memo_tab[y] = fy |
| 1686 | return fy |
| 1687 | |
| 1688 | return _mem |
| 1689 | |
| 1690 | |
| 1691 | # Find a root by Newton's method with bounds and bisection, |