OptimizationExpression.exp — Operate on retained optimization expressions and comparisons.
Standard optimization-model class methods construct expressions, project properties or evaluate the same original model graph. See optimexpr for operations, point fields, comparison directions and current scope.
Syntax
result = function(operands,metadata...)Inputs
operands_and_metadata- Type
Any- Required
- Variadic
- Default
- —
- Description
- Symbolic operand, ordinary metadata, subscript descriptor or evaluation point.
Returns
result- Type
Any- Description
- Expression or comparison object; evaluate returns its same-shaped double value.
Errors
RunMat:OptimModel:InvalidInput- When
- Invalid expression dimensions, operand, index, property, point field or comparison.
- Message
invalid optimization-model input
Construction and assignment
optimexpr with no arguments creates an empty expression accumulator. Adding or subtracting the first expression initializes its shape and original variable references. This empty initializer is distinct from a scalar numerical zero and from arrays of unassigned slots.
zeros(dimensions...,'like',prototype) creates a zero-valued OptimizationExpression when prototype is an original expression or variable. Dimensions follow ordinary zeros: no dimensions gives 1-by-1, one scalar gives a square array, and a size vector or separate dimensions gives the requested N-D shape. An empty size vector gives 0-by-0. The result can be assigned symbolically without converting variable values to double.
optimexpr(n) creates n-by-1 unassigned expression slots. Separate positive double dimensions, a dimension vector, named string/cell axes, and a cell of mixed axes create N-D arrays. A lone named vector preserves its orientation. Assign expressions into these slots with numeric, logical, colon or named selectors; repeated indices follow normal assignment order.
Unassigned coordinates are not numeric zeros. Evaluating an expression that still depends on an unassigned coordinate reports an error. An assigned subset can be evaluated without first assigning unrelated slots. Expression edits create a new expression value; the retained original variable definitions remain shared.
Arithmetic and numerical functions
Explicit modeling constants must be finite and real. Complex, Inf and NaN inputs are rejected during expression construction, including numeric function metadata. This restriction applies to construction constants. Numerical evaluation can produce nonfinite results, and variable bounds may be infinite.
Addition, subtraction, unary signs, transpose, conjugate transpose, matrix/pointwise multiplication, constant division and constant scalar powers construct expression nodes. Matrix powers require a constant scalar exponent. Pointwise division requires a constant denominator (or numerator for left division). Black-box function conversion with fcn2optimexpr is unavailable.
Supported numerical functions include sum, mean, prod, trace, cumsum, cumprod, diff, reshape, diag, dot, default or numeric-two norm, sqrt, exp, log, and the trigonometric, inverse-trigonometric, hyperbolic and inverse-hyperbolic functions. The norm is Euclidean for scalar/vector inputs and spectral for 2-D matrices; a matrix spectral norm square is not a squared-residual or quadratic certificate. cat, horzcat and vertcat concatenate expressions. Function options and array dimensions follow the corresponding numerical function. Construction rejects unsupported forms and forms whose shape cannot be established.
Properties and variable references
The RunMat functional setfield extension accepts contextual end inside a native property index path. The actual property child is retained and indexed once, with the same native class and access checks as ordinary assignment.
IndexNames contains one cell entry per axis; empty entries use numerical indexing. IndexNames can be edited directly or through an indexed cell property path. Variables is a read-only scalar structure containing complete original variable definitions reachable from the expression, including variables used only through subsets.
Copy Variables into a separate structure to edit the bounds of its live variable handles. Different original definitions with the same name cannot be merged into one evaluation point. An unrelated user object or callback capture is not converted into a numeric model operand.
Evaluation and comparisons
evaluate(expr,point) returns a double array with the expression's shape. point is a scalar structure whose selected fields have the names and complete original shapes of the reachable variables. Real host numeric point values use the canonical double conversion; each original definition is converted once per evaluation. Extra point fields are not inspected.
Comparisons ==, <= and >= require equal shapes or one scalar side. Equality results have class optim.problemdef.OptimizationEquality; inequality results have class optim.problemdef.OptimizationInequality. evaluate(L<=R,point) is L-R, evaluate(L>=R,point) is R-L, and evaluate(L==R,point) is abs(L-R). IndexNames and Variables are available on comparison values.
Execution and current limits
Model construction and evaluation use the original invocation context and cooperate with cancellation. Invalid structural carriers are rejected before property/capture traversal or numeric conversion. Variable definitions and expression dependencies remain managed GC roots throughout construction, evaluation and property edits.
Finite host-memory graph construction/evaluation, model transport, expression growth, and constraint-array element indexing/assignment are unsupported. Virtual index metadata uses checked platform-sized offsets and allocates only the addressed selection, subject to the existing per-selection materialization limit. Evaluation of a selected uniform zero source materializes only the requested output. A nonempty unassigned selection remains an error; empty selections have no missing element. General arithmetic and full-array property results can still require physical storage for their complete inputs or outputs. optimconstr, optimeq, optimineq, OptimizationValues, expression display/export and fcn2optimexpr are unavailable. The problem-based solve interface supports continuous scalar affine problems; other model solver forms remain unavailable.
Using OptimizationExpression.exp with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how OptimizationExpression.exp changes the result.
Run a small OptimizationExpression.exp example, explain the result, then change one input and compare the output.
Related Math functions
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Signal
blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. Read exactly how OptimizationExpression.exp is executed, line by line, in Rust.
- View the source for OptimizationExpression.exp in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.