Represents symbolic rational function.
A function f(x) is a rational function, if f(x) = p(x) / q(x), where both p(x) and q(x) are polynomials of x. Note that rational functions are closed under (+, -, x, /). One application of rational function is in polynomial optimization, where we represent (or approximate) functions using rational functions, and then convert the constraint f(x) = h(x) (where h(x) is a polynomial) to a polynomial constraint p(x) - q(x) * h(x) = 0, or convert the inequality constraint f(x) >= h(x) as p(x) - q(x) * h(x) >= 0 if we know q(x) > 0.
This class represents a special subset of the symbolic::Expression. While a symbolic::Expression can represent a rational function, extracting the numerator and denominator, generally, is quite difficult; for instance, from p1(x) / q1(x) + p2(x) / q2(x) + ... + pn(x) / qn(x). This class's explicit structure facilitates this decomposition.
#include <drake/common/symbolic/rational_function.h>
Public Member Functions | |
RationalFunction () | |
Constructs a zero rational function 0 / 1. More... | |
RationalFunction (Polynomial numerator, Polynomial denominator) | |
Constructs the rational function: numerator / denominator. More... | |
RationalFunction (const Polynomial &p) | |
Constructs the rational function: p / 1. More... | |
RationalFunction (const Monomial &m) | |
Constructs the rational function: m / 1 for any type which can be cast to a monomial. More... | |
RationalFunction (double c) | |
Constructs the rational function: c / 1. More... | |
double | Evaluate (const Environment &env) const |
Evaluates this rational function under a given environment env . More... | |
~RationalFunction ()=default | |
const Polynomial & | numerator () const |
Getter for the numerator. More... | |
const Polynomial & | denominator () const |
Getter for the denominator. More... | |
RationalFunction & | operator+= (const RationalFunction &f) |
RationalFunction & | operator+= (const Polynomial &p) |
RationalFunction & | operator+= (const Monomial &m) |
RationalFunction & | operator+= (double c) |
RationalFunction & | operator-= (const RationalFunction &f) |
RationalFunction & | operator-= (const Polynomial &p) |
RationalFunction & | operator-= (const Monomial &m) |
RationalFunction & | operator-= (double c) |
RationalFunction & | operator *= (const RationalFunction &f) |
RationalFunction & | operator *= (const Polynomial &p) |
RationalFunction & | operator *= (const Monomial &m) |
RationalFunction & | operator *= (double c) |
RationalFunction & | operator/= (const RationalFunction &f) |
RationalFunction & | operator/= (const Polynomial &p) |
RationalFunction & | operator/= (const Monomial &m) |
RationalFunction & | operator/= (double c) |
bool | EqualTo (const RationalFunction &f) const |
Returns true if this rational function and f are structurally equal. More... | |
Formula | operator== (const RationalFunction &f) const |
Returns a symbolic formula representing the condition where this rational function and f are the same. More... | |
Formula | operator!= (const RationalFunction &f) const |
Returns a symbolic formula representing the condition where this rational function and f are not the same. More... | |
Expression | ToExpression () const |
Returns an equivalent symbolic expression of this rational function. More... | |
void | SetIndeterminates (const Variables &new_indeterminates) |
Sets the indeterminates of the numerator and denominator polynomials. More... | |
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable | |
RationalFunction (const RationalFunction &)=default | |
RationalFunction & | operator= (const RationalFunction &)=default |
RationalFunction (RationalFunction &&)=default | |
RationalFunction & | operator= (RationalFunction &&)=default |
Friends | |
RationalFunction | operator- (RationalFunction f) |
Unary minus operation for rational function. More... | |
std::ostream & | operator<< (std::ostream &, const RationalFunction &f) |
RationalFunction | ( | ) |
Constructs a zero rational function 0 / 1.
|
default |
|
default |
RationalFunction | ( | Polynomial | numerator, |
Polynomial | denominator | ||
) |
Constructs the rational function: numerator / denominator.
numerator | The numerator of the fraction. |
denominator | The denominator of the fraction. |
|
explicit |
Constructs the rational function: p / 1.
Note that we use 1 as the denominator.
p | The numerator of the rational function. |
|
explicit |
Constructs the rational function: m / 1 for any type which can be cast to a monomial.
m | The numerator of the rational function. |
|
explicit |
Constructs the rational function: c / 1.
Note that we use 1 as the denominator.
c | The numerator of the rational function. |
|
default |
const Polynomial& denominator | ( | ) | const |
Getter for the denominator.
bool EqualTo | ( | const RationalFunction & | f | ) | const |
Returns true if this rational function and f are structurally equal.
double Evaluate | ( | const Environment & | env | ) | const |
Evaluates this rational function under a given environment env
.
std::exception | if there is a variable in this rational function whose assignment is not provided by env . |
const Polynomial& numerator | ( | ) | const |
Getter for the numerator.
RationalFunction& operator *= | ( | const RationalFunction & | f | ) |
RationalFunction& operator *= | ( | const Polynomial & | p | ) |
RationalFunction& operator *= | ( | const Monomial & | m | ) |
RationalFunction& operator *= | ( | double | c | ) |
Formula operator!= | ( | const RationalFunction & | f | ) | const |
Returns a symbolic formula representing the condition where this rational function and f
are not the same.
RationalFunction& operator+= | ( | const RationalFunction & | f | ) |
RationalFunction& operator+= | ( | const Polynomial & | p | ) |
RationalFunction& operator+= | ( | const Monomial & | m | ) |
RationalFunction& operator+= | ( | double | c | ) |
RationalFunction& operator-= | ( | const RationalFunction & | f | ) |
RationalFunction& operator-= | ( | const Polynomial & | p | ) |
RationalFunction& operator-= | ( | const Monomial & | m | ) |
RationalFunction& operator-= | ( | double | c | ) |
RationalFunction& operator/= | ( | const RationalFunction & | f | ) |
std::exception | if the numerator of the divisor is structurally equal to zero. Note that this does not guarantee that the denominator of the result is not zero after expansion. |
RationalFunction& operator/= | ( | const Polynomial & | p | ) |
std::exception | if the divisor is structurally equal to zero. Note that this does not guarantee that the denominator of the result is not zero after expansion. |
RationalFunction& operator/= | ( | const Monomial & | m | ) |
RationalFunction& operator/= | ( | double | c | ) |
std::exception | if c is 0 |
|
default |
|
default |
Formula operator== | ( | const RationalFunction & | f | ) | const |
Returns a symbolic formula representing the condition where this rational function and f
are the same.
If f1 = p1 / q1, f2 = p2 / q2, then f1 == f2 <=> p1 * q2 == p2 * q1
void SetIndeterminates | ( | const Variables & | new_indeterminates | ) |
Sets the indeterminates of the numerator and denominator polynomials.
Expression ToExpression | ( | ) | const |
Returns an equivalent symbolic expression of this rational function.
|
friend |
Unary minus operation for rational function.
if f(x) = p(x) / q(x), then -f(x) = (-p(x)) / q(x)
|
friend |