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