Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
RationalFunction Class Reference

Detailed Description

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.
 RationalFunction (Polynomial numerator, Polynomial denominator)
 Constructs the rational function: numerator / denominator.
 RationalFunction (const Polynomial &p)
 Constructs the rational function: p / 1.
 RationalFunction (const Monomial &m)
 Constructs the rational function: m / 1 for any type which can be cast to a monomial.
 RationalFunction (double c)
 Constructs the rational function: c / 1.
double Evaluate (const Environment &env) const
 Evaluates this rational function under a given environment env.
 ~RationalFunction ()=default
const Polynomialnumerator () const
 Getter for the numerator.
const Polynomialdenominator () const
 Getter for the denominator.
RationalFunctionoperator+= (const RationalFunction &f)
RationalFunctionoperator+= (const Polynomial &p)
RationalFunctionoperator+= (const Monomial &m)
RationalFunctionoperator+= (double c)
RationalFunctionoperator-= (const RationalFunction &f)
RationalFunctionoperator-= (const Polynomial &p)
RationalFunctionoperator-= (const Monomial &m)
RationalFunctionoperator-= (double c)
RationalFunctionoperator*= (const RationalFunction &f)
RationalFunctionoperator*= (const Polynomial &p)
RationalFunctionoperator*= (const Monomial &m)
RationalFunctionoperator*= (double c)
RationalFunctionoperator/= (const RationalFunction &f)
RationalFunctionoperator/= (const Polynomial &p)
RationalFunctionoperator/= (const Monomial &m)
RationalFunctionoperator/= (double c)
bool EqualTo (const RationalFunction &f) const
 Returns true if this rational function and f are structurally equal.
Formula operator== (const RationalFunction &f) const
 Returns a symbolic formula representing the condition where this rational function and f are the same.
Formula operator!= (const RationalFunction &f) const
 Returns a symbolic formula representing the condition where this rational function and f are not the same.
Expression ToExpression () const
 Returns an equivalent symbolic expression of this rational function.
void SetIndeterminates (const Variables &new_indeterminates)
 Sets the indeterminates of the numerator and denominator polynomials.
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 RationalFunction (const RationalFunction &)=default
RationalFunctionoperator= (const RationalFunction &)=default
 RationalFunction (RationalFunction &&)=default
RationalFunctionoperator= (RationalFunction &&)=default

Friends

RationalFunction operator- (RationalFunction f)
 Unary minus operation for rational function.
std::ostream & operator<< (std::ostream &, const RationalFunction &f)

Constructor & Destructor Documentation

◆ RationalFunction() [1/7]

Constructs a zero rational function 0 / 1.

◆ RationalFunction() [2/7]

RationalFunction ( const RationalFunction & )
default

◆ RationalFunction() [3/7]

◆ RationalFunction() [4/7]

RationalFunction ( Polynomial numerator,
Polynomial denominator )

Constructs the rational function: numerator / denominator.

Parameters
numeratorThe numerator of the fraction.
denominatorThe denominator of the fraction.
Precondition
denominator is not equal to zero.
None of the indeterminates in the numerator can be decision variables in the denominator; similarly none of the indeterminates in the denominator can be decision variables in the numerator.

◆ RationalFunction() [5/7]

RationalFunction ( const Polynomial & p)
explicit

Constructs the rational function: p / 1.

Note that we use 1 as the denominator.

Parameters
pThe numerator of the rational function.

◆ RationalFunction() [6/7]

RationalFunction ( const Monomial & m)
explicit

Constructs the rational function: m / 1 for any type which can be cast to a monomial.

Parameters
mThe numerator of the rational function.

◆ RationalFunction() [7/7]

RationalFunction ( double c)
explicit

Constructs the rational function: c / 1.

Note that we use 1 as the denominator.

Parameters
cThe numerator of the rational function.

◆ ~RationalFunction()

~RationalFunction ( )
default

Member Function Documentation

◆ denominator()

const Polynomial & denominator ( ) const
nodiscard

Getter for the denominator.

◆ EqualTo()

bool EqualTo ( const RationalFunction & f) const
nodiscard

Returns true if this rational function and f are structurally equal.

◆ Evaluate()

double Evaluate ( const Environment & env) const
nodiscard

Evaluates this rational function under a given environment env.

Exceptions
std::exceptionif there is a variable in this rational function whose assignment is not provided by env.

◆ numerator()

const Polynomial & numerator ( ) const
nodiscard

Getter for the numerator.

◆ operator!=()

Formula operator!= ( const RationalFunction & f) const

Returns a symbolic formula representing the condition where this rational function and f are not the same.

◆ operator*=() [1/4]

RationalFunction & operator*= ( const Monomial & m)

◆ operator*=() [2/4]

RationalFunction & operator*= ( const Polynomial & p)

◆ operator*=() [3/4]

RationalFunction & operator*= ( const RationalFunction & f)

◆ operator*=() [4/4]

RationalFunction & operator*= ( double c)

◆ operator+=() [1/4]

RationalFunction & operator+= ( const Monomial & m)

◆ operator+=() [2/4]

RationalFunction & operator+= ( const Polynomial & p)

◆ operator+=() [3/4]

RationalFunction & operator+= ( const RationalFunction & f)

◆ operator+=() [4/4]

RationalFunction & operator+= ( double c)

◆ operator-=() [1/4]

RationalFunction & operator-= ( const Monomial & m)

◆ operator-=() [2/4]

RationalFunction & operator-= ( const Polynomial & p)

◆ operator-=() [3/4]

RationalFunction & operator-= ( const RationalFunction & f)

◆ operator-=() [4/4]

RationalFunction & operator-= ( double c)

◆ operator/=() [1/4]

RationalFunction & operator/= ( const Monomial & m)

◆ operator/=() [2/4]

RationalFunction & operator/= ( const Polynomial & p)
Exceptions
std::exceptionif the divisor is structurally equal to zero. Note that this does not guarantee that the denominator of the result is not zero after expansion.

◆ operator/=() [3/4]

RationalFunction & operator/= ( const RationalFunction & f)
Exceptions
std::exceptionif 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.

◆ operator/=() [4/4]

RationalFunction & operator/= ( double c)
Exceptions
std::exceptionif c is 0

◆ operator=() [1/2]

RationalFunction & operator= ( const RationalFunction & )
default

◆ operator=() [2/2]

RationalFunction & operator= ( RationalFunction && )
default

◆ operator==()

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

◆ SetIndeterminates()

void SetIndeterminates ( const Variables & new_indeterminates)

Sets the indeterminates of the numerator and denominator polynomials.

◆ ToExpression()

Expression ToExpression ( ) const
nodiscard

Returns an equivalent symbolic expression of this rational function.

◆ operator-

RationalFunction operator- ( RationalFunction f)
friend

Unary minus operation for rational function.

if f(x) = p(x) / q(x), then -f(x) = (-p(x)) / q(x)

◆ operator<<

std::ostream & operator<< ( std::ostream & ,
const RationalFunction & f )
friend

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