----------------------------------------------- lines 31-166 of file: introduction/exp_eps.xrst ----------------------------------------------- {xrst_begin exp_eps_for0} exp_eps: Operation Sequence and Zero Order Forward Sweep ######################################################## Mathematical Form ***************** Suppose that we use the algorithm :ref:`exp_eps.hpp-name` to compute ``exp_eps`` ( *x* , *epsilon* ) with *x* is equal to .5 and *epsilon* is equal to .2. For this case, the mathematical form for the operation sequence corresponding to the ``exp_eps`` is .. math:: f( x , \varepsilon ) = 1 + x + x^2 / 2 Note that, for these particular values of *x* and *epsilon* , this is the same as the mathematical form for :ref:`exp_2` . Operation Sequence ****************** We consider the :ref:`operation sequence` corresponding to the algorithm :ref:`exp_eps.hpp-name` with the argument *x* is equal to .5 and *epsilon* is equal to .2. Variable ======== We refer to values that depend on the input variables *x* and *epsilon* as variables. Parameter ========= We refer to values that do not depend on the input variables *x* or *epsilon* as parameters. Operations where the result is a parameter are not included in the zero order sweep below. Index ===== The Index column contains the index in the operation sequence of the corresponding atomic operation and variable. A Forward sweep starts with the first operation and ends with the last. Code ==== The Code column contains the C++ source code corresponding to the corresponding atomic operation in the sequence. Operation ========= The Operation column contains the mathematical function corresponding to each atomic operation in the sequence. Zero Order ========== The Zero Order column contains the :ref:`zero order derivative` for the corresponding variable in the operation sequence. Forward mode refers to the fact that these coefficients are computed in the same order as the original algorithm; i.e., in order of increasing index. Sweep ===== .. csv-table:: :widths: auto **Index**,,**Code**,,**Operation**,,**Zero Order** 1,,``abs_x = x;``,,:math:`v_1 = x`,,:math:`v_1^{(0)} = 0.5` 2,,``temp = term * abs_x;``,,:math:`v_2 = 1 * v_1`,,:math:`v_2^{(0)} = 0.5` 3,,``term = temp / Type(k);``,,:math:`v_3 = v_2 / 1`,,:math:`v_3^{(0)} = 0.5` 4,,``sum = sum + term;``,,:math:`v_4 = 1 + v_3`,,:math:`v_4^{(0)} = 1.5` 5,,``temp = term * abs_x;``,,:math:`v_5 = v_3 * v_1`,,:math:`v_5^{(0)} = 0.25` 6,,``term = temp / Type(k);``,,:math:`v_6 = v_5 / 2`,,:math:`v_6^{(0)} = 0.125` 7,,``sum = sum + term;``,,:math:`v_7 = v_4 + v_6`,,:math:`v_7^{(0)} = 1.625` Return Value ************ The return value for this case is .. math:: 1.625 = v_7^{(0)} = f ( x^{(0)} , \varepsilon^{(0)} ) Comparisons *********** If *x* were negative, or if *epsilon* were a much smaller or much larger value, the results of the following comparisons could be different: :: if( Type(0) > x ) while(term > epsilon) This in turn would result in a different operation sequence. Thus the operation sequence above only corresponds to :ref:`exp_eps.hpp-name` for values of *x* and *epsilon* within a certain range. Note that there is a neighborhood of :math:`x = 0.5` for which the comparisons would have the same result and hence the operation sequence would be the same. {xrst_toc_hidden introduction/exp_eps_for0.cpp } Verification ************ The file :ref:`exp_eps_for0.cpp-name` contains a routine that verifies the values computed above. Exercises ********* #. Suppose that :math:`x^{(0)} = .1`, what is the result of a zero order forward sweep for the operation sequence above; i.e., what are the corresponding values for :math:`v_1^{(0)} , v_2^{(0)} , \ldots , v_7^{(0)}`. #. Create a modified version of :ref:`exp_eps_for0.cpp-name` that verifies the values you obtained for the previous exercise. #. Create and run a main program that reports the result of calling the modified version of :ref:`exp_eps_for0.cpp-name` in the previous exercise. {xrst_end exp_eps_for0}