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  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 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

◆ compilation_check_ptr

Definition at line 2168 of file exprtk.hpp.

◆ loop_runtime_check_ptr

Definition at line 2129 of file exprtk.hpp.

◆ vector_access_runtime_check_ptr

Definition at line 2153 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 40353 of file exprtk.hpp.

40356 {
40357 typedef details::collector_helper<T> collect_t;
40358
40359 std::set<std::string> symbol_set;
40360
40361 const bool variable_pass = collect_t::collection_pass
40362 (expression, symbol_set, false, true, false, extrnl_symbol_table);
40363 const bool vector_pass = collect_t::collection_pass
40364 (expression, symbol_set, false, true, true, extrnl_symbol_table);
40365
40366 if (!variable_pass && !vector_pass)
40367 return false;
40368
40369 std::set<std::string>::iterator itr = symbol_set.begin();
40370
40371 while (symbol_set.end() != itr)
40372 {
40373 symbol_list.push_back(*itr);
40374 ++itr;
40375 }
40376
40377 return true;
40378 }

◆ 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 40321 of file exprtk.hpp.

40323 {
40324 typedef double T;
40325 typedef details::collector_helper<T> collect_t;
40326
40327 collect_t::symbol_table_t null_symbol_table;
40328
40329 std::set<std::string> symbol_set;
40330
40331 const bool variable_pass = collect_t::collection_pass
40332 (expression, symbol_set, false, true, false, null_symbol_table);
40333 const bool vector_pass = collect_t::collection_pass
40334 (expression, symbol_set, false, true, true, null_symbol_table);
40335
40336 if (!variable_pass && !vector_pass)
40337 return false;
40338
40339 std::set<std::string>::iterator itr = symbol_set.begin();
40340
40341 while (symbol_set.end() != itr)
40342 {
40343 symbol_list.push_back(*itr);
40344 ++itr;
40345 }
40346
40347 return true;
40348 }

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 40292 of file exprtk.hpp.

40295 {
40296 typedef details::collector_helper<T> collect_t;
40297
40298 std::set<std::string> symbol_set;
40299
40300 const bool variable_pass = collect_t::collection_pass
40301 (expression, symbol_set, true, false, false, extrnl_symbol_table);
40302 const bool vector_pass = collect_t::collection_pass
40303 (expression, symbol_set, true, false, true, extrnl_symbol_table);
40304
40305 if (!variable_pass && !vector_pass)
40306 return false;
40307
40308 std::set<std::string>::iterator itr = symbol_set.begin();
40309
40310 while (symbol_set.end() != itr)
40311 {
40312 symbol_list.push_back(*itr);
40313 ++itr;
40314 }
40315
40316 return true;
40317 }

◆ 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 40260 of file exprtk.hpp.

40262 {
40263 typedef double T;
40264 typedef details::collector_helper<T> collect_t;
40265
40266 collect_t::symbol_table_t null_symbol_table;
40267
40268 std::set<std::string> symbol_set;
40269
40270 const bool variable_pass = collect_t::collection_pass
40271 (expression, symbol_set, true, false, false, null_symbol_table);
40272 const bool vector_pass = collect_t::collection_pass
40273 (expression, symbol_set, true, false, true, null_symbol_table);
40274
40275 if (!variable_pass && !vector_pass)
40276 return false;
40277
40278 std::set<std::string>::iterator itr = symbol_set.begin();
40279
40280 while (symbol_set.end() != itr)
40281 {
40282 symbol_list.push_back(*itr);
40283 ++itr;
40284 }
40285
40286 return true;
40287 }

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 40666 of file exprtk.hpp.

40669 {
40670 // Only 'x', 'y' or 'z'
40671 static const std::string x_var("x");
40672 static const std::string y_var("y");
40673 static const std::string z_var("z");
40674
40677 symbol_table.add_constant(x_var,x);
40678 symbol_table.add_constant(y_var,y);
40679 symbol_table.add_constant(z_var,z);
40680
40683
40685
40686 if (parser.compile(expression_string,expression))
40687 {
40688 result = expression.value();
40689
40690 return true;
40691 }
40692 else
40693 return false;
40694 }
void register_symbol_table(symbol_table< T > &st)
Definition exprtk.hpp:20992
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:23584
bool add_constant(const std::string &constant_name, const T &value)
Definition exprtk.hpp:20098

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 40637 of file exprtk.hpp.

40640 {
40641 // Only 'x' and 'y'
40642 static const std::string x_var("x");
40643 static const std::string y_var("y");
40644
40647 symbol_table.add_constant(x_var,x);
40648 symbol_table.add_constant(y_var,y);
40649
40652
40654
40655 if (parser.compile(expression_string,expression))
40656 {
40657 result = expression.value();
40658
40659 return true;
40660 }
40661 else
40662 return false;
40663 }

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 40610 of file exprtk.hpp.

40613 {
40614 // Only 'x'
40615 static const std::string x_var("x");
40616
40619 symbol_table.add_constant(x_var,x);
40620
40623
40625
40626 if (parser.compile(expression_string,expression))
40627 {
40628 result = expression.value();
40629
40630 return true;
40631 }
40632 else
40633 return false;
40634 }

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 40588 of file exprtk.hpp.

40589 {
40590 // No variables
40593
40596
40598
40599 if (parser.compile(expression_string,expression))
40600 {
40601 result = expression.value();
40602
40603 return true;
40604 }
40605 else
40606 return false;
40607 }

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 40497 of file exprtk.hpp.

40500 {
40501 const symbol_table<T>& sym_table = e.get_symbol_table();
40502
40503 if (!sym_table.valid())
40504 {
40505 return std::numeric_limits<T>::quiet_NaN();
40506 }
40507
40508 details::variable_node<T>* var = sym_table.get_variable(variable_name);
40509
40510 if (var)
40511 {
40512 T& x = var->ref();
40513 const T x_original = x;
40514 const T result = derivative(e, x, h);
40515 x = x_original;
40516
40517 return result;
40518 }
40519
40520 return std::numeric_limits<T>::quiet_NaN();
40521 }
variable_ptr get_variable(const std::string &variable_name) const
Definition exprtk.hpp:19895
bool valid() const
Definition exprtk.hpp:20576

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 40433 of file exprtk.hpp.

40436 {
40437 const T x_init = x;
40438 const T _2h = T(2) * h;
40439
40440 x = x_init + _2h;
40441 const T y0 = e.value();
40442 x = x_init + h;
40443 const T y1 = e.value();
40444 x = x_init - h;
40445 const T y2 = e.value();
40446 x = x_init - _2h;
40447 const T y3 = e.value();
40448 x = x_init;
40449
40450 return (-y0 + T(8) * (y1 - y2) + y3) / (T(12) * h);
40451 }

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 18838 of file exprtk.hpp.

18839 {
18840 func.has_side_effects() = false;
18841 }

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 18826 of file exprtk.hpp.

18827 {
18828 func.allow_zero_parameters() = false;
18829 }

◆ enable_has_side_effects()

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

Definition at line 18832 of file exprtk.hpp.

18833 {
18834 func.has_side_effects() = true;
18835 }

◆ enable_zero_parameters()

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

Definition at line 18815 of file exprtk.hpp.

18816 {
18817 func.allow_zero_parameters() = true;
18818
18819 if (0 != func.min_num_args())
18820 {
18821 func.min_num_args() = 0;
18822 }
18823 }

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 40405 of file exprtk.hpp.

40409 {
40410 const symbol_table<T>& sym_table = e.get_symbol_table();
40411
40412 if (!sym_table.valid())
40413 {
40414 return std::numeric_limits<T>::quiet_NaN();
40415 }
40416
40417 details::variable_node<T>* var = sym_table.get_variable(variable_name);
40418
40419 if (var)
40420 {
40421 T& x = var->ref();
40422 const T x_original = x;
40423 const T result = integrate(e, x, r0, r1, number_of_intervals);
40424 x = x_original;
40425
40426 return result;
40427 }
40428
40429 return std::numeric_limits<T>::quiet_NaN();
40430 }

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 40381 of file exprtk.hpp.

40385 {
40386 if (r0 > r1)
40387 return T(0);
40388
40389 const T h = (r1 - r0) / (T(2) * number_of_intervals);
40390 T total_area = T(0);
40391
40392 for (std::size_t i = 0; i < number_of_intervals; ++i)
40393 {
40394 x = r0 + T(2) * i * h;
40395 const T y0 = e.value(); x += h;
40396 const T y1 = e.value(); x += h;
40397 const T y2 = e.value(); x += h;
40398 total_area += h * (y0 + T(4) * y1 + y2) / T(3);
40399 }
40400
40401 return total_area;
40402 }

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 21185 of file exprtk.hpp.

21186 {
21187 return expr.control_block_ && !expression_helper<T>::is_null(expr);
21188 }
control_block * control_block_
Definition exprtk.hpp:21138

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 4593 of file exprtk.hpp.

4595 {
4596 return vector_view<T>(v.data() + offset, size);
4597 }

◆ 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 4586 of file exprtk.hpp.

4588 {
4589 return vector_view<T>(data + offset, size);
4590 }

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

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 40524 of file exprtk.hpp.

40527 {
40528 const symbol_table<T>& sym_table = e.get_symbol_table();
40529
40530 if (!sym_table.valid())
40531 {
40532 return std::numeric_limits<T>::quiet_NaN();
40533 }
40534
40535 details::variable_node<T>* var = sym_table.get_variable(variable_name);
40536
40537 if (var)
40538 {
40539 T& x = var->ref();
40540 const T x_original = x;
40541 const T result = second_derivative(e, x, h);
40542 x = x_original;
40543
40544 return result;
40545 }
40546
40547 return std::numeric_limits<T>::quiet_NaN();
40548 }

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 40454 of file exprtk.hpp.

40457 {
40458 const T x_init = x;
40459 const T _2h = T(2) * h;
40460
40461 const T y = e.value();
40462 x = x_init + _2h;
40463 const T y0 = e.value();
40464 x = x_init + h;
40465 const T y1 = e.value();
40466 x = x_init - h;
40467 const T y2 = e.value();
40468 x = x_init - _2h;
40469 const T y3 = e.value();
40470 x = x_init;
40471
40472 return (-y0 + T(16) * (y1 + y2) - T(30) * y - y3) / (T(12) * h * h);
40473 }

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 18853 of file exprtk.hpp.

18854 {
18855 func.max_num_args() = num_args;
18856 }

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 18844 of file exprtk.hpp.

18845 {
18846 func.min_num_args() = num_args;
18847
18848 if ((0 != func.min_num_args()) && func.allow_zero_parameters())
18849 func.allow_zero_parameters() = false;
18850 }

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 40551 of file exprtk.hpp.

40554 {
40555 const symbol_table<T>& sym_table = e.get_symbol_table();
40556
40557 if (!sym_table.valid())
40558 {
40559 return std::numeric_limits<T>::quiet_NaN();
40560 }
40561
40562 details::variable_node<T>* var = sym_table.get_variable(variable_name);
40563
40564 if (var)
40565 {
40566 T& x = var->ref();
40567 const T x_original = x;
40568 const T result = third_derivative(e, x, h);
40569 x = x_original;
40570
40571 return result;
40572 }
40573
40574 return std::numeric_limits<T>::quiet_NaN();
40575 }

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 40476 of file exprtk.hpp.

40479 {
40480 const T x_init = x;
40481 const T _2h = T(2) * h;
40482
40483 x = x_init + _2h;
40484 const T y0 = e.value();
40485 x = x_init + h;
40486 const T y1 = e.value();
40487 x = x_init - h;
40488 const T y2 = e.value();
40489 x = x_init - _2h;
40490 const T y3 = e.value();
40491 x = x_init;
40492
40493 return (y0 + T(2) * (y2 - y1) - y3) / (T(2) * h * h * h);
40494 }

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 4795 of file exprtk.hpp.

4796 {
4797 return std::string(view.begin(),view.size());
4798 }

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

Here is the caller graph for this function: