This repository has been archived by the owner on Nov 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddf_ari.cpp
788 lines (683 loc) · 21.4 KB
/
ddf_ari.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
/*
** CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
**
** Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
** Universitaet Karlsruhe, Germany
** (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
** Universitaet Wuppertal, Germany
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Library General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Library General Public License for more details.
**
** You should have received a copy of the GNU Library General Public
** License along with this library; if not, write to the Free
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* CVS $Id: ddf_ari.cpp,v 1.17 2014/01/30 17:49:26 cxsc Exp $ */
//============================================================================
//
// Program/Module
// from
// C++ TOOLBOX FOR VERIFIED COMPUTING I
// Basic Numerical Problems
//
// Copyright (c) 1995 Rolf Hammer, Matthias Hocks, Dietmar Ratz
//
// For details on theory, algorithms, and programs, see the book
//
// R. Hammer, M. Hocks, U. Kulisch, D. Ratz: C++ Toolbox for
// Verified Computing I - Basic Numerical Problems. Springer-Verlag,
// Heidelberg, New York, 1995.
//
//============================================================================
//----------------------------------------------------------------------------
// File: ddf_ari (implementation)
// Purpose: Definition of an interval differentiation arithmetic which allows
// function evaluation with automatic differentiation up to second order.
// Method: Overloading of operators and elementary functions for operations
// of data type 'DerivType'.
// Class DerivType:
// DerivType() : constructors
// operators +, -, *, / : operators of diff. arithmetic
// operator = : assignment operator
// DerivConst()
// DerivVar() : to define derivative constants/variables
// fValue()
// dfValue()
// ddfValue() : to get function and derivative values
// sqr(), sqrt(), power(),
// exp(), sin(), cos(), ...: elementary functions of diff. arithmetic
// fEval() : to compute function value only
// dfEval() : to compute function and first derivative
// value
// ddfEval() : to compute function, first, and second
// derivative value
//----------------------------------------------------------------------------
#include <imath.hpp> // Interval mathematical functions
#include "ddf_ari.hpp"
using namespace cxsc;
using namespace std;
// The local variable 'DerivOrder' is used to select the highest order of
// derivative which is computed. Its default value is 2, and normally the
// first and the second derivatives are computed.
//----------------------------------------------------------------------------
#ifdef _WIN32
static __declspec(thread) int DerivOrder = 2;
#elif __APPLE__ && !CXSC_FORCE_TLS
static int DerivOrder = 2;
#else
static __thread int DerivOrder = 2;
#endif
//----------------------------------------------------------------------------
// Constructors and assignment operator
//----------------------------------------------------------------------------
DerivType::DerivType ( )
{
f = 0.0;
df = 0.0;
ddf = 0.0;
}
DerivType::DerivType ( const interval& x_f, const interval& x_df, const interval& x_ddf )
{
f = x_f;
df = x_df;
ddf = x_ddf;
}
DerivType::DerivType ( const DerivType& u )
{
f = u.f;
df = u.df;
ddf = u.ddf;
}
DerivType& DerivType::operator= ( const DerivType& u )
{
f = u.f;
df = u.df;
ddf = u.ddf;
return *this;
}
//----------------------------------------------------------------------------
// Transfer functions for constants and variables
//----------------------------------------------------------------------------
DerivType DerivConst ( const real& c ) // Generate constant
{ //------------------
DerivType u;
u.f = c;
u.df = 0.0;
u.ddf = 0.0;
return u;
}
DerivType DerivConst ( const interval& c ) // Generate constant
{ //------------------
DerivType u;
u.f = c;
u.df = 0.0;
u.ddf = 0.0;
return u;
}
DerivType DerivVar ( const real& v ) // Generate variable
{ //------------------
DerivType u;
u.f = v;
u.df = 1.0;
u.ddf = 0.0;
return u;
}
DerivType DerivVar ( const interval& v ) // Generate variable
{ //------------------
DerivType u;
u.f = v;
u.df = 1.0;
u.ddf = 0.0;
return u;
}
//----------------------------------------------------------------------------
// Unary operators + and - for DerivType operands
//----------------------------------------------------------------------------
inline DerivType operator+ ( DerivType& u )
{ return u; }
DerivType operator- ( const DerivType& u )
{
DerivType res;
res.f = -u.f;
if (DerivOrder > 0) {
res.df = -u.df;
if (DerivOrder > 1) res.ddf = -u.ddf;
}
return res;
}
//----------------------------------------------------------------------------
// Operators +, -, *, and / for two DerivType operands
//----------------------------------------------------------------------------
DerivType operator+ ( const DerivType& u, const DerivType& v )
{
DerivType res;
res.f = u.f + v.f;
if (DerivOrder > 0) {
res.df = u.df + v.df;
if (DerivOrder > 1) res.ddf = u.ddf + v.ddf;
}
return res;
}
DerivType operator- ( const DerivType& u, const DerivType& v )
{
DerivType res;
res.f = u.f - v.f;
if (DerivOrder > 0) {
res.df = u.df - v.df;
if (DerivOrder > 1) res.ddf = u.ddf - v.ddf;
}
return res;
}
DerivType operator* ( const DerivType& u, const DerivType& v )
{
DerivType res;
res.f = u.f * v.f;
if (DerivOrder > 0) {
res.df = u.df*v.f + u.f*v.df;
if (DerivOrder > 1) res.ddf = u.ddf*v.f + 2.0*u.df*v.df + u.f*v.ddf;
}
return res;
}
DerivType operator/ ( const DerivType& u, const DerivType& v )
{
DerivType res;
interval h1, h2;
h1 = u.f / v.f; // Can propagate 'division by zero' error
res.f = h1; //---------------------------------------
if (DerivOrder > 0) {
h2 = (u.df - h1*v.df) / v.f;
res.df = h2;
if (DerivOrder > 1) res.ddf = (u.ddf - h1*v.ddf - 2.0*h2*v.df)/v.f;
}
return res;
}
//----------------------------------------------------------------------------
// Operators +, -, *, and / for one interval and one DerivType operand
//----------------------------------------------------------------------------
DerivType operator+ ( const interval& u, const DerivType& v )
{
DerivType res;
res.f = u + v.f;
if (DerivOrder > 0) {
res.df = v.df;
if (DerivOrder > 1) res.ddf = v.ddf;
}
return res;
}
DerivType operator- ( const interval& u, const DerivType& v )
{
DerivType res;
res.f = u - v.f;
if (DerivOrder > 0) {
res.df = -v.df;
if (DerivOrder > 1) res.ddf = - v.ddf;
}
return res;
}
DerivType operator* ( const interval& u, const DerivType& v )
{
DerivType res;
res.f = u*v.f;
if (DerivOrder > 0) {
res.df = u * v.df;
if (DerivOrder > 1) res.ddf = u*v.ddf;
}
return res;
}
DerivType operator/ ( const interval& u, const DerivType& v )
{
DerivType res;
interval h1, h2;
h1 = u / v.f; // Can propagate 'division by zero' error
res.f = h1; //---------------------------------------
if (DerivOrder > 0) {
h2 = -h1 * v.df / v.f;
res.df = h2;
if (DerivOrder > 1) res.ddf = (-h1*v.ddf - 2.0*h2*v.df)/v.f;
}
return res;
}
DerivType operator+ ( const DerivType& u, const interval& v )
{
DerivType res;
res.f = u.f + v;
if (DerivOrder > 0) {
res.df = u.df;
if (DerivOrder > 1) res.ddf = u.ddf;
}
return res;
}
DerivType operator- ( const DerivType& u, const interval& v )
{
DerivType res;
res.f = u.f - v;
if (DerivOrder > 0) {
res.df = u.df;
if (DerivOrder > 1) res.ddf = u.ddf;
}
return res;
}
DerivType operator* ( const DerivType& u, const interval& v )
{
DerivType res;
res.f = u.f * v;
if (DerivOrder > 0) {
res.df = u.df * v;
if (DerivOrder > 1) res.ddf = u.ddf * v;
}
return res;
}
DerivType operator/ ( const DerivType& u, const interval& v )
{
DerivType res;
res.f = u.f / v; // Can propagate 'division by zero' error
if (DerivOrder > 0) { //---------------------------------------
res.df = u.df / v;
if (DerivOrder > 1) res.ddf = u.ddf / v;
}
return res;
}
//----------------------------------------------------------------------------
// Operands for +, -, *, and / for one real and one DerivType operand
//----------------------------------------------------------------------------
DerivType operator+ ( const real& u, const DerivType& v )
{ return( interval(u) + v ); }
DerivType operator- ( const real& u, const DerivType& v )
{ return( interval(u) - v ); }
DerivType operator* ( const real& u, const DerivType& v )
{ return( interval(u) * v ); }
DerivType operator/ ( const real& u, const DerivType& v )
{ return( interval(u) / v ); } // Can propagate 'division by zero' error
//---------------------------------------
DerivType operator+ ( const DerivType& u, const real& v )
{ return( u + interval(v) ); }
DerivType operator- ( const DerivType& u, const real& v )
{ return( u - interval(v) ); }
DerivType operator* ( const DerivType& u, const real& v )
{ return( u * interval(v) ); }
DerivType operator/ ( const DerivType& u, const real& v )
{ return( u / interval(v) ); } // Can propagate 'division by zero' error
//---------------------------------------
//----------------------------------------------------------------------------
// Elementary functions for DerivType arguments
//----------------------------------------------------------------------------
DerivType sqr ( const DerivType& u )
{
DerivType res;
res.f = Power(u.f,2);
if (DerivOrder > 0) {
res.df = 2.0*u.f*u.df;
if (DerivOrder > 1) res.ddf = 2.0 * (Power(u.df,2) + u.f*u.ddf);
}
return res;
}
DerivType power ( const DerivType& u, int k )
{
DerivType res;
interval h1;
if (k == 0)
res = DerivConst(1.0);
else if (k == 1)
res = u;
else {
res.f = Power(u.f, k);
if (DerivOrder > 0) {
h1 = double(k) * Power(u.f, k-1);
res.df = h1 * u.df;
if (DerivOrder > 1)
res.ddf = h1 * u.ddf + double(k*(k-1))*Power(u.f,k-2)*Power(u.df,2);
}
}
return res;
}
DerivType power ( const DerivType& u, const interval& k )
{
DerivType res;
interval h1;
if (k == 0)
res = DerivConst(1.0);
else if (k == 1)
res = u;
else {
res.f = pow(u.f, k);
if (DerivOrder > 0) {
h1 = k * pow(u.f, k-1);
res.df = h1 * u.df;
if (DerivOrder > 1)
res.ddf = h1 * u.ddf + (k*(k-1))*pow(u.f,k-2)*power(u.df,2);
}
}
return res;
}
DerivType sqrt ( const DerivType& u )
{
DerivType res;
interval h1, h2;
h1 = sqrt(u.f); // Can propagate domain error
res.f = h1; //---------------------------
if (DerivOrder > 0) {
h1 = 0.5/h1;
h2 = u.df*h1;
res.df = h2;
if (DerivOrder > 1) res.ddf = u.ddf*h1 - 0.5*u.df/u.f*h2;
}
return res;
}
DerivType exp ( const DerivType& u )
{
DerivType res;
interval h1, h2;
h1 = exp(u.f);
res.f = h1;
if (DerivOrder > 0) {
h2 = h1*u.df;
res.df = h2;
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*u.df;
}
return res;
}
DerivType ln ( const DerivType& u )
{
DerivType res;
interval h;
res.f = ln(u.f); // Can propagate domain error
if (DerivOrder > 0) { //---------------------------
h = u.df/u.f;
res.df = h;
if (DerivOrder > 1) res.ddf = (u.ddf - h*u.df) / u.f;
}
return res;
}
DerivType sin ( const DerivType& u )
{
DerivType res;
interval h0, h1;
h0 = sin(u.f);
res.f = h0;
if (DerivOrder > 0) {
h1 = cos(u.f);
res.df = h1*u.df;
if (DerivOrder > 1) res.ddf = h1*u.ddf - h0*sqr(u.df);
}
return res;
}
DerivType cos ( const DerivType& u )
{
DerivType res;
interval h0, h1;
h0 = cos(u.f);
res.f = h0;
if (DerivOrder > 0) {
h1 = -sin(u.f);
res.df = h1*u.df;
if (DerivOrder > 1) res.ddf = h1*u.ddf - h0*sqr(u.df);
}
return res;
}
DerivType tan ( const DerivType& u )
{
DerivType res;
interval h0, h1, h2;
h0 = tan(u.f); // Can propagate domain error
res.f = h0; //---------------------------
if (DerivOrder > 0) { // The subdistributive law implies
h1 = sqr(h0)+1.0; // h0 * (h0^2 + 1) <= h0^3 + h0.
h2 = 2.0*h0*h1; // So, the first form is used.
res.df = h1*u.df; //--------------------------------
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType cot ( const DerivType& u )
{
DerivType res;
interval h0, h1, h2;
h0 = cot(u.f); // Can propagate domain error
res.f = h0; //---------------------------
if (DerivOrder > 0) { // The subdistributive law implies
h1 = -(sqr(h0)+1.0); // h0 * (h0^2 + 1) <= h0^3 + h0.
h2 = -2.0*h0*h1; // So, the first form is used.
res.df = h1*u.df; //--------------------------------
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType asin ( const DerivType& u )
{
DerivType res;
interval h, h1, h2;
res.f = asin(u.f); // Can propagate domain error
if (DerivOrder > 0) { //---------------------------
h = 1.0 - sqr(u.f);
h1 = 1.0/sqrt(h);
res.df = h1*u.df;
h2 = u.f*h1/h;
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType acos ( const DerivType& u )
{
DerivType res;
interval h, h1, h2;
res.f = acos(u.f); // Can propagate domain error
if (DerivOrder > 0) { //---------------------------
h = 1.0 - sqr(u.f);
h1 = -1.0/sqrt(h);
res.df = h1*u.df;
h2 = u.f*h1/h;
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType atan ( const DerivType& u )
{
DerivType res;
interval h1, h2;
res.f = atan(u.f);
if (DerivOrder > 0) {
h1 = 1.0 / (1.0 + sqr(u.f));
res.df = h1*u.df;
h2 = -2.0*u.f*sqr(h1);
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType acot ( const DerivType& u )
{
DerivType res;
interval h1, h2;
res.f = acot(u.f); // Can propagate domain error
if (DerivOrder > 0) { //---------------------------
h1 = -1.0 / (1.0 + sqr(u.f));
res.df = h1*u.df;
h2 = 2.0*u.f*sqr(h1);
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType sinh ( const DerivType& u )
{
DerivType res;
interval h0, h1;
h0 = sinh(u.f);
res.f = h0;
if (DerivOrder > 0) {
h1 = cosh(u.f);
res.df = h1*u.df;
if (DerivOrder > 1) res.ddf = h1*u.ddf + h0*sqr(u.df);
}
return res;
}
DerivType cosh ( const DerivType& u )
{
DerivType res;
interval h0, h1;
h0 = cosh(u.f);
res.f = h0;
if (DerivOrder > 0) {
h1 = sinh(u.f);
res.df = h1*u.df;
if (DerivOrder > 1) res.ddf = h1*u.ddf + h0*sqr(u.df);
}
return res;
}
DerivType tanh ( const DerivType& u )
{
DerivType res;
interval h0, h1, h2;
h0 = tanh(u.f);
res.f = h0;
if (DerivOrder > 0) { // The subdistributive law implies
h1 = 1.0 - sqr(h0); // h0 * (h0^2 - 1) <= h0^3 - h0.
h2 = -2.0*h0*h1; // So, the first form is used.
res.df = h1*u.df; //--------------------------------
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType coth ( const DerivType& u )
{
DerivType res;
interval h0, h1, h2;
h0 = coth(u.f); // Can propagate domain error
res.f = h0; //---------------------------
if (DerivOrder > 0) { // The subdistributive law implies
h1 = 1.0 - sqr(h0); // h0 * (h0^2 - 1) <= h0^3 - h0.
h2 = -2.0*h0*h1; // So, the first form is used.
res.df = h1*u.df; //--------------------------------
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType asinh ( const DerivType& u )
{
DerivType res;
interval h, h1, h2;
res.f = asinh(u.f); // Can propagate domain error
if (DerivOrder > 0) { //---------------------------
h = 1.0 + sqr(u.f);
h1 = 1.0/sqrt(h);
res.df = h1*u.df;
h2 = -u.f*h1/h;
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType acosh ( const DerivType& u )
{
DerivType res;
interval h, h1, h2;
res.f = acosh(u.f); // Can propagate domain error
if (DerivOrder > 0) { //---------------------------
h = sqr(u.f) - 1.0;
h1 = 1.0/sqrt(h);
res.df = h1*u.df;
h2 = -u.f*h1/h;
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType atanh ( const DerivType& u )
{
DerivType res;
interval h1, h2;
res.f = atanh(u.f); // Can propagate domain error
if (DerivOrder > 0) { //---------------------------
h1 = 1.0 / (1.0 - sqr(u.f));
res.df = h1*u.df;
h2 = 2.0*u.f*sqr(h1);
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
DerivType acoth ( const DerivType& u )
{
DerivType res;
interval h1, h2;
res.f = acoth(u.f); // Can propagate domain error
if (DerivOrder > 0) { //---------------------------
h1 = 1.0 / (1.0 - sqr(u.f));
res.df = h1*u.df;
h2 = 2.0*u.f*sqr(h1);
if (DerivOrder > 1) res.ddf = h1*u.ddf + h2*sqr(u.df);
}
return res;
}
//----------------------------------------------------------------------------
// Predefined routines for evaluation of DerivType-functions
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Purpose: Evaluation of function 'f' for argument 'x' in differentiation
// arithmetic computing only the function value.
// Parameters:
// In : 'f' : function of 'DerivType'
// 'x' : argument for evaluation of 'f'
// Out: 'fx': returns the function value 'f(x)'
// Description: This function sets 'DerivOrder' to 0, evaluates 'f(x)' in
// differentiation arithmetic, and returns the function value only.
//----------------------------------------------------------------------------
void fEval ( ddf_FctPtr f, interval x, interval& fx )
{
DerivType xD, fxD;
DerivOrder = 0;
xD = DerivVar(x);
fxD = f(xD);
fx = fxD.f;
DerivOrder = 2;
}
//----------------------------------------------------------------------------
// Purpose: Evaluation of function 'f' for argument 'x' in differentiation
// arithmetic computing the function value and the value of the first
// derivative.
// Parameters:
// In : 'f' : function of 'DerivType'
// 'x' : argument for evaluation of 'f'
// Out: 'fx' : returns the function value 'f(x)'
// 'dfx': returns the first derivative value 'f'(x)'
// Description: This function sets 'DerivOrder' to 1, evaluates 'f(x)' in
// differentiation arithmetic, and returns the function value and the
// value of the first derivative.
//----------------------------------------------------------------------------
void dfEval ( ddf_FctPtr f, interval x, interval& fx, interval& dfx )
{
DerivType xD, fxD;
DerivOrder = 1;
xD = DerivVar (x);
fxD = f(xD);
fx = fxD.f;
dfx = fxD.df;
DerivOrder = 2;
}
//----------------------------------------------------------------------------
// Purpose: Evaluation of function 'f' for argument 'x' in differentiation
// arithmetic computing the function value, the value of the first, and
// the value of the second derivative.
// Parameters:
// In : 'f' : function of 'DerivType'
// 'x' : argument for evaluation of 'f'
// Out: 'fx' : returns the function value 'f(x)'
// 'dfx' : returns the value of the first derivative 'f'(x)'
// 'ddfx': returns the value of the second derivative 'f''(x)'
// Description: This function keeps 'DerivOrder' = 2, evaluates 'f(x)' in
// differentiation arithmetic, and returns the function value, the value
// of the first, and the value of the second derivative.
//----------------------------------------------------------------------------
void ddfEval ( ddf_FctPtr f, interval x, interval& fx, interval& dfx,
interval& ddfx )
{
DerivType xD, fxD;
xD = DerivVar(x);
fxD = f(xD);
fx = fxD.f;
dfx = fxD.df;
ddfx = fxD.ddf;
}