1 #ifndef _tinyfadthirteen_h_ 2 #define _tinyfadthirteen_h_ 9 template <
class T>
class TinyFad<13,T> {
34 void diff(
const size_t ith,
const size_t sz){
51 case 0 : dx0_ = T(1.);
break;
52 case 1 : dx1_ = T(1.);
break;
53 case 2 : dx2_ = T(1.);
break;
54 case 3 : dx3_ = T(1.);
break;
55 case 4 : dx4_ = T(1.);
break;
56 case 5 : dx5_ = T(1.);
break;
57 case 6 : dx6_ = T(1.);
break;
58 case 7 : dx7_ = T(1.);
break;
59 case 8 : dx8_ = T(1.);
break;
60 case 9 : dx9_ = T(1.);
break;
61 case 10 : dx10_ = T(1.);
break;
62 case 11 : dx11_ = T(1.);
break;
63 case 12 : dx12_ = T(1.);
break;
64 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
68 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
84 case 0 : dx0_ = T(1.);
break;
85 case 1 : dx1_ = T(1.);
break;
86 case 2 : dx2_ = T(1.);
break;
87 case 3 : dx3_ = T(1.);
break;
88 case 4 : dx4_ = T(1.);
break;
89 case 5 : dx5_ = T(1.);
break;
90 case 6 : dx6_ = T(1.);
break;
91 case 7 : dx7_ = T(1.);
break;
92 case 8 : dx8_ = T(1.);
break;
93 case 9 : dx9_ = T(1.);
break;
94 case 10 : dx10_ = T(1.);
break;
95 case 11 : dx11_ = T(1.);
break;
96 case 12 : dx12_ = T(1.);
break;
97 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
149 int N()
const {
return n-1;}
154 const T&
d0()
const {
return dx0_;}
155 T&
d0() {
return dx0_;}
157 const T&
d1()
const {
return dx1_;}
158 T&
d1() {
return dx1_;}
160 const T&
d2()
const {
return dx2_;}
161 T&
d2() {
return dx2_;}
163 const T&
d3()
const {
return dx3_;}
164 T&
d3() {
return dx3_;}
166 const T&
d4()
const {
return dx4_;}
167 T&
d4() {
return dx4_;}
169 const T&
d5()
const {
return dx5_;}
170 T&
d5() {
return dx5_;}
172 const T&
d6()
const {
return dx6_;}
173 T&
d6() {
return dx6_;}
175 const T&
d7()
const {
return dx7_;}
176 T&
d7() {
return dx7_;}
178 const T&
d8()
const {
return dx8_;}
179 T&
d8() {
return dx8_;}
181 const T&
d9()
const {
return dx9_;}
182 T&
d9() {
return dx9_;}
184 const T&
d10()
const {
return dx10_;}
187 const T&
d11()
const {
return dx11_;}
190 const T&
d12()
const {
return dx12_;}
195 case 0 :
return dx0_;
196 case 1 :
return dx1_;
197 case 2 :
return dx2_;
198 case 3 :
return dx3_;
199 case 4 :
return dx4_;
200 case 5 :
return dx5_;
201 case 6 :
return dx6_;
202 case 7 :
return dx7_;
203 case 8 :
return dx8_;
204 case 9 :
return dx9_;
205 case 10 :
return dx10_;
206 case 11 :
return dx11_;
207 case 12 :
return dx12_;
208 default : cout <<
"i out of bounds" << endl;exit(1);
211 const T&
dx(
int i)
const {
213 case 0 :
return dx0_;
214 case 1 :
return dx1_;
215 case 2 :
return dx2_;
216 case 3 :
return dx3_;
217 case 4 :
return dx4_;
218 case 5 :
return dx5_;
219 case 6 :
return dx6_;
220 case 7 :
return dx7_;
221 case 8 :
return dx8_;
222 case 9 :
return dx9_;
223 case 10 :
return dx10_;
224 case 11 :
return dx11_;
225 case 12 :
return dx12_;
226 default : cout <<
"i out of bounds" << endl;exit(1);
231 case 0 :
return dx0_;
232 case 1 :
return dx1_;
233 case 2 :
return dx2_;
234 case 3 :
return dx3_;
235 case 4 :
return dx4_;
236 case 5 :
return dx5_;
237 case 6 :
return dx6_;
238 case 7 :
return dx7_;
239 case 8 :
return dx8_;
240 case 9 :
return dx9_;
241 case 10 :
return dx10_;
242 case 11 :
return dx11_;
243 case 12 :
return dx12_;
244 default : cout <<
"i out of bounds" << endl;exit(1);
247 const T&
d(
int i)
const {
249 case 0 :
return dx0_;
250 case 1 :
return dx1_;
251 case 2 :
return dx2_;
252 case 3 :
return dx3_;
253 case 4 :
return dx4_;
254 case 5 :
return dx5_;
255 case 6 :
return dx6_;
256 case 7 :
return dx7_;
257 case 8 :
return dx8_;
258 case 9 :
return dx9_;
259 case 10 :
return dx10_;
260 case 11 :
return dx11_;
261 case 12 :
return dx12_;
262 default : cout <<
"i out of bounds" << endl;exit(1);
344 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
345 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
346 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
347 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
348 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
349 dx5_ = dx5_ * in.
val_ + val_ * in.
dx5_;
350 dx6_ = dx6_ * in.
val_ + val_ * in.
dx6_;
351 dx7_ = dx7_ * in.
val_ + val_ * in.
dx7_;
352 dx8_ = dx8_ * in.
val_ + val_ * in.
dx8_;
353 dx9_ = dx9_ * in.
val_ + val_ * in.
dx9_;
354 dx10_ = dx10_ * in.
val_ + val_ * in.
dx10_;
355 dx11_ = dx11_ * in.
val_ + val_ * in.
dx11_;
356 dx12_ = dx12_ * in.
val_ + val_ * in.
dx12_;
362 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
409 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
460 template <
class L,
class R>
inline 469 tmp.d0() = un.d0() + deux.d0();
471 tmp.d1() = un.d1() + deux.d1();
473 tmp.d2() = un.d2() + deux.d2();
475 tmp.d3() = un.d3() + deux.d3();
477 tmp.d4() = un.d4() + deux.d4();
479 tmp.d5() = un.d5() + deux.d5();
481 tmp.d6() = un.d6() + deux.d6();
483 tmp.d7() = un.d7() + deux.d7();
485 tmp.d8() = un.d8() + deux.d8();
487 tmp.d9() = un.d9() + deux.d9();
489 tmp.d10() = un.d10() + deux.d10();
491 tmp.d11() = un.d11() + deux.d11();
493 tmp.d12() = un.d12() + deux.d12();
500 template <
class L,
class R>
inline 529 tmp.d10() = un.d10();
531 tmp.d11() = un.d11();
533 tmp.d12() = un.d12();
535 tmp.
val() = un.
val() + deux;
540 template <
class L,
class R>
inline 546 template <
class L,
class R>
inline 555 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
557 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
559 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
561 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
563 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
565 tmp.d5() = un.d5()*deux.
val() + un.
val() * deux.d5();
567 tmp.d6() = un.d6()*deux.
val() + un.
val() * deux.d6();
569 tmp.d7() = un.d7()*deux.
val() + un.
val() * deux.d7();
571 tmp.d8() = un.d8()*deux.
val() + un.
val() * deux.d8();
573 tmp.d9() = un.d9()*deux.
val() + un.
val() * deux.d9();
575 tmp.d10() = un.d10()*deux.
val() + un.
val() * deux.d10();
577 tmp.d11() = un.d11()*deux.
val() + un.
val() * deux.d11();
579 tmp.d12() = un.d12()*deux.
val() + un.
val() * deux.d12();
586 template <
class L,
class R>
inline 595 tmp.d0() = un.d0()*deux;
597 tmp.d1() = un.d1()*deux;
599 tmp.d2() = un.d2()*deux;
601 tmp.d3() = un.d3()*deux;
603 tmp.d4() = un.d4()*deux;
605 tmp.d5() = un.d5()*deux;
607 tmp.d6() = un.d6()*deux;
609 tmp.d7() = un.d7()*deux;
611 tmp.d8() = un.d8()*deux;
613 tmp.d9() = un.d9()*deux;
615 tmp.d10() = un.d10()*deux;
617 tmp.d11() = un.d11()*deux;
619 tmp.d12() = un.d12()*deux;
621 tmp.
val() = un.
val() * deux;
626 template <
class L,
class R>
inline 634 template <
class L,
class R>
inline 643 tmp.d0() = un.d0() - deux.d0();
645 tmp.d1() = un.d1() - deux.d1();
647 tmp.d2() = un.d2() - deux.d2();
649 tmp.d3() = un.d3() - deux.d3();
651 tmp.d4() = un.d4() - deux.d4();
653 tmp.d5() = un.d5() - deux.d5();
655 tmp.d6() = un.d6() - deux.d6();
657 tmp.d7() = un.d7() - deux.d7();
659 tmp.d8() = un.d8() - deux.d8();
661 tmp.d9() = un.d9() - deux.d9();
663 tmp.d10() = un.d10() - deux.d10();
665 tmp.d11() = un.d11() - deux.d11();
667 tmp.d12() = un.d12() - deux.d12();
674 template <
class L,
class R>
inline 683 tmp.d0() -= deux.d0();
685 tmp.d1() -= deux.d1();
687 tmp.d2() -= deux.d2();
689 tmp.d3() -= deux.d3();
691 tmp.d4() -= deux.d4();
693 tmp.d5() -= deux.d5();
695 tmp.d6() -= deux.d6();
697 tmp.d7() -= deux.d7();
699 tmp.d8() -= deux.d8();
701 tmp.d9() -= deux.d9();
703 tmp.d10() -= deux.d10();
705 tmp.d11() -= deux.d11();
707 tmp.d12() -= deux.d12();
709 tmp.
val() = un - deux.
val();
714 template <
class L,
class R>
inline 742 tmp.d10() = un.d10();
744 tmp.d11() = un.d11();
746 tmp.d12() = un.d12();
748 tmp.
val() = un.
val() - deux;
753 template <
class L,
class R>
inline 759 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<13,L> & un, const TinyFad<13,R> & deux), dividing by 0");
763 value_type dval = deux.
val();
765 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
767 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
769 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
771 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
773 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
775 tmp.d5() = ( un.d5()* deux.
val() - un.
val() * deux.d5() ) / dval / dval ;
777 tmp.d6() = ( un.d6()* deux.
val() - un.
val() * deux.d6() ) / dval / dval ;
779 tmp.d7() = ( un.d7()* deux.
val() - un.
val() * deux.d7() ) / dval / dval ;
781 tmp.d8() = ( un.d8()* deux.
val() - un.
val() * deux.d8() ) / dval / dval ;
783 tmp.d9() = ( un.d9()* deux.
val() - un.
val() * deux.d9() ) / dval / dval ;
785 tmp.d10() = ( un.d10()* deux.
val() - un.
val() * deux.d10() ) / dval / dval ;
787 tmp.d11() = ( un.d11()* deux.
val() - un.
val() * deux.d11() ) / dval / dval ;
789 tmp.d12() = ( un.d12()* deux.
val() - un.
val() * deux.d12() ) / dval / dval ;
791 tmp.
val() = un.
val() / dval;
796 template <
class L,
class R>
inline 802 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<13,R> & deux), dividing by 0");
806 value_type dval = deux.
val();
808 tmp.d0() = - un * deux.d0() / dval / dval ;
810 tmp.d1() = - un * deux.d1() / dval / dval ;
812 tmp.d2() = - un * deux.d2() / dval / dval ;
814 tmp.d3() = - un * deux.d3() / dval / dval ;
816 tmp.d4() = - un * deux.d4() / dval / dval ;
818 tmp.d5() = - un * deux.d5() / dval / dval ;
820 tmp.d6() = - un * deux.d6() / dval / dval ;
822 tmp.d7() = - un * deux.d7() / dval / dval ;
824 tmp.d8() = - un * deux.d8() / dval / dval ;
826 tmp.d9() = - un * deux.d9() / dval / dval ;
828 tmp.d10() = - un * deux.d10() / dval / dval ;
830 tmp.d11() = - un * deux.d11() / dval / dval ;
832 tmp.d12() = - un * deux.d12() / dval / dval ;
834 tmp.
val() = un / dval;
839 template <
class L,
class R>
inline 845 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<13,L> & un, const R & deux), dividing by 0");
850 tmp.d0() = un.d0() / deux;
852 tmp.d1() = un.d1() / deux;
854 tmp.d2() = un.d2() / deux;
856 tmp.d3() = un.d3() / deux;
858 tmp.d4() = un.d4() / deux;
860 tmp.d5() = un.d5() / deux;
862 tmp.d6() = un.d6() / deux;
864 tmp.d7() = un.d7() / deux;
866 tmp.d8() = un.d8() / deux;
868 tmp.d9() = un.d9() / deux;
870 tmp.d10() = un.d10() / deux;
872 tmp.d11() = un.d11() / deux;
874 tmp.d12() = un.d12() / deux;
876 tmp.
val() = un.
val() / deux;
904 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
926 if ( in.
val() < 0. )
error(
"TinyFad<13,T> sqrt (const TinyFad& in) : negative value");
930 if ( in.
val() == T(0.) ){
931 if ( in.
d0() != T(0.) ) test =
false;
933 if ( in.
d1() != T(0.) ) test =
false;
935 if ( in.
d2() != T(0.) ) test =
false;
937 if ( in.
d3() != T(0.) ) test =
false;
939 if ( in.
d4() != T(0.) ) test =
false;
941 if ( in.
d5() != T(0.) ) test =
false;
943 if ( in.
d6() != T(0.) ) test =
false;
945 if ( in.
d7() != T(0.) ) test =
false;
947 if ( in.
d8() != T(0.) ) test =
false;
949 if ( in.
d9() != T(0.) ) test =
false;
951 if ( in.
d10() != T(0.) ) test =
false;
953 if ( in.
d11() != T(0.) ) test =
false;
955 if ( in.
d12() != T(0.) ) test =
false;
958 error(
"TinyFad<13,T> sqrt (const TinyFad& in) : null value");
1023 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
1026 T cosinus =
cos(in.
val());
1027 tmp.
d0() = in.
d0() / cosinus / cosinus;
1028 tmp.
d1() = in.
d1() / cosinus / cosinus;
1029 tmp.
d2() = in.
d2() / cosinus / cosinus;
1030 tmp.
d3() = in.
d3() / cosinus / cosinus;
1031 tmp.
d4() = in.
d4() / cosinus / cosinus;
1032 tmp.
d5() = in.
d5() / cosinus / cosinus;
1033 tmp.
d6() = in.
d6() / cosinus / cosinus;
1034 tmp.
d7() = in.
d7() / cosinus / cosinus;
1035 tmp.
d8() = in.
d8() / cosinus / cosinus;
1036 tmp.
d9() = in.
d9() / cosinus / cosinus;
1037 tmp.
d10() = in.
d10() / cosinus / cosinus;
1038 tmp.
d11() = in.
d11() / cosinus / cosinus;
1039 tmp.
d12() = in.
d12() / cosinus / cosinus;
1067 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
1104 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
1105 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
1106 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
1107 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
1108 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
1109 tmp.d5() = e*in.
d5()*
pow((
double)in.
val(), (double)e-1);
1110 tmp.d6() = e*in.
d6()*
pow((
double)in.
val(), (double)e-1);
1111 tmp.d7() = e*in.
d7()*
pow((
double)in.
val(), (double)e-1);
1112 tmp.d8() = e*in.
d8()*
pow((
double)in.
val(), (double)e-1);
1113 tmp.d9() = e*in.
d9()*
pow((
double)in.
val(), (double)e-1);
1114 tmp.d10() = e*in.
d10()*
pow((
double)in.
val(), (double)e-1);
1115 tmp.d11() = e*in.
d11()*
pow((
double)in.
val(), (double)e-1);
1116 tmp.d12() = e*in.
d12()*
pow((
double)in.
val(), (double)e-1);
1123 int sign = in.
val() > 0? 1:0;
1125 if (sign)
return in;
1129 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<13,T>& a)
1131 os.setf(std::ios::fixed,std::ios::scientific);
1133 os << a.
val() <<
" [";
TinyFad< 13, T > sqrt(const TinyFad< 13, T > &in)
TinyFad< 13, T > pow(const TinyFad< 13, T > &in, double e)
TinyFad(const TinyFad< 13, T > &in)
TinyFad(const No_Initialization &)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
const T & dx(int i) const
TinyFad< 13, T > operator++(int)
TinyFad< 13, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 13, L > &un, const TinyFad< 13, R > &deux)
AutoPointerMutexArrayInit tmp
TinyFad< 13, T > log(const TinyFad< 13, T > &in)
TinyFad< 13, T > exp(const TinyFad< 13, T > &in)
TinyFad< 13, T > operator-(const TinyFad< 13, T > &in)
TinyFad< 13, T > abs(const TinyFad< 13, T > &in)
void diff(const size_t ith, const size_t sz)
TinyFad(const T &ind, const int ini)
TinyFad< 13, T > operator--(int)
TinyFad< 13, T > sin(const TinyFad< 13, T > &in)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 13, T > & operator++()
TinyFad< 13, T > & operator--()
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< 13, T > cos(const TinyFad< 13, T > &in)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 13, T > tan(const TinyFad< 13, T > &in)
TinyFad< 13, T > operator+(const TinyFad< 13, T > &in)
TinyFad< 13, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 13, L > &un, const TinyFad< 13, R > &deux)