stator
A math, geometry, and utility library
Classes | Namespaces | Typedefs | Functions | Variables
simplify.hpp File Reference

Go to the source code of this file.

Classes

struct  sym::expand_Constants
 
struct  sym::expand_Constants_to< T >
 
struct  sym::expand_to_Polynomial
 
struct  sym::PowerOpEnableExpansion< T >
 
struct  sym::PowerOpEnableExpansion< Var< VarArgs... > >
 
struct  sym::SimplifyConfig< Args >
 

Namespaces

 sym
 The stator symbolic math library.
 
 sym::detail
 Namespace containing the details of the implmentation for general stator components.
 

Typedefs

using sym::DefaultSimplifyConfig = SimplifyConfig<>
 
typedef SimplifyConfig< expand_to_Polynomial, expand_Constants > sym::ExpandConfig
 
typedef SimplifyConfig< expand_Constants > sym::NConfig
 

Functions

f _l _r sym::C< 1 > ()))
 
template<class T >
auto sym::expand (const T &a) -> STATOR_AUTORETURN(simplify< ExpandConfig >(a))
 A variant of simplify that expands into Polynomial types aggressively. More...
 
constexpr size_t sym::detail::max_order (size_t N, size_t M)
 
template<class T >
auto sym::N (const T &a) -> STATOR_AUTORETURN(simplify< NConfig >(a))
 A variant of simplify that converts compile time symbols into numbers. More...
 
template<class Config = DefaultSimplifyConfig>
void sym::simplify ()
 The simplify base implementation. More...
 
template<class Config = DefaultSimplifyConfig, class Arg , std::intmax_t Power, typename = typename std::enable_if<PowerOpEnableExpansion<Arg>::value>::type>
auto sym::simplify (const PowerOp< Arg, C< Power, 1 > > &f) -> STATOR_AUTORETURN(simplify_powerop_impl< Config >(f, detail::select_overload
 Expansion operator for PowerOp types. More...
 
template<class Config = DefaultSimplifyConfig, class L , class Op , class R >
auto sym::simplify (BinaryOp< L, Op, R > t) -> STATOR_AUTORETURN(simplify_BinaryOp< Config >(t, detail::select_overload
 
template<class Config = DefaultSimplifyConfig, class PolyVar , class ... VarArgs, size_t Order, class Real , typename = typename std::enable_if<(Config::expand_to_Polynomial && variable_in<Var<VarArgs...>, PolyVar>::value)>::type>
Polynomial< Order+1, Real, typename variable_combine< PolyVar, Var< VarArgs... > >::type > sym::simplify (const MultiplyOp< Polynomial< Order, Real, PolyVar >, Var< VarArgs... > > &f)
 Simplification of a Polynomial RHS multiplied by a Var. More...
 
template<class Config = DefaultSimplifyConfig, class ... VarArgs, typename = typename std::enable_if<Config::expand_to_Polynomial>::type>
auto sym::simplify (Var< VarArgs... >) -> STATOR_AUTORETURN((Polynomial< 1, int, Var< VarArgs... > >
 Conversion of a Var to a polynomial if polynomial expansion is enabled. More...
 
template<class Config = DefaultSimplifyConfig, class ... VarArgs, std::intmax_t Power, typename = typename std::enable_if<Config::expand_to_Polynomial>::type>
Polynomial< Power, int, Var< VarArgs... > > sym::simplify (const PowerOp< Var< VarArgs... >, C< Power, 1 > > &)
 Conversion of a PowerOp to a Polynomial when Polynomial expansion is enabled. More...
 
template<class Config , std::intmax_t num, std::intmax_t den, typename = typename std::enable_if<Config::expand_Constants>::type>
auto sym::simplify (const C< num, den > &f) -> STATOR_AUTORETURN(typename Config::expand_Constants_to_t(num)/typename Config::expand_Constants_to_t(den))
 
template<class Config = DefaultSimplifyConfig, class Real1 , size_t N, class Real2 , size_t M, class PolyVar1 , class PolyVar2 , class Op , typename = typename std::enable_if<std::is_same<Op,detail::Add>::value || std::is_same<Op,detail::Subtract>::value>::type, typename = typename enable_if_var_in<PolyVar1, PolyVar2>::type>
auto sym::simplify (const BinaryOp< Polynomial< N, Real1, PolyVar1 >, Op, Polynomial< M, Real2, PolyVar2 >> &f) -> Polynomial< detail::max_order(M, N), decltype(store(Op::apply(f._l[0], f._r[0]))), typename variable_combine< PolyVar1, PolyVar2 >::type >
 Addition operator for two Polynomial types. More...
 
template<class Config = DefaultSimplifyConfig, class Real1 , class Real2 , size_t M, size_t N, class PolyVar1 , class PolyVar2 , class Op , typename = typename std::enable_if<std::is_same<Op,detail::Multiply>::value>::type>
auto sym::simplify (const BinaryOp< Polynomial< M, Real1, PolyVar1 >, Op, Polynomial< N, Real2, PolyVar2 >> &f) -> Polynomial< M+N, decltype(store(Op::apply(f._l[0], f._r[0]))), typename variable_combine< PolyVar1, PolyVar2 >::type >
 Multiplication between two Polynomial types. More...
 
template<class Config = DefaultSimplifyConfig, class Real1 , class Real2 , size_t M, class PolyVar1 , class PolyVar2 >
auto sym::simplify (const BinaryOp< Polynomial< M, Real1, PolyVar1 >, detail::Divide, Polynomial< 0, Real2, PolyVar2 >> &f) -> Polynomial< M, decltype(store(f._l[0]/f._r[0])), typename variable_combine< PolyVar1, PolyVar2 >::type >
 Division between two Polynomial types. More...
 
template<class Config = DefaultSimplifyConfig, class Arg , class Op >
auto sym::simplify (const UnaryOp< Arg, Op > &f) -> STATOR_AUTORETURN(simplify_UnaryOp< Config >(f, detail::select_overload
 
template<class Config = DefaultSimplifyConfig, class Arg , std::intmax_t Power>
auto sym::simplify (const PowerOp< UnaryOp< Arg, detail::Arbsign >, C< Power, 1 > > &f) -> typename std::enable_if<!(Power % 2), decltype(try_simplify< Config >(pow(f._l._arg, C< Power >())))>::type
 
template<class Config , class LHS , class RHS , class Op >
auto sym::simplify_BinaryOp (const BinaryOp< LHS, Op, RHS > &f, detail::choice< 0 >) -> typename std::enable_if<!std::is_same< decltype(Op::apply(f._l, f._r)), BinaryOp< LHS, Op, RHS > >::value, decltype(Op::apply(f._l, f._r))>::type
 
template<class Config , class LHS , class RHS , class Op , typename = typename std::enable_if<std::is_same<RHS, typename Op::right_zero>::value >::type>
Op::right_zero sym::simplify_BinaryOp (const BinaryOp< LHS, Op, RHS > &, detail::choice< 0 >)
 
template<class Config , class LHS , class RHS , class Op , typename = typename std::enable_if<std::is_same<LHS, typename Op::left_zero>::value && !std::is_same<RHS, typename Op::right_zero>::value>::type>
Op::left_zero sym::simplify_BinaryOp (const BinaryOp< LHS, Op, RHS > &, detail::choice< 0 >)
 
template<class Config , class LHS , class Op >
auto sym::simplify_BinaryOp (const BinaryOp< LHS, Op, typename Op::right_identity > &op, detail::choice< 0 >) -> STATOR_AUTORETURN(try_simplify< Config >(op._l))
 
template<class Config , class RHS , class Op , typename = typename std::enable_if<!std::is_same<RHS, typename Op::right_identity>::value>::type>
auto sym::simplify_BinaryOp (const BinaryOp< typename Op::left_identity, Op, RHS > &op, detail::choice< 0 >) -> STATOR_AUTORETURN(try_simplify< Config >(op._r))
 
template<class Config , class ... VarArgs1, class ... VarArgs2, typename = typename enable_if_var_in<Var<VarArgs1...>, Var<VarArgs2...> >::type>
Unity sym::simplify_BinaryOp (const BinaryOp< Var< VarArgs1... >, detail::Divide, Var< VarArgs2... >> &op, detail::choice< 0 >)
 
template<class Config , class RHS , typename = typename std::enable_if<!std::is_same<RHS, Null>::value>::type>
RHS sym::simplify_BinaryOp (const SubtractOp< Null, RHS > &r, detail::choice< 0 >)
 
template<class Config , class ... VarArgs1, class ... VarArgs2, typename = typename enable_if_var_in<Var<VarArgs1...>, Var<VarArgs2...> >::type>
auto sym::simplify_BinaryOp (const MultiplyOp< Var< VarArgs1... >, Var< VarArgs2... > > &, detail::choice< 0 >) -> STATOR_AUTORETURN(sym::pow(typename variable_combine< Var< VarArgs1... >, Var< VarArgs2... > >::type(), C< 2 >()))
 
template<class Config , class ... VarArgs1, class ... VarArgs2, class Order , typename = typename enable_if_var_in<Var<VarArgs1...>, Var<VarArgs2...> >::type>
auto sym::simplify_BinaryOp (const MultiplyOp< PowerOp< Var< VarArgs1... >, Order >, Var< VarArgs2... > > &f, detail::choice< 0 >) -> STATOR_AUTORETURN(sym::pow(typename variable_combine< Var< VarArgs1... >, Var< VarArgs2... > >::type
 
template<class Config , class ... VarArgs1, class ... VarArgs2, class Order , typename = typename enable_if_var_in<Var<VarArgs1...>, Var<VarArgs2...> >::type>
auto sym::simplify_BinaryOp (const MultiplyOp< Var< VarArgs1... >, PowerOp< Var< VarArgs2... >, Order > > &f, detail::choice< 0 >) -> STATOR_AUTORETURN(sym::pow(typename variable_combine< Var< VarArgs1... >, Var< VarArgs2... > >::type
 
template<class Config , class LHS , class RHS , class Op >
auto sym::simplify_BinaryOp (const BinaryOp< LHS, Op, RHS > &f, detail::choice< 2 >) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(simplify< Config >(f._l), simplify< Config >(f._r))))
 
template<class Config , class LHS , class RHS , class Op >
auto sym::simplify_BinaryOp (const BinaryOp< LHS, Op, RHS > &f, detail::choice< 3 >) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(simplify< Config >(f._l), f._r)))
 
template<class Config , class Arg1 , class Arg2 , class Arg3 , class Op , typename = typename std::enable_if<Op::associative>::type>
auto sym::simplify_BinaryOp (const BinaryOp< BinaryOp< Arg1, Op, Arg2 >, Op, Arg3 > &f, detail::choice< 6 >) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(f._l._l, simplify< Config >(BinaryOp< Arg2, Op, Arg3 >(f._l._r, f._r)))))
 
template<class Config , class Arg1 , class Arg2 , class Arg3 , class Op , typename = typename std::enable_if<Op::associative>::type>
auto sym::simplify_BinaryOp (const BinaryOp< Arg1, Op, BinaryOp< Arg2, Op, Arg3 > > &f, detail::choice< 6 >) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(simplify< Config >(BinaryOp< Arg1, Op, Arg2 >(f._l, f._r._l)), f._r._r)))
 
template<class Config , class Arg1 , class Arg2 , class Arg3 , class Op , typename = typename std::enable_if<Op::associative>::type>
auto sym::simplify_BinaryOp (const BinaryOp< BinaryOp< Arg1, Op, Arg2 >, Op, Arg3 > &f, detail::choice< 7 >) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(simplify< Config >(BinaryOp< Arg1, Op, Arg3 >(f._l._l, f._r)), f._l._r)))
 
template<class Config , class Arg1 , class Arg2 , class Arg3 , class Op , typename = typename std::enable_if<Op::associative>::type>
auto sym::simplify_BinaryOp (const BinaryOp< Arg1, Op, BinaryOp< Arg2, Op, Arg3 > > &f, detail::choice< 7 >) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(simplify< Config >(BinaryOp< Arg1, Op, Arg3 >(f._l, f._r._r)), f._r._l)))
 
template<class Config , class PolyVar , size_t Order, class Real , class Op , class Real2 , typename = typename std::enable_if<Config::expand_to_Polynomial && detail::IsConstant<Real2>::value>::type>
auto sym::simplify_BinaryOp (const BinaryOp< Polynomial< Order, Real, PolyVar >, Op, Real2 > &f, detail::last_choice) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(f._l, Polynomial< 0, decltype(toArithmetic(f._r)), PolyVar >
 Simplification of a Polynomial operating with a constant RHS. More...
 
template<class Config , class PolyVar , size_t Order, class Real , class Op , class Real2 , typename = typename std::enable_if<Config::expand_to_Polynomial && detail::IsConstant<Real2>::value>::type>
auto sym::simplify_BinaryOp (const BinaryOp< Real2, Op, Polynomial< Order, Real, PolyVar >> &f, detail::last_choice) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(Polynomial< 0, decltype(toArithmetic(f._l)), PolyVar >
 Simplification of a Polynomial operating with a constant LHS. More...
 
template<class Config = DefaultSimplifyConfig, class Arg1 , class Arg2 , class Op , typename = typename std::enable_if<std::is_same<Op,detail::Multiply>::value || std::is_same<Op,detail::Divide>::value>::type>
auto sym::simplify_BinaryOp (const BinaryOp< UnaryOp< Arg1, detail::Arbsign >, Op, UnaryOp< Arg2, detail::Arbsign > > &f, detail::choice< 4 >) -> STATOR_AUTORETURN(try_simplify< Config >(detail::Arbsign::apply(Op::apply(f._l._arg, f._r._arg))))
 
template<class Config , class LHS , class Arg , class Op , typename = typename std::enable_if<std::is_same<Op,detail::Multiply>::value || std::is_same<Op,detail::Divide>::value>::type>
auto sym::simplify_BinaryOp (const BinaryOp< LHS, Op, UnaryOp< Arg, detail::Arbsign > > &f, detail::choice< 5 >) -> STATOR_AUTORETURN(try_simplify< Config >(detail::Arbsign::apply(Op::apply(f._l, f._r._arg))))
 
template<class Config , class RHS , class Arg , class Op , typename = typename std::enable_if<std::is_same<Op,detail::Multiply>::value || std::is_same<Op,detail::Divide>::value>::type>
auto sym::simplify_BinaryOp (const BinaryOp< UnaryOp< Arg, detail::Arbsign >, Op, RHS > &f, detail::choice< 5 >) -> STATOR_AUTORETURN(try_simplify< Config >(detail::Arbsign::apply(Op::apply(f._l._arg, f._r))))
 
template<class Config , class Arg , std::intmax_t Power>
auto sym::simplify_powerop_impl (const PowerOp< Arg, C< Power, 1 > > &f, detail::choice< 0 >) -> STATOR_AUTORETURN(try_simplify< Config >(PowerOpSub< Power >::eval(simplify< Config >(f._l))))
 
template<class Config , class Arg , std::intmax_t Power>
auto sym::simplify_powerop_impl (const PowerOp< Arg, C< Power, 1 > > &f, detail::choice< 1 >) -> STATOR_AUTORETURN(simplify< Config >(PowerOpSub< Power >::eval(f._l)))
 
template<class Config , class Arg >
auto sym::simplify_UnaryOp (const UnaryOp< UnaryOp< Arg, detail::Arbsign >, detail::Arbsign > &f, detail::choice< 0 >) -> STATOR_AUTORETURN(try_simplify< Config >(detail::Arbsign::apply(f._arg._arg)))
 Specialisation for squares of matrix expressions. More...
 
template<class Config , class Arg , class Op >
auto sym::simplify_UnaryOp (const UnaryOp< Arg, Op > &f, detail::last_choice) -> STATOR_AUTORETURN(try_simplify< Config >(Op::apply(simplify< Config >(f._arg))))
 
template<class T , typename = typename std::enable_if<std::is_arithmetic<T>::value || std::is_base_of<Eigen::EigenBase<T>, T>::value>::type>
auto sym::toArithmetic (T val) -> STATOR_AUTORETURN_BYVALUE(val)
 A converter to arithmetic types. More...
 
template<class T , typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
auto sym::toArithmetic (std::complex< T > val) -> STATOR_AUTORETURN_BYVALUE(val)
 
template<std::intmax_t n1, std::intmax_t d1, typename = typename std::enable_if<!(n1 % d1)>::type>
std::intmax_t sym::toArithmetic (C< n1, d1 > val)
 
template<std::intmax_t n1, std::intmax_t d1, typename = typename std::enable_if<n1 % d1>::type>
double sym::toArithmetic (C< n1, d1 > val)
 
template<class T >
auto sym::try_expand (const T &a) -> STATOR_AUTORETURN(try_simplify< ExpandConfig >(a))
 A variant of try_simplify that expands into Polynomial types aggressively. More...
 
template<class T >
auto sym::try_N (const T &a) -> STATOR_AUTORETURN(try_simplify< NConfig >(a))
 A variant of try_simplify that converts compile time symbols into numbers. More...
 
template<class Config = DefaultSimplifyConfig, class T >
auto sym::try_simplify (const T &a) -> decltype(detail::try_simplify_imp< Config >(a, detail::select_overload
 A method to apply simplification only if it is available. More...
 
template<class Config , class T >
auto sym::detail::try_simplify_imp (const T &a, detail::choice< 0 >) -> STATOR_AUTORETURN(simplify< Config >(a))
 
template<class Config , class T >
sym::detail::try_simplify_imp (const T &a, detail::choice< 1 >)
 

Variables

sym::_r