| Title: | Disciplined Convex Optimization |
|---|---|
| Description: | An object-oriented modeling language for disciplined convex programming (DCP) as described in Fu, Narasimhan, and Boyd (2020, <doi:10.18637/jss.v094.i14>). It allows the user to formulate convex optimization problems in a natural way following mathematical convention and DCP rules. The system analyzes the problem, verifies its convexity, converts it into a canonical form, and hands it off to an appropriate solver to obtain the solution. This version uses the S7 object system for improved performance and maintainability. |
| Authors: | Anqi Fu [aut, cre], Balasubramanian Narasimhan [aut], Steven Diamond [aut], John Miller [aut], Stephen Boyd [ctb] |
| Maintainer: | Anqi Fu <[email protected]> |
| License: | Apache License 2.0 | file LICENSE |
| Version: | 1.8.2-1 |
| Built: | 2026-05-21 07:13:29 UTC |
| Source: | https://github.com/cvxgrp/cvxr |
Creates an NSD constraint: e2 - e1 is positive semidefinite,
i.e., e1 is NSD relative to e2.
This is the R equivalent of Python's A << B.
e1 %<<% e2e1 %<<% e2
e1, e2
|
CVXR expressions or numeric matrices. |
A PSD constraint object.
## Not run: X <- Variable(3, 3, symmetric = TRUE) constr <- X %<<% diag(3) # I - X is PSD (X is NSD relative to I) ## End(Not run)## Not run: X <- Variable(3, 3, symmetric = TRUE) constr <- X %<<% diag(3) # I - X is PSD (X is NSD relative to I) ## End(Not run)
Creates a PSD constraint: e1 - e2 is positive semidefinite.
This is the R equivalent of Python's A >> B.
e1 %>>% e2e1 %>>% e2
e1, e2
|
CVXR expressions or numeric matrices. |
A PSD constraint object.
## Not run: X <- Variable(3, 3, symmetric = TRUE) constr <- X %>>% diag(3) # X - I is PSD ## End(Not run)## Not run: X <- Variable(3, 3, symmetric = TRUE) constr <- X %>>% diag(3) # X - I is PSD ## End(Not run)
Returns 1 if and only if all arguments equal 1, and 0 otherwise.
For two operands, can also be written with the & operator: x & y.
And(..., id = NULL)And(..., id = NULL)
... |
Two or more boolean Variables or logic expressions. |
id |
Optional integer ID (internal use). |
An And expression.
Not(), Or(), Xor(), implies(), iff()
## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) both <- x & y # operator syntax both <- And(x, y) # functional syntax all3 <- And(x, y, z) # n-ary ## End(Not run)## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) both <- x & y # operator syntax both <- And(x, y) # functional syntax all3 <- And(x, y, z) # n-ary ## End(Not run)
Wraps numeric vectors, matrices, and Matrix package objects as CVXR Constant objects. Values that are already CVXR expressions are returned unchanged.
as_cvxr_expr(x)as_cvxr_expr(x)
x |
A numeric vector, matrix, Matrix::Matrix object, Matrix::sparseVector object, or CVXR expression. |
A CVXR expression (either the input unchanged or wrapped in Constant).
Objects from the Matrix package (dgCMatrix, dgeMatrix,
ddiMatrix, sparseVector, etc.) are S4 classes.
Because S4 dispatch preempts S7/S3 dispatch, raw Matrix objects cannot be
used directly with CVXR operators (+, -, *, /, %*%, >=, ==,
etc.).
Use as_cvxr_expr() to wrap a Matrix object as a CVXR Constant before
combining it with CVXR variables or expressions. This preserves sparsity
(unlike as.matrix(), which densifies).
Base R matrix and numeric objects work natively with CVXR operators —
no wrapping is needed.
x <- Variable(3) ## Sparse Matrix needs as_cvxr_expr() for CVXR operator dispatch: A <- Matrix::sparseMatrix(i = 1:3, j = 1:3, x = 1.0) expr <- as_cvxr_expr(A) %*% x ## All operators work with wrapped Matrix objects: y <- Variable(c(3, 3)) expr2 <- as_cvxr_expr(A) + y constr <- as_cvxr_expr(A) >= y ## Base R matrix works natively (no wrapping needed): D <- matrix(1:9, 3, 3) expr3 <- D %*% xx <- Variable(3) ## Sparse Matrix needs as_cvxr_expr() for CVXR operator dispatch: A <- Matrix::sparseMatrix(i = 1:3, j = 1:3, x = 1.0) expr <- as_cvxr_expr(A) %*% x ## All operators work with wrapped Matrix objects: y <- Variable(c(3, 3)) expr2 <- as_cvxr_expr(A) + y constr <- as_cvxr_expr(A) >= y ## Base R matrix works natively (no wrapping needed): D <- matrix(1:9, 3, 3) expr3 <- D %*% x
Returns the names of installed solvers that are not currently excluded.
Use exclude_solvers() to temporarily disable solvers.
available_solvers() exclude_solvers(solvers) include_solvers(solvers) set_excluded_solvers(solvers)available_solvers() exclude_solvers(solvers) include_solvers(solvers) set_excluded_solvers(solvers)
solvers |
A character vector of solver names. |
A character vector of solver names.
The current exclusion list (character vector), invisibly.
exclude_solvers(): Add solvers to the exclusion list
include_solvers(): Remove solvers from the exclusion list
set_excluded_solvers(): Replace the entire exclusion list
installed_solvers(), exclude_solvers(), include_solvers(), set_excluded_solvers()
Differentiates through the solution map of problem: populates
the gradient slot of each Parameter with the sensitivity of
a scalar-valued function of the variables (defaulting to the
sum-of-x loss; override per variable by setting
gradient(variable) <- before calling) with respect to that
parameter. Mirrors cvxpy.Problem.backward().
backward(problem)backward(problem)
problem |
A solved |
Must be called after psolve() with requires_grad = TRUE.
The problem (for piping); side-effect sets
gradient(param) on each parameter.
derivative(), psolve(), gradient()
Takes a list of lists. Each internal list is stacked horizontally. The internal lists are stacked vertically.
bmat(block_lists)bmat(block_lists)
block_lists |
A list of lists of Expression objects (or numerics). Each inner list forms one block row. |
An Expression representing the block matrix.
A Parameter whose value is computed by a user-supplied callback
function rather than stored explicitly. Mirrors CVXPY's
cp.CallbackParam (cvxpy/expressions/constants/callback_param.py).
CallbackParam( callback, shape = c(1L, 1L), name = NULL, id = NULL, latex_name = NULL, ... )CallbackParam( callback, shape = c(1L, 1L), name = NULL, id = NULL, latex_name = NULL, ... )
callback |
A function (no arguments) returning the parameter's
numeric value. Re-evaluated on every read of |
shape |
Integer vector of length 1 or 2 giving parameter
dimensions. Defaults to |
name |
Optional character string name. |
id |
Optional integer ID. If |
latex_name |
Optional LaTeX name for visualisation. |
... |
Other Parameter attributes (e.g., |
Each call to value(param) re-evaluates the callback and validates
the returned numeric against the parameter's shape and attribute
domain. Setting via value(param) <- v is not allowed and signals
an error.
A CallbackParam object (subclass of Parameter).
If p and q are scalar Parameters, the expression p * q is
not DPP. Wrapping it in a CallbackParam,
pq <- CallbackParam(callback = function() value(p) * value(q))
yields a DPP-compliant Parameter whose value tracks p and q
automatically.
p <- Parameter(); value(p) <- 2 q <- Parameter(); value(q) <- 3 pq <- CallbackParam(callback = function() value(p) * value(q)) value(pq) # evaluates the callback => 6p <- Parameter(); value(p) <- 2 q <- Parameter(); value(q) <- 3 pq <- CallbackParam(callback = function() value(p) * value(q)) value(pq) # evaluates the callback => 6
Global Monthly and Annual Temperature Anomalies (degrees C), 1850-2015 (Relative to the 1961-1990 Mean) (May 2016)
cdiaccdiac
A data frame with 166 rows and 14 variables:
Year
Anomaly for month of January
Anomaly for month of February
Anomaly for month of March
Anomaly for month of April
Anomaly for month of May
Anomaly for month of June
Anomaly for month of July
Anomaly for month of August
Anomaly for month of September
Anomaly for month of October
Anomaly for month of November
Anomaly for month of December
Annual anomaly for the year
Returns the ceiling (smallest integer >= x) of each element.
This atom is quasiconvex and quasiconcave but NOT convex or concave,
so it can only be used in DQCP problems (solved with qcp = TRUE).
ceil_expr(x)ceil_expr(x)
x |
A CVXR expression. |
A Ceil expression.
Computes the condition number lambda_max(A) / lambda_min(A) for a positive semidefinite matrix A. This is a quasiconvex atom.
condition_number(A)condition_number(A)
A |
A square matrix expression (must be PSD) |
An expression representing the condition number of A
Wraps a numeric value as a CVXR constant for use in optimization expressions. Constants are typically created implicitly when combining numeric values with CVXR expressions via arithmetic operators.
Constant(value, name = NULL)Constant(value, name = NULL)
value |
A numeric scalar, vector, matrix, or sparse matrix. |
name |
Optional character string name. |
A Constant object (inherits from Leaf and
Expression).
c1 <- Constant(5) c2 <- Constant(matrix(1:6, 2, 3))c1 <- Constant(5) c2 <- Constant(matrix(1:6, 2, 3))
Get the Constants in an Expression
constants(x, ...)constants(x, ...)
x |
An expression or problem object. |
... |
Not used. |
List of Constant objects.
Returns a copy of the problem's constraint list.
constraints(x)constraints(x)
x |
A Problem object. |
Problem objects are immutable: constraints cannot be modified after
construction. To change constraints, create a new Problem().
This matches CVXPY's design where problems are immutable except
through Parameter value changes.
A list of constraint objects.
x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(x >= 1)) length(constraints(prob)) # 1x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(x >= 1)) length(constraints(prob)) # 1
1D discrete convolution
conv(a, b)conv(a, b)
a |
An Expression (vector, one must be constant) |
b |
An Expression (vector) |
A Convolve atom
Cumulative maximum along an axis
cummax_expr(x, axis = 2L)cummax_expr(x, axis = 2L)
x |
An Expression |
axis |
1 (across rows) or 2 (down columns, default) |
A Cummax atom
Cumulative sum along an axis
cumsum_axis(x, axis = NULL)cumsum_axis(x, axis = NULL)
x |
An Expression |
axis |
NULL (all), 1 (across rows), or 2 (down columns) |
A Cumsum atom
Returns the DCP curvature of an expression as a string.
curvature(x)curvature(x)
x |
A CVXR expression. |
Character: "CONSTANT", "AFFINE", "CONVEX", "CONCAVE",
or "UNKNOWN".
is_convex(), is_concave(), is_affine(), is_constant()
CVaR at confidence level beta: average of the (1-beta) largest values.
cvar(x, beta)cvar(x, beta)
x |
An Expression (vector) |
beta |
Confidence level in [0, 1) |
An Expression representing the CVaR
Takes in an expression and returns an expression with the kth order differences along the given axis. The output shape is the same as the input except the size along the specified axis is reduced by k.
cvxr_diff(x, k = 1L, axis = 2L)cvxr_diff(x, k = 1L, axis = 2L)
x |
An Expression or numeric value. |
k |
Integer. The number of times values are differenced. Default is 1.
(Mapped from R's |
axis |
Integer. The axis along which the difference is taken. 2 = along rows/down columns (default), 1 = along columns/across rows. |
An Expression representing the kth order differences.
Computes the arithmetic mean of an expression along an axis.
cvxr_mean(x, axis = NULL, keepdims = FALSE)cvxr_mean(x, axis = NULL, keepdims = FALSE)
x |
An Expression or numeric value. |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise). |
keepdims |
Logical; keep reduced dimension? |
An Expression representing the mean.
Compute a norm of an expression
cvxr_norm(x, p = 2, axis = NULL, keepdims = FALSE, max_denom = 1024L)cvxr_norm(x, p = 2, axis = NULL, keepdims = FALSE, max_denom = 1024L)
x |
An Expression |
p |
Norm type: 1, 2, Inf, or "fro" (Frobenius) |
axis |
NULL (all), 0 (columns), or 1 (rows) |
keepdims |
Logical |
max_denom |
Integer max denominator |
A norm atom
Computes the outer product x %*% t(y). Both inputs must be vectors.
cvxr_outer(x, y)cvxr_outer(x, y)
x |
An Expression or numeric value (vector). |
y |
An Expression or numeric value (vector). |
An Expression of shape (length(x), length(y)).
Computes the standard deviation of an expression.
cvxr_std(x, axis = NULL, keepdims = FALSE, ddof = 0) std(x, axis = NULL, keepdims = FALSE, ddof = 0)cvxr_std(x, axis = NULL, keepdims = FALSE, ddof = 0) std(x, axis = NULL, keepdims = FALSE, ddof = 0)
x |
An Expression or numeric value. |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise). |
keepdims |
Logical; keep reduced dimension? |
ddof |
Degrees of freedom correction (default 0, population std). |
An Expression representing the standard deviation.
Computes the variance. Only supports full reduction (axis = NULL).
cvxr_var(x, axis = NULL, keepdims = FALSE, ddof = 0)cvxr_var(x, axis = NULL, keepdims = FALSE, ddof = 0)
x |
An Expression or numeric value. |
axis |
NULL only (axis reduction not yet supported). |
keepdims |
Logical; keep reduced dimension? |
ddof |
Degrees of freedom correction (default 0, population variance). |
An Expression representing the variance.
delta of a Variable or ParameterUsed by psolve() with requires_grad = TRUE and
Problem$derivative(). On a Parameter, the user sets delta
to a perturbation of the parameter's value; derivative() then
reports the predicted change in each Variable's optimal value
as delta(variable).
delta(x) delta(x) <- valuedelta(x) delta(x) <- value
x |
A |
value |
A numeric array of the same shape as |
The perturbation (numeric array) or NULL.
Forward-mode counterpart of backward(): reads delta(param) for
each parameter, applies the cone-program derivative, and writes
the predicted change in each variable's optimum to delta(var).
Mirrors cvxpy.Problem.derivative().
derivative(problem)derivative(problem)
problem |
A solved |
Must be called after psolve() with requires_grad = TRUE.
The problem (for piping); side-effect sets
delta(variable) on each variable.
Extracts the k-th diagonal of a square matrix as a column vector.
DiagMat(x, k = 0L, id = NULL)DiagMat(x, k = 0L, id = NULL)
x |
A CVXR expression (square matrix). |
k |
Integer diagonal offset. |
id |
Optional integer ID. |
A DiagMat expression of shape
c(n - abs(k), 1).
Constructs a diagonal matrix from a column vector. If k != 0,
the vector is placed on the k-th super- or sub-diagonal.
DiagVec(x, k = 0L, id = NULL)DiagVec(x, k = 0L, id = NULL)
x |
A CVXR expression (column vector). |
k |
Integer diagonal offset. |
id |
Optional integer ID. |
A DiagVec expression of shape
c(n + abs(k), n + abs(k)).
Equivalent to x * one_minus_pos(y / x).
diff_pos(x, y)diff_pos(x, y)
x |
An Expression (positive) |
y |
An Expression (positive, elementwise less than x) |
A product expression
Computes norm(x - a)_2 / norm(x - b)_2, where a and b are constants. This is a quasiconvex atom.
dist_ratio(x, a, b)dist_ratio(x, a, b)
x |
A vector expression |
a |
A numeric constant vector |
b |
A numeric constant vector |
An expression representing the distance ratio
Computes <sort(vec(X)), sort(vec(W))> where X is an expression and W is a
constant. A generalization of sum_largest and sum_smallest.
dotsort(X, W)dotsort(X, W)
X |
An Expression or numeric value. |
W |
A constant numeric vector or matrix. |
A scalar convex Expression.
Randomly generated data for direct standardization example.
Sex was drawn from a Bernoulli distribution, and age was drawn from a uniform distribution on .
The response was drawn from a normal distribution with a mean that depends on sex and age, and a variance of 1.
dspopdspop
A data frame with 1000 rows and 3 variables:
Response variable
Sex of individual, coded male (0) and female (1)
Age of individual
A sample of dspop for direct standardization example.
The sample is skewed such that young males are overrepresented in comparison to the population.
dssampdssamp
A data frame with 100 rows and 3 variables:
Response variable
Sex of individual, coded male (0) and female (1)
Age of individual
Returns the dual variable value(s) associated with a constraint
after solving. Returns NULL before the problem is solved.
dual_value(x)dual_value(x)
x |
A |
A numeric matrix (single dual variable) or a list of
numeric matrices (multiple dual variables), or NULL.
Create an entropy atom -x * log(x)
entr(x)entr(x)
x |
An Expression |
An Entr atom
Constrains two expressions to be equal elementwise: .
Typically created via the == operator on CVXR expressions.
Equality(lhs, rhs, constr_id = NULL)Equality(lhs, rhs, constr_id = NULL)
lhs |
A CVXR expression (left-hand side). |
rhs |
A CVXR expression (right-hand side). |
constr_id |
Optional integer constraint ID. |
An Equality constraint object.
Constrains to lie in the exponential cone:
ExpCone(x_expr, y_expr, z_expr, constr_id = NULL)ExpCone(x_expr, y_expr, z_expr, constr_id = NULL)
x_expr |
A CVXR expression. |
y_expr |
A CVXR expression. |
z_expr |
A CVXR expression. |
constr_id |
Optional integer constraint ID. |
All three arguments must be affine, real, and have the same shape.
An ExpCone constraint object.
Equivalent to CVXPY's .H property. For real expressions, returns
t(x). For complex expressions, returns Conj(t(x)).
expr_H(x)expr_H(x)
x |
A CVXR Expression. |
The conjugate-transpose expression.
Returns the sign of an expression under DCP analysis. Use this instead
of sign(), which conflicts with the base R function.
expr_sign(x, ...)expr_sign(x, ...)
x |
An expression object. |
... |
Not used. |
Character string: "POSITIVE", "NEGATIVE",
"ZERO", or "UNKNOWN".
Log-log convex atom for DGP. Solve with
psolve(problem, gp = TRUE).
eye_minus_inv(X)eye_minus_inv(X)
X |
An Expression (positive square matrix with spectral radius < 1) |
An EyeMinusInv atom
X <- Variable(c(2, 2), pos = TRUE) prob <- Problem(Minimize(sum(eye_minus_inv(X))), list(X <= 0.4)) ## Not run: psolve(prob, gp = TRUE, solver = "SCS")X <- Variable(c(2, 2), pos = TRUE) prob <- Problem(Minimize(sum(eye_minus_inv(X))), list(X <= 0.4)) ## Not run: psolve(prob, gp = TRUE, solver = "SCS")
Constrain each entry of an Expression to take a value in a given finite set of real numbers.
FiniteSet(expre, vec, ineq_form = FALSE, constr_id = NULL)FiniteSet(expre, vec, ineq_form = FALSE, constr_id = NULL)
expre |
An affine Expression. |
vec |
A numeric vector (or set) of allowed values. |
ineq_form |
Logical; controls MIP canonicalization strategy.
If |
constr_id |
Optional integer constraint ID (internal use). |
A FiniteSet constraint.
Returns the floor (largest integer <= x) of each element.
This atom is quasiconvex and quasiconcave but NOT convex or concave,
so it can only be used in DQCP problems (solved with qcp = TRUE).
floor_expr(x)floor_expr(x)
x |
A CVXR expression. |
A Floor expression.
Recursive analogue of expr_name() that substitutes user-supplied
labels (see set_label()) for sub-expressions wherever they are set,
falling back to the structural name on unlabelled nodes. Mirrors
CVXPY's Expression.format_labeled.
format_labeled(x)format_labeled(x)
x |
An Expression object. |
A character string.
Computes the maximum generalized eigenvalue lambda_max(A, B). Requires A symmetric and B positive semidefinite. This is a quasiconvex atom.
gen_lambda_max(A, B)gen_lambda_max(A, B)
A |
A square symmetric matrix expression |
B |
A square PSD matrix expression of the same dimension as A |
An expression representing the maximum generalized eigenvalue
(Weighted) geometric mean of a vector
geo_mean(x, p = NULL, max_denom = 1024L, approx = TRUE)geo_mean(x, p = NULL, max_denom = 1024L, approx = TRUE)
x |
An Expression (vector) |
p |
Numeric weight vector (default: uniform) |
max_denom |
Maximum denominator for rational approximation |
approx |
If TRUE (default), use SOC approximation. If FALSE, use exact power cone. |
A GeoMean or GeoMeanApprox atom
get_problem_data(x, solver = NULL, ...)get_problem_data(x, solver = NULL, ...)
x |
A |
solver |
Character string naming solver, or |
... |
Additional arguments. |
Use problem_data instead.
A list with components data, chain, and
inverse_data.
Computes the geometric matrix product where (A diamond X)_ij = prod_k X_kj^A_ik.
Log-log affine atom for DGP. Solve with
psolve(problem, gp = TRUE).
gmatmul(A, X)gmatmul(A, X)
A |
A constant matrix |
X |
An Expression (positive matrix) |
A Gmatmul atom
x <- Variable(2, pos = TRUE) A <- matrix(c(1, 0, 0, 1), 2, 2) prob <- Problem(Minimize(sum(gmatmul(A, x))), list(x >= 0.5)) ## Not run: psolve(prob, gp = TRUE)x <- Variable(2, pos = TRUE) A <- matrix(c(1, 0, 0, 1), 2, 2) prob <- Problem(Minimize(sum(gmatmul(A, x))), list(x >= 0.5)) ## Not run: psolve(prob, gp = TRUE)
Used by psolve() with requires_grad = TRUE and
Problem$backward(). Stores a numeric array of the same shape as
the leaf, or NULL (the default).
gradient(x) gradient(x) <- valuegradient(x) gradient(x) <- value
x |
A |
value |
A numeric array of the same shape as |
The gradient (numeric array) or NULL.
Harmonic mean: n / sum(1/x_i)
harmonic_mean(x)harmonic_mean(x)
x |
An Expression (must be positive for DCP) |
An Expression representing the harmonic mean
Horizontal concatenation of expressions
hstack(...)hstack(...)
... |
Expressions (same number of rows) |
An HStack atom
Create a Huber loss atom
huber(x, M = 1)huber(x, M = 1)
x |
An Expression |
M |
Numeric threshold (default 1) |
A Huber atom
Returns the unique integer identifier for a CVXR object.
id(x)id(x)
x |
A CVXR expression, variable, parameter, or constraint. |
An integer.
Logical biconditional: x <=> y.
Returns 1 if and only if x and y have the same value.
Equivalent to Not(Xor(x, y)).
iff(x, y)iff(x, y)
x, y
|
Boolean Variables or logic expressions. |
A Not expression wrapping Xor.
implies(), Not(), And(), Or(), Xor()
## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) expr <- iff(x, y) ## End(Not run)## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) expr <- iff(x, y) ## End(Not run)
Logical implication: x => y.
Returns 1 unless x = 1 and y = 0. Equivalent to Or(Not(x), y).
implies(x, y)implies(x, y)
x, y
|
Boolean Variables or logic expressions. |
An Or expression representing !x | y.
iff(), Not(), And(), Or(), Xor()
## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) expr <- implies(x, y) ## End(Not run)## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) expr <- implies(x, y) ## End(Not run)
Creates an expression that equals 0 if all constraints are satisfied and +Inf otherwise. Use this to embed constraints into the objective.
indicator(constraints, err_tol = 0.001)indicator(constraints, err_tol = 0.001)
constraints |
A list of constraint objects |
err_tol |
Numeric tolerance for checking constraint satisfaction (default 1e-3) |
An Indicator expression
Constrains the left-hand side to be less than or equal to the
right-hand side elementwise: . Typically created
via the <= operator on CVXR expressions.
Inequality(lhs, rhs, constr_id = NULL)Inequality(lhs, rhs, constr_id = NULL)
lhs |
A CVXR expression (left-hand side). |
rhs |
A CVXR expression (right-hand side). |
constr_id |
Optional integer constraint ID. |
An Inequality constraint object.
Returns the names of solvers whose R packages are available.
installed_solvers()installed_solvers()
A character vector of solver names.
(for x > 0)Inverse position: (for x > 0)
inv_pos(x)inv_pos(x)
x |
An Expression |
A Power atom with p=-1
Computes the reciprocal of the product of entries.
Equivalent to geo_mean(x)^(-n) where n is the number of entries.
inv_prod(x, approx = TRUE)inv_prod(x, approx = TRUE)
x |
An Expression or numeric value (must have positive entries). |
approx |
Logical; if TRUE (default), use SOC approximation. |
A convex Expression representing the reciprocal product.
Check if an Expression is Affine
is_affine(x, ...)is_affine(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if an Expression is Concave
is_concave(x, ...)is_concave(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if an Expression is Constant
is_constant(x, ...)is_constant(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if an Expression is Convex
is_convex(x, ...)is_convex(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Tests whether an expression follows the Disciplined Convex Programming (DCP) rules.
is_dcp(x, ...)is_dcp(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if a Constraint is DGP-Compliant
is_dgp(x, ...)is_dgp(x, ...)
x |
A constraint object. |
... |
Not used. |
Logical scalar.
Determines whether an expression or problem satisfies the rules of Disciplined Parameterized Programming (DPP). A DPP-compliant problem enables caching the compilation across parameter value changes.
is_dpp(x, ...)is_dpp(x, ...)
x |
An expression, constraint, or problem object. |
... |
Not used. |
Logical scalar.
Tests whether an expression follows the Disciplined Quasiconvex Programming (DQCP) rules.
is_dqcp(x, ...)is_dqcp(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Log-Log Affine
is_log_log_affine(x, ...)is_log_log_affine(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Log-Log Concave
is_log_log_concave(x, ...)is_log_log_concave(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Log-Log Convex
is_log_log_convex(x, ...)is_log_log_convex(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if a Problem is a Linear Program
is_lp(x, ...)is_lp(x, ...)
x |
A |
... |
Not used. |
Logical scalar.
Returns TRUE if the expression has both dimensions greater than 1.
is_matrix(x)is_matrix(x)
x |
A CVXR expression. |
Logical.
size(), is_scalar(), is_vector()
Returns TRUE if any variable in the problem has a
boolean or integer attribute.
is_mixed_integer(problem)is_mixed_integer(problem)
problem |
A |
Logical scalar.
Check if Expression is Non-Negative
is_nonneg(x, ...)is_nonneg(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Non-Positive
is_nonpos(x, ...)is_nonpos(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Negative Semidefinite
is_nsd(x, ...)is_nsd(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Positive Semidefinite
is_psd(x, ...)is_psd(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Piecewise Linear
Is the Expression Piecewise Linear?
is_pwl(x, ...)is_pwl(x, ...)
x |
A CVXR expression. |
... |
Not used. |
Logical scalar.
Logical.
Check if a Problem is a Quadratic Program
is_qp(x, ...)is_qp(x, ...)
x |
A |
... |
Not used. |
Logical scalar.
Check if an Expression is Quadratic
is_quadratic(x, ...)is_quadratic(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Quasiconcave
is_quasiconcave(x, ...)is_quasiconcave(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Quasiconvex
is_quasiconvex(x, ...)is_quasiconvex(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Check if Expression is Quasilinear
is_quasilinear(x, ...)is_quasilinear(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Is the Expression a Scalar?
is_scalar(x)is_scalar(x)
x |
A CVXR expression. |
Logical.
size(), is_vector(), is_matrix()
Check if Expression is Symmetric
is_symmetric(x, ...)is_symmetric(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
Returns TRUE if the expression has at most one dimension greater than 1.
is_vector(x)is_vector(x)
x |
A CVXR expression. |
Logical.
size(), is_scalar(), is_matrix()
Check if Expression is Zero
is_zero(x, ...)is_zero(x, ...)
x |
An expression object. |
... |
Not used. |
Logical scalar.
KL Divergence: x*log(x/y) - x + y
kl_div(x, y)kl_div(x, y)
x |
An Expression |
y |
An Expression |
A KlDiv atom
Kronecker product of two expressions
kron(a, b)kron(a, b)
a |
An Expression (one must be constant) |
b |
An Expression |
A Kron atom
Returns the human-readable label set via set_label() (or
label(x) <- ...), or NULL if no label has been set.
label(x)label(x)
x |
An Expression object. |
A length-1 character string, or NULL.
R replacement form of set_label(). label(x) <- value stores
value (coerced to character) in x's internal label slot; setting
to NULL clears the label. Equivalent to x <- set_label(x, value).
label(x) <- valuelabel(x) <- value
x |
An Expression object. |
value |
A character string, or |
x, invisibly, with the label updated.
Maximum eigenvalue
lambda_max(A)lambda_max(A)
A |
A square matrix expression |
An expression representing the maximum eigenvalue of A
Minimum eigenvalue
lambda_min(A)lambda_min(A)
A |
A square matrix expression |
An expression representing the minimum eigenvalue of A
Sum of largest k eigenvalues
lambda_sum_largest(A, k)lambda_sum_largest(A, k)
A |
A square matrix expression |
k |
Number of largest eigenvalues to sum (positive integer) |
An expression representing the sum of the k largest eigenvalues
Sum of smallest k eigenvalues
lambda_sum_smallest(A, k)lambda_sum_smallest(A, k)
A |
A square matrix expression |
k |
Number of smallest eigenvalues to sum (positive integer) |
An expression representing the sum of the k smallest eigenvalues
Returns the index of the last nonzero element of a vector (1-based).
This atom is quasiconvex but NOT convex, so it can only be used in
DQCP problems (solved with qcp = TRUE).
length_expr(x)length_expr(x)
x |
A CVXR vector expression. |
A Length expression (scalar).
Computes log(det(A)) for PSD matrix A.
log_det(A)log_det(A)
A |
A square PSD matrix expression |
An expression representing log(det(A))
Quadratic approximation of log(pnorm(x)) with modest accuracy over the range -4 to 4.
log_normcdf(x)log_normcdf(x)
x |
An Expression or numeric value. |
A concave Expression representing log(Phi(x)).
Log-sum-exp: log(sum(exp(x)))
log_sum_exp(x, axis = NULL, keepdims = FALSE)log_sum_exp(x, axis = NULL, keepdims = FALSE)
x |
An Expression |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Logical: keep reduced dimensions? |
A LogSumExp atom
Log(1 + x) – elementwise
log1p_atom(x) log1p_expr(x)log1p_atom(x) log1p_expr(x)
x |
An Expression |
A Log1p atom
Piecewise linear approximation of log(gamma(x)).
Has modest accuracy over the full range, approaching perfect accuracy
as x goes to infinity.
loggamma(x)loggamma(x)
x |
An Expression or numeric value (must be positive for DCP). |
A convex Expression representing log(gamma(x)).
Logistic function: log(1 + exp(x)) – elementwise
logistic(x)logistic(x)
x |
An Expression |
A Logistic atom
Make a CSC sparse diagonal matrix
make_sparse_diagonal_matrix(size, diagonal = NULL)make_sparse_diagonal_matrix(size, diagonal = NULL)
size |
number of rows or columns |
diagonal |
if specified, the diagonal values, in which case size is ignored |
a compressed sparse column diagonal matrix
CVXR registers methods so that standard R functions create the
appropriate atoms when applied to Expression objects.
For CVXR expressions, computes the matrix/vector norm atom.
For other inputs, falls through to Matrix::norm which
dispatches via S4 for both Matrix and base matrix objects.
For CVXR expressions, computes the standard deviation atom (ddof=0 by default,
matching CVXPY/numpy convention). For numeric inputs, falls through to
sd.
For CVXR expressions, computes the variance atom (ddof=0 by default).
For numeric inputs, falls through to var.
For CVXR expressions, computes the outer product of two vectors.
For other inputs, falls through to outer.
For CVXR expressions, dispatches to DiagVec (vector to
diagonal matrix) or DiagMat (extract diagonal from matrix),
matching CVXPY's cp.diag() behavior. For other inputs, falls
through to Matrix::diag which dispatches via S4 for both Matrix
and base matrix objects.
norm(x, type = "2", ...) sd(x, ...) var(x, ...) outer(X, Y, ...) diag(x, nrow, ncol, names = TRUE, k = 0L)norm(x, type = "2", ...) sd(x, ...) var(x, ...) outer(X, Y, ...) diag(x, nrow, ncol, names = TRUE, k = 0L)
x |
An Expression, matrix, vector, or scalar. |
type |
Norm type: |
... |
For non-Expression inputs: passed to |
X |
An Expression or numeric. |
Y |
An Expression or numeric. |
nrow |
For non-Expression: passed to |
ncol |
For non-Expression: passed to |
names |
For non-Expression: passed to |
k |
Integer diagonal offset for Expressions only. |
The k parameter (off-diagonal offset) is only available for
Expression inputs. For the full-featured version with k on
non-Expression inputs, use DiagVec or DiagMat
directly.
An Expression or numeric value.
An Expression or numeric value.
An Expression or numeric value.
An Expression or matrix.
An Expression, matrix, or vector.
abs(x)Absolute value (convex, nonneg)
exp(x)Exponential (convex, positive)
log(x)Natural logarithm (concave, domain x >= 0)
sqrt(x)Square root via power(x, 0.5) (concave)
log1p(x)log(1+x) compound expression (concave)
log2(x), log10(x)
Base-2/10 logarithm
cumsum(x)Cumulative sum (affine)
cummax(x)Cumulative max (convex)
cumprod(x)Cumulative product
ceiling(x), floor(x)
Round up/down (MIP)
sum(x)Sum all entries (affine)
max(x)Maximum entry (convex)
min(x)Minimum entry (concave)
mean(x)Arithmetic mean; pass axis/keepdims via ...
diff(x)First-order differences; also cvxr_diff
These mask the base/stats versions and dispatch on argument type:
norm(x)2-norm; use type for "1", "I" (infinity), "F" (Frobenius)
sd(x)Standard deviation (ddof=0 for expressions)
var(x)Variance (ddof=0 for expressions)
outer(X, Y)Outer product of two vector expressions
For axis-aware reductions, keepdims, or other options not available
through the standard interface, use the explicit functions:
cvxr_norm, cvxr_mean, cvxr_diff,
cvxr_std, cvxr_var, cvxr_outer.
power, sum_entries,
max_entries, min_entries
cvxr_norm for the full-featured version with
axis and keepdims arguments
cvxr_std for the full-featured version
cvxr_var for the full-featured version
cvxr_outer for the CVXR-specific version
Computes . If P is a constant matrix, uses
a QuadForm shortcut for efficiency.
matrix_frac(X, P)matrix_frac(X, P)
X |
A matrix expression (n by m) |
P |
A square matrix expression (n by n), must be PSD |
An expression representing
For matrix_trace(A %*% B), uses the O(n^2) identity
trace(A %*% B) = sum(A * t(B)) instead of forming the
full matrix product.
matrix_trace(x)matrix_trace(x)
x |
An Expression (square matrix) |
A Trace atom or equivalent expression (scalar)
Elementwise maximum of expressions
max_elemwise(...)max_elemwise(...)
... |
Expressions (at least 2) |
A Maximum atom
Maximum entry of an expression
max_entries(x, axis = NULL, keepdims = FALSE)max_entries(x, axis = NULL, keepdims = FALSE)
x |
An Expression |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Logical |
A MaxEntries atom
Specifies that the objective expression should be maximized. The expression must be concave and scalar for a DCP-compliant problem.
Maximize(expr)Maximize(expr)
expr |
A CVXR expression or numeric value to maximize. |
A Maximize object.
x <- Variable() obj <- Maximize(-x^2 + 1)x <- Variable() obj <- Maximize(-x^2 + 1)
Elementwise minimum of expressions
min_elemwise(...)min_elemwise(...)
... |
Expressions (at least 2) |
A Minimum atom
Minimum entry of an expression
min_entries(x, axis = NULL, keepdims = FALSE)min_entries(x, axis = NULL, keepdims = FALSE)
x |
An Expression |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Logical |
A MinEntries atom
Specifies that the objective expression should be minimized. The expression must be convex and scalar for a DCP-compliant problem.
Minimize(expr)Minimize(expr)
expr |
A CVXR expression or numeric value to minimize. |
A Minimize object.
x <- Variable() obj <- Minimize(x^2 + 1)x <- Variable() obj <- Minimize(x^2 + 1)
norm): column-wise p-norm, then q-normMixed norm ( norm): column-wise p-norm, then q-norm
mixed_norm(X, p = 2, q = 1)mixed_norm(X, p = 2, q = 1)
X |
An Expression (matrix) |
p |
Inner norm parameter (default 2) |
q |
Outer norm parameter (default 1) |
An Expression representing the mixed norm
multiply(x, y)multiply(x, y)
x, y
|
Expressions or numeric values. |
Use the * operator instead: x * y.
An Expression representing the elementwise product.
Returns a human-readable string representation of a CVXR expression, variable, or constraint.
name(x)name(x)
x |
A CVXR expression, variable, parameter, constant, or constraint. |
A character string.
x <- Variable(2, name = "x") name(x) # "x" name(x + 1) # "x + 1"x <- Variable(2, name = "x") name(x) # "x" name(x + 1) # "x + 1"
Negative part: -min(x, 0)
neg(x)neg(x)
x |
An Expression |
A negated Minimum atom
Constrains an expression to be non-negative elementwise: .
NonNeg(expr, constr_id = NULL)NonNeg(expr, constr_id = NULL)
expr |
A CVXR expression. |
constr_id |
Optional integer constraint ID. |
A NonNeg constraint object.
Constrains an expression to be non-positive elementwise: .
NonPos(expr, constr_id = NULL)NonPos(expr, constr_id = NULL)
expr |
A CVXR expression. |
constr_id |
Optional integer constraint ID. |
A NonPos constraint object.
L-infinity norm of an expression
norm_inf(x, axis = NULL, keepdims = FALSE)norm_inf(x, axis = NULL, keepdims = FALSE)
x |
An Expression |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Logical: keep reduced dimensions? |
A NormInf atom
Nuclear norm (sum of singular values)
norm_nuc(A)norm_nuc(A)
A |
A matrix expression |
An expression representing the nuclear norm of A
L1 norm of an expression
norm1(x, axis = NULL, keepdims = FALSE)norm1(x, axis = NULL, keepdims = FALSE)
x |
An Expression |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Logical: keep reduced dimensions? |
A Norm1 atom
norm2(x)norm2(x)
x |
An Expression. |
Use p_norm(x, 2) instead.
An Expression representing the L2 norm.
Returns 1 - x, flipping 0 to 1 and 1 to 0.
Can also be written with the ! operator: !x.
Not(x, id = NULL)Not(x, id = NULL)
x |
A boolean Variable or logic expression. |
id |
Optional integer ID (internal use). |
A Not expression.
And(), Or(), Xor(), implies(), iff()
## Not run: x <- Variable(boolean = TRUE) not_x <- !x # operator syntax not_x <- Not(x) # functional syntax ## End(Not run)## Not run: x <- Variable(boolean = TRUE) not_x <- !x # operator syntax not_x <- Not(x) # functional syntax ## End(Not run)
Returns the problem's objective.
objective(x)objective(x)
x |
A Problem object. |
Problem objects are immutable: the objective cannot be modified after
construction. To change the objective, create a new Problem().
A Minimize or Maximize object.
x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(x >= 1)) objective(prob)x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(x >= 1)) objective(prob)
Log-log concave atom for DGP. Solve with
psolve(problem, gp = TRUE).
one_minus_pos(x)one_minus_pos(x)
x |
An Expression (elementwise in (0, 1)) |
A OneMInusPos atom
x <- Variable(pos = TRUE) prob <- Problem(Maximize(one_minus_pos(x)), list(x >= 0.1, x <= 0.5)) ## Not run: psolve(prob, gp = TRUE)x <- Variable(pos = TRUE) prob <- Problem(Maximize(one_minus_pos(x)), list(x >= 0.1, x <= 0.5)) ## Not run: psolve(prob, gp = TRUE)
Returns 1 if and only if at least one argument equals 1, and 0 otherwise.
For two operands, can also be written with the | operator: x | y.
Or(..., id = NULL)Or(..., id = NULL)
... |
Two or more boolean Variables or logic expressions. |
id |
Optional integer ID (internal use). |
An Or expression.
Not(), And(), Xor(), implies(), iff()
## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) either <- x | y # operator syntax either <- Or(x, y) # functional syntax any3 <- Or(x, y, z) # n-ary ## End(Not run)## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) either <- x | y # operator syntax either <- Or(x, y) # functional syntax any3 <- Or(x, y, z) # n-ary ## End(Not run)
General p-norm of an expression
p_norm( x, p = 2, axis = NULL, keepdims = FALSE, max_denom = 1024L, approx = TRUE )p_norm( x, p = 2, axis = NULL, keepdims = FALSE, max_denom = 1024L, approx = TRUE )
x |
An Expression |
p |
Numeric exponent (default 2) |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Logical |
max_denom |
Integer max denominator for rational approx |
approx |
If TRUE (default), use SOC approximation. If FALSE, use exact power cone. |
A Pnorm, PnormApprox, Norm1, or NormInf atom
Mirrors CVXPY's Problem.param_dict property
(cvxpy/problems/problem.py:260-264): returns a named list keyed by
each parameter's name, where the value is the Parameter
object itself.
param_dict(x, ...)param_dict(x, ...)
x |
A |
... |
Not used. |
Named list of Parameter objects, keyed by name.
Constructs a parameter whose numeric value can be changed without re-canonicalizing the problem. Parameters are treated as constants for DCP purposes but their value can be updated between solves.
Parameter( shape = c(1L, 1L), name = NULL, value = NULL, id = NULL, latex_name = NULL, ... )Parameter( shape = c(1L, 1L), name = NULL, value = NULL, id = NULL, latex_name = NULL, ... )
shape |
Integer vector of length 1 or 2 giving the parameter
dimensions. A scalar |
name |
Optional character string name. If |
value |
Optional initial numeric value. |
id |
Optional integer ID. |
latex_name |
Optional character string giving a custom LaTeX name for
use in visualizations. For example, |
... |
Additional attributes: |
A Parameter object (inherits from Leaf and
Expression).
p <- Parameter() value(p) <- 5 p_vec <- Parameter(3, nonneg = TRUE) gamma <- Parameter(1, name = "gamma", latex_name = "\\gamma")p <- Parameter() value(p) <- 5 p_vec <- Parameter(3, nonneg = TRUE) gamma <- Parameter(1, name = "gamma", latex_name = "\\gamma")
Get the Parameters in an Expression
parameters(x, ...)parameters(x, ...)
x |
An expression or problem object. |
... |
Not used. |
List of Parameter objects.
Builds an Expression representing the optimal value of prob as
a function of the variables you choose NOT to optimise over. Useful
for two-stage / hierarchical optimisation, custom atom definitions,
and embedding sub-problems inside larger problems.
partial_optimize( prob, opt_vars = NULL, dont_opt_vars = NULL, solver = NULL, ... )partial_optimize( prob, opt_vars = NULL, dont_opt_vars = NULL, solver = NULL, ... )
prob |
A Problem to partially optimise. |
opt_vars |
Optional list of Variables to optimise over. |
dont_opt_vars |
Optional list of Variables to keep as free arguments of the resulting expression. |
solver |
Optional solver name (passed to |
... |
Additional named arguments forwarded to |
Exactly one of opt_vars or dont_opt_vars may be NULL; the
missing list is taken to be the complement (relative to the full
list of variables in prob). If both are supplied, they must
together cover every variable in prob.
The returned PartialProblem is an Expression with scalar shape:
it is convex when prob is DCP with a Minimize objective and
concave when DCP with Maximize. Embed it like any other
expression in a larger Problem; the larger problem's canonicalizer
will pull the inner objective and constraints into the outer cone
form so a single solve handles both layers.
A PartialProblem expression.
## Not run: x <- Variable(3) t <- Variable(3) abs_x <- partial_optimize( Problem(Minimize(sum_entries(t)), list(-t <= x, x <= t)), opt_vars = list(t) ) ## abs_x is now an expression of x alone, equivalent to sum(abs(x)). ## End(Not run)## Not run: x <- Variable(3) t <- Variable(3) abs_x <- partial_optimize( Problem(Minimize(sum_entries(t)), list(-t <= x, x <= t)), opt_vars = list(t) ) ## abs_x is now an expression of x alone, equivalent to sum(abs(x)). ## End(Not run)
Assumes expr is a 2D square matrix representing a Kronecker product
of length(dims) subsystems. Returns the partial trace over the
subsystem at index axis (1-indexed).
partial_trace(expr, dims, axis = 1L)partial_trace(expr, dims, axis = 1L)
expr |
An Expression (2D square matrix) |
dims |
Integer vector of subsystem dimensions |
axis |
Integer (1-indexed) subsystem to trace out |
An Expression representing the partial trace
Assumes expr is a 2D square matrix representing a Kronecker product
of length(dims) subsystems. Returns the partial transpose with
the transpose applied to the subsystem at index axis (1-indexed).
partial_transpose(expr, dims, axis = 1L)partial_transpose(expr, dims, axis = 1L)
expr |
An Expression (2D square matrix) |
dims |
Integer vector of subsystem dimensions |
axis |
Integer (1-indexed) subsystem to transpose |
An Expression representing the partial transpose
Creates the perspective transform of a scalar convex or concave expression.
Given a scalar expression f(x) and a nonneg variable s,
the perspective is s * f(x/s).
perspective(f, s, f_recession = NULL)perspective(f, s, f_recession = NULL)
f |
A scalar convex or concave Expression. |
s |
A nonneg Variable (scalar). |
f_recession |
Optional recession function for handling |
A Perspective expression.
Log-log convex atom for DGP. Solve with
psolve(problem, gp = TRUE).
pf_eigenvalue(X)pf_eigenvalue(X)
X |
An Expression (positive square matrix) |
A PfEigenvalue atom (scalar)
X <- Variable(c(2, 2), pos = TRUE) prob <- Problem(Minimize(pf_eigenvalue(X)), list(X[1,1] >= 0.1, X[2,2] >= 0.1)) ## Not run: psolve(prob, gp = TRUE)X <- Variable(c(2, 2), pos = TRUE) prob <- Problem(Minimize(pf_eigenvalue(X)), list(X[1,1] >= 0.1, X[2,2] >= 0.1)) ## Not run: psolve(prob, gp = TRUE)
Positive part: max(x, 0)
pos(x)pos(x)
x |
An Expression |
A Maximum atom
Constrains to lie in the 3D power cone:
PowCone3D(x_expr, y_expr, z_expr, alpha, constr_id = NULL)PowCone3D(x_expr, y_expr, z_expr, alpha, constr_id = NULL)
x_expr |
A CVXR expression. |
y_expr |
A CVXR expression. |
z_expr |
A CVXR expression. |
alpha |
A CVXR expression or numeric value in |
constr_id |
Optional integer constraint ID. |
A PowCone3D constraint object.
Constrains to lie in the N-dimensional power cone:
where and .
PowConeND(W, z, alpha, axis = 2L, constr_id = NULL)PowConeND(W, z, alpha, axis = 2L, constr_id = NULL)
W |
A CVXR expression (vector or matrix). |
z |
A CVXR expression (scalar or vector). |
alpha |
A CVXR expression with positive entries summing to 1 along the specified axis. |
axis |
Integer, 2 (default, column-wise) or 1 (row-wise). |
constr_id |
Optional integer constraint ID. |
A PowConeND constraint object.
The R clarabel solver does not currently support the PowConeND cone
specification. Problems involving PowConeND (e.g., exact geometric mean
with more than 2 arguments) should use SCS or MOSEK as the solver, or
use approximation-based atoms (e.g., geo_mean(x, approx = TRUE)).
Create a Power atom
power(x, p, max_denom = 1024L, approx = TRUE)power(x, p, max_denom = 1024L, approx = TRUE)
x |
An Expression |
p |
Numeric exponent |
max_denom |
Maximum denominator for rational approximation |
approx |
If TRUE (default), use SOC approximation. If FALSE, use exact power cone. |
A Power or PowerApprox atom
sqrt(x) on a CVXR expression dispatches to
Power(x, 0.5) via the Math group generic.
See math_atoms for all standard R function dispatch.
Constructs a convex optimization problem from an objective and a list of
constraints. Use psolve to solve the problem.
Problem(objective, constraints = list())Problem(objective, constraints = list())
objective |
|
constraints |
A list of |
A Problem object.
Problems must contain at least one Variable.
Zero-variable problems (e.g., minimizing a constant) will cause an
internal error in the reduction pipeline.
x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(x >= 1))x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(x >= 1))
Returns the problem data that would be passed to a specific solver, along with the reduction chain and inverse data for solution retrieval.
problem_data(x, solver = NULL, ...)problem_data(x, solver = NULL, ...)
x |
A |
solver |
Character string naming solver, or |
... |
Additional arguments. |
A list with components data, chain, and
inverse_data.
problem_solution(x)problem_solution(x)
x |
A |
Use solution instead.
A Solution object, or NULL if the problem
has not been solved.
problem_status(x)problem_status(x)
x |
A |
Use status instead.
Character string, or NULL if the problem has not been
solved.
Inverts the reduction chain and unpacks the raw solver solution into the original problem's variables and constraints. This is step 3 of the decomposed solve pipeline:
problem_data() – compile the problem
solve_via_data(chain, data) – call the solver
problem_unpack_results() – invert and unpack
problem_unpack_results(problem, solution, chain, inverse_data)problem_unpack_results(problem, solution, chain, inverse_data)
problem |
A |
solution |
The raw solver result from |
chain |
The |
inverse_data |
The inverse data list from |
After calling this function, variable values are available via
value() and constraint duals via dual_value().
The problem object (invisibly), with solution unpacked.
Used in DGP (geometric programming) context. Solve with
psolve(problem, gp = TRUE).
prod_entries(x, axis = NULL, keepdims = FALSE)prod_entries(x, axis = NULL, keepdims = FALSE)
x |
An Expression |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Whether to keep reduced dimensions |
A Prod atom
x <- Variable(3, pos = TRUE) prob <- Problem(Minimize(prod_entries(x)), list(x >= 2)) ## Not run: psolve(prob, gp = TRUE)x <- Variable(3, pos = TRUE) prob <- Problem(Minimize(prod_entries(x)), list(x >= 2)) ## Not run: psolve(prob, gp = TRUE)
Constrains a square matrix expression to be positive semidefinite (PSD):
. The expression must be square.
PSD(expr, constr_id = NULL)PSD(expr, constr_id = NULL)
expr |
A CVXR expression representing a square matrix. |
constr_id |
Optional integer constraint ID. |
A PSD constraint object.
Solves the problem and returns the optimal objective value. After solving,
variable values can be retrieved with value, constraint
dual values with dual_value, and solver information with
solver_stats.
psolve( problem, solver = NULL, gp = FALSE, qcp = FALSE, verbose = FALSE, warm_start = FALSE, requires_grad = FALSE, solver_path = NULL, ... )psolve( problem, solver = NULL, gp = FALSE, qcp = FALSE, verbose = FALSE, warm_start = FALSE, requires_grad = FALSE, solver_path = NULL, ... )
problem |
A |
solver |
Character string naming the solver to use (e.g.,
|
gp |
Logical; if |
qcp |
Logical; if |
verbose |
Logical; if |
warm_start |
Logical; if |
requires_grad |
Logical; if |
solver_path |
Optional fallback chain. A character vector of
solver names or a list whose entries are either character names or
length-2 |
... |
Solver options passed to |
The optimal objective value (numeric scalar), or Inf /
-Inf for infeasible / unbounded problems.
Problem, status,
solver_stats, solver_default_param
x <- Variable() prob <- Problem(Minimize(x), list(x >= 5)) result <- psolve(prob, solver = "CLARABEL")x <- Variable() prob <- Problem(Minimize(x), list(x >= 5)) result <- psolve(prob, solver = "CLARABEL")
Computes the range of values along an axis: max(x) - min(x).
The result is always nonnegative.
ptp(x, axis = NULL, keepdims = FALSE)ptp(x, axis = NULL, keepdims = FALSE)
x |
An Expression or numeric value. |
axis |
NULL (all), 0 (columns), or 1 (rows). |
keepdims |
Logical; keep reduced dimension? |
An Expression representing max(x) - min(x).
When x is constant, returns t(Conj(x)) %*% P %*% x
(affine in P).
When P is constant, returns a QuadForm atom (quadratic in x).
At least one of x or P must be constant.
quad_form(x, P, assume_PSD = FALSE)quad_form(x, P, assume_PSD = FALSE)
x |
An Expression (vector) |
P |
An Expression (square matrix, symmetric/Hermitian) |
assume_PSD |
If TRUE, assume P is PSD without checking (only when P is constant). |
A QuadForm atom or an affine Expression
Sum of squares divided by a scalar
quad_over_lin(x, y, axis = NULL, keepdims = FALSE)quad_over_lin(x, y, axis = NULL, keepdims = FALSE)
x |
An Expression |
y |
An Expression (scalar, positive) |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Logical: keep reduced dimensions? |
A QuadOverLin atom
Reduction chain-rule hooks (backward / forward, parameter / variable)
param_backward(x, param, dparams) param_forward(x, param, delta) var_backward(x, var, value) var_forward(x, var, value)param_backward(x, param, dparams) param_forward(x, param, delta) var_backward(x, var, value) var_forward(x, var, value)
x |
A |
param |
A |
dparams |
Named list of param-id -> gradient arrays for the reduced (transformed) parameters. |
delta |
Numeric array of perturbations to the original |
var |
A |
value |
Numeric array (gradient or delta) attached to |
A gradient array for param, or NULL if this reduction
does not touch param.
Named list of transformed-param-id -> delta arrays, or
NULL if this reduction does not touch param.
Relative Entropy: x*log(x/y)
rel_entr(x, y)rel_entr(x, y)
x |
An Expression |
y |
An Expression |
A RelEntr atom
Reshape an expression to a new shape
reshape_expr(x, dim, order = "F")reshape_expr(x, dim, order = "F")
x |
An Expression or numeric value. |
dim |
Integer vector of length 2: the target shape c(nrow, ncol). A single integer is treated as c(dim, 1). Use -1 to infer a dimension. |
order |
Character: "F" (column-major, default) or "C" (row-major). |
A Reshape expression.
Returns the residual of a constraint, measuring how much the constraint is violated or satisfied.
residual(x, ...)residual(x, ...)
x |
A constraint object. |
... |
Not used. |
Numeric array, or NULL if expression has no value.
Equivalent to (1/s) * eye_minus_inv(X / s).
resolvent(X, s)resolvent(X, s)
X |
An Expression (positive square matrix) |
s |
A positive scalar |
An expression for the resolvent
Scalar product (alias for vdot)
scalar_product(x, y)scalar_product(x, y)
x |
An Expression or numeric value. |
y |
An Expression or numeric value. |
A scalar Expression representing sum(x * y).
Scalene penalty: alpha * pos(x) + beta * neg(x)
scalene(x, alpha, beta)scalene(x, alpha, beta)
x |
An Expression |
alpha |
Coefficient for the positive part |
beta |
Coefficient for the negative part |
An Expression representing the scalene penalty
CVXPY-parity setter that returns its first argument so calls can be
chained (e.g. sum_squares(x) |> set_label("cost")). See
format_labeled() for the pretty-printer that consumes labels.
set_label(x, value)set_label(x, value)
x |
An Expression object. |
value |
A label (character; coerced via |
x with the label updated.
Maximum singular value
sigma_max(A)sigma_max(A)
A |
A matrix expression |
An expression representing the maximum singular value of A
Returns the total number of elements in the expression.
size(x)size(x)
x |
A CVXR expression. |
An integer (product of shape dimensions).
is_scalar(), is_vector(), is_matrix()
Mirrors CVXPY's Problem.size_metrics property
(cvxpy/problems/problem.py:486-490, class at lines 1690-1752):
returns a SizeMetrics object summarising the problem's scale.
size_metrics(x, ...)size_metrics(x, ...)
x |
A |
... |
Not used. |
A SizeMetrics object with seven numeric fields.
Reports scalar-counts and data-dimension metrics for a
Problem. Constructed by size_metrics;
end users normally call size_metrics(prob) rather than this
constructor directly.
SizeMetrics( num_scalar_variables = 0L, num_scalar_data = 0L, num_scalar_eq_constr = 0L, num_scalar_leq_constr = 0L, max_data_dimension = 0L, max_big_small_squared = 0 )SizeMetrics( num_scalar_variables = 0L, num_scalar_data = 0L, num_scalar_eq_constr = 0L, num_scalar_leq_constr = 0L, max_data_dimension = 0L, max_big_small_squared = 0 )
num_scalar_variables |
Total scalar entries across all variables in the problem. |
num_scalar_data |
Total scalar entries across all constants and parameters. |
num_scalar_eq_constr |
Total scalar entries in equality
( |
num_scalar_leq_constr |
Total scalar entries in inequality
( |
max_data_dimension |
Largest single dimension across any data block (constant or parameter). |
max_big_small_squared |
Maximum of |
A SizeMetrics object.
Constrains for each column or row ,
where t is a vector and X is a matrix.
SOC(t, X, axis = 2L, constr_id = NULL)SOC(t, X, axis = 2L, constr_id = NULL)
t |
A CVXR expression (scalar or vector) representing the upper bound. |
X |
A CVXR expression (vector or matrix) whose columns/rows are bounded. |
axis |
Integer, 2 (default, column-wise) or 1 (row-wise). Determines whether columns ( |
constr_id |
Optional integer constraint ID. |
An SOC constraint object.
Returns the raw Solution object from the most recent solve,
containing primal and dual variable values, status, and solver
attributes.
solution(x)solution(x)
x |
A |
A Solution object, or NULL if the problem
has not been solved.
Calls the solver on pre-compiled problem data (step 2 of the
decomposed solve pipeline). Dispatches on x: when x
is a SolvingChain, delegates to the terminal solver with
proper cache management.
solve_via_data( x, data, warm_start = FALSE, verbose = FALSE, solver_opts = list(), ... )solve_via_data( x, data, warm_start = FALSE, verbose = FALSE, solver_opts = list(), ... )
x |
A |
data |
Named list of solver data from |
warm_start |
Logical; use warm-start if supported. |
verbose |
Logical; print solver output. |
solver_opts |
Named list of solver-specific options. |
... |
Additional arguments (e.g., |
Solver-specific result (a named list).
problem_data, problem_unpack_results
Returns a named list mapping standard CVXR parameter names (reltol,
abstol, feastol, num_iter) to solver-specific
parameter names and their default values. Used internally by
psolve to translate standard parameters into
solver-native names.
solver_default_param()solver_default_param()
A named list keyed by solver name (e.g. "CLARABEL",
"OSQP"). Each element is a list of standard parameter mappings,
where each mapping has name (solver-native parameter name) and
value (default value).
Constructs a structured list of solver options for use with
psolve and problem_data. Known parameters
are sorted into named slots; solver-specific parameters are collected
in $solver_specific.
solver_opts( use_quad_obj = TRUE, feastol = NULL, reltol = NULL, abstol = NULL, num_iter = NULL, ... )solver_opts( use_quad_obj = TRUE, feastol = NULL, reltol = NULL, abstol = NULL, num_iter = NULL, ... )
use_quad_obj |
Logical. If |
feastol |
Feasibility tolerance (solver-agnostic). Translated to
solver-native name by internal mapping. |
reltol |
Relative tolerance. |
abstol |
Absolute tolerance. |
num_iter |
Maximum iterations. |
... |
Solver-specific parameters passed directly to the solver
(e.g., |
A named list with class "solver_opts".
solver_opts(feastol = 1e-6) solver_opts(use_quad_obj = FALSE, eps_abs = 1e-7) solver_opts(scip_params = list("limits/time" = 10))solver_opts(feastol = 1e-6) solver_opts(use_quad_obj = FALSE, eps_abs = 1e-7) solver_opts(scip_params = list("limits/time" = 10))
Returns solver statistics from the most recent solve, including solve time, setup time, and iteration count.
solver_stats(x)solver_stats(x)
x |
A |
A SolverStats object, or NULL if the problem
has not been solved.
Character string constants identifying the available solvers.
SCS_SOLVER OSQP_SOLVER CLARABEL_SOLVER DIFFCP_SOLVER HIGHS_SOLVER MOSEK_SOLVER GUROBI_SOLVER GLPK_SOLVER GLPK_MI_SOLVER ECOS_SOLVER ECOS_BB_SOLVER CPLEX_SOLVER CVXOPT_SOLVER PIQP_SOLVER SCIP_SOLVER XPRESS_SOLVERSCS_SOLVER OSQP_SOLVER CLARABEL_SOLVER DIFFCP_SOLVER HIGHS_SOLVER MOSEK_SOLVER GUROBI_SOLVER GLPK_SOLVER GLPK_MI_SOLVER ECOS_SOLVER ECOS_BB_SOLVER CPLEX_SOLVER CVXOPT_SOLVER PIQP_SOLVER SCIP_SOLVER XPRESS_SOLVER
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
A character string.
Square of an expression: x^2
square(x)square(x)
x |
An Expression |
A Power atom with p=2
Returns the status string from the most recent solve, such as
"optimal", "infeasible", or "unbounded".
status(x)status(x)
x |
A |
Character string, or NULL if the problem has not been
solved.
OPTIMAL, INFEASIBLE,
UNBOUNDED
Character string constants representing the possible solution statuses
returned by problem_status.
OPTIMAL INFEASIBLE UNBOUNDED SOLVER_ERROR OPTIMAL_INACCURATE INFEASIBLE_INACCURATE UNBOUNDED_INACCURATE USER_LIMIT INFEASIBLE_OR_UNBOUNDEDOPTIMAL INFEASIBLE UNBOUNDED SOLVER_ERROR OPTIMAL_INACCURATE INFEASIBLE_INACCURATE UNBOUNDED_INACCURATE USER_LIMIT INFEASIBLE_OR_UNBOUNDED
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
An object of class character of length 1.
A character string.
Sum the entries of an expression
sum_entries(x, axis = NULL, keepdims = FALSE)sum_entries(x, axis = NULL, keepdims = FALSE)
x |
An Expression or numeric value. |
axis |
NULL (sum all), 1 (row-wise, like apply(X,1,sum)), or 2 (column-wise, like apply(X,2,sum)). |
keepdims |
Logical: if TRUE, keep the reduced dimension as size 1. |
A SumEntries expression.
Sum of k largest entries
sum_largest(x, k)sum_largest(x, k)
x |
An Expression |
k |
Number of largest entries to sum |
A SumLargest atom
Sum of k smallest entries
sum_smallest(x, k)sum_smallest(x, k)
x |
An Expression |
k |
Number of smallest entries to sum |
An Expression equal to -SumLargest(-x, k)
Sum of squares (= quad_over_lin(x, 1))
sum_squares(x, axis = NULL, keepdims = FALSE)sum_squares(x, axis = NULL, keepdims = FALSE)
x |
An Expression |
axis |
NULL (all), 1 (row-wise), or 2 (column-wise) |
keepdims |
Logical: keep reduced dimensions? |
A QuadOverLin atom
Renders a CVXR Problem, Expression, or Constraint
as a LaTeX string. Problem-level output uses the optidef package
(mini*/maxi* environments) and atom macros from
dcp.sty (shipped as system.file("sty", "dcp.sty", package = "CVXR")).
to_latex(x, ...)to_latex(x, ...)
x |
A |
... |
Reserved for future options. |
A character string containing LaTeX code.
x <- Variable(3, name = "x") cat(to_latex(p_norm(x, 2))) # \cvxnorm{x}_2x <- Variable(3, name = "x") cat(to_latex(p_norm(x, 2))) # \cvxnorm{x}_2
Computes total variation using L1 norm of discrete gradients for vectors and L2 norm of discrete gradients for matrices.
total_variation(value, ...)total_variation(value, ...)
value |
An Expression or numeric constant (vector or matrix) |
... |
Additional matrix expressions extending the third dimension |
An Expression representing the total variation
Computes for PSD matrix X.
tr_inv(X)tr_inv(X)
X |
A square PSD matrix expression |
An expression representing
tv(...)tv(...)
... |
Arguments passed to |
Use total_variation() instead.
unpack_results(problem, solution, chain, inverse_data)unpack_results(problem, solution, chain, inverse_data)
problem |
A |
solution |
The raw solver result from |
chain |
The |
inverse_data |
The inverse data list from |
Use problem_unpack_results() instead. This alias exists for
backward compatibility with older CVXR examples.
The problem object (invisibly), with solution unpacked.
Extract strict upper triangle of a square matrix
upper_tri(x)upper_tri(x)
x |
An Expression (square matrix) |
An UpperTri atom (column vector)
Returns the numeric value of a CVXR expression, variable, or constant. For variables, the value is set after solving a problem.
value(x, ...)value(x, ...)
x |
An expression object. |
... |
Not used. |
A numeric matrix, or NULL if no value has been set.
Assigns a numeric value to a Variable or
Parameter.
value(x) <- valuevalue(x) <- value
x |
A leaf expression object. |
value |
The value to assign. |
The modified object (invisibly).
Mirrors CVXPY's Problem.var_dict property
(cvxpy/problems/problem.py:267-271): returns a named list keyed by
each variable's name, where the value is the Variable
object itself.
var_dict(x, ...)var_dict(x, ...)
x |
A |
... |
Not used. |
Named list of Variable objects, keyed by name.
Constructs a variable to be used in a CVXR optimization problem. Variables are decision variables that the solver optimizes over.
Variable( shape = c(1L, 1L), name = NULL, value = NULL, var_id = NULL, latex_name = NULL, ... )Variable( shape = c(1L, 1L), name = NULL, value = NULL, var_id = NULL, latex_name = NULL, ... )
shape |
Integer vector of length 1 or 2 giving the variable dimensions.
A scalar |
name |
Optional character string name for the variable. If |
value |
Optional numeric initial value (scalar, vector, or matrix
matching |
var_id |
Optional integer ID. If |
latex_name |
Optional character string giving a custom LaTeX name for
use in visualizations. For example, |
... |
Additional attributes: |
A Variable object (inherits from Leaf and
Expression).
x <- Variable(3) # 3x1 column vector X <- Variable(c(2, 3)) # 2x3 matrix y <- Variable(2, nonneg = TRUE) # non-negative variable z <- Variable(3, name = "z", latex_name = "\\mathbf{z}") # custom LaTeXx <- Variable(3) # 3x1 column vector X <- Variable(c(2, 3)) # 2x3 matrix y <- Variable(2, nonneg = TRUE) # non-negative variable z <- Variable(3, name = "z", latex_name = "\\mathbf{z}") # custom LaTeX
Get the Variables in an Expression
variables(x, ...)variables(x, ...)
x |
An expression or problem object. |
... |
Not used. |
List of Variable objects.
Computes the inner product: sum of element-wise products after flattening. Returns a scalar expression.
vdot(x, y)vdot(x, y)
x |
An Expression or numeric value. |
y |
An Expression or numeric value. |
A scalar Expression representing sum(x * y).
Reshapes an expression into a column vector of shape (n*m, 1).
vec(x)vec(x)
x |
An Expression or numeric value. |
A Reshape atom (column vector).
Inverts upper_tri. Takes a flat vector and returns an
upper triangular matrix (row-major order, matching CVXPY convention).
vec_to_upper_tri(expr, strict = FALSE)vec_to_upper_tri(expr, strict = FALSE)
expr |
An Expression (vector). |
strict |
Logical. If TRUE, returns a strictly upper triangular matrix (diagonal is zero). If FALSE, includes the diagonal. Default is FALSE. |
An Expression representing the upper triangular matrix.
Returns the scalar violation (distance to feasibility) of a constraint.
violation(x, ...)violation(x, ...)
x |
A constraint object. |
... |
Not used. |
Numeric scalar.
Displays the Smith form decomposition of a convex optimization problem, showing each stage of the DCP canonicalization pipeline: expression tree, Smith form, relaxed Smith form, conic form, and (optionally) standard cone form and solver data.
visualize( problem, output = c("text", "json", "html", "latex", "tikz"), solver = NULL, digits = 4L, file = NULL, open = interactive(), doc_base = "https://cvxr.rbind.io/reference/" )visualize( problem, output = c("text", "json", "html", "latex", "tikz"), solver = NULL, digits = 4L, file = NULL, open = interactive(), doc_base = "https://cvxr.rbind.io/reference/" )
problem |
A Problem object. |
output |
Character: output format.
|
solver |
Solver specification for matrix stuffing stages (4-5).
|
digits |
Integer: significant digits for displaying scalar constants. Integer-valued constants (0, 1, -3) always display without decimals regardless of this setting. Defaults to 4. |
file |
Character: path for HTML output file. If |
open |
Logical: whether to open the HTML file in a browser.
Defaults to |
doc_base |
Character: base URL for atom documentation links. Defaults to the CVXR pkgdown site. |
For "text": invisible model list.
For "json": a JSON string (or list if jsonlite not available).
For "html": the file path (invisibly).
For other formats: the rendered output (Phase 2+).
## Not run: x <- Variable(3, name = "x") prob <- Problem(Minimize(p_norm(x, 2)), list(x >= 1)) visualize(prob) # Stages 0-3 only visualize(prob, solver = TRUE) # Stages 0-5, default solver visualize(prob, solver = "Clarabel") # Stages 0-5, specific solver visualize(prob, output = "html", solver = TRUE) ## End(Not run)## Not run: x <- Variable(3, name = "x") prob <- Problem(Minimize(p_norm(x, 2)), list(x >= 1)) visualize(prob) # Stages 0-3 only visualize(prob, solver = TRUE) # Stages 0-5, default solver visualize(prob, solver = "Clarabel") # Stages 0-5, specific solver visualize(prob, output = "html", solver = TRUE) ## End(Not run)
Vertical concatenation of expressions
vstack(...)vstack(...)
... |
Expressions (same number of columns) |
A VStack atom
x * exp(x) – elementwise
xexp(x)xexp(x)
x |
An Expression |
An Xexp atom
For two arguments: result is 1 iff exactly one is 1. For n arguments: result is 1 iff an odd number are 1 (parity).
Xor(..., id = NULL)Xor(..., id = NULL)
... |
Two or more boolean Variables or logic expressions. |
id |
Optional integer ID (internal use). |
Note: R's ^ operator is used for power(), so Xor is functional syntax only.
A Xor expression.
Not(), And(), Or(), implies(), iff()
## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) exclusive <- Xor(x, y) ## End(Not run)## Not run: x <- Variable(boolean = TRUE) y <- Variable(boolean = TRUE) exclusive <- Xor(x, y) ## End(Not run)
Constrains an expression to equal zero elementwise: .
Zero(expr, constr_id = NULL)Zero(expr, constr_id = NULL)
expr |
A CVXR expression. |
constr_id |
Optional integer constraint ID. |
A Zero constraint object.