Last change on this file since 3320 was 3320, checked in by bradbell, 6 years ago

these warnings, so supress then in these cases.

1. Move check that arguments come before result into on place,

CPPAD_ASSERT_ARG_BEFORE_RESULT (only one argument case so far).

main.cpp: fix shadowing of index variable.
CMakeLists.txt: adapt to change in teuchos library name.
check_svn_id.sh: ignore svn_commit.sh.

• Property svn:keywords set to `Id`
File size: 42.6 KB
Line
1/* \$Id: prototype_op.hpp 3320 2014-09-11 23:06:21Z bradbell \$ */
4
5/* --------------------------------------------------------------------------
7
9the terms of the
10                    Eclipse Public License Version 1.0.
11
12A copy of this license is included in the COPYING file of this distribution.
14-------------------------------------------------------------------------- */
15
16
18/*!
19\file prototype_op.hpp
20Documentation for generic cases (these generic cases are never used).
21*/
22
23// ==================== Unary operators with one result ====================
24
25
26/*!
27Prototype for forward mode unary operator with one result (not used).
28
29\tparam Base
30base type for the operator; i.e., this operation was recorded
31using AD< \a Base > and computations by this routine are done using type
32\a Base.
33
34\param p
35lowest order of the Taylor coefficient that we are computing.
36
37\param q
38highest order of the Taylor coefficient that we are computing.
39
40\param i_z
41variable index corresponding to the result for this operation;
42i.e. the row index in \a taylor corresponding to z.
43
44\param i_x
45variable index corresponding to the argument for this operator;
46i.e. the row index in \a taylor corresponding to x.
47
48\param cap_order
49maximum number of orders that will fit in the \c taylor array.
50
51\param taylor
52\b Input: <code>taylor [ i_x * cap_order + k ]</code>,
53for k = 0 , ... , q,
54is the k-th order Taylor coefficient corresponding to x.
55\n
56\b Input: <code>taylor [ i_z * cap_order + k ]</code>,
57for k = 0 , ... , p-1,
58is the k-th order Taylor coefficient corresponding to z.
59\n
60\b Output: <code>taylor [ i_z * cap_order + k ]</code>,
61for k = p , ... , q,
62is the k-th order Taylor coefficient corresponding to z.
63
64\par Checked Assertions
65\li NumArg(op) == 1
66\li NumRes(op) == 1
67\li q < cap_order
68\li p <= q
69*/
70template <class Base>
71inline void forward_unary1_op(
72        size_t p           ,
73        size_t q           ,
74        size_t i_z         ,
75        size_t i_x         ,
76        size_t cap_order   ,
77        Base*  taylor      )
78{
79        // This routine is only for documentaiton, it should not be used
81}
82
83/*!
84Prototype for multiple direction forward mode unary operator with one result
85(not used).
86
87\tparam Base
88base type for the operator; i.e., this operation was recorded
89using AD< \a Base > and computations by this routine are done using type
90\a Base.
91
92\param q
93order of the Taylor coefficients that we are computing.
94
95\param r
96number of directions for Taylor coefficients that we are computing.
97
98\param i_z
99variable index corresponding to the last (primary) result for this operation;
100i.e. the row index in \a taylor corresponding to z.
101The auxillary result is called y has index \a i_z - 1.
102
103\param i_x
104variable index corresponding to the argument for this operator;
105i.e. the row index in \a taylor corresponding to x.
106
107\param cap_order
108maximum number of orders that will fit in the \c taylor array.
109
110\par tpv
111We use the notation
112<code>tpv = (cap_order-1) * r + 1</code>
113which is the number of Taylor coefficients per variable
114
115\param taylor
116\b Input: If x is a variable,
117<code>taylor [ arg[0] * tpv + 0 ]</code>,
118is the zero order Taylor coefficient for all directions and
119<code>taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ]</code>,
120for k = 1 , ... , q,
121ell = 0, ..., r-1,
122is the k-th order Taylor coefficient
123corresponding to x and the ell-th direction.
124\n
125\b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
126is the zero order Taylor coefficient for all directions and
127<code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
128for k = 1 , ... , q-1,
129ell = 0, ..., r-1,
130is the k-th order Taylor coefficient
131corresponding to z and the ell-th direction.
132\n
133\b Output:
134<code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
135ell = 0, ..., r-1,
136is the q-th order Taylor coefficient
137corresponding to z and the ell-th direction.
138
139\par Checked Assertions
140\li NumArg(op) == 1
141\li NumRes(op) == 2
142\li i_x < i_z
143\li 0 < q
144\li q < cap_order
145*/
146template <class Base>
147inline void forward_unary1_op_dir(
148        size_t q           ,
149        size_t r           ,
150        size_t i_z         ,
151        size_t i_x         ,
152        size_t cap_order   ,
153        Base*  taylor      )
154{
155        // This routine is only for documentaiton, it should not be used
157}
158
159/*!
160Prototype for zero order forward mode unary operator with one result (not used).
161\tparam Base
162base type for the operator; i.e., this operation was recorded
163using AD< \a Base > and computations by this routine are done using type
164\a Base .
165
166\param i_z
167variable index corresponding to the result for this operation;
168i.e. the row index in \a taylor corresponding to z.
169
170\param i_x
171variable index corresponding to the argument for this operator;
172i.e. the row index in \a taylor corresponding to x.
173
174\param cap_order
175maximum number of orders that will fit in the \c taylor array.
176
177\param taylor
178\b Input: \a taylor [ \a i_x * \a cap_order + 0 ]
179is the zero order Taylor coefficient corresponding to x.
180\n
181\b Output: \a taylor [ \a i_z * \a cap_order + 0 ]
182is the zero order Taylor coefficient corresponding to z.
183
184\par Checked Assertions
185\li NumArg(op) == 1
186\li NumRes(op) == 1
187\li \a i_x < \a i_z
188\li \a 0 < \a cap_order
189*/
190template <class Base>
191inline void forward_unary1_op_0(
192        size_t i_z         ,
193        size_t i_x         ,
194        size_t cap_order   ,
195        Base*  taylor      )
196{
197        // This routine is only for documentaiton, it should not be used
199}
200
201/*!
202Prototype for reverse mode unary operator with one result (not used).
203
204This routine is given the partial derivatives of a function
205G(z , x , w, u ... )
206and it uses them to compute the partial derivatives of
207\verbatim
208        H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ]
209\endverbatim
210
211\tparam Base
212base type for the operator; i.e., this operation was recorded
213using AD< \a Base > and computations by this routine are done using type
214\a Base .
215
216\param d
217highest order Taylor coefficient that
218we are computing the partial derivatives with respect to.
219
220\param i_z
221variable index corresponding to the result for this operation;
222i.e. the row index in \a taylor to z.
223
224\param i_x
225variable index corresponding to the argument for this operation;
226i.e. the row index in \a taylor corresponding to x.
227
228\param cap_order
229maximum number of orders that will fit in the \c taylor array.
230
231\param taylor
232\a taylor [ \a i_x * \a cap_order + k ]
233for k = 0 , ... , \a d
234is the k-th order Taylor coefficient corresponding to x.
235\n
236\a taylor [ \a i_z * \a cap_order + k ]
237for k = 0 , ... , \a d
238is the k-th order Taylor coefficient corresponding to z.
239
240\param nc_partial
241number of colums in the matrix containing all the partial derivatives.
242
243\param partial
244\b Input: \a partial [ \a i_x * \a nc_partial + k ]
245for k = 0 , ... , \a d
246is the partial derivative of G( z , x , w , u , ... ) with respect to
247the k-th order Taylor coefficient for x.
248\n
249\b Input: \a partial [ \a i_z * \a nc_partial + k ]
250for k = 0 , ... , \a d
251is the partial derivative of G( z , x , w , u , ... ) with respect to
252the k-th order Taylor coefficient for z.
253\n
254\b Output: \a partial [ \a i_x * \a nc_partial + k ]
255for k = 0 , ... , \a d
256is the partial derivative of H( x , w , u , ... ) with respect to
257the k-th order Taylor coefficient for x.
258\n
259\b Output: \a partial [ \a i_z * \a nc_partial + k ]
260for k = 0 , ... , \a d
261may be used as work space; i.e., may change in an unspecified manner.
262
263
264\par Checked Assumptions
265\li NumArg(op) == 1
266\li NumRes(op) == 1
267\li \a i_x < \a i_z
268\li \a d < \a cap_order
269\li \a d < \a nc_partial
270*/
271template <class Base>
272inline void reverse_unary1_op(
273        size_t      d            ,
274        size_t      i_z          ,
275        size_t      i_x          ,
276        size_t      cap_order    ,
277        const Base* taylor       ,
278        size_t      nc_partial   ,
279        Base*       partial      )
280{
281        // This routine is only for documentaiton, it should not be used
283}
284
285// ==================== Unary operators with two results ====================
286
287/*!
288Prototype for forward mode unary operator with two results (not used).
289
290\tparam Base
291base type for the operator; i.e., this operation was recorded
292using AD< \a Base > and computations by this routine are done using type
293\a Base.
294
295\param p
296lowest order of the Taylor coefficients that we are computing.
297
298\param q
299highest order of the Taylor coefficients that we are computing.
300
301\param i_z
302variable index corresponding to the last (primary) result for this operation;
303i.e. the row index in \a taylor corresponding to z.
304The auxillary result is called y has index \a i_z - 1.
305
306\param i_x
307variable index corresponding to the argument for this operator;
308i.e. the row index in \a taylor corresponding to x.
309
310\param cap_order
311maximum number of orders that will fit in the \c taylor array.
312
313\param taylor
314\b Input: <code>taylor [ i_x * cap_order + k ]</code>
315for k = 0 , ... , q,
316is the k-th order Taylor coefficient corresponding to x.
317\n
318\b Input: <code>taylor [ i_z * cap_order + k ]</code>
319for k = 0 , ... , p - 1,
320is the k-th order Taylor coefficient corresponding to z.
321\n
322\b Input: <code>taylor [ ( i_z - 1) * cap_order + k ]</code>
323for k = 0 , ... , p-1,
324is the k-th order Taylor coefficient corresponding to the auxillary result y.
325\n
326\b Output: <code>taylor [ i_z * cap_order + k ]</code>,
327for k = p , ... , q,
328is the k-th order Taylor coefficient corresponding to z.
329\n
330\b Output: <code>taylor [ ( i_z - 1 ) * cap_order + k ]</code>,
331for k = p , ... , q,
332is the k-th order Taylor coefficient corresponding to
333the autillary result y.
334
335\par Checked Assertions
336\li NumArg(op) == 1
337\li NumRes(op) == 2
338\li i_x + 1 < i_z
339\li q < cap_order
340\li p <= q
341*/
342template <class Base>
343inline void forward_unary2_op(
344        size_t p           ,
345        size_t q           ,
346        size_t i_z         ,
347        size_t i_x         ,
348        size_t cap_order   ,
349        Base*  taylor      )
350{
351        // This routine is only for documentaiton, it should not be used
353}
354
355/*!
356Prototype for multiple direction forward mode unary operator with two results
357(not used).
358
359\tparam Base
360base type for the operator; i.e., this operation was recorded
361using AD< \a Base > and computations by this routine are done using type
362\a Base.
363
364\param q
365order of the Taylor coefficients that we are computing.
366
367\param r
368number of directions for Taylor coefficients that we are computing.
369
370\param i_z
371variable index corresponding to the last (primary) result for this operation;
372i.e. the row index in \a taylor corresponding to z.
373The auxillary result is called y has index \a i_z - 1.
374
375\param i_x
376variable index corresponding to the argument for this operator;
377i.e. the row index in \a taylor corresponding to x.
378
379\param cap_order
380maximum number of orders that will fit in the \c taylor array.
381
382\par tpv
383We use the notation
384<code>tpv = (cap_order-1) * r + 1</code>
385which is the number of Taylor coefficients per variable
386
387\param taylor
388\b Input: <code>taylor [ i_x * tpv + 0 ]</code>
389is the zero order Taylor coefficient for all directions and
390<code>taylor [ i_x * tpv + (k-1)*r + ell + 1</code>
391for k = 1 , ... , q,
392ell = 0 , ..., r-1,
393is the k-th order Taylor coefficient
394corresponding to x and the ell-th direction.
395\n
396\b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
397is the zero order Taylor coefficient for all directions and
398<code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
399for k = 1 , ... , q-1,
400ell = 0, ..., r-1,
401is the k-th order Taylor coefficient
402corresponding to z and the ell-th direction.
403\n
404\b Input: <code>taylor [ (i_z-1) * tpv + 0 ]</code>,
405is the zero order Taylor coefficient for all directions and
406<code>taylor [ (i_z-1) * tpv + (k-1)*r + ell + 1 ]</code>,
407for k = 1 , ... , q-1,
408ell = 0, ..., r-1,
409is the k-th order Taylor coefficient
410corresponding to the auxillary result y and the ell-th direction.
411\n
412\b Output:
413<code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
414ell = 0, ..., r-1,
415is the q-th order Taylor coefficient
416corresponding to z and the ell-th direction.
417
418\par Checked Assertions
419\li NumArg(op) == 1
420\li NumRes(op) == 2
421\li i_x + 1 < i_z
422\li 0 < q
423\li q < cap_order
424*/
425template <class Base>
426inline void forward_unary2_op_dir(
427        size_t q           ,
428        size_t r           ,
429        size_t i_z         ,
430        size_t i_x         ,
431        size_t cap_order   ,
432        Base*  taylor      )
433{
434        // This routine is only for documentaiton, it should not be used
436}
437
438/*!
439Prototype for zero order forward mode unary operator with two results (not used).
440\tparam Base
441base type for the operator; i.e., this operation was recorded
442using AD< \a Base > and computations by this routine are done using type
443\a Base .
444
445\param i_z
446variable index corresponding to the last (primary) result for this operation;
447i.e. the row index in \a taylor corresponding to z.
448The auxillary result is called y and has index \a i_z - 1.
449
450\param i_x
451variable index corresponding to the argument for this operator;
452i.e. the row index in \a taylor corresponding to x.
453
454\param cap_order
455maximum number of orders that will fit in the \c taylor array.
456
457\param taylor
458\b Input: \a taylor [ \a i_x * \a cap_order + 0 ]
459is the zero order Taylor coefficient corresponding to x.
460\n
461\b Output: \a taylor [ \a i_z * \a cap_order + 0 ]
462is the zero order Taylor coefficient corresponding to z.
463\n
464\b Output: \a taylor [ ( \a i_z - 1 ) * \a cap_order + j ]
465is the j-th order Taylor coefficient corresponding to
466the autillary result y.
467
468\par Checked Assertions
469\li NumArg(op) == 1
470\li NumRes(op) == 2
471\li \a i_x + 1 < \a i_z
472\li \a j < \a cap_order
473*/
474template <class Base>
475inline void forward_unary2_op_0(
476        size_t i_z         ,
477        size_t i_x         ,
478        size_t cap_order   ,
479        Base*  taylor      )
480{
481        // This routine is only for documentaiton, it should not be used
483}
484
485/*!
486Prototype for reverse mode unary operator with two results (not used).
487
488This routine is given the partial derivatives of a function
489G( z , y , x , w , ... )
490and it uses them to compute the partial derivatives of
491\verbatim
492        H( x , w , u , ... ) = G[ z(x) , y(x), x , w , u , ... ]
493\endverbatim
494
495\tparam Base
496base type for the operator; i.e., this operation was recorded
497using AD< \a Base > and computations by this routine are done using type
498\a Base .
499
500\param d
501highest order Taylor coefficient that
502we are computing the partial derivatives with respect to.
503
504\param i_z
505variable index corresponding to the last (primary) result for this operation;
506i.e. the row index in \a taylor to z.
507The auxillary result is called y and has index \a i_z - 1.
508
509\param i_x
510variable index corresponding to the argument for this operation;
511i.e. the row index in \a taylor corresponding to x.
512
513\param cap_order
514maximum number of orders that will fit in the \c taylor array.
515
516\param taylor
517\a taylor [ \a i_x * \a cap_order + k ]
518for k = 0 , ... , \a d
519is the k-th order Taylor coefficient corresponding to x.
520\n
521\a taylor [ \a i_z * \a cap_order + k ]
522for k = 0 , ... , \a d
523is the k-th order Taylor coefficient corresponding to z.
524\n
525\a taylor [ ( \a i_z - 1) * \a cap_order + k ]
526for k = 0 , ... , \a d
527is the k-th order Taylor coefficient corresponding to
528the auxillary variable y.
529
530\param nc_partial
531number of colums in the matrix containing all the partial derivatives.
532
533\param partial
534\b Input: \a partial [ \a i_x * \a nc_partial + k ]
535for k = 0 , ... , \a d
536is the partial derivative of
537G( z , y , x , w , u , ... )
538with respect to the k-th order Taylor coefficient for x.
539\n
540\b Input: \a partial [ \a i_z * \a nc_partial + k ]
541for k = 0 , ... , \a d
542is the partial derivative of G( z , y , x , w , u , ... ) with respect to
543the k-th order Taylor coefficient for z.
544\n
545\b Input: \a partial [ ( \a i_z - 1) * \a nc_partial + k ]
546for k = 0 , ... , \a d
547is the partial derivative of G( z , x , w , u , ... ) with respect to
548the k-th order Taylor coefficient for the auxillary variable y.
549\n
550\b Output: \a partial [ \a i_x * \a nc_partial + k ]
551for k = 0 , ... , \a d
552is the partial derivative of H( x , w , u , ... ) with respect to
553the k-th order Taylor coefficient for x.
554\n
555\b Output: \a partial [ \a ( i_z - j ) * \a nc_partial + k ]
556for j = 0 , 1 , and for k = 0 , ... , \a d
557may be used as work space; i.e., may change in an unspecified manner.
558
559
560\par Checked Assumptions
561\li NumArg(op) == 1
562\li NumRes(op) == 2
563\li \a i_x + 1 < \a i_z
564\li \a d < \a cap_order
565\li \a d < \a nc_partial
566*/
567template <class Base>
568inline void reverse_unary2_op(
569        size_t      d            ,
570        size_t      i_z          ,
571        size_t      i_x          ,
572        size_t      cap_order    ,
573        const Base* taylor       ,
574        size_t      nc_partial   ,
575        Base*       partial      )
576{
577        // This routine is only for documentaiton, it should not be used
579}
580// =================== Binary operators with one result ====================
581
582/*!
583Prototype forward mode x op y (not used)
584
585\tparam Base
586base type for the operator; i.e., this operation was recorded
587using AD< \a Base > and computations by this routine are done using type
588\a Base.
589
590\param p
591lowest order of the Taylor coefficient that we are computing.
592
593\param q
594highest order of the Taylor coefficient that we are computing.
595
596\param i_z
597variable index corresponding to the result for this operation;
598i.e. the row index in \a taylor corresponding to z.
599
600\param arg
601\a arg[0]
602index corresponding to the left operand for this operator;
603i.e. the index corresponding to x.
604\n
605\a arg[1]
606index corresponding to the right operand for this operator;
607i.e. the index corresponding to y.
608
609\param parameter
610If x is a parameter, \a parameter [ \a arg[0] ]
611is the value corresponding to x.
612\n
613If y is a parameter, \a parameter [ \a arg[1] ]
614is the value corresponding to y.
615
616\param cap_order
617maximum number of orders that will fit in the \c taylor array.
618
619\param taylor
620\b Input: If x is a variable,
621<code>taylor [ arg[0] * cap_order + k ]</code>,
622for k = 0 , ... , q,
623is the k-th order Taylor coefficient corresponding to x.
624\n
625\b Input: If y is a variable,
626<code>taylor [ arg[1] * cap_order + k ]</code>,
627for k = 0 , ... , q,
628is the k-th order Taylor coefficient corresponding to y.
629\n
630\b Input: <code>taylor [ i_z * cap_order + k ]</code>,
631for k = 0 , ... , p-1,
632is the k-th order Taylor coefficient corresponding to z.
633\n
634\b Output: <code>taylor [ i_z * cap_order + k ]</code>,
635for k = p, ... , q,
636is the k-th order Taylor coefficient corresponding to z.
637
638\par Checked Assertions
639\li NumArg(op) == 2
640\li NumRes(op) == 1
641\li If x is a variable, arg[0] < i_z
642\li If y is a variable, arg[1] < i_z
643\li q <  cap_order
644\li p <=  q
645*/
646template <class Base>
647inline void forward_binary_op(
648        size_t        p          ,
649        size_t        q          ,
650        size_t        i_z        ,
652        const Base*   parameter  ,
653        size_t        cap_order  ,
654        Base*         taylor     )
655{
656        // This routine is only for documentaiton, it should not be used
658}
659
660/*!
661Prototype multiple direction forward mode x op y (not used)
662
663\tparam Base
664base type for the operator; i.e., this operation was recorded
665using AD< \a Base > and computations by this routine are done using type
666\a Base.
667
668\param q
669is the order of the Taylor coefficients that we are computing.
670
671\param r
672number of directions for Taylor coefficients that we are computing
673
674\param i_z
675variable index corresponding to the result for this operation;
676i.e. the row index in \a taylor corresponding to z.
677
678\param arg
679\a arg[0]
680index corresponding to the left operand for this operator;
681i.e. the index corresponding to x.
682\n
683\a arg[1]
684index corresponding to the right operand for this operator;
685i.e. the index corresponding to y.
686
687\param parameter
688If x is a parameter, \a parameter [ \a arg[0] ]
689is the value corresponding to x.
690\n
691If y is a parameter, \a parameter [ \a arg[1] ]
692is the value corresponding to y.
693
694\param cap_order
695maximum number of orders that will fit in the \c taylor array.
696
697\par tpv
698We use the notation
699<code>tpv = (cap_order-1) * r + 1</code>
700which is the number of Taylor coefficients per variable
701
702\param taylor
703\b Input: If x is a variable,
704<code>taylor [ arg[0] * tpv + 0 ]</code>,
705is the zero order Taylor coefficient for all directions and
706<code>taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ]</code>,
707for k = 1 , ... , q,
708ell = 0, ..., r-1,
709is the k-th order Taylor coefficient
710corresponding to x and the ell-th direction.
711\n
712\b Input: If y is a variable,
713<code>taylor [ arg[1] * tpv + 0 ]</code>,
714is the zero order Taylor coefficient for all directions and
715<code>taylor [ arg[1] * tpv + (k-1)*r + ell + 1 ]</code>,
716for k = 1 , ... , q,
717ell = 0, ..., r-1,
718is the k-th order Taylor coefficient
719corresponding to y and the ell-th direction.
720\n
721\b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
722is the zero order Taylor coefficient for all directions and
723<code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
724for k = 1 , ... , q-1,
725ell = 0, ..., r-1,
726is the k-th order Taylor coefficient
727corresponding to z and the ell-th direction.
728\n
729\b Output:
730<code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
731ell = 0, ..., r-1,
732is the q-th order Taylor coefficient
733corresponding to z and the ell-th direction.
734
735\par Checked Assertions
736\li NumArg(op) == 2
737\li NumRes(op) == 1
738\li If x is a variable, arg[0] < i_z
739\li If y is a variable, arg[1] < i_z
740\li 0 < q <  cap_order
741*/
742template <class Base>
743inline void forward_binary_op_dir(
744        size_t        q          ,
745        size_t        r          ,
746        size_t        i_z        ,
748        const Base*   parameter  ,
749        size_t        cap_order  ,
750        Base*         taylor     )
751{
752        // This routine is only for documentaiton, it should not be used
754}
755
756
757/*!
758Prototype zero order forward mode x op y (not used)
759
760\tparam Base
761base type for the operator; i.e., this operation was recorded
762using AD< \a Base > and computations by this routine are done using type
763\a Base.
764
765\param i_z
766variable index corresponding to the result for this operation;
767i.e. the row index in \a taylor corresponding to z.
768
769\param arg
770\a arg[0]
771index corresponding to the left operand for this operator;
772i.e. the index corresponding to x.
773\n
774\a arg[1]
775index corresponding to the right operand for this operator;
776i.e. the index corresponding to y.
777
778\param parameter
779If x is a parameter, \a parameter [ \a arg[0] ]
780is the value corresponding to x.
781\n
782If y is a parameter, \a parameter [ \a arg[1] ]
783is the value corresponding to y.
784
785\param cap_order
786maximum number of orders that will fit in the \c taylor array.
787
788\param taylor
789\b Input: If x is a variable, \a taylor [ \a arg[0] * \a cap_order + 0 ]
790is the zero order Taylor coefficient corresponding to x.
791\n
792\b Input: If y is a variable, \a taylor [ \a arg[1] * \a cap_order + 0 ]
793is the zero order Taylor coefficient corresponding to y.
794\n
795\b Output: \a taylor [ \a i_z * \a cap_order + 0 ]
796is the zero order Taylor coefficient corresponding to z.
797
798\par Checked Assertions
799\li NumArg(op) == 2
800\li NumRes(op) == 1
801\li If x is a variable, \a arg[0] < \a i_z
802\li If y is a variable, \a arg[1] < \a i_z
803*/
804template <class Base>
805inline void forward_binary_op_0(
806        size_t        i_z         ,
808        const Base*   parameter   ,
809        size_t        cap_order   ,
810        Base*         taylor      )
811{
812        // This routine is only for documentaiton, it should not be used
814}
815
816/*!
817Prototype for reverse mode binary operator x op y (not used).
818
819This routine is given the partial derivatives of a function
820G( z , y , x , w , ... )
821and it uses them to compute the partial derivatives of
822\verbatim
823        H( y , x , w , u , ... ) = G[ z(x , y) , y , x , w , u , ... ]
824\endverbatim
825
826\tparam Base
827base type for the operator; i.e., this operation was recorded
828using AD< \a Base > and computations by this routine are done using type
829\a Base .
830
831\param d
832highest order Taylor coefficient that
833we are computing the partial derivatives with respect to.
834
835\param i_z
836variable index corresponding to the result for this operation;
837i.e. the row index in \a taylor corresponding to z.
838
839\param arg
840\a arg[0]
841index corresponding to the left operand for this operator;
842i.e. the index corresponding to x.
843\n
844\a arg[1]
845index corresponding to the right operand for this operator;
846i.e. the index corresponding to y.
847
848\param parameter
849If x is a parameter, \a parameter [ \a arg[0] ]
850is the value corresponding to x.
851\n
852If y is a parameter, \a parameter [ \a arg[1] ]
853is the value corresponding to y.
854
855\param cap_order
856maximum number of orders that will fit in the \c taylor array.
857
858\param taylor
859\a taylor [ \a i_z * \a cap_order + k ]
860for k = 0 , ... , \a d
861is the k-th order Taylor coefficient corresponding to z.
862\n
863If x is a variable, \a taylor [ \a arg[0] * \a cap_order + k ]
864for k = 0 , ... , \a d
865is the k-th order Taylor coefficient corresponding to x.
866\n
867If y is a variable, \a taylor [ \a arg[1] * \a cap_order + k ]
868for k = 0 , ... , \a d
869is the k-th order Taylor coefficient corresponding to y.
870
871\param nc_partial
872number of colums in the matrix containing all the partial derivatives.
873
874\param partial
875\b Input: \a partial [ \a i_z * \a nc_partial + k ]
876for k = 0 , ... , \a d
877is the partial derivative of
878G( z , y , x , w , u , ... )
879with respect to the k-th order Taylor coefficient for z.
880\n
881\b Input: If x is a variable, \a partial [ \a arg[0] * \a nc_partial + k ]
882for k = 0 , ... , \a d
883is the partial derivative of G( z , y , x , w , u , ... ) with respect to
884the k-th order Taylor coefficient for x.
885\n
886\b Input: If y is a variable, \a partial [ \a arg[1] * \a nc_partial + k ]
887for k = 0 , ... , \a d
888is the partial derivative of G( z , x , w , u , ... ) with respect to
889the k-th order Taylor coefficient for the auxillary variable y.
890\n
891\b Output: If x is a variable, \a partial [ \a arg[0] * \a nc_partial + k ]
892for k = 0 , ... , \a d
893is the partial derivative of H( y , x , w , u , ... ) with respect to
894the k-th order Taylor coefficient for x.
895\n
896\b Output: If y is a variable, \a partial [ \a arg[1] * \a nc_partial + k ]
897for k = 0 , ... , \a d
898is the partial derivative of H( y , x , w , u , ... ) with respect to
899the k-th order Taylor coefficient for y.
900\n
901\b Output: \a partial [ \a i_z * \a nc_partial + k ]
902for k = 0 , ... , \a d
903may be used as work space; i.e., may change in an unspecified manner.
904
905\par Checked Assumptions
906\li NumArg(op) == 2
907\li NumRes(op) == 1
908\li \a If x is a variable, arg[0] < \a i_z
909\li \a If y is a variable, arg[1] < \a i_z
910\li \a d < \a cap_order
911\li \a d < \a nc_partial
912*/
913template <class Base>
914inline void reverse_binary_op(
915        size_t      d            ,
916        size_t      i_z          ,
918        const Base* parameter    ,
919        size_t      cap_order    ,
920        const Base* taylor       ,
921        size_t      nc_partial   ,
922        Base*       partial      )
923{
924        // This routine is only for documentaiton, it should not be used
926}
927// ======================= Pow Function ===================================
928/*!
929Prototype for forward mode z = pow(x, y) (not used).
930
931\tparam Base
932base type for the operator; i.e., this operation was recorded
933using AD< \a Base > and computations by this routine are done using type
934\a Base.
935
936\param p
937lowest order of the Taylor coefficient that we are computing.
938
939\param q
940highest order of the Taylor coefficient that we are computing.
941
942\param i_z
943variable index corresponding to the last (primary) result for this operation;
944i.e. the row index in \a taylor corresponding to z.
945Note that there are three results for this operation,
946below they are referred to as z_0, z_1, z_2 and correspond to
947\verbatim
948        z_0 = log(x)
949        z_1 = z0 * y
950        z_2 = exp(z1)
951\endverbatim
952It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
953
954\param arg
955\a arg[0]
956index corresponding to the left operand for this operator;
957i.e. the index corresponding to x.
958\n
959\a arg[1]
960index corresponding to the right operand for this operator;
961i.e. the index corresponding to y.
962
963\param parameter
964If x is a parameter, \a parameter [ \a arg[0] ]
965is the value corresponding to x.
966\n
967If y is a parameter, \a parameter [ \a arg[1] ]
968is the value corresponding to y.
969
970\param cap_order
971maximum number of orders that will fit in the \c taylor array.
972
973\param taylor
974\b Input: If x is a variable,
975<code>taylor [ arg[0] * cap_order + k ]</code>
976for k = 0 , ... , q,
977is the k-th order Taylor coefficient corresponding to x.
978\n
979\b Input: If y is a variable,
980<code>taylor [ arg[1] * cap_order + k ]</code>
981for k = 0 , ... , q
982is the k-th order Taylor coefficient corresponding to y.
983\n
984\b Input: <code>taylor [ (i_z-2+j) * cap_order + k ]</code>,
985for j = 0, 1, 2 , for k = 0 , ... , p-1,
986is the k-th order Taylor coefficient corresponding to z_j.
987\n
988\b Output: <code>taylor [ (i_z-2+j) * cap_order + k ]</code>,
989is the k-th order Taylor coefficient corresponding to z_j.
990
991\par Checked Assertions
992\li NumArg(op) == 2
993\li NumRes(op) == 3
994\li If x is a variable, arg[0] < i_z - 2
995\li If y is a variable, arg[1] < i_z - 2
996\li q < cap_order
997\li p <= q
998*/
999template <class Base>
1000inline void forward_pow_op(
1001        size_t        p          ,
1002        size_t        q          ,
1003        size_t        i_z        ,
1005        const Base*   parameter  ,
1006        size_t        cap_order  ,
1007        Base*         taylor     )
1008{
1009        // This routine is only for documentaiton, it should not be used
1011}
1012/*!
1013Prototype for multiple direction forward mode z = pow(x, y) (not used).
1014
1015\tparam Base
1016base type for the operator; i.e., this operation was recorded
1017using AD< \a Base > and computations by this routine are done using type
1018\a Base.
1019
1020\param q
1021order of the Taylor coefficient that we are computing.
1022
1023\param r
1024is the number of Taylor coefficient directions that we are computing
1025
1026\param i_z
1027variable index corresponding to the last (primary) result for this operation;
1028i.e. the row index in \a taylor corresponding to z.
1029Note that there are three results for this operation,
1030below they are referred to as z_0, z_1, z_2 and correspond to
1031\verbatim
1032        z_0 = log(x)
1033        z_1 = z0 * y
1034        z_2 = exp(z1)
1035\endverbatim
1036It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1037
1038\param arg
1039\a arg[0]
1040index corresponding to the left operand for this operator;
1041i.e. the index corresponding to x.
1042\n
1043\a arg[1]
1044index corresponding to the right operand for this operator;
1045i.e. the index corresponding to y.
1046
1047\param parameter
1048If x is a parameter, \a parameter [ \a arg[0] ]
1049is the value corresponding to x.
1050\n
1051If y is a parameter, \a parameter [ \a arg[1] ]
1052is the value corresponding to y.
1053
1054\param cap_order
1055maximum number of orders that will fit in the \c taylor array.
1056
1057\par tpv
1058We use the notation
1059<code>tpv = (cap_order-1) * r + 1</code>
1060which is the number of Taylor coefficients per variable
1061
1062\param taylor
1063\b Input: If x is a variable,
1064<code>taylor [ arg[0] * tpv + 0 ]</code>
1065is the zero order coefficient corresponding to x and
1066<code>taylor [ arg[0] * tpv + (k-1)*r+1+ell ]</code>
1067for k = 1 , ... , q,
1068ell = 0 , ... , r-1,
1069is the k-th order Taylor coefficient corresponding to x
1070for the ell-th direction.
1071\n
1072\n
1073\b Input: If y is a variable,
1074<code>taylor [ arg[1] * tpv + 0 ]</code>
1075is the zero order coefficient corresponding to y and
1076<code>taylor [ arg[1] * tpv + (k-1)*r+1+ell ]</code>
1077for k = 1 , ... , q,
1078ell = 0 , ... , r-1,
1079is the k-th order Taylor coefficient corresponding to y
1080for the ell-th direction.
1081\n
1082\n
1083\b Input:
1084<code>taylor [ (i_z-2+j) * tpv + 0 ]</code>,
1085is the zero order coefficient corresponding to z_j and
1086<code>taylor [ (i_z-2+j) * tpv + (k-1)*r+1+ell ]</code>,
1087for j = 0, 1, 2 , k = 0 , ... , q-1, ell = 0, ... , r-1,
1088is the k-th order Taylor coefficient corresponding to z_j
1089for the ell-th direction.
1090\n
1091\n
1092\b Output:
1093<code>taylor [ (i_z-2+j) * tpv + (q-1)*r+1+ell ]</code>,
1094for j = 0, 1, 2 , ell = 0, ... , r-1,
1095is the q-th order Taylor coefficient corresponding to z_j
1096for the ell-th direction.
1097
1098\par Checked Assertions
1099\li NumArg(op) == 2
1100\li NumRes(op) == 3
1101\li If x is a variable, arg[0] < i_z - 2
1102\li If y is a variable, arg[1] < i_z - 2
1103\li 0 < q
1104\li q < cap_order
1105*/
1106template <class Base>
1107inline void forward_pow_op_dir(
1108        size_t        q          ,
1109        size_t        r          ,
1110        size_t        i_z        ,
1112        const Base*   parameter  ,
1113        size_t        cap_order  ,
1114        Base*         taylor     )
1115{
1116        // This routine is only for documentaiton, it should not be used
1118}
1119/*!
1120Prototype for zero order forward mode z = pow(x, y) (not used).
1121
1122\tparam Base
1123base type for the operator; i.e., this operation was recorded
1124using AD< \a Base > and computations by this routine are done using type
1125\a Base.
1126
1127\param i_z
1128variable index corresponding to the last (primary) result for this operation;
1129i.e. the row index in \a taylor corresponding to z.
1130Note that there are three results for this operation,
1131below they are referred to as z_0, z_1, z_2 and correspond to
1132\verbatim
1133        z_0 = log(x)
1134        z_1 = z0 * y
1135        z_2 = exp(z1)
1136\endverbatim
1137It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1138
1139\param arg
1140\a arg[0]
1141index corresponding to the left operand for this operator;
1142i.e. the index corresponding to x.
1143\n
1144\a arg[1]
1145index corresponding to the right operand for this operator;
1146i.e. the index corresponding to y.
1147
1148\param parameter
1149If x is a parameter, \a parameter [ \a arg[0] ]
1150is the value corresponding to x.
1151\n
1152If y is a parameter, \a parameter [ \a arg[1] ]
1153is the value corresponding to y.
1154
1155\param cap_order
1156maximum number of orders that will fit in the \c taylor array.
1157
1158\param taylor
1159\b Input: If x is a variable, \a taylor [ \a arg[0] * \a cap_order + 0 ]
1160is the zero order Taylor coefficient corresponding to x.
1161\n
1162\b Input: If y is a variable, \a taylor [ \a arg[1] * \a cap_order + 0 ]
1163is the k-th order Taylor coefficient corresponding to y.
1164\n
1165\b Output: \a taylor [ \a (i_z - 2 + j) * \a cap_order + 0 ]
1166is the zero order Taylor coefficient corresponding to z_j.
1167
1168\par Checked Assertions
1169\li NumArg(op) == 2
1170\li NumRes(op) == 3
1171\li If x is a variable, \a arg[0] < \a i_z - 2
1172\li If y is a variable, \a arg[1] < \a i_z - 2
1173*/
1174template <class Base>
1175inline void forward_pow_op_0(
1176        size_t        i_z        ,
1178        const Base*   parameter  ,
1179        size_t        cap_order  ,
1180        Base*         taylor     )
1181{
1182        // This routine is only for documentaiton, it should not be used
1184}
1185/*!
1186Prototype for reverse mode z = pow(x, y) (not used).
1187
1188This routine is given the partial derivatives of a function
1189G( z , y , x , w , ... )
1190and it uses them to compute the partial derivatives of
1191\verbatim
1192        H( y , x , w , u , ... ) = G[ pow(x , y) , y , x , w , u , ... ]
1193\endverbatim
1194
1195\tparam Base
1196base type for the operator; i.e., this operation was recorded
1197using AD< \a Base > and computations by this routine are done using type
1198\a Base .
1199
1200\param d
1201highest order Taylor coefficient that
1202we are computing the partial derivatives with respect to.
1203
1204\param i_z
1205variable index corresponding to the last (primary) result for this operation;
1206i.e. the row index in \a taylor corresponding to z.
1207Note that there are three results for this operation,
1208below they are referred to as z_0, z_1, z_2 and correspond to
1209\verbatim
1210        z_0 = log(x)
1211        z_1 = z0 * y
1212        z_2 = exp(z1)
1213\endverbatim
1214It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1215
1216\param arg
1217\a arg[0]
1218index corresponding to the left operand for this operator;
1219i.e. the index corresponding to x.
1220\n
1221\a arg[1]
1222index corresponding to the right operand for this operator;
1223i.e. the index corresponding to y.
1224
1225\param parameter
1226If x is a parameter, \a parameter [ \a arg[0] ]
1227is the value corresponding to x.
1228\n
1229If y is a parameter, \a parameter [ \a arg[1] ]
1230is the value corresponding to y.
1231
1232\param cap_order
1233maximum number of orders that will fit in the \c taylor array.
1234
1235\param taylor
1236\a taylor [ \a (i_z - 2 + j) * \a cap_order + k ]
1237for j = 0, 1, 2 and k = 0 , ... , \a d
1238is the k-th order Taylor coefficient corresponding to z_j.
1239\n
1240If x is a variable, \a taylor [ \a arg[0] * \a cap_order + k ]
1241for k = 0 , ... , \a d
1242is the k-th order Taylor coefficient corresponding to x.
1243\n
1244If y is a variable, \a taylor [ \a arg[1] * \a cap_order + k ]
1245for k = 0 , ... , \a d
1246is the k-th order Taylor coefficient corresponding to y.
1247
1248\param nc_partial
1249number of colums in the matrix containing all the partial derivatives.
1250
1251\param partial
1252\b Input: \a partial [ \a (i_z - 2 + j) * \a nc_partial + k ]
1253for j = 0, 1, 2, and k = 0 , ... , \a d
1254is the partial derivative of
1255G( z , y , x , w , u , ... )
1256with respect to the k-th order Taylor coefficient for z_j.
1257\n
1258\b Input: If x is a variable, \a partial [ \a arg[0] * \a nc_partial + k ]
1259for k = 0 , ... , \a d
1260is the partial derivative of G( z , y , x , w , u , ... ) with respect to
1261the k-th order Taylor coefficient for x.
1262\n
1263\b Input: If y is a variable, \a partial [ \a arg[1] * \a nc_partial + k ]
1264for k = 0 , ... , \a d
1265is the partial derivative of G( z , x , w , u , ... ) with respect to
1266the k-th order Taylor coefficient for the auxillary variable y.
1267\n
1268\b Output: If x is a variable, \a partial [ \a arg[0] * \a nc_partial + k ]
1269for k = 0 , ... , \a d
1270is the partial derivative of H( y , x , w , u , ... ) with respect to
1271the k-th order Taylor coefficient for x.
1272\n
1273\b Output: If y is a variable, \a partial [ \a arg[1] * \a nc_partial + k ]
1274for k = 0 , ... , \a d
1275is the partial derivative of H( y , x , w , u , ... ) with respect to
1276the k-th order Taylor coefficient for y.
1277\n
1278\b Output: \a partial [ \a ( i_z - j ) * \a nc_partial + k ]
1279for j = 0 , 1 , 2 and for k = 0 , ... , \a d
1280may be used as work space; i.e., may change in an unspecified manner.
1281
1282\par Checked Assumptions
1283\li NumArg(op) == 2
1284\li NumRes(op) == 3
1285\li \a If x is a variable, arg[0] < \a i_z - 2
1286\li \a If y is a variable, arg[1] < \a i_z - 2
1287\li \a d < \a cap_order
1288\li \a d < \a nc_partial
1289*/
1290template <class Base>
1291inline void reverse_pow_op(
1292        size_t      d            ,
1293        size_t      i_z          ,
1295        const Base* parameter    ,
1296        size_t      cap_order    ,
1297        const Base* taylor       ,
1298        size_t      nc_partial   ,
1299        Base*       partial      )
1300{
1301        // This routine is only for documentaiton, it should not be used
1303}
1304
1305// ==================== Sparsity Calculations ==============================
1306/*!
1307Prototype for reverse mode Hessian sparsity unary operators.
1308
1309This routine is given the forward mode Jacobian sparsity patterns for x.
1310It is also given the reverse mode dependence of G on z.
1311In addition, it is given the revese mode Hessian sparsity
1312for the quanity of interest G(z , y , ... )
1313and it uses them to compute the sparsity patterns for
1314\verbatim
1315        H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ]
1316\endverbatim
1317
1318\tparam Vector_set
1319is the type used for vectors of sets. It can be either
1320\c sparse_pack, \c sparse_set, or \c sparse_list.
1321
1322\param i_z
1323variable index corresponding to the result for this operation;
1324i.e. the row index in sparsity corresponding to z.
1325
1326\param i_x
1327variable index corresponding to the argument for this operator;
1328i.e. the row index in sparsity corresponding to x.
1329
1330\param rev_jacobian
1331\a rev_jacobian[i_z]
1332is all false (true) if the Jacobian of G with respect to z must be zero
1333(may be non-zero).
1334\n
1335\n
1336\a rev_jacobian[i_x]
1337is all false (true) if the Jacobian with respect to x must be zero
1338(may be non-zero).
1339On input, it corresponds to the function G,
1340and on output it corresponds to the function H.
1341
1342\param for_jac_sparsity
1343The set with index \a i_x in for_jac_sparsity
1344is the forward mode Jacobian sparsity pattern for the variable x.
1345
1346\param rev_hes_sparsity
1347The set with index \a i_z in in \a rev_hes_sparsity
1348is the Hessian sparsity pattern for the fucntion G
1349where one of the partials derivative is with respect to z.
1350\n
1351\n
1352The set with index \a i_x in \a rev_hes_sparsity
1353is the Hessian sparsity pattern
1354where one of the partials derivative is with respect to x.
1355On input, it corresponds to the function G,
1356and on output it corresponds to the function H.
1357
1358\par Checked Assertions:
1359\li \a i_x < \a i_z
1360*/
1361
1362template <class Vector_set>
1363inline void reverse_sparse_hessian_unary_op(
1364        size_t              i_z               ,
1365        size_t              i_x               ,
1366        bool*               rev_jacobian      ,
1367        Vector_set&         for_jac_sparsity  ,
1368        Vector_set&         rev_hes_sparsity  )
1369{
1370        // This routine is only for documentaiton, it should not be used
1372}
1373
1374/*!
1375Prototype for reverse mode Hessian sparsity binary operators.
1376
1377This routine is given the sparsity patterns the Hessian
1378of a function G(z, y, x, ... )
1379and it uses them to compute the sparsity patterns for the Hessian of
1380\verbatim
1381        H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ]
1382\endverbatim
1383
1384\tparam Vector_set
1385is the type used for vectors of sets. It can be either
1386\c sparse_pack, \c sparse_set, or \c sparse_list.
1387
1388\param i_z
1389variable index corresponding to the result for this operation;
1390i.e. the row index in sparsity corresponding to z.
1391
1392\param arg
1393\a arg[0]
1394variable index corresponding to the left operand for this operator;
1395i.e. the set with index \a arg[0] in \a var_sparsity
1396is the spasity pattern correspoding to x.
1397\n
1398\n arg[1]
1399variable index corresponding to the right operand for this operator;
1400i.e. the row index in sparsity patterns corresponding to y.
1401
1402\param jac_reverse
1403\a jac_reverse[i_z]
1404is false (true) if the Jacobian of G with respect to z is always zero
1405(may be non-zero).
1406\n
1407\n
1408\a jac_reverse[ \a arg[0] ]
1409is false (true) if the Jacobian with respect to x is always zero
1410(may be non-zero).
1411On input, it corresponds to the function G,
1412and on output it corresponds to the function H.
1413\n
1414\n
1415\a jac_reverse[ \a arg[1] ]
1416is false (true) if the Jacobian with respect to y is always zero
1417(may be non-zero).
1418On input, it corresponds to the function G,
1419and on output it corresponds to the function H.
1420
1421\param for_jac_sparsity
1422The set with index \a arg[0] in \a for_jac_sparsity for the
1423is the forward Jacobian sparsity pattern for x.
1424\n
1425\n
1426The set with index \a arg[1] in \a for_jac_sparsity
1427is the forward sparsity pattern for y.
1428
1429\param rev_hes_sparsity
1430The set wiht index \a i_x in \a rev_hes_sparsity
1431is the Hessian sparsity pattern for the function G
1432where one of the partial derivatives is with respect to z.
1433\n
1434\n
1435The set with index \a arg[0] in  \a rev_hes_sparsity
1436is the Hessian sparsity pattern where one of the
1437partial derivatives is with respect to x.
1438On input, it corresponds to the function G,
1439and on output it correspondst to H.
1440\n
1441\n
1442The set with index \a arg[1] in \a rev_hes_sparsity
1443is the Hessian sparsity pattern where one of the
1444partial derivatives is with respect to y.
1445On input, it corresponds to the function G,
1446and on output it correspondst to H.
1447
1448\par Checked Assertions:
1449\li \a arg[0] < \a i_z
1450\li \a arg[1] < \a i_z
1451*/
1452template <class Vector_set>
1453inline void reverse_sparse_hessian_binary_op(
1454        size_t            i_z                ,