C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Functions
exprtk Namespace Reference

Namespaces

namespace  details
 
namespace  helper
 
namespace  information
 
namespace  lexer
 
namespace  parser_error
 
namespace  rtl
 

Classes

struct  assert_check
 
struct  compilation_check
 
class  expression
 
class  expression_helper
 
class  function_compositor
 
class  function_traits
 
class  ifunction
 
class  igeneric_function
 
class  ivararg_function
 
struct  loop_runtime_check
 
class  parser
 
class  polynomial
 
class  results_context
 
class  stringvar_base
 
class  symbol_table
 
class  timer
 
struct  type_defs
 
struct  type_store
 
struct  vector_access_runtime_check
 
class  vector_view
 

Typedefs

typedef loop_runtime_checkloop_runtime_check_ptr
 
typedef vector_access_runtime_checkvector_access_runtime_check_ptr
 
typedef assert_checkassert_check_ptr
 
typedef compilation_checkcompilation_check_ptr
 

Functions

template<typename T >
vector_view< T > make_vector_view (T *data, const std::size_t size, const std::size_t offset=0)
 
template<typename T >
vector_view< T > make_vector_view (std::vector< T > &v, const std::size_t size, const std::size_t offset=0)
 
template<typename StringView >
std::string to_str (const StringView &view)
 
template<typename FunctionType >
void enable_zero_parameters (FunctionType &func)
 
template<typename FunctionType >
void disable_zero_parameters (FunctionType &func)
 
template<typename FunctionType >
void enable_has_side_effects (FunctionType &func)
 
template<typename FunctionType >
void disable_has_side_effects (FunctionType &func)
 
template<typename FunctionType >
void set_min_num_args (FunctionType &func, const std::size_t &num_args)
 
template<typename FunctionType >
void set_max_num_args (FunctionType &func, const std::size_t &num_args)
 
template<typename T >
bool is_valid (const expression< T > &expr)
 
template<typename Allocator , template< typename, typename > class Sequence>
bool collect_variables (const std::string &expression, Sequence< std::string, Allocator > &symbol_list)
 
template<typename T , typename Allocator , template< typename, typename > class Sequence>
bool collect_variables (const std::string &expression, exprtk::symbol_table< T > &extrnl_symbol_table, Sequence< std::string, Allocator > &symbol_list)
 
template<typename Allocator , template< typename, typename > class Sequence>
bool collect_functions (const std::string &expression, Sequence< std::string, Allocator > &symbol_list)
 
template<typename T , typename Allocator , template< typename, typename > class Sequence>
bool collect_functions (const std::string &expression, exprtk::symbol_table< T > &extrnl_symbol_table, Sequence< std::string, Allocator > &symbol_list)
 
template<typename T >
integrate (const expression< T > &e, T &x, const T &r0, const T &r1, const std::size_t number_of_intervals=1000000)
 
template<typename T >
integrate (const expression< T > &e, const std::string &variable_name, const T &r0, const T &r1, const std::size_t number_of_intervals=1000000)
 
template<typename T >
derivative (const expression< T > &e, T &x, const T &h=T(0.00000001))
 
template<typename T >
second_derivative (const expression< T > &e, T &x, const T &h=T(0.00001))
 
template<typename T >
third_derivative (const expression< T > &e, T &x, const T &h=T(0.0001))
 
template<typename T >
derivative (const expression< T > &e, const std::string &variable_name, const T &h=T(0.00000001))
 
template<typename T >
second_derivative (const expression< T > &e, const std::string &variable_name, const T &h=T(0.00001))
 
template<typename T >
third_derivative (const expression< T > &e, const std::string &variable_name, const T &h=T(0.0001))
 
template<typename T >
bool compute (const std::string &expression_string, T &result)
 
template<typename T >
bool compute (const std::string &expression_string, const T &x, T &result)
 
template<typename T >
bool compute (const std::string &expression_string, const T &x, const T &y, T &result)
 
template<typename T >
bool compute (const std::string &expression_string, const T &x, const T &y, const T &z, T &result)
 

Typedef Documentation

◆ assert_check_ptr

Definition at line 2212 of file exprtk.hpp.

◆ compilation_check_ptr

Definition at line 2227 of file exprtk.hpp.

◆ loop_runtime_check_ptr

Definition at line 2168 of file exprtk.hpp.

◆ vector_access_runtime_check_ptr

Definition at line 2192 of file exprtk.hpp.

Function Documentation

◆ collect_functions() [1/2]

template<typename T , typename Allocator , template< typename, typename > class Sequence>
bool exprtk::collect_functions ( const std::string &  expression,
exprtk::symbol_table< T > &  extrnl_symbol_table,
Sequence< std::string, Allocator > &  symbol_list 
)
inline

Definition at line 41835 of file exprtk.hpp.

41838 {
41839 typedef details::collector_helper<T> collect_t;
41840
41841 std::set<std::string> symbol_set;
41842
41843 const bool variable_pass = collect_t::collection_pass
41844 (expression, symbol_set, false, true, false, extrnl_symbol_table);
41845 const bool vector_pass = collect_t::collection_pass
41846 (expression, symbol_set, false, true, true, extrnl_symbol_table);
41847
41848 if (!variable_pass && !vector_pass)
41849 return false;
41850
41851 std::set<std::string>::iterator itr = symbol_set.begin();
41852
41853 while (symbol_set.end() != itr)
41854 {
41855 symbol_list.push_back(*itr);
41856 ++itr;
41857 }
41858
41859 return true;
41860 }

◆ collect_functions() [2/2]

template<typename Allocator , template< typename, typename > class Sequence>
bool exprtk::collect_functions ( const std::string &  expression,
Sequence< std::string, Allocator > &  symbol_list 
)
inline

Definition at line 41803 of file exprtk.hpp.

41805 {
41806 typedef double T;
41807 typedef details::collector_helper<T> collect_t;
41808
41809 collect_t::symbol_table_t null_symbol_table;
41810
41811 std::set<std::string> symbol_set;
41812
41813 const bool variable_pass = collect_t::collection_pass
41814 (expression, symbol_set, false, true, false, null_symbol_table);
41815 const bool vector_pass = collect_t::collection_pass
41816 (expression, symbol_set, false, true, true, null_symbol_table);
41817
41818 if (!variable_pass && !vector_pass)
41819 return false;
41820
41821 std::set<std::string>::iterator itr = symbol_set.begin();
41822
41823 while (symbol_set.end() != itr)
41824 {
41825 symbol_list.push_back(*itr);
41826 ++itr;
41827 }
41828
41829 return true;
41830 }

Referenced by exprtk::details::collector_helper< T >::collection_pass(), extract_expression_dependents(), and run_test10().

Here is the caller graph for this function:

◆ collect_variables() [1/2]

template<typename T , typename Allocator , template< typename, typename > class Sequence>
bool exprtk::collect_variables ( const std::string &  expression,
exprtk::symbol_table< T > &  extrnl_symbol_table,
Sequence< std::string, Allocator > &  symbol_list 
)
inline

Definition at line 41774 of file exprtk.hpp.

41777 {
41778 typedef details::collector_helper<T> collect_t;
41779
41780 std::set<std::string> symbol_set;
41781
41782 const bool variable_pass = collect_t::collection_pass
41783 (expression, symbol_set, true, false, false, extrnl_symbol_table);
41784 const bool vector_pass = collect_t::collection_pass
41785 (expression, symbol_set, true, false, true, extrnl_symbol_table);
41786
41787 if (!variable_pass && !vector_pass)
41788 return false;
41789
41790 std::set<std::string>::iterator itr = symbol_set.begin();
41791
41792 while (symbol_set.end() != itr)
41793 {
41794 symbol_list.push_back(*itr);
41795 ++itr;
41796 }
41797
41798 return true;
41799 }

◆ collect_variables() [2/2]

template<typename Allocator , template< typename, typename > class Sequence>
bool exprtk::collect_variables ( const std::string &  expression,
Sequence< std::string, Allocator > &  symbol_list 
)
inline

Definition at line 41742 of file exprtk.hpp.

41744 {
41745 typedef double T;
41746 typedef details::collector_helper<T> collect_t;
41747
41748 collect_t::symbol_table_t null_symbol_table;
41749
41750 std::set<std::string> symbol_set;
41751
41752 const bool variable_pass = collect_t::collection_pass
41753 (expression, symbol_set, true, false, false, null_symbol_table);
41754 const bool vector_pass = collect_t::collection_pass
41755 (expression, symbol_set, true, false, true, null_symbol_table);
41756
41757 if (!variable_pass && !vector_pass)
41758 return false;
41759
41760 std::set<std::string>::iterator itr = symbol_set.begin();
41761
41762 while (symbol_set.end() != itr)
41763 {
41764 symbol_list.push_back(*itr);
41765 ++itr;
41766 }
41767
41768 return true;
41769 }

Referenced by exprtk::details::collector_helper< T >::collection_pass(), extract_expression_dependents(), and run_test10().

Here is the caller graph for this function:

◆ compute() [1/4]

template<typename T >
bool exprtk::compute ( const std::string &  expression_string,
const T &  x,
const T &  y,
const T &  z,
T &  result 
)
inline

Definition at line 42148 of file exprtk.hpp.

42151 {
42152 // Only 'x', 'y' or 'z'
42153 static const std::string x_var("x");
42154 static const std::string y_var("y");
42155 static const std::string z_var("z");
42156
42159 symbol_table.add_constant(x_var,x);
42160 symbol_table.add_constant(y_var,y);
42161 symbol_table.add_constant(z_var,z);
42162
42165
42167
42168 if (parser.compile(expression_string,expression))
42169 {
42170 result = expression.value();
42171
42172 return true;
42173 }
42174 else
42175 return false;
42176 }
bool register_symbol_table(symbol_table< T > &st)
Definition exprtk.hpp:21726
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:24443
bool add_constant(const std::string &constant_name, const T &value)
Definition exprtk.hpp:20782

References exprtk::symbol_table< T >::add_constant(), exprtk::symbol_table< T >::add_constants(), exprtk::parser< T >::compile(), exprtk::expression< T >::register_symbol_table(), and exprtk::expression< T >::value().

Here is the call graph for this function:

◆ compute() [2/4]

template<typename T >
bool exprtk::compute ( const std::string &  expression_string,
const T &  x,
const T &  y,
T &  result 
)
inline

Definition at line 42119 of file exprtk.hpp.

42122 {
42123 // Only 'x' and 'y'
42124 static const std::string x_var("x");
42125 static const std::string y_var("y");
42126
42129 symbol_table.add_constant(x_var,x);
42130 symbol_table.add_constant(y_var,y);
42131
42134
42136
42137 if (parser.compile(expression_string,expression))
42138 {
42139 result = expression.value();
42140
42141 return true;
42142 }
42143 else
42144 return false;
42145 }

References exprtk::symbol_table< T >::add_constant(), exprtk::symbol_table< T >::add_constants(), exprtk::parser< T >::compile(), exprtk::expression< T >::register_symbol_table(), and exprtk::expression< T >::value().

Here is the call graph for this function:

◆ compute() [3/4]

template<typename T >
bool exprtk::compute ( const std::string &  expression_string,
const T &  x,
T &  result 
)
inline

Definition at line 42092 of file exprtk.hpp.

42095 {
42096 // Only 'x'
42097 static const std::string x_var("x");
42098
42101 symbol_table.add_constant(x_var,x);
42102
42105
42107
42108 if (parser.compile(expression_string,expression))
42109 {
42110 result = expression.value();
42111
42112 return true;
42113 }
42114 else
42115 return false;
42116 }

References exprtk::symbol_table< T >::add_constant(), exprtk::symbol_table< T >::add_constants(), exprtk::parser< T >::compile(), exprtk::expression< T >::register_symbol_table(), and exprtk::expression< T >::value().

Here is the call graph for this function:

◆ compute() [4/4]

template<typename T >
bool exprtk::compute ( const std::string &  expression_string,
T &  result 
)
inline

Definition at line 42070 of file exprtk.hpp.

42071 {
42072 // No variables
42075
42078
42080
42081 if (parser.compile(expression_string,expression))
42082 {
42083 result = expression.value();
42084
42085 return true;
42086 }
42087 else
42088 return false;
42089 }

References exprtk::symbol_table< T >::add_constants(), exprtk::parser< T >::compile(), exprtk::expression< T >::register_symbol_table(), and exprtk::expression< T >::value().

Here is the call graph for this function:

◆ derivative() [1/2]

template<typename T >
T exprtk::derivative ( const expression< T > &  e,
const std::string &  variable_name,
const T &  h = T(0.00000001) 
)
inline

Definition at line 41979 of file exprtk.hpp.

41982 {
41983 const symbol_table<T>& sym_table = e.get_symbol_table();
41984
41985 if (!sym_table.valid())
41986 {
41987 return std::numeric_limits<T>::quiet_NaN();
41988 }
41989
41990 details::variable_node<T>* var = sym_table.get_variable(variable_name);
41991
41992 if (var)
41993 {
41994 T& x = var->ref();
41995 const T x_original = x;
41996 const T result = derivative(e, x, h);
41997 x = x_original;
41998
41999 return result;
42000 }
42001
42002 return std::numeric_limits<T>::quiet_NaN();
42003 }
variable_ptr get_variable(const std::string &variable_name) const
Definition exprtk.hpp:20579
bool valid() const
Definition exprtk.hpp:21295

References derivative(), exprtk::symbol_table< T >::get_variable(), exprtk::details::variable_node< T >::ref(), and exprtk::symbol_table< T >::valid().

Here is the call graph for this function:

◆ derivative() [2/2]

template<typename T >
T exprtk::derivative ( const expression< T > &  e,
T &  x,
const T &  h = T(0.00000001) 
)
inline

Definition at line 41915 of file exprtk.hpp.

41918 {
41919 const T x_init = x;
41920 const T _2h = T(2) * h;
41921
41922 x = x_init + _2h;
41923 const T y0 = e.value();
41924 x = x_init + h;
41925 const T y1 = e.value();
41926 x = x_init - h;
41927 const T y2 = e.value();
41928 x = x_init - _2h;
41929 const T y3 = e.value();
41930 x = x_init;
41931
41932 return (-y0 + T(8) * (y1 - y2) + y3) / (T(12) * h);
41933 }

Referenced by derivative(), and run_test07().

Here is the caller graph for this function:

◆ disable_has_side_effects()

template<typename FunctionType >
void exprtk::disable_has_side_effects ( FunctionType &  func)

Definition at line 19520 of file exprtk.hpp.

19521 {
19522 func.has_side_effects() = false;
19523 }

Referenced by myfunc< T >::myfunc(), and exprtk::polynomial< T, N >::polynomial().

Here is the caller graph for this function:

◆ disable_zero_parameters()

template<typename FunctionType >
void exprtk::disable_zero_parameters ( FunctionType &  func)

Definition at line 19508 of file exprtk.hpp.

19509 {
19510 func.allow_zero_parameters() = false;
19511 }

◆ enable_has_side_effects()

template<typename FunctionType >
void exprtk::enable_has_side_effects ( FunctionType &  func)

Definition at line 19514 of file exprtk.hpp.

19515 {
19516 func.has_side_effects() = true;
19517 }

◆ enable_zero_parameters()

template<typename FunctionType >
void exprtk::enable_zero_parameters ( FunctionType &  func)

Definition at line 19497 of file exprtk.hpp.

19498 {
19499 func.allow_zero_parameters() = true;
19500
19501 if (0 != func.min_num_args())
19502 {
19503 func.min_num_args() = 0;
19504 }
19505 }

Referenced by exprtk::rtl::io::print< T >::print(), exprtk::rtl::io::println< T >::println(), and va_func< T >::va_func().

Here is the caller graph for this function:

◆ integrate() [1/2]

template<typename T >
T exprtk::integrate ( const expression< T > &  e,
const std::string &  variable_name,
const T &  r0,
const T &  r1,
const std::size_t  number_of_intervals = 1000000 
)
inline

Definition at line 41887 of file exprtk.hpp.

41891 {
41892 const symbol_table<T>& sym_table = e.get_symbol_table();
41893
41894 if (!sym_table.valid())
41895 {
41896 return std::numeric_limits<T>::quiet_NaN();
41897 }
41898
41899 details::variable_node<T>* var = sym_table.get_variable(variable_name);
41900
41901 if (var)
41902 {
41903 T& x = var->ref();
41904 const T x_original = x;
41905 const T result = integrate(e, x, r0, r1, number_of_intervals);
41906 x = x_original;
41907
41908 return result;
41909 }
41910
41911 return std::numeric_limits<T>::quiet_NaN();
41912 }

References exprtk::symbol_table< T >::get_variable(), integrate(), exprtk::details::variable_node< T >::ref(), and exprtk::symbol_table< T >::valid().

Here is the call graph for this function:

◆ integrate() [2/2]

template<typename T >
T exprtk::integrate ( const expression< T > &  e,
T &  x,
const T &  r0,
const T &  r1,
const std::size_t  number_of_intervals = 1000000 
)
inline

Definition at line 41863 of file exprtk.hpp.

41867 {
41868 if (r0 > r1)
41869 return T(0);
41870
41871 const T h = (r1 - r0) / (T(2) * number_of_intervals);
41872 T total_area = T(0);
41873
41874 for (std::size_t i = 0; i < number_of_intervals; ++i)
41875 {
41876 x = r0 + T(2) * i * h;
41877 const T y0 = e.value(); x += h;
41878 const T y1 = e.value(); x += h;
41879 const T y2 = e.value(); x += h;
41880 total_area += h * (y0 + T(4) * y1 + y2) / T(3);
41881 }
41882
41883 return total_area;
41884 }

Referenced by integrate(), and run_test06().

Here is the caller graph for this function:

◆ is_valid()

template<typename T >
bool exprtk::is_valid ( const expression< T > &  expr)
inline

Definition at line 22034 of file exprtk.hpp.

22035 {
22036 return expr.control_block_ && !expression_helper<T>::is_null(expr);
22037 }
control_block * control_block_
Definition exprtk.hpp:21878

References exprtk::expression< T >::control_block_, and exprtk::expression_helper< T >::is_null().

Here is the call graph for this function:

◆ make_vector_view() [1/2]

template<typename T >
vector_view< T > exprtk::make_vector_view ( std::vector< T > &  v,
const std::size_t  size,
const std::size_t  offset = 0 
)
inline

Definition at line 4667 of file exprtk.hpp.

4669 {
4670 return vector_view<T>(v.data() + offset, size);
4671 }

◆ make_vector_view() [2/2]

template<typename T >
vector_view< T > exprtk::make_vector_view ( T *  data,
const std::size_t  size,
const std::size_t  offset = 0 
)
inline

Definition at line 4660 of file exprtk.hpp.

4662 {
4663 return vector_view<T>(data + offset, size);
4664 }

Referenced by run_test01(), run_test18(), run_test21(), vector_inline_resize_example(), and vector_resize_example().

Here is the caller graph for this function:

◆ second_derivative() [1/2]

template<typename T >
T exprtk::second_derivative ( const expression< T > &  e,
const std::string &  variable_name,
const T &  h = T(0.00001) 
)
inline

Definition at line 42006 of file exprtk.hpp.

42009 {
42010 const symbol_table<T>& sym_table = e.get_symbol_table();
42011
42012 if (!sym_table.valid())
42013 {
42014 return std::numeric_limits<T>::quiet_NaN();
42015 }
42016
42017 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42018
42019 if (var)
42020 {
42021 T& x = var->ref();
42022 const T x_original = x;
42023 const T result = second_derivative(e, x, h);
42024 x = x_original;
42025
42026 return result;
42027 }
42028
42029 return std::numeric_limits<T>::quiet_NaN();
42030 }

References exprtk::symbol_table< T >::get_variable(), exprtk::details::variable_node< T >::ref(), second_derivative(), and exprtk::symbol_table< T >::valid().

Here is the call graph for this function:

◆ second_derivative() [2/2]

template<typename T >
T exprtk::second_derivative ( const expression< T > &  e,
T &  x,
const T &  h = T(0.00001) 
)
inline

Definition at line 41936 of file exprtk.hpp.

41939 {
41940 const T x_init = x;
41941 const T _2h = T(2) * h;
41942
41943 const T y = e.value();
41944 x = x_init + _2h;
41945 const T y0 = e.value();
41946 x = x_init + h;
41947 const T y1 = e.value();
41948 x = x_init - h;
41949 const T y2 = e.value();
41950 x = x_init - _2h;
41951 const T y3 = e.value();
41952 x = x_init;
41953
41954 return (-y0 + T(16) * (y1 + y2) - T(30) * y - y3) / (T(12) * h * h);
41955 }

Referenced by run_test07(), and second_derivative().

Here is the caller graph for this function:

◆ set_max_num_args()

template<typename FunctionType >
void exprtk::set_max_num_args ( FunctionType &  func,
const std::size_t &  num_args 
)

Definition at line 19535 of file exprtk.hpp.

19536 {
19537 func.max_num_args() = num_args;
19538 }

Referenced by va_func< T >::va_func().

Here is the caller graph for this function:

◆ set_min_num_args()

template<typename FunctionType >
void exprtk::set_min_num_args ( FunctionType &  func,
const std::size_t &  num_args 
)

Definition at line 19526 of file exprtk.hpp.

19527 {
19528 func.min_num_args() = num_args;
19529
19530 if ((0 != func.min_num_args()) && func.allow_zero_parameters())
19531 func.allow_zero_parameters() = false;
19532 }

Referenced by va_func< T >::va_func().

Here is the caller graph for this function:

◆ third_derivative() [1/2]

template<typename T >
T exprtk::third_derivative ( const expression< T > &  e,
const std::string &  variable_name,
const T &  h = T(0.0001) 
)
inline

Definition at line 42033 of file exprtk.hpp.

42036 {
42037 const symbol_table<T>& sym_table = e.get_symbol_table();
42038
42039 if (!sym_table.valid())
42040 {
42041 return std::numeric_limits<T>::quiet_NaN();
42042 }
42043
42044 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42045
42046 if (var)
42047 {
42048 T& x = var->ref();
42049 const T x_original = x;
42050 const T result = third_derivative(e, x, h);
42051 x = x_original;
42052
42053 return result;
42054 }
42055
42056 return std::numeric_limits<T>::quiet_NaN();
42057 }

References exprtk::symbol_table< T >::get_variable(), exprtk::details::variable_node< T >::ref(), third_derivative(), and exprtk::symbol_table< T >::valid().

Here is the call graph for this function:

◆ third_derivative() [2/2]

template<typename T >
T exprtk::third_derivative ( const expression< T > &  e,
T &  x,
const T &  h = T(0.0001) 
)
inline

Definition at line 41958 of file exprtk.hpp.

41961 {
41962 const T x_init = x;
41963 const T _2h = T(2) * h;
41964
41965 x = x_init + _2h;
41966 const T y0 = e.value();
41967 x = x_init + h;
41968 const T y1 = e.value();
41969 x = x_init - h;
41970 const T y2 = e.value();
41971 x = x_init - _2h;
41972 const T y3 = e.value();
41973 x = x_init;
41974
41975 return (y0 + T(2) * (y2 - y1) - y3) / (T(2) * h * h * h);
41976 }

Referenced by run_test07(), and third_derivative().

Here is the caller graph for this function:

◆ to_str()

template<typename StringView >
std::string exprtk::to_str ( const StringView &  view)
inline

Definition at line 4869 of file exprtk.hpp.

4870 {
4871 return std::string(view.begin(),view.size());
4872 }

Referenced by exprtk::rtl::io::file::open< T >::operator()(), exprtk::rtl::vecops::sort< T >::operator()(), import_packages< T >::operator()(), gen_func< T >::operator()(), and exprtk::rtl::io::details::print_impl< T >::print().

Here is the caller graph for this function: