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

◆ compilation_check_ptr

Definition at line 2268 of file exprtk.hpp.

◆ loop_runtime_check_ptr

Definition at line 2210 of file exprtk.hpp.

◆ vector_access_runtime_check_ptr

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

42331 {
42332 typedef details::collector_helper<T> collect_t;
42333
42334 std::set<std::string> symbol_set;
42335
42336 const bool variable_pass = collect_t::collection_pass
42337 (expression, symbol_set, false, true, false, extrnl_symbol_table);
42338 const bool vector_pass = collect_t::collection_pass
42339 (expression, symbol_set, false, true, true, extrnl_symbol_table);
42340
42341 if (!variable_pass && !vector_pass)
42342 return false;
42343
42344 std::set<std::string>::iterator itr = symbol_set.begin();
42345
42346 while (symbol_set.end() != itr)
42347 {
42348 symbol_list.push_back(*itr);
42349 ++itr;
42350 }
42351
42352 return true;
42353 }

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

42298 {
42299 typedef double T;
42300 typedef details::collector_helper<T> collect_t;
42301
42302 collect_t::symbol_table_t null_symbol_table;
42303
42304 std::set<std::string> symbol_set;
42305
42306 const bool variable_pass = collect_t::collection_pass
42307 (expression, symbol_set, false, true, false, null_symbol_table);
42308 const bool vector_pass = collect_t::collection_pass
42309 (expression, symbol_set, false, true, true, null_symbol_table);
42310
42311 if (!variable_pass && !vector_pass)
42312 return false;
42313
42314 std::set<std::string>::iterator itr = symbol_set.begin();
42315
42316 while (symbol_set.end() != itr)
42317 {
42318 symbol_list.push_back(*itr);
42319 ++itr;
42320 }
42321
42322 return true;
42323 }

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

42270 {
42271 typedef details::collector_helper<T> collect_t;
42272
42273 std::set<std::string> symbol_set;
42274
42275 const bool variable_pass = collect_t::collection_pass
42276 (expression, symbol_set, true, false, false, extrnl_symbol_table);
42277 const bool vector_pass = collect_t::collection_pass
42278 (expression, symbol_set, true, false, true, extrnl_symbol_table);
42279
42280 if (!variable_pass && !vector_pass)
42281 return false;
42282
42283 std::set<std::string>::iterator itr = symbol_set.begin();
42284
42285 while (symbol_set.end() != itr)
42286 {
42287 symbol_list.push_back(*itr);
42288 ++itr;
42289 }
42290
42291 return true;
42292 }

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

42237 {
42238 typedef double T;
42239 typedef details::collector_helper<T> collect_t;
42240
42241 collect_t::symbol_table_t null_symbol_table;
42242
42243 std::set<std::string> symbol_set;
42244
42245 const bool variable_pass = collect_t::collection_pass
42246 (expression, symbol_set, true, false, false, null_symbol_table);
42247 const bool vector_pass = collect_t::collection_pass
42248 (expression, symbol_set, true, false, true, null_symbol_table);
42249
42250 if (!variable_pass && !vector_pass)
42251 return false;
42252
42253 std::set<std::string>::iterator itr = symbol_set.begin();
42254
42255 while (symbol_set.end() != itr)
42256 {
42257 symbol_list.push_back(*itr);
42258 ++itr;
42259 }
42260
42261 return true;
42262 }

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

42644 {
42645 // Only 'x', 'y' or 'z'
42646 static const std::string x_var("x");
42647 static const std::string y_var("y");
42648 static const std::string z_var("z");
42649
42652 symbol_table.add_constant(x_var,x);
42653 symbol_table.add_constant(y_var,y);
42654 symbol_table.add_constant(z_var,z);
42655
42658
42660
42661 if (parser.compile(expression_string,expression))
42662 {
42663 result = expression.value();
42664
42665 return true;
42666 }
42667 else
42668 return false;
42669 }
bool register_symbol_table(symbol_table< T > &st)
Definition exprtk.hpp:21991
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:24742
bool add_constant(const std::string &constant_name, const T &value)
Definition exprtk.hpp:21047

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

42615 {
42616 // Only 'x' and 'y'
42617 static const std::string x_var("x");
42618 static const std::string y_var("y");
42619
42622 symbol_table.add_constant(x_var,x);
42623 symbol_table.add_constant(y_var,y);
42624
42627
42629
42630 if (parser.compile(expression_string,expression))
42631 {
42632 result = expression.value();
42633
42634 return true;
42635 }
42636 else
42637 return false;
42638 }

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

42588 {
42589 // Only 'x'
42590 static const std::string x_var("x");
42591
42594 symbol_table.add_constant(x_var,x);
42595
42598
42600
42601 if (parser.compile(expression_string,expression))
42602 {
42603 result = expression.value();
42604
42605 return true;
42606 }
42607 else
42608 return false;
42609 }

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

42564 {
42565 // No variables
42568
42571
42573
42574 if (parser.compile(expression_string,expression))
42575 {
42576 result = expression.value();
42577
42578 return true;
42579 }
42580 else
42581 return false;
42582 }

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

42475 {
42476 const symbol_table<T>& sym_table = e.get_symbol_table();
42477
42478 if (!sym_table.valid())
42479 {
42480 return std::numeric_limits<T>::quiet_NaN();
42481 }
42482
42483 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42484
42485 if (var)
42486 {
42487 T& x = var->ref();
42488 const T x_original = x;
42489 const T result = derivative(e, x, h);
42490 x = x_original;
42491
42492 return result;
42493 }
42494
42495 return std::numeric_limits<T>::quiet_NaN();
42496 }
variable_ptr get_variable(const std::string &variable_name) const
Definition exprtk.hpp:20844
bool valid() const
Definition exprtk.hpp:21560

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

42411 {
42412 const T x_init = x;
42413 const T _2h = T(2) * h;
42414
42415 x = x_init + _2h;
42416 const T y0 = e.value();
42417 x = x_init + h;
42418 const T y1 = e.value();
42419 x = x_init - h;
42420 const T y2 = e.value();
42421 x = x_init - _2h;
42422 const T y3 = e.value();
42423 x = x_init;
42424
42425 return (-y0 + T(8) * (y1 - y2) + y3) / (T(12) * h);
42426 }

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

19760 {
19761 func.has_side_effects() = false;
19762 }

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

19748 {
19749 func.allow_zero_parameters() = false;
19750 }

◆ enable_has_side_effects()

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

Definition at line 19753 of file exprtk.hpp.

19754 {
19755 func.has_side_effects() = true;
19756 }

◆ enable_zero_parameters()

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

Definition at line 19736 of file exprtk.hpp.

19737 {
19738 func.allow_zero_parameters() = true;
19739
19740 if (0 != func.min_num_args())
19741 {
19742 func.min_num_args() = 0;
19743 }
19744 }

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

42384 {
42385 const symbol_table<T>& sym_table = e.get_symbol_table();
42386
42387 if (!sym_table.valid())
42388 {
42389 return std::numeric_limits<T>::quiet_NaN();
42390 }
42391
42392 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42393
42394 if (var)
42395 {
42396 T& x = var->ref();
42397 const T x_original = x;
42398 const T result = integrate(e, x, r0, r1, number_of_intervals);
42399 x = x_original;
42400
42401 return result;
42402 }
42403
42404 return std::numeric_limits<T>::quiet_NaN();
42405 }

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

42360 {
42361 if (r0 > r1)
42362 return T(0);
42363
42364 const T h = (r1 - r0) / (T(2) * number_of_intervals);
42365 T total_area = T(0);
42366
42367 for (std::size_t i = 0; i < number_of_intervals; ++i)
42368 {
42369 x = r0 + T(2) * i * h;
42370 const T y0 = e.value(); x += h;
42371 const T y1 = e.value(); x += h;
42372 const T y2 = e.value(); x += h;
42373 total_area += h * (y0 + T(4) * y1 + y2) / T(3);
42374 }
42375
42376 return total_area;
42377 }

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

22300 {
22301 return expr.control_block_ && !expression_helper<T>::is_null(expr);
22302 }
control_block * control_block_
Definition exprtk.hpp:22143

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

4771 {
4772 return vector_view<T>(v.data() + offset, size);
4773 }

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

4764 {
4765 return vector_view<T>(data + offset, size);
4766 }

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

42502 {
42503 const symbol_table<T>& sym_table = e.get_symbol_table();
42504
42505 if (!sym_table.valid())
42506 {
42507 return std::numeric_limits<T>::quiet_NaN();
42508 }
42509
42510 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42511
42512 if (var)
42513 {
42514 T& x = var->ref();
42515 const T x_original = x;
42516 const T result = second_derivative(e, x, h);
42517 x = x_original;
42518
42519 return result;
42520 }
42521
42522 return std::numeric_limits<T>::quiet_NaN();
42523 }

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

42432 {
42433 const T x_init = x;
42434 const T _2h = T(2) * h;
42435
42436 const T y = e.value();
42437 x = x_init + _2h;
42438 const T y0 = e.value();
42439 x = x_init + h;
42440 const T y1 = e.value();
42441 x = x_init - h;
42442 const T y2 = e.value();
42443 x = x_init - _2h;
42444 const T y3 = e.value();
42445 x = x_init;
42446
42447 return (-y0 + T(16) * (y1 + y2) - T(30) * y - y3) / (T(12) * h * h);
42448 }

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

19775 {
19776 func.max_num_args() = num_args;
19777 }

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

19766 {
19767 func.min_num_args() = num_args;
19768
19769 if ((0 != func.min_num_args()) && func.allow_zero_parameters())
19770 func.allow_zero_parameters() = false;
19771 }

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

42529 {
42530 const symbol_table<T>& sym_table = e.get_symbol_table();
42531
42532 if (!sym_table.valid())
42533 {
42534 return std::numeric_limits<T>::quiet_NaN();
42535 }
42536
42537 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42538
42539 if (var)
42540 {
42541 T& x = var->ref();
42542 const T x_original = x;
42543 const T result = third_derivative(e, x, h);
42544 x = x_original;
42545
42546 return result;
42547 }
42548
42549 return std::numeric_limits<T>::quiet_NaN();
42550 }

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

42454 {
42455 const T x_init = x;
42456 const T _2h = T(2) * h;
42457
42458 x = x_init + _2h;
42459 const T y0 = e.value();
42460 x = x_init + h;
42461 const T y1 = e.value();
42462 x = x_init - h;
42463 const T y2 = e.value();
42464 x = x_init - _2h;
42465 const T y3 = e.value();
42466 x = x_init;
42467
42468 return (y0 + T(2) * (y2 - y1) - y3) / (T(2) * h * h * h);
42469 }

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

4997 {
4998 return std::string(view.begin(),view.size());
4999 }

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: