19 #define CFUN_K_CONST 3
20 #define CFUN_K_PLUS 10
21 #define CFUN_K_MINUS 11
22 #define CFUN_K_MULT 12
24 #define CFUN_K_POWER 14
26 #define CFUN_K_SQRT 17
28 #define CFUN_K_LOG10 19
32 #define CFUN_K_ARCSIN 23
33 #define CFUN_K_ARCCOS 24
34 #define CFUN_K_ARCTAN 25
35 #define CFUN_K_SINH 26
36 #define CFUN_K_COSH 27
37 #define CFUN_K_TANH 28
38 #define CFUN_K_UMINUS 29
39 #define CFUN_K_SIGN 30
41 #define CFUN_K_DELTA 32
42 #define CFUN_K_INFINITY 33
43 #define CFUN_K_MNINFINITY 34
44 #define CFUN_K_INTSIN 35
45 #define CFUN_K_INTCOS 36
47 #define CFUN_K_DSOLVE 38
49 #define CFUN_O_BRACE '{'
50 #define CFUN_C_BRACE '}'
51 #define CFUN_O_BRACKET '['
52 #define CFUN_C_BRACKET ']'
53 #define CFUN_O_PARENTH '('
54 #define CFUN_C_PARENTH ')'
55 #define CFUN_O_SPARENTH "("
56 #define CFUN_C_SPARENTH ")"
57 #define CFUN_COMMA ','
59 #define CFUN_MINUS '-'
60 #define CFUN_POWER '^'
63 #define CFUN_POINT '.'
64 #define CFUN_SIGNS "()+-^*/"
65 #define CFUN_INF "INF"
67 #define CFUN_EXP "exp"
68 #define CFUN_SQRT "sqrt"
69 #define CFUN_LOG "log"
70 #define CFUN_LOG10 "log10"
71 #define CFUN_SIN "sin"
72 #define CFUN_COS "cos"
73 #define CFUN_TAN "tan"
74 #define CFUN_ASIN "asin"
75 #define CFUN_ACOS "acos"
76 #define CFUN_ATAN "atan"
77 #define CFUN_SINH "sinh"
78 #define CFUN_COSH "cosh"
79 #define CFUN_TANH "tanh"
80 #define CFUN_SI "sinint"
81 #define CFUN_CI "cosint"
82 #define CFUN_SMINUS "-"
83 #define CFUN_SPLUS "+"
84 #define CFUN_SMULT "*"
86 #define CFUN_SPOWER "^"
87 #define CFUN_SCOMMA ","
88 #define CFUN_SSPACE " "
89 #define CFUN_SIGN "sign"
90 #define CFUN_ABS "abs"
91 #define CFUN_IIF "iif"
92 #define CFUN_DELTA "delta"
93 #define CFUN_POWERS "power"
94 #define CFUN_SAT "sat"
96 #define CFUN_SPACES " \t\r\n"
97 #define CFUN_SINF CFUN_O_SPARENTH CFUN_INF CFUN_C_SPARENTH
98 #define CFUN_SMINF CFUN_O_SPARENTH CFUN_SMINUS CFUN_INF CFUN_C_SPARENTH
101 #define CFUN_NOT_FOUND size_t(~0)
103 #if defined (CVM_FLOAT)
104 # define CFUN_M_ZERO 0.F
105 # define CFUN_M_ONE 1.F
106 # define CFUN_M_TWO 2.F
107 # define CFUN_M_MONE -1.F
108 # define CFUN_M_HALF 0.5F
109 # define CFUN_M_E 2.7182818284590452353602874713527F
110 # define CFUN_M_LN2 0.69314718055994530941723212145818F
111 # define CFUN_M_PI 3.1415926535897932384626433832795F
112 # define CFUN_M_PI_2 1.5707963267948966192313216916398F
113 # define CFUN_M_LN_10 2.3025850929940456840179914546844F
114 # define CFUN_M_GAMMA 0.57721566490153286060651209008240243F
116 # define CFUN_M_ZERO 0.L
117 # define CFUN_M_ONE 1.L
118 # define CFUN_M_TWO 2.L
119 # define CFUN_M_MONE -1.L
120 # define CFUN_M_HALF 0.5L
121 # define CFUN_M_E 2.7182818284590452353602874713527L
122 # define CFUN_M_LN2 0.69314718055994530941723212145818L
123 # define CFUN_M_PI 3.1415926535897932384626433832795L
124 # define CFUN_M_PI_2 1.5707963267948966192313216916398L
125 # define CFUN_M_LN_10 2.3025850929940456840179914546844L
126 # define CFUN_M_GAMMA 0.57721566490153286060651209008240243L
129 #define CFUN_OK CVM_OK
130 #define CFUN_PARSEERROR CVM_THE_LAST_ERROR_CODE + 1
131 #define CFUN_DOMAINERROR CVM_THE_LAST_ERROR_CODE + 2
132 #define CFUN_DOMAINERROR_C CVM_THE_LAST_ERROR_CODE + 3
133 #define CFUN_CONVERGENCEERROR CVM_THE_LAST_ERROR_CODE + 4
134 #define CFUN_CONVERGENCEERROR_C CVM_THE_LAST_ERROR_CODE + 5
135 #define CFUN_SUBSTPARAMETERERROR CVM_THE_LAST_ERROR_CODE + 6
136 #define CFUN_VARSDONTMATCH CVM_THE_LAST_ERROR_CODE + 7
137 #define CFUN_NULLPOINTERERROR CVM_THE_LAST_ERROR_CODE + 8
138 #define CFUN_PARAMETER_RECURSION CVM_THE_LAST_ERROR_CODE + 9
140 #define CFUN_SIMPS_STACK_DEPTH 32
141 #define CFUN_MAX_EI_ITERATIONS 1000
150 template <
typename T>
151 class ElementaryFunctions
153 typedef std::complex<T> TC;
168 static T tan(
const T& v)
172 static T atan(
const T& v)
176 static T sinh(
const T& v)
180 static T cosh(
const T& v)
184 static T tanh(
const T& v)
196 if (v < cvm::basic_cvmMachMin<T>())
202 if (v < cvm::basic_cvmMachMin<T>())
206 static T pow(
const T& vBase,
const T& vPower)
208 return ::pow(vBase, vPower);
212 static T sinint(
const T& x,
const T& eps)
throw(
cvmexception)
227 f *= xa * xa / T((i - 1) * i);
231 if (t / cvm::_abs(si) < eps)
233 if (i >= CFUN_MAX_EI_ITERATIONS - 2) {
246 static T cosint(
const T& x,
const T& eps)
throw(
cvmexception)
254 ci = -e1(x, eps).real();
261 f *= x * x / T((i - 1) * i);
265 if (t / cvm::_abs(ci) < eps)
267 if (i >= CFUN_MAX_EI_ITERATIONS - 2) {
277 static TC e1(
const T& x,
const T& eps)
throw(
cvmexception)
290 d = c1 / (a * d + b);
294 if (cvm::_abs(
CFUN_M_ONE - a.real()) + cvm::_abs(a.imag()) < eps)
296 if (i >= CFUN_MAX_EI_ITERATIONS - 1) {
300 return TC(cos(x), -sin(x)) * e;
304 template <
typename T>
305 class ElementaryFunctions<std::complex<T> >
307 typedef std::complex<T> TC;
309 static TC asin(
const TC& v)
313 return cmi * std::log(std::sqrt(c1 - v * v) - cmi * v);
315 static TC acos(
const TC& v)
319 return cmi * std::log(v - cmi * std::sqrt(c1 - v * v));
321 static TC tan(
const TC& v)
325 if (cvm::_abs(im) >= basic_cvmLogMachMax<T>()) {
329 const T d = ::cos(rm) + ::cosh(im);
330 return TC(::sin(rm) / d, ::sinh(im) / d);
333 static TC atan(
const TC& v)
337 return ci2 * std::log((ci + v) / (ci - v));
339 static TC sinh(
const TC& v)
343 static TC cosh(
const TC& v)
347 static TC tanh(
const TC& v)
351 static TC sqrt(
const TC& v)
355 static TC log(
const TC& v)
359 static TC log10(
const TC& v)
361 return std::log10(v);
363 static TC pow(
const TC& vBase,
const TC& vPower)
365 return std::pow(vBase, vPower);
369 static TC sinint(
const TC& x,
const T& eps)
throw(
cvmexception)
372 if (cvm::_abs(x) > eps) {
377 f *= x * x / T((i - 1) * i);
381 if (cvm::_abs(t) / cvm::_abs(si) < eps)
383 if (i >= CFUN_MAX_EI_ITERATIONS - 2) {
392 static TC cosint(
const TC& x,
const T& eps)
throw(
cvmexception)
395 if (cvm::_abs(x) < eps) {
404 f *= x * x / T((i - 1) * i);
408 if (cvm::_abs(t) / cvm::_abs(ci) < eps)
410 if (i >= CFUN_MAX_EI_ITERATIONS - 2) {
414 return ci + log(x) + gamma;
420 template <
typename T1,
typename T2>
424 static bool lt(
const T1& l,
const T2& r);
425 static bool le(
const T1& l,
const T2& r);
426 static bool gt(
const T1& l,
const T2& r);
427 static bool ge(
const T1& l,
const T2& r);
428 static bool eq(
const T1& l,
const T2& r);
437 template <
typename T>
438 class shared_ptr_pair
440 std::shared_ptr<T> mp1;
441 std::shared_ptr<T> mp2;
449 shared_ptr_pair(T* p1, T* p2)
460 shared_ptr_pair(
const std::shared_ptr<T>& p1,
const std::shared_ptr<T>& p2)
471 shared_ptr_pair(std::shared_ptr<T>&& p1, std::shared_ptr<T>&& p2)
472 : mp1(std::move(p1)),
482 std::shared_ptr<T> operator[](
size_t i)
throw(
cvmexception)
500 inline size_t __not(
size_t i)
505 inline void __clean_array(string_array& a)
508 a.erase(a.begin(), a.end());
512 template <
typename T>
513 inline bool __parse_num(
const std::string& s, T& result)
517 result = T(::strtod(s.c_str(), &stop));
518 if ((result ==
CFUN_M_ZERO && s[0] !=
'0') || result == HUGE_VAL || result == -HUGE_VAL || *stop !=
'\0') {
528 inline std::string::const_iterator __trim_beg(
const std::string& s,
size_t nEdge = 0)
531 std::string::const_iterator it = s.end();
532 size_t nLen = s.length();
534 if (nLen > nEdge * 2) {
535 nLen = s.find_first_not_of(szSpaces, nEdge);
538 it = s.begin() + nLen;
544 inline std::string::const_iterator __trim_end(
const std::string& s,
size_t nEdge = 0)
547 std::string::const_iterator it = s.end();
548 size_t nLen = s.length();
550 if (nLen > nEdge * 2) {
551 nLen = s.find_last_not_of(szSpaces, nLen - nEdge - 1);
554 it = s.begin() + (nLen + 1);
561 inline bool __strip_parenth(
const std::string& s,
size_t& nFirst,
size_t& nLast)
568 const size_t nLastOld = nLast;
569 if (s.length() <= nLast || (s[nLast] && sSigns.find(s[nLast]) !=
CFUN_NOT_FOUND)) {
574 nFirst = s.find_first_not_of(szSpaces, nFirst);
575 nLast = s.find_last_not_of(szSpaces, nLast);
582 for (
size_t i = nFirst + 1; i < nLast; i++) {
604 if (nLastOld > nLast) {
610 inline size_t __tassign(std::string& sDest,
const std::string& sSrc,
size_t nFirst,
size_t nLast)
613 if (__strip_parenth(sSrc, nFirst, nLast)) {
614 if (&sDest == &sSrc) {
615 if (nLast < sDest.length()) {
616 sDest.erase(sDest.begin() + nLast, sDest.end());
619 sDest.erase(sDest.begin(), sDest.begin() + nFirst);
623 sDest.assign(sSrc.begin() + nFirst, sSrc.begin() + nLast);
625 nRet = nLast - nFirst;
637 inline int __separate(
const std::string& sBody,
size_t nFirst,
size_t nLast,
638 std::string& sLeft, std::string& sRight)
640 if (__strip_parenth(sBody, nFirst, nLast)) {
648 __tassign(sLeft, sBody, nFirst, nLast);
654 (nCPos > nOPos && (i < nOPos || i > nCPos))) {
655 __tassign(sLeft, sBody, nFirst, i);
656 __tassign(sRight, sBody, i + 1, nLast);
667 inline void __push_back_unique(string_array& a,
const std::string& v)
669 string_array::const_iterator it = a.begin();
670 string_array::const_iterator end = a.end();
679 inline bool __arrays_equal(
const string_array& a1,
const string_array& a2)
681 bool ret = a1.size() == a2.size();
683 string_array::const_iterator i1 = a1.begin();
684 string_array::const_iterator e1 = a1.end();
685 string_array::const_iterator i2 = a2.begin();
687 if ((*i1) != (*i2)) {
698 inline void __add_to_array(string_array& a,
const std::string& sSrc,
699 std::string::const_iterator iBeg, std::string::const_iterator iEnd)
703 size_t nFirst = sSrc.find_first_not_of(szSpaces, iBeg - sSrc.begin());
706 size_t nLast = sSrc.find_last_not_of(szSpaces, iEnd - sSrc.begin() - 1);
710 a.push_back(std::string(sSrc.begin() + nFirst, sSrc.begin() + (nLast + 1)));
716 inline void __parse_vars(
const std::string& sVars,
size_t nFirst,
size_t nLast, string_array& saResult)
719 __clean_array(saResult);
723 __add_to_array(saResult, sVars, sVars.begin() + nFirst, sVars.begin() + nLast);
726 __add_to_array(saResult, sVars, sVars.begin() + nFirst, sVars.begin() + nL);
731 inline std::string __format_vars(
const string_array& a,
bool emptyBraces =
true)
733 std::stringstream stream;
734 bool showBraces = emptyBraces || a.size() > 0;
738 string_array::const_iterator it = a.begin();
739 string_array::const_iterator end = a.end();
753 inline int is_alpha(
int c)
756 if ((c >= 0141 && c <= 0172) || (c >= 0101 && c <= 0132)) {
766 inline bool __subst_parameter(std::string& sBody,
const string_array& saParameters,
770 const size_t nPsz = saParameters.size();
772 for (
size_t i = 0; i < nPsz; i++) {
773 if (sBody == saParameters[i]) {
775 if (i < saMeanings.size()) {
776 const std::string& sMeaning = saMeanings[i];
777 size_t nBeg = sMeaning.find_first_of(sBody);
779 size_t nEnd = nBeg + sBody.length();
780 if ((nBeg <= 0 || !is_alpha(sMeaning.at(nBeg - 1))) &&
781 (nEnd >= sMeaning.length() || !is_alpha(sMeaning.at(nEnd)))) {
787 sBody.assign(__trim_beg(sMeaning), __trim_end(sMeaning));
799 inline bool __ifbodynum(
const std::string& sBody,
size_t nBodyLength,
size_t nSignPos)
801 static const char ccExp =
'e', ccExpb =
'E', ccPoint =
'.';
802 return nSignPos < nBodyLength - 1 &&
803 isdigit(sBody[nSignPos + 1]) &&
805 (sBody[nSignPos - 1] == ccExp || sBody[nSignPos - 1] == ccExpb) &&
806 (sBody[nSignPos - 2] == ccPoint || isdigit(sBody[nSignPos - 2]));
809 inline size_t __tassign(std::string& sDest,
const std::string& sSrc,
size_t nFirst)
811 return __tassign(sDest, sSrc, nFirst, sSrc.length());
814 inline size_t __tassign(std::string& sDest,
const std::string& sSrc)
816 return __tassign(sDest, sSrc, 0, sSrc.length());
822 template <
typename T>
class Fconst;
823 template <
typename T>
class Finfinity;
824 template <
typename T>
class Fmninfinity;
825 template <
typename T>
class Fplus;
826 template <
typename T>
class Fminus;
827 template <
typename T>
class Fmult;
828 template <
typename T>
class Fdiv;
829 template <
typename T>
class Fpower;
830 template <
typename T>
class Fsat;
831 template <
typename T>
class Fexp;
832 template <
typename T>
class Fsqrt;
833 template <
typename T>
class Flog;
834 template <
typename T>
class Flog10;
835 template <
typename T>
class Fsin;
836 template <
typename T>
class Fcos;
837 template <
typename T>
class Ftan;
838 template <
typename T>
class Fasin;
839 template <
typename T>
class Facos;
840 template <
typename T>
class Fatan;
841 template <
typename T>
class Fsinh;
842 template <
typename T>
class Fcosh;
843 template <
typename T>
class Ftanh;
844 template <
typename T>
class Fsinint;
845 template <
typename T>
class Fcosint;
846 template <
typename T>
class Fuminus;
847 template <
typename T>
class Fsign;
848 template <
typename T>
class Fabs;
849 template <
typename T>
class Fdelta;
850 template <
typename T>
class Fvar;
851 template <
typename T>
class Fiif;
853 #ifdef CVM_USE_VARIADIC_TEMPLATES
854 # define CFUN_NEW_FUNC(cls, ...) std::make_shared<cls<T>>(__VA_ARGS__)
856 # define CFUN_NEW_FUNC(cls, ...) BasePointer(new cls<T>(__VA_ARGS__))
868 template <
typename T>
880 const string_array& saVars,
881 const string_array& saParameters,
882 const string_array& saMeanings,
887 static const char pccInfinity[] =
CFUN_INF;
888 std::string sBody, sLeft;
889 size_t nBodyLength = __tassign(sBody, sPar, nFirst, nLast);
892 throw cvmexception(
CFUN_PARSEERROR, sPar.c_str(), __format_vars(saVars).c_str());
896 BasePointer pfConst = CFUN_NEW_FUNC(Fconst, sBody,
false);
897 if (pfConst->is_valid()) {
901 if (subst && __subst_parameter(sBody, saParameters, saMeanings)) {
919 if (__ifbodynum(sBody, nBodyLength, i)) {
922 return CFUN_NEW_FUNC(Fplus, sBody, 0, i, i + 1, nBodyLength, saVars, saParameters, saMeanings);
927 if (__ifbodynum(sBody, nBodyLength, i)) {
931 return CFUN_NEW_FUNC(Fuminus, sBody, 1, nBodyLength, saVars, saParameters, saMeanings);
933 return CFUN_NEW_FUNC(Fminus, sBody, 0, i, i + 1, nBodyLength, saVars, saParameters, saMeanings);
941 throw cvmexception(
CFUN_PARSEERROR, sBody.c_str(), __format_vars(saVars).c_str());
954 throw cvmexception(
CFUN_PARSEERROR, sBody.c_str(), __format_vars(saVars).c_str());
957 return CFUN_NEW_FUNC(Fmult, sBody, 0, i, i + 1, nBodyLength, saVars, saParameters, saMeanings);
962 throw cvmexception(
CFUN_PARSEERROR, sBody.c_str(), __format_vars(saVars).c_str());
965 return CFUN_NEW_FUNC(Fdiv, sBody, 0, i, i + 1, nBodyLength, saVars, saParameters, saMeanings);
973 for (i = 0; i < nBodyLength; ++i) {
983 throw cvmexception(
CFUN_PARSEERROR, sBody.c_str(), __format_vars(saVars).c_str());
986 return CFUN_NEW_FUNC(Fpower, sBody, 0, i, i + 1, nBodyLength, saVars, saParameters, saMeanings);
994 if (isdigit(sBody[0]) || sBody[0] ==
CFUN_POINT) {
995 return CFUN_NEW_FUNC(Fconst, sBody);
997 if (sBody == pccInfinity) {
998 return CFUN_NEW_FUNC(Finfinity);
1000 for (i = 0; i < saVars.size(); ++i) {
1001 if (saVars[i] == sBody) {
1002 return std::make_shared<Fvar<T>>(sBody, i);
1006 size_t nLeft = sBody.find_first_of(pccSigns, 0);
1007 __tassign(sLeft, sBody, 0, nLeft);
1009 if (sLeft.length() == 0) {
1010 throw cvmexception(
CFUN_PARSEERROR, sBody.c_str(), __format_vars(saVars).c_str());
1014 return CFUN_NEW_FUNC(Fexp, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1016 return CFUN_NEW_FUNC(Fsqrt, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1018 return CFUN_NEW_FUNC(Flog, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1020 return CFUN_NEW_FUNC(Flog10, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1022 return CFUN_NEW_FUNC(Fsin, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1024 return CFUN_NEW_FUNC(Fcos, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1026 return CFUN_NEW_FUNC(Ftan, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1028 return CFUN_NEW_FUNC(Fasin, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1030 return CFUN_NEW_FUNC(Facos, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1032 return CFUN_NEW_FUNC(Fatan, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1034 return CFUN_NEW_FUNC(Fsinh, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1036 return CFUN_NEW_FUNC(Fcosh, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1038 return CFUN_NEW_FUNC(Ftanh, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1040 return CFUN_NEW_FUNC(Fsinint, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1042 return CFUN_NEW_FUNC(Fcosint, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1044 return CFUN_NEW_FUNC(Fsign, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1046 return CFUN_NEW_FUNC(Fabs, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1048 return CFUN_NEW_FUNC(Fiif, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1050 return CFUN_NEW_FUNC(Fdelta, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1052 return CFUN_NEW_FUNC(Fpower, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1054 return CFUN_NEW_FUNC(Fsat, sBody, nLeft, nBodyLength, saVars, saParameters, saMeanings);
1055 else if (sLeft ==
CFUN_I)
1056 return CFUN_NEW_FUNC(Fconst, T(1));
1058 throw cvmexception(
CFUN_PARSEERROR, sLeft.c_str(), __format_vars(saVars).c_str());
1059 return CFUN_NEW_FUNC(Fconst, T(0));
1070 template <
typename T>
1078 virtual int _depth(
bool)
const = 0;
1099 virtual int _kind()
const = 0;
1100 virtual T _value(
const T* pdVars)
const = 0;
1102 virtual BasePointer _deriv(
size_t nVarNum)
const = 0;
1103 virtual bool _equals(
const BasePointer& pfSrc)
const = 0;
1104 virtual std::string _format(
int nPrecision)
const = 0;
1106 virtual bool is_valid()
const {
1118 pRet = this->_clone();
1124 pRet = this->_simpl();
1139 template <
typename T>
1148 virtual int _depth(
bool)
const = 0;
1174 :
mf0(std::move(rfSrc.
mf0))
1187 :
mf0(std::move(pfSrc))
1195 const string_array& saParameters,
const string_array& saMeanings)
1196 :
mf0(
FunctionFactory<T>::compile(sArg, 0, sArg.length(), saVars, saParameters, saMeanings))
1203 UnaryFunction(
const std::string& sArg,
size_t nF,
size_t nL,
const string_array& saVars,
1204 const string_array& saParameters,
const string_array& saMeanings)
1223 mf0 = std::move(rfSrc.mf0);
1228 virtual int _kind()
const = 0;
1229 virtual T _value(
const T* pdVars)
const = 0;
1231 virtual BasePointer _deriv(
size_t nVarNum)
const = 0;
1232 virtual const char* _name()
const = 0;
1234 bool _equals(
const BasePointer& pfSrc)
const override
1238 this->_kind() == pfSrc->_kind() &&
1239 mf0->_equals(pfSrc->_getArg(0));
1242 BasePointer _getArg(
size_t nArgNum)
const override
1244 return nArgNum ?
nullptr :
mf0;
1247 std::string _format(
int nPrecision)
const override
1249 std::ostringstream osBuf;
1263 template <
typename T>
1271 void BinCtr(
const std::string& sBodyCommaBody,
1272 size_t nFirst,
size_t nLast,
1273 const string_array& saVars,
1274 const string_array& saParameters,
const string_array& saMeanings)
throw(
cvmexception)
1276 std::string sLeft, sRight;
1277 if (__separate(sBodyCommaBody, nFirst, nLast, sLeft, sRight) == 1) {
1287 virtual int _depth(
bool)
const = 0;
1313 mf1(std::move(rfSrc.
mf1))
1339 const string_array& saVars,
1340 const string_array& saParameters,
const string_array& saMeanings)
1341 :
UnaryFunction<T>(sArg1, 0, sArg1.length(), saVars, saParameters, saMeanings),
1342 mf1(
FunctionFactory<T>::compile(sArg2, 0, sArg2.length(), saVars, saParameters, saMeanings))
1350 size_t nF1,
size_t nL1,
size_t nF2,
size_t nL2,
1351 const string_array& saVars,
1352 const string_array& saParameters,
const string_array& saMeanings)
1353 :
UnaryFunction<T>(sArgs, nF1, nL1, saVars, saParameters, saMeanings),
1362 const string_array& saVars,
1363 const string_array& saParameters,
const string_array& saMeanings)
1366 std::string sArg1, sArg2;
1367 if (__separate(sArg, nFirst, nLast, sArg1, sArg2) == 1) {
1388 this->
mf0 = std::move(rfSrc.mf0);
1389 this->
mf1 = std::move(rfSrc.mf1);
1394 virtual int _kind()
const = 0;
1395 virtual T _value(
const T* pdVars)
const = 0;
1397 virtual BasePointer _deriv(
size_t nVarNum)
const = 0;
1398 virtual std::string _format(
int nPrecision)
const = 0;
1400 bool _equals(
const BasePointer& pfSrc)
const override
1402 return pfSrc && this->
mf0 && this->
mf1 &&
1403 this->_kind() == pfSrc->_kind() &&
1404 this->
mf0->_equals(pfSrc->_getArg(0)) &&
1405 this->
mf1->_equals(pfSrc->_getArg(1));
1408 BasePointer _getArg(
size_t nArgNum)
const override
1410 return nArgNum ? this->
mf1 : this->
mf0;
1413 const char* _name()
const override
1418 static const char sz_exp[] =
"";
1426 template <
typename T>
1433 int _kind()
const override {
1440 BasePointer _simpl()
const override {
1441 return this->_clone();
1444 int _depth(
bool)
const override {
1455 Fconst(
const Fconst& rfSrc)
1457 mdConst(rfSrc.mdConst),
1458 mbValid(rfSrc.mbValid)
1462 Fconst(
const T& rdSrc)
1468 Fconst(
const std::string& sConst,
bool bThrow =
true)
1470 mbValid(Helper<T>::convert(sConst, mdConst, bThrow))
1474 bool is_valid()
const override {
1478 T _value(
const T*)
const override {
1482 BasePointer _clone()
const override {
1483 return std::make_shared<Fconst<T>>(*this);
1486 BasePointer _deriv(
size_t)
const override {
1487 return std::make_shared<Fconst<T>>();
1490 std::string _format(
int nPrecision)
const override {
1491 return Helper<T>::_format(mdConst, nPrecision);
1494 bool _equals(
const BasePointer& pfSrc)
const override {
1495 return this->_kind() == pfSrc->_kind() && Comparator<T,T>::eq(mdConst, pfSrc->_value(
nullptr));
1500 template<
typename U>
1503 static std::string _format(
const U& v,
int nPrecision)
1505 std::ostringstream osBuf;
1506 if (nPrecision > 0) {
1507 osBuf.precision(nPrecision);
1508 osBuf.setf(std::ios::scientific | std::ios::showpoint | std::ios::left);
1518 static bool convert(
const std::string& s, U& u,
bool bThrow)
throw(
cvmexception)
1520 bool ret = __parse_num<U>(s, u);
1521 if (bThrow && !ret) {
1528 template<
typename U>
1529 class Helper<std::complex<U> > {
1530 typedef std::complex<U> UC;
1532 static std::string _format(
const UC& v,
int nPrecision)
1534 std::ostringstream osBuf;
1535 if (nPrecision > 0) {
1536 osBuf.precision(nPrecision);
1537 osBuf.setf(std::ios::scientific | std::ios::showpoint | std::ios::left);
1542 static bool convert(
const std::string& s, UC& uc,
bool bThrow)
throw(
cvmexception)
1544 bool ret1 =
true, ret2 =
true;
1545 std::string sRe, sIm;
1546 if (__separate(s, 0, s.length(), sRe, sIm) == 1) {
1548 ret1 = __parse_num<U>(sRe, re);
1549 if (bThrow && !ret1) {
1552 ret2 = __parse_num<U>(sIm, im);
1553 if (bThrow && !ret2) {
1560 ret1 = __parse_num<U>(s, re);
1561 if (bThrow && !ret1) {
1566 return ret1 && ret2;
1572 template <
typename T>
1576 int _kind()
const override {
1583 BasePointer _simpl()
const override {
1584 return this->_clone();
1587 int _depth(
bool)
const override {
1597 T _value(
const T*)
const override {
1598 return basic_cvmMachMax<T>();
1601 BasePointer _clone()
const {
1602 return std::make_shared<Finfinity<T>>();
1605 BasePointer _deriv(
size_t)
const override {
1606 return this->_clone();
1609 std::string _format(
int)
const override {
1613 bool _equals(
const BasePointer& pfSrc)
const override {
1614 return this->_kind() == pfSrc->_kind();
1618 template <
typename T>
1622 int _kind()
const override {
1629 BasePointer _simpl()
const override {
1630 return this->_clone();
1633 int _depth(
bool)
const override {
1643 T _value(
const T*)
const override {
1644 return -basic_cvmMachMax<T>();
1647 BasePointer _clone()
const override {
1648 return std::make_shared<Fmninfinity<T>>();
1651 BasePointer _deriv(
size_t)
const override {
1652 return this->_clone();
1655 std::string _format(
int)
const override {
1659 bool _equals(
const BasePointer& pfSrc)
const override {
1660 return this->_kind() == pfSrc->_kind();
1664 template <
typename T>
1668 int _kind()
const override {
1673 int _depth(
bool bAcquire)
const override
1676 return bAcquire ? ++nDepth : --nDepth;
1680 typedef shared_ptr_pair<BaseFunction<T>> PointerPair;
1682 BasePointer _simpl()
const override
1685 BasePointer fZero = std::make_shared<Fconst<T>>();
1686 PointerPair fCopy(this->mf0->_simp(), this->mf1->_simp());
1688 for (i = 0; i <= 1; ++i)
1690 if (fCopy[i]->_equals(fZero))
1692 return fCopy[__not(i)];
1695 for (i = 0; i <= 1; ++i)
1699 return std::make_shared<Finfinity<T>>();
1702 for (i = 0; i <= 1; ++i)
1706 return std::make_shared<Fmninfinity<T>>();
1712 return std::make_shared<Fconst<T>>(fCopy[0]->_value(
nullptr) + fCopy[1]->_value(
nullptr));
1714 for (i = 0; i <= 1; ++i)
1718 T val = fCopy[i]->_value(
nullptr);
1721 return std::make_shared<Fminus<T>>(fCopy[__not(i)], std::make_shared<Fconst<T>>(-val))->_simp();
1725 if (fCopy[0]->_equals(fCopy[1]))
1727 return std::make_shared<Fmult<T>>(std::make_shared<Fconst<T>>(
CFUN_M_TWO), fCopy[0])->_simp();
1730 for (i = 0; i <= 1; ++i)
1734 return std::make_shared<Fminus<T>>(fCopy[__not(i)], fCopy[i]->_getArg(0))->_simp();
1741 for (i = 0; i <= 1; ++i)
1743 for (j = 0; j <= 1; ++j)
1745 if (fCopy[0]->_getArg(i)->_equals(fCopy[1]->_getArg(j)))
1748 std::make_shared<Fmult<T>>(fCopy[0]->_getArg(i),
1749 std::make_shared<Fplus<T>>(fCopy[0]->_getArg(__not(i)),
1750 fCopy[1]->_getArg(__not(j))))->_simp();
1755 for (j = 0; j <= 1; ++j)
1759 for (i = 0; i <= 1; ++i)
1761 if (fCopy[j]->_getArg(i)->_equals(fCopy[__not(j)]))
1764 std::make_shared<Fmult<T>>(fCopy[__not(j)],
1765 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(__not(i)),
1766 std::make_shared<Fconst<T>>(
CFUN_M_ONE)))->_simp();
1773 fCopy[0]->_getArg(1)->_equals(fCopy[1]->_getArg(1)))
1776 std::make_shared<Fdiv<T>>(std::make_shared<Fplus<T>>(fCopy[0]->_getArg(0),
1777 fCopy[1]->_getArg(0)),
1778 fCopy[0]->_getArg(1))->_simp();
1780 for (j = 0; j <= 1; ++j)
1784 for (i = 0; i <= 1; ++i)
1787 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(i),
1789 BasePointer fTmps(fTmp->_simp());
1790 if (!fTmp->_equals(fTmps))
1793 std::make_shared<Fplus<T>>(fTmps,
1794 fCopy[j]->_getArg(__not(i)))->_simp();
1799 for (i = 0; i <= 1; ++i)
1801 for (k = 0; k <= 1; ++k)
1804 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(i),
1805 fCopy[__not(j)]->_getArg(k));
1806 BasePointer fTmps(fTmp->_simp());
1807 if (!fTmp->_equals(fTmps))
1810 std::make_shared<Fplus<T>>(fTmps,
1811 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(__not(i)),
1812 fCopy[__not(j)]->_getArg(__not(k))))->_simp();
1819 for (i = 0; i <= 1; ++i)
1822 std::make_shared<Fminus<T>>(fCopy[j]->_getArg(i),
1823 fCopy[__not(j)]->_getArg(1));
1824 BasePointer fTmps(fTmp->_simp());
1825 if (!fTmp->_equals(fTmps))
1828 std::make_shared<Fplus<T>>(fTmps,
1829 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(__not(i)),
1830 fCopy[__not(j)]->_getArg(0)))->_simp();
1833 for (i = 0; i <= 1; ++i)
1836 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(i),
1837 fCopy[__not(j)]->_getArg(0));
1838 BasePointer fTmps(fTmp->_simp());
1839 if (!fTmp->_equals(fTmps))
1842 std::make_shared<Fplus<T>>(fTmps,
1843 std::make_shared<Fminus<T>>(fCopy[j]->_getArg(__not(i)),
1844 fCopy[__not(j)]->_getArg(1)))->_simp();
1853 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(0),
1855 BasePointer fTmps(fTmp->_simp());
1856 if (!fTmp->_equals(fTmps))
1859 std::make_shared<Fminus<T>>(fTmps,
1860 fCopy[j]->_getArg(1))->_simp();
1865 std::make_shared<Fminus<T>>(fCopy[__not(j)],
1866 fCopy[j]->_getArg(1));
1867 BasePointer fTmps(fTmp->_simp());
1868 if (!fTmp->_equals(fTmps))
1871 std::make_shared<Fplus<T>>(fTmps,
1872 fCopy[j]->_getArg(0))->_simp();
1878 for (i = 0; i <= 1; ++i)
1881 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(i),
1882 fCopy[__not(j)]->_getArg(i));
1883 BasePointer fTmps(fTmp->_simp());
1884 if (!fTmp->_equals(fTmps))
1888 std::make_shared<Fminus<T>>(std::make_shared<Fplus<T>>(fCopy[j]->_getArg(0),
1889 fCopy[__not(j)]->_getArg(0)),
1892 std::make_shared<Fminus<T>>(fTmps,
1893 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(1),
1894 fCopy[__not(j)]->_getArg(1)));
1895 return fTmp->_simp();
1899 std::make_shared<Fminus<T>>(fCopy[j]->_getArg(0),
1900 fCopy[__not(j)]->_getArg(1));
1901 BasePointer fTmps(fTmp->_simp());
1902 if (!fTmp->_equals(fTmps))
1905 std::make_shared<Fplus<T>>(std::make_shared<Fminus<T>>(fCopy[__not(j)]->_getArg(0),
1906 fCopy[j]->_getArg(1)),
1912 return std::make_shared<Fplus<T>>(fCopy[0], fCopy[1]);
1916 Fplus(
const BasePointer& pfSrc0,
const BasePointer& pfSrc1)
1921 Fplus(
const std::string& sAddend1,
const std::string& sAddend2,
1922 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
1923 :
BinaryFunction<T>(sAddend1, sAddend2, saVars, saParameters, saMeanings)
1927 Fplus(
const std::string& sArgs,
size_t nF1,
size_t nL1,
size_t nF2,
size_t nL2,
1928 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
1929 :
BinaryFunction<T>(sArgs, nF1, nL1, nF2, nL2, saVars, saParameters, saMeanings)
1933 T _value(
const T* pdVars)
const override {
1934 return this->mf0->_value(pdVars) + this->mf1->_value(pdVars);
1937 BasePointer _clone()
const override {
1938 return std::make_shared<Fplus<T>>(this->
mf0, this->
mf1);
1941 BasePointer _deriv(
size_t nVarNum)
const override
1944 std::make_shared<Fplus<T>>(this->mf0->_deriv(nVarNum),
1945 this->mf1->_deriv(nVarNum))->_simp();
1948 std::string _format(
int nPrecision)
const override
1950 std::ostringstream osBuf;
1951 osBuf << this->mf0->_format(nPrecision) <<
CFUN_SPLUS;
1956 osBuf << this->mf1->_format(nPrecision);
1962 template <
typename T>
1966 int _kind()
const override {
1971 int _depth(
bool bAcquire)
const override
1974 return bAcquire ? ++nDepth : --nDepth;
1978 typedef shared_ptr_pair<BaseFunction<T>> PointerPair;
1980 BasePointer _simpl()
const override
1983 BasePointer fZero = std::make_shared<Fconst<T>>();
1984 PointerPair fCopy(this->mf0->_simp(), this->mf1->_simp());
1985 if (fCopy[0]->_equals(fZero))
1987 return std::make_shared<Fuminus<T>>(fCopy[1])->_simp();
1989 if (fCopy[1]->_equals(fZero))
1995 return std::make_shared<Finfinity<T>>();
1999 return std::make_shared<Finfinity<T>>();
2003 return std::make_shared<Fmninfinity<T>>();
2007 return std::make_shared<Fmninfinity<T>>();
2012 return std::make_shared<Fconst<T>>(fCopy[0]->_value(
nullptr)-
2013 fCopy[1]->_value(
nullptr));
2015 if (fCopy[0]->_equals(fCopy[1]))
2017 return std::make_shared<Fconst<T>>();
2022 std::make_shared<Fuminus<T>>(std::make_shared<Fplus<T>>(fCopy[0]->_getArg(0),
2023 fCopy[1])->_simp())->_simp();
2028 std::make_shared<Fplus<T>>(fCopy[0],
2029 fCopy[1]->_getArg(0))->_simp();
2034 for (i = 0; i <= 1; ++i)
2036 for (j = 0; j <= 1; ++j)
2038 if (fCopy[0]->_getArg(i)->_equals(fCopy[1]->_getArg(j)))
2041 std::make_shared<Fmult<T>>(fCopy[0]->_getArg(i),
2042 std::make_shared<Fminus<T>>(fCopy[0]->_getArg(__not(i)),
2043 fCopy[1]->_getArg(__not(j))))->_simp();
2048 for (j = 0; j <= 1; ++j)
2052 for (i = 0; i <= 1; ++i)
2054 if (fCopy[j]->_getArg(i)->_equals(fCopy[__not(j)]))
2057 std::make_shared<Fmult<T>>(fCopy[__not(j)],
2059 std::make_shared<Fminus<T>>(std::make_shared<Fconst<T>>(
CFUN_M_ONE),
2060 fCopy[j]->_getArg(__not(i)))
2062 std::make_shared<Fminus<T>>(fCopy[j]->_getArg(__not(i)),
2064 return fTmp->_simp();
2071 fCopy[0]->_getArg(1)->_equals(fCopy[1]->_getArg(1)))
2074 std::make_shared<Fdiv<T>>(std::make_shared<Fminus<T>>(fCopy[0]->_getArg(0),
2075 fCopy[1]->_getArg(0)),
2076 fCopy[0]->_getArg(1))->_simp();
2078 for (j = 0; j <= 1; ++j)
2082 for (i = 0; i <= 1; ++i)
2084 BasePointer fTmp = std::make_shared<Fminus<T>>(fCopy[j]->_getArg(i),
2086 BasePointer fTmps(fTmp->_simp());
2087 if (!fTmp->_equals(fTmps))
2092 std::make_shared<Fminus<T>>(fTmps,
2093 fCopy[j]->_getArg(__not(i)))->_simp();
2097 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(__not(i)),
2104 for (i = 0; i <= 1; ++i)
2106 for (k = 0; k <= 1; ++k)
2108 BasePointer fTmp = std::make_shared<Fminus<T>>(fCopy[j]->_getArg(i),
2109 fCopy[__not(j)]->_getArg(k));
2110 BasePointer fTmps(fTmp->_simp());
2111 if (!fTmp->_equals(fTmps))
2114 std::make_shared<Fminus<T>>(fTmps,
2115 std::make_shared<Fplus<T>>(fCopy[j]->_getArg(__not(i)),
2116 fCopy[__not(j)]->_getArg(__not(k))))->_simp();
2126 std::make_shared<Fplus<T>>(fCopy[0],
2127 std::make_shared<Fminus<T>>(fCopy[1]->_getArg(1),
2128 fCopy[1]->_getArg(0)))->_simp();
2132 for (i = 0; i <= 1; ++i)
2134 BasePointer fTmp = std::make_shared<Fminus<T>>(fCopy[0]->_getArg(0),
2135 fCopy[1]->_getArg(i));
2136 BasePointer fTmps(fTmp->_simp());
2137 if (!fTmp->_equals(fTmps))
2140 std::make_shared<Fminus<T>>(fTmps,
2141 std::make_shared<Fplus<T>>(fCopy[0]->_getArg(1),
2142 fCopy[1]->_getArg(__not(i))))->_simp();
2145 for (i = 0; i <= 1; ++i)
2147 BasePointer fTmp = std::make_shared<Fplus<T>>(fCopy[0]->_getArg(1),
2148 fCopy[1]->_getArg(i));
2149 BasePointer fTmps(fTmp->_simp());
2150 if (!fTmp->_equals(fTmps))
2153 std::make_shared<Fminus<T>>(std::make_shared<Fminus<T>>(fCopy[0]->_getArg(0),
2154 fCopy[1]->_getArg(__not(i))),
2166 std::make_shared<Fplus<T>>(fCopy[0],
2167 std::make_shared<Fminus<T>>(fCopy[1]->_getArg(1),
2168 fCopy[1]->_getArg(0)))->_simp();
2173 BasePointer fTmp = std::make_shared<Fminus<T>>(fCopy[j]->_getArg(0),
2175 BasePointer fTmps(fTmp->_simp());
2176 if (!fTmp->_equals(fTmps))
2179 std::make_shared<Fminus<T>>(fTmps,
2180 fCopy[j]->_getArg(1))->_simp();
2185 BasePointer fTmp = std::make_shared<Fplus<T>>(fCopy[j]->_getArg(1),
2187 BasePointer fTmps(fTmp->_simp());
2188 if (!fTmp->_equals(fTmps))
2191 std::make_shared<Fminus<T>>(fCopy[j]->_getArg(0),
2198 return std::make_shared<Fminus<T>>(fCopy[0], fCopy[1]);
2202 Fminus(
const BasePointer& pfSrc0,
const BasePointer& pfSrc1)
2207 Fminus(
const std::string& sMinuend,
const std::string& sSubtrahend,
2208 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2209 :
BinaryFunction<T>(sMinuend, sSubtrahend, saVars, saParameters, saMeanings)
2213 Fminus(
const std::string& sArgs,
size_t nF1,
size_t nL1,
size_t nF2,
size_t nL2,
2214 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2215 :
BinaryFunction<T>(sArgs, nF1, nL1, nF2, nL2, saVars, saParameters, saMeanings)
2219 T _value(
const T* pdVars)
const override {
2220 return this->mf0->_value(pdVars) - this->mf1->_value(pdVars);
2223 BasePointer _clone()
const override {
2224 return std::make_shared<Fminus<T>>(this->
mf0, this->
mf1);
2227 BasePointer _deriv(
size_t nVarNum)
const override
2230 std::make_shared<Fminus<T>>(this->mf0->_deriv(nVarNum),
2231 this->mf1->_deriv(nVarNum))->_simp();
2234 std::string _format(
int nPrecision)
const override
2236 std::ostringstream osBuf;
2237 osBuf << this->mf0->_format(nPrecision) <<
CFUN_SMINUS;
2242 osBuf << this->mf1->_format(nPrecision);
2248 template <
typename T>
2252 int _kind()
const override {
2257 int _depth(
bool bAcquire)
const override
2260 return bAcquire ? ++nDepth : --nDepth;
2264 typedef shared_ptr_pair<BaseFunction<T>> PointerPair;
2266 BasePointer _simpl()
const override
2269 BasePointer fZero = std::make_shared<Fconst<T>>();
2270 BasePointer fOne = std::make_shared<Fconst<T>>(
CFUN_M_ONE);
2271 BasePointer fMOne = std::make_shared<Fconst<T>>(
CFUN_M_MONE);
2272 PointerPair fCopy(this->mf0->_simp(), this->mf1->_simp());
2273 for (i = 0; i <= 1; ++i)
2277 return std::make_shared<Finfinity<T>>();
2281 return std::make_shared<Fmninfinity<T>>();
2284 if (fCopy[0]->_equals(fZero) ||
2285 fCopy[1]->_equals(fZero))
2289 for (i = 0; i <= 1; ++i)
2291 if (fCopy[i]->_equals(fOne)) {
2292 return fCopy[__not(i)];
2295 for (i = 0; i <= 1; ++i)
2297 if (fCopy[i]->_equals(fMOne))
2300 std::make_shared<Fuminus<T>>(fCopy[__not(i)])->_simp();
2306 return std::make_shared<Fconst<T>>(fCopy[0]->_value(
nullptr) * fCopy[1]->_value(
nullptr));
2308 if (fCopy[0]->_equals(fCopy[1]))
2311 std::make_shared<Fpower<T>>(fCopy[0],
2312 std::make_shared<Fconst<T>>(
CFUN_M_TWO))->_simp();
2318 std::make_shared<Fmult<T>>(fCopy[0]->_getArg(0),
2319 fCopy[1]->_getArg(0))->_simp();
2321 for (i = 0; i <= 1; ++i)
2326 std::make_shared<Fuminus<T>>(std::make_shared<Fmult<T>>(fCopy[i]->_getArg(0),
2327 fCopy[__not(i)]))->_simp();
2332 fCopy[0]->_getArg(0)->_equals(fCopy[1]->_getArg(0)))
2335 std::make_shared<Fpower<T>>(fCopy[0]->_getArg(0),
2336 std::make_shared<Fplus<T>>(fCopy[0]->_getArg(1),
2337 fCopy[1]->_getArg(1)))->_simp();
2343 std::make_shared<Fexp<T>>(std::make_shared<Fplus<T>>(fCopy[0]->_getArg(0),
2344 fCopy[1]->_getArg(0)))->_simp();
2347 fCopy[0]->_getArg(0)->_equals(fCopy[1]))
2350 std::make_shared<Fpower<T>>(fCopy[1],
2351 std::make_shared<Fplus<T>>(fCopy[0]->_getArg(1),
2352 std::make_shared<Fconst<T>>(
CFUN_M_ONE)))->_simp();
2355 fCopy[1]->_getArg(0)->_equals(fCopy[0]))
2358 std::make_shared<Fpower<T>>(fCopy[0],
2359 std::make_shared<Fplus<T>>(fCopy[1]->_getArg(1),
2363 for (j = 0; j <= 1; ++j)
2367 for (i = 0; i <= 1; ++i)
2369 BasePointer fTmp = std::make_shared<Fmult<T>>(fCopy[j]->_getArg(i),
2371 BasePointer fTmps(fTmp->_simp());
2372 if (!fTmp->_equals(fTmps))
2375 std::make_shared<Fmult<T>>(fTmps,
2376 fCopy[j]->_getArg(__not(i)))->_simp();
2381 for (i = 0; i <= 1; ++i)
2383 for (k = 0; k <= 1; ++k)
2385 BasePointer fTmp = std::make_shared<Fmult<T>>(fCopy[j]->_getArg(i),
2386 fCopy[__not(j)]->_getArg(k));
2387 BasePointer fTmps(fTmp->_simp());
2388 if (!fTmp->_equals(fTmps))
2391 std::make_shared<Fmult<T>>(fTmps,
2392 std::make_shared<Fmult<T>>(fCopy[j]->_getArg(__not(i)),
2393 fCopy[__not(j)]->_getArg(__not(k))))->_simp();
2401 for (i = 0; i <= 1; ++i)
2403 BasePointer fTmp = std::make_shared<Fdiv<T>>(fCopy[j]->_getArg(i),
2404 fCopy[__not(j)]->_getArg(1));
2405 BasePointer fTmps(fTmp->_simp());
2406 if (!fTmp->_equals(fTmps))
2409 std::make_shared<Fmult<T>>(fTmps,
2410 std::make_shared<Fmult<T>>(fCopy[j]->_getArg(__not(i)),
2411 fCopy[__not(j)]->_getArg(0)))->_simp();
2414 for (i = 0; i <= 1; ++i)
2416 BasePointer fTmp = std::make_shared<Fmult<T>>(fCopy[j]->_getArg(i),
2417 fCopy[__not(j)]->_getArg(0));
2418 BasePointer fTmps(fTmp->_simp());
2419 if (!fTmp->_equals(fTmps))
2422 std::make_shared<Fmult<T>>(fTmps,
2423 std::make_shared<Fdiv<T>>(fCopy[j]->_getArg(__not(i)),
2424 fCopy[__not(j)]->_getArg(1)))->_simp();
2432 BasePointer fTmp = std::make_shared<Fmult<T>>(fCopy[j]->_getArg(0),
2434 BasePointer fTmps(fTmp->_simp());
2435 if (!fTmp->_equals(fTmps))
2438 std::make_shared<Fdiv<T>>(fTmps,
2439 fCopy[j]->_getArg(1))->_simp();
2443 BasePointer fTmp = std::make_shared<Fdiv<T>>(fCopy[__not(j)],
2444 fCopy[j]->_getArg(1));
2445 BasePointer fTmps(fTmp->_simp());
2446 if (!fTmp->_equals(fTmps))
2449 std::make_shared<Fmult<T>>(fTmps,
2450 fCopy[j]->_getArg(0))->_simp();
2456 for (i = 0; i <= 1; ++i)
2458 BasePointer fTmp = std::make_shared<Fmult<T>>(fCopy[j]->_getArg(i),
2459 fCopy[__not(j)]->_getArg(i));
2460 BasePointer fTmps(fTmp->_simp());
2461 if (!fTmp->_equals(fTmps))
2465 std::make_shared<Fdiv<T>>(std::make_shared<Fmult<T>>(fCopy[j]->_getArg(0),
2466 fCopy[__not(j)]->_getArg(0)),
2469 std::make_shared<Fdiv<T>>(fTmps,
2470 std::make_shared<Fmult<T>>(fCopy[j]->_getArg(1),
2471 fCopy[__not(j)]->_getArg(1)));
2472 return fTmp->_simp();
2475 BasePointer fTmp = std::make_shared<Fdiv<T>>(fCopy[j]->_getArg(0),
2476 fCopy[__not(j)]->_getArg(1));
2477 BasePointer fTmps(fTmp->_simp());
2478 if (!fTmp->_equals(fTmps))
2481 std::make_shared<Fmult<T>>(std::make_shared<Fdiv<T>>(fCopy[__not(j)]->_getArg(0),
2482 fCopy[j]->_getArg(1)),
2488 return std::make_shared<Fmult<T>>(fCopy[0], fCopy[1]);
2492 Fmult(
const BasePointer& pfSrc0,
const BasePointer& pfSrc1)
2497 Fmult(
const std::string& sMultiplicand,
const std::string& sMultiplier,
2498 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2499 :
BinaryFunction<T>(sMultiplicand, sMultiplier, saVars, saParameters, saMeanings)
2503 Fmult(
const std::string& sArgs,
size_t nF1,
size_t nL1,
size_t nF2,
size_t nL2,
2504 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2505 :
BinaryFunction<T>(sArgs, nF1, nL1, nF2, nL2, saVars, saParameters, saMeanings)
2509 T _value(
const T* pdVars)
const override {
2510 return this->mf0->_value(pdVars) * this->mf1->_value(pdVars);
2513 BasePointer _clone()
const override {
2514 return std::make_shared<Fmult<T>>(this->
mf0, this->
mf1);
2517 BasePointer _deriv(
size_t nVarNum)
const override
2520 std::make_shared<Fplus<T>>(std::make_shared<Fmult<T>>(this->mf0->_deriv(nVarNum),
2522 std::make_shared<Fmult<T>>(this->mf0,
2523 this->mf1->_deriv(nVarNum)))->_simp();
2526 std::string _format(
int nPrecision)
const override
2528 std::ostringstream osBuf;
2529 switch (this->mf0->_kind()) {
2535 osBuf << this->mf0->_format(nPrecision) <<
CFUN_SMULT;
2538 switch (this->mf1->_kind()) {
2545 osBuf << this->mf1->_format(nPrecision);
2552 template <
typename T>
2556 int _kind()
const override {
2561 int _depth(
bool bAcquire)
const override
2564 return bAcquire ? ++nDepth : --nDepth;
2568 typedef shared_ptr_pair<BaseFunction<T>> PointerPair;
2570 BasePointer _simpl()
const override
2573 BasePointer fZero = std::make_shared<Fconst<T>>();
2574 BasePointer fOne = std::make_shared<Fconst<T>>(
CFUN_M_ONE);
2575 BasePointer fMOne = std::make_shared<Fconst<T>>(
CFUN_M_MONE);
2576 PointerPair fCopy(this->mf0->_simp(), this->mf1->_simp());
2577 if (fCopy[0]->_equals(fZero))
2581 if (fCopy[1]->_equals(fZero))
2583 return std::make_shared<Finfinity<T>>();
2590 if (fCopy[1]->_equals(fOne))
2594 if (fCopy[1]->_equals(fMOne))
2596 return std::make_shared<Fuminus<T>>(fCopy[0]);
2601 T dNomin = fCopy[0]->_value(
nullptr);
2602 T dDenom = fCopy[1]->_value(
nullptr);
2607 return std::make_shared<Fmninfinity<T>>();
2611 return std::make_shared<Finfinity<T>>();
2616 return std::make_shared<Fconst<T>>(dNomin / dDenom);
2619 if (fCopy[0]->_equals(fCopy[1]))
2621 return std::make_shared<Fconst<T>>(
CFUN_M_ONE);
2627 std::make_shared<Fdiv<T>>(fCopy[0]->_getArg(0),
2628 fCopy[1]->_getArg(0))->_simp();
2630 for (i = 0; i <= 1; ++i)
2636 std::make_shared<Fuminus<T>>(std::make_shared<Fdiv<T>>(fCopy[__not(i)],
2637 fCopy[i]->_getArg(0)))
2639 std::make_shared<Fuminus<T>>(std::make_shared<Fdiv<T>>(fCopy[i]->_getArg(0),
2641 return fTmp->_simp();
2646 fCopy[0]->_getArg(0)->_equals(fCopy[1]->_getArg(0)))
2649 std::make_shared<Fpower<T>>(fCopy[0]->_getArg(0),
2650 std::make_shared<Fminus<T>>(fCopy[0]->_getArg(1),
2651 fCopy[1]->_getArg(1)))->_simp();
2654 fCopy[0]->_getArg(0)->_equals(fCopy[1]))
2657 std::make_shared<Fpower<T>>(fCopy[1],
2658 std::make_shared<Fminus<T>>(fCopy[0]->_getArg(1),
2659 std::make_shared<Fconst<T>>(
CFUN_M_ONE)))->_simp();
2662 fCopy[1]->_getArg(0)->_equals(fCopy[0]))
2665 std::make_shared<Fpower<T>>(fCopy[0],
2666 std::make_shared<Fminus<T>>(std::make_shared<Fconst<T>>(
CFUN_M_ONE),
2667 fCopy[1]->_getArg(1)))->_simp();
2670 for (j = 0; j <= 1; ++j)
2674 for (i = 0; i <= 1; ++i)
2676 BasePointer pNum = fCopy[j]->_getArg(i);
2677 BasePointer pDen = fCopy[__not(j)];
2678 BasePointer fTmp = std::make_shared<Fdiv<T>>(j ? pDen : pNum,
2680 BasePointer fTmps(fTmp->_simp());
2681 if (!fTmp->_equals(fTmps))
2686 std::make_shared<Fdiv<T>>(fTmps,
2687 fCopy[j]->_getArg(__not(i)))->_simp();
2692 std::make_shared<Fmult<T>>(fCopy[j]->_getArg(__not(i)),
2699 for (i = 0; i <= 1; ++i)
2701 for (k = 0; k <= 1; ++k)
2703 BasePointer fTmp = std::make_shared<Fdiv<T>>(fCopy[j]->_getArg(i),
2704 fCopy[__not(j)]->_getArg(k));
2705 BasePointer fTmps(fTmp->_simp());
2706 if (!fTmp->_equals(fTmps))
2709 std::make_shared<Fdiv<T>>(fTmps,
2710 std::make_shared<Fmult<T>>(fCopy[j]->_getArg(__not(i)),
2711 fCopy[__not(j)]->_getArg(__not(k))))->_simp();
2722 std::make_shared<Fmult<T>>(fCopy[0],
2723 std::make_shared<Fdiv<T>>(fCopy[1]->_getArg(1),
2724 fCopy[1]->_getArg(0)))->_simp();
2728 for (i = 0; i <= 1; ++i)
2730 BasePointer fTmp = std::make_shared<Fdiv<T>>(fCopy[0]->_getArg(0),
2731 fCopy[1]->_getArg(i));
2732 BasePointer fTmps(fTmp->_simp());
2733 if (!fTmp->_equals(fTmps))
2736 std::make_shared<Fdiv<T>>(fTmps,
2737 std::make_shared<Fmult<T>>(fCopy[0]->_getArg(1),
2738 fCopy[1]->_getArg(__not(i))))->_simp();
2741 for (i = 0; i <= 1; ++i)
2743 BasePointer fTmp = std::make_shared<Fmult<T>>(fCopy[0]->_getArg(1),
2744 fCopy[1]->_getArg(i));
2745 BasePointer fTmps(fTmp->_simp());
2746 if (!fTmp->_equals(fTmps))
2749 std::make_shared<Fdiv<T>>(std::make_shared<Fdiv<T>>(fCopy[0]->_getArg(0),
2750 fCopy[1]->_getArg(__not(i))),
2762 std::make_shared<Fmult<T>>(fCopy[0],
2763 std::make_shared<Fdiv<T>>(fCopy[1]->_getArg(1),
2764 fCopy[1]->_getArg(0)))->_simp();
2769 BasePointer fTmp = std::make_shared<Fdiv<T>>(fCopy[j]->_getArg(0),
2771 BasePointer fTmps(fTmp->_simp());
2772 if (!fTmp->_equals(fTmps))
2775 std::make_shared<Fdiv<T>>(fTmps,
2776 fCopy[j]->_getArg(1))->_simp();
2780 BasePointer fTmp = std::make_shared<Fmult<T>>(fCopy[j]->_getArg(1),
2782 BasePointer fTmps(fTmp->_simp());
2783 if (!fTmp->_equals(fTmps))
2786 std::make_shared<Fdiv<T>>(fCopy[j]->_getArg(0),
2793 return std::make_shared<Fdiv<T>>(fCopy[0], fCopy[1]);
2797 Fdiv(
const BasePointer& pfSrc0,
const BasePointer& pfSrc1)
2802 Fdiv(
const std::string& sDividend,
const std::string& sDivisor,
2803 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2804 :
BinaryFunction<T>(sDividend, sDivisor, saVars, saParameters, saMeanings)
2808 Fdiv(
const std::string& sArgs,
size_t nF1,
size_t nL1,
size_t nF2,
size_t nL2,
2809 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2810 :
BinaryFunction<T>(sArgs, nF1, nL1, nF2, nL2, saVars, saParameters, saMeanings)
2814 T _value(
const T* pdVars)
const override
2816 T dDenom = this->mf1->_value(pdVars);
2820 return this->mf0->_value(pdVars) / dDenom;
2823 BasePointer _clone()
const override {
2824 return std::make_shared<Fdiv<T>>(this->
mf0, this->
mf1);
2827 BasePointer _deriv(
size_t nVarNum)
const override
2830 std::make_shared<Fdiv<T>>(std::make_shared<Fminus<T>>(std::make_shared<Fmult<T>>(this->mf0->_deriv(nVarNum),
2832 std::make_shared<Fmult<T>>(this->mf0,
2833 this->mf1->_deriv(nVarNum))),
2834 std::make_shared<Fpower<T>>(this->
mf1,
2835 std::make_shared<Fconst<T>>(
CFUN_M_TWO)))->_simp();
2838 std::string _format(
int nPrecision)
const override
2840 std::ostringstream osBuf;
2841 switch (this->mf0->_kind()) {
2848 osBuf << this->mf0->_format(nPrecision) <<
CFUN_SDIV;
2851 switch (this->mf1->_kind()) {
2860 osBuf << this->mf1->_format(nPrecision);
2867 template <
typename T>
2871 int _kind()
const override {
2876 int _depth(
bool bAcquire)
const override
2879 return bAcquire ? ++nDepth : --nDepth;
2883 typedef shared_ptr_pair<BaseFunction<T>> PointerPair;
2885 BasePointer _simpl()
const override
2887 BasePointer fZero = std::make_shared<Fconst<T>>();
2888 BasePointer fOne = std::make_shared<Fconst<T>>(
CFUN_M_ONE);
2889 BasePointer fMOne = std::make_shared<Fconst<T>>(
CFUN_M_MONE);
2890 PointerPair fCopy(this->mf0->_simp(), this->mf1->_simp());
2891 if (fCopy[1]->_equals(fZero))
2895 else if (fCopy[0]->_equals(fZero))
2899 else if (fCopy[1]->_equals(fOne))
2907 std::make_shared<Fconst<T>>(std::pow(fCopy[0]->_value(
nullptr), fCopy[1]->_value(
nullptr)));
2909 else if (fCopy[1]->_equals(fMOne))
2912 std::make_shared<Fdiv<T>>(fOne,
2918 std::make_shared<Fpower<T>>(fCopy[0]->_getArg(0),
2919 std::make_shared<Fmult<T>>(fCopy[0]->_getArg(1),
2920 fCopy[1]))->_simp();
2922 return std::make_shared<Fpower<T>>(fCopy[0], fCopy[1]);
2926 Fpower(
const BasePointer& pfSrc0,
const BasePointer& pfSrc1)
2931 Fpower(
const std::string& sBasis,
const std::string& sExponent,
2932 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2933 :
BinaryFunction<T>(sBasis, sExponent, saVars, saParameters, saMeanings)
2937 Fpower(
const std::string& sBasisCommaExponent,
size_t nFirst,
size_t nLast,
2938 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2940 this->BinCtr(sBasisCommaExponent, nFirst, nLast, saVars, saParameters, saMeanings);
2943 Fpower(
const std::string& sArgs,
size_t nF1,
size_t nL1,
size_t nF2,
size_t nL2,
2944 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
2945 :
BinaryFunction<T>(sArgs, nF1, nL1, nF2, nL2, saVars, saParameters, saMeanings)
2949 T _value(
const T* pdVars)
const override {
2950 return std::pow(this->mf0->_value(pdVars), this->mf1->_value(pdVars));
2953 BasePointer _clone()
const override {
2954 return std::make_shared<Fpower<T>>(this->
mf0, this->
mf1);
2957 BasePointer _deriv(
size_t nVarNum)
const override
2960 std::make_shared<Fplus<T>>(std::make_shared<Fmult<T>>(this->mf0->_deriv(nVarNum),
2961 std::make_shared<Fmult<T>>(this->
mf1,
2962 std::make_shared<Fpower<T>>(this->
mf0,
2963 std::make_shared<Fplus<T>>(this->
mf1,
2965 std::make_shared<Fmult<T>>(this->mf1->_deriv(nVarNum),
2966 std::make_shared<Fmult<T>>(std::make_shared<Fpower<T>>(this->
mf0,
2968 std::make_shared<Flog<T>>(this->mf0))))->_simp();
2971 std::string _format(
int nPrecision)
const override
2973 std::ostringstream osBuf;
2974 switch (this->mf0->_kind()) {
2984 osBuf << this->mf0->_format(nPrecision) <<
CFUN_SPOWER;
2987 switch (this->mf1->_kind()) {
2997 osBuf << this->mf1->_format(nPrecision);
3004 template <
typename T>
3008 int _kind()
const override {
3013 int _depth(
bool bAcquire)
const override
3016 return bAcquire ? ++nDepth : --nDepth;
3020 typedef shared_ptr_pair<BaseFunction<T>> PointerPair;
3022 BasePointer _simpl()
const override
3024 BasePointer fZero = std::make_shared<Fconst<T>>();
3025 PointerPair fCopy(this->mf0->_simp(), this->mf1->_simp());
3026 if (fCopy[0]->_equals(fZero)) {
3029 return std::make_shared<Fsat<T>>(fCopy[0], fCopy[1]);
3033 Fsat(
const BasePointer& pfSrc0,
const BasePointer& pfSrc1)
3038 Fsat(
const std::string& sFun,
const std::string& sDelta,
3039 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3040 :
BinaryFunction<T>(sFun, sDelta, saVars, saParameters, saMeanings)
3044 Fsat(
const std::string& sFunCommaDelta,
size_t nFirst,
size_t nLast,
3045 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3047 this->BinCtr(sFunCommaDelta, nFirst, nLast, saVars, saParameters, saMeanings);
3050 Fsat(
const std::string& sArgs,
size_t nF1,
size_t nL1,
size_t nF2,
size_t nL2,
3051 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3052 :
BinaryFunction<T>(sArgs, nF1, nL1, nF2, nL2, saVars, saParameters, saMeanings)
3056 T _value(
const T* pdVars)
const override {
3057 return Helper<T>::_value(this->mf0.get(), this->mf1.get(), pdVars);
3060 BasePointer _clone()
const override {
3061 return std::make_shared<Fsat<T>>(this->
mf0, this->
mf1);
3064 BasePointer _deriv(
size_t)
const override
3067 std::make_shared<Fplus<T>>(std::make_shared<Fdelta<T>>(this->
mf0,
3069 std::make_shared<Fdelta<T>>(this->mf0,
3070 std::make_shared<Fuminus<T>>(this->mf1)))->_simp();
3073 std::string _format(
int nPrecision)
const override
3075 std::ostringstream osBuf;
3083 template<
typename U>
3089 const U dMeans = pfArg0->_value(pdVars);
3090 const U dDelta = cvm::_abs(pfArg1->_value(pdVars));
3091 if (dMeans > dDelta) {
3094 else if (dMeans < -dDelta) {
3101 template<
typename U>
3102 class Helper<std::complex<U> > {
3103 typedef std::complex<U> UC;
3108 const U dMeans = pfArg0->_value(pdVars).real();
3109 const U dDelta = cvm::_abs(pfArg1->_value(pdVars).real());
3110 if (dMeans > dDelta) {
3113 else if (dMeans < -dDelta) {
3122 template <
typename T>
3126 int _kind()
const override {
3131 int _depth(
bool bAcquire)
const override
3134 return bAcquire ? ++nDepth : --nDepth;
3139 BasePointer _simpl()
const override
3141 BasePointer fCopy(this->mf0->_simp());
3143 return std::make_shared<Fconst<T>>(std::exp(fCopy->_value(
nullptr)));
3145 return std::make_shared<Fexp<T>>(fCopy);
3149 Fexp(
const BasePointer& pfSrc)
3154 Fexp(
const std::string& sArg,
3155 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3160 Fexp(
const std::string& sArg,
size_t nF,
size_t nL,
3161 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3162 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3166 T _value(
const T* pdVars)
const override {
3167 return std::exp(this->mf0->_value(pdVars));
3170 BasePointer _clone()
const override {
3171 return std::make_shared<Fexp<T>>(this->
mf0);
3174 BasePointer _deriv(
size_t nVarNum)
const override
3177 std::make_shared<Fmult<T>>(this->mf0->_deriv(nVarNum),
3178 std::make_shared<Fexp<T>>(this->
mf0))->_simp();
3181 const char* _name()
const override
3183 static const char sz_exp[] =
CFUN_EXP;
3188 template <
typename T>
3192 int _kind()
const override {
3197 int _depth(
bool bAcquire)
const override
3200 return bAcquire ? ++nDepth : --nDepth;
3205 BasePointer _simpl()
const override
3207 BasePointer fCopy(this->mf0->_simp());
3209 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::sqrt(fCopy->_value(
nullptr)));
3211 return std::make_shared<Fsqrt<T>>(fCopy);
3215 Fsqrt(
const BasePointer& pfSrc)
3220 Fsqrt(
const std::string& sArg,
3221 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3226 Fsqrt(
const std::string& sArg,
size_t nF,
size_t nL,
3227 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3228 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3232 T _value(
const T* pdVars)
const override {
3233 return ElementaryFunctions<T>::sqrt(this->mf0->_value(pdVars));
3236 BasePointer _clone()
const override {
3237 return std::make_shared<Fsqrt<T>>(this->
mf0);
3240 BasePointer _deriv(
size_t nVarNum)
const override
3243 std::make_shared<Fdiv<T>>(this->mf0->_deriv(nVarNum),
3244 std::make_shared<Fmult<T>>(std::make_shared<Fconst<T>>(
CFUN_M_TWO),
3245 std::make_shared<Fsqrt<T>>(this->mf0)))->_simp();
3248 const char* _name()
const override
3250 static const char sz_sqrt[] =
CFUN_SQRT;
3255 template <
typename T>
3259 int _kind()
const override {
3264 int _depth(
bool bAcquire)
const override
3267 return bAcquire ? ++nDepth : --nDepth;
3272 BasePointer _simpl()
const override
3274 BasePointer fZero = std::make_shared<Fconst<T>>();
3275 BasePointer fCopy(this->mf0->_simp());
3276 if (fCopy->_equals(fZero))
3278 return std::make_shared<Fmninfinity<T>>();
3282 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::log(fCopy->_value(
nullptr)));
3287 std::make_shared<Fmult<T>>(std::make_shared<Flog<T>>(fCopy->_getArg(0)),
3288 std::make_shared<Fconst<T>>(
CFUN_M_HALF))->_simp();
3293 std::make_shared<Fmult<T>>(std::make_shared<Flog<T>>(fCopy->_getArg(0)),
3294 fCopy->_getArg(1))->_simp();
3296 return std::make_shared<Flog<T>>(fCopy);
3300 Flog(
const BasePointer& pfSrc)
3305 Flog(
const std::string& sArg,
3306 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3311 Flog(
const std::string& sArg,
size_t nF,
size_t nL,
3312 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3313 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3317 T _value(
const T* pdVars)
const override {
3318 return ElementaryFunctions<T>::log(this->mf0->_value(pdVars));
3321 BasePointer _clone()
const override {
3322 return std::make_shared<Flog<T>>(this->
mf0);
3325 BasePointer _deriv(
size_t nVarNum)
const override
3328 std::make_shared<Fdiv<T>>(this->mf0->_deriv(nVarNum),
3329 this->
mf0)->_simp();
3332 const char* _name()
const override
3334 static const char sz_log[] =
CFUN_LOG;
3339 template <
typename T>
3343 int _kind()
const override {
3348 int _depth(
bool bAcquire)
const override
3351 return bAcquire ? ++nDepth : --nDepth;
3356 BasePointer _simpl()
const override
3358 BasePointer fZero = std::make_shared<Fconst<T>>();
3359 BasePointer fCopy(this->mf0->_simp());
3360 if (fCopy->_equals(fZero))
3362 return std::make_shared<Fmninfinity<T>>();
3366 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::log10(fCopy->_value(
nullptr)));
3371 std::make_shared<Fmult<T>>(std::make_shared<Flog10<T>>(fCopy->_getArg(0)),
3372 std::make_shared<Fconst<T>>(
CFUN_M_HALF))->_simp();
3377 std::make_shared<Fmult<T>>(std::make_shared<Flog10<T>>(fCopy->_getArg(0)),
3378 fCopy->_getArg(1))->_simp();
3380 return std::make_shared<Flog10<T>>(fCopy);
3384 Flog10(
const BasePointer& pfSrc)
3389 Flog10(
const std::string& sArg,
3390 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3395 Flog10(
const std::string& sArg,
size_t nF,
size_t nL,
3396 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3397 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3401 T _value(
const T* pdVars)
const override {
3402 return ElementaryFunctions<T>::log10(this->mf0->_value(pdVars));
3405 BasePointer _clone()
const override {
3406 return std::make_shared<Flog10<T>>(*this);
3409 BasePointer _deriv(
size_t nVarNum)
const override
3412 std::make_shared<Fdiv<T>>(this->mf0->_deriv(nVarNum),
3413 std::make_shared<Fmult<T>>(std::make_shared<Fconst<T>>(
CFUN_M_LN_10),
3414 this->mf0))->_simp();
3417 const char* _name()
const override
3424 template <
typename T>
3428 int _kind()
const override {
3433 int _depth(
bool bAcquire)
const override
3436 return bAcquire ? ++nDepth : --nDepth;
3441 BasePointer _simpl()
const override
3443 BasePointer fCopy(this->mf0->_simp());
3445 return std::make_shared<Fconst<T>>(std::sin(fCopy->_value(
nullptr)));
3447 return std::make_shared<Fsin<T>>(fCopy);
3451 Fsin(
const BasePointer& pfSrc)
3456 Fsin(
const std::string& sArg,
3457 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3462 Fsin(
const std::string& sArg,
size_t nF,
size_t nL,
3463 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3464 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3468 T _value(
const T* pdVars)
const override {
3469 return std::sin(this->mf0->_value(pdVars));
3472 BasePointer _clone()
const override {
3473 return std::make_shared<Fsin<T>>(this->
mf0);
3476 BasePointer _deriv(
size_t nVarNum)
const override
3479 std::make_shared<Fmult<T>>(this->mf0->_deriv(nVarNum),
3480 std::make_shared<Fcos<T>>(this->
mf0))->_simp();
3483 const char* _name()
const override
3485 static const char sz_sin[] =
CFUN_SIN;
3490 template <
typename T>
3493 int _kind()
const override {
3498 int _depth(
bool bAcquire)
const override
3501 return bAcquire ? ++nDepth : --nDepth;
3506 BasePointer _simpl()
const override
3508 BasePointer fCopy(this->mf0->_simp());
3510 return std::make_shared<Fconst<T>>(std::cos(fCopy->_value(
nullptr)));
3512 return std::make_shared<Fcos<T>>(fCopy);
3516 Fcos(
const BasePointer& pfSrc)
3521 Fcos(
const std::string& sArg,
3522 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3527 Fcos(
const std::string& sArg,
size_t nF,
size_t nL,
3528 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3529 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3533 T _value(
const T* pdVars)
const override {
3534 return std::cos(this->mf0->_value(pdVars));
3537 BasePointer _clone()
const override {
3538 return std::make_shared<Fcos<T>>(this->
mf0);
3541 BasePointer _deriv(
size_t nVarNum)
const override
3544 std::make_shared<Fmult<T>>(this->mf0->_deriv(nVarNum),
3545 std::make_shared<Fuminus<T>>(std::make_shared<Fsin<T>>(this->
mf0)))->_simp();
3548 const char* _name()
const override
3550 static const char sz_cos[] =
CFUN_COS;
3555 template <
typename T>
3559 int _kind()
const override {
3564 int _depth(
bool bAcquire)
const override
3567 return bAcquire ? ++nDepth : --nDepth;
3572 BasePointer _simpl()
const override
3574 BasePointer fCopy(this->mf0->_simp());
3576 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::tan(fCopy->_value(
nullptr)));
3578 return std::make_shared<Ftan<T>>(fCopy);
3582 Ftan(
const BasePointer& pfSrc)
3587 Ftan(
const std::string& sArg,
3588 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3593 Ftan(
const std::string& sArg,
size_t nF,
size_t nL,
3594 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3595 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3599 T _value(
const T* pdVars)
const override {
3600 return ElementaryFunctions<T>::tan(this->mf0->_value(pdVars));
3603 BasePointer _clone()
const override {
3604 return std::make_shared<Ftan<T>>(this->
mf0);
3607 BasePointer _deriv(
size_t nVarNum)
const override
3610 std::make_shared<Fdiv<T>>(this->mf0->_deriv(nVarNum),
3611 std::make_shared<Fpower<T>>(std::make_shared<Fcos<T>>(this->
mf0),
3612 std::make_shared<Fconst<T>>(
CFUN_M_TWO)))->_simp();
3615 const char* _name()
const override
3617 static const char sz_tan[] =
CFUN_TAN;
3622 template <
typename T>
3626 int _kind()
const override {
3631 int _depth(
bool bAcquire)
const override
3634 return bAcquire ? ++nDepth : --nDepth;
3639 BasePointer _simpl()
const override
3641 BasePointer fCopy(this->mf0->_simp());
3643 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::asin(fCopy->_value(
nullptr)));
3645 return std::make_shared<Fasin<T>>(fCopy);
3649 Fasin(
const BasePointer& pfSrc)
3654 Fasin(
const std::string& sArg,
3655 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3660 Fasin(
const std::string& sArg,
size_t nF,
size_t nL,
3661 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3662 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3666 T _value(
const T* pdVars)
const override {
3667 return ElementaryFunctions<T>::asin(this->mf0->_value(pdVars));
3670 BasePointer _clone()
const override {
3671 return std::make_shared<Fasin<T>>(this->
mf0);
3674 BasePointer _deriv(
size_t nVarNum)
const override
3677 std::make_shared<Fdiv<T>>(this->mf0->_deriv(nVarNum),
3678 std::make_shared<Fsqrt<T>>(std::make_shared<Fminus<T>>(std::make_shared<Fconst<T>>(
CFUN_M_ONE),
3679 std::make_shared<Fpower<T>>(this->mf0,
3680 std::make_shared<Fconst<T>>(
CFUN_M_TWO)))))->_simp();
3683 const char* _name()
const override
3685 static const char sz_asin[] =
CFUN_ASIN;
3690 template <
typename T>
3694 int _kind()
const override {
3699 int _depth(
bool bAcquire)
const override
3702 return bAcquire ? ++nDepth : --nDepth;
3707 BasePointer _simpl()
const override
3709 BasePointer fCopy(this->mf0->_simp());
3711 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::acos(fCopy->_value(
nullptr)));
3713 return std::make_shared<Facos<T>>(fCopy);
3717 Facos(
const BasePointer& pfSrc)
3722 Facos(
const std::string& sArg,
3723 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3728 Facos(
const std::string& sArg,
size_t nF,
size_t nL,
3729 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3730 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3734 T _value(
const T* pdVars)
const override {
3735 return ElementaryFunctions<T>::acos(this->mf0->_value(pdVars));
3738 BasePointer _clone()
const override {
3739 return std::make_shared<Facos<T>>(this->
mf0);
3742 BasePointer _deriv(
size_t nVarNum)
const override
3745 std::make_shared<Fuminus<T>>(std::make_shared<Fasin<T>>(this->
mf0)->_deriv(nVarNum))->_simp();
3748 const char* _name()
const override
3750 static const char sz_acos[] =
CFUN_ACOS;
3755 template <
typename T>
3759 int _kind()
const override {
3764 int _depth(
bool bAcquire)
const override
3767 return bAcquire ? ++nDepth : --nDepth;
3772 BasePointer _simpl()
const override
3774 BasePointer fCopy(this->mf0->_simp());
3776 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::atan(fCopy->_value(
nullptr)));
3778 return std::make_shared<Fatan<T>>(fCopy);
3782 Fatan(
const BasePointer& pfSrc)
3787 Fatan(
const std::string& sArg,
3788 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3793 Fatan(
const std::string& sArg,
size_t nF,
size_t nL,
3794 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3795 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3799 T _value(
const T* pdVars)
const override {
3800 return ElementaryFunctions<T>::atan(this->mf0->_value(pdVars));
3803 BasePointer _clone()
const override {
3804 return std::make_shared<Fatan<T>>(this->
mf0);
3807 BasePointer _deriv(
size_t nVarNum)
const override
3810 std::make_shared<Fdiv<T>>(this->mf0->_deriv(nVarNum),
3811 std::make_shared<Fplus<T>>(std::make_shared<Fconst<T>>(
CFUN_M_ONE),
3812 std::make_shared<Fpower<T>>(this->mf0,
3813 std::make_shared<Fconst<T>>(
CFUN_M_TWO))))->_simp();
3816 const char* _name()
const override
3818 static const char sz_atan[] =
CFUN_ATAN;
3824 template <
typename T>
3828 int _kind()
const override {
3833 int _depth(
bool bAcquire)
const override
3836 return bAcquire ? ++nDepth : --nDepth;
3841 BasePointer _simpl()
const override
3843 BasePointer fCopy(this->mf0->_simp());
3845 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::sinh(fCopy->_value(
nullptr)));
3847 return std::make_shared<Fsinh<T>>(fCopy);
3851 Fsinh(
const BasePointer& pfSrc)
3856 Fsinh(
const std::string& sArg,
3857 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3862 Fsinh(
const std::string& sArg,
size_t nF,
size_t nL,
3863 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3864 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3868 T _value(
const T* pdVars)
const override {
3869 return ElementaryFunctions<T>::sinh(this->mf0->_value(pdVars));
3872 BasePointer _clone()
const override {
3873 return std::make_shared<Fsinh<T>>(this->
mf0);
3876 BasePointer _deriv(
size_t nVarNum)
const override
3879 std::make_shared<Fmult<T>>(this->mf0->_deriv(nVarNum),
3880 std::make_shared<Fcosh<T>>(this->
mf0))->_simp();
3883 const char* _name()
const override
3885 static const char sz_sinh[] =
CFUN_SINH;
3891 template <
typename T>
3895 int _kind()
const override {
3900 int _depth(
bool bAcquire)
const override
3903 return bAcquire ? ++nDepth : --nDepth;
3908 BasePointer _simpl()
const override
3910 BasePointer fCopy(this->mf0->_simp());
3912 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::cosh(fCopy->_value(
nullptr)));
3914 return std::make_shared<Fcosh<T>>(fCopy);
3918 Fcosh(
const BasePointer& pfSrc)
3923 Fcosh(
const std::string& sArg,
3924 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3929 Fcosh(
const std::string& sArg,
size_t nF,
size_t nL,
3930 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3931 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
3935 T _value(
const T* pdVars)
const override {
3936 return ElementaryFunctions<T>::cosh(this->mf0->_value(pdVars));
3939 BasePointer _clone()
const override {
3940 return std::make_shared<Fcosh<T>>(this->
mf0);
3943 BasePointer _deriv(
size_t nVarNum)
const override
3946 std::make_shared<Fmult<T>>(this->mf0->_deriv(nVarNum),
3947 std::make_shared<Fuminus<T>>(std::make_shared<Fsinh<T>>(this->
mf0)))->_simp();
3950 const char* _name()
const override
3952 static const char sz_cosh[] =
CFUN_COSH;
3958 template <
typename T>
3962 int _kind()
const override {
3967 int _depth(
bool bAcquire)
const override
3970 return bAcquire ? ++nDepth : --nDepth;
3975 BasePointer _simpl()
const override
3977 BasePointer fCopy(this->mf0->_simp());
3979 return std::make_shared<Fconst<T>>(ElementaryFunctions<T>::tanh(fCopy->_value(
nullptr)));
3981 return std::make_shared<Ftanh<T>>(fCopy);
3985 Ftanh(
const BasePointer& pfSrc)
3990 Ftanh(
const std::string& sArg,
3991 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3996 Ftanh(
const std::string& sArg,
size_t nF,
size_t nL,
3997 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
3998 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
4002 T _value(
const T* pdVars)
const override {
4003 return ElementaryFunctions<T>::tanh(this->mf0->_value(pdVars));
4006 BasePointer _clone()
const override {
4007 return std::make_shared<Ftanh<T>>(this->
mf0);
4010 BasePointer _deriv(
size_t nVarNum)
const override
4013 std::make_shared<Fdiv<T>>(this->mf0->_deriv(nVarNum),
4014 std::make_shared<Fpower<T>>(std::make_shared<Fcosh<T>>(this->
mf0),
4015 std::make_shared<Fconst<T>>(
CFUN_M_TWO)))->_simp();
4018 const char* _name()
const override
4020 static const char sz_tanh[] =
CFUN_TANH;
4025 template <
typename T>
4029 int _kind()
const override {
4034 int _depth(
bool bAcquire)
const override {
4036 return bAcquire ? ++nDepth : --nDepth;
4041 BasePointer _simpl()
const override
4043 BasePointer fCopy(this->mf0->_simp());
4045 return std::make_shared<Fconst<T>>(Helper<T>::_value(fCopy.get(),
nullptr));
4047 return std::make_shared<Fsinint<T>>(fCopy);
4051 Fsinint(
const BasePointer& pfSrc)
4056 Fsinint(
const std::string& sArg,
4057 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4062 Fsinint(
const std::string& sArg,
size_t nF,
size_t nL,
4063 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4064 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
4068 T _value(
const T* pdVars)
const override {
4069 return Helper<T>::_value(this->mf0.get(), pdVars);
4072 BasePointer _clone()
const override {
4073 return std::make_shared<Fsinint<T>>(this->
mf0);
4076 BasePointer _deriv(
size_t)
const override
4079 std::make_shared<Fdiv<T>>(std::make_shared<Fsin<T>>(this->
mf0),
4080 this->mf0)->_simp();
4083 const char* _name()
const override
4085 static const char sz_si[] =
CFUN_SI;
4091 template<
typename U>
4096 return ElementaryFunctions<U>::sinint(pfArg->_value(pdVars), basic_cvmMachSp<U>());
4099 template<
typename U>
4100 class Helper<std::complex<U> > {
4101 typedef std::complex<U> UC;
4105 return ElementaryFunctions<UC>::sinint(pfArg->_value(pdVars), basic_cvmMachSp<U>());
4111 template <
typename T>
4115 int _kind()
const override {
4120 int _depth(
bool bAcquire)
const override
4123 return bAcquire ? ++nDepth : --nDepth;
4128 BasePointer _simpl()
const override
4130 BasePointer fCopy(this->mf0->_simp());
4132 return std::make_shared<Fconst<T>>(Helper<T>::_value(fCopy.get(),
nullptr));
4134 return std::make_shared<Fcosint<T>>(fCopy);
4138 Fcosint(
const BasePointer& pfSrc)
4143 Fcosint(
const std::string& sArg,
4144 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4149 Fcosint(
const std::string& sArg,
size_t nF,
size_t nL,
4150 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4151 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
4155 T _value(
const T* pdVars)
const override {
4156 return Helper<T>::_value(this->mf0.get(), pdVars);
4159 BasePointer _clone()
const override {
4160 return std::make_shared<Fcosint<T>>(this->
mf0);
4163 BasePointer _deriv(
size_t)
const override
4166 std::make_shared<Fdiv<T>>(std::make_shared<Fcos<T>>(this->
mf0),
4167 this->mf0)->_simp();
4170 const char* _name()
const override
4172 static const char sz_ci[] =
CFUN_CI;
4178 template<
typename U>
4183 return ElementaryFunctions<U>::cosint(pfArg->_value(pdVars), basic_cvmMachSp<U>());
4186 template<
typename U>
4187 class Helper<std::complex<U> > {
4188 typedef std::complex<U> UC;
4192 return ElementaryFunctions<UC>::cosint(pfArg->_value(pdVars), basic_cvmMachSp<U>());
4198 template <
typename T>
4202 int _kind()
const override {
4207 int _depth(
bool bAcquire)
const override
4210 return bAcquire ? ++nDepth : --nDepth;
4215 BasePointer _simpl()
const override
4217 BasePointer fCopy(this->mf0->_simp());
4220 return fCopy->_getArg(0);
4224 return std::make_shared<Fmninfinity<T>>();
4228 return std::make_shared<Finfinity<T>>();
4232 return std::make_shared<Fconst<T>>(- fCopy->_value(
nullptr));
4237 std::make_shared<Fminus<T>>(fCopy->_getArg(1),
4242 for (
size_t i = 0; i <= 1; ++i)
4244 BasePointer fTmp = std::make_shared<Fuminus<T>>(fCopy->_getArg(i));
4245 BasePointer fTmps(fTmp->_simp());
4246 if (!fTmp->_equals(fTmps))
4249 std::make_shared<Fmult<T>>(fTmps,
4250 fCopy->_getArg(__not(i)))->_simp();
4256 for (
size_t i = 0; i <= 1; ++i)
4258 BasePointer fTmp = std::make_shared<Fuminus<T>>(fCopy->_getArg(i));
4259 BasePointer fTmps(fTmp->_simp());
4260 if (!fTmp->_equals(fTmps))
4264 std::make_shared<Fdiv<T>>(fCopy->_getArg(__not(i)),
4267 std::make_shared<Fdiv<T>>(fTmps,
4268 fCopy->_getArg(__not(i))));
4269 return fTmp->_simp();
4273 return std::make_shared<Fuminus<T>>(fCopy);
4277 Fuminus(
const BasePointer& pfSrc)
4282 Fuminus(
const std::string& sArg,
4283 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4288 Fuminus(
const std::string& sArg,
size_t nF,
size_t nL,
4289 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4290 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
4294 T _value(
const T* pdVars)
const override {
4295 return - this->mf0->_value(pdVars);
4298 BasePointer _clone()
const override {
4299 return std::make_shared<Fuminus<T>>(this->
mf0);
4302 std::string _format(
int nPrecision)
const override
4304 std::ostringstream osBuf;
4305 osBuf << this->_name();
4306 switch (this->mf0->_kind()) {
4313 osBuf << this->mf0->_format(nPrecision);
4319 BasePointer _deriv(
size_t nVarNum)
const override
4322 std::make_shared<Fuminus<T>>(this->mf0->_deriv(nVarNum))->_simp();
4325 const char* _name()
const override
4332 template <
typename T>
4336 int _kind()
const override {
4341 int _depth(
bool bAcquire)
const override
4344 return bAcquire ? ++nDepth : --nDepth;
4349 BasePointer _simpl()
const override
4351 BasePointer fCopy(this->mf0->_simp());
4354 return std::make_shared<Fconst<T>>(Helper<T>::_value(fCopy.get(),
nullptr));
4356 return std::make_shared<Fsign<T>>(fCopy);
4360 Fsign(
const BasePointer& pfSrc)
4365 Fsign(
const std::string& sArg,
4366 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4371 Fsign(
const std::string& sArg,
size_t nF,
size_t nL,
4372 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4373 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
4377 T _value(
const T* pdVars)
const override {
4378 return Helper<T>::_value(this->mf0.get(), pdVars);
4381 BasePointer _clone()
const override {
4382 return std::make_shared<Fsign<T>>(this->
mf0);
4385 BasePointer _deriv(
size_t)
const override
4388 std::make_shared<Fdelta<T>>(this->
mf0,
4389 std::make_shared<Fconst<T>>())->_simp();
4392 const char* _name()
const override
4394 static const char sz_sign[] =
CFUN_SIGN;
4400 template<
typename U>
4405 const U dV = pfArg->_value(pdVars);
4411 template<
typename U>
4412 class Helper<std::complex<U> > {
4413 typedef std::complex<U> UC;
4417 const U dV = pfArg->_value(pdVars).real();
4425 template <
typename T>
4429 int _kind()
const override {
4434 int _depth(
bool bAcquire)
const override
4437 return bAcquire ? ++nDepth : --nDepth;
4442 BasePointer _simpl()
const override
4444 BasePointer fCopy(this->mf0->_simp());
4446 return std::make_shared<Fconst<T>>(cvm::_abs(fCopy->_value(
nullptr)));
4451 return std::make_shared<Fabs<T>>(fCopy);
4455 Fabs(
const BasePointer& pfSrc)
4460 Fabs(
const std::string& sArg,
4461 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4466 Fabs(
const std::string& sArg,
size_t nF,
size_t nL,
4467 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4468 :
UnaryFunction<T>(sArg, nF, nL, saVars, saParameters, saMeanings)
4472 T _value(
const T* pdVars)
const override {
4473 return cvm::_abs(this->mf0->_value(pdVars));
4476 BasePointer _clone()
const override {
4477 return std::make_shared<Fabs<T>>(this->
mf0);
4480 BasePointer _deriv(
size_t nVarNum)
const override
4483 std::make_shared<Fmult<T>>(std::make_shared<Fsign<T>>(this->
mf0),
4484 this->mf0->_deriv(nVarNum))->_simp();
4487 const char* _name()
const override
4489 static const char sz_abs[] =
CFUN_ABS;
4494 template <
typename T>
4498 int _kind()
const override {
4503 int _depth(
bool bAcquire)
const override
4506 return bAcquire ? ++nDepth : --nDepth;
4510 typedef shared_ptr_pair<BaseFunction<T>> PointerPair;
4512 BasePointer _simpl()
const override
4514 PointerPair fCopy(this->mf0->_simp(), this->mf1->_simp());
4516 T dM1 = fCopy[0]->_value(
nullptr);
4517 T dM2 = fCopy[1]->_value(
nullptr);
4519 return std::make_shared<Finfinity<T>>();
4522 return std::make_shared<Fconst<T>>();
4525 return std::make_shared<Fdelta<T>>(fCopy[0], fCopy[1]);
4529 Fdelta(
const BasePointer& pfSrc0,
const BasePointer& pfSrc1)
4534 Fdelta(
const std::string& sArg1,
const std::string& sArg2,
4535 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4536 :
BinaryFunction<T>(sArg1, sArg2, saVars, saParameters, saMeanings)
4540 Fdelta(
const std::string& sArgs,
size_t nF1,
size_t nL1,
size_t nF2,
size_t nL2,
4541 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4542 :
BinaryFunction<T>(sArgs, nF1, nL1, nF2, nL2, saVars, saParameters, saMeanings)
4546 Fdelta(
const std::string& sArg,
size_t nFirst,
size_t nLast,
4547 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4548 :
BinaryFunction<T>(sArg, nFirst, nLast, saVars, saParameters, saMeanings)
4552 T _value(
const T* pdVars)
const override {
4553 return Helper<T>::_value(this->mf0.get(), this->mf1.get(), pdVars);
4556 BasePointer _clone()
const override {
4557 return std::make_shared<Fdelta<T>>(this->
mf0, this->
mf1);
4560 BasePointer _deriv(
size_t)
const override
4563 std::make_shared<Fdelta<T>>(this->
mf0,
4564 this->
mf1)->_simp();
4567 std::string _format(
int nPrecision)
const override
4569 std::ostringstream osBuf;
4577 template<
typename U>
4582 return cvm::_abs(pfArg0->_value(pdVars) - pfArg1->_value(pdVars)) <= basic_cvmMachMin<U>() ?
4587 template<
typename U>
4588 class Helper<std::complex<U> > {
4589 typedef std::complex<U> UC;
4593 return cvm::_abs((pfArg0->_value(pdVars) - pfArg1->_value(pdVars)).real()) <= basic_cvmMachMin<U>() ?
4600 template <
typename T>
4605 std::string msVarName;
4607 int _kind()
const override {
4612 int _depth(
bool)
const override {
4619 BasePointer _simpl()
const override
4621 return this->_clone();
4631 Fvar(
const Fvar<T>& rfSrc)
4632 : mnVarPos(rfSrc.mnVarPos),
4633 msVarName(rfSrc.msVarName)
4637 Fvar(std::string& sVN,
size_t nVP)
4643 T _value(
const T* pdVars)
const override
4645 if (pdVars ==
nullptr) {
4648 return pdVars[mnVarPos];
4651 BasePointer _clone()
const override {
4652 return std::make_shared<Fvar<T>>(*this);
4655 std::string _format(
int)
const override {
4659 BasePointer _deriv(
size_t nVarNum)
const override
4661 if (mnVarPos == nVarNum) {
4662 return std::make_shared<Fconst<T>>(
CFUN_M_ONE);
4664 return std::make_shared<Fconst<T>>();
4667 bool _equals(
const BasePointer& pfSrc)
const override
4669 return this->_kind() == pfSrc->_kind() &&
4671 mnVarPos ==
reinterpret_cast<const Fvar<T>*
>(pfSrc.get())->mnVarPos &&
4672 msVarName ==
reinterpret_cast<const Fvar<T>*
>(pfSrc.get())->msVarName;
4675 BasePointer _getArg(
size_t)
const override {
4680 template <
typename T>
4686 int _kind()
const override {
4694 void TriCtr(
const std::string& sBodyCommaBodyCommaBody,
size_t nFirst,
size_t nLast,
4695 const string_array& saVars,
4696 const string_array& saParameters,
const string_array& saMeanings)
throw(
cvmexception)
4698 std::string sF, sLeft, sRight;
4699 if (__separate(sBodyCommaBodyCommaBody, nFirst, nLast, sF, sRight) == 1) {
4701 if (__separate(sRight, 0, sRight.length(), sLeft, sRight) == 1) {
4710 int _depth(
bool bAcquire)
const override
4713 return bAcquire ? ++nDepth : --nDepth;
4716 BasePointer _simpl()
const override
4718 return std::make_shared<Fiif<T>>(this->mf0->_simp(), this->mpflt->_simp(), this->mpfge->_simp());
4722 Fiif(
const BasePointer& rfSrc,
const BasePointer& rfLT,
const BasePointer& rfGE)
4729 Fiif(
const std::string& sBody,
4730 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4734 TriCtr(sBody, 0, sBody.length(), saVars, saParameters, saMeanings);
4737 Fiif(
const std::string& sBody,
size_t nFirst,
size_t nLast,
4738 const string_array& saVars,
const string_array& saParameters,
const string_array& saMeanings)
4742 TriCtr(sBody, nFirst, nLast, saVars, saParameters, saMeanings);
4745 T _value(
const T* pdVars)
const override {
4746 return Helper<T>::left(this->mf0.get(), pdVars) ? this->mpflt->_value(pdVars) :
4747 this->mpfge->_value(pdVars);
4750 BasePointer _clone()
const override {
4751 return std::make_shared<Fiif<T>>(*this);
4754 BasePointer _deriv(
size_t nVarNum)
const override
4757 std::make_shared<Fiif<T>>(this->
mf0, this->mpflt->_deriv(nVarNum), this->mpfge->_deriv(nVarNum));
4760 std::string _format(
int nPrecision)
const override
4762 std::ostringstream osBuf;
4764 this->mpflt->_format(nPrecision) <<
CFUN_SCOMMA <<
4769 const char* _name()
const override
4771 static const char sz_iif[] =
CFUN_IIF;
4777 template<
typename U>
4786 template<
typename U>
4787 class Helper<std::complex<U> > {
4788 typedef std::complex<U> UC;
4792 return pfArg0->_value(pdVars).real() <
CFUN_M_ZERO;
4918 template <
typename T>
4929 const string_array& _check_vars(
const string_array& saVars)
const throw(
cvmexception)
4931 if (this->
vars_num() > 0 && saVars.size() > 0 && !__arrays_equal(
mvars, saVars)) {
4945 :
mvars(std::move(saVars)),
4977 mp(std::make_shared<Fconst<T>>())
5010 mp(std::make_shared<Fconst<T>>())
5043 mp(std::make_shared<Fconst<T>>(dConst))
5081 mp(std::move(rf.
mp))
5125 string_array saParameters, saMeanings;
5129 __parse_vars(sInput, nAF + 1, nAL,
mvars);
5178 string_array saParameters, saMeanings;
5229 const string_array& saParameters,
const string_array& saMeanings)
5278 return mvars.size();
5312 return mp->_value(pd);
5347 return mp->_value(pd);
5380 return mp->_value(&d);
5417 return mp->_value(dVals);
5451 return mp->_value(dVals);
5493 static const T dZero = T();
5494 return mp->_value(&dZero);
5530 std::string
format(
int nPrecision = 0)
const {
5531 return mp->_format(nPrecision);
5570 std::stringstream stream;
5571 std::string
vars = __format_vars(this->
mvars,
false);
5572 if (vars.size() > 0) {
5575 stream <<
mp->_format(nPrecision);
5576 return stream.str();
5748 if (
mp != rfSrc.
mp) {
5761 if (
mp != rfSrc.mp) {
5763 mvars = std::move(rfSrc.mvars);
5764 mp = std::move(rfSrc.mp);
5800 mp = std::make_shared<Fconst<T>>(rdSrc);
5863 return basic_function(this->_check_vars(rf.mvars), std::make_shared<Fplus<T>>(
mp, rf.mp));
5897 return basic_function(this->_check_vars(rf.mvars), std::make_shared<Fminus<T>>(
mp, rf.mp));
5935 return basic_function(this->_check_vars(rf.mvars), std::make_shared<Fmult<T>>(
mp, rf.mp));
5973 return basic_function(this->_check_vars(rf.mvars), std::make_shared<Fdiv<T>>(
mp, rf.mp));
6007 return basic_function(this->_check_vars(rf.mvars), std::make_shared<Fpower<T>>(
mp, rf.mp));
6045 mvars = this->_check_vars(rf.mvars);
6046 mp = std::make_shared<Fplus<T>>(
mp, rf.mp);
6085 mvars = this->_check_vars(rf.mvars);
6086 mp = std::make_shared<Fminus<T>>(
mp, rf.mp);
6129 mvars = this->_check_vars(rf.mvars);
6130 mp = std::make_shared<Fmult<T>>(
mp, rf.mp);
6173 mvars = this->_check_vars(rf.mvars);
6174 mp = std::make_shared<Fdiv<T>>(
mp, rf.mp);
6345 mp = std::make_shared<Fplus<T>>(
mp, std::make_shared<Fconst<T>>(d));
6376 mp = std::make_shared<Fminus<T>>(
mp, std::make_shared<Fconst<T>>(d));
6411 mp = std::make_shared<Fmult<T>>(
mp, std::make_shared<Fconst<T>>(d));
6446 mp = std::make_shared<Fdiv<T>>(
mp, std::make_shared<Fconst<T>>(d));
6477 mp = std::make_shared<Fpower<T>>(
mp, std::make_shared<Fconst<T>>(d));
6541 return basic_function(this->_check_vars(rf.mvars), std::make_shared<Fsat<T>>(
mp, rf.mp));
7150 return basic_function(this->_check_vars(rf.mvars), std::make_shared<Fdelta<T>>(
mp, rf.mp));
7214 const string_array& saVarsT = this->_check_vars(rfNeg.mvars);
7215 const string_array& saVarsF = this->_check_vars(rfNotNeg.mvars);
7216 const string_array& saVars = saVarsT.size() > saVarsF.size() ? saVarsT : saVarsF;
7217 return basic_function(saVars, std::make_shared<Fiif<T>>(
mp, rfNeg.mp, rfNotNeg.mp));
7271 return basic_function(rf.
mvars, std::make_shared<Fminus<T>>(std::make_shared<Fconst<T>>(d), rf.
mp));
7360 return basic_function(rf.
mvars, std::make_shared<Fpower<T>>(std::make_shared<Fconst<T>>(d), rf.
mp));
7390 std::string
vars = __format_vars(rf.
mvars,
false);
7391 if (vars.size() > 0) {
7404 const string_array& saVars1 = this->_check_vars(fa1->vars());
7405 const string_array& saVars2 = this->_check_vars(fa2->vars());
7406 const string_array& saVars = saVars1.size() > saVars2.size() ? saVars1 : saVars2;
7409 mp = std::make_shared<Fconst<T>>();
7411 for (
size_t i = 0; i < nSize; ++i, fa1 += incr1, fa2 += incr2)
7413 *
this += (*fa1) * (*fa2);
7415 return this->
simp();
7422 template<
typename BaseFunction>
7423 inline void _copy(
size_t nSize,
7427 for (
size_t i = 0; i < nSize; ++i, faFrom += incrFrom, faTo += incrTo) {
7442 template<
typename T>
7448 std::vector<BaseFunction>
mv;
7451 void _assign(
const FArray& a)
7453 for (
size_t i = 0; i <
mv.size(); ++i) {
7454 mv.at(i) = a.
mv.at(i);
7497 :
mv(std::move(a.
mv))
7512 for (
size_t i = 0; i <
mv.size(); ++i) {
7528 FArray(
const string_array& saVars,
const string_array& saBodies,
7529 const string_array& saParameters,
const string_array& saMeanings)
7532 for (
size_t i = 0; i <
mv.size(); ++i) {
7533 mv.at(i) =
BaseFunction(saVars, saBodies[i], saParameters, saMeanings);
7551 std::vector<BaseFunction>&
impl() {
7562 const std::vector<BaseFunction>&
impl()
const {
7755 void value(T d1, T d2, T d3, T* pv)
const {
7801 for (
size_t i = 0; i <
mv.size(); ++i) {
7802 pv[i] =
mv.at(i).value(pd);
7808 void _drv(
const FArray& a,
size_t nVarNum)
7810 for (
size_t i = 0; i <
mv.size(); ++i) {
7811 mv.at(i) = a.
mv.at(i).drv(nVarNum);
7817 for (
size_t i = 0; i <
mv.size(); ++i) {
7822 bool _equals(
const FArray& a)
const
7824 bool bResult =
true;
7825 if (
mv.size() != a.
size()) {
7829 for (
size_t i = 0; i <
mv.size(); ++i) {
7830 if (
mv.at(i) != a.
mv.at(i)) {
7838 void _add(
const FArray& a)
7840 for (
size_t i = 0; i <
mv.size(); ++i) {
7841 mv.at(i) += a.
mv.at(i);
7845 void _subtract(
const FArray& a)
7847 for (
size_t i = 0; i <
mv.size(); ++i) {
7848 mv.at(i) -= a.
mv.at(i);
7854 for (
size_t i = 0; i <
mv.size(); ++i) {
7855 mv.at(i) = a1.
mv.at(i) + a2.
mv.at(i);
7861 for (
size_t i = 0; i <
mv.size(); ++i) {
7862 mv.at(i) = a1.
mv.at(i) - a2.
mv.at(i);
7868 for (
size_t i = 0; i <
mv.size(); ++i) {
7875 for (
size_t i = 0; i <
mv.size(); ++i) {
7882 for (
size_t i = 0; i <
mv.size(); ++i) {
7883 mv.at(i) = a.
mv.at(i) * f;
7889 for (
size_t i = 0; i <
mv.size(); ++i) {
7890 mv.at(i) = a.
mv.at(i) / f;
7894 void _mult(
const T& t)
7896 for (
size_t i = 0; i <
mv.size(); ++i) {
7901 void _div(
const T& t)
7903 for (
size_t i = 0; i <
mv.size(); ++i) {
7908 void _mult(
const FArray& a,
const T& t)
7910 for (
size_t i = 0; i <
mv.size(); ++i) {
7911 mv.at(i) = a.
mv.at(i) * t;
7915 void _div(
const FArray& a,
const T& t)
7917 for (
size_t i = 0; i <
mv.size(); ++i) {
7918 mv.at(i) = a.
mv.at(i) / t;
7938 template<
typename T>
8076 const string_array& saParameters,
const string_array& saMeanings)
8077 :
BaseFArray(saVars, saBodies, saParameters, saMeanings)
8132 this->_check_size(fv.size());
8142 this->_check_size(fv.size());
8143 this->
mv = std::move(fv.mv);
8181 return this->_equals(fv);
8218 return !this->_equals(fv);
8252 this->
mv.resize(fv.
size());
8288 vRet._drv(*
this, nVarNum);
8356 this->_check_size(fv.size());
8358 vRet._add(*
this, fv);
8398 this->_check_size(fv.size());
8400 vRet._subtract(*
this, fv);
8443 this->_check_size(fv.size());
8487 this->_check_size(fv.size());
8488 this->_subtract(fv);
8529 vRet.BaseFArray::_mult(*
this, f);
8570 vRet._div(*
this, f);
8609 vRet.BaseFArray::_mult(*
this, d);
8648 vRet._div(*
this, d);
8693 this->BaseFArray::_mult(f);
8738 this->BaseFArray::_div(f);
8782 this->BaseFArray::_mult(d);
8826 this->BaseFArray::_div(d);
8868 this->_check_size(fv.size());
8870 fRet._scalar_product(this->
mv.size(), &this->
mv.at(0), 1, &fv.mv.at(0), 1);
8921 this->_check_size(fm.msize());
8923 vRet._mult(*
this, fm);
8980 fv._check_size(fm.msize());
8981 this->_check_size(fm.nsize());
8982 return this->_mult(fv, fm);
9038 fv._check_size(fm.nsize());
9039 this->_check_size(fm.msize());
9040 return this->_mult(fm, fv);
9105 const size_t m = this->
size();
9109 const size_t sz = this->
mv.at(0).vars().size();
9112 const size_t n = vars > 0 ? vars : sz - nfrom;
9116 this->_jacobi(fmj, nfrom);
9192 const size_t m = this->
size();
9195 const size_t sz = this->
mv.at(0).vars().size();
9197 const size_t n = vars > 0 ? vars : sz - nfrom;
9200 this->_jacobi(fmj, nfrom);
9231 friend std::ostream& operator <<(std::ostream& os, const basic_fvector<T>& fv)
9233 for (
size_t i = 0; i < fv.size(); ++i) {
9234 os << fv.mv.at(i) <<
" ";
9245 for (
size_t i = 0; i < fm.nsize(); ++i) {
9246 this->
mv.at(i)._scalar_product(fv.size(), &fv.mv.at(0), 1, &fm.mv.at(fm.msize() * i), 1);
9253 for (
size_t i = 0; i < fm.msize(); ++i) {
9254 this->
mv.at(i)._scalar_product(fm.nsize(), &fm.mv.at(i), fm.msize(), &fv.mv.at(0), 1);
9262 for (
size_t i = 0; i < fmj.
msize(); ++i) {
9263 for (
size_t j = 0; j < fmj.
nsize(); ++j) {
9264 fmj.
mv.at(fmj.
msize() * j + i) = this->
mv.at(i).drv(j + nfrom);
9404 rfvector(
const string_array& saVars,
const string_array& saBodies,
9405 const string_array& saParameters,
const string_array& saMeanings)
9406 :
BaseFVector(saVars, saBodies, saParameters, saMeanings)
9495 this->
value(d, ret);
9532 this->
value(d1, d2, ret);
9570 this->
value(d1, d2, d3, ret);
9611 this->
value(pd, ret);
9749 cfvector(
const string_array& saVars,
const string_array& saBodies,
9750 const string_array& saParameters,
const string_array& saMeanings)
9751 :
BaseFVector(saVars, saBodies, saParameters, saMeanings)
9839 this->
value(d, ret);
9876 this->
value(d1, d2, ret);
9914 this->
value(d1, d2, d3, ret);
9955 this->
value(pd, ret);
9971 template<
typename T>
9991 static const size_t ZERO(0);
10038 this->_check_sizes();
10080 this->_check_sizes();
10129 basic_fmatrix(
size_t m,
size_t n,
const string_array& saVars,
const string_array& saBodies,
10130 const string_array& saParameters,
const string_array& saMeanings)
10131 :
BaseFArray(saVars, saBodies, saParameters, saMeanings),
mM(m),
mN(n)
10133 this->_check_sizes();
10236 this->_check_sizes(fm);
10246 this->_check_sizes(fm);
10247 this->mp = std::move(fm.mv);
10302 return this->
mv.at(
mM * nCol + nRow);
10337 return this->
mv.at(
mM * nCol + nRow);
10446 this->
mv.resize(fm.
size());
10493 fmRet._drv(*
this, nVarNum);
10569 this->_check_sizes(fm);
10571 fmRet._add(*
this, fm);
10614 this->_check_sizes(fm);
10616 fmRet._subtract(*
this, fm);
10663 this->_check_sizes(fm);
10711 this->_check_sizes(fm);
10712 this->_subtract(fm);
10762 fmRet.BaseFArray::_mult(*
this, f);
10812 fmRet._div(*
this, f);
10859 fmRet.BaseFArray::_mult(*
this, d);
10906 fmRet._div(*
this, d);
10951 this->BaseFArray::_mult(f);
10997 this->BaseFArray::_div(f);
11040 this->BaseFArray::_mult(d);
11083 this->BaseFArray::_div(d);
11134 _copy(this->
mN, &this->
mv.at(nRow), this->
mM, &fvRet.
mv.at(0), 1);
11185 _copy(this->
mM, &this->
mv.at(this->mM * nCol), 1, &fvRet.
mv.at(0), 1);
11240 _copy(this->
mN, &fv.mv.at(0), 1, &this->
mv.at(nRow), this->
mM);
11295 _copy(this->
mM, &fv.mv.at(0), 1, &this->
mv.at(this->
mM * nCol), 1);
11352 vRet._mult(*
this, fv);
11419 mRet._mult(*
this, fm);
11490 return this->_mult(fmA, fmB);
11524 friend std::ostream& operator <<(std::ostream& os, const basic_fmatrix<T>& fm)
11526 for (
size_t i = 0; i < fm.msize(); ++i) {
11527 for (
size_t j = 0; j < fm.nsize(); ++j) {
11528 os << fm.mv.at(fm.msize() * j + i) <<
CFUN_SSPACE;
11540 for (
size_t i = 0; i < this->
mM; ++i) {
11541 for (
size_t j = 0; j < this->
mN; ++j) {
11542 this->
mv.at(this->mM * j + i)._scalar_product(fmA.nsize(), &fmA.mv.at(i), this->
mM, &fmB.mv.at(fmB.msize() * j), 1);
11686 rfmatrix(
size_t m,
size_t n,
const string_array& saVars,
const string_array& saBodies,
11687 const string_array& saParameters,
const string_array& saMeanings)
11688 :
BaseFMatrix(m, n, saVars, saBodies, saParameters, saMeanings)
11788 this->
value(d, ret);
11830 this->
value(d1, d2, ret);
11873 this->
value(d1, d2, d3, ret);
11919 this->
value(pd, ret);
12062 cfmatrix(
size_t m,
size_t n,
const string_array& saVars,
const string_array& saBodies,
12063 const string_array& saParameters,
const string_array& saMeanings)
12064 :
BaseFMatrix(m, n, saVars, saBodies, saParameters, saMeanings)
12164 this->
value(d, ret);
12206 this->
value(d1, d2, ret);
12249 this->
value(d1, d2, d3, ret);
12295 this->
value(pd, ret);
12307 template<
typename T>
12308 class Comparator<T,T>
12311 static bool lt(
const T& l,
const T& r)
12315 static bool le(
const T& l,
const T& r)
12319 static bool gt(
const T& l,
const T& r)
12323 static bool ge(
const T& l,
const T& r)
12327 static bool eq(
const T& l,
const T& r)
12329 return cvm::_abs(l - r) <= cvm::basic_cvmMachMin<T>();
12333 template<
typename T>
12334 class Comparator<std::complex<T>, std::complex<T> >
12337 static bool lt(
const std::complex<T>& l,
const std::complex<T>& r)
12339 return l.
real() < r.real();
12341 static bool le(
const std::complex<T>& l,
const std::complex<T>& r)
12343 return l.real() <= r.real();
12345 static bool gt(
const std::complex<T>& l,
const std::complex<T>& r)
12347 return l.real() > r.real();
12349 static bool ge(
const std::complex<T>& l,
const std::complex<T>& r)
12351 return l.real() >= r.real();
12353 static bool eq(
const std::complex<T>& l,
const std::complex<T>& r)
12355 return cvm::_abs(l.real() - r.real()) <= cvm::basic_cvmMachMin<T>() &&
12356 cvm::_abs(l.imag() - r.imag()) <= cvm::basic_cvmMachMin<T>();
12360 template<
typename T>
12361 class Comparator<T,std::complex<T> >
12364 static bool lt(
const T& l,
const std::complex<T>& r)
12366 return l < r.real();
12368 static bool le(
const T& l,
const std::complex<T>& r)
12370 return l <= r.real();
12372 static bool gt(
const T& l,
const std::complex<T>& r)
12374 return l > r.real();
12376 static bool ge(
const T& l,
const std::complex<T>& r)
12378 return l >= r.real();
12380 static bool eq(
const T& l,
const std::complex<T>& r)
12382 return cvm::_abs(l - r.real()) <= cvm::basic_cvmMachMin<T>() &&
12383 cvm::_abs(r.imag()) <= cvm::basic_cvmMachMin<T>();
12387 template<
typename T>
12388 class Comparator<std::complex<T>, T>
12391 static bool lt(
const std::complex<T>& l,
const T& r)
12393 return l.real() < r;
12395 static bool le(
const std::complex<T>& l,
const T& r)
12397 return l.real() <= r;
12399 static bool gt(
const std::complex<T>& l,
const T& r)
12401 return l.real() > r;
12403 static bool ge(
const std::complex<T>& l,
const T& r)
12405 return l.real() >= r;
12407 static bool eq(
const std::complex<T>& l,
const T& r)
12409 return cvm::_abs(l.real() - r) <= cvm::basic_cvmMachMin<T>() &&
12410 cvm::_abs(l.imag()) <= cvm::basic_cvmMachMin<T>();