Loading...
Searching...
No Matches
SymEngine::Derivative Class Reference

#include <functions.h>

+ Inheritance diagram for SymEngine::Derivative:
+ Collaboration diagram for SymEngine::Derivative:

Public Member Functions

virtual void accept (Visitor &v) const
 
virtual void accept (EvalRealDoubleVisitorFinal &v) const
 
 Derivative (const RCP< const Basic > &arg, const multiset_basic &x)
 
virtual hash_t __hash__ () const
 
virtual bool __eq__ (const Basic &o) const
 Test equality. More...
 
virtual int compare (const Basic &o) const
 
RCP< const Basicget_arg () const
 
const multiset_basicget_symbols () const
 
virtual vec_basic get_args () const
 Returns the list of arguments. More...
 
bool is_canonical (const RCP< const Basic > &arg, const multiset_basic &x) const
 
- Public Member Functions inherited from SymEngine::Basic
TypeID get_type_code () const
 
 Basic ()
 Constructor. More...
 
 Basic (const Basic &)=delete
 Delete the copy constructor and assignment.
 
Basicoperator= (const Basic &)=delete
 Assignment operator in continuation with above.
 
 Basic (Basic &&)=delete
 Delete the move constructor and assignment.
 
Basicoperator= (Basic &&)=delete
 Assignment operator in continuation with above.
 
virtual hash_t __hash__ () const =0
 
hash_t hash () const
 
virtual bool __eq__ (const Basic &o) const =0
 Test equality. More...
 
bool __neq__ (const Basic &o) const
 true if this is not equal to o. More...
 
int __cmp__ (const Basic &o) const
 Comparison operator. More...
 
virtual int compare (const Basic &o) const =0
 
std::string __str__ () const
 
std::string dumps () const
 Returns a string of the instance serialized. More...
 
RCP< const Basicsubs (const map_basic_basic &subs_dict) const
 Substitutes 'subs_dict' into 'self'. More...
 
RCP< const Basicxreplace (const map_basic_basic &subs_dict) const
 
virtual RCP< const Basicexpand_as_exp () const
 expands the special function in terms of exp function More...
 
virtual vec_basic get_args () const =0
 Returns the list of arguments. More...
 
virtual void accept (Visitor &v) const =0
 
virtual void accept (EvalRealDoubleVisitorFinal &v) const =0
 
RCP< const Basicdiff (const RCP< const Symbol > &x, bool cache=true) const
 
- Public Member Functions inherited from SymEngine::EnableRCPFromThis< Basic >
RCP< Basicrcp_from_this ()
 Get RCP<T> pointer to self (it will cast the pointer to T) More...
 
RCP< const Basicrcp_from_this () const
 Get RCP<const T> pointer to self (it will cast the pointer to const T) More...
 
RCP< const T2 > rcp_from_this_cast () const
 Get RCP<T2> pointer to self (it will cast the pointer to T2) More...
 
unsigned int use_count () const
 

Static Public Member Functions

static RCP< const Derivativecreate (const RCP< const Basic > &arg, const multiset_basic &x)
 
- Static Public Member Functions inherited from SymEngine::Basic
static RCP< const Basicloads (const std::string &)
 Creates an instance of a serialized string. More...
 

Static Public Attributes

static const TypeID type_code_id = SYMENGINE_DERIVATIVE
 x, y, ... More...
 

Private Attributes

RCP< const Basicarg_
 
multiset_basic x_
 The expression to be differentiated. More...
 

Additional Inherited Members

- Data Fields inherited from SymEngine::Basic
TypeID type_code_
 

Detailed Description

Derivative operator Derivative(f, [x, y, ...]) represents a derivative of f with respect to x, y, and so on.

Definition at line 686 of file functions.h.

Constructor & Destructor Documentation

◆ Derivative()

SymEngine::Derivative::Derivative ( const RCP< const Basic > &  arg,
const multiset_basic x 
)

Definition at line 1928 of file functions.cpp.

1930 : arg_{arg}, x_{x}
1931{
1932 SYMENGINE_ASSIGN_TYPEID()
1933 SYMENGINE_ASSERT(is_canonical(arg, x))
1934}
multiset_basic x_
The expression to be differentiated.
Definition: functions.h:701

Member Function Documentation

◆ __eq__()

bool SymEngine::Derivative::__eq__ ( const Basic o) const
virtual

Test equality.

A virtual function for testing the equality of two Basic objects

Deprecated:
Use eq(const Basic &a, const Basic &b) non-member method
Parameters
oa constant reference to object to test against
Returns
True if this is equal to o

Implements SymEngine::Basic.

Definition at line 2008 of file functions.cpp.

2009{
2010 if (is_a<Derivative>(o)
2011 and eq(*arg_, *(down_cast<const Derivative &>(o).arg_))
2012 and unified_eq(x_, down_cast<const Derivative &>(o).x_))
2013 return true;
2014 return false;
2015}
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21

◆ __hash__()

hash_t SymEngine::Derivative::__hash__ ( ) const
virtual

Calculates the hash of the given SymEngine class. Use Basic.hash() which gives a cached version of the hash.

Returns
64-bit integer value for the hash

Implements SymEngine::Basic.

Definition at line 1998 of file functions.cpp.

1999{
2000 hash_t seed = SYMENGINE_DERIVATIVE;
2001 hash_combine<Basic>(seed, *arg_);
2002 for (auto &p : x_) {
2003 hash_combine<Basic>(seed, *p);
2004 }
2005 return seed;
2006}

◆ accept() [1/2]

virtual void SymEngine::Derivative::accept ( EvalRealDoubleVisitorFinal v) const
virtual

Implements SymEngine::Basic.

◆ accept() [2/2]

virtual void SymEngine::Derivative::accept ( Visitor v) const
virtual

Implements SymEngine::Basic.

◆ compare()

int SymEngine::Derivative::compare ( const Basic o) const
virtual

Returns -1, 0, 1 for this < o, this == o, this > o. This method is used when you want to sort things like x+y+z into canonical order. This function assumes that o is the same type as this. Use __cmp__ if you want general comparison.

Implements SymEngine::Basic.

Definition at line 2017 of file functions.cpp.

2018{
2019 SYMENGINE_ASSERT(is_a<Derivative>(o))
2020 const Derivative &s = down_cast<const Derivative &>(o);
2021 int cmp = arg_->__cmp__(*(s.arg_));
2022 if (cmp != 0)
2023 return cmp;
2024 cmp = unified_compare(x_, s.x_);
2025 return cmp;
2026}
int unified_compare(const T &a, const T &b)
Definition: dict.h:205

◆ create()

static RCP< const Derivative > SymEngine::Derivative::create ( const RCP< const Basic > &  arg,
const multiset_basic x 
)
inlinestatic

Definition at line 707 of file functions.h.

709 {
710 return make_rcp<const Derivative>(arg, x);
711 }

◆ get_arg()

RCP< const Basic > SymEngine::Derivative::get_arg ( ) const
inline

Definition at line 716 of file functions.h.

717 {
718 return arg_;
719 }

◆ get_args()

virtual vec_basic SymEngine::Derivative::get_args ( ) const
inlinevirtual

Returns the list of arguments.

Implements SymEngine::Basic.

Definition at line 724 of file functions.h.

725 {
726 vec_basic args = {arg_};
727 args.insert(args.end(), x_.begin(), x_.end());
728 return args;
729 }
T begin(T... args)
T end(T... args)

◆ get_symbols()

const multiset_basic & SymEngine::Derivative::get_symbols ( ) const
inline

Definition at line 720 of file functions.h.

721 {
722 return x_;
723 }

◆ is_canonical()

bool SymEngine::Derivative::is_canonical ( const RCP< const Basic > &  arg,
const multiset_basic x 
) const

Definition at line 1936 of file functions.cpp.

1938{
1939 // Check that 'x' are Symbols:
1940 for (const auto &a : x)
1941 if (not is_a<Symbol>(*a))
1942 return false;
1943 if (is_a<FunctionSymbol>(*arg) or is_a<LeviCivita>(*arg)) {
1944 for (auto &p : x) {
1945 RCP<const Symbol> s = rcp_static_cast<const Symbol>(p);
1946 RCP<const MultiArgFunction> f
1947 = rcp_static_cast<const MultiArgFunction>(arg);
1948 bool found_s = false;
1949 // 's' should be one of the args of the function
1950 // and should not appear anywhere else.
1951 for (const auto &a : f->get_args()) {
1952 if (eq(*a, *s)) {
1953 if (found_s) {
1954 return false;
1955 } else {
1956 found_s = true;
1957 }
1958 } else if (neq(*a->diff(s), *zero)) {
1959 return false;
1960 }
1961 }
1962 if (!found_s) {
1963 return false;
1964 }
1965 }
1966 return true;
1967 } else if (is_a<Abs>(*arg)) {
1968 return true;
1969 } else if (is_a<FunctionWrapper>(*arg)) {
1970 return true;
1971 } else if (is_a<PolyGamma>(*arg) or is_a<Zeta>(*arg)
1972 or is_a<UpperGamma>(*arg) or is_a<LowerGamma>(*arg)
1973 or is_a<Dirichlet_eta>(*arg)) {
1974 bool found = false;
1975 auto v = arg->get_args();
1976 for (auto &p : x) {
1977 if (has_symbol(*v[0], *rcp_static_cast<const Symbol>(p))) {
1978 found = true;
1979 break;
1980 }
1981 }
1982 return found;
1983 } else if (is_a<KroneckerDelta>(*arg)) {
1984 bool found = false;
1985 auto v = arg->get_args();
1986 for (auto &p : x) {
1987 if (has_symbol(*v[0], *rcp_static_cast<const Symbol>(p))
1988 or has_symbol(*v[1], *rcp_static_cast<const Symbol>(p))) {
1989 found = true;
1990 break;
1991 }
1992 }
1993 return found;
1994 }
1995 return false;
1996}
bool neq(const Basic &a, const Basic &b)
Checks inequality for a and b
Definition: basic-inl.h:29

Field Documentation

◆ arg_

RCP<const Basic> SymEngine::Derivative::arg_
private

Definition at line 689 of file functions.h.

◆ type_code_id

const TypeID SymEngine::Derivative::type_code_id = SYMENGINE_DERIVATIVE
static

x, y, ...

Type_code_id shared by all instances

Definition at line 704 of file functions.h.

◆ x_

multiset_basic SymEngine::Derivative::x_
private

The expression to be differentiated.

Definition at line 701 of file functions.h.


The documentation for this class was generated from the following files: