5 #ifndef BPP_NUMERIC_FUNCTION_OPERATORS_BINARYOPERATOR_H 6 #define BPP_NUMERIC_FUNCTION_OPERATORS_BINARYOPERATOR_H 28 BinaryOperator(
char symb, std::shared_ptr<Operator> left, std::shared_ptr<Operator> right) :
29 symb_(symb), left_(left), right_(right)
57 return left_->getValue() + right_->getValue();
59 return left_->getValue() - right_->getValue();
61 if (right_->getValue() == 0)
64 return left_->getValue() / right_->getValue();
66 return left_->getValue() * right_->getValue();
74 double dl = left_->getFirstOrderDerivative(variable);
75 double dr = right_->getFirstOrderDerivative(variable);
76 double l = left_->getValue();
77 double r = right_->getValue();
89 return (dl * r - dr * l ) / (r * r);
91 return dl * r + dr * l;
100 double d2l = left_->getSecondOrderDerivative(variable);
101 double d2r = right_->getSecondOrderDerivative(variable);
102 double l = left_->getValue();
103 double r = right_->getValue();
104 double dl = left_->getFirstOrderDerivative(variable);
105 double dr = right_->getFirstOrderDerivative(variable);
121 return (d2l * r - d2r * l ) / r2 - ( 2 * dl * ( dl * r - dr * l) ) / r3;
124 return d2l * r + d2r * l + 2 * dr * dl;
132 return "(" + left_->output() +
" " + symb_ +
" " + right_->output() +
")";
136 #endif // BPP_NUMERIC_FUNCTION_OPERATORS_BINARYOPERATOR_H
Binary arithmetic operator for numerical computation.
std::shared_ptr< Operator > getRightSon()
std::shared_ptr< Operator > right_
BinaryOperator * clone() const
Create a copy of this object and send a pointer to it.
std::shared_ptr< Operator > getLeftSon()
std::string output() const
BinaryOperator(char symb, std::shared_ptr< Operator > left, std::shared_ptr< Operator > right)
double getSecondOrderDerivative(const std::string &variable) const
std::shared_ptr< Operator > left_
double getFirstOrderDerivative(const std::string &variable) const
Interface of operator for numerical computation.