CVM Class Library  8.1
This C++ class library encapsulates concepts of vector and different matrices including square, band, symmetric and hermitian ones in Euclidean space of real and complex numbers.
 All Classes Files Functions Variables Typedefs Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
basic_function< T > Class Template Reference

End-user class encapsulating elementary function of real or complex numbers (depending on T type). More...

#include <cfun.h>

Public Types

typedef FunctionFactory< T >
::BasePointer 
BasePointer
 Shared pointer to BaseFunction.

Public Member Functions

 basic_function ()
 Default constructor.
 basic_function (const string_array &saVars)
 Constructor.
 basic_function (const T &dConst)
 Constructor.
 basic_function (const basic_function &rf)
 Copy Constructor.
 basic_function (basic_function &&rf)
 Move Constructor.
 basic_function (const std::string &sInput)
 Constructor.
 basic_function (const string_array &saVars, const std::string &sBody)
 Constructor.
 basic_function (const string_array &saVars, const std::string &sBody, const string_array &saParameters, const string_array &saMeanings)
 Constructor.
virtual ~basic_function ()
 Destructor.
const string_arrayvars () const
 Variables.
size_t vars_num () const
 Number of variables.
value (const T *pd) const
 Numerical value.
operator() (const T *pd) const
 Numerical value.
operator() (const T &d) const
 Numerical value.
operator() (const T &d1, const T &d2) const
 Numerical value.
operator() (const T &d1, const T &d2, const T &d3) const
 Numerical value.
operator() () const
 Numerical value.
std::string format (int nPrecision=0) const
 Function body as a string.
std::string vformat (int nPrecision=0) const
 Function variables and body as a string.
bool operator== (const basic_function &rf) const
 Functions comparison.
bool operator!= (const basic_function &rf) const
 Functions comparison.
basic_function drv (size_t nVarNum=0) const
 Partial derivative.
basic_functionsimp ()
 Simplifier.
basic_functionoperator= (const basic_function &rfSrc)
 Assignment operator.
basic_functionoperator= (basic_function &&rfSrc)
 Move assignment operator.
basic_functionoperator= (const T &rdSrc)
 Assignment operator.
basic_function operator- () const
 Unary minus operator.
basic_function operator+ (const basic_function &rf) const throw (cvmexception)
 Addition operator.
basic_function operator- (const basic_function &rf) const throw (cvmexception)
 Subtraction operator.
basic_function operator* (const basic_function &rf) const throw (cvmexception)
 Multiplication operator.
basic_function operator/ (const basic_function &rf) const throw (cvmexception)
 Division operator.
basic_function operator^ (const basic_function &rf) const throw (cvmexception)
 Power to operator.
basic_functionoperator+= (const basic_function &rf) throw (cvmexception)
 Increment operator.
basic_functionoperator-= (const basic_function &rf) throw (cvmexception)
 Decrement operator.
basic_functionoperator*= (const basic_function &rf) throw (cvmexception)
 Multiply and assign operator.
basic_functionoperator/= (const basic_function &rf) throw (cvmexception)
 Divide and assign operator.
basic_function operator+ (const T &d) const throw (cvmexception)
 Addition operator.
basic_function operator- (const T &d) const throw (cvmexception)
 Subtraction operator.
basic_function operator* (const T &d) const throw (cvmexception)
 Multiplication operator.
basic_function operator/ (const T &d) const throw (cvmexception)
 Division operator.
basic_function operator^ (const T &d) const throw (cvmexception)
 Power to operator.
basic_functionoperator+= (const T &d) throw (cvmexception)
 Increment operator.
basic_functionoperator-= (const T &d) throw (cvmexception)
 Decrement operator.
basic_functionoperator*= (const T &d) throw (cvmexception)
 Multiply and assign operator.
basic_functionoperator/= (const T &d) throw (cvmexception)
 Divide and assign operator.
basic_functionoperator^= (const T &d) throw (cvmexception)
 Power to and assign operator.
basic_function sat (const basic_function &rf) const throw (cvmexception)
 Satellite function.
basic_function exp () const
 Exponent.
basic_function sqrt () const
 Square root.
basic_function log () const
 Natural logarithm.
basic_function log10 () const
 Common (base 10) logarithm.
basic_function sin () const
 Sine.
basic_function cos () const
 Cosine.
basic_function tan () const
 Tangent.
basic_function asin () const
 Arcsine.
basic_function acos () const
 Arc cosine.
basic_function atan () const
 Arc tangent.
basic_function sinh () const
 Hyperbolic sine.
basic_function cosh () const
 Hyperbolic cosine.
basic_function tanh () const
 Hyperbolic tangent.
basic_function sinint () const
 Integral sine.
basic_function cosint () const
 Integral cosine.
basic_function sign () const
 Sign.
basic_function abs () const
 Absolute value.
basic_function delta (const basic_function &rf) const throw (cvmexception)
 Delta function.
basic_function iif (const basic_function &rfNeg, const basic_function &rfNotNeg) const throw (cvmexception)
 Immediate If function.

Protected Attributes

string_array mvars
 Array of variables.
BasePointer mp
 Pointer to function's instance.

Friends

basic_function< T > operator+ (const T &d, const basic_function< T > &rf)
 Addition operator (left sided)
basic_function< T > operator- (const T &d, const basic_function< T > &rf)
 Subtraction operator (left sided)
basic_function< T > operator* (const T &d, const basic_function< T > &rf)
 Multiplication operator (left sided)
basic_function< T > operator/ (const T &d, const basic_function< T > &rf)
 Division operator (left sided)
basic_function< T > operator^ (const T &d, const basic_function< T > &rf)
 Power to operator (left sided)
std::ostream & operator<< (std::ostream &os, const basic_function &rf)
 Output operator.

Detailed Description

template<typename T>
class basic_function< T >

End-user class encapsulating elementary function of real or complex numbers (depending on T type).

Typically used to convert strings entered by a user to computable expressions without need to parse same expression over and over again. Also might be used to simplify computable expressions and to compute derivatives analytically, i.e. without using numerical methods. Functions can have zero, one or more than one variables and can be parameterized.

Elementary functions supported

\[ \begin{aligned} +\ -\ *\ /\ \verb|^| \quad & \text{arithmetic operators: add, subtract, multiply, divide, power}\\ \texttt{exp(x)}\quad & e^x \\ \texttt{sqrt(x)}\quad & \sqrt x\\ \texttt{log(x)}\quad & \text{natural logarithm of}\ x\\ \texttt{log10(x)}\quad & \text{common (base 10) logarithm of}\ x\\ \texttt{sin(x)}\quad & \text{sine of}\ x\\ \texttt{cos(x)}\quad & \text{cosine of}\ x\\ \texttt{tan(x)}\quad & \text{tangent of}\ x\\ \texttt{asin(x)}\quad & \text{arc sine of}\ x\\ \texttt{acos(x)}\quad & \text{arc cosine of}\ x\\ \texttt{atan(x)}\quad & \text{arc tangent of}\ x\\ \texttt{sinh(x)}\quad & \text{hyperbolic sine of}\ x\\ \texttt{cosh(x)}\quad & \text{hyperbolic cosine of}\ x\\ \texttt{tanh(x)}\quad & \text{hyperbolic tangent of}\ x\\ \texttt{sinint(x)}\quad & \text{sine integral of}\ x,\quad \int_0^x \frac{\sin t}{t}dt\\ \texttt{cosint(x)}\quad & \text{cosine integral of}\ x,\quad -\int_x^\infty \frac{\cos t}{t}dt \\ \texttt{sign(x)}\quad & \text{sign of}\ x,\quad \left\{ \begin{aligned} -1 & \text{ if } x < 0\\ 0 & \text{ if } x = 0\\ 1 & \text{ if } x > 0 \end{aligned} \right.\\ \texttt{abs(x)}\quad & |x| \\ \texttt{iif(x,expr1,expr2)}\quad & \text{immediate if}\quad \left\{ \begin{aligned} expr1 & \text{ if } x < 0\\ expr2 & \text{ if } x \ge 0 \end{aligned} \right.\\ \texttt{sat(x,y)}\quad & \text{satellite function of}\ x\ \text{and}\ y,\quad \left\{ \begin{aligned} 1 & \text{ if } x > |y|\\ 0 & \text{ if } -|y| \le x \le |y|\\ -1 & \text{ if } x < -|y| \end{aligned} \right.\\ \texttt{i}\quad & 1\ \text{(one)}\\ & 0\ \text{(empty field means zero)} \end{aligned} \]

Example:
try{
rfunction rf("{x,y} cos(x)*cos(y) + x + x + x");
std::cout << rf.simp() << std::endl;
std::cout << rf.drv(0) << std::endl;
std::cout << rf.drv(1) << std::endl;
double vars[] = {0., 0.};
std::cout << rf(vars) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*3+cos(x)*cos(y)
{x,y} 3-sin(x)*cos(y)
{x,y} -sin(y)*cos(x)
1
See Also
BaseFunction, UnaryFunction, BinaryFunction

Definition at line 4919 of file cfun.h.

Member Typedef Documentation

template<typename T>
typedef FunctionFactory<T>::BasePointer basic_function< T >::BasePointer

Shared pointer to BaseFunction.

Definition at line 4922 of file cfun.h.

Constructor & Destructor Documentation

template<typename T>
basic_function< T >::basic_function ( )
inline

Default constructor.

Creates zero function of no variables.

Example:
using namespace cvm;
std::cout << rf << std::endl;
std::cout << rf() << std::endl;
std::cout << cf << std::endl;
std::cout << cf() << std::endl;
prints
0
0
(0,0)
(0,0)

Definition at line 4975 of file cfun.h.

Here is the caller graph for this function:

template<typename T>
basic_function< T >::basic_function ( const string_array saVars)
inlineexplicit

Constructor.

Creates zero function with given list of variables.

Example:
using namespace cvm;
args.push_back("x");
args.push_back("y");
rfunction rf(args);
std::cout << rf << std::endl;
std::cout << rf() << std::endl;
cfunction cf(args);
std::cout << cf << std::endl;
std::cout << cf() << std::endl;
prints
{x,y} 0
0
{x,y} (0,0)
(0,0)
Parameters
[in]saVarsstring_array of variables.

Definition at line 5008 of file cfun.h.

template<typename T>
basic_function< T >::basic_function ( const T &  dConst)
inlineexplicit

Constructor.

Creates constant number function of no variables.

Example:
using namespace cvm;
using namespace std;
rfunction rf(1.234);
std::cout << rf << std::endl;
std::cout << rf() << std::endl;
cfunction cf(complex<double>(1.,2.));
std::cout << cf << std::endl;
std::cout << cf() << std::endl;
prints
1.234
1.234
(1,2)
(1,2)
Parameters
[in]dConstreal (for rfunction) or complex (for cfunction) number.

Definition at line 5041 of file cfun.h.

template<typename T>
basic_function< T >::basic_function ( const basic_function< T > &  rf)
inline

Copy Constructor.

Creates deep (default) or shallow (if bDeep = false) copy of a function referred by rf. Shallow copying is reserved for internal use only.

Example:
using namespace cvm;
rfunction rf(1.234);
rfunction rf1(rf);
rf = 2.5;
std::cout << rf << std::endl;
std::cout << rf1 << std::endl;
prints
2.5
1.234
Parameters
[in]rffunction (rfunction or cfunction) to copy from.

Definition at line 5070 of file cfun.h.

template<typename T>
basic_function< T >::basic_function ( basic_function< T > &&  rf)
inline

Move Constructor.

Definition at line 5079 of file cfun.h.

template<typename T>
basic_function< T >::basic_function ( const std::string &  sInput)
inlineexplicit

Constructor.

Creates function of one or more variables using Wolfram's Mathemaca syntax {var1[,var2,...]} expr. Throws cvmexception in case of syntax or memory allocation error.

Example:
using namespace cvm;
using namespace std;
try{
rfunction rf("{x,y} cos(x)*sin(y)");
double rvars[] = {0., 3.14159 / 2.};
std::cout << rf << std::endl;
std::cout << rf(rvars) << std::endl;
cfunction cf("{x,y} sqrt(x) + sqrt(y)");
complex<double> cvars[] = {complex<double>(0., 1.), complex<double>(1., 0.)};
std::cout << cf << std::endl;
std::cout << cf(cvars) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} cos(x)*sin(y)
1
{x,y} sqrt(x)+sqrt(y)
(1.70711,0.707107)
Parameters
[in]sInputString representing a function as {var1[,var2,...]} expr. For expression syntax look at basic_function description.

Definition at line 5121 of file cfun.h.

template<typename T>
basic_function< T >::basic_function ( const string_array saVars,
const std::string &  sBody 
)
inline

Constructor.

Creates function of one or more variables. Throws cvmexception in case of syntax or memory allocation error.

Example:
using namespace cvm;
using namespace std;
try{
vars.push_back("x");
vars.push_back("y");
rfunction rf(vars, "cos(x)*sin(y)");
double rvars[] = {0., 3.14159 / 2.};
std::cout << rf << std::endl;
std::cout << rf(rvars) << std::endl;
cfunction cf(vars, "sqrt(x) + sqrt(y)");
complex<double> cvars[] = {complex<double>(0., 1.), complex<double>(1., 0.)};
std::cout << cf << std::endl;
std::cout << cf(cvars) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} cos(x)*sin(y)
1
{x,y} sqrt(x)+sqrt(y)
(1.70711,0.707107)
Parameters
[in]saVarsString array with variables (may be empty).
[in]sBodyString with function expression. For expression syntax look at basic_function description.

Definition at line 5174 of file cfun.h.

template<typename T>
basic_function< T >::basic_function ( const string_array saVars,
const std::string &  sBody,
const string_array saParameters,
const string_array saMeanings 
)
inline

Constructor.

Creates parameterized function of one or more variables. Throws cvmexception in case of syntax or memory allocation error.

Example:
using namespace cvm;
using namespace std;
try{
string_array vars, params, meanings;
vars.push_back("x");
vars.push_back("y");
params.push_back("p");
meanings.push_back("sqrt(x) + sqrt(y)");
rfunction rf(vars, "p^2 + p + x + y", params, meanings);
double rvars[] = {0., 3.14159 / 2.};
std::cout << rf << std::endl;
std::cout << rf(rvars) << std::endl;
cfunction cf(vars, "p^2 + p + x + y", params, meanings);
complex<double> cvars[] = {complex<double>(0., 1.), complex<double>(1., 0.)};
std::cout << cf << std::endl;
std::cout << cf(cvars) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} (sqrt(x)+sqrt(y))^2+sqrt(x)+sqrt(y)+x+y
4.3949
{x,y} (sqrt(x)+sqrt(y))^(2,0)+sqrt(x)+sqrt(y)+x+y
(5.12132,4.12132)
Parameters
[in]saVarsString array with variables (may be empty).
[in]sBodyString with function expression. For expression syntax look at basic_function description.
[in]saParametersString array with parameters (may be empty).
[in]saMeaningsString array with parameters' meanings (may be empty, must have the same size as saParameters).

Definition at line 5228 of file cfun.h.

template<typename T>
virtual basic_function< T >::~basic_function ( )
inlinevirtual

Destructor.

Definition at line 5238 of file cfun.h.

Member Function Documentation

template<typename T>
const string_array& basic_function< T >::vars ( ) const
inline

Variables.

Returns constant referense to array of variables.

Example:
rfunction rf("{x,y} cos(x)*sin(y)");
const string_array vars = rf.vars();
std::cout << vars[0] << " " << vars[1] << std::endl;
prints
x y
Returns
Referernce to array of strings.

Definition at line 5258 of file cfun.h.

Here is the caller graph for this function:

template<typename T>
size_t basic_function< T >::vars_num ( ) const
inline

Number of variables.

Returns number of variables.

Example:
rfunction rf("{x,y} cos(x)*sin(y)");
std::cout << rf.vars_num() << std::endl;
prints
2
Returns
size_t number.

Definition at line 5277 of file cfun.h.

Here is the caller graph for this function:

template<typename T>
T basic_function< T >::value ( const T *  pd) const
inline

Numerical value.

Returns numerical value of function for given values of variables. Array's dimension is not verified.

Example:
using namespace cvm;
using namespace std;
try{
rfunction rf("{x,y} x + 2*y");
const double rvars[] = {1., 2.};
std::cout << rf.value(rvars) << std::endl;
cfunction cf("{x,y} x + 2*y");
const complex<double> cvars[] = {complex<double>(1., 0.), complex<double>(1., 1.)};
std::cout << cf.value(cvars) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
5
(3,2)
Parameters
[in]pdArray of variables' values.
Returns
real or complex number.

Definition at line 5311 of file cfun.h.

template<typename T>
T basic_function< T >::operator() ( const T *  pd) const
inline

Numerical value.

Returns numerical value of function for given values of variables. Array's dimension is not verified.

Example:
using namespace cvm;
using namespace std;
try{
rfunction rf("{x,y} x + 2*y");
const double rvars[] = {1., 2.};
std::cout << rf(rvars) << std::endl;
cfunction cf("{x,y} x + 2*y");
const complex<double> cvars[] = {complex<double>(1., 0.), complex<double>(1., 1.)};
std::cout << cf(cvars) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
5
(3,2)
Parameters
[in]pdArray of variables' values.
Returns
real or complex number.

Definition at line 5346 of file cfun.h.

template<typename T>
T basic_function< T >::operator() ( const T &  d) const
inline

Numerical value.

Returns numerical value of function for given value of single variable. Result is unpredictable if function is of more than one variable.

Example:
using namespace cvm;
using namespace std;
try{
rfunction rf("{x} 2*x+1");
std::cout << rf(1.) << std::endl;
cfunction cf("{x} 2*x+(1,1)");
std::cout << cf(complex<double>(2., 1.)) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
3
(5,3)
Parameters
[in]dVariable's value.
Returns
real or complex number.

Definition at line 5379 of file cfun.h.

template<typename T>
T basic_function< T >::operator() ( const T &  d1,
const T &  d2 
) const
inline

Numerical value.

Returns numerical value of function for given two variables' values. Result is unpredictable if function is of more than two variables.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} sin(x)^2 + cos(y)^2");
std::cout << rf(1.,1.) << std::endl;
std::cout << rf(3.1459,0.) << std::endl;
cfunction cf("{x,y} sqrt(x) + sqrt(y)");
std::cout << cf(complex<double>(-1., 0.), complex<double>(-4., 0.)) << std::endl;
std::cout << cf(complex<double>(9., 0.), complex<double>(-4., 0.)) << std::endl;
prints
1
1.00002
(0,3)
(3,2)
Parameters
[in]d1First variable's value.
[in]d2Second variable's value.
Returns
real or complex number.

Definition at line 5412 of file cfun.h.

template<typename T>
T basic_function< T >::operator() ( const T &  d1,
const T &  d2,
const T &  d3 
) const
inline

Numerical value.

Returns numerical value of function for given three variables' values. Result is unpredictable if function is of more than three variables.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y,z} x*y*z");
std::cout << rf(2.,3.,4.) << std::endl;
cfunction cf("{x,y,z} x*y*z");
std::cout << cf(complex<double>(1., 1.), complex<double>(2., 1.), complex<double>(3., 1.)) << std::endl;
prints
24
(0,10)
Parameters
[in]d1First variable's value.
[in]d2Second variable's value.
[in]d3Third variable's value.
Returns
real or complex number.

Definition at line 5445 of file cfun.h.

template<typename T>
T basic_function< T >::operator() ( ) const
inline

Numerical value.

Returns numerical value of function for given zero value of single variable or function of no variables. Result is unpredictable if function is of more than one variable.

Example:
using namespace cvm;
try{
rfunction rf("{x} 2*x+1");
std::cout << rf() << std::endl;
rfunction rf0("sqrt(9)");
std::cout << rf0() << std::endl;
cfunction cf("{x} 2*x+(1,1)");
std::cout << cf() << std::endl;
cfunction cf0("sqrt(-1)");
std::cout << cf0() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
1
3
(1,1)
(0,1)
Returns
real or complex number.
Function object.
boolean value.
Reference to changed calling function.

Definition at line 5491 of file cfun.h.

template<typename T>
std::string basic_function< T >::format ( int  nPrecision = 0) const
inline

Function body as a string.

Returns function body formatted as a string.

Example:
using namespace cvm;
try{
string_array vars, params, meanings;
vars.push_back("x");
vars.push_back("y");
params.push_back("p");
meanings.push_back("sqrt(x) + sqrt(y)");
rfunction rf(vars, "p^2 + p + x + y", params, meanings);
std::cout << rf.format() << std::endl;
cfunction cf(vars, "p^2 + p + x + y", params, meanings);
std::cout << cf.format() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
(sqrt(x)+sqrt(y))^2+sqrt(x)+sqrt(y)+x+y
(sqrt(x)+sqrt(y))^(2,0)+sqrt(x)+sqrt(y)+x+y
Parameters
[in]nPrecisionPrecision of numbers printed. Zero for auto mode (default).
Returns
std::string object.

Definition at line 5530 of file cfun.h.

template<typename T>
std::string basic_function< T >::vformat ( int  nPrecision = 0) const
inline

Function variables and body as a string.

Returns function variables and body formatted as a string in [{var1,var2,...}] expr format.

Example:
using namespace cvm;
try{
string_array vars, params, meanings;
vars.push_back("x");
vars.push_back("y");
params.push_back("p");
meanings.push_back("sqrt(x) + sqrt(y)");
rfunction rf(vars, "p^2 + p + x + y", params, meanings);
std::cout << rf.vformat() << std::endl;
cfunction cf(vars, "p^2 + p + x + y", params, meanings);
std::cout << cf.vformat() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} (sqrt(x)+sqrt(y))^2+sqrt(x)+sqrt(y)+x+y
{x,y} (sqrt(x)+sqrt(y))^(2,0)+sqrt(x)+sqrt(y)+x+y
Parameters
[in]nPrecisionPrecision of numbers printed. Zero for auto mode (default).
Returns
std::string object.

Definition at line 5568 of file cfun.h.

Here is the call graph for this function:

template<typename T>
bool basic_function< T >::operator== ( const basic_function< T > &  rf) const
inline

Functions comparison.

Returns true if functions are equal and false otherwise.

Example:
using namespace cvm;
try{
vars.push_back("x");
vars.push_back("y");
rfunction rf1(vars, "x + y");
rfunction rf2("{x,y} x + y");
std::cout << (rf1 == rf2) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1
Parameters
[in]rfConst reference to function to compare with.
Returns
boolean value.

Definition at line 5606 of file cfun.h.

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T>
bool basic_function< T >::operator!= ( const basic_function< T > &  rf) const
inline

Functions comparison.

Returns true if functions are equal and false otherwise.

Example:
using namespace cvm;
try{
vars.push_back("x");
vars.push_back("z");
rfunction rf1(vars, "x + z");
rfunction rf2("{x,y} x + y");
std::cout << (rf1 != rf2) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1
Parameters
[in]rfConst reference to function to compare with.
Returns
boolean value.

Definition at line 5637 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::drv ( size_t  nVarNum = 0) const
inline

Partial derivative.

Creates basic_function object as a partial derivative of calling function. Variables set remains the same even if the derivative doesn't depend on some of them. Partial derivative is computed by nVarNum's variable (0-based, 0 by default).

Example:
using namespace cvm;
try{
rfunction rf1("{x} x + log(x) + x^x");
std::cout << rf1.drv() << std::endl;
cfunction cf1("{x} x + log(x) + x^x");
std::cout << cf1.drv() << std::endl;
rfunction rf2("{x,y} sin(x)*cos(y) + sin(y)*cos(x) + x*y");
std::cout << rf2.drv(0) << std::endl;
std::cout << rf2.drv(1) << std::endl;
cfunction cf2("{x,y} sin(x)*cos(y) + sin(y)*cos(x) + x*y");
std::cout << cf2.drv(0) << std::endl;
std::cout << cf2.drv(1) << std::endl;
rfunction rf3("{x,y} x");
std::cout << rf3.drv(0) << std::endl;
std::cout << rf3.drv(1) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} 1+1/x+x^x*(log(x)+1)
{x} (1,0)+(1,0)/x+x^x*(log(x)+(1,0))
{x,y} cos(x)*cos(y)-sin(x)*sin(y)+y
{x,y} cos(y)*cos(x)-sin(y)*sin(x)+x
{x,y} cos(x)*cos(y)-sin(x)*sin(y)+y
{x,y} cos(y)*cos(x)-sin(y)*sin(x)+x
{x,y} 1
{x,y} 0
Parameters
[in]nVarNumVariable's index (0-based, 0 by default).
Returns
Function object.

Definition at line 5688 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function& basic_function< T >::simp ( )
inline

Simplifier.

Simplifies basic_function for fatsest numerical computation possible and returns reference to the object changed.

Example:
using namespace cvm;
try{
rfunction rf1("{x} x*2 + 3*x");
std::cout << rf1.simp() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} x*5
Returns
Reference to changed calling function.

Definition at line 5714 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator= ( const basic_function< T > &  rfSrc)
inline

Assignment operator.

Assigns basic_function object to calling one by performing deep copying. No verifications made, it just copies over and returns reference to the object changed.

Example:
using namespace cvm;
try{
rfunction rf1("{x} x*2");
rfunction rf2("{y} y*3");
rf1 = rf2;
std::cout << rf1 << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{y} y*3
Parameters
[in]rfSrcConst reference to function to assign.
Returns
Reference to changed calling function.

Definition at line 5746 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator= ( basic_function< T > &&  rfSrc)
inline

Move assignment operator.

Definition at line 5759 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator= ( const T &  rdSrc)
inline

Assignment operator.

Assigns real or complex number to calling basic_function object and makes it to be constant function of variables originally set. Returns reference to the object changed.

Example:
using namespace cvm;
using namespace std;
rfunction rf1("{x} x*2");
rf1 = 1.234;
std::cout << rf1 << std::endl;
rf2 = 1.234;
std::cout << rf2 << std::endl;
cfunction cf("{x} x*2");
cf = complex<double>(1., 2.);
std::cout << cf << std::endl;
prints
{x} 1.234
1.234
{x} (1,2)
Parameters
[in]rdSrcConst reference to number to assign.
Returns
Reference to changed calling function.

Definition at line 5798 of file cfun.h.

template<typename T>
basic_function basic_function< T >::operator- ( ) const
inline

Unary minus operator.

Creates basic_function object as calling function with opposite sign.

Example:
using namespace cvm;
rfunction rf("{x} x*2");
std::cout << -rf << std::endl;
std::cout << (-rf).simp() << std::endl;
cfunction cf("{x} x*(1,2)");
std::cout << -cf << std::endl;
std::cout << (-cf).simp() << std::endl;
prints
{x} -x*2
{x} (-2)*x
{x} -x*(1,2)
{x} (-1,-2)*x
Returns
Function object.

Definition at line 5828 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator+ ( const basic_function< T > &  rf) const throw (cvmexception)
inline

Addition operator.

Creates basic_function object as sum of calling function and function referred by rf. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
rfunction rf1("{x,y} x*2");
rfunction rf2("{x,y} y*3");
std::cout << (rf1 + rf2) << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
std::cout << (cf1 + cf2) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*2+y*3
{x,y} x*(1,2)+y*(3,4)
Parameters
[in]rfConst reference to function to add.
Returns
Function object.

Definition at line 5862 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator- ( const basic_function< T > &  rf) const throw (cvmexception)
inline

Subtraction operator.

Creates basic_function object as difference of calling function and function referred by rf. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try {
rfunction rf1("{x,y} x*2");
rfunction rf2("{x,y} y*3");
std::cout << (rf1 - rf2) << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
std::cout << (cf1 - cf2) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*2-y*3
{x,y} x*(1,2)-y*(3,4)
Parameters
[in]rfConst reference to function to subtract.
Returns
Function object.

Definition at line 5896 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator* ( const basic_function< T > &  rf) const throw (cvmexception)
inline

Multiplication operator.

Creates basic_function object as product of calling function and function referred by rf. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
rfunction rf1("{x,y} x*2");
rfunction rf2("{x,y} y*3");
std::cout << (rf1 * rf2) << std::endl;
std::cout << (rf1 * rf2).simp() << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
std::cout << (cf1 * cf2) << std::endl;
std::cout << (cf1 * cf2).simp() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*2*y*3
{x,y} 6*y*x
{x,y} x*(1,2)*y*(3,4)
{x,y} (-5,10)*y*x
Parameters
[in]rfConst reference to function to multiply by.
Returns
Function object.

Definition at line 5934 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator/ ( const basic_function< T > &  rf) const throw (cvmexception)
inline

Division operator.

Creates basic_function object as calling function divided by function referred by rf. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
rfunction rf1("{x,y} x*2");
rfunction rf2("{x,y} y*2");
std::cout << (rf1 / rf2) << std::endl;
std::cout << (rf1 / rf2).simp() << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
std::cout << (cf1 / cf2) << std::endl;
std::cout << (cf1 / cf2).simp() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*2/(y*2)
{x,y} x/y
{x,y} x*(1,2)/(y*(3,4))
{x,y} x*(0.44,0.08)/y
Parameters
[in]rfConst reference to function to divide by.
Returns
Function object.

Definition at line 5972 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator^ ( const basic_function< T > &  rf) const throw (cvmexception)
inline

Power to operator.

Creates basic_function object as calling function powered to function referred by rf. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
rfunction rf1("{x,y} x*2");
rfunction rf2("{x,y} y*2");
std::cout << (rf1 ^ rf2) << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
std::cout << (cf1 ^ cf2) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} (x*2)^(y*2)
{x,y} (x*(1,2))^(y*(3,4))
Parameters
[in]rfConst reference to function to power to.
Returns
Function object.

Definition at line 6006 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function& basic_function< T >::operator+= ( const basic_function< T > &  rf) throw (cvmexception)
inline

Increment operator.

Adds to calling basic_function function referred by rf and returns reference to the object changed. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
rfunction rf1("{x,y} x*3");
rfunction rf2("{x,y} y*2");
rf1 += rf2;
std::cout << rf1 << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
cf1 += cf2;
std::cout << cf1 << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*3+y*2
{x,y} x*(1,2)+y*(3,4)
Parameters
[in]rfConst reference to function to add.
Returns
Reference to changed calling function.

Definition at line 6043 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator-= ( const basic_function< T > &  rf) throw (cvmexception)
inline

Decrement operator.

Subtracts from calling basic_function function referred by rf and returns reference to the object changed. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
rfunction rf1("{x,y} x*3");
rfunction rf2("{x,y} y*2");
rf1 -= rf2;
std::cout << rf1 << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
cf1 -= cf2;
std::cout << cf1 << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*3-y*2
{x,y} x*(1,2)-y*(3,4)
Parameters
[in]rfConst reference to function to subtract.
Returns
Reference to changed calling function.

Definition at line 6083 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator*= ( const basic_function< T > &  rf) throw (cvmexception)
inline

Multiply and assign operator.

Multiplies calling basic_function by function referred by rf and returns reference to the object changed. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
rfunction rf1("{x,y} x*3");
rfunction rf2("{x,y} y*2");
rf1 *= rf2;
std::cout << rf1 << std::endl;
std::cout << rf1.simp() << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
cf1 *= cf2;
std::cout << cf1 << std::endl;
std::cout << cf1.simp() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*3*y*2
{x,y} 6*y*x
{x,y} x*(1,2)*y*(3,4)
{x,y} (-5,10)*y*x
Parameters
[in]rfConst reference to function to multiply by.
Returns
Reference to changed calling function.

Definition at line 6127 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator/= ( const basic_function< T > &  rf) throw (cvmexception)
inline

Divide and assign operator.

Divides calling basic_function by function referred by rf and returns reference to the object changed. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
rfunction rf1("{x,y} x*3");
rfunction rf2("{x,y} y*2");
rf1 /= rf2;
std::cout << rf1 << std::endl;
std::cout << rf1.simp() << std::endl;
cfunction cf1("{x,y} x*(1,2)");
cfunction cf2("{x,y} y*(3,4)");
cf1 /= cf2;
std::cout << cf1 << std::endl;
std::cout << cf1.simp() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*3/(y*2)
{x,y} x*1.5/y
{x,y} x*(1,2)/(y*(3,4))
{x,y} x*(0.44,0.08)/y
Parameters
[in]rfConst reference to function to multiply by.
Returns
Reference to changed calling function.

Definition at line 6171 of file cfun.h.

template<typename T>
basic_function basic_function< T >::operator+ ( const T &  d) const throw (cvmexception)
inline

Addition operator.

Creates basic_function object as sum of calling function and real or complex number referred by d.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
std::cout << (rf + 2.) << std::endl;
cfunction cf("{x,y} x*(1,2)");
std::cout << (cf + complex<double>(3., 4.)) << std::endl;
prints
{x,y} x*3+2
{x,y} x*(1,2)+(3,4)
Parameters
[in]dConst reference to number to add.
Returns
Function object.

Definition at line 6200 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator- ( const T &  d) const throw (cvmexception)
inline

Subtraction operator.

Creates basic_function object as difference of calling function and real or complex number referred by d.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
std::cout << (rf - 2.) << std::endl;
cfunction cf("{x,y} x*(1,2)");
std::cout << (cf - complex<double>(3., 4.)) << std::endl;
prints
{x,y} x*3-2
{x,y} x*(1,2)-(3,4)
Parameters
[in]dConst reference to number to subtract.
Returns
Function object.

Definition at line 6227 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator* ( const T &  d) const throw (cvmexception)
inline

Multiplication operator.

Creates basic_function object as product of calling function and real or complex number referred by d.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
std::cout << rf * 2. << std::endl;
std::cout << (rf * 2.).simp() << std::endl;
cfunction cf("{x,y} x*(1,2)");
std::cout << cf * complex<double>(3., 4.) << std::endl;
std::cout << (cf * complex<double>(3., 4.)).simp() << std::endl;
prints
{x,y} x*3*2
{x,y} 6*x
{x,y} x*(1,2)*(3,4)
{x,y} (-5,10)*x
Parameters
[in]dConst reference to number to multiply by.
Returns
Function object.

Definition at line 6258 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator/ ( const T &  d) const throw (cvmexception)
inline

Division operator.

Creates basic_function object as division of calling function by real or complex number referred by d.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
std::cout << rf / 2. << std::endl;
std::cout << (rf / 2.).simp() << std::endl;
cfunction cf("{x,y} x*(1,2)");
std::cout << cf / complex<double>(3., 4.) << std::endl;
std::cout << (cf / complex<double>(3., 4.)).simp() << std::endl;
prints
{x,y} x*3/2
{x,y} x*1.5
{x,y} x*(1,2)/(3,4)
{x,y} x*(0.44,0.08)
Parameters
[in]dConst reference to number to multiply by.
Returns
Function object.

Definition at line 6288 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::operator^ ( const T &  d) const throw (cvmexception)
inline

Power to operator.

Creates basic_function object as power of calling function to real or complex number referred by d.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
std::cout << (rf ^ 2.) << std::endl;
cfunction cf("{x,y} x*(1,2)");
std::cout << (cf ^ complex<double>(3., 4.)) << std::endl;
prints
{x,y} (x*3)^2
{x,y} (x*(1,2))^(3,4)
Parameters
[in]dConst reference to number to power to.
Returns
Function object.

Definition at line 6314 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function& basic_function< T >::operator+= ( const T &  d) throw (cvmexception)
inline

Increment operator.

Adds to calling basic_function real or complex number referred by d and returns reference to the object changed.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
rf += 2.;
std::cout << rf << std::endl;
cfunction cf("{x,y} x*(1,2)");
cf += complex<double>(3., 4.);
std::cout << cf << std::endl;
prints
{x,y} x*3+2
{x,y} x*(1,2)+(3,4)
Parameters
[in]dNumber to add.
Returns
Reference to changed calling function.

Definition at line 6343 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator-= ( const T &  d) throw (cvmexception)
inline

Decrement operator.

Subtracts from calling basic_function real or complex number referred by d and returns reference to the object changed.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
rf -= 2.;
std::cout << rf << std::endl;
cfunction cf("{x,y} x*(1,2)");
cf -= complex<double>(3., 4.);
std::cout << cf << std::endl;
prints
{x,y} x*3-2
{x,y} x*(1,2)-(3,4)
Parameters
[in]dNumber to subtract.
Returns
Reference to changed calling function.

Definition at line 6374 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator*= ( const T &  d) throw (cvmexception)
inline

Multiply and assign operator.

Multiplies calling basic_function by real or complex number referred by d and returns reference to the object changed.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
rf *= 2.;
std::cout << rf << std::endl;
std::cout << rf.simp() << std::endl;
cfunction cf("{x,y} x*(1,2)");
cf *= complex<double>(3., 4.);
std::cout << cf << std::endl;
std::cout << cf.simp() << std::endl;
prints
{x,y} x*3*2
{x,y} 6*x
{x,y} x*(1,2)*(3,4)
{x,y} (-5,10)*x
Parameters
[in]dNumber to multiply by.
Returns
Reference to changed calling function.

Definition at line 6409 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator/= ( const T &  d) throw (cvmexception)
inline

Divide and assign operator.

Divides calling basic_function by real or complex number referred by d and returns reference to the object changed.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
rf /= 2.;
std::cout << rf << std::endl;
std::cout << rf.simp() << std::endl;
cfunction cf("{x,y} x*(1,2)");
cf /= complex<double>(3., 4.);
std::cout << cf << std::endl;
std::cout << cf.simp() << std::endl;
prints
{x,y} x*3/2
{x,y} x*1.5
{x,y} x*(1,2)/(3,4)
{x,y} x*(0.44,0.08)
Parameters
[in]dNumber to divide by.
Returns
Reference to changed calling function.

Definition at line 6444 of file cfun.h.

template<typename T>
basic_function& basic_function< T >::operator^= ( const T &  d) throw (cvmexception)
inline

Power to and assign operator.

Powers calling basic_function to real or complex number referred by d and returns reference to the object changed.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
rf ^= 2.;
std::cout << rf << std::endl;
cfunction cf("{x,y} x*(1,2)");
cf ^= complex<double>(3., 4.);
std::cout << cf << std::endl;
prints
{x,y} (x*3)^2
{x,y} (x*(1,2))^(3,4)
Parameters
[in]dNumber to power to.
Returns
Reference to changed calling function.

Definition at line 6475 of file cfun.h.

template<typename T>
basic_function basic_function< T >::sat ( const basic_function< T > &  rf) const throw (cvmexception)
inline

Satellite function.

Creates basic_function object as satellite of calling basic_function and function referred by rf. For complex numbers real part is used only. Function throws cvmexception if variables don't match.

\[ \texttt{sat(x,y)}= \left\{ \begin{aligned} 1 & \text{ if } x > |y|\\ 0 & \text{ if } -|y| \le x \le |y|\\ -1 & \text{ if } x < -|y| \end{aligned} \right.\\ \]

Example:
using namespace cvm;
using namespace std;
try{
rfunction rf1("{x,y} x");
rfunction rf2("{x,y} y");
rfunction rs = rf1.sat(rf2);
std::cout << rs << std::endl;
std::cout << rs(1.5,1.) << std::endl;
std::cout << rs(0.5,1.) << std::endl;
std::cout << rs(-1.5,1.) << std::endl;
cfunction cf1("{x,y} x");
cfunction cf2("{x,y} y");
cfunction cs = cf1.sat(cf2);
std::cout << cs << std::endl;
std::cout << cs(complex<double>(1.5, 0.), complex<double>(1., 1.)) << std::endl;
std::cout << cs(complex<double>(0.5, 0.), complex<double>(1., 1.)) << std::endl;
std::cout << cs(complex<double>(-1.5, 0.), complex<double>(1., 1.)) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} sat(x,y)
1
0
-1
{x,y} sat(x,y)
(1,0)
(0,0)
(-1,0)
Parameters
[in]rfConst reference to other function.
Returns
Function object.

Definition at line 6540 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::exp ( ) const
inline

Exponent.

Creates basic_function object as exponent of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.exp();
std::cout << re << std::endl;
std::cout << re(1.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.exp();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0., 3.141592653589793)) << std::endl;
prints
{x} exp(x)
2.71828
{x} exp(x)
(-1,1.22465e-016)
Returns
Function object.

Definition at line 6570 of file cfun.h.

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T>
basic_function basic_function< T >::sqrt ( ) const
inline

Square root.

Creates basic_function object as square root of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.sqrt();
std::cout << re << std::endl;
std::cout << re(9.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.sqrt();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(-1.,0.)) << std::endl;
prints
{x} sqrt(x)
3
{x} sqrt(x)
(0,1)
Returns
Function object.

Definition at line 6601 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::log ( ) const
inline

Natural logarithm.

Creates basic_function object as natural logarithm of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.log();
std::cout << re << std::endl;
std::cout << re(::exp(1.)) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.log();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(-1.,0.)) << std::endl;
prints
{x} log(x)
1
{x} log(x)
(0,3.14159)
Returns
Function object.

Definition at line 6632 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::log10 ( ) const
inline

Common (base 10) logarithm.

Creates basic_function object as common (base 10) logarithm of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.log10();
std::cout << re << std::endl;
std::cout << re(100.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.log10();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(1.,0.)) << std::endl;
prints
{x} log10(x)
2
{x} log10(x)
(0,0)
Returns
Function object.

Definition at line 6663 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::sin ( ) const
inline

Sine.

Creates basic_function object as sine of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.sin();
std::cout << re << std::endl;
std::cout << re(3.141592653589793 / 2.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.sin();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,3.141592653589793)) << std::endl;
prints
{x} sin(x)
1
{x} sin(x)
(0,11.5487)
Returns
Function object.

Definition at line 6694 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::cos ( ) const
inline

Cosine.

Creates basic_function object as cosine of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.cos();
std::cout << re << std::endl;
std::cout << re(0.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.cos();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,3.141592653589793)) << std::endl;
prints
{x} cos(x)
1
{x} cos(x)
(11.592,-0)
Returns
Function object.

Definition at line 6725 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::tan ( ) const
inline

Tangent.

Creates basic_function object as tangent of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.tan();
std::cout << re << std::endl;
std::cout << re(3.141592653589793 / 4.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.tan();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,3.141592653589793)) << std::endl;
prints
{x} tan(x)
1
{x} tan(x)
(0,0.996272)
Returns
Function object.

Definition at line 6755 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::asin ( ) const
inline

Arcsine.

Creates basic_function object as arcsine of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.asin();
std::cout << re << std::endl;
std::cout << re(-1.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.asin();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,2.)) << std::endl;
prints
{x} asin(x)
-1.5708
{x} asin(x)
(0,1.44364)
Returns
Function object.

Definition at line 6785 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::acos ( ) const
inline

Arc cosine.

Creates basic_function object as arc cosine of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.acos();
std::cout << re << std::endl;
std::cout << re(-1.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.acos();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,2.)) << std::endl;
prints
{x} acos(x)
3.14159
{x} acos(x)
(1.5708,-1.44364)
Returns
Function object.

Definition at line 6815 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::atan ( ) const
inline

Arc tangent.

Creates basic_function object as arc tangent of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.atan();
std::cout << re << std::endl;
std::cout << re(1.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.atan();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,0.5)) << std::endl;
prints
{x} atan(x)
0.785398
{x} atan(x)
(0,0.549306)
Returns
Function object.

Definition at line 6846 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::sinh ( ) const
inline

Hyperbolic sine.

Creates basic_function object as hyperbolic sine of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.sinh();
std::cout << re << std::endl;
std::cout << re(1.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.sinh();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,1.)) << std::endl;
prints
{x} sinh(x)
1.1752
{x} sinh(x)
(0,0.841471)
Returns
Function object.

Definition at line 6877 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::cosh ( ) const
inline

Hyperbolic cosine.

Creates basic_function object as hyperbolic cosine of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.cosh();
std::cout << re << std::endl;
std::cout << re(1.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.cosh();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,1.)) << std::endl;
prints
{x} cosh(x)
1.54308
{x} cosh(x)
(0.540302,0)
Returns
Function object.

Definition at line 6908 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::tanh ( ) const
inline

Hyperbolic tangent.

Creates basic_function object as hyperbolic tangent of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.tanh();
std::cout << re << std::endl;
std::cout << re(1.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.tanh();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,1.)) << std::endl;
prints
{x} tanh(x)
0.761594
{x} tanh(x)
(0,1.55741)
Returns
Function object.

Definition at line 6939 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::sinint ( ) const
inline

Integral sine.

Creates basic_function object as integral sine of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.sinint();
std::cout << re << std::endl;
std::cout << re(1000.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.sinint();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,1.)) << std::endl;
prints
{x} sinint(x)
1.57023
{x} sinint(x)
(0,1.05725)
Returns
Function object.

Definition at line 6970 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::cosint ( ) const
inline

Integral cosine.

Creates basic_function object as integral cosine of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.cosint();
std::cout << re << std::endl;
std::cout << re(1000.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.cosint();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(0.,1.)) << std::endl;
prints
{x} cosint(x)
0.000826316
{x} cosint(x)
(0.837867,1.5708)
Returns
Function object.

Definition at line 7001 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::sign ( ) const
inline

Sign.

Creates basic_function object as sign of calling function. For complex numbers real part is used only.

\[ \texttt{sign(x)}= \left\{ \begin{aligned} -1 & \text{ if } x < 0\\ 0 & \text{ if } x = 0\\ 1 & \text{ if } x > 0 \end{aligned} \right.\\ \]

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.sign();
std::cout << re << std::endl;
std::cout << re(-2.) << std::endl;
std::cout << re(0.) << std::endl;
std::cout << re(3.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.sign();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(-2.,1.)) << std::endl;
std::cout << ce(complex<double>(0.,1.)) << std::endl;
std::cout << ce(complex<double>(3.,1.)) << std::endl;
prints
{x} sign(x)
-1
0
1
{x} sign(x)
(-1,0)
(0,0)
(1,0)
Returns
Function object.

Definition at line 7052 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::abs ( ) const
inline

Absolute value.

Creates basic_function object as absolute value of calling function.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x} x");
rfunction re = rf.abs();
std::cout << re << std::endl;
std::cout << re(-2.) << std::endl;
std::cout << re(0.) << std::endl;
std::cout << re(3.) << std::endl;
cfunction cf("{x} x");
cfunction ce = cf.abs();
std::cout << ce << std::endl;
std::cout << ce(complex<double>(-1.,1.)) << std::endl;
std::cout << ce(complex<double>(0.,1.)) << std::endl;
std::cout << ce(complex<double>(1.,1.)) << std::endl;
prints
{x} abs(x)
2
0
3
{x} abs(x)
(1.41421,0)
(1,0)
(1.41421,0)
Returns
Function object.

Definition at line 7091 of file cfun.h.

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T>
basic_function basic_function< T >::delta ( const basic_function< T > &  rf) const throw (cvmexception)
inline

Delta function.

Creates basic_function object as delta function of calling basic_function and function referred by rf. For complex numbers real part is used only. Function throws cvmexception if variables don't match.

\[ \texttt{delta(x,y)}= \left\{ \begin{aligned} 0 & \text{ if } |x - y| = 0\\ \infty & \text{ if } |x - y| \ne 0 \end{aligned} \right.\\ \]

Example:
using namespace cvm;
using namespace std;
try{
rfunction rf1("{x,y} x");
rfunction rf2("{x,y} y");
rfunction rd = rf1.delta(rf2);
std::cout << rd << std::endl;
std::cout << rd(1.5,1.) << std::endl;
std::cout << rd(1.,1.) << std::endl;
cfunction cf1("{x,y} x");
cfunction cf2("{x,y} y");
cfunction cd = cf1.delta(cf2);
std::cout << cd << std::endl;
std::cout << cd(complex<double>(1., 1.), complex<double>(1., 0.)) << std::endl;
std::cout << cd(complex<double>(0.5, 1.), complex<double>(1., 0.)) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what() << std::endl;
}
prints
{x,y} delta(x,y)
0
1.79769e+308
{x,y} delta(x,y)
(1.79769e+308,0)
(0,0)
Parameters
[in]rfConst reference to other function.
Returns
Function object.

Definition at line 7149 of file cfun.h.

Here is the call graph for this function:

template<typename T>
basic_function basic_function< T >::iif ( const basic_function< T > &  rfNeg,
const basic_function< T > &  rfNotNeg 
) const throw (cvmexception)
inline

Immediate If function.

Creates basic_function object as Immediate If function of calling basic_function and functions referred by rfNeg and rfNotNeg. For complex numbers real part of calling function is used only. Function throws cvmexception if variables don't match.

\[ \texttt{iif(x,expr1,expr2)}= \left\{ \begin{aligned} expr1 & \text{ if } x < 0\\ expr2 & \text{ if } x \ge 0 \end{aligned} \right.\\ \]

Example:
using namespace cvm;
using namespace std;
try{
rfunction rf("{x,y,z} x");
rfunction rf1("{x,y,z} y");
rfunction rf2("{x,y,z} z");
rfunction ri = rf.iif(rf1,rf2);
std::cout << ri << std::endl;
std::cout << ri(-1.,1.,2.) << std::endl;
std::cout << ri( 0.,1.,2.) << std::endl;
cfunction cf("{x,y,z} x");
cfunction cf1("{x,y,z} y");
cfunction cf2("{x,y,z} z");
cfunction ci = cf.iif(cf1,cf2);
std::cout << ci << std::endl;
std::cout << ci(complex<double>(-1.,1.), complex<double>(1.,1.), complex<double>(2.,2.)) << std::endl;
std::cout << ci(complex<double>( 0.,1.), complex<double>(1.,1.), complex<double>(2.,2.)) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what() << std::endl;
}
prints
{x,y,z} iif(x,y,z)
1
2
{x,y,z} iif(x,y,z)
(1,1)
(2,2)
Parameters
[in]rfNegConst reference to function for negative calling function value.
[in]rfNotNegConst reference to function for non-negative calling function value.
Returns
Function object.

Definition at line 7211 of file cfun.h.

Here is the call graph for this function:

Friends And Related Function Documentation

template<typename T>
basic_function<T> operator+ ( const T &  d,
const basic_function< T > &  rf 
)
friend

Addition operator (left sided)

Creates basic_function object as sum of real or complex number referred by d and function referred by rf.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
std::cout << (2. + rf) << std::endl;
cfunction cf("{x,y} x*(1,2)");
std::cout << (complex<double>(3., 4.) + cf) << std::endl;
prints
{x,y} x*3+2
{x,y} x*(1,2)+(3,4)
Parameters
[in]dConst reference to number to add to.
[in]rfConst reference to function to add.
Returns
Function object.

Definition at line 7243 of file cfun.h.

template<typename T>
basic_function<T> operator- ( const T &  d,
const basic_function< T > &  rf 
)
friend

Subtraction operator (left sided)

Creates basic_function object as difference of real or complex number referred by d and function referred by rf.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
std::cout << (2. - rf) << std::endl;
cfunction cf("{x,y} x*(1,2)");
std::cout << (complex<double>(3., 4.) - cf) << std::endl;
prints
{x,y} 2-x*3
{x,y} (3,4)-x*(1,2)
Parameters
[in]dConst reference to number to subtract from.
[in]rfConst reference to function to subtract.
Returns
Function object.

Definition at line 7270 of file cfun.h.

template<typename T>
basic_function<T> operator* ( const T &  d,
const basic_function< T > &  rf 
)
friend

Multiplication operator (left sided)

Creates basic_function object as product of real or complex number referred by d and function referred by rf.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*3");
std::cout << 2. * rf << std::endl;
std::cout << (2. * rf).simp() << std::endl;
cfunction cf("{x,y} x*(1,2)");
std::cout << complex<double>(3., 4.) * cf << std::endl;
std::cout << (complex<double>(3., 4.) * cf).simp() << std::endl;
prints
{x,y} x*3*2
{x,y} 6*x
{x,y} x*(1,2)*(3,4)
{x,y} (-5,10)*x
Parameters
[in]dConst reference to number to multiply.
[in]rfConst reference to function to multiply by.
Returns
Function object.

Definition at line 7301 of file cfun.h.

template<typename T>
basic_function<T> operator/ ( const T &  d,
const basic_function< T > &  rf 
)
friend

Division operator (left sided)

Creates basic_function object as division of real or complex number referred by d by function referred by rf.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*2");
std::cout << 3. / rf << std::endl;
std::cout << (3. / rf).simp() << std::endl;
cfunction cf("{x,y} x*(3,4)");
std::cout << complex<double>(1., 2.) / cf << std::endl;
std::cout << (complex<double>(1., 2.) / cf).simp() << std::endl;
prints
{x,y} 3/(x*2)
{x,y} 1.5/x
{x,y} (1,2)/(x*(3,4))
{x,y} (0.44,0.08)/x
Parameters
[in]dConst reference to number to divide.
[in]rfConst reference to function to divide by.
Returns
Function object.

Definition at line 7332 of file cfun.h.

template<typename T>
basic_function<T> operator^ ( const T &  d,
const basic_function< T > &  rf 
)
friend

Power to operator (left sided)

Creates basic_function object as power of real or complex number referred by d to function referred by rf

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x");
std::cout << (2. ^ rf) << std::endl;
cfunction cf("{x,y} x");
std::cout << (complex<double>(3., 4.) ^ cf) << std::endl;
prints
{x,y} 2^x
{x,y} (3,4)^x
Parameters
[in]dConst reference to number to power.
[in]rfConst reference to function to power to.
Returns
Function object.

Definition at line 7359 of file cfun.h.

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
const basic_function< T > &  rf 
)
friend

Output operator.

Prints function referred by rf to output stream referred by os using Wolfram's Mathemaca syntax {var1[,var2,...]} expr.

Example:
using namespace cvm;
using namespace std;
rfunction rf("{x,y} x*y + x^2");
std::cout << rf << std::endl;
cfunction cf("{x,y} x*y + x^2");
std::cout << cf << std::endl;
prints
{x,y} x*y+x^2
{x,y} x*y+x^(2,0)
Parameters
[in]osReference to output stream.
[in]rfConst reference to function to print.
Returns
Reference to output stream.

Definition at line 7388 of file cfun.h.

Member Data Documentation

template<typename T>
string_array basic_function< T >::mvars
mutableprotected

Array of variables.

Definition at line 4925 of file cfun.h.

template<typename T>
BasePointer basic_function< T >::mp
protected

Pointer to function's instance.

Definition at line 4926 of file cfun.h.


The documentation for this class was generated from the following file: