API Documentation

Docstrings for PiecewiseQuadratics.jl interface members can be accessed through Julia's built-in documentation system or in the list below.

Contents

Index

Types

PiecewiseQuadratics.IntervalType
Interval(lb::Real, ub::Real)

Represents a univariate interval.

The fields represent:

  • lb: Lower bound of the interval
  • ub: Upper bound of the interval

Example

julia> interval = Interval(0., 1.)
[0.00000, 1.00000]

julia> Interval()
ℝ
source
PiecewiseQuadratics.BoundedQuadraticType
BoundedQuadratic(lb::Real, ub::Real, p::Real, q::Real, r::Real)

Represents bounded quadratic function

\[f(x) = px^2 + qx + r, ∀ x ∈ [lb, ub]\]

The fields represent:

  • lb: Lower bound of the function
  • ub: Upper bound of the function
  • p: Coefficient of the quadratic term
  • q: Coefficient of the linear term
  • r: Constant

Example

julia> bq = BoundedQuadratic(0., 5., 3., 2., 1.)
BoundedQuadratic: f(x) = 3.00000 x² + 2.00000 x + 1.00000, ∀x ∈ [0.00000, 5.00000]
source
PiecewiseQuadratics.PiecewiseQuadraticType
PiecewiseQuadratic()
PiecewiseQuadratic(f::BoundedQuadratic)
PiecewiseQuadratic(f_list::Vector{BoundedQuadratic}[; simplify_result=false])

Represents piecewise quadratic function, where each piece is a BoundedQuadratic.

The fields represent:

  • f_list: a Vector of BoundedQuadratic functions

Example

julia> left = BoundedQuadratic(-Inf, 0., 0., -1., 0.)
BoundedQuadratic: f(x) = - 1.00000 x , ∀x ∈ [-Inf, 0.00000]

julia> right = BoundedQuadratic(0., Inf, 0., 1., 0.)
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [0.00000, Inf]

julia> pwq = PiecewiseQuadratic([left, right])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 1.00000 x , ∀x ∈ [-Inf, 0.00000]
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [0.00000, Inf]
source
PiecewiseQuadratics.FixedMemoryPwqType
FixedMemoryPwq(len::Int64)

Represents piecewise quadratic function with a fixed-length Vector of BoundedQuadratics.

The fields represent:

  • f_list: a Vector of BoundedQuadratic functions
  • len: how many of the f_list entries are filled in.
source

Constructors

Base.zeroFunction
zero(::Type{BoundedQuadratic})

Construct an empty BoundedQuadratic with no constraints.

Example

julia> zero(BoundedQuadratic)
BoundedQuadratic: f(x) = 0, ∀x ∈ ℝ
source
zero(::Type{PiecewiseQuadratic})

Construct an empty PiecewiseQuadratic with no constraints.

Example

julia> zero(PiecewiseQuadratic)
Piecewise quadratic function:
BoundedQuadratic: f(x) = 0, ∀x ∈ ℝ
source
PiecewiseQuadratics.indicatorFunction
indicator(dom::Interval)
indicator(lb::Real, ub::Real)

Construct a PiecewiseQuadratic that is 0 on the interval and Inf everywhere else.

Example

julia> indicator(-5, 5)
Piecewise quadratic function:
BoundedQuadratic: f(x) = 0, ∀x ∈ [-5.00000, 5.00000]
source
PiecewiseQuadratics.get_lineFunction
get_line(x1::Real, y1::Real, x2::Real, y2::Real)

Construct a new unbounded BoundedQuadratic representing a line passing through (x1, y1) and (x2, y2).

Example

julia> line = get_line(1., 2., 3., 4.)
BoundedQuadratic: f(x) = + 1.00000 x + 1.00000, ∀x ∈ ℝ
source

Functions

Boolean

Base.isemptyFunction
isempty(A::Interval)

Return true if the interval A is empty (isempty(A::Interval)).

source
isempty(f::BoundedQuadratic)

Return true if the domain of the BoundedQuadratic f is empty.

source
isempty(f::PiecewiseQuadratic)

Return true if the PiecewiseQuadratic f is empty (f_list empty).

source
PiecewiseQuadratics.is_pointFunction
is_point(f::BoundedQuadratic)

Return true if the BoundedQuadratic is defined only on a single point (lb == ub).

See also: is_almost_point

Example

julia> bq = BoundedQuadratic(0., 5., 3., 2., 1.)
BoundedQuadratic: f(x) = 3.00000 x² + 2.00000 x + 1.00000, ∀x ∈ [0.00000, 5.00000]

julia> is_point(bq)
false

julia> bq = BoundedQuadratic(5., 5., 3., 2., 1.)
BoundedQuadratic: f(x) = 3.00000 x² + 2.00000 x + 1.00000, ∀x ∈ [5.00000, 5.00000]

julia> is_point(bq)
true
source
PiecewiseQuadratics.is_almost_pointFunction
is_almost_point(f::BoundedQuadratic)

Return true if the BoundedQuadratic is approximately defined only on a single point (lb ≈ ub).

See also: is_point

Example

julia> bq = BoundedQuadratic(5., 5. + 1e-14, 3., 2., 1.)
BoundedQuadratic: f(x) = 3.00000 x² + 2.00000 x + 1.00000, ∀x ∈ [5.00000, 5.00000]

julia> is_point(bq)
false

julia> is_almost_point(bq)
true
source
PiecewiseQuadratics.is_convexFunction
is_convex(f::PiecewiseQuadratic)

Return true if f is convex.

A PiecewiseQuadratic is convex if for all i:

  • f_i is convex
  • f_i.ub == f_{i+1}.lb
  • derivative(f_i)(f_i.ub) <= derivative(f_{i+1})(f_{i+1}.lb)

Example

julia> left = BoundedQuadratic(-Inf, 0., 0., -1., 0.)
BoundedQuadratic: f(x) = - 1.00000 x , ∀x ∈ [-Inf, 0.00000]

julia> right = BoundedQuadratic(0., Inf, 0., 1., 0.)
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [0.00000, Inf]

julia> pwq = PiecewiseQuadratic([left, right])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 1.00000 x , ∀x ∈ [-Inf, 0.00000]
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [0.00000, Inf]

julia> is_convex(pwq)
true
source

Quadratic Manipulation

Base.reverseFunction
reverse(f::BoundedQuadratic)

Return f reversed over the y axis. That is, given f(x), return f(-x).

See also: reverse!

Example

julia> bq = BoundedQuadratic(-1., 2., 1., 1., 1.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-1.00000, 2.00000]

julia> reverse(bq)
BoundedQuadratic: f(x) = 1.00000 x² - 1.00000 x + 1.00000, ∀x ∈ [-2.00000, 1.00000]
source
reverse(f::PiecewiseQuadratic)

Return f reversed over the y axis. That is, given f(x), return f(-x).

See also: reverse

source
PiecewiseQuadratics.reverse!Function
reverse!(f::BoundedQuadratic)
reverse!(f::BoundedQuadratic, out::BoundedQuadratic)

Reverse f inplace.

See also: reverse

source
reverse!(f::PiecewiseQuadratic)
reverse!(f::PiecewiseQuadratic, out::PiecewiseQuadratic)

Reverse f inplace.

See also: reverse

source
PiecewiseQuadratics.scaleFunction
scale(f::BoundedQuadratic, α::Real)

Return a new BoundedQuadratic that has been scaled by α. That is, given f(x) and α, returns f(αx).

Note: this operation requires scaling the domain.

See also: scale!

Example

julia> bq = BoundedQuadratic(-1., 1., 1., 1., 1.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-1.00000, 1.00000]

julia> scale(bq, 2.)
BoundedQuadratic: f(x) = 4.00000 x² + 2.00000 x + 1.00000, ∀x ∈ [-0.50000, 0.50000]
source
scale(f::PiecewiseQuadratic, α::Real)

Return a new PiecewiseQuadratic that has been scaled by α. That is, given f(x) and α, returns f(αx).

Note: this operation requires scaling the domain.

See also: scale!

Example

julia> f = PiecewiseQuadratic([BoundedQuadratic(-1., 0., 0., -1., 0.),
                               BoundedQuadratic(0., 1., 0., 1., 0.),
                               BoundedQuadratic(1., 5., 1., 1., 1.)])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 1.00000 x , ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [0.00000, 1.00000]
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [1.00000, 5.00000]

julia> scale(f, 5)
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 5.00000 x , ∀x ∈ [-0.20000, 0.00000]
BoundedQuadratic: f(x) = + 5.00000 x , ∀x ∈ [0.00000, 0.20000]
BoundedQuadratic: f(x) = 25.00000 x² + 5.00000 x + 1.00000, ∀x ∈ [0.20000, 1.00000]
source
PiecewiseQuadratics.scale!Function
 scale!(f::BoundedQuadratic, α::Real)
 scale!(f::BoundedQuadratic, α::Real, out::BoundedQuadratic)

Scale f inplace.

See also: scale

source
scale!(f::PiecewiseQuadratic, α::Real)
scale!(f::PiecewiseQuadratic, α::Real, out::PiecewiseQuadratic)

Scale f inplace.

See also: scale

source
PiecewiseQuadratics.perspectiveFunction
perspective(f::BoundedQuadratic, α::Real)

Return the perspective function of f. That is, given f(x) and α, return α * f(x / α).

Note: that this operation requires scaling of the domain.

See also: perspective!

Example

julia> bq = BoundedQuadratic(-1., 1., 1., 1., 1.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-1.00000, 1.00000]

julia> perspective(bq, 2.)
BoundedQuadratic: f(x) = 0.50000 x² + 1.00000 x + 2.00000, ∀x ∈ [-2.00000, 2.00000]
source
perspective(f::PiecewiseQuadratic, α::Real)

Return the perspective function of f. That is, given f(x) and α, return α * f(x / α).

Note: that this operation requires scaling of the domain.

See also: perspective!

Example

julia> f = PiecewiseQuadratic([BoundedQuadratic(-1., 0., 0., -5., 0.),
                               BoundedQuadratic(0., 2., 0., 2., 0.)])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 5.00000 x , ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = + 2.00000 x , ∀x ∈ [0.00000, 2.00000]

julia> persp = perspective(f, 5.)
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 5.00000 x , ∀x ∈ [-5.00000, 0.00000]
BoundedQuadratic: f(x) = + 2.00000 x , ∀x ∈ [0.00000, 10.00000]
source
PiecewiseQuadratics.perspective!Function
perspective!(f::BoundedQuadratic, α::Real)
perspective!(f::BoundedQuadratic, α::Real, out::BoundedQuadratic)

Shift perspective of f inplace.

See also: perspective

source
perspective!(f::PiecewiseQuadratic, α::Real)
perspective!(f::PiecewiseQuadratic, α::Real, out::PiecewiseQuadratic)

Shift perspective of f inplace.

See also: perspective

source
PiecewiseQuadratics.shiftFunction
shift(f::BoundedQuadratic, δ::Real)

Return f shifted along the x-axis by δ.

Note: for δ > 0, this is a right shift. For δ < 0, this is a left shift.

See also: shift!

Example

julia> bq = BoundedQuadratic(-1., 1., 1., 1., 1.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-1.00000, 1.00000]

julia> shift(bq, 2.)
BoundedQuadratic: f(x) = 1.00000 x² - 3.00000 x + 3.00000, ∀x ∈ [1.00000, 3.00000]
source
shift(f::PiecewiseQuadratic, δ::Real)

Return f shifted along the x-axis by δ.

Note: for δ > 0, this is a right shift. For δ < 0, this is a left shift.

See also: shift!

Example

julia> f = PiecewiseQuadratic([BoundedQuadratic(-1., 0., 0., -5., 0.),
                               BoundedQuadratic(0., 2., 0., 2., 0.)])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 5.00000 x , ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = + 2.00000 x , ∀x ∈ [0.00000, 2.00000]

julia> shift(f, 5.)
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 5.00000 x + 25.00000, ∀x ∈ [4.00000, 5.00000]
BoundedQuadratic: f(x) = + 2.00000 x - 10.00000, ∀x ∈ [5.00000, 7.00000]
source
PiecewiseQuadratics.shift!Function
shift!(f::BoundedQuadratic, δ::Real)
shift!(f::BoundedQuadratic, δ::Real, out::BoundedQuadratic)

Shift f inplace along the x-axis by δ.

See also: shift

source
shift!(f::PiecewiseQuadratic, δ::Real)
shift!(f::PiecewiseQuadratic, δ::Real, out::PiecewiseQuadratic)

Shift f inplace along the x-axis by δ.

See also: shift

source
PiecewiseQuadratics.tiltFunction
tilt(f::BoundedQuadratic, α::Real)

Return f tilted by α. This shifts linear coefficient q by α.

See also: tilt!

Example

julia> bq = BoundedQuadratic(-1., 1., 1., 1., 1.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-1.00000, 1.00000]

julia> tilt(bq, 2.)
BoundedQuadratic: f(x) = 1.00000 x² + 3.00000 x + 1.00000, ∀x ∈ [-1.00000, 1.00000]
source
tilt(f::PiecewiseQuadratic, α::Real)

Return f tilted by α. This shifts linear coefficient q by α.

See also: tilt!

Example

julia> f = PiecewiseQuadratic([BoundedQuadratic(-1., 0., 0., -5., 0.),
                               BoundedQuadratic(0., 2., 0., 2., 0.)])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 5.00000 x , ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = + 2.00000 x , ∀x ∈ [0.00000, 2.00000]

julia> tilt(f, 5.)
Piecewise quadratic function:
BoundedQuadratic: f(x) = 0, ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = + 7.00000 x , ∀x ∈ [0.00000, 2.00000]
source
PiecewiseQuadratics.tilt!Function
tilt!(f::BoundedQuadratic, α::Real)
tilt!(f::BoundedQuadratic, α::Real, out::BoundedQuadratic)

Tilt f inplace.

See also: tilt

source
tilt!(f::PiecewiseQuadratic, α::Real)
tilt!(f::PiecewiseQuadratic, α::Real, out::PiecewiseQuadratic)

Tilt f inplace.

source
PiecewiseQuadratics.restrict_domFunction
restrict_dom(f::BoundedQuadratic, dom::Interval)
restrict_dom(f::BoundedQuadratic, lb::Real, ub::Real)

Return a new BoundedQuadratic with domain restricted to the intersect of the passed domain.

See also: restrict_dom!

Example

julia> bq = BoundedQuadratic(-10., 10., 1., 1., 1.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-10.00000, 10.00000]

julia> restrict_dom(bq, 2., 3.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [2.00000, 3.00000]
source
PiecewiseQuadratics.restrict_dom!Function
restrict_dom!(f::BoundedQuadratic, dom::Interval)
restrict_dom!(f::BoundedQuadratic, lb::Real, ub::Real)
restrict_dom!(f::BoundedQuadratic, lb::Real, ub::Real, out::BoundedQuadratic)

Restrict domain of f inplace.

See also: restrict_dom

source
PiecewiseQuadratics.extend_domFunction
extend_dom(f::BoundedQuadratic)

Return an unbounded version of f.

See also: extend_dom!

Example

julia> bq = BoundedQuadratic(-1., 1., 1., 1., 1.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-1.00000, 1.00000]

julia> extend_dom(bq)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ ℝ
source
Base.append!Function
append!(f::PiecewiseQuadratic, g::PiecewiseQuadratic; simplify_result=false)

Append a PiecewiseQuadratic g to the right hand side of PiecewiseQuadratic f.

source
Base.push!Function
 push!(f::PiecewiseQuadratic, g::BoundedQuadratic; simplify_result=false)

Add a BoundedQuadratic g to the right hand side of PiecewiseQuadratic f.

source
PiecewiseQuadratics.simplifyFunction
 simplify(f::PiecewiseQuadratic)

Return a simplified piecewise quadratic f.

A BoundedQuadratic f_i and and the current rightmost piece should be combined (to become the new rightmost piece) if

  • Either of f_i or the rightmost piece is a point and they overlap at their lower and upper endpoints respectively
  • f_i and the rightmost piece have the same coefficients and they correspond at their lower and upper endpoints respectively (they're just currently separate parts of the same function).

We also eliminate functions that are points at Inf or -Inf if they come up.

Example

julia> f = PiecewiseQuadratic([BoundedQuadratic(-1., 0., 0., -1., 0.),
                                      BoundedQuadratic(0., 0., 0., 0., 0.),
                                      BoundedQuadratic(0., 1., 0., 1., 0.),
                                      BoundedQuadratic(1., 2., 0., 1., 0.),
                                      BoundedQuadratic(3., 5., 1., 1., 1.)])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 1.00000 x , ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = 0, ∀x ∈ [0.00000, 0.00000]
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [0.00000, 1.00000]
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [1.00000, 2.00000]
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [3.00000, 5.00000]

julia> simplify(f)
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 1.00000 x , ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [0.00000, 2.00000]
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [3.00000, 5.00000]
source

Utility

PiecewiseQuadratics.domainFunction
domain(f::BoundedQuadratic)

Return the Interval on which the BoundedQuadratic is defined.

Example

julia> bq = BoundedQuadratic(0., 5., 3., 2., 1.)
BoundedQuadratic: f(x) = 3.00000 x² + 2.00000 x + 1.00000, ∀x ∈ [0.00000, 5.00000]

julia> dom = domain(bq)
[0.00000, 5.00000]
source
Base.intersectFunction
intersect(f_list::Vector{BoundedQuadratic})

Intersect the domains of a list of BoundedQuadratics if possible.

Example

julia> f_list = [BoundedQuadratic(-100, 100, 1, 1, 1),
          BoundedQuadratic(-50, 25, 1, 1, 1),
          BoundedQuadratic(0, 50, 1, 1, 1)]
3-element Vector{BoundedQuadratic}:
 BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-100.00000, 100.00000]

 BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-50.00000, 25.00000]

 BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [0.00000, 50.00000]

julia> out, valid = intersect(f_list);

julia> valid
true

julia> out
3-element Vector{BoundedQuadratic}:
 BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [0.00000, 25.00000]

 BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [0.00000, 25.00000]

 BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [0.00000, 25.00000]


julia> f_list = [BoundedQuadratic(-100, 0, 1,1,1)
            BoundedQuadratic(25, 50, 1,1,1)]  # non-overlapping
2-element Vector{BoundedQuadratic}:
 BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-100.00000, 0.00000]

 BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [25.00000, 50.00000]

julia> out, valid = intersect(f_list);

julia> valid
false

julia> out
2-element Vector{BoundedQuadratic}:
 #undef
 #undef
source
PiecewiseQuadratics.derivativeFunction
derivative(f::BoundedQuadratic)

Return the derivative of f, f'

Example

julia> bq = BoundedQuadratic(3., 2., 1.)
BoundedQuadratic: f(x) = 3.00000 x² + 2.00000 x + 1.00000, ∀x ∈ ℝ

julia> derivative(bq)
BoundedQuadratic: f(x) = + 6.00000 x + 2.00000, ∀x ∈ ℝ
source
derivative(f::BoundedQuadratic, x::Real)

Evaluate the derivative of f at x, f'(x).

Example

julia> bq = BoundedQuadratic(3., 2., 1.)
BoundedQuadratic: f(x) = 3.00000 x² + 2.00000 x + 1.00000, ∀x ∈ ℝ

julia> derivative(bq, 2.)
14.0
source
Base.sumFunction
sum(f_list::Vector{BoundedQuadratic})

Return the BoundedQuadratic sum of a list of BoundedQuadratics if it is valid, else nothing.

Example

julia> bq = BoundedQuadratic(-1., 5., 1., 2., 3.)
BoundedQuadratic: f(x) = 1.00000 x² + 2.00000 x + 3.00000, ∀x ∈ [-1.00000, 5.00000]

julia> sum([bq, bq])
BoundedQuadratic: f(x) = 2.00000 x² + 4.00000 x + 6.00000, ∀x ∈ [-1.00000, 5.00000]
source
sum(f_list::Vector{PiecewiseQuadratic})

Return the PiecewiseQuadratic sum of a list of PiecewiseQuadratics.

Example

julia> f = PiecewiseQuadratic([BoundedQuadratic(-1., 0., 0., -5., 0.),
                               BoundedQuadratic(0., 2., 0., 2., 0.)])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 5.00000 x , ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = + 2.00000 x , ∀x ∈ [0.00000, 2.00000]

julia> sum([f,f])
Piecewise quadratic function:
BoundedQuadratic: f(x) = - 10.00000 x , ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = + 4.00000 x , ∀x ∈ [0.00000, 2.00000]

julia> sum([f,-f])
Piecewise quadratic function:
BoundedQuadratic: f(x) = 0, ∀x ∈ [-1.00000, 0.00000]
BoundedQuadratic: f(x) = 0, ∀x ∈ [0.00000, 2.00000]
source
PiecewiseQuadratics.get_tangentFunction
get_tangent(f::BoundedQuadratic, x::Real)

Construct a new unbounded BoundedQuadratic representing the (unbounded) tangent line to f at the point x.

Example

julia> bq = BoundedQuadratic(-1., 1., 1., 1., 1.)
BoundedQuadratic: f(x) = 1.00000 x² + 1.00000 x + 1.00000, ∀x ∈ [-1.00000, 1.00000]

julia> tangent = get_tangent(bq, 0.5)
BoundedQuadratic: f(x) = + 2.00000 x + 0.75000, ∀x ∈ ℝ
source

Optimization

PiecewiseQuadratics.minimizeFunction
minimize(f::BoundedQuadratic)

Return the minimum x and f(x) of f over its domain.

source
minimize(f::PiecewiseQuadratic)

Return the minimum x and f(x) of f over its domain.

source
PiecewiseQuadratics.envelopeFunction
envelope(f::PiecewiseQuadratic)

Computes the greatest convex lower bound of a PiecewiseQuadratic f.

Example

julia> f = PiecewiseQuadratic([BoundedQuadratic(-Inf, 0., 0., 1., 0.),
                               BoundedQuadratic(0., 3., 0., 0., 0.)])
Piecewise quadratic function:
BoundedQuadratic: f(x) = + 1.00000 x , ∀x ∈ [-Inf, 0.00000]
BoundedQuadratic: f(x) = 0, ∀x ∈ [0.00000, 3.00000]

julia> envelope(f)
Piecewise quadratic function:
BoundedQuadratic: f(x) = + 1.00000 x - 3.00000, ∀x ∈ [-Inf, 3.00000]
source
PiecewiseQuadratics.proxFunction
prox(f::PiecewiseQuadratic, u::Float64[, ρ::Float64=1.0]; use_quadratic::Bool=true)

Return the proximal operator of f, ρ evaluated at u.

Note: The proximal operator of f, rho is denoted:

\[prox_{f, rho}(u) = argmin_{x ∈ dom(f)} f(x) + (rho / 2)||x - u||_2^2\]

See Section 6.2 of arXiv:2103.05455 for more information.

source

Plotting

PiecewiseQuadratics.get_plotFunction
get_plot(f::PiecewiseQuadratic; N::Int64=1000)

Return x, y N-vectors for use with plotting libraries.

Example

julia> using Plots

julia> f = PiecewiseQuadratic([
         BoundedQuadratic(-Inf, 3.0, 1.0, -3.0, 3.0),
         BoundedQuadratic(3.0, 4.0, 0.0, -1.0, 3.0),
         BoundedQuadratic(4.0, 6.0, 2.0, -20.0, 47.0),
         BoundedQuadratic(6.0, 7.5, 0.0, 1.0, -7.0),
         BoundedQuadratic(7.5, Inf, 0.0, 4.0, -29.0)
       ])
Piecewise quadratic function:
BoundedQuadratic: f(x) = 1.00000 x² - 3.00000 x + 3.00000, ∀x ∈ [-Inf, 3.00000]
BoundedQuadratic: f(x) = - 1.00000 x + 3.00000, ∀x ∈ [3.00000, 4.00000]
BoundedQuadratic: f(x) = 2.00000 x² - 20.00000 x + 47.00000, ∀x ∈ [4.00000, 6.00000]
BoundedQuadratic: f(x) = + 1.00000 x - 7.00000, ∀x ∈ [6.00000, 7.50000]
BoundedQuadratic: f(x) = + 4.00000 x - 29.00000, ∀x ∈ [7.50000, Inf]

julia> plot(get_plot(f); grid=false, linestyle=:dash, color=:black, label="piece-wise quadratic")
Plot{Plots.GRBackend() n=1}

julia> plot!(get_plot(simplify(envelope(f))); color=:blue, la=0.5, label="envelope")
Plot{Plots.GRBackend() n=2}
source