2 | | For many applications such as numerical integration, differential equation |
3 | | approximation, plotting a 3d surface, optimization problems, monte-carlo |
4 | | simulations, etc. one wishes to pass around and evaluate a single algebraic |
5 | | many, many times at various floating point values. Doing this via recursive |
6 | | calls over a python representation of the object (even if maxima or other |
7 | | outside packages are not involved) is extremely inefficient. |
| 2 | Fast Numerical Evaluation. |
9 | | Up until now the solution has been to use lambda expressions, but this is neither |
10 | | intuitive, Sage-like, nor efficient (compared to operating on raw c doubles). |
11 | | This module provides a representation of algebraic expression in Reverse |
12 | | Polish Notation, and provides an efficient interpreter on c double values |
13 | | as a callable python object. It does what it can in C, and will call out |
14 | | to Python if necessary. |
| 4 | For many applications such as numerical integration, differential |
| 5 | equation approximation, plotting a 3d surface, optimization problems, |
| 6 | monte-carlo simulations, etc., one wishes to pass around and evaluate |
| 7 | a single algebraic expression many, many times at various floating |
| 8 | point values. Doing this via recursive calls over a python |
| 9 | representation of the object (even if maxima or other outside packages |
| 10 | are not involved) is extremely inefficient. |
16 | | Essential to the understanding of this class is the distinction between |
17 | | symbolic expressions and callable symbolic expressions (where the later |
18 | | binds argument names to argument positions). The \code{*vars} parameter |
19 | | passed around encapsulates this information. |
| 12 | Up until now the solution has been to use lambda expressions, but this |
| 13 | is neither intuitive, Sage-like, nor efficient (compared to operating |
| 14 | on raw C doubles). This module provides a representation of algebraic |
| 15 | expression in Reverse Polish Notation, and provides an efficient |
| 16 | interpreter on C double values as a callable python object. It does |
| 17 | what it can in C, and will call out to Python if necessary. |
| 18 | |
| 19 | Essential to the understanding of this class is the distinction |
| 20 | between symbolic expressions and callable symbolic expressions (where |
| 21 | the later binds argument names to argument positions). The |
| 22 | \code{*vars} parameter passed around encapsulates this information. |
24 | | To provide this interface for a class, implement \code{_fast_float_(self, *vars)}. |
25 | | The basic building blocks are provided by the functions \code{fast_float_constant} |
26 | | (returns a constant function), \code{fast_float_arg} (selects the $n$-th |
27 | | value when called with $\ge n$ arguments), and \code{fast_float_func} which |
28 | | wraps a callable Python function. These may be combined with the standard |
29 | | Python arithmatic operators, and support many of the basic math functions |
30 | | such sqrt, exp, and trig functions. |
| 27 | To provide this interface for a class, implement |
| 28 | \code{_fast_float_(self, *vars)}. The basic building blocks are |
| 29 | provided by the functions \code{fast_float_constant} (returns a |
| 30 | constant function), \code{fast_float_arg} (selects the $n$-th value |
| 31 | when called with $\ge n$ arguments), and \code{fast_float_func} which |
| 32 | wraps a callable Python function. These may be combined with the |
| 33 | standard Python arithmetic operators, and support many of the basic |
| 34 | math functions such sqrt, exp, and trig functions. |