SymEngine Namespace Reference

Main namespace for SymEngine package. More...

Data Structures

class  Add
 The base class for representing addition in symbolic expressions. More...
 
class  RealImagVisitor
 
class  Assumptions
 
struct  ConstantInitializer
 
class  Basic
 The lowest unit of symbolic representation. More...
 
struct  RCPBasicHash
 Our hash: More...
 
struct  RCPBasicKeyEq
 Our comparison (==) More...
 
struct  RCPBasicKeyLess
 Our less operator (<): More...
 
class  ComplexBase
 ComplexBase Class for deriving all complex classes. More...
 
class  Complex
 Complex Class. More...
 
class  ComplexDouble
 Complex Double Class to hold std::complex<double> values. More...
 
class  ComplexMPC
 
struct  storage_for
 
class  Constant
 
class  FuncArgTracker
 
class  OptsCSEVisitor
 
class  RebuildVisitor
 
class  DiffVisitor
 
struct  vec_hash
 
class  EvalVisitor
 
class  EvalDoubleVisitor
 
class  EvalRealDoubleVisitor
 
class  EvalRealDoubleVisitorPattern
 
class  EvalRealDoubleVisitorFinal
 
class  EvalComplexDoubleVisitor
 
class  ExpandVisitor
 
class  Expression
 
class  GaloisFieldDict
 
class  GaloisField
 
class  fmpz_wrapper
 
class  mpz_view_flint
 
class  fmpq_wrapper
 
class  mpq_view_flint
 
class  fmpz_poly_factor_wrapper
 
class  fmpz_poly_wrapper
 
class  fmpq_poly_wrapper
 
class  Function
 
class  OneArgFunction
 
class  TwoArgBasic
 
class  MultiArgFunction
 
class  Sign
 
class  Floor
 
class  Ceiling
 
class  Truncate
 
class  Conjugate
 
class  TrigBase
 
class  TrigFunction
 
class  InverseTrigFunction
 
class  Sin
 
class  Cos
 
class  Tan
 
class  Cot
 
class  Csc
 
class  Sec
 
class  ASin
 
class  ACos
 
class  ASec
 
class  ACsc
 
class  ATan
 
class  ACot
 
class  ATan2
 
class  Log
 
class  LambertW
 
class  Zeta
 
class  Dirichlet_eta
 
class  FunctionSymbol
 
class  FunctionWrapper
 
class  Derivative
 
class  Subs
 
class  HyperbolicBase
 
class  HyperbolicFunction
 
class  InverseHyperbolicFunction
 
class  Sinh
 
class  Csch
 
class  Cosh
 
class  Sech
 
class  Tanh
 
class  Coth
 
class  ASinh
 
class  ACsch
 
class  ACosh
 
class  ATanh
 
class  ACoth
 
class  ASech
 
class  KroneckerDelta
 
class  LeviCivita
 
class  Erf
 
class  Erfc
 
class  Gamma
 
class  LowerGamma
 
class  UpperGamma
 
class  LogGamma
 
class  Beta
 
class  PolyGamma
 
class  Abs
 
class  Max
 
class  Min
 
class  UnevaluatedExpr
 
class  EvaluateInfty
 
class  Infty
 
class  Integer
 Integer Class. More...
 
struct  RCPIntegerKeyLess
 less operator (<) for Integers More...
 
class  LambdaDoubleVisitor
 
class  LambdaRealDoubleVisitor
 
class  LambdaComplexDoubleVisitor
 
class  IRBuilder
 
class  Boolean
 
class  BooleanAtom
 
class  Contains
 
class  Piecewise
 
class  And
 
class  Or
 
class  Not
 
class  Xor
 
class  Relational
 
class  Equality
 
class  Unequality
 
class  LessThan
 
class  StrictLessThan
 
class  ConjugateMatrixVisitor
 
class  ConjugateMatrix
 
class  DiagonalMatrix
 
class  HadamardProduct
 
class  IdentityMatrix
 
class  ImmutableDenseMatrix
 
class  MatrixDiagonalVisitor
 
class  MatrixLowerVisitor
 
class  MatrixRealVisitor
 
class  MatrixSquareVisitor
 
class  MatrixSymmetricVisitor
 
class  MatrixToeplitzVisitor
 
class  MatrixUpperVisitor
 
class  MatrixZeroVisitor
 
class  MatrixAdd
 
class  MatrixExpr
 
class  MatrixMul
 
class  MatrixSymbol
 
class  MatrixSizeVisitor
 
class  MatrixTraceVisitor
 
class  Trace
 
class  TransposeVisitor
 
class  Transpose
 
class  ZeroMatrix
 
class  MatrixBase
 
class  DenseMatrix
 
class  CSRMatrix
 
struct  two_by_two_matrix
 
class  mp_randstate
 
class  Mul
 
class  EvaluateNaN
 
class  NaN
 
class  PrimePi
 
class  Primorial
 
class  Number
 
class  NumberWrapper
 
class  Evaluate
 A class that will evaluate functions numerically. More...
 
class  NumerDenomVisitor
 
class  PolyGeneratorVisitor
 
class  PolyGeneratorVisitorPow
 
class  BasicToUPolyBase
 
class  BasicToUIntPoly
 
class  BasicToUExprPoly
 
class  BasicToURatPoly
 
class  BasicToMPolyBase
 
class  BasicToMIntPoly
 
class  BasicToMExprPoly
 
class  UDictWrapper
 
class  MIntDict
 
class  MExprDict
 
class  MSymEnginePoly
 
class  MIntPoly
 
class  MExprPoly
 
class  UExprDict
 
class  UExprPoly
 
class  UIntDict
 
class  UIntPoly
 
class  ODictWrapper
 
class  UPolyBase
 
class  UExprPolyBase
 
class  UNonExprPoly
 
class  UIntPolyBase
 
class  URatPolyBase
 
class  ContainerBaseIter
 
class  ContainerForIter
 
class  ContainerRevIter
 
struct  is_a_UPoly
 
class  URatDict
 
class  URatPoly
 
class  USymEnginePoly
 
class  Pow
 
class  Sieve
 
class  CodePrinter
 
class  C89CodePrinter
 
class  C99CodePrinter
 
class  JSCodePrinter
 
class  LatexPrinter
 
class  MathMLPrinter
 
class  SbmlPrinter
 
class  StringBox
 
struct  PrinterBasicCmp
 Less operator (<) using cmp: More...
 
class  Precedence
 
class  StrPrinter
 
class  JuliaStrPrinter
 
class  UnicodePrinter
 
class  Rational
 Rational Class. More...
 
class  EvaluateDouble
 Evaluate functions with double precision. More...
 
class  EvaluateRealDouble
 
class  EvaluateComplexDouble
 
class  RealDouble
 RealDouble Class to hold double values. More...
 
class  RealMPFR
 
class  RefineVisitor
 
class  RewriteAsExp
 
class  RewriteAsSin
 
class  RewriteAsCos
 
class  SeriesCoeffInterface
 
class  SeriesBase
 
class  UnivariateSeries
 UnivariateSeries Class. More...
 
class  SeriesVisitor
 
class  NeedsSymbolicExpansionVisitor
 
class  SupVisitor
 
class  InfVisitor
 
class  BoundaryVisitor
 
class  Set
 
class  EmptySet
 
class  UniversalSet
 
class  FiniteSet
 
class  Interval
 
class  Complexes
 
class  Reals
 
class  Rationals
 
class  Integers
 
class  Naturals
 
class  Naturals0
 
class  Union
 
class  Intersection
 
class  Complement
 
class  ConditionSet
 
class  ImageSet
 
class  SimplifyVisitor
 
class  IsALinearArgTrigVisitor
 
class  InvertComplexVisitor
 
class  XReplaceVisitor
 
class  SubsVisitor
 
class  MSubsVisitor
 
class  SSubsVisitor
 
class  Symbol
 
class  Dummy
 
struct  remove_reference
 
struct  remove_reference< T & >
 
class  EnableRCPFromThis
 
class  ZeroVisitor
 
class  PositiveVisitor
 
class  NonPositiveVisitor
 
class  NegativeVisitor
 
class  NonNegativeVisitor
 
class  IntegerVisitor
 
class  RealVisitor
 
class  ComplexVisitor
 
class  PolynomialVisitor
 
class  RationalVisitor
 
class  FiniteVisitor
 
class  AlgebraicVisitor
 
class  Tuple
 
class  FreeSymbolsVisitor
 
class  Visitor
 
class  BaseVisitor
 
class  StopVisitor
 
class  LocalStopVisitor
 
class  HasSymbolVisitor
 
class  CoeffVisitor
 
class  TransformVisitor
 
struct  is_base_of_multiple
 
struct  is_base_of_multiple< Derived, First >
 
class  AtomsVisitor
 
class  CountOpsVisitor
 

Typedefs

typedef std::unordered_map< RCP< const Basic >, bool, RCPBasicHash, RCPBasicKeyEqumap_basic_bool
 
typedef uint64_t hash_t
 
typedef std::unordered_map< RCP< const Basic >, RCP< const Number >, RCPBasicHash, RCPBasicKeyEqumap_basic_num
 
typedef std::unordered_map< short, RCP< const Basic > > umap_short_basic
 
typedef std::unordered_map< int, RCP< const Basic > > umap_int_basic
 
typedef std::unordered_map< RCP< const Basic >, RCP< const Basic >, RCPBasicHash, RCPBasicKeyEqumap_basic_basic
 
typedef std::unordered_set< RCP< const Basic >, RCPBasicHash, RCPBasicKeyEquset_basic
 
typedef std::vector< int > vec_int
 
typedef std::vector< RCP< const Basic > > vec_basic
 
typedef std::vector< RCP< const Integer > > vec_integer
 
typedef std::vector< unsigned int > vec_uint
 
typedef std::vector< integer_class > vec_integer_class
 
typedef std::vector< RCP< const Symbol > > vec_sym
 
typedef std::set< RCP< const Basic >, RCPBasicKeyLessset_basic
 
typedef std::multiset< RCP< const Basic >, RCPBasicKeyLessmultiset_basic
 
typedef std::map< vec_uint, unsigned long long int > map_vec_uint
 
typedef std::map< vec_uint, integer_class > map_vec_mpz
 
typedef std::map< RCP< const Basic >, RCP< const Number >, RCPBasicKeyLessmap_basic_num
 
typedef std::map< RCP< const Basic >, RCP< const Basic >, RCPBasicKeyLessmap_basic_basic
 
typedef std::map< RCP< const Integer >, unsigned, RCPIntegerKeyLessmap_integer_uint
 
typedef std::map< unsigned, integer_class > map_uint_mpz
 
typedef std::map< unsigned, rational_class > map_uint_mpq
 
typedef std::map< int, Expressionmap_int_Expr
 
typedef std::unordered_map< RCP< const Basic >, unsigned int, RCPBasicHash, RCPBasicKeyEqumap_basic_uint
 
typedef std::vector< std::pair< RCP< const Basic >, RCP< const Basic > > > vec_pair
 
typedef std::unordered_map< vec_uint, integer_class, vec_hash< vec_uint > > umap_uvec_mpz
 
typedef std::unordered_map< vec_int, integer_class, vec_hash< vec_int > > umap_vec_mpz
 
typedef std::unordered_map< vec_int, Expression, vec_hash< vec_int > > umap_vec_expr
 
template<bool B, class T = void>
using enable_if_t = typename std::enable_if< B, T >::type
 
typedef std::function< double(const Basic &)> fn
 
typedef TwoArgBasic< FunctionTwoArgFunction
 
using CodeGenOptLevel = llvm::CodeGenOpt::Level
 
typedef std::set< RCP< const Boolean >, RCPBasicKeyLessset_boolean
 
typedef std::vector< RCP< const Boolean > > vec_boolean
 
typedef std::vector< std::pair< RCP< const Basic >, RCP< const Boolean > > > PiecewiseVec
 
typedef std::vector< std::pair< int, int > > permutelist
 
typedef boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > integer_class
 
typedef boost::multiprecision::number< boost::multiprecision::cpp_rational_backend, boost::multiprecision::et_off > rational_class
 
typedef std::set< RCP< const Set >, RCPBasicKeyLessset_set
 

Enumerations

enum  TypeID { TypeID_Count }
 
enum class  EvalfDomain { Complex = 0 , Real = 1 , Symbolic = 2 }
 
enum class  PrecedenceEnum {
  Relational , Add , Mul , Pow ,
  Atom
}
 
enum class  tribool { indeterminate = -1 , trifalse = 0 , tritrue = 1 }
 

Functions

RCP< const Basicadd (const RCP< const Basic > &a, const RCP< const Basic > &b)
 Adds two objects (safely). More...
 
RCP< const Basicadd (const vec_basic &a)
 Sums the elements of a vector. More...
 
RCP< const Basicsub (const RCP< const Basic > &a, const RCP< const Basic > &b)
 Substracts b from a. More...
 
void pow_number (const RCP< const Basic > &in_re, const RCP< const Basic > &in_im, unsigned long n, Ptr< RCP< const Basic >> &out_re, Ptr< RCP< const Basic >> &out_im)
 
void as_real_imag (const RCP< const Basic > &x, const Ptr< RCP< const Basic >> &real, const Ptr< RCP< const Basic >> &imag)
 
bool eq (const Basic &a, const Basic &b)
 Checks equality for a and b More...
 
bool neq (const Basic &a, const Basic &b)
 Checks inequality for a and b More...
 
template<class T >
bool is_a (const Basic &b)
 Templatised version to check is_a type. More...
 
template<class T >
bool is_a_sub (const Basic &b)
 
bool is_same_type (const Basic &a, const Basic &b)
 Returns true if a and b are exactly the same type T.
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::Basic &p)
 << Operator More...
 
template<typename T >
void hash_combine_impl (hash_t &seed, const T &v, typename std::enable_if< std::is_base_of< Basic, T >::value >::type *=nullptr)
 Templatised version to combine hash.
 
template<typename T >
void hash_combine_impl (hash_t &seed, const T &v, typename std::enable_if< std::is_integral< T >::value >::type *=nullptr)
 
void hash_combine_impl (hash_t &seed, const std::string &s)
 
void hash_combine_impl (hash_t &seed, const double &s)
 
template<class T >
void hash_combine (hash_t &seed, const T &v)
 
template<typename T >
std::string to_string (const T &value)
 workaround for MinGW bug
 
std::string type_code_name (TypeID id)
 
const char * get_version ()
 
bool is_a_Atom (const Basic &b)
 Returns true if b is an atom. i.e. b.get_args returns an empty vector.
 
RCP< const Basicexpand (const RCP< const Basic > &self, bool deep=true)
 Expands self
 
void as_numer_denom (const RCP< const Basic > &x, const Ptr< RCP< const Basic >> &numer, const Ptr< RCP< const Basic >> &denom)
 
RCP< const Basicrewrite_as_exp (const RCP< const Basic > &x)
 
RCP< const Basicrewrite_as_sin (const RCP< const Basic > &x)
 
RCP< const Basicrewrite_as_cos (const RCP< const Basic > &x)
 
void cse (vec_pair &replacements, vec_basic &reduced_exprs, const vec_basic &exprs)
 
RCP< const Numberpow_number (const Complex &x, unsigned long n)
 
bool is_a_Complex (const Basic &b)
 
RCP< const ComplexDoublecomplex_double (std::complex< double > x)
 
RCP< const ComplexDoublecomplex_double (double real, double imag)
 
RCP< const Constantconstant (const std::string &name)
 inline version to return Constant
 
umap_basic_basic opt_cse (const vec_basic &exprs)
 
void tree_cse (vec_pair &replacements, vec_basic &reduced_exprs, const vec_basic &exprs, umap_basic_basic &opt_subs)
 
std::vector< unsigned > set_diff (const std::set< unsigned > &a, const std::vector< unsigned > &b)
 
void add_to_sorted_vec (std::vector< unsigned > &vec, unsigned number)
 
void match_common_args (const std::string &func_class, const vec_basic &funcs_, umap_basic_basic &opt_subs)
 
vec_basic set_as_vec (const set_basic &s)
 
template<typename T >
bool is_aligned (T *p, size_t n=alignof(T))
 
static std::string _str (const Basic &a)
 
void jacobian (const DenseMatrix &A, const DenseMatrix &x, DenseMatrix &result, bool diff_cache)
 
void sjacobian (const DenseMatrix &A, const DenseMatrix &x, DenseMatrix &result, bool diff_cache)
 
void diff (const DenseMatrix &A, const RCP< const Symbol > &x, DenseMatrix &result, bool diff_cache)
 
void sdiff (const DenseMatrix &A, const RCP< const Basic > &x, DenseMatrix &result, bool diff_cache)
 
void conjugate_dense (const DenseMatrix &A, DenseMatrix &B)
 
void transpose_dense (const DenseMatrix &A, DenseMatrix &B)
 
void conjugate_transpose_dense (const DenseMatrix &A, DenseMatrix &B)
 
void submatrix_dense (const DenseMatrix &A, DenseMatrix &B, unsigned row_start, unsigned col_start, unsigned row_end, unsigned col_end, unsigned row_step, unsigned col_step)
 
void add_dense_dense (const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &C)
 
void add_dense_scalar (const DenseMatrix &A, const RCP< const Basic > &k, DenseMatrix &B)
 
void mul_dense_dense (const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &C)
 
void elementwise_mul_dense_dense (const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &C)
 
void mul_dense_scalar (const DenseMatrix &A, const RCP< const Basic > &k, DenseMatrix &B)
 
void row_exchange_dense (DenseMatrix &A, unsigned i, unsigned j)
 
void row_mul_scalar_dense (DenseMatrix &A, unsigned i, RCP< const Basic > &c)
 
void row_add_row_dense (DenseMatrix &A, unsigned i, unsigned j, RCP< const Basic > &c)
 
void permuteFwd (DenseMatrix &A, permutelist &pl)
 
void column_exchange_dense (DenseMatrix &A, unsigned i, unsigned j)
 
void pivoted_gaussian_elimination (const DenseMatrix &A, DenseMatrix &B, permutelist &pl)
 
void fraction_free_gaussian_elimination (const DenseMatrix &A, DenseMatrix &B)
 
void pivoted_fraction_free_gaussian_elimination (const DenseMatrix &A, DenseMatrix &B, permutelist &pl)
 
void pivoted_gauss_jordan_elimination (const DenseMatrix &A, DenseMatrix &B, permutelist &pl)
 
void fraction_free_gauss_jordan_elimination (const DenseMatrix &A, DenseMatrix &B)
 
void pivoted_fraction_free_gauss_jordan_elimination (const DenseMatrix &A, DenseMatrix &B, permutelist &pl)
 
unsigned pivot (DenseMatrix &B, unsigned r, unsigned c)
 
void reduced_row_echelon_form (const DenseMatrix &A, DenseMatrix &b, vec_uint &pivot_cols, bool normalize_last)
 
void diagonal_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x)
 
void back_substitution (const DenseMatrix &U, const DenseMatrix &b, DenseMatrix &x)
 
void forward_substitution (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x)
 
void fraction_free_gaussian_elimination_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x)
 
void fraction_free_gauss_jordan_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x, bool pivot)
 
void fraction_free_LU_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x)
 
void LU_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x)
 
void pivoted_LU_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x)
 
void LDL_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x)
 
void fraction_free_LU (const DenseMatrix &A, DenseMatrix &LU)
 
void LU (const DenseMatrix &A, DenseMatrix &L, DenseMatrix &U)
 
void pivoted_LU (const DenseMatrix &A, DenseMatrix &LU, permutelist &pl)
 
void pivoted_LU (const DenseMatrix &A, DenseMatrix &L, DenseMatrix &U, permutelist &pl)
 
void fraction_free_LDU (const DenseMatrix &A, DenseMatrix &L, DenseMatrix &D, DenseMatrix &U)
 
void QR (const DenseMatrix &A, DenseMatrix &Q, DenseMatrix &R)
 
void LDL (const DenseMatrix &A, DenseMatrix &L, DenseMatrix &D)
 
void cholesky (const DenseMatrix &A, DenseMatrix &L)
 
bool is_symmetric_dense (const DenseMatrix &A)
 
RCP< const Basicdet_bareis (const DenseMatrix &A)
 
void berkowitz (const DenseMatrix &A, std::vector< DenseMatrix > &polys)
 
RCP< const Basicdet_berkowitz (const DenseMatrix &A)
 
void char_poly (const DenseMatrix &A, DenseMatrix &B)
 
void inverse_fraction_free_LU (const DenseMatrix &A, DenseMatrix &B)
 
void inverse_LU (const DenseMatrix &A, DenseMatrix &B)
 
void inverse_pivoted_LU (const DenseMatrix &A, DenseMatrix &B)
 
void inverse_gauss_jordan (const DenseMatrix &A, DenseMatrix &B)
 
void dot (const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &C)
 
void cross (const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &C)
 
RCP< const Seteigen_values (const DenseMatrix &A)
 
void eye (DenseMatrix &A, int k)
 
void diag (DenseMatrix &A, vec_basic &v, int k)
 
void ones (DenseMatrix &A)
 
void zeros (DenseMatrix &A)
 
template<typename T >
static RCP< const Basicfdiff (const T &self, RCP< const Symbol > x, DiffVisitor &visitor)
 
static bool fdiff (const Ptr< RCP< const Basic >> &ret, const Zeta &self, unsigned index)
 
static bool fdiff (const Ptr< RCP< const Basic >> &ret, const UpperGamma &self, unsigned index)
 
static bool fdiff (const Ptr< RCP< const Basic >> &ret, const LowerGamma &self, unsigned index)
 
static bool fdiff (const Ptr< RCP< const Basic >> &ret, const PolyGamma &self, unsigned index)
 
static bool fdiff (const Ptr< RCP< const Basic >> &ret, const Function &self, unsigned index)
 
template<typename P >
static RCP< const Basicdiff_upolyflint (const P &self, const Symbol &x)
 
template<typename Poly , typename Dict >
static RCP< const Basicdiff_upoly (const Poly &self, const Symbol &x)
 
template<typename Container , typename Poly >
static RCP< const Basicdiff_mpoly (const MSymEnginePoly< Container, Poly > &self, const RCP< const Symbol > &x)
 
static RCP< const Symbolget_dummy (const Basic &b, std::string name)
 
RCP< const Basicdiff (const RCP< const Basic > &arg, const RCP< const Symbol > &x, bool cache=true)
 Differentiation w.r.t symbols.
 
RCP< const Basicsdiff (const RCP< const Basic > &arg, const RCP< const Basic > &x, bool cache)
 SymPy style differentiation for non-symbol variables. More...
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::umap_basic_num &d)
 print functions
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::map_basic_num &d)
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::map_basic_basic &d)
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::umap_basic_basic &d)
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::vec_basic &d)
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::set_basic &d)
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::map_int_Expr &d)
 
std::ostreamoperator<< (std::ostream &out, const SymEngine::vec_pair &d)
 
bool vec_basic_eq_perm (const vec_basic &a, const vec_basic &b)
 misc functions
 
template<typename T1 , typename T2 , typename T3 >
void insert (T1 &m, const T2 &first, const T3 &second)
 
template<class M , typename C = std::less<typename M::key_type>>
std::vector< typename M::key_type > sorted_keys (const M &d)
 
template<typename T , typename U >
bool unified_eq (const std::pair< T, U > &a, const std::pair< T, U > &b)
 
template<typename T , typename U >
bool unified_eq (const std::set< T, U > &a, const std::set< T, U > &b)
 
template<typename T , typename U >
bool unified_eq (const std::multiset< T, U > &a, const std::multiset< T, U > &b)
 
template<typename K , typename V , typename C >
bool unified_eq (const std::map< K, V, C > &a, const std::map< K, V, C > &b)
 
template<typename K , typename V , typename H , typename E >
bool unified_eq (const std::unordered_map< K, V, H, E > &a, const std::unordered_map< K, V, H, E > &b)
 
template<typename T , typename U , typename = enable_if_t<std::is_base_of<Basic, T>::value and std::is_base_of<Basic, U>::value>>
bool unified_eq (const RCP< const T > &a, const RCP< const U > &b)
 
template<typename T , typename = enable_if_t<std::is_arithmetic<T>::value or std::is_same<T, integer_class>::value>>
bool unified_eq (const T &a, const T &b)
 
template<class T >
bool unordered_eq (const T &a, const T &b)
 
template<class T >
bool ordered_eq (const T &A, const T &B)
 
template<typename T >
bool unified_eq (const std::vector< T > &a, const std::vector< T > &b)
 
template<typename T , typename = enable_if_t<std::is_arithmetic<T>::value or std::is_same<T, integer_class>::value or std::is_same<T, rational_class>::value>>
int unified_compare (const T &a, const T &b)
 
template<typename T , typename U , typename = enable_if_t<std::is_base_of<Basic, T>::value and std::is_base_of<Basic, U>::value>>
int unified_compare (const RCP< const T > &a, const RCP< const U > &b)
 
template<class T >
int ordered_compare (const T &A, const T &B)
 
template<typename T >
int unified_compare (const std::vector< T > &a, const std::vector< T > &b)
 
template<typename T , typename U >
int unified_compare (const std::set< T, U > &a, const std::set< T, U > &b)
 
template<typename T , typename U >
int unified_compare (const std::multiset< T, U > &a, const std::multiset< T, U > &b)
 
template<typename T , typename U >
int unified_compare (const std::pair< T, U > &a, const std::pair< T, U > &b)
 
template<typename K , typename V , typename C >
int unified_compare (const std::map< K, V, C > &a, const std::map< K, V, C > &b)
 
template<typename K , typename V , typename H , typename E >
int unified_compare (const std::unordered_map< K, V, H, E > &a, const std::unordered_map< K, V, H, E > &b)
 
template<class M , typename C = std::less<typename M::key_type>>
int unordered_compare (const M &a, const M &b)
 
bool order (const DenseMatrix &t, const std::vector< DenseMatrix > &basis, unsigned k)
 
bool is_minimum (const DenseMatrix &t, const std::vector< DenseMatrix > &basis, unsigned n)
 
void homogeneous_lde (std::vector< DenseMatrix > &basis, const DenseMatrix &A)
 
RCP< const Numberevalf_numeric (const Basic &b, unsigned long bits, bool real)
 
RCP< const Basicevalf (const Basic &b, unsigned long bits, EvalfDomain domain)
 
static std::vector< fninit_eval_double ()
 
double eval_double (const Basic &b)
 
std::complex< double > eval_complex_double (const Basic &b)
 
double eval_double_single_dispatch (const Basic &b)
 
double eval_double_visitor_pattern (const Basic &b)
 
RCP< const Number_mulnum (const RCP< const Number > &x, const RCP< const Number > &y)
 
void _imulnum (const Ptr< RCP< const Number >> &self, const RCP< const Number > &other)
 
Expression pow (const Expression &base, const Expression &exp)
 
Expression expand (const Expression &arg)
 
bool unified_eq (const Expression &a, const Expression &b)
 
int unified_compare (const Expression &a, const Expression &b)
 
RCP< const GaloisFieldgf_poly (RCP< const Basic > i, GaloisFieldDict &&dict)
 
RCP< const GaloisFieldgf_poly (RCP< const Basic > i, map_uint_mpz &&dict, integer_class modulo_)
 
RCP< const GaloisFieldpow_upoly (const GaloisField &a, unsigned int p)
 
vec_basic generate_fdiff_weights_vector (const vec_basic &grid, const unsigned max_deriv, const RCP< const Basic > around)
 
RCP< const Basicsqrt (RCP< const Basic > &arg)
 
RCP< const Basiccbrt (RCP< const Basic > &arg)
 
static const RCP< const Basic > * sin_table ()
 
static const umap_basic_basicinverse_cst ()
 
static const umap_basic_basicinverse_tct ()
 
RCP< const Basicconjugate (const RCP< const Basic > &arg)
 Canonicalize Conjugate.
 
bool get_pi_shift (const RCP< const Basic > &arg, const Ptr< RCP< const Number >> &n, const Ptr< RCP< const Basic >> &x)
 
bool trig_has_basic_shift (const RCP< const Basic > &arg)
 
bool could_extract_minus (const Basic &arg)
 
bool handle_minus (const RCP< const Basic > &arg, const Ptr< RCP< const Basic >> &rarg)
 
bool trig_simplify (const RCP< const Basic > &arg, unsigned period, bool odd, bool conj_odd, const Ptr< RCP< const Basic >> &rarg, int &index, int &sign)
 
bool inverse_lookup (const umap_basic_basic &d, const RCP< const Basic > &t, const Ptr< RCP< const Basic >> &index)
 
RCP< const Basicsign (const RCP< const Basic > &arg)
 Canonicalize Sign.
 
RCP< const Basicfloor (const RCP< const Basic > &arg)
 Canonicalize Floor:
 
RCP< const Basicceiling (const RCP< const Basic > &arg)
 Canonicalize Ceiling:
 
RCP< const Basictruncate (const RCP< const Basic > &arg)
 Canonicalize Truncate:
 
RCP< const Basicsin (const RCP< const Basic > &arg)
 Canonicalize Sin:
 
RCP< const Basiccos (const RCP< const Basic > &arg)
 Canonicalize Cos:
 
RCP< const Basictan (const RCP< const Basic > &arg)
 Canonicalize Tan:
 
RCP< const Basiccot (const RCP< const Basic > &arg)
 Canonicalize Cot:
 
RCP< const Basiccsc (const RCP< const Basic > &arg)
 Canonicalize Csc:
 
RCP< const Basicsec (const RCP< const Basic > &arg)
 Canonicalize Sec:
 
RCP< const Basictrig_to_sqrt (const RCP< const Basic > &arg)
 
RCP< const Basicasin (const RCP< const Basic > &arg)
 Canonicalize ASin:
 
RCP< const Basicacos (const RCP< const Basic > &arg)
 Canonicalize ACos:
 
RCP< const Basicasec (const RCP< const Basic > &arg)
 Canonicalize ASec:
 
RCP< const Basicacsc (const RCP< const Basic > &arg)
 Canonicalize ACsc:
 
RCP< const Basicatan (const RCP< const Basic > &arg)
 Canonicalize ATan:
 
RCP< const Basicacot (const RCP< const Basic > &arg)
 Canonicalize ACot:
 
RCP< const Basicatan2 (const RCP< const Basic > &num, const RCP< const Basic > &den)
 Canonicalize ATan2:
 
RCP< const Basiclog (const RCP< const Basic > &arg)
 Returns the Natural Logarithm from argument arg
 
RCP< const Basiclog (const RCP< const Basic > &arg, const RCP< const Basic > &base)
 
RCP< const Basiclambertw (const RCP< const Basic > &arg)
 Create a new LambertW instance:
 
RCP< const Basicfunction_symbol (std::string name, const vec_basic &arg)
 
RCP< const Basicfunction_symbol (std::string name, const RCP< const Basic > &arg)
 Create a new FunctionSymbol instance:
 
RCP< const Basicsinh (const RCP< const Basic > &arg)
 Canonicalize Sinh:
 
RCP< const Basiccsch (const RCP< const Basic > &arg)
 Canonicalize Csch:
 
RCP< const Basiccosh (const RCP< const Basic > &arg)
 Canonicalize Cosh:
 
RCP< const Basicsech (const RCP< const Basic > &arg)
 Canonicalize Sech:
 
RCP< const Basictanh (const RCP< const Basic > &arg)
 Canonicalize Tanh:
 
RCP< const Basiccoth (const RCP< const Basic > &arg)
 Canonicalize Coth:
 
RCP< const Basicasinh (const RCP< const Basic > &arg)
 Canonicalize ASinh:
 
RCP< const Basicacsch (const RCP< const Basic > &arg)
 Canonicalize ACsch:
 
RCP< const Basicacosh (const RCP< const Basic > &arg)
 Canonicalize ACosh:
 
RCP< const Basicatanh (const RCP< const Basic > &arg)
 Canonicalize ATanh:
 
RCP< const Basicacoth (const RCP< const Basic > &arg)
 Canonicalize ACoth:
 
RCP< const Basicasech (const RCP< const Basic > &arg)
 Canonicalize ASech:
 
RCP< const Basickronecker_delta (const RCP< const Basic > &i, const RCP< const Basic > &j)
 Canonicalize KroneckerDelta:
 
bool has_dup (const vec_basic &arg)
 
RCP< const Basiceval_levicivita (const vec_basic &arg, int len)
 
RCP< const Basiclevi_civita (const vec_basic &arg)
 Canonicalize LeviCivita:
 
RCP< const Basiczeta (const RCP< const Basic > &s, const RCP< const Basic > &a)
 Create a new Zeta instance:
 
RCP< const Basiczeta (const RCP< const Basic > &s)
 
RCP< const Basicdirichlet_eta (const RCP< const Basic > &s)
 Create a new Dirichlet_eta instance:
 
RCP< const Basicerf (const RCP< const Basic > &arg)
 Canonicalize Erf:
 
RCP< const Basicerfc (const RCP< const Basic > &arg)
 Canonicalize Erfc:
 
RCP< const Basicgamma_positive_int (const RCP< const Basic > &arg)
 
RCP< const Basicgamma_multiple_2 (const RCP< const Basic > &arg)
 
RCP< const Basicgamma (const RCP< const Basic > &arg)
 Canonicalize Gamma:
 
RCP< const Basiclowergamma (const RCP< const Basic > &s, const RCP< const Basic > &x)
 Canonicalize LowerGamma:
 
RCP< const Basicuppergamma (const RCP< const Basic > &s, const RCP< const Basic > &x)
 Canonicalize UpperGamma:
 
RCP< const Basicloggamma (const RCP< const Basic > &arg)
 Canonicalize LogGamma:
 
RCP< const Basicbeta (const RCP< const Basic > &x, const RCP< const Basic > &y)
 Canonicalize Beta:
 
RCP< const Basicpolygamma (const RCP< const Basic > &n, const RCP< const Basic > &x)
 Canonicalize PolyGamma.
 
RCP< const Basicdigamma (const RCP< const Basic > &x)
 
RCP< const Basictrigamma (const RCP< const Basic > &x)
 
RCP< const Basicabs (const RCP< const Basic > &arg)
 Canonicalize Abs:
 
RCP< const Basicmax (const vec_basic &arg)
 Canonicalize Max:
 
RCP< const Basicmin (const vec_basic &arg)
 Canonicalize Min:
 
RCP< const Basicunevaluated_expr (const RCP< const Basic > &arg)
 
RCP< const Basicsqrt (const RCP< const Basic > &arg)
 
RCP< const Basiccbrt (const RCP< const Basic > &arg)
 
RCP< const Inftyinfty (const RCP< const Number > &direction)
 
RCP< const Inftyinfty (int n=1)
 
RCP< const Integerisqrt (const Integer &n)
 Integer Square root.
 
RCP< const Integeriabs (const Integer &n)
 Integer Absolute value.
 
int i_nth_root (const Ptr< RCP< const Integer >> &r, const Integer &a, unsigned long int n)
 Integer nth root.
 
bool perfect_square (const Integer &n)
 Perfect Square.
 
bool perfect_power (const Integer &n)
 Perfect Square.
 
template<typename T >
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer (T i)
 
RCP< const Integerinteger (integer_class i)
 
llvm::Function * get_float_intrinsic (llvm::Type *type, llvm::Intrinsic::ID id, unsigned n, llvm::Module *mod)
 
RCP< const Booleancontains (const RCP< const Basic > &expr, const RCP< const Set > &set)
 
RCP< const Basicpiecewise (const PiecewiseVec &vec)
 
const vec_boolean get_vec_from_set (const set_boolean &s)
 
template<typename caller >
RCP< const Booleanand_or (const set_boolean &s, const bool &op_x_notx)
 
RCP< const Booleanlogical_not (const RCP< const Boolean > &s)
 
RCP< const Booleanlogical_xor (const vec_boolean &s)
 
RCP< const BooleanEq (const RCP< const Basic > &lhs)
 Returns the canonicalized Equality object from a single argument.
 
RCP< const BooleanEq (const RCP< const Basic > &lhs, const RCP< const Basic > &rhs)
 Returns the canonicalized Equality object from the two arguments.
 
RCP< const BooleanNe (const RCP< const Basic > &lhs, const RCP< const Basic > &rhs)
 Returns the canonicalized Unequality object from the arguments.
 
RCP< const BooleanLe (const RCP< const Basic > &lhs, const RCP< const Basic > &rhs)
 Returns the canonicalized LessThan object from the arguments.
 
RCP< const BooleanGe (const RCP< const Basic > &lhs, const RCP< const Basic > &rhs)
 Convenience function returning LessThan object.
 
RCP< const BooleanLt (const RCP< const Basic > &lhs, const RCP< const Basic > &rhs)
 Returns the canonicalized StrictLessThan object from the arguments.
 
RCP< const BooleanGt (const RCP< const Basic > &lhs, const RCP< const Basic > &rhs)
 Convenience function returning StrictLessThan object.
 
RCP< const Booleanlogical_and (const set_boolean &s)
 
RCP< const Booleanlogical_nand (const set_boolean &s)
 
RCP< const Booleanlogical_or (const set_boolean &s)
 
RCP< const Booleanlogical_nor (const set_boolean &s)
 
RCP< const Booleanlogical_xnor (const vec_boolean &s)
 
RCP< const BooleanAtomboolean (bool b)
 
bool is_a_Relational (const Basic &b)
 
bool is_a_Boolean (const Basic &b)
 
RCP< const MatrixExprconjugate_matrix (const RCP< const MatrixExpr > &arg)
 
bool is_zero_vec (const vec_basic &container)
 
bool is_identity_vec (const vec_basic &container)
 
RCP< const MatrixExprdiagonal_matrix (const vec_basic &container)
 
void check_matching_sizes (const vec_basic &vec)
 
RCP< const MatrixExprhadamard_product (const vec_basic &factors)
 
RCP< const MatrixExpridentity_matrix (const RCP< const Basic > &n)
 
bool is_identity_dense (size_t n, const vec_basic &container)
 
bool is_diagonal_dense (size_t n, const vec_basic &container)
 
vec_basic extract_diagonal (size_t n, const vec_basic &container)
 
RCP< const MatrixExprimmutable_dense_matrix (size_t m, size_t n, const vec_basic &container)
 
tribool is_diagonal (const MatrixExpr &m, const Assumptions *assumptions)
 
tribool is_lower (const MatrixExpr &m, const Assumptions *assumptions)
 
tribool is_real (const MatrixExpr &m, const Assumptions *assumptions)
 
tribool is_square (const MatrixExpr &m, const Assumptions *assumptions)
 
tribool is_symmetric (const MatrixExpr &m, const Assumptions *assumptions)
 
tribool is_toeplitz (const MatrixExpr &m, const Assumptions *assumptions)
 
tribool is_upper (const MatrixExpr &m, const Assumptions *assumptions)
 
tribool is_zero (const MatrixExpr &m, const Assumptions *assumptions)
 
RCP< const MatrixExprmatrix_add (const vec_basic &terms)
 
bool is_a_MatrixExpr (const Basic &b)
 
RCP< const DiagonalMatrixmul_diag_diag (const DiagonalMatrix &A, const DiagonalMatrix &B)
 
RCP< const ImmutableDenseMatrixmul_dense_dense (const ImmutableDenseMatrix &A, const ImmutableDenseMatrix &B)
 
RCP< const ImmutableDenseMatrixmul_diag_dense (const DiagonalMatrix &A, const ImmutableDenseMatrix &B)
 
RCP< const ImmutableDenseMatrixmul_dense_diag (const ImmutableDenseMatrix &A, const DiagonalMatrix &B)
 
void check_matching_mul_sizes (const vec_basic &vec)
 
RCP< const MatrixExprmatrix_mul (const vec_basic &factors)
 
RCP< const MatrixExprmatrix_symbol (const std::string &name)
 
std::pair< RCP< const Basic >, RCP< const Basic > > size (const MatrixExpr &m)
 
RCP< const Basictrace (const RCP< const MatrixExpr > &arg)
 
RCP< const MatrixExprtranspose (const RCP< const MatrixExpr > &arg)
 
RCP< const MatrixExprzero_matrix (const RCP< const Basic > &m, const RCP< const Basic > &n)
 
template<class T >
bool is_a (const MatrixBase &b)
 
bool operator== (const SymEngine::MatrixBase &lhs, const SymEngine::MatrixBase &rhs)
 
bool operator!= (const SymEngine::MatrixBase &lhs, const SymEngine::MatrixBase &rhs)
 
void monomial_mul (const vec_int &A, const vec_int &B, vec_int &C)
 Monomial multiplication.
 
integer_class pow (const integer_class &a, unsigned long b)
 
void mp_fdiv_qr (integer_class &q, integer_class &r, const integer_class &a, const integer_class &b)
 
void mp_cdiv_qr (integer_class &q, integer_class &r, const integer_class &a, const integer_class &b)
 
void mp_gcdext (integer_class &gcd, integer_class &s, integer_class &t, const integer_class &a, const integer_class &b)
 
bool mp_invert (integer_class &res, const integer_class &a, const integer_class &m)
 
integer_class fmod (const integer_class &a, const integer_class &mod)
 
void mp_pow_ui (rational_class &res, const rational_class &i, unsigned long n)
 
void mp_powm (integer_class &res, const integer_class &base, const integer_class &exp, const integer_class &m)
 
integer_class step (const unsigned long &n, const integer_class &i, integer_class &x)
 
bool positive_root (integer_class &res, const integer_class &i, const unsigned long n)
 
bool mp_root (integer_class &res, const integer_class &i, const unsigned long n)
 
integer_class mp_sqrt (const integer_class &i)
 
void mp_rootrem (integer_class &a, integer_class &b, const integer_class &i, unsigned long n)
 
void mp_sqrtrem (integer_class &a, integer_class &b, const integer_class &i)
 
int mp_probab_prime_p (const integer_class &i, unsigned retries)
 
void mp_nextprime (integer_class &res, const integer_class &i)
 
unsigned long mp_scan1 (const integer_class &i)
 
two_by_two_matrix fib_matrix (unsigned long n)
 
void mp_fib_ui (integer_class &res, unsigned long n)
 
void mp_fib2_ui (integer_class &a, integer_class &b, unsigned long n)
 
two_by_two_matrix luc_matrix (unsigned long n)
 
void mp_lucnum_ui (integer_class &res, unsigned long n)
 
void mp_lucnum2_ui (integer_class &a, integer_class &b, unsigned long n)
 
void mp_fac_ui (integer_class &res, unsigned long n)
 
void mp_bin_ui (integer_class &res, const integer_class &n, unsigned long r)
 
bool mp_perfect_power_p (const integer_class &i)
 
bool mp_perfect_square_p (const integer_class &i)
 
integer_class mp_primorial (unsigned long n)
 
int mp_legendre (const integer_class &a, const integer_class &n)
 
int unchecked_jacobi (const integer_class &a, const integer_class &n)
 
int mp_jacobi (const integer_class &a, const integer_class &n)
 
int mp_kronecker (const integer_class &a, const integer_class &n)
 
integer_class operator""_z (const char *str)
 Literal for creating multiple precision integers.
 
rational_class operator""_q (const char *str)
 
integer_class mp_abs (const integer_class &i)
 
int mp_sign (const integer_class &i)
 
double mp_get_d (const integer_class &i)
 
void mp_set_d (integer_class &i, double a)
 
void mp_set_str (integer_class &i, const std::string &a)
 
std::string mp_get_hex_str (const integer_class &i)
 
void mp_demote (integer_class &i)
 
bool mp_fits_ulong_p (const integer_class &i)
 
bool mp_fits_slong_p (const integer_class &i)
 
unsigned long mp_get_ui (const integer_class &i)
 
long mp_get_si (const integer_class &i)
 
mpz_srcptr get_mpz_t (const integer_class &i)
 
mpz_ptr get_mpz_t (integer_class &i)
 
void mp_pow_ui (integer_class &res, const integer_class &i, unsigned long n)
 
void mp_gcd (integer_class &res, const integer_class &a, const integer_class &b)
 
void mp_and (integer_class &res, const integer_class &a, const integer_class &b)
 
void mp_fdiv_r (integer_class &res, const integer_class &a, const integer_class &b)
 
void mp_fdiv_q (integer_class &res, const integer_class &a, const integer_class &b)
 
void mp_cdiv_q (integer_class &res, const integer_class &a, const integer_class &b)
 
void mp_tdiv_q (integer_class &res, const integer_class &a, const integer_class &b)
 
void mp_divexact (integer_class &q, const integer_class &a, const integer_class &b)
 
void mp_lcm (integer_class &q, const integer_class &a, const integer_class &b)
 
void mp_tdiv_qr (integer_class &q, integer_class &r, const integer_class &a, const integer_class &b)
 
void mp_addmul (integer_class &r, const integer_class &a, const integer_class &b)
 
const integer_class & get_den (const rational_class &i)
 
const integer_class & get_num (const rational_class &i)
 
integer_class & get_den (rational_class &i)
 
integer_class & get_num (rational_class &i)
 
mpq_srcptr get_mpq_t (const rational_class &i)
 
void canonicalize (rational_class &i)
 
double mp_get_d (const rational_class &i)
 
int mp_sign (const rational_class &i)
 
rational_class mp_abs (const rational_class &i)
 
bool mp_divisible_p (const integer_class &a, const integer_class &b)
 
void mp_urandomm (integer_class &a, gmp_randstate_t &t, const integer_class &b)
 
auto get_mp_t (const integer_class &x) -> decltype(get_mpz_t(x))
 
auto get_mp_t (const rational_class &x) -> decltype(get_mpq_t(x))
 
int mp_cmpabs (const integer_class &a, const integer_class &b)
 
std::ostreamoperator<< (std::ostream &os, const fmpz_wrapper &f)
 
std::ostreamoperator<< (std::ostream &os, const fmpq_wrapper &f)
 
RCP< const Basicmul (const RCP< const Basic > &a, const RCP< const Basic > &b)
 Multiplication.
 
RCP< const Basicmul (const vec_basic &a)
 
RCP< const Basicdiv (const RCP< const Basic > &a, const RCP< const Basic > &b)
 Division.
 
RCP< const Basicneg (const RCP< const Basic > &a)
 Negation.
 
RCP< const Integergcd (const Integer &a, const Integer &b)
 Greatest Common Divisor.
 
void gcd_ext (const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, const Ptr< RCP< const Integer >> &t, const Integer &a, const Integer &b)
 Extended GCD.
 
RCP< const Integerlcm (const Integer &a, const Integer &b)
 Least Common Multiple.
 
int mod_inverse (const Ptr< RCP< const Integer >> &b, const Integer &a, const Integer &m)
 inverse modulo
 
RCP< const Integermod (const Integer &n, const Integer &d)
 modulo round toward zero
 
RCP< const Integerquotient (const Integer &n, const Integer &d)
 
void quotient_mod (const Ptr< RCP< const Integer >> &q, const Ptr< RCP< const Integer >> &r, const Integer &n, const Integer &d)
 
RCP< const Integermod_f (const Integer &n, const Integer &d)
 modulo round toward -inf
 
RCP< const Integerquotient_f (const Integer &n, const Integer &d)
 
void quotient_mod_f (const Ptr< RCP< const Integer >> &q, const Ptr< RCP< const Integer >> &r, const Integer &n, const Integer &d)
 
RCP< const Integerfibonacci (unsigned long n)
 Fibonacci number.
 
void fibonacci2 (const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, unsigned long n)
 Fibonacci n and n-1.
 
RCP< const Integerlucas (unsigned long n)
 Lucas number.
 
void lucas2 (const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, unsigned long n)
 Lucas number n and n-1.
 
RCP< const Integerbinomial (const Integer &n, unsigned long k)
 Binomial Coefficient.
 
RCP< const Integerfactorial (unsigned long n)
 Factorial.
 
bool divides (const Integer &a, const Integer &b)
 
int probab_prime_p (const Integer &a, unsigned reps=25)
 Probabilistic Prime.
 
RCP< const Integernextprime (const Integer &a)
 
int factor_lehman_method (const Ptr< RCP< const Integer >> &f, const Integer &n)
 Factor using lehman's methods.
 
int factor_pollard_pm1_method (const Ptr< RCP< const Integer >> &f, const Integer &n, unsigned B=10, unsigned retries=5)
 Factor using Pollard's p-1 method.
 
int factor_pollard_rho_method (const Ptr< RCP< const Integer >> &f, const Integer &n, unsigned retries=5)
 Factor using Pollard's rho methods.
 
int factor (const Ptr< RCP< const Integer >> &f, const Integer &n, double B1)
 
int factor_trial_division (const Ptr< RCP< const Integer >> &f, const Integer &n)
 
void prime_factors (std::vector< RCP< const Integer >> &primes, const Integer &n)
 Find prime factors of n
 
void prime_factor_multiplicities (map_integer_uint &primes, const Integer &n)
 Find multiplicities of prime factors of n
 
RCP< const Numberbernoulli (unsigned long n)
 
RCP< const Numberharmonic (unsigned long n, long m=1)
 Computes the sum of the inverses of the first perfect mth powers.
 
bool crt (const Ptr< RCP< const Integer >> &R, const std::vector< RCP< const Integer >> &rem, const std::vector< RCP< const Integer >> &mod)
 Chinese remainder function. Return true when a solution exists.
 
bool primitive_root (const Ptr< RCP< const Integer >> &g, const Integer &n)
 Computes a primitive root. Returns false if no primitive root exists.
 
void primitive_root_list (std::vector< RCP< const Integer >> &roots, const Integer &n)
 
RCP< const Integertotient (const RCP< const Integer > &n)
 Euler's totient function.
 
RCP< const Integercarmichael (const RCP< const Integer > &n)
 Carmichael function.
 
bool multiplicative_order (const Ptr< RCP< const Integer >> &o, const RCP< const Integer > &a, const RCP< const Integer > &n)
 Multiplicative order. Return false if order does not exist.
 
int legendre (const Integer &a, const Integer &n)
 Legendre Function.
 
int jacobi (const Integer &a, const Integer &n)
 Jacobi Function.
 
int kronecker (const Integer &a, const Integer &n)
 Kronecker Function.
 
bool _is_nthroot_mod_prime_power (const integer_class &a, const integer_class &n, const integer_class &p, const unsigned k)
 
bool nthroot_mod (const Ptr< RCP< const Integer >> &root, const RCP< const Integer > &a, const RCP< const Integer > &n, const RCP< const Integer > &m)
 A solution to x**n == a mod m. Return false if none exists.
 
void nthroot_mod_list (std::vector< RCP< const Integer >> &roots, const RCP< const Integer > &a, const RCP< const Integer > &n, const RCP< const Integer > &m)
 All Solutions to x**n == a mod m. Return false if none exists.
 
bool powermod (const Ptr< RCP< const Integer >> &powm, const RCP< const Integer > &a, const RCP< const Number > &b, const RCP< const Integer > &m)
 
void powermod_list (std::vector< RCP< const Integer >> &pows, const RCP< const Integer > &a, const RCP< const Number > &b, const RCP< const Integer > &m)
 
vec_integer_class quadratic_residues (const Integer &a)
 Finds all Quadratic Residues of a Positive Integer.
 
bool is_quad_residue (const Integer &a, const Integer &p)
 Returns true if 'a' is a quadratic residue of 'p'.
 
bool is_nth_residue (const Integer &a, const Integer &n, const Integer &mod)
 Returns true if 'a' is a nth power residue of 'mod'.
 
int mobius (const Integer &a)
 Mobius Function.
 
long mertens (const unsigned long a)
 
integer_class mp_polygonal_number (const integer_class &s, const integer_class &n)
 Numeric calculation of the n:th s-gonal number. More...
 
integer_class mp_principal_polygonal_root (const integer_class &s, const integer_class &x)
 Numeric calculation of the principal s-gonal root of x. More...
 
std::pair< integer_class, integer_class > mp_perfect_power_decomposition (const integer_class &n, bool lowest_exponent=false)
 Decompose a positive integer into perfect powers. More...
 
RCP< const Basicprimepi (const RCP< const Basic > &arg)
 
RCP< const Basicprimorial (const RCP< const Basic > &arg)
 
RCP< const Basicpolygonal_number (const RCP< const Basic > &s, const RCP< const Basic > &n)
 The n:th s-gonal number. More...
 
RCP< const Basicprincipal_polygonal_root (const RCP< const Basic > &s, const RCP< const Basic > &x)
 The principal s-gonal root of x. More...
 
RCP< const Numberaddnum (const RCP< const Number > &self, const RCP< const Number > &other)
 Add self and other
 
RCP< const Numbersubnum (const RCP< const Number > &self, const RCP< const Number > &other)
 Subtract self and other
 
RCP< const Numbermulnum (const RCP< const Number > &self, const RCP< const Number > &other)
 Multiply self and other
 
RCP< const Numberdivnum (const RCP< const Number > &self, const RCP< const Number > &other)
 Divide self and other
 
RCP< const Numberpownum (const RCP< const Number > &self, const RCP< const Number > &other)
 Raise self to power other
 
void iaddnum (const Ptr< RCP< const Number >> &self, const RCP< const Number > &other)
 
void imulnum (const Ptr< RCP< const Number >> &self, const RCP< const Number > &other)
 
void idivnum (const Ptr< RCP< const Number >> &self, const RCP< const Number > &other)
 
bool is_a_Number (const Basic &b)
 
bool is_number_and_zero (const Basic &b)
 
tribool is_zero (const Basic &b, const Assumptions *assumptions=nullptr)
 Check if a number is zero. More...
 
tribool is_nonzero (const Basic &b, const Assumptions *assumptions=nullptr)
 Check if a number is non-zero. More...
 
tribool is_positive (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_nonpositive (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_negative (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_nonnegative (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_integer (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_real (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_complex (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_rational (const Basic &b)
 
tribool is_irrational (const Basic &b)
 
tribool is_finite (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_infinite (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_even (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_odd (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_algebraic (const Basic &b, const Assumptions *assumptions=nullptr)
 
tribool is_transcendental (const Basic &b, const Assumptions *assumptions=nullptr)
 
RCP< const Basicparse (const std::string &s, bool convert_xor=true, const std::map< const std::string, const RCP< const Basic >> &constants={})
 
RCP< const Basicparse_old (const std::string &s, bool convert_xor=true)
 
RCP< const Basicparse_sbml (const std::string &s, const std::map< const std::string, const RCP< const Basic >> &constants={})
 
umap_basic_num _find_gens_poly_pow (const RCP< const Basic > &x, const RCP< const Basic > &base)
 
umap_basic_num _find_gens_poly (const RCP< const Basic > &x)
 
template<typename P >
RCP< const P > from_basic (const RCP< const Basic > &basic, const RCP< const Basic > &gen, bool ex=false)
 
template<typename P >
enable_if_t< is_a_UPoly< P >::value, RCP< const P > > from_basic (const RCP< const Basic > &basic, bool ex=false)
 
template<typename T , typename P >
enable_if_t< std::is_same< T, UExprDict >::value, T > _basic_to_upoly (const RCP< const Basic > &basic, const RCP< const Basic > &gen)
 
template<typename T , typename P >
enable_if_t< std::is_base_of< UIntPolyBase< T, P >, P >::value, T > _basic_to_upoly (const RCP< const Basic > &basic, const RCP< const Basic > &gen)
 
template<typename T , typename P >
enable_if_t< std::is_base_of< URatPolyBase< T, P >, P >::value, T > _basic_to_upoly (const RCP< const Basic > &basic, const RCP< const Basic > &gen)
 
template<typename P >
enable_if_t< std::is_same< MIntPoly, P >::value, typename P::container_type > _basic_to_mpoly (const RCP< const Basic > &basic, const set_basic &gens)
 
template<typename P >
enable_if_t< std::is_same< MExprPoly, P >::value, typename P::container_type > _basic_to_mpoly (const RCP< const Basic > &basic, const set_basic &gens)
 
template<typename P >
RCP< const P > from_basic (const RCP< const Basic > &basic, set_basic &gens, bool ex=false)
 
template<typename P >
enable_if_t< std::is_base_of< MSymEnginePoly< typename P::container_type, P >, P >::value, RCP< const P > > from_basic (const RCP< const Basic > &basic, bool ex=false)
 
template<typename Poly >
void cancel (const RCP< const Basic > &numer, const RCP< const Basic > &denom, const Ptr< RCP< const Poly >> &result_numer, const Ptr< RCP< const Poly >> &result_denom, const Ptr< RCP< const Poly >> &common)
 
unsigned int reconcile (vec_uint &v1, vec_uint &v2, set_basic &s, const set_basic &s1, const set_basic &s2)
 
template<typename Poly , typename Container >
set_basic get_translated_container (Container &x, Container &y, const Poly &a, const Poly &b)
 
template<typename Poly >
RCP< const Poly > add_mpoly (const Poly &a, const Poly &b)
 
template<typename Poly >
RCP< const Poly > sub_mpoly (const Poly &a, const Poly &b)
 
template<typename Poly >
RCP< const Poly > mul_mpoly (const Poly &a, const Poly &b)
 
template<typename Poly >
RCP< const Poly > neg_mpoly (const Poly &a)
 
template<typename Poly >
RCP< const Poly > pow_mpoly (const Poly &a, unsigned int n)
 
RCP< const UExprPolyuexpr_poly (RCP< const Basic > i, UExprDict &&dict)
 
RCP< const UExprPolyuexpr_poly (RCP< const Basic > i, map_int_Expr &&dict)
 
bool divides_upoly (const UIntPoly &a, const UIntPoly &b, const Ptr< RCP< const UIntPoly >> &out)
 
template<typename T >
unsigned int bit_length (T t)
 
integer_class to_mp_class (const integer_class &i)
 
rational_class to_mp_class (const rational_class &i)
 
template<typename Poly >
RCP< const Poly > add_upoly (const Poly &a, const Poly &b)
 
template<typename Poly >
RCP< const Poly > neg_upoly (const Poly &a)
 
template<typename Poly >
RCP< const Poly > sub_upoly (const Poly &a, const Poly &b)
 
template<typename Poly >
RCP< const Poly > mul_upoly (const Poly &a, const Poly &b)
 
template<typename Poly >
RCP< const Poly > quo_upoly (const Poly &a, const Poly &b)
 
bool divides_upoly (const URatPoly &a, const URatPoly &b, const Ptr< RCP< const URatPoly >> &out)
 
template<typename Container , template< typename X, typename Y > class BaseType, typename Poly >
RCP< const Poly > pow_upoly (const USymEnginePoly< Container, BaseType, Poly > &a, unsigned int p)
 
RCP< const Basicpow (const RCP< const Basic > &a, const RCP< const Basic > &b)
 
void multinomial_coefficients (unsigned m, unsigned n, map_vec_uint &r)
 
void multinomial_coefficients_mpz (unsigned m, unsigned n, map_vec_mpz &r)
 
RCP< const Basicexp (const RCP< const Basic > &x)
 Returns the natural exponential function E**x = pow(E, x)
 
RCP< const Basicpow_expand (const RCP< const Pow > &self)
 Expand the power expression.
 
static std::vector< unsigned > & sieve_primes ()
 
std::string ccode (const Basic &x)
 
std::string jscode (const Basic &x)
 
std::string c89code (const Basic &x)
 
std::string c99code (const Basic &x)
 
std::string latex (const Basic &x)
 
void print_rational_class (const rational_class &r, std::ostringstream &s)
 
std::string latex (const DenseMatrix &m, const unsigned max_rows, const unsigned max_cols)
 
std::vector< std::stringinit_latex_printer_names ()
 
std::vector< std::stringinit_mathml_printer_names ()
 
std::string mathml (const Basic &x)
 
static std::vector< std::stringinit_sbml_printer_names ()
 
std::string sbml (const Basic &x)
 
std::string ascii_art ()
 
std::string print_double (double d)
 
template<typename T >
char _print_sign (const T &i)
 
template<typename P >
std::string upoly_print (const P &x)
 
std::vector< std::stringinit_str_printer_names ()
 
std::string str (const Basic &x)
 
std::string str (const DenseMatrix &x)
 
std::string julia_str (const Basic &x)
 
static std::vector< std::stringinit_unicode_printer_names ()
 
static std::vector< size_t > init_unicode_printer_lengths (const std::vector< std::string > &names)
 
std::string unicode (const Basic &x)
 
void get_num_den (const Rational &rat, const Ptr< RCP< const Integer >> &num, const Ptr< RCP< const Integer >> &den)
 returns the num and den of rational rat as RCP<const Integer>
 
RCP< const Numberrational (long n, long d)
 convenience creator from two longs
 
RCP< const RealDoublereal_double (double x)
 
RCP< const Numbernumber (std::complex< double > x)
 
RCP< const Numbernumber (double x)
 
RCP< const Basicrefine (const RCP< const Basic > &x, const Assumptions *assumptions)
 
void expr2poly (const RCP< const Basic > &p, umap_basic_num &syms, umap_vec_mpz &P)
 Converts expression p into a polynomial P, with symbols sym
 
void poly_mul (const umap_vec_mpz &A, const umap_vec_mpz &B, umap_vec_mpz &C)
 Multiply two polynomials: C = A*B
 
template<class Archive >
void save_basic (Archive &ar, const Basic &b)
 
template<class Archive >
void save_basic (Archive &ar, const Symbol &b)
 
template<class Archive >
void save_basic (Archive &ar, const Mul &b)
 
template<class Archive >
void save_basic (Archive &ar, const Add &b)
 
template<class Archive >
void save_basic (Archive &ar, const Pow &b)
 
template<typename Archive >
void save_helper (Archive &ar, const integer_class &intgr)
 
template<typename Archive >
void save_helper (Archive &ar, const rational_class &rat)
 
template<typename Archive >
void save_basic (Archive &ar, const URatPoly &b)
 
template<class Archive >
void save_basic (Archive &ar, const Integer &b)
 
template<class Archive >
void save_basic (Archive &ar, const RealDouble &b)
 
template<class Archive >
void save_basic (Archive &ar, const Rational &b)
 
template<class Archive >
void save_basic (Archive &ar, const ComplexBase &b)
 
template<class Archive >
void save_basic (Archive &ar, const Interval &b)
 
template<class Archive >
void save_basic (Archive &ar, const BooleanAtom &b)
 
template<class Archive >
void save_basic (Archive &ar, const Infty &b)
 
template<class Archive >
void save_basic (Archive &ar, const NaN &b)
 
template<class Archive >
void save_basic (Archive &ar, const Constant &b)
 
template<class Archive >
void save_basic (Archive &ar, const OneArgFunction &b)
 
template<class Archive >
void save_basic (Archive &ar, const TwoArgFunction &b)
 
template<class Archive >
void save_basic (Archive &ar, const Relational &b)
 
template<class Archive >
void save_basic (Archive &ar, const And &b)
 
template<class Archive >
void save_basic (Archive &ar, const Or &b)
 
template<class Archive >
void save_basic (Archive &ar, const Xor &b)
 
template<class Archive >
void save_basic (Archive &ar, const Not &b)
 
template<class Archive >
void save_basic (Archive &ar, const Contains &b)
 
template<class Archive >
void save_basic (Archive &ar, const Piecewise &b)
 
template<class Archive >
void save_basic (Archive &ar, const Reals &b)
 
template<class Archive >
void save_basic (Archive &ar, const Rationals &b)
 
template<class Archive >
void save_basic (Archive &ar, const EmptySet &b)
 
template<class Archive >
void save_basic (Archive &ar, const Integers &b)
 
template<class Archive >
void save_basic (Archive &ar, const UniversalSet &b)
 
template<class Archive >
void save_basic (Archive &ar, const Union &b)
 
template<class Archive >
void save_basic (Archive &ar, const Complement &b)
 
template<class Archive >
void save_basic (Archive &ar, const ImageSet &b)
 
template<class Archive >
void save_basic (Archive &ar, const FiniteSet &b)
 
template<class Archive >
void save_basic (Archive &ar, const ConditionSet &b)
 
template<class Archive >
void save_basic (Archive &ar, const GaloisField &b)
 
template<class Archive >
void save_basic (Archive &ar, const SeriesCoeffInterface &)
 
template<class Archive >
void save_basic (Archive &ar, const MultiArgFunction &b)
 
template<class Archive >
void save_basic (Archive &ar, const FunctionSymbol &b)
 
template<class Archive >
void save_basic (Archive &ar, const Derivative &b)
 
template<class Archive >
void save_basic (Archive &ar, const Subs &b)
 
template<class Archive >
void save_basic (Archive &ar, const NumberWrapper &b)
 
template<class Archive >
void save_basic (Archive &ar, const FunctionWrapper &b)
 
template<class Archive >
void save_basic (Archive &ar, RCP< const Basic > const &ptr)
 
template<class Archive , class T >
void CEREAL_SAVE_FUNCTION_NAME (Archive &ar, RCP< const T > const &ptr)
 Saving for SymEngine::RCP.
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const RealDouble > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Infty > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const NaN > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Symbol > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Mul > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Add > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Pow > &)
 
template<typename Archive >
void load_helper (Archive &ar, integer_class &intgr)
 
template<typename Archive >
void load_helper (Archive &ar, const rational_class &rat)
 
template<typename Archive >
RCP< const Basicload_basic (Archive &ar, const URatPoly &b)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Integer > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Constant > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Rational > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Complex > &)
 
template<class Archive , class T >
RCP< const Basicload_basic (Archive &ar, RCP< const T > &, typename std::enable_if< std::is_base_of< ComplexBase, T >::value, int >::type *=nullptr)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Interval > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const BooleanAtom > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const And > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Or > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Xor > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Not > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Piecewise > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Contains > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Reals > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Rationals > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const EmptySet > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Integers > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const UniversalSet > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Union > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Complement > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const ImageSet > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const FiniteSet > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const ConditionSet > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Derivative > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const Subs > &)
 
template<class Archive , class T >
RCP< const Basicload_basic (Archive &ar, RCP< const T > &, typename std::enable_if< std::is_base_of< OneArgFunction, T >::value, int >::type *=nullptr)
 
template<class Archive , class T >
RCP< const Basicload_basic (Archive &ar, RCP< const T > &, typename std::enable_if< std::is_base_of< TwoArgFunction, T >::value, int >::type *=nullptr)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const FunctionSymbol > &)
 
template<class Archive >
RCP< const Basicload_basic (Archive &ar, RCP< const FunctionWrapper > &)
 
template<class Archive , class T >
RCP< const Basicload_basic (Archive &ar, RCP< const T > &, typename std::enable_if< std::is_base_of< MultiArgFunction, T >::value, int >::type *=nullptr)
 
template<class Archive , class T >
RCP< const Basicload_basic (Archive &ar, RCP< const T > &, typename std::enable_if< std::is_base_of< Relational, T >::value, int >::type *=nullptr)
 
template<class Archive , class T >
RCP< const Basicload_basic (Archive &ar, RCP< const T > &, typename std::enable_if< not(std::is_base_of< Relational, T >::value or std::is_base_of< ComplexBase, T >::value or std::is_base_of< OneArgFunction, T >::value or std::is_base_of< MultiArgFunction, T >::value or std::is_base_of< TwoArgFunction, T >::value), int >::type *=nullptr)
 
template<class Archive >
void save_typeid (Archive &ar, TypeID &t)
 
template<class Archive >
void load_typeid (Archive &ar, TypeID &t)
 
template<class Archive , class T >
void CEREAL_LOAD_FUNCTION_NAME (Archive &ar, RCP< const T > &ptr)
 Loading for SymEngine::RCP.
 
bool needs_symbolic_constants (const RCP< const Basic > &ex, const RCP< const Symbol > &var)
 
RCP< const SeriesCoeffInterfaceseries (const RCP< const Basic > &ex, const RCP< const Symbol > &var, unsigned int prec)
 
RCP< const SeriesCoeffInterfaceseries_invfunc (const RCP< const Basic > &ex, const RCP< const Symbol > &var, unsigned int prec)
 
RCP< const UnivariateSeriesunivariate_series (RCP< const Symbol > i, unsigned int prec, const UExprDict &s)
 
RCP< const Basicsup (const Set &s)
 
RCP< const Basicinf (const Set &s)
 
RCP< const Setboundary (const Set &s)
 
RCP< const Setinterior (const Set &s)
 
RCP< const Setclosure (const Set &s)
 
static RCP< const Setmake_set_union (const set_set &in)
 
static RCP< const Setmake_set_intersection (const set_set &in)
 
RCP< const Setset_union (const set_set &in)
 
RCP< const Setset_intersection (const set_set &in)
 
RCP< const Setset_complement_helper (const RCP< const Set > &container, const RCP< const Set > &universe)
 
RCP< const Setset_complement (const RCP< const Set > &universe, const RCP< const Set > &container)
 
RCP< const Setconditionset (const RCP< const Basic > &sym, const RCP< const Boolean > &condition)
 
bool is_a_Set (const Basic &b)
 
RCP< const Complexescomplexes ()
 
RCP< const Realsreals ()
 
RCP< const Rationalsrationals ()
 
RCP< const Integersintegers ()
 
RCP< const Naturalsnaturals ()
 
RCP< const Naturals0naturals0 ()
 
RCP< const EmptySetemptyset ()
 
RCP< const UniversalSetuniversalset ()
 
RCP< const Setfiniteset (const set_basic &container)
 
RCP< const Setinterval (const RCP< const Number > &start, const RCP< const Number > &end, const bool left_open=false, const bool right_open=false)
 
RCP< const Setimageset (const RCP< const Basic > &sym, const RCP< const Basic > &expr, const RCP< const Set > &base)
 
RCP< const Basicsimplify (const RCP< const Basic > &x, const Assumptions *assumptions)
 
RCP< const Setsolve_poly_linear (const vec_basic &coeffs, const RCP< const Set > &domain)
 
RCP< const Setsolve_poly_quadratic (const vec_basic &coeffs, const RCP< const Set > &domain)
 
RCP< const Setsolve_poly_cubic (const vec_basic &coeffs, const RCP< const Set > &domain)
 
RCP< const Setsolve_poly_quartic (const vec_basic &coeffs, const RCP< const Set > &domain)
 
RCP< const Setsolve_poly_heuristics (const vec_basic &coeffs, const RCP< const Set > &domain)
 
RCP< const Basicget_coeff_basic (const integer_class &i)
 
RCP< const Basicget_coeff_basic (const Expression &i)
 
template<typename Poly >
vec_basic extract_coeffs (const RCP< const Poly > &f)
 
RCP< const Setsolve_poly (const RCP< const Basic > &f, const RCP< const Symbol > &sym, const RCP< const Set > &domain)
 
RCP< const Setsolve_rational (const RCP< const Basic > &f, const RCP< const Symbol > &sym, const RCP< const Set > &domain)
 
bool is_a_LinearArgTrigEquation (const Basic &b, const Symbol &x)
 
RCP< const SetinvertComplex (const RCP< const Basic > &fX, const RCP< const Set > &gY, const RCP< const Symbol > &sym, const RCP< const Dummy > &nD, const RCP< const Set > &domain)
 
RCP< const Setsolve_trig (const RCP< const Basic > &f, const RCP< const Symbol > &sym, const RCP< const Set > &domain)
 
RCP< const Setsolve (const RCP< const Basic > &f, const RCP< const Symbol > &sym, const RCP< const Set > &domain)
 
vec_basic linsolve_helper (const DenseMatrix &A, const DenseMatrix &b)
 
vec_basic linsolve (const DenseMatrix &system, const vec_sym &syms)
 
vec_basic linsolve (const vec_basic &system, const vec_sym &syms)
 
set_basic get_set_from_vec (const vec_sym &syms)
 
std::pair< DenseMatrix, DenseMatrixlinear_eqns_to_matrix (const vec_basic &equations, const vec_sym &syms)
 
void csr_matmat_pass1 (const CSRMatrix &A, const CSRMatrix &B, CSRMatrix &C)
 
void csr_matmat_pass2 (const CSRMatrix &A, const CSRMatrix &B, CSRMatrix &C)
 
void csr_diagonal (const CSRMatrix &A, DenseMatrix &D)
 
void csr_scale_rows (CSRMatrix &A, const DenseMatrix &X)
 
void csr_scale_columns (CSRMatrix &A, const DenseMatrix &X)
 
void csr_binop_csr_canonical (const CSRMatrix &A, const CSRMatrix &B, CSRMatrix &C, RCP< const Basic >(&bin_op)(const RCP< const Basic > &, const RCP< const Basic > &))
 
RCP< const Basicxreplace (const RCP< const Basic > &x, const map_basic_basic &subs_dict, bool cache)
 Mappings in the subs_dict are applied to the expression tree of x
 
RCP< const Basicsubs (const RCP< const Basic > &x, const map_basic_basic &subs_dict, bool cache=true)
 
RCP< const Basicmsubs (const RCP< const Basic > &x, const map_basic_basic &subs_dict, bool cache)
 Subs which treat f(t) and Derivative(f(t), t) as separate variables.
 
RCP< const Basicssubs (const RCP< const Basic > &x, const map_basic_basic &subs_dict, bool cache)
 SymPy compatible subs.
 
RCP< const Symbolsymbol (const std::string &name)
 inline version to return Symbol
 
RCP< const Dummydummy ()
 inline version to return Dummy
 
RCP< const Dummydummy (const std::string &name)
 
template<typename To , typename From >
To implicit_cast (const From &f)
 
template<typename To , typename From >
To down_cast (From *f)
 
template<typename To , typename From >
To down_cast (From &f)
 
template<typename To , typename From >
To numeric_cast (From f, typename std::enable_if<(std::is_signed< From >::value &&std::is_signed< To >::value)||(std::is_unsigned< From >::value &&std::is_unsigned< To >::value)>::type *=nullptr)
 
template<typename To , typename From >
To numeric_cast (From f, typename std::enable_if<(std::is_signed< From >::value &&std::is_unsigned< To >::value)>::type *=nullptr)
 
template<typename To , typename From >
To numeric_cast (From f, typename std::enable_if<(std::is_unsigned< From >::value &&std::is_signed< To >::value)>::type *=nullptr)
 
template<typename T , typename... Args>
RCP< T > make_rcp (Args &&...args)
 
bool is_polynomial (const Basic &b, const set_basic &variables={})
 Check if expression is a polynomial. More...
 
bool is_true (tribool x)
 
bool is_false (tribool x)
 
bool is_indeterminate (tribool x)
 
tribool tribool_from_bool (bool x)
 
tribool and_tribool (tribool a, tribool b)
 
tribool or_tribool (tribool a, tribool b)
 
tribool not_tribool (tribool a)
 
tribool andwk_tribool (tribool a, tribool b)
 
tribool orwk_tribool (tribool a, tribool b)
 
RCP< const Basictuple (const vec_basic &arg)
 
void preorder_traversal (const Basic &b, Visitor &v)
 
void postorder_traversal (const Basic &b, Visitor &v)
 
void preorder_traversal_stop (const Basic &b, StopVisitor &v)
 
void postorder_traversal_stop (const Basic &b, StopVisitor &v)
 
bool has_symbol (const Basic &b, const Basic &x)
 
RCP< const Basiccoeff (const Basic &b, const Basic &x, const Basic &n)
 
set_basic free_symbols (const MatrixBase &m)
 
set_basic free_symbols (const Basic &b)
 
set_basic function_symbols (const Basic &b)
 
void preorder_traversal_local_stop (const Basic &b, LocalStopVisitor &v)
 
unsigned count_ops (const vec_basic &a)
 
template<typename... Args>
set_basic atoms (const Basic &b)
 

Variables

static struct SymEngine::ConstantInitializer constantInitializer
 
static int nifty_counter
 
static storage_for< RCP< const Integer > > zero_buf
 
RCP< const Integer > & zero = reinterpret_cast<RCP<const Integer > &>( zero_buf)
 
static storage_for< RCP< const Integer > > one_buf
 
RCP< const Integer > & one = reinterpret_cast<RCP<const Integer > &>( one_buf)
 
static storage_for< RCP< const Integer > > minus_one_buf
 
RCP< const Integer > & minus_one = reinterpret_cast<RCP<const Integer > &>( minus_one_buf)
 
static storage_for< RCP< const Integer > > two_buf
 
RCP< const Integer > & two = reinterpret_cast<RCP<const Integer > &>( two_buf)
 
static storage_for< RCP< const Number > > I_buf
 
RCP< const Number > & I = reinterpret_cast<RCP<const Number > &>( I_buf)
 
static storage_for< RCP< const Constant > > pi_buf
 
RCP< const Constant > & pi = reinterpret_cast<RCP<const Constant > &>( pi_buf)
 
static storage_for< RCP< const Constant > > E_buf
 
RCP< const Constant > & E = reinterpret_cast<RCP<const Constant > &>( E_buf)
 
static storage_for< RCP< const Constant > > EulerGamma_buf
 
RCP< const Constant > & EulerGamma = reinterpret_cast<RCP<const Constant > &>( EulerGamma_buf)
 
static storage_for< RCP< const Constant > > Catalan_buf
 
RCP< const Constant > & Catalan = reinterpret_cast<RCP<const Constant > &>( Catalan_buf)
 
static storage_for< RCP< const Constant > > GoldenRatio_buf
 
RCP< const Constant > & GoldenRatio = reinterpret_cast<RCP<const Constant > &>( GoldenRatio_buf)
 
static storage_for< RCP< const Infty > > Inf_buf
 
RCP< const Infty > & Inf = reinterpret_cast<RCP<const Infty > &>( Inf_buf)
 
static storage_for< RCP< const Infty > > NegInf_buf
 
RCP< const Infty > & NegInf = reinterpret_cast<RCP<const Infty > &>( NegInf_buf)
 
static storage_for< RCP< const Infty > > ComplexInf_buf
 
RCP< const Infty > & ComplexInf = reinterpret_cast<RCP<const Infty > &>( ComplexInf_buf)
 
static storage_for< RCP< const NaN > > Nan_buf
 
RCP< const NaN > & Nan = reinterpret_cast<RCP<const NaN > &>( Nan_buf)
 
static storage_for< RCP< const Basic > > i2_buf
 
RCP< const Basic > & i2 = reinterpret_cast<RCP<const Basic > &>( i2_buf)
 
static storage_for< RCP< const Basic > > i3_buf
 
RCP< const Basic > & i3 = reinterpret_cast<RCP<const Basic > &>( i3_buf)
 
static storage_for< RCP< const Basic > > i5_buf
 
RCP< const Basic > & i5 = reinterpret_cast<RCP<const Basic > &>( i5_buf)
 
static storage_for< RCP< const Basic > > im2_buf
 
RCP< const Basic > & im2 = reinterpret_cast<RCP<const Basic > &>( im2_buf)
 
static storage_for< RCP< const Basic > > im3_buf
 
RCP< const Basic > & im3 = reinterpret_cast<RCP<const Basic > &>( im3_buf)
 
static storage_for< RCP< const Basic > > im5_buf
 
RCP< const Basic > & im5 = reinterpret_cast<RCP<const Basic > &>( im5_buf)
 
static storage_for< RCP< const Basic > > sq3_buf
 
RCP< const Basic > & sq3 = reinterpret_cast<RCP<const Basic > &>( sq3_buf)
 
static storage_for< RCP< const Basic > > sq2_buf
 
RCP< const Basic > & sq2 = reinterpret_cast<RCP<const Basic > &>( sq2_buf)
 
static storage_for< RCP< const Basic > > sq5_buf
 
RCP< const Basic > & sq5 = reinterpret_cast<RCP<const Basic > &>( sq5_buf)
 
static storage_for< RCP< const Basic > > C0_buf
 
RCP< const Basic > & C0 = reinterpret_cast<RCP<const Basic > &>( C0_buf)
 
static storage_for< RCP< const Basic > > C1_buf
 
RCP< const Basic > & C1 = reinterpret_cast<RCP<const Basic > &>( C1_buf)
 
static storage_for< RCP< const Basic > > C2_buf
 
RCP< const Basic > & C2 = reinterpret_cast<RCP<const Basic > &>( C2_buf)
 
static storage_for< RCP< const Basic > > C3_buf
 
RCP< const Basic > & C3 = reinterpret_cast<RCP<const Basic > &>( C3_buf)
 
static storage_for< RCP< const Basic > > C4_buf
 
RCP< const Basic > & C4 = reinterpret_cast<RCP<const Basic > &>( C4_buf)
 
static storage_for< RCP< const Basic > > C5_buf
 
RCP< const Basic > & C5 = reinterpret_cast<RCP<const Basic > &>( C5_buf)
 
static storage_for< RCP< const Basic > > C6_buf
 
RCP< const Basic > & C6 = reinterpret_cast<RCP<const Basic > &>( C6_buf)
 
static storage_for< RCP< const Basic > > mC0_buf
 
RCP< const Basic > & mC0 = reinterpret_cast<RCP<const Basic > &>( mC0_buf)
 
static storage_for< RCP< const Basic > > mC1_buf
 
RCP< const Basic > & mC1 = reinterpret_cast<RCP<const Basic > &>( mC1_buf)
 
static storage_for< RCP< const Basic > > mC2_buf
 
RCP< const Basic > & mC2 = reinterpret_cast<RCP<const Basic > &>( mC2_buf)
 
static storage_for< RCP< const Basic > > mC3_buf
 
RCP< const Basic > & mC3 = reinterpret_cast<RCP<const Basic > &>( mC3_buf)
 
static storage_for< RCP< const Basic > > mC4_buf
 
RCP< const Basic > & mC4 = reinterpret_cast<RCP<const Basic > &>( mC4_buf)
 
static storage_for< RCP< const Basic > > mC5_buf
 
RCP< const Basic > & mC5 = reinterpret_cast<RCP<const Basic > &>( mC5_buf)
 
static storage_for< RCP< const Basic > > mC6_buf
 
RCP< const Basic > & mC6 = reinterpret_cast<RCP<const Basic > &>( mC6_buf)
 
static storage_for< RCP< const BooleanAtom > > boolTrue_buf
 
RCP< const BooleanAtom > & boolTrue = reinterpret_cast<RCP<const BooleanAtom > &>( boolTrue_buf)
 
static storage_for< RCP< const BooleanAtom > > boolFalse_buf
 
RCP< const BooleanAtom > & boolFalse = reinterpret_cast<RCP<const BooleanAtom > &>( boolFalse_buf)
 

Detailed Description

Main namespace for SymEngine package.

Enumeration Type Documentation

◆ TypeID

Enumerator
TypeID_Count 

The 'TypeID_Count' returns the number of elements in 'TypeID'. For this to work, do not assign numbers to the elements above (or if you do, you must assign the correct count below).

Definition at line 43 of file basic.h.

43  {
44 #define SYMENGINE_INCLUDE_ALL
45 #define SYMENGINE_ENUM(type, Class) type,
46 #include "symengine/type_codes.inc"
47 #undef SYMENGINE_ENUM
48 #undef SYMENGINE_INCLUDE_ALL
53 };
@ TypeID_Count
Definition: basic.h:52

Function Documentation

◆ add() [1/2]

RCP< const Basic > add ( const RCP< const Basic > &  a,
const RCP< const Basic > &  b 
)

Adds two objects (safely).

This implementation is slower than the methods of Add, however it is conceptually simpler and also safer, as it is more general and can perform canonicalization.

Note that:

x + y will return an Add. x + x will return Mul (2*x).

Parameters
ais a Basic object.
bis a Basic object.
Returns
a+b in its most aproriate form.

Definition at line 425 of file add.cpp.

426 {
428  RCP<const Number> coef;
429  RCP<const Basic> t;
430  if (is_a<Add>(*a) and is_a<Add>(*b)) {
431  coef = (down_cast<const Add &>(*a)).get_coef();
432  d = (down_cast<const Add &>(*a)).get_dict();
433  for (const auto &p : (down_cast<const Add &>(*b)).get_dict())
434  Add::dict_add_term(d, p.second, p.first);
435  iaddnum(outArg(coef), down_cast<const Add &>(*b).get_coef());
436  } else if (is_a<Add>(*a)) {
437  coef = (down_cast<const Add &>(*a)).get_coef();
438  d = (down_cast<const Add &>(*a)).get_dict();
439  if (is_a_Number(*b)) {
440  if (not down_cast<const Number &>(*b).is_zero()) {
441  iaddnum(outArg(coef), rcp_static_cast<const Number>(b));
442  }
443  } else {
444  RCP<const Number> coef2;
445  Add::as_coef_term(b, outArg(coef2), outArg(t));
446  Add::dict_add_term(d, coef2, t);
447  }
448  } else if (is_a<Add>(*b)) {
449  coef = (down_cast<const Add &>(*b)).get_coef();
450  d = (down_cast<const Add &>(*b)).get_dict();
451  if (is_a_Number(*a)) {
452  if (not down_cast<const Number &>(*a).is_zero()) {
453  iaddnum(outArg(coef), rcp_static_cast<const Number>(a));
454  }
455  } else {
456  RCP<const Number> coef2;
457  Add::as_coef_term(a, outArg(coef2), outArg(t));
458  Add::dict_add_term(d, coef2, t);
459  }
460  } else {
461  Add::as_coef_term(a, outArg(coef), outArg(t));
462  Add::dict_add_term(d, coef, t);
463  Add::as_coef_term(b, outArg(coef), outArg(t));
464  Add::dict_add_term(d, coef, t);
465  auto it = d.find(one);
466  if (it == d.end()) {
467  coef = zero;
468  } else {
469  coef = it->second;
470  d.erase(it);
471  }
472  return Add::from_dict(coef, std::move(d));
473  }
474  return Add::from_dict(coef, std::move(d));
475 }
T end(T... args)
T erase(T... args)
T find(T... args)
T move(T... args)
bool is_a_Number(const Basic &b)
Definition: number.h:130

◆ add() [2/2]

RCP< const Basic > add ( const vec_basic a)

Sums the elements of a vector.

This should be faster for n elements compared to performing n-1 additions.

Parameters
ais a vector.
Returns
sum of elements of the input vector a.

Definition at line 481 of file add.cpp.

482 {
484  RCP<const Number> coef = zero;
485  for (const auto &i : a) {
486  Add::coef_dict_add_term(outArg(coef), d, one, i);
487  }
488  return Add::from_dict(coef, std::move(d));
489 }

◆ bernoulli()

RCP< const Number > SymEngine::bernoulli ( unsigned long  n)

Computes the Bernoulli number Bn as an exact fraction, for an isolated integer n

Definition at line 496 of file ntheory.cpp.

497 {
498 #ifdef HAVE_SYMENGINE_ARB
499  fmpq_t res;
500  fmpq_init(res);
501  bernoulli_fmpq_ui(res, n);
502  mpq_t a;
503  mpq_init(a);
504  fmpq_get_mpq(a, res);
505  rational_class b(a);
506  fmpq_clear(res);
507  mpq_clear(a);
508  return Rational::from_mpq(std::move(b));
509 #else
510  // TODO: implement a faster algorithm
512  for (unsigned m = 0; m <= n; ++m) {
513  v[m] = rational_class(1u, m + 1);
514 
515  for (unsigned j = m; j >= 1; --j) {
516  v[j - 1] = j * (v[j - 1] - v[j]);
517  }
518  }
519  return Rational::from_mpq(v[0]);
520 #endif
521 }

◆ cbrt()

RCP< const Basic > SymEngine::cbrt ( const RCP< const Basic > &  x)
inline
Returns
cbrt of the arg
cube root of x

Definition at line 66 of file pow.h.

67 {
68  return pow(x, div(one, integer(3)));
69 }
T div(T... args)
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
Definition: integer.h:197
T pow(T... args)

◆ complexes()

RCP<const Complexes> SymEngine::complexes ( )
inline
Returns
RCP<const Complexes>

Definition at line 554 of file sets.h.

555 {
556  return Complexes::getInstance();
557 }

◆ conditionset()

RCP< const Set > SymEngine::conditionset ( const RCP< const Basic > &  sym,
const RCP< const Boolean > &  condition 
)
Returns
RCP<const Set>

Definition at line 1781 of file sets.cpp.

1783 {
1784  if (eq(*condition, *boolean(false))) {
1785  return emptyset();
1786  } else if (eq(*condition, *boolean(true))) {
1787  return universalset();
1788  }
1789  if (is_a<And>(*condition)) {
1790  auto cont = down_cast<const And &>(*condition).get_container();
1791  set_boolean newcont;
1792  set_basic present, others;
1793  for (auto it = cont.begin(); it != cont.end(); it++) {
1794  if (is_a<Contains>(**it)
1795  and eq(*down_cast<const Contains &>(**it).get_expr(), *sym)
1796  and is_a<FiniteSet>(
1797  *down_cast<const Contains &>(**it).get_set())) {
1798  auto fset = down_cast<const Contains &>(**it).get_set();
1799  auto fcont
1800  = down_cast<const FiniteSet &>(*fset).get_container();
1801  // use the result of simplification done in `logical_and()`
1802  for (const auto &elem : fcont) {
1803  if (not(is_a_Number(*elem) or is_a<Constant>(*elem))) {
1804  others.insert(elem);
1805  } else {
1806  // logical_and() doesn't guarantee that if element of a
1807  // finiteset is a number, then it satisfies other
1808  // conditions
1809  // it only assures that there doesn't exist any such
1810  // element of finiteset that surely fails in other
1811  // conditions.
1812  auto restCont = cont;
1813  restCont.erase(*it);
1814  auto restCond = logical_and(restCont);
1815  map_basic_basic d;
1816  d[sym] = elem;
1817  auto contain = restCond->subs(d);
1818  if (eq(*contain, *boolean(true))) {
1819  present.insert(elem);
1820  } else if (not eq(*contain, *boolean(false))) {
1821  others.insert(elem);
1822  } else {
1823  throw SymEngineException("element should have "
1824  "been removed within "
1825  "logical_and()");
1826  }
1827  }
1828  }
1829  } else {
1830  newcont.insert(*it);
1831  }
1832  }
1833  if (not present.empty()) {
1834  newcont.insert(finiteset(others)->contains(sym));
1835  return SymEngine::set_union(
1836  {finiteset(present), conditionset(sym, logical_and(newcont))});
1837  }
1838  }
1839  if (is_a<Contains>(*condition)) {
1840  return down_cast<const Contains &>(*condition).get_set();
1841  }
1842  return make_rcp<const ConditionSet>(sym, condition);
1843 }
T insert(T... args)
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21
RCP< const EmptySet > emptyset()
Definition: sets.h:590
RCP< const UniversalSet > universalset()
Definition: sets.h:596
RCP< const Set > conditionset(const RCP< const Basic > &sym, const RCP< const Boolean > &condition)
Definition: sets.cpp:1781
RCP< const Set > finiteset(const set_basic &container)
Definition: sets.h:602

◆ could_extract_minus()

bool SymEngine::could_extract_minus ( const Basic arg)
Returns
true if arg contains a negative sign.

Definition at line 325 of file functions.cpp.

326 {
327  if (is_a_Number(arg)) {
328  if (down_cast<const Number &>(arg).is_negative()) {
329  return true;
330  } else if (is_a_Complex(arg)) {
331  const ComplexBase &c = down_cast<const ComplexBase &>(arg);
332  RCP<const Number> real_part = c.real_part();
333  return (real_part->is_negative())
334  or (eq(*real_part, *zero)
335  and c.imaginary_part()->is_negative());
336  } else {
337  return false;
338  }
339  } else if (is_a<Mul>(arg)) {
340  const Mul &s = down_cast<const Mul &>(arg);
341  return could_extract_minus(*s.get_coef());
342  } else if (is_a<Add>(arg)) {
343  const Add &s = down_cast<const Add &>(arg);
344  if (s.get_coef()->is_zero()) {
345  map_basic_num d(s.get_dict().begin(), s.get_dict().end());
346  return could_extract_minus(*d.begin()->second);
347  } else {
348  return could_extract_minus(*s.get_coef());
349  }
350  } else {
351  return false;
352  }
353 }
bool could_extract_minus(const Basic &arg)
Definition: functions.cpp:325
bool is_a_Complex(const Basic &b)
Definition: complex.h:24

◆ divides()

bool SymEngine::divides ( const Integer a,
const Integer b 
)
Returns
true if b divides a

Definition at line 162 of file ntheory.cpp.

163 {
164  return mp_divisible_p(a.as_integer_class(), b.as_integer_class()) != 0;
165 }

◆ emptyset()

RCP<const EmptySet> SymEngine::emptyset ( )
inline
Returns
RCP<const EmptySet>

Definition at line 590 of file sets.h.

591 {
592  return EmptySet::getInstance();
593 }

◆ eq()

bool SymEngine::eq ( const Basic a,
const Basic b 
)
inline

Checks equality for a and b

Returns
true if a equal b

Definition at line 21 of file basic-inl.h.

22 {
23  if (&a == &b) {
24  return true;
25  }
26  return a.__eq__(b);
27 }

◆ factor()

int SymEngine::factor ( const Ptr< RCP< const Integer >> &  f,
const Integer n,
double  B1 = 1.0 
)

Factorization

Parameters
B1is only used when n is factored using gmp-ecm

Definition at line 371 of file ntheory.cpp.

372 {
373  int ret_val = 0;
374  integer_class _n, _f;
375 
376  _n = n.as_integer_class();
377 
378 #ifdef HAVE_SYMENGINE_ECM
379  if (mp_perfect_power_p(_n)) {
380 
381  unsigned long int i = 1;
382  integer_class m, rem;
383  rem = 1; // Any non zero number
384  m = 2; // set `m` to 2**i, i = 1 at the begining
385 
386  // calculate log2n, this can be improved
387  for (; m < _n; ++i)
388  m = m * 2;
389 
390  // eventually `rem` = 0 zero as `n` is a perfect power. `f_t` will
391  // be set to a factor of `n` when that happens
392  while (i > 1 and rem != 0) {
393  mp_rootrem(_f, rem, _n, i);
394  --i;
395  }
396 
397  ret_val = 1;
398  } else {
399 
400  if (mp_probab_prime_p(_n, 25) > 0) { // most probably, n is a prime
401  ret_val = 0;
402  _f = _n;
403  } else {
404 
405  for (int i = 0; i < 10 and not ret_val; ++i)
406  ret_val = ecm_factor(get_mpz_t(_f), get_mpz_t(_n), B1, nullptr);
407  mp_demote(_f);
408  if (not ret_val)
409  throw SymEngineException(
410  "ECM failed to factor the given number");
411  }
412  }
413 #else
414  // B1 is discarded if gmp-ecm is not installed
415  ret_val = _factor_trial_division_sieve(_f, _n);
416 #endif // HAVE_SYMENGINE_ECM
417  *f = integer(std::move(_f));
418 
419  return ret_val;
420 }

◆ factor_trial_division()

int SymEngine::factor_trial_division ( const Ptr< RCP< const Integer >> &  f,
const Integer n 
)

Factor using trial division.

Returns
1 if a non-trivial factor is found, otherwise 0.

Definition at line 422 of file ntheory.cpp.

423 {
424  int ret_val;
425  integer_class factor;
426  ret_val = _factor_trial_division_sieve(factor, n.as_integer_class());
427  if (ret_val == 1)
428  *f = integer(std::move(factor));
429  return ret_val;
430 }
int factor(const Ptr< RCP< const Integer >> &f, const Integer &n, double B1)
Definition: ntheory.cpp:371

◆ finiteset()

RCP<const Set> SymEngine::finiteset ( const set_basic container)
inline
Returns
RCP<const Set>

Definition at line 602 of file sets.h.

603 {
604  if (FiniteSet::is_canonical(container)) {
605  return make_rcp<const FiniteSet>(container);
606  }
607  return emptyset();
608 }

◆ get_pi_shift()

bool SymEngine::get_pi_shift ( const RCP< const Basic > &  arg,
const Ptr< RCP< const Number >> &  n,
const Ptr< RCP< const Basic >> &  m 
)
Returns
true if arg is of form m + n*pi where n is a rational

Definition at line 203 of file functions.cpp.

205 {
206  if (is_a<Add>(*arg)) {
207  const Add &s = down_cast<const Add &>(*arg);
208  RCP<const Basic> coef = s.get_coef();
209  auto size = s.get_dict().size();
210  if (size > 1) {
211  // arg should be of form `x + n*pi`
212  // `n` is an integer
213  // `x` is an `Expression`
214  bool check_pi = false;
215  RCP<const Basic> temp;
216  *x = coef;
217  for (const auto &p : s.get_dict()) {
218  if (eq(*p.first, *pi)
219  and (is_a<Integer>(*p.second)
220  or is_a<Rational>(*p.second))) {
221  check_pi = true;
222  *n = p.second;
223  } else {
224  *x = add(mul(p.first, p.second), *x);
225  }
226  }
227  if (check_pi)
228  return true;
229  else // No term with `pi` found
230  return false;
231  } else if (size == 1) {
232  // arg should be of form `a + n*pi`
233  // where `a` is a `Number`.
234  auto p = s.get_dict().begin();
235  if (eq(*p->first, *pi)
236  and (is_a<Integer>(*p->second) or is_a<Rational>(*p->second))) {
237  *n = p->second;
238  *x = coef;
239  return true;
240  } else {
241  return false;
242  }
243  } else { // Should never reach here though!
244  // Dict of size < 1
245  return false;
246  }
247  } else if (is_a<Mul>(*arg)) {
248  // `arg` is of the form `k*pi/12`
249  const Mul &s = down_cast<const Mul &>(*arg);
250  auto p = s.get_dict().begin();
251  // dict should contain symbol `pi` only
252  if (s.get_dict().size() == 1 and eq(*p->first, *pi)
253  and eq(*p->second, *one)
254  and (is_a<Integer>(*s.get_coef())
255  or is_a<Rational>(*s.get_coef()))) {
256  *n = s.get_coef();
257  *x = zero;
258  return true;
259  } else {
260  return false;
261  }
262  } else if (eq(*arg, *pi)) {
263  *n = one;
264  *x = zero;
265  return true;
266  } else if (eq(*arg, *zero)) {
267  *n = zero;
268  *x = zero;
269  return true;
270  } else {
271  return false;
272  }
273 }
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
Definition: add.cpp:425
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
Definition: mul.cpp:352

◆ hash_combine()

template<class T >
void SymEngine::hash_combine ( hash_t &  seed,
const T &  v 
)
inline

Standard hash_combine() function. Example of usage:

hash_t seed1 = 0;
hash_combine<std::string>(seed1, "x");
hash_combine<std::string>(seed1, "y");

You can use it with any SymEngine class:

RCP<const Symbol> x = symbol("x");
RCP<const Symbol> y = symbol("y");
hash_t seed2 = 0;
hash_combine<Basic>(seed2, *x);
hash_combine<Basic>(seed2, *y);

Definition at line 95 of file basic-inl.h.

96 {
97  hash_combine_impl(seed, v);
98 }
void hash_combine_impl(hash_t &seed, const T &v, typename std::enable_if< std::is_base_of< Basic, T >::value >::type *=nullptr)
Templatised version to combine hash.
Definition: basic-inl.h:61

◆ insert()

template<typename T1 , typename T2 , typename T3 >
void SymEngine::insert ( T1 &  m,
const T2 &  first,
const T3 &  second 
)
inline

insert(m, first, second) is equivalent to m[first] = second, just faster, because no default constructor is called on the second type.

Definition at line 83 of file dict.h.

84 {
85  m.insert(std::pair<T2, T3>(first, second));
86 }

◆ integer() [1/2]

RCP<const Integer> SymEngine::integer ( integer_class  i)
inline
Returns
RCP<const Integer> from integer_class

Definition at line 203 of file integer.h.

204 {
205  return make_rcp<const Integer>(std::move(i));
206 }

◆ integer() [2/2]

template<typename T >
std::enable_if<std::is_integral<T>::value, RCP<const Integer> >::type SymEngine::integer ( i)
inline
Returns
RCP<const Integer> from integral values

Definition at line 197 of file integer.h.

198 {
199  return make_rcp<const Integer>(integer_class(i));
200 }

◆ integers()

RCP<const Integers> SymEngine::integers ( )
inline
Returns
RCP<const Integers>

Definition at line 572 of file sets.h.

573 {
574  return Integers::getInstance();
575 }

◆ interval()

RCP<const Set> SymEngine::interval ( const RCP< const Number > &  start,
const RCP< const Number > &  end,
const bool  left_open = false,
const bool  right_open = false 
)
inline
Returns
RCP<const Set>

Definition at line 611 of file sets.h.

615 {
616  if (Interval::is_canonical(start, end, left_open, right_open))
617  return make_rcp<const Interval>(start, end, left_open, right_open);
618  if (eq(*start, *end) and not(left_open or right_open))
619  return finiteset({start});
620  return emptyset();
621 }

◆ inverse_lookup()

bool SymEngine::inverse_lookup ( const umap_basic_basic d,
const RCP< const Basic > &  t,
const Ptr< RCP< const Basic >> &  index 
)

returns true if the given argument t is found in the lookup table d. It also returns the value in index

Definition at line 480 of file functions.cpp.

482 {
483  auto it = d.find(t);
484  if (it == d.end()) {
485  // Not found in lookup
486  return false;
487  } else {
488  *index = (it->second);
489  return true;
490  }
491 }

◆ is_a()

template<class T >
bool SymEngine::is_a ( const Basic b)
inline

Templatised version to check is_a type.

Returns true if b is exactly of type T. Example: is_a<Symbol>(b) : true if "b" is of type Symbol

Definition at line 36 of file basic-inl.h.

37 {
38  return T::type_code_id == b.get_type_code();
39 }

◆ is_a_Complex()

bool SymEngine::is_a_Complex ( const Basic b)
inline
Returns
true if 'b' is any of the subclasses of ComplexBase

Definition at line 24 of file complex.h.

25 {
26  return (b.get_type_code() == SYMENGINE_COMPLEX
27  || b.get_type_code() == SYMENGINE_COMPLEX_MPC
28  || b.get_type_code() == SYMENGINE_COMPLEX_DOUBLE);
29 }

◆ is_a_Number()

bool SymEngine::is_a_Number ( const Basic b)
inline
Returns
true if 'b' is a Number or any of its subclasses

Definition at line 130 of file number.h.

131 {
132  // `NumberWraper` is the last subclass of Number in TypeID
133  // An enum should be before `SYMENIGNE_NUMBER_WRAPPER` iff it is a
134  // subclass of Number
135  return b.get_type_code() <= SYMENGINE_NUMBER_WRAPPER;
136 }

◆ is_a_sub()

template<class T >
bool SymEngine::is_a_sub ( const Basic b)
inline

Returns true if b is of type T or any of its subclasses. Example:

 is_a_sub<Symbol>(b)  // true if `b` is of type `Symbol` or any Symbol's

subclass

Definition at line 42 of file basic-inl.h.

43 {
44  return dynamic_cast<const T *>(&b) != nullptr;
45 }

◆ is_nonzero()

tribool SymEngine::is_nonzero ( const Basic b,
const Assumptions assumptions = nullptr 
)

Check if a number is non-zero.

Parameters
bBasic
assumptionsAssumptions
Returns
tribool

Check if b is non-zero. If b is not numeric an exception will be thrown.

Definition at line 88 of file test_visitors.cpp.

89 {
90  ZeroVisitor visitor(assumptions);
91  return not_tribool(visitor.apply(b));
92 }

◆ is_number_and_zero()

bool SymEngine::is_number_and_zero ( const Basic b)
inline
Returns
true if 'b' is a Number and is zero

Definition at line 139 of file number.h.

140 {
141  return is_a_Number(b) and down_cast<const Number &>(b).is_zero();
142 }

◆ is_polynomial()

bool SymEngine::is_polynomial ( const Basic b,
const set_basic variables = {} 
)

Check if expression is a polynomial.

Parameters
bBasic
variablesSet of symbols for variables in polynomial
Returns
True if b is a polynomial in variables and false otherwise

Check if b is a polynomial in variables. If no variables are specified all free symbols in b are considered to be variables. All symbols that are not variables will be considered to be constants.

Definition at line 812 of file test_visitors.cpp.

813 {
814  PolynomialVisitor visitor(variables);
815  return visitor.apply(b);
816 }

◆ is_zero()

tribool SymEngine::is_zero ( const Basic b,
const Assumptions assumptions = nullptr 
)

Check if a number is zero.

Parameters
bBasic
assumptionsAssumptions
Returns
tribool

Check if b is zero. If b is not numeric an exception will be thrown.

Definition at line 82 of file test_visitors.cpp.

83 {
84  ZeroVisitor visitor(assumptions);
85  return visitor.apply(b);
86 }

◆ log()

RCP< const Basic > SymEngine::log ( const RCP< const Basic > &  arg,
const RCP< const Basic > &  b 
)
Returns
Log from argument arg wrt base b

Definition at line 1817 of file functions.cpp.

1818 {
1819  return div(log(arg), log(base));
1820 }
T log(T... args)

◆ mp_perfect_power_decomposition()

std::pair< integer_class, integer_class > SymEngine::mp_perfect_power_decomposition ( const integer_class &  n,
bool  lowest_exponent = false 
)

Decompose a positive integer into perfect powers.

Parameters
nInteger to decompose
lowest_exponentCan be set to find the perfect power with the lowest exponent. Default is to find the highest exponent.
Returns
The base and exponent as a pair of integers. (n, 1) if no perfect power exists.

See https://en.wikipedia.org/wiki/Perfect_power

Definition at line 1677 of file ntheory.cpp.

1678 {
1679  // From
1680  // https://codegolf.stackexchange.com/questions/1935/fastest-algorithm-for-decomposing-a-perfect-power
1681  unsigned long p = 2;
1682  integer_class intone, i, j, m, res;
1683  intone = 1;
1685  respair = std::make_pair(n, intone);
1686 
1687  while ((intone << p) <= n) {
1688  i = 2;
1689  j = n;
1690  while (j > i + 1) {
1691  m = (i + j) / 2;
1692  mp_pow_ui(res, m, p);
1693  if (res > n)
1694  j = m;
1695  else
1696  i = m;
1697  }
1698  mp_pow_ui(res, i, p);
1699  if (res == n) {
1700  respair = std::make_pair(i, p);
1701  if (lowest_exponent) {
1702  return respair;
1703  }
1704  }
1705  p++;
1706  }
1707  return respair;
1708 }
T make_pair(T... args)

◆ mp_polygonal_number()

integer_class SymEngine::mp_polygonal_number ( const integer_class &  s,
const integer_class &  n 
)

Numeric calculation of the n:th s-gonal number.

Parameters
sNumber of sides of the polygon. Must be greater than 2.
nMust be greater than 0
Returns
The n:th s-gonal number

A fast pure numeric calculation of the n:th s-gonal number. No bounds checking of the input is performed. See https://en.wikipedia.org/wiki/Polygonal_number for source of formula.

Definition at line 1649 of file ntheory.cpp.

1651 {
1652  auto res = ((s - 2) * n * n - (s - 4) * n) / 2;
1653  return res;
1654 }

◆ mp_principal_polygonal_root()

integer_class SymEngine::mp_principal_polygonal_root ( const integer_class &  s,
const integer_class &  x 
)

Numeric calculation of the principal s-gonal root of x.

Parameters
sNumber of sides of the polygon. Must be greater than 2.
xAn integer greater than 0
Returns
The root

A fast pure numeric calculation of the principal (i.e. positive) s-gonal root of x. No bounds checking of the input is performed. See https://en.wikipedia.org/wiki/Polygonal_number for source of formula.

Definition at line 1666 of file ntheory.cpp.

1668 {
1669  integer_class tmp;
1670  mp_pow_ui(tmp, s - 4, 2);
1671  integer_class root = mp_sqrt(8 * x * (s - 2) + tmp);
1672  integer_class n = (root + s - 4) / (2 * (s - 2));
1673  return n;
1674 }

◆ naturals()

RCP<const Naturals> SymEngine::naturals ( )
inline
Returns
RCP<const Naturals>

Definition at line 578 of file sets.h.

579 {
580  return Naturals::getInstance();
581 }

◆ naturals0()

RCP<const Naturals0> SymEngine::naturals0 ( )
inline
Returns
RCP<const Naturals>

Definition at line 584 of file sets.h.

585 {
586  return Naturals0::getInstance();
587 }

◆ neq()

bool SymEngine::neq ( const Basic a,
const Basic b 
)
inline

Checks inequality for a and b

Returns
true if a not equal b

Definition at line 29 of file basic-inl.h.

30 {
31  return not(a.__eq__(b));
32 }

◆ nextprime()

RCP< const Integer > SymEngine::nextprime ( const Integer a)
Returns
next prime after a

Definition at line 173 of file ntheory.cpp.

174 {
175  integer_class c;
176  mp_nextprime(c, a.as_integer_class());
177  return integer(std::move(c));
178 }

◆ operator<<()

std::ostream & SymEngine::operator<< ( std::ostream out,
const SymEngine::Basic p 
)
inline

<< Operator

This << overloaded function simply calls p.__str__, so it allows any Basic type to be printed.

This prints using: std::cout << *x;

Definition at line 53 of file basic-inl.h.

54 {
55  out << p.__str__();
56  return out;
57 }
std::string __str__() const
Definition: basic.cpp:46

◆ polygonal_number()

RCP< const Basic > SymEngine::polygonal_number ( const RCP< const Basic > &  s,
const RCP< const Basic > &  n 
)

The n:th s-gonal number.

n:th s-gonal number

Parameters
sNumber of sides of the polygon. Must be greater than 2
nMust be greater than 0
Returns
The n:th s-gonal number

Symbolic calculation of the n:th s-gonal number.

Parameters
sNumber of sides of the polygon. Must be greater than 2.
nMust be greater than 0
Returns
The n:th s-gonal number

Symbolic calculation of the n:th s-gonal number. Sources: https://en.wikipedia.org/wiki/Polygonal_number https://reference.wolfram.com/language/ref/PolygonalNumber.html

Definition at line 110 of file ntheory_funcs.cpp.

112 {
113  if (is_a_Number(*s)) {
114  if (not is_a<Integer>(*s)
115  or not down_cast<const Integer &>(*sub(s, integer(2)))
116  .is_positive()) {
117  throw DomainError("The number of sides of the polygon must be an "
118  "integer greater than 2");
119  }
120  }
121  if (is_a_Number(*n)) {
122  if (not is_a<Integer>(*n)
123  or not down_cast<const Integer &>(*n).is_positive()) {
124  throw DomainError("n must be an integer greater than 0");
125  }
126  }
127 
128  if (is_a_Number(*s) and is_a_Number(*n)) {
129  // Optimized numeric calculation
130  auto s_int = down_cast<const Integer &>(*s).as_integer_class();
131  auto n_int = down_cast<const Integer &>(*n).as_integer_class();
132  auto res = mp_polygonal_number(s_int, n_int);
133  return make_rcp<const Integer>(res);
134  }
135 
136  RCP<const Integer> m1 = integer(-1);
137  RCP<const Integer> m2 = integer(-2);
138  RCP<const Integer> p2 = integer(2);
139  RCP<const Integer> p4 = integer(4);
140  RCP<const Basic> x = div(
141  add(mul(add(s, m2), pow(n, p2)), mul(add(p4, mul(m1, s)), n)), p2);
142  return x;
143 }
RCP< const Basic > sub(const RCP< const Basic > &a, const RCP< const Basic > &b)
Substracts b from a.
Definition: add.cpp:495
integer_class mp_polygonal_number(const integer_class &s, const integer_class &n)
Numeric calculation of the n:th s-gonal number.
Definition: ntheory.cpp:1649

◆ pow()

RCP< const Basic > SymEngine::pow ( const RCP< const Basic > &  a,
const RCP< const Basic > &  b 
)
Returns
Pow from a and b

Definition at line 92 of file pow.cpp.

93 {
94  if (is_number_and_zero(*b)) {
95  // addnum is used for converting to the type of `b`.
96  return addnum(one, rcp_static_cast<const Number>(b));
97  }
98  if (eq(*b, *one))
99  return a;
100 
101  if (eq(*a, *zero)) {
102  if (is_a_Number(*b)
103  and rcp_static_cast<const Number>(b)->is_positive()) {
104  return zero;
105  } else if (is_a_Number(*b)
106  and rcp_static_cast<const Number>(b)->is_negative()) {
107  return ComplexInf;
108  } else {
109  return make_rcp<const Pow>(a, b);
110  }
111  }
112 
113  if (eq(*a, *one) and not is_a_Number(*b))
114  return one;
115  if (eq(*a, *minus_one)) {
116  if (is_a<Integer>(*b)) {
117  return is_a<Integer>(*div(b, integer(2))) ? one : minus_one;
118  } else if (is_a<Rational>(*b) and eq(*b, *rational(1, 2))) {
119  return I;
120  }
121  }
122 
123  if (is_a_Number(*b)) {
124  if (is_a_Number(*a)) {
125  if (is_a<Integer>(*b)) {
126  return down_cast<const Number &>(*a).pow(
127  *rcp_static_cast<const Number>(b));
128  } else if (is_a<Rational>(*b)) {
129  if (is_a<Rational>(*a)) {
130  return down_cast<const Rational &>(*a).powrat(
131  down_cast<const Rational &>(*b));
132  } else if (is_a<Integer>(*a)) {
133  return down_cast<const Rational &>(*b).rpowrat(
134  down_cast<const Integer &>(*a));
135  } else if (is_a<Complex>(*a)) {
136  return make_rcp<const Pow>(a, b);
137  } else {
138  return down_cast<const Number &>(*a).pow(
139  *rcp_static_cast<const Number>(b));
140  }
141  } else if (is_a<Complex>(*b)
142  and down_cast<const Number &>(*a).is_exact()) {
143  return make_rcp<const Pow>(a, b);
144  } else {
145  return down_cast<const Number &>(*a).pow(
146  *rcp_static_cast<const Number>(b));
147  }
148  } else if (eq(*a, *E)) {
149  RCP<const Number> p = rcp_static_cast<const Number>(b);
150  if (not p->is_exact()) {
151  // Evaluate E**0.2, but not E**2
152  return p->get_eval().exp(*p);
153  }
154  } else if (is_a<Mul>(*a)) {
155  // Expand (x*y)**b = x**b*y**b
156  map_basic_basic d;
157  RCP<const Number> coef = one;
158  down_cast<const Mul &>(*a).power_num(
159  outArg(coef), d, rcp_static_cast<const Number>(b));
160  return Mul::from_dict(coef, std::move(d));
161  }
162  }
163  if (is_a<Pow>(*a) and is_a<Integer>(*b)) {
164  // Convert (x**y)**b = x**(b*y), where 'b' is an integer. This holds for
165  // any complex 'x', 'y' and integer 'b'.
166  RCP<const Pow> A = rcp_static_cast<const Pow>(a);
167  return pow(A->get_base(), mul(A->get_exp(), b));
168  }
169  if (is_a<Pow>(*a)
170  and eq(*down_cast<const Pow &>(*a).get_exp(), *minus_one)) {
171  // Convert (x**-1)**b = x**(-b)
172  RCP<const Pow> A = rcp_static_cast<const Pow>(a);
173  return pow(A->get_base(), neg(b));
174  }
175  return make_rcp<const Pow>(a, b);
176 }
bool is_number_and_zero(const Basic &b)
Definition: number.h:139
RCP< const Number > rational(long n, long d)
convenience creator from two longs
Definition: rational.h:328
RCP< const Number > addnum(const RCP< const Number > &self, const RCP< const Number > &other)
Add self and other
Definition: number.h:81
RCP< const Basic > neg(const RCP< const Basic > &a)
Negation.
Definition: mul.cpp:443

◆ powermod()

bool SymEngine::powermod ( const Ptr< RCP< const Integer >> &  powm,
const RCP< const Integer > &  a,
const RCP< const Number > &  b,
const RCP< const Integer > &  m 
)

A solution to x**s == a**r mod m where b = r / s. Return false if none exists.

Definition at line 1434 of file ntheory.cpp.

1436 {
1437  if (is_a<Integer>(*b)) {
1438  integer_class t = down_cast<const Integer &>(*b).as_integer_class();
1439  if (b->is_negative())
1440  t *= -1;
1441  mp_powm(t, a->as_integer_class(), t, m->as_integer_class());
1442  if (b->is_negative()) {
1443  bool ret_val = mp_invert(t, t, m->as_integer_class());
1444  if (not ret_val)
1445  return false;
1446  }
1447  *powm = integer(std::move(t));
1448  return true;
1449  } else if (is_a<Rational>(*b)) {
1450  RCP<const Integer> num, den, r;
1451  get_num_den(down_cast<const Rational &>(*b), outArg(num), outArg(den));
1452  if (den->is_negative()) {
1453  den = den->mulint(*minus_one);
1454  num = num->mulint(*minus_one);
1455  }
1456  integer_class t = mp_abs(num->as_integer_class());
1457  mp_powm(t, a->as_integer_class(), t, m->as_integer_class());
1458  if (num->is_negative()) {
1459  bool ret_val = mp_invert(t, t, m->as_integer_class());
1460  if (not ret_val)
1461  return false;
1462  }
1463  r = integer(std::move(t));
1464  return nthroot_mod(powm, r, den, m);
1465  }
1466  return false;
1467 }
void get_num_den(const Rational &rat, const Ptr< RCP< const Integer >> &num, const Ptr< RCP< const Integer >> &den)
returns the num and den of rational rat as RCP<const Integer>
Definition: rational.cpp:130
bool nthroot_mod(const Ptr< RCP< const Integer >> &root, const RCP< const Integer > &a, const RCP< const Integer > &n, const RCP< const Integer > &mod)
A solution to x**n == a mod m. Return false if none exists.
Definition: ntheory.cpp:1372

◆ powermod_list()

void SymEngine::powermod_list ( std::vector< RCP< const Integer >> &  pows,
const RCP< const Integer > &  a,
const RCP< const Number > &  b,
const RCP< const Integer > &  m 
)

All solutions to x**s == a**r mod m where b = r / s. Return false if none exists.

Definition at line 1469 of file ntheory.cpp.

1472 {
1473  if (is_a<Integer>(*b)) {
1474  integer_class t
1475  = mp_abs(down_cast<const Integer &>(*b).as_integer_class());
1476  mp_powm(t, a->as_integer_class(), t, m->as_integer_class());
1477  if (b->is_negative()) {
1478  bool ret_val = mp_invert(t, t, m->as_integer_class());
1479  if (not ret_val)
1480  return;
1481  }
1482  pows.push_back(integer(std::move(t)));
1483  } else if (is_a<Rational>(*b)) {
1484  RCP<const Integer> num, den, r;
1485  get_num_den(down_cast<const Rational &>(*b), outArg(num), outArg(den));
1486  if (den->is_negative()) {
1487  den = den->mulint(*integer(-1));
1488  num = num->mulint(*integer(-1));
1489  }
1490  integer_class t = num->as_integer_class();
1491  if (num->is_negative())
1492  t *= -1;
1493  mp_powm(t, a->as_integer_class(), t, m->as_integer_class());
1494  if (num->is_negative()) {
1495  bool ret_val = mp_invert(t, t, m->as_integer_class());
1496  if (not ret_val)
1497  return;
1498  }
1499  r = integer(t);
1500  nthroot_mod_list(pows, r, den, m);
1501  }
1502 }
void nthroot_mod_list(std::vector< RCP< const Integer >> &roots, const RCP< const Integer > &a, const RCP< const Integer > &n, const RCP< const Integer > &m)
All Solutions to x**n == a mod m. Return false if none exists.
Definition: ntheory.cpp:1402
T push_back(T... args)

◆ primitive_root_list()

void SymEngine::primitive_root_list ( std::vector< RCP< const Integer >> &  roots,
const Integer n 
)

Computes all primitive roots less than n. Returns false if no primitive root exists.

Definition at line 765 of file ntheory.cpp.

767 {
768  integer_class _n = n.as_integer_class();
769  if (_n < 0)
770  _n = -_n;
771  if (_n <= 1)
772  return;
773  if (_n < 5) {
774  roots.push_back(integer(_n - 1));
775  return;
776  }
777  bool even = false;
778  if (_n % 2 == 0) {
779  if (_n % 4 == 0) {
780  return; // If n%4 == 0 and n > 4, then no primitive roots.
781  }
782  _n /= 2;
783  even = true;
784  }
785  integer_class p, e;
786  if (not _prime_power(p, e, _n))
787  return;
788  _primitive_root_list(roots, p, e, even);
789  std::sort(roots.begin(), roots.end(), SymEngine::RCPIntegerKeyLess());
790  return;
791 }
T begin(T... args)
T sort(T... args)
less operator (<) for Integers
Definition: integer.h:185

◆ principal_polygonal_root()

RCP< const Basic > SymEngine::principal_polygonal_root ( const RCP< const Basic > &  s,
const RCP< const Basic > &  x 
)

The principal s-gonal root of x.

Principal s-gonal root of x.

Parameters
sNumber of sides of the polygon. Must be greater than 2
nMust be greater than 0
Returns
The n:th s-gonal number

Symbolic calculation of the principal (i.e. positive) s-gonal root of x.

Parameters
sNumber of sides of the polygon. Must be greater than 2.
xAn integer greater than 0
Returns
The root

Symbolic calculation of the principal (i.e. positive) s-gonal root of x. References https://en.wikipedia.org/wiki/Polygonal_number http://oeis.org/wiki/Polygonal_numbers#Polygonal_roots

Definition at line 153 of file ntheory_funcs.cpp.

155 {
156  if (is_a_Number(*s)) {
157  if (not is_a<Integer>(*s)
158  or not down_cast<const Integer &>(*sub(s, integer(2)))
159  .is_positive()) {
160  throw DomainError("The number of sides of the polygon must be an "
161  "integer greater than 2");
162  }
163  }
164  if (is_a_Number(*x)) {
165  if (not is_a<Integer>(*x)
166  or not down_cast<const Integer &>(*x).is_positive()) {
167  throw DomainError("x must be an integer greater than 0");
168  }
169  }
170 
171  if (is_a_Number(*s) and is_a_Number(*x)) {
172  // Optimized numeric calculation
173  auto s_int = down_cast<const Integer &>(*s).as_integer_class();
174  auto x_int = down_cast<const Integer &>(*x).as_integer_class();
175  auto res = mp_principal_polygonal_root(s_int, x_int);
176  return make_rcp<const Integer>(res);
177  }
178 
179  RCP<const Integer> m2 = integer(-2);
180  RCP<const Integer> m4 = integer(-4);
181  RCP<const Integer> p2 = integer(2);
182  RCP<const Integer> p8 = integer(8);
183  RCP<const Basic> root
184  = sqrt(add(mul(mul(p8, add(s, m2)), x), pow(add(s, m4), p2)));
185  RCP<const Basic> n = div(add(root, add(s, m4)), mul(p2, add(s, m2)));
186  return n;
187 }
RCP< const Basic > sqrt(const RCP< const Basic > &arg)
Definition: pow.h:61
integer_class mp_principal_polygonal_root(const integer_class &s, const integer_class &x)
Numeric calculation of the principal s-gonal root of x.
Definition: ntheory.cpp:1666

◆ quotient()

RCP< const Integer > SymEngine::quotient ( const Integer n,
const Integer d 
)
Returns
quotient round toward zero when n is divided by d

Definition at line 72 of file ntheory.cpp.

73 {
74  return integer(n.as_integer_class() / d.as_integer_class());
75 }

◆ quotient_f()

RCP< const Integer > SymEngine::quotient_f ( const Integer n,
const Integer d 
)
Returns
quotient round toward -inf when n is divided by d

Definition at line 94 of file ntheory.cpp.

95 {
96  integer_class q;
97  mp_fdiv_q(q, n.as_integer_class(), d.as_integer_class());
98  return integer(std::move(q));
99 }

◆ quotient_mod()

void SymEngine::quotient_mod ( const Ptr< RCP< const Integer >> &  q,
const Ptr< RCP< const Integer >> &  r,
const Integer a,
const Integer b 
)
Returns
modulo and quotient round toward zero

Definition at line 77 of file ntheory.cpp.

80 {
81  integer_class _q, _r;
82  mp_tdiv_qr(_q, _r, n.as_integer_class(), d.as_integer_class());
83  *q = integer(std::move(_q));
84  *r = integer(std::move(_r));
85 }

◆ quotient_mod_f()

void SymEngine::quotient_mod_f ( const Ptr< RCP< const Integer >> &  q,
const Ptr< RCP< const Integer >> &  r,
const Integer a,
const Integer b 
)
Returns
modulo and quotient round toward -inf

Definition at line 101 of file ntheory.cpp.

104 {
105  integer_class _q, _r;
106  mp_fdiv_qr(_q, _r, n.as_integer_class(), d.as_integer_class());
107  *q = integer(std::move(_q));
108  *r = integer(std::move(_r));
109 }

◆ rationals()

RCP<const Rationals> SymEngine::rationals ( )
inline
Returns
RCP<const Rationals>

Definition at line 566 of file sets.h.

567 {
568  return Rationals::getInstance();
569 }

◆ reals()

RCP<const Reals> SymEngine::reals ( )
inline
Returns
RCP<const Reals>

Definition at line 560 of file sets.h.

561 {
562  return Reals::getInstance();
563 }

◆ sdiff()

RCP< const Basic > SymEngine::sdiff ( const RCP< const Basic > &  arg,
const RCP< const Basic > &  x,
bool  cache 
)

SymPy style differentiation for non-symbol variables.

SymPy style differentiation w.r.t non-symbols and symbols.

Definition at line 818 of file derivative.cpp.

820 {
821  if (is_a<Symbol>(*x)) {
822  return arg->diff(rcp_static_cast<const Symbol>(x), cache);
823  } else {
824  RCP<const Symbol> d = get_dummy(*arg, "x");
825  return ssubs(ssubs(arg, {{x, d}})->diff(d, cache), {{d, x}});
826  }
827 }
RCP< const Basic > ssubs(const RCP< const Basic > &x, const map_basic_basic &subs_dict, bool cache=true)
SymPy compatible subs.
Definition: subs.h:559

◆ sqrt()

RCP< const Basic > SymEngine::sqrt ( const RCP< const Basic > &  x)
inline
Returns
sqrt of the arg
square root of x

Definition at line 61 of file pow.h.

62 {
63  return pow(x, div(one, integer(2)));
64 }

◆ sub()

RCP< const Basic > sub ( const RCP< const Basic > &  a,
const RCP< const Basic > &  b 
)

Substracts b from a.

This essentially implements the addition of a and -b. Note that since this calls add() it performs canonicalization if required.

Parameters
ais the minuend.
bis the subtrahend.
Returns
the difference a-b.

Definition at line 495 of file add.cpp.

496 {
497  return add(a, mul(minus_one, b));
498 }

◆ trig_to_sqrt()

RCP< const Basic > SymEngine::trig_to_sqrt ( const RCP< const Basic > &  arg)
Returns
simplified form if possible

Definition at line 1246 of file functions.cpp.

1247 {
1248  RCP<const Basic> i_arg;
1249 
1250  if (is_a<Sin>(*arg)) {
1251  if (is_a<ACos>(*arg->get_args()[0])) {
1252  i_arg = down_cast<const ACos &>(*(arg->get_args()[0])).get_arg();
1253  return sqrt(sub(one, pow(i_arg, i2)));
1254  } else if (is_a<ATan>(*arg->get_args()[0])) {
1255  i_arg = down_cast<const ATan &>(*(arg->get_args()[0])).get_arg();
1256  return div(i_arg, sqrt(add(one, pow(i_arg, i2))));
1257  } else if (is_a<ASec>(*arg->get_args()[0])) {
1258  i_arg = down_cast<const ASec &>(*(arg->get_args()[0])).get_arg();
1259  return sqrt(sub(one, pow(i_arg, im2)));
1260  } else if (is_a<ACot>(*arg->get_args()[0])) {
1261  i_arg = down_cast<const ACot &>(*(arg->get_args()[0])).get_arg();
1262  return div(one, mul(i_arg, sqrt(add(one, pow(i_arg, im2)))));
1263  }
1264  } else if (is_a<Cos>(*arg)) {
1265  if (is_a<ASin>(*arg->get_args()[0])) {
1266  i_arg = down_cast<const ASin &>(*(arg->get_args()[0])).get_arg();
1267  return sqrt(sub(one, pow(i_arg, i2)));
1268  } else if (is_a<ATan>(*arg->get_args()[0])) {
1269  i_arg = down_cast<const ATan &>(*(arg->get_args()[0])).get_arg();
1270  return div(one, sqrt(add(one, pow(i_arg, i2))));
1271  } else if (is_a<ACsc>(*arg->get_args()[0])) {
1272  i_arg = down_cast<const ACsc &>(*(arg->get_args()[0])).get_arg();
1273  return sqrt(sub(one, pow(i_arg, im2)));
1274  } else if (is_a<ACot>(*arg->get_args()[0])) {
1275  i_arg = down_cast<const ACot &>(*(arg->get_args()[0])).get_arg();
1276  return div(one, sqrt(add(one, pow(i_arg, im2))));
1277  }
1278  } else if (is_a<Tan>(*arg)) {
1279  if (is_a<ASin>(*arg->get_args()[0])) {
1280  i_arg = down_cast<const ASin &>(*(arg->get_args()[0])).get_arg();
1281  return div(i_arg, sqrt(sub(one, pow(i_arg, i2))));
1282  } else if (is_a<ACos>(*arg->get_args()[0])) {
1283  i_arg = down_cast<const ACos &>(*(arg->get_args()[0])).get_arg();
1284  return div(sqrt(sub(one, pow(i_arg, i2))), i_arg);
1285  } else if (is_a<ACsc>(*arg->get_args()[0])) {
1286  i_arg = down_cast<const ACsc &>(*(arg->get_args()[0])).get_arg();
1287  return div(one, mul(i_arg, sqrt(sub(one, pow(i_arg, im2)))));
1288  } else if (is_a<ASec>(*arg->get_args()[0])) {
1289  i_arg = down_cast<const ASec &>(*(arg->get_args()[0])).get_arg();
1290  return mul(i_arg, sqrt(sub(one, pow(i_arg, im2))));
1291  }
1292  } else if (is_a<Csc>(*arg)) {
1293  if (is_a<ACos>(*arg->get_args()[0])) {
1294  i_arg = down_cast<const ACos &>(*(arg->get_args()[0])).get_arg();
1295  return div(one, sqrt(sub(one, pow(i_arg, i2))));
1296  } else if (is_a<ATan>(*arg->get_args()[0])) {
1297  i_arg = down_cast<const ATan &>(*(arg->get_args()[0])).get_arg();
1298  return div(sqrt(add(one, pow(i_arg, i2))), i_arg);
1299  } else if (is_a<ASec>(*arg->get_args()[0])) {
1300  i_arg = down_cast<const ASec &>(*(arg->get_args()[0])).get_arg();
1301  return div(one, sqrt(sub(one, pow(i_arg, im2))));
1302  } else if (is_a<ACot>(*arg->get_args()[0])) {
1303  i_arg = down_cast<const ACot &>(*(arg->get_args()[0])).get_arg();
1304  return mul(i_arg, sqrt(add(one, pow(i_arg, im2))));
1305  }
1306  } else if (is_a<Sec>(*arg)) {
1307  if (is_a<ASin>(*arg->get_args()[0])) {
1308  i_arg = down_cast<const ASin &>(*(arg->get_args()[0])).get_arg();
1309  return div(one, sqrt(sub(one, pow(i_arg, i2))));
1310  } else if (is_a<ATan>(*arg->get_args()[0])) {
1311  i_arg = down_cast<const ATan &>(*(arg->get_args()[0])).get_arg();
1312  return sqrt(add(one, pow(i_arg, i2)));
1313  } else if (is_a<ACsc>(*arg->get_args()[0])) {
1314  i_arg = down_cast<const ACsc &>(*(arg->get_args()[0])).get_arg();
1315  return div(one, sqrt(sub(one, pow(i_arg, im2))));
1316  } else if (is_a<ACot>(*arg->get_args()[0])) {
1317  i_arg = down_cast<const ACot &>(*(arg->get_args()[0])).get_arg();
1318  return sqrt(add(one, pow(i_arg, im2)));
1319  }
1320  } else if (is_a<Cot>(*arg)) {
1321  if (is_a<ASin>(*arg->get_args()[0])) {
1322  i_arg = down_cast<const ASin &>(*(arg->get_args()[0])).get_arg();
1323  return div(sqrt(sub(one, pow(i_arg, i2))), i_arg);
1324  } else if (is_a<ACos>(*arg->get_args()[0])) {
1325  i_arg = down_cast<const ACos &>(*(arg->get_args()[0])).get_arg();
1326  return div(i_arg, sqrt(sub(one, pow(i_arg, i2))));
1327  } else if (is_a<ACsc>(*arg->get_args()[0])) {
1328  i_arg = down_cast<const ACsc &>(*(arg->get_args()[0])).get_arg();
1329  return mul(i_arg, sqrt(sub(one, pow(i_arg, im2))));
1330  } else if (is_a<ASec>(*arg->get_args()[0])) {
1331  i_arg = down_cast<const ASec &>(*(arg->get_args()[0])).get_arg();
1332  return div(one, mul(i_arg, sqrt(sub(one, pow(i_arg, im2)))));
1333  }
1334  }
1335 
1336  return arg;
1337 }

◆ unified_compare()

template<typename T , typename = enable_if_t<std::is_arithmetic<T>::value or std::is_same<T, integer_class>::value or std::is_same<T, rational_class>::value>>
int SymEngine::unified_compare ( const T &  a,
const T &  b 
)
inline

compare functions base

Returns
-1, 0, 1 for a < b, a == b, a > b

Definition at line 205 of file dict.h.

206 {
207  if (a == b)
208  return 0;
209  return a < b ? -1 : 1;
210 }

◆ universalset()

RCP<const UniversalSet> SymEngine::universalset ( )
inline
Returns
RCP<const UniversalSet>

Definition at line 596 of file sets.h.

597 {
598  return UniversalSet::getInstance();
599 }

◆ unordered_eq()

template<class T >
bool SymEngine::unordered_eq ( const T &  a,
const T &  b 
)
inline

eq function base

Returns
true if the two dictionaries a and b are equal. Otherwise false

Definition at line 156 of file dict.h.

157 {
158  // This follows the same algorithm as Python's dictionary comparison
159  // (a==b), which is implemented by "dict_equal" function in
160  // Objects/dictobject.c.
161 
162  // Can't be equal if # of entries differ:
163  if (a.size() != b.size())
164  return false;
165  // Loop over keys in "a":
166  for (const auto &p : a) {
167  // O(1) lookup of the key in "b":
168  auto f = b.find(p.first);
169  if (f == b.end())
170  return false; // no such element in "b"
171  if (not unified_eq(p.second, f->second))
172  return false; // values not equal
173  }
174  return true;
175 }