C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
exprtk Namespace Reference

Namespaces

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

Classes

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

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)
bool is_true (const double v)
bool is_true (const double v)
bool is_true (const double v)

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

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

42461 {
42462 typedef details::collector_helper<T> collect_t;
42463
42464 std::set<std::string> symbol_set;
42465
42466 const bool variable_pass = collect_t::collection_pass
42467 (expression, symbol_set, false, true, false, extrnl_symbol_table);
42468 const bool vector_pass = collect_t::collection_pass
42469 (expression, symbol_set, false, true, true, extrnl_symbol_table);
42470
42471 if (!variable_pass && !vector_pass)
42472 return false;
42473
42474 std::set<std::string>::iterator itr = symbol_set.begin();
42475
42476 while (symbol_set.end() != itr)
42477 {
42478 symbol_list.push_back(*itr);
42479 ++itr;
42480 }
42481
42482 return true;
42483 }

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

42428 {
42429 typedef double T;
42430 typedef details::collector_helper<T> collect_t;
42431
42432 collect_t::symbol_table_t null_symbol_table;
42433
42434 std::set<std::string> symbol_set;
42435
42436 const bool variable_pass = collect_t::collection_pass
42437 (expression, symbol_set, false, true, false, null_symbol_table);
42438 const bool vector_pass = collect_t::collection_pass
42439 (expression, symbol_set, false, true, true, null_symbol_table);
42440
42441 if (!variable_pass && !vector_pass)
42442 return false;
42443
42444 std::set<std::string>::iterator itr = symbol_set.begin();
42445
42446 while (symbol_set.end() != itr)
42447 {
42448 symbol_list.push_back(*itr);
42449 ++itr;
42450 }
42451
42452 return true;
42453 }

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

42400 {
42401 typedef details::collector_helper<T> collect_t;
42402
42403 std::set<std::string> symbol_set;
42404
42405 const bool variable_pass = collect_t::collection_pass
42406 (expression, symbol_set, true, false, false, extrnl_symbol_table);
42407 const bool vector_pass = collect_t::collection_pass
42408 (expression, symbol_set, true, false, true, extrnl_symbol_table);
42409
42410 if (!variable_pass && !vector_pass)
42411 return false;
42412
42413 std::set<std::string>::iterator itr = symbol_set.begin();
42414
42415 while (symbol_set.end() != itr)
42416 {
42417 symbol_list.push_back(*itr);
42418 ++itr;
42419 }
42420
42421 return true;
42422 }

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

42367 {
42368 typedef double T;
42369 typedef details::collector_helper<T> collect_t;
42370
42371 collect_t::symbol_table_t null_symbol_table;
42372
42373 std::set<std::string> symbol_set;
42374
42375 const bool variable_pass = collect_t::collection_pass
42376 (expression, symbol_set, true, false, false, null_symbol_table);
42377 const bool vector_pass = collect_t::collection_pass
42378 (expression, symbol_set, true, false, true, null_symbol_table);
42379
42380 if (!variable_pass && !vector_pass)
42381 return false;
42382
42383 std::set<std::string>::iterator itr = symbol_set.begin();
42384
42385 while (symbol_set.end() != itr)
42386 {
42387 symbol_list.push_back(*itr);
42388 ++itr;
42389 }
42390
42391 return true;
42392 }

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

42774 {
42775 // Only 'x', 'y' or 'z'
42776 static const std::string x_var("x");
42777 static const std::string y_var("y");
42778 static const std::string z_var("z");
42779
42782 symbol_table.add_constant(x_var,x);
42783 symbol_table.add_constant(y_var,y);
42784 symbol_table.add_constant(z_var,z);
42785
42788
42790
42791 if (parser.compile(expression_string,expression))
42792 {
42793 result = expression.value();
42794
42795 return true;
42796 }
42797 else
42798 return false;
42799 }
bool register_symbol_table(symbol_table< T > &st)
Definition exprtk.hpp:22071
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:24826
bool add_constant(const std::string &constant_name, const T &value)
Definition exprtk.hpp:21127

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

42745 {
42746 // Only 'x' and 'y'
42747 static const std::string x_var("x");
42748 static const std::string y_var("y");
42749
42752 symbol_table.add_constant(x_var,x);
42753 symbol_table.add_constant(y_var,y);
42754
42757
42759
42760 if (parser.compile(expression_string,expression))
42761 {
42762 result = expression.value();
42763
42764 return true;
42765 }
42766 else
42767 return false;
42768 }

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

42718 {
42719 // Only 'x'
42720 static const std::string x_var("x");
42721
42724 symbol_table.add_constant(x_var,x);
42725
42728
42730
42731 if (parser.compile(expression_string,expression))
42732 {
42733 result = expression.value();
42734
42735 return true;
42736 }
42737 else
42738 return false;
42739 }

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

42694 {
42695 // No variables
42698
42701
42703
42704 if (parser.compile(expression_string,expression))
42705 {
42706 result = expression.value();
42707
42708 return true;
42709 }
42710 else
42711 return false;
42712 }

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

42605 {
42606 const symbol_table<T>& sym_table = e.get_symbol_table();
42607
42608 if (!sym_table.valid())
42609 {
42610 return std::numeric_limits<T>::quiet_NaN();
42611 }
42612
42613 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42614
42615 if (var)
42616 {
42617 T& x = var->ref();
42618 const T x_original = x;
42619 const T result = derivative(e, x, h);
42620 x = x_original;
42621
42622 return result;
42623 }
42624
42625 return std::numeric_limits<T>::quiet_NaN();
42626 }
variable_ptr get_variable(const std::string &variable_name) const
Definition exprtk.hpp:20924
bool valid() const
Definition exprtk.hpp:21640
T derivative(const expression< T > &e, T &x, const T &h=T(0.00000001))
Definition exprtk.hpp:42538

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

42541 {
42542 const T x_init = x;
42543 const T _2h = T(2) * h;
42544
42545 x = x_init + _2h;
42546 const T y0 = e.value();
42547 x = x_init + h;
42548 const T y1 = e.value();
42549 x = x_init - h;
42550 const T y2 = e.value();
42551 x = x_init - _2h;
42552 const T y3 = e.value();
42553 x = x_init;
42554
42555 return (-y0 + T(8) * (y1 - y2) + y3) / (T(12) * h);
42556 }

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

19840 {
19841 func.has_side_effects() = false;
19842 }

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

19828 {
19829 func.allow_zero_parameters() = false;
19830 }

◆ enable_has_side_effects()

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

Definition at line 19833 of file exprtk.hpp.

19834 {
19835 func.has_side_effects() = true;
19836 }

◆ enable_zero_parameters()

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

Definition at line 19816 of file exprtk.hpp.

19817 {
19818 func.allow_zero_parameters() = true;
19819
19820 if (0 != func.min_num_args())
19821 {
19822 func.min_num_args() = 0;
19823 }
19824 }

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

42514 {
42515 const symbol_table<T>& sym_table = e.get_symbol_table();
42516
42517 if (!sym_table.valid())
42518 {
42519 return std::numeric_limits<T>::quiet_NaN();
42520 }
42521
42522 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42523
42524 if (var)
42525 {
42526 T& x = var->ref();
42527 const T x_original = x;
42528 const T result = integrate(e, x, r0, r1, number_of_intervals);
42529 x = x_original;
42530
42531 return result;
42532 }
42533
42534 return std::numeric_limits<T>::quiet_NaN();
42535 }
T integrate(const expression< T > &e, T &x, const T &r0, const T &r1, const std::size_t number_of_intervals=1000000)
Definition exprtk.hpp:42486

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

42490 {
42491 if (r0 > r1)
42492 return T(0);
42493
42494 const T h = (r1 - r0) / (T(2) * number_of_intervals);
42495 T total_area = T(0);
42496
42497 for (std::size_t i = 0; i < number_of_intervals; ++i)
42498 {
42499 x = r0 + T(2) * i * h;
42500 const T y0 = e.value(); x += h;
42501 const T y1 = e.value(); x += h;
42502 const T y2 = e.value(); x += h;
42503 total_area += h * (y0 + T(4) * y1 + y2) / T(3);
42504 }
42505
42506 return total_area;
42507 }

Referenced by integrate(), and run_test06().

Here is the caller graph for this function:

◆ is_true() [1/3]

bool exprtk::details::is_true ( const double v)
inline

Definition at line 5763 of file exprtk.hpp.

5764 {
5765 return std::not_equal_to<double>()(0.0,v);
5766 }

◆ is_true() [2/3]

bool exprtk::details::is_true ( const double v)
inline

Definition at line 5763 of file exprtk.hpp.

5764 {
5765 return std::not_equal_to<double>()(0.0,v);
5766 }

◆ is_true() [3/3]

bool exprtk::details::is_true ( const double v)
inline

Definition at line 5763 of file exprtk.hpp.

5764 {
5765 return std::not_equal_to<double>()(0.0,v);
5766 }

◆ is_valid()

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

Definition at line 22383 of file exprtk.hpp.

22384 {
22385 return expr.control_block_ && !expression_helper<T>::is_null(expr);
22386 }
static bool is_null(const expression< T > &expr)
Definition exprtk.hpp:22292
control_block * control_block_
Definition exprtk.hpp:22227

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

4792 {
4793 return vector_view<T>(v.data() + offset, size);
4794 }

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

4785 {
4786 return vector_view<T>(data + offset, size);
4787 }

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

42632 {
42633 const symbol_table<T>& sym_table = e.get_symbol_table();
42634
42635 if (!sym_table.valid())
42636 {
42637 return std::numeric_limits<T>::quiet_NaN();
42638 }
42639
42640 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42641
42642 if (var)
42643 {
42644 T& x = var->ref();
42645 const T x_original = x;
42646 const T result = second_derivative(e, x, h);
42647 x = x_original;
42648
42649 return result;
42650 }
42651
42652 return std::numeric_limits<T>::quiet_NaN();
42653 }
T second_derivative(const expression< T > &e, T &x, const T &h=T(0.00001))
Definition exprtk.hpp:42559

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

42562 {
42563 const T x_init = x;
42564 const T _2h = T(2) * h;
42565
42566 const T y = e.value();
42567 x = x_init + _2h;
42568 const T y0 = e.value();
42569 x = x_init + h;
42570 const T y1 = e.value();
42571 x = x_init - h;
42572 const T y2 = e.value();
42573 x = x_init - _2h;
42574 const T y3 = e.value();
42575 x = x_init;
42576
42577 return (-y0 + T(16) * (y1 + y2) - T(30) * y - y3) / (T(12) * h * h);
42578 }

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

19855 {
19856 func.max_num_args() = num_args;
19857 }

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

19846 {
19847 func.min_num_args() = num_args;
19848
19849 if ((0 != func.min_num_args()) && func.allow_zero_parameters())
19850 func.allow_zero_parameters() = false;
19851 }

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

42659 {
42660 const symbol_table<T>& sym_table = e.get_symbol_table();
42661
42662 if (!sym_table.valid())
42663 {
42664 return std::numeric_limits<T>::quiet_NaN();
42665 }
42666
42667 details::variable_node<T>* var = sym_table.get_variable(variable_name);
42668
42669 if (var)
42670 {
42671 T& x = var->ref();
42672 const T x_original = x;
42673 const T result = third_derivative(e, x, h);
42674 x = x_original;
42675
42676 return result;
42677 }
42678
42679 return std::numeric_limits<T>::quiet_NaN();
42680 }
T third_derivative(const expression< T > &e, T &x, const T &h=T(0.0001))
Definition exprtk.hpp:42581

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

42584 {
42585 const T x_init = x;
42586 const T _2h = T(2) * h;
42587
42588 x = x_init + _2h;
42589 const T y0 = e.value();
42590 x = x_init + h;
42591 const T y1 = e.value();
42592 x = x_init - h;
42593 const T y2 = e.value();
42594 x = x_init - _2h;
42595 const T y3 = e.value();
42596 x = x_init;
42597
42598 return (y0 + T(2) * (y2 - y1) - y3) / (T(2) * h * h * h);
42599 }

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

5018 {
5019 return std::string(view.begin(),view.size());
5020 }

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

Here is the caller graph for this function: