NeoPZ
tinyfadnine.h
Go to the documentation of this file.
1 #ifndef _tinyfadnine_h_
2 #define _tinyfadnine_h_
3 
4 //*********************************************************
5 // This file is generated by generate.cc.
6 // Use this file for any modification
7 //*********************************************************
8 
9 template <class T> class TinyFad<9,T> {
10 public:
11  typedef T value_type;
12  typedef T grad_type;
13 protected:
14 
15  int n;
16  T val_;
17 
18  T dx0_;
19  T dx1_;
20  T dx2_;
21  T dx3_;
22  T dx4_;
23  T dx5_;
24  T dx6_;
25  T dx7_;
26  T dx8_;
27 
28 
29 public:
30  void diff(const size_t ith, const size_t sz){
31  n = ith+1;
32  dx0_ = T(0.);
33  dx1_ = T(0.);
34  dx2_ = T(0.);
35  dx3_ = T(0.);
36  dx4_ = T(0.);
37  dx5_ = T(0.);
38  dx6_ = T(0.);
39  dx7_ = T(0.);
40  dx8_ = T(0.);
41 
42  switch(ith){
43  case 0 : dx0_ = T(1.);break;
44  case 1 : dx1_ = T(1.);break;
45  case 2 : dx2_ = T(1.);break;
46  case 3 : dx3_ = T(1.);break;
47  case 4 : dx4_ = T(1.);break;
48  case 5 : dx5_ = T(1.);break;
49  case 6 : dx6_ = T(1.);break;
50  case 7 : dx7_ = T(1.);break;
51  case 8 : dx8_ = T(1.);break;
52  default : cout << "ith = " << ith << " out of definition set" << endl;exit(1);
53  }
54  }
55 
56  TinyFad(const T& ind, const int ini) : n(ini+1), val_(ind) {
57  dx0_ = T(0.);
58  dx1_ = T(0.);
59  dx2_ = T(0.);
60  dx3_ = T(0.);
61  dx4_ = T(0.);
62  dx5_ = T(0.);
63  dx6_ = T(0.);
64  dx7_ = T(0.);
65  dx8_ = T(0.);
66 
67  switch(ini){
68  case 0 : dx0_ = T(1.);break;
69  case 1 : dx1_ = T(1.);break;
70  case 2 : dx2_ = T(1.);break;
71  case 3 : dx3_ = T(1.);break;
72  case 4 : dx4_ = T(1.);break;
73  case 5 : dx5_ = T(1.);break;
74  case 6 : dx6_ = T(1.);break;
75  case 7 : dx7_ = T(1.);break;
76  case 8 : dx8_ = T(1.);break;
77  default : cout << "ini = " << ini << " out of definition set" << endl;exit(1);
78  }
79  }
80  TinyFad() : n(0), val_(0.) {
81  dx0_ = T(0.);
82  dx1_ = T(0.);
83  dx2_ = T(0.);
84  dx3_ = T(0.);
85  dx4_ = T(0.);
86  dx5_ = T(0.);
87  dx6_ = T(0.);
88  dx7_ = T(0.);
89  dx8_ = T(0.);
90  }
91  TinyFad(const No_Initialization &): n(0) {}
92  TinyFad(const T& in) : n(0), val_(in) {
93  dx0_ = T(0.);
94  dx1_ = T(0.);
95  dx2_ = T(0.);
96  dx3_ = T(0.);
97  dx4_ = T(0.);
98  dx5_ = T(0.);
99  dx6_ = T(0.);
100  dx7_ = T(0.);
101  dx8_ = T(0.);
102  }
103  TinyFad(const TinyFad<9,T> & in) : n(0), val_(in.val_) {
104  dx0_ = in.dx0_;
105  dx1_ = in.dx1_;
106  dx2_ = in.dx2_;
107  dx3_ = in.dx3_;
108  dx4_ = in.dx4_;
109  dx5_ = in.dx5_;
110  dx6_ = in.dx6_;
111  dx7_ = in.dx7_;
112  dx8_ = in.dx8_;
113  }
114 
115  ~TinyFad() {}
116 
117  int N() const {return n-1;}
118 
119  const T& val() const { return val_;}
120  T& val() { return val_;}
121 
122  const T& d0() const { return dx0_;}
123  T& d0() { return dx0_;}
124 
125  const T& d1() const { return dx1_;}
126  T& d1() { return dx1_;}
127 
128  const T& d2() const { return dx2_;}
129  T& d2() { return dx2_;}
130 
131  const T& d3() const { return dx3_;}
132  T& d3() { return dx3_;}
133 
134  const T& d4() const { return dx4_;}
135  T& d4() { return dx4_;}
136 
137  const T& d5() const { return dx5_;}
138  T& d5() { return dx5_;}
139 
140  const T& d6() const { return dx6_;}
141  T& d6() { return dx6_;}
142 
143  const T& d7() const { return dx7_;}
144  T& d7() { return dx7_;}
145 
146  const T& d8() const { return dx8_;}
147  T& d8() { return dx8_;}
148 
149  T& dx(int i){
150  switch(i){
151  case 0 : return dx0_;
152  case 1 : return dx1_;
153  case 2 : return dx2_;
154  case 3 : return dx3_;
155  case 4 : return dx4_;
156  case 5 : return dx5_;
157  case 6 : return dx6_;
158  case 7 : return dx7_;
159  case 8 : return dx8_;
160  default : cout << "i out of bounds" << endl;exit(1);
161  }
162  }
163  const T& dx(int i) const {
164  switch(i){
165  case 0 : return dx0_;
166  case 1 : return dx1_;
167  case 2 : return dx2_;
168  case 3 : return dx3_;
169  case 4 : return dx4_;
170  case 5 : return dx5_;
171  case 6 : return dx6_;
172  case 7 : return dx7_;
173  case 8 : return dx8_;
174  default : cout << "i out of bounds" << endl;exit(1);
175  }
176  }
177  T& d(int i){
178  switch(i){
179  case 0 : return dx0_;
180  case 1 : return dx1_;
181  case 2 : return dx2_;
182  case 3 : return dx3_;
183  case 4 : return dx4_;
184  case 5 : return dx5_;
185  case 6 : return dx6_;
186  case 7 : return dx7_;
187  case 8 : return dx8_;
188  default : cout << "i out of bounds" << endl;exit(1);
189  }
190  }
191  const T& d(int i) const {
192  switch(i){
193  case 0 : return dx0_;
194  case 1 : return dx1_;
195  case 2 : return dx2_;
196  case 3 : return dx3_;
197  case 4 : return dx4_;
198  case 5 : return dx5_;
199  case 6 : return dx6_;
200  case 7 : return dx7_;
201  case 8 : return dx8_;
202  default : cout << "i out of bounds" << endl;exit(1);
203  }
204  }
205 
207  val_ = in.val_;
208 
209  dx0_ = in.dx0_;
210  dx1_ = in.dx1_;
211  dx2_ = in.dx2_;
212  dx3_ = in.dx3_;
213  dx4_ = in.dx4_;
214  dx5_ = in.dx5_;
215  dx6_ = in.dx6_;
216  dx7_ = in.dx7_;
217  dx8_ = in.dx8_;
218 
219  return *this;
220  }
221 
222  TinyFad<9,T> & operator = (const T & in){
223  val_ = in;
224 
225  dx0_ = T(0.);
226  dx1_ = T(0.);
227  dx2_ = T(0.);
228  dx3_ = T(0.);
229  dx4_ = T(0.);
230  dx5_ = T(0.);
231  dx6_ = T(0.);
232  dx7_ = T(0.);
233  dx8_ = T(0.);
234 
235  return *this;
236  }
237 
239  dx0_ += in.dx0_;
240  dx1_ += in.dx1_;
241  dx2_ += in.dx2_;
242  dx3_ += in.dx3_;
243  dx4_ += in.dx4_;
244  dx5_ += in.dx5_;
245  dx6_ += in.dx6_;
246  dx7_ += in.dx7_;
247  dx8_ += in.dx8_;
248  val_ += in.val_;
249 
250 
251  return *this;
252  }
254  dx0_ -= in.dx0_;
255  dx1_ -= in.dx1_;
256  dx2_ -= in.dx2_;
257  dx3_ -= in.dx3_;
258  dx4_ -= in.dx4_;
259  dx5_ -= in.dx5_;
260  dx6_ -= in.dx6_;
261  dx7_ -= in.dx7_;
262  dx8_ -= in.dx8_;
263  val_ -= in.val_;
264 
265  return *this;
266  }
268  dx0_ = dx0_ * in.val_ + val_ * in.dx0_;
269  dx1_ = dx1_ * in.val_ + val_ * in.dx1_;
270  dx2_ = dx2_ * in.val_ + val_ * in.dx2_;
271  dx3_ = dx3_ * in.val_ + val_ * in.dx3_;
272  dx4_ = dx4_ * in.val_ + val_ * in.dx4_;
273  dx5_ = dx5_ * in.val_ + val_ * in.dx5_;
274  dx6_ = dx6_ * in.val_ + val_ * in.dx6_;
275  dx7_ = dx7_ * in.val_ + val_ * in.dx7_;
276  dx8_ = dx8_ * in.val_ + val_ * in.dx8_;
277  val_ *= in.val_;
278 
279  return *this;
280  }
282  if (in.val_ == 0.) error("TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
283  dx0_ = ( dx0_ * in.val_ - val_ * in.dx0_ ) / in.val_ / in.val_ ;
284  dx1_ = ( dx1_ * in.val_ - val_ * in.dx1_ ) / in.val_ / in.val_ ;
285  dx2_ = ( dx2_ * in.val_ - val_ * in.dx2_ ) / in.val_ / in.val_ ;
286  dx3_ = ( dx3_ * in.val_ - val_ * in.dx3_ ) / in.val_ / in.val_ ;
287  dx4_ = ( dx4_ * in.val_ - val_ * in.dx4_ ) / in.val_ / in.val_ ;
288  dx5_ = ( dx5_ * in.val_ - val_ * in.dx5_ ) / in.val_ / in.val_ ;
289  dx6_ = ( dx6_ * in.val_ - val_ * in.dx6_ ) / in.val_ / in.val_ ;
290  dx7_ = ( dx7_ * in.val_ - val_ * in.dx7_ ) / in.val_ / in.val_ ;
291  dx8_ = ( dx8_ * in.val_ - val_ * in.dx8_ ) / in.val_ / in.val_ ;
292  val_ /= in.val_;
293 
294  return *this;
295  }
296 
297  TinyFad<9,T> & operator += (const T & in){ val_ += in;
298 
299  return *this;
300  }
301  TinyFad<9,T> & operator -= (const T & in){ val_ -= in;
302 
303  return *this;
304  }
305  TinyFad<9,T> & operator *= (const T & in){
306  val_ *= in;
307 
308  dx0_ *= in;
309  dx1_ *= in;
310  dx2_ *= in;
311  dx3_ *= in;
312  dx4_ *= in;
313  dx5_ *= in;
314  dx6_ *= in;
315  dx7_ *= in;
316  dx8_ *= in;
317 
318  return *this;
319  }
320  TinyFad<9,T> & operator /= (const T & in){
321  if ( in == T(0.) ) error("TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
322  val_ /= in;
323 
324  dx0_ /= in;
325  dx1_ /= in;
326  dx2_ /= in;
327  dx3_ /= in;
328  dx4_ /= in;
329  dx5_ /= in;
330  dx6_ /= in;
331  dx7_ /= in;
332  dx8_ /= in;
333 
334  return *this;
335  }
336 
338  TinyFad<9,T> tmp(*this);
339  tmp.val_++;
340  return tmp;
341  };
343  TinyFad<9,T> tmp(*this);
344  tmp.val_--;
345  return tmp;
346  };
348  return *this;
349  }
351  return *this;
352  }
353 };
354 
355 
356 template <class T> inline TinyFad<9,T> operator + (const TinyFad<9,T>& in)
357 {
358  return TinyFad<9,T>(in);
359 }
360 
361 template <class T> inline TinyFad<9,T> operator - (const TinyFad<9,T>& in)
362 {
364  tmp -= in;
365  return tmp;
366 }
367 
368 template <class L, class R> inline
370 operator +(const TinyFad<9,L>& un, const TinyFad<9,R>& deux) {
371 
372  typedef typename NumericalTraits<L,R>::promote value_type;
373 
374  No_Initialization nothing;
375  TinyFad<9,value_type> tmp( nothing );
376 
377  tmp.d0() = un.d0() + deux.d0();
378 
379  tmp.d1() = un.d1() + deux.d1();
380 
381  tmp.d2() = un.d2() + deux.d2();
382 
383  tmp.d3() = un.d3() + deux.d3();
384 
385  tmp.d4() = un.d4() + deux.d4();
386 
387  tmp.d5() = un.d5() + deux.d5();
388 
389  tmp.d6() = un.d6() + deux.d6();
390 
391  tmp.d7() = un.d7() + deux.d7();
392 
393  tmp.d8() = un.d8() + deux.d8();
394 
395  tmp.val() = un.val() + deux.val();
396 
397  return tmp;
398 }
399 
400 template <class L, class R> inline
402 operator +(const TinyFad<9,L>& un, const R& deux) {
403 
404  typedef typename NumericalTraits<L,R>::promote value_type;
405 
406  No_Initialization nothing;
407  TinyFad<9,value_type> tmp( nothing );
408 
409  tmp.d0() = un.d0();
410 
411  tmp.d1() = un.d1();
412 
413  tmp.d2() = un.d2();
414 
415  tmp.d3() = un.d3();
416 
417  tmp.d4() = un.d4();
418 
419  tmp.d5() = un.d5();
420 
421  tmp.d6() = un.d6();
422 
423  tmp.d7() = un.d7();
424 
425  tmp.d8() = un.d8();
426 
427  tmp.val() = un.val() + deux;
428 
429  return tmp;
430 }
431 
432 template <class L, class R> inline
434 operator +(const L& un, const TinyFad<9,R>& deux) {
435  return operator +(deux,un);
436 }
437 
438 template <class L, class R> inline
440 operator *(const TinyFad<9,L>& un, const TinyFad<9,R>& deux) {
441 
442  typedef typename NumericalTraits<L,R>::promote value_type;
443 
444  No_Initialization nothing;
445  TinyFad<9,value_type> tmp( nothing );
446 
447  tmp.d0() = un.d0()*deux.val() + un.val() * deux.d0();
448 
449  tmp.d1() = un.d1()*deux.val() + un.val() * deux.d1();
450 
451  tmp.d2() = un.d2()*deux.val() + un.val() * deux.d2();
452 
453  tmp.d3() = un.d3()*deux.val() + un.val() * deux.d3();
454 
455  tmp.d4() = un.d4()*deux.val() + un.val() * deux.d4();
456 
457  tmp.d5() = un.d5()*deux.val() + un.val() * deux.d5();
458 
459  tmp.d6() = un.d6()*deux.val() + un.val() * deux.d6();
460 
461  tmp.d7() = un.d7()*deux.val() + un.val() * deux.d7();
462 
463  tmp.d8() = un.d8()*deux.val() + un.val() * deux.d8();
464 
465  tmp.val() = un.val() * deux.val();
466 
467  return tmp;
468 }
469 
470 template <class L, class R> inline
472 operator *(const TinyFad<9,L>& un, const R& deux) {
473 
474  typedef typename NumericalTraits<L,R>::promote value_type;
475 
476  No_Initialization nothing;
477  TinyFad<9,value_type> tmp( nothing );
478 
479  tmp.d0() = un.d0()*deux;
480 
481  tmp.d1() = un.d1()*deux;
482 
483  tmp.d2() = un.d2()*deux;
484 
485  tmp.d3() = un.d3()*deux;
486 
487  tmp.d4() = un.d4()*deux;
488 
489  tmp.d5() = un.d5()*deux;
490 
491  tmp.d6() = un.d6()*deux;
492 
493  tmp.d7() = un.d7()*deux;
494 
495  tmp.d8() = un.d8()*deux;
496 
497  tmp.val() = un.val() * deux;
498 
499  return tmp;
500 }
501 
502 template <class L, class R> inline
504 operator *(const L& un, const TinyFad<9,R>& deux) {
505 
506  return operator *(deux,un);
507 }
508 
509 
510 template <class L, class R> inline
512 operator -(const TinyFad<9,L> & un, const TinyFad<9,R> & deux) {
513 
514  typedef typename NumericalTraits<L,R>::promote value_type;
515 
516  No_Initialization nothing;
517  TinyFad<9,value_type> tmp( nothing );
518 
519  tmp.d0() = un.d0() - deux.d0();
520 
521  tmp.d1() = un.d1() - deux.d1();
522 
523  tmp.d2() = un.d2() - deux.d2();
524 
525  tmp.d3() = un.d3() - deux.d3();
526 
527  tmp.d4() = un.d4() - deux.d4();
528 
529  tmp.d5() = un.d5() - deux.d5();
530 
531  tmp.d6() = un.d6() - deux.d6();
532 
533  tmp.d7() = un.d7() - deux.d7();
534 
535  tmp.d8() = un.d8() - deux.d8();
536 
537  tmp.val() = un.val() - deux.val();
538 
539  return tmp;
540 }
541 
542 template <class L, class R> inline
544 operator -(const L & un, const TinyFad<9,R> & deux) {
545 
546  typedef typename NumericalTraits<L,R>::promote value_type;
547 
548  No_Initialization nothing;
549  TinyFad<9,value_type> tmp( nothing );
550 
551  tmp.d0() -= deux.d0();
552 
553  tmp.d1() -= deux.d1();
554 
555  tmp.d2() -= deux.d2();
556 
557  tmp.d3() -= deux.d3();
558 
559  tmp.d4() -= deux.d4();
560 
561  tmp.d5() -= deux.d5();
562 
563  tmp.d6() -= deux.d6();
564 
565  tmp.d7() -= deux.d7();
566 
567  tmp.d8() -= deux.d8();
568 
569  tmp.val() = un - deux.val();
570 
571  return tmp;
572 }
573 
574 template <class L, class R> inline
576 operator -(const TinyFad<9,L> & un, const R & deux) {
577  typedef typename NumericalTraits<L,R>::promote value_type;
578 
579  No_Initialization nothing;
580  TinyFad<9,value_type> tmp( nothing );
581 
582  tmp.d0() = un.d0();
583 
584  tmp.d1() = un.d1();
585 
586  tmp.d2() = un.d2();
587 
588  tmp.d3() = un.d3();
589 
590  tmp.d4() = un.d4();
591 
592  tmp.d5() = un.d5();
593 
594  tmp.d6() = un.d6();
595 
596  tmp.d7() = un.d7();
597 
598  tmp.d8() = un.d8();
599 
600  tmp.val() = un.val() - deux;
601 
602  return tmp;
603 }
604 
605 template <class L, class R> inline
607 operator /(const TinyFad<9,L> & un, const TinyFad<9,R> & deux) {
608 
609  typedef typename NumericalTraits<L,R>::promote value_type;
610 
611  if (deux.val() == 0.) error("TinyFad & TinyFad::operator /(const TinyFad<9,L> & un, const TinyFad<9,R> & deux), dividing by 0");
612 
613  No_Initialization nothing;
614  TinyFad<9,value_type> tmp( nothing );
615  value_type dval = deux.val();
616 
617  tmp.d0() = ( un.d0()* deux.val() - un.val() * deux.d0() ) / dval / dval ;
618 
619  tmp.d1() = ( un.d1()* deux.val() - un.val() * deux.d1() ) / dval / dval ;
620 
621  tmp.d2() = ( un.d2()* deux.val() - un.val() * deux.d2() ) / dval / dval ;
622 
623  tmp.d3() = ( un.d3()* deux.val() - un.val() * deux.d3() ) / dval / dval ;
624 
625  tmp.d4() = ( un.d4()* deux.val() - un.val() * deux.d4() ) / dval / dval ;
626 
627  tmp.d5() = ( un.d5()* deux.val() - un.val() * deux.d5() ) / dval / dval ;
628 
629  tmp.d6() = ( un.d6()* deux.val() - un.val() * deux.d6() ) / dval / dval ;
630 
631  tmp.d7() = ( un.d7()* deux.val() - un.val() * deux.d7() ) / dval / dval ;
632 
633  tmp.d8() = ( un.d8()* deux.val() - un.val() * deux.d8() ) / dval / dval ;
634 
635  tmp.val() = un.val() / dval;
636 
637  return tmp;
638 }
639 
640 template <class L, class R> inline
642 operator /(const L & un, const TinyFad<9,R> & deux) {
643 
644  typedef typename NumericalTraits<L,R>::promote value_type;
645 
646  if (deux.val() == 0.) error("TinyFad & TinyFad::operator /(const L & un, const TinyFad<9,R> & deux), dividing by 0");
647 
648  No_Initialization nothing;
649  TinyFad<9,value_type> tmp( nothing );
650  value_type dval = deux.val();
651 
652  tmp.d0() = - un * deux.d0() / dval / dval ;
653 
654  tmp.d1() = - un * deux.d1() / dval / dval ;
655 
656  tmp.d2() = - un * deux.d2() / dval / dval ;
657 
658  tmp.d3() = - un * deux.d3() / dval / dval ;
659 
660  tmp.d4() = - un * deux.d4() / dval / dval ;
661 
662  tmp.d5() = - un * deux.d5() / dval / dval ;
663 
664  tmp.d6() = - un * deux.d6() / dval / dval ;
665 
666  tmp.d7() = - un * deux.d7() / dval / dval ;
667 
668  tmp.d8() = - un * deux.d8() / dval / dval ;
669 
670  tmp.val() = un / dval;
671 
672  return tmp;
673 }
674 
675 template <class L, class R> inline
677 operator /(const TinyFad<9,L> & un, const R & deux) {
678 
679  typedef typename NumericalTraits<L,R>::promote value_type;
680 
681  if (deux == 0.) error("TinyFad & TinyFad::operator /(const TinyFad<9,L> & un, const R & deux), dividing by 0");
682 
683  No_Initialization nothing;
684  TinyFad<9,value_type> tmp( nothing );
685 
686  tmp.d0() = un.d0() / deux;
687 
688  tmp.d1() = un.d1() / deux;
689 
690  tmp.d2() = un.d2() / deux;
691 
692  tmp.d3() = un.d3() / deux;
693 
694  tmp.d4() = un.d4() / deux;
695 
696  tmp.d5() = un.d5() / deux;
697 
698  tmp.d6() = un.d6() / deux;
699 
700  tmp.d7() = un.d7() / deux;
701 
702  tmp.d8() = un.d8() / deux;
703 
704  tmp.val() = un.val() / deux;
705 
706  return tmp;
707 }
708 
709 template <class T> TinyFad<9,T> exp (const TinyFad<9,T>& in)
710 {
711  TinyFad<9,T> tmp(exp(in.val()));
712 
713  tmp.d0() = in.d0()*exp(in.val());
714  tmp.d1() = in.d1()*exp(in.val());
715  tmp.d2() = in.d2()*exp(in.val());
716  tmp.d3() = in.d3()*exp(in.val());
717  tmp.d4() = in.d4()*exp(in.val());
718  tmp.d5() = in.d5()*exp(in.val());
719  tmp.d6() = in.d6()*exp(in.val());
720  tmp.d7() = in.d7()*exp(in.val());
721  tmp.d8() = in.d8()*exp(in.val());
722 
723  return tmp;
724 }
725 
726 template <class T> TinyFad<9,T> log (const TinyFad<9,T>& in)
727 {
728  if ( in.val() <= 0) error("TinyFad log (const TinyFad& in) : zero or negative value");
729  TinyFad<9,T> tmp(log(in.val()));
730 
731  tmp.d0() = in.d0() / in.val();
732  tmp.d1() = in.d1() / in.val();
733  tmp.d2() = in.d2() / in.val();
734  tmp.d3() = in.d3() / in.val();
735  tmp.d4() = in.d4() / in.val();
736  tmp.d5() = in.d5() / in.val();
737  tmp.d6() = in.d6() / in.val();
738  tmp.d7() = in.d7() / in.val();
739  tmp.d8() = in.d8() / in.val();
740 
741  return tmp;
742 }
743 
744 template <class T> TinyFad<9,T> sqrt (const TinyFad<9,T>& in)
745 {
746  if ( in.val() < 0. ) error("TinyFad<9,T> sqrt (const TinyFad& in) : negative value");
747  TinyFad<9,T> tmp(sqrt(in.val()));
748 
749  bool test=true;
750  if ( in.val() == T(0.) ){
751  if ( in.d0() != T(0.) ) test = false;
752 
753  if ( in.d1() != T(0.) ) test = false;
754 
755  if ( in.d2() != T(0.) ) test = false;
756 
757  if ( in.d3() != T(0.) ) test = false;
758 
759  if ( in.d4() != T(0.) ) test = false;
760 
761  if ( in.d5() != T(0.) ) test = false;
762 
763  if ( in.d6() != T(0.) ) test = false;
764 
765  if ( in.d7() != T(0.) ) test = false;
766 
767  if ( in.d8() != T(0.) ) test = false;
768 
769  if ( !test )
770  error("TinyFad<9,T> sqrt (const TinyFad& in) : null value");
771  }
772  else {
773  tmp.d0() = in.d0() / sqrt(in.val()) / 2.;
774  tmp.d1() = in.d1() / sqrt(in.val()) / 2.;
775  tmp.d2() = in.d2() / sqrt(in.val()) / 2.;
776  tmp.d3() = in.d3() / sqrt(in.val()) / 2.;
777  tmp.d4() = in.d4() / sqrt(in.val()) / 2.;
778  tmp.d5() = in.d5() / sqrt(in.val()) / 2.;
779  tmp.d6() = in.d6() / sqrt(in.val()) / 2.;
780  tmp.d7() = in.d7() / sqrt(in.val()) / 2.;
781  tmp.d8() = in.d8() / sqrt(in.val()) / 2.;
782  }
783 
784  return tmp;
785 }
786 
787 template <class T> TinyFad<9,T> sin (const TinyFad<9,T>& in)
788 {
789  TinyFad<9,T> tmp( sin(in.val()) );
790 
791  tmp.d0() = in.d0() * cos( in.val() );
792  tmp.d1() = in.d1() * cos( in.val() );
793  tmp.d2() = in.d2() * cos( in.val() );
794  tmp.d3() = in.d3() * cos( in.val() );
795  tmp.d4() = in.d4() * cos( in.val() );
796  tmp.d5() = in.d5() * cos( in.val() );
797  tmp.d6() = in.d6() * cos( in.val() );
798  tmp.d7() = in.d7() * cos( in.val() );
799  tmp.d8() = in.d8() * cos( in.val() );
800 
801  return tmp;
802 }
803 
804 template <class T> TinyFad<9,T> cos (const TinyFad<9,T>& in)
805 {
806  TinyFad<9,T> tmp(cos(in.val()));
807 
808  tmp.d0() = - in.d0() * sin( in.val() );
809  tmp.d1() = - in.d1() * sin( in.val() );
810  tmp.d2() = - in.d2() * sin( in.val() );
811  tmp.d3() = - in.d3() * sin( in.val() );
812  tmp.d4() = - in.d4() * sin( in.val() );
813  tmp.d5() = - in.d5() * sin( in.val() );
814  tmp.d6() = - in.d6() * sin( in.val() );
815  tmp.d7() = - in.d7() * sin( in.val() );
816  tmp.d8() = - in.d8() * sin( in.val() );
817 
818  return tmp;
819 }
820 
821 template <class T> TinyFad<9,T> tan (const TinyFad<9,T>& in)
822 {
823  if ( in.val() == 0) error("TinyFad tan (const TinyFad& in) undiefined in 0.");
824  TinyFad<9,T> tmp(tan(in.val()));
825 
826  T cosinus = cos(in.val());
827  tmp.d0() = in.d0() / cosinus / cosinus;
828  tmp.d1() = in.d1() / cosinus / cosinus;
829  tmp.d2() = in.d2() / cosinus / cosinus;
830  tmp.d3() = in.d3() / cosinus / cosinus;
831  tmp.d4() = in.d4() / cosinus / cosinus;
832  tmp.d5() = in.d5() / cosinus / cosinus;
833  tmp.d6() = in.d6() / cosinus / cosinus;
834  tmp.d7() = in.d7() / cosinus / cosinus;
835  tmp.d8() = in.d8() / cosinus / cosinus;
836 
837  return tmp;
838 }
839 
840 template <class T> TinyFad<9,T> pow (const TinyFad<9,T>& in, double e)
841 {
842  TinyFad<9,T> tmp(pow(in.val(), e));
843 
844  tmp.d0() = e*in.d0()*pow(in.val(), e-1);
845  tmp.d1() = e*in.d1()*pow(in.val(), e-1);
846  tmp.d2() = e*in.d2()*pow(in.val(), e-1);
847  tmp.d3() = e*in.d3()*pow(in.val(), e-1);
848  tmp.d4() = e*in.d4()*pow(in.val(), e-1);
849  tmp.d5() = e*in.d5()*pow(in.val(), e-1);
850  tmp.d6() = e*in.d6()*pow(in.val(), e-1);
851  tmp.d7() = e*in.d7()*pow(in.val(), e-1);
852  tmp.d8() = e*in.d8()*pow(in.val(), e-1);
853 
854  return tmp;
855 }
856 
857 template <class T> TinyFad<9,T> pow (const TinyFad<9,T>& un, const TinyFad<9,T>& deux)
858 {
859  if (un.val() == 0) error("TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
860  TinyFad<9,T> tmp(pow(un.val(), deux.val()));
861 
862  tmp.d0() = deux.d0() * log(un.val()) * pow(un.val(), deux.val())
863  + deux.val() * un.d0() * pow(un.val(), deux.val()-1);
864  tmp.d1() = deux.d1() * log(un.val()) * pow(un.val(), deux.val())
865  + deux.val() * un.d1() * pow(un.val(), deux.val()-1);
866  tmp.d2() = deux.d2() * log(un.val()) * pow(un.val(), deux.val())
867  + deux.val() * un.d2() * pow(un.val(), deux.val()-1);
868  tmp.d3() = deux.d3() * log(un.val()) * pow(un.val(), deux.val())
869  + deux.val() * un.d3() * pow(un.val(), deux.val()-1);
870  tmp.d4() = deux.d4() * log(un.val()) * pow(un.val(), deux.val())
871  + deux.val() * un.d4() * pow(un.val(), deux.val()-1);
872  tmp.d5() = deux.d5() * log(un.val()) * pow(un.val(), deux.val())
873  + deux.val() * un.d5() * pow(un.val(), deux.val()-1);
874  tmp.d6() = deux.d6() * log(un.val()) * pow(un.val(), deux.val())
875  + deux.val() * un.d6() * pow(un.val(), deux.val()-1);
876  tmp.d7() = deux.d7() * log(un.val()) * pow(un.val(), deux.val())
877  + deux.val() * un.d7() * pow(un.val(), deux.val()-1);
878  tmp.d8() = deux.d8() * log(un.val()) * pow(un.val(), deux.val())
879  + deux.val() * un.d8() * pow(un.val(), deux.val()-1);
880 
881  return tmp;
882 }
883 
884 template <class T> TinyFad<9,T> pow (const TinyFad<9,T>& in, const int e)
885 {
886  TinyFad<9,T> tmp( pow((double)in.val(), (double)e) );
887 
888  tmp.d0() = e*in.d0()*pow((double)in.val(), (double)e-1);
889  tmp.d1() = e*in.d1()*pow((double)in.val(), (double)e-1);
890  tmp.d2() = e*in.d2()*pow((double)in.val(), (double)e-1);
891  tmp.d3() = e*in.d3()*pow((double)in.val(), (double)e-1);
892  tmp.d4() = e*in.d4()*pow((double)in.val(), (double)e-1);
893  tmp.d5() = e*in.d5()*pow((double)in.val(), (double)e-1);
894  tmp.d6() = e*in.d6()*pow((double)in.val(), (double)e-1);
895  tmp.d7() = e*in.d7()*pow((double)in.val(), (double)e-1);
896  tmp.d8() = e*in.d8()*pow((double)in.val(), (double)e-1);
897 
898  return tmp;
899 }
900 
901 template <class T> TinyFad<9,T> abs (const TinyFad<9,T>& in)
902 {
903  int sign = in.val() > 0? 1:0;
904 
905  if (sign) return in;
906  else return (-in);
907 }
908 
909 template <class T> std::ostream& operator << (std::ostream& os, const TinyFad<9,T>& a)
910 {
911  os.setf(std::ios::fixed,std::ios::scientific);
912  os.width(12);
913  os << a.val() << " [";
914 
915  os.width(12);
916  os << a.d0();
917  os.width(12);
918  os << a.d1();
919  os.width(12);
920  os << a.d2();
921  os.width(12);
922  os << a.d3();
923  os.width(12);
924  os << a.d4();
925  os.width(12);
926  os << a.d5();
927  os.width(12);
928  os << a.d6();
929  os.width(12);
930  os << a.d7();
931  os.width(12);
932  os << a.d8();
933 
934  os << "]";
935 
936  return os;
937 }
938 
939 
940 #endif
TinyFad< 9, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 9, L > &un, const TinyFad< 9, R > &deux)
Definition: tinyfadnine.h:440
const T & val() const
Definition: tinyfadnine.h:119
TinyFad< 9, T > log(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:726
TinyFad(const T &ind, const int ini)
Definition: tinyfadnine.h:56
TinyFad< 9, T > sqrt(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:744
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:233
TinyFad< 9, T > tan(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:821
const T & dx(int i) const
Definition: tinyfadnine.h:163
Definition: test.py:1
TinyFad< 9, T > abs(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:901
int N() const
Definition: tinyfadnine.h:117
const T & d0() const
Definition: tinyfadnine.h:122
TinyFad< 9, T > operator+(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:356
AutoPointerMutexArrayInit tmp
TinyFad< 9, T > pow(const TinyFad< 9, T > &in, double e)
Definition: tinyfadnine.h:840
T val_
Definition: tinyfad.h:47
const T & d(int i) const
Definition: tinyfadnine.h:191
T & dx(int i)
Definition: tinyfadnine.h:149
void error(char *string)
Definition: testShape.cc:7
const T & d3() const
Definition: tinyfadnine.h:131
TinyFad< 9, T > & operator--()
Definition: tinyfadnine.h:350
const T & d7() const
Definition: tinyfadnine.h:143
TinyFad< 9, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 9, L > &un, const TinyFad< 9, R > &deux)
Definition: tinyfadnine.h:607
TinyFad< 9, T > & operator++()
Definition: tinyfadnine.h:347
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:189
TinyFad< 9, T > operator++(int)
Definition: tinyfadnine.h:337
const T & d4() const
Definition: tinyfadnine.h:134
TinyFad(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:103
TinyFad(const T &in)
Definition: tinyfadnine.h:92
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:219
T value_type
Definition: tinyfad.h:53
const T & d8() const
Definition: tinyfadnine.h:146
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:247
TinyFad< 9, T > cos(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:804
TinyFad< 9, T > operator-(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:361
const T & d1() const
Definition: tinyfadnine.h:125
TinyFad< 9, T > operator--(int)
Definition: tinyfadnine.h:342
const T & d2() const
Definition: tinyfadnine.h:128
const T & d6() const
Definition: tinyfadnine.h:140
TinyFad(const No_Initialization &)
Definition: tinyfadnine.h:91
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:261
TinyFad< 9, T > exp(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:709
T & d(int i)
Definition: tinyfadnine.h:177
TinyFad< 9, T > sin(const TinyFad< 9, T > &in)
Definition: tinyfadnine.h:787
const T & d5() const
Definition: tinyfadnine.h:137
const T & val() const
Definition: tinyfad.h:72
void diff(const size_t ith, const size_t sz)
Definition: tinyfadnine.h:30