Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# Nonlinear Operation Codes

Nonlinear expressions are built as a tree of operations, each with an associated operation code (opcode). Each opcode has both a name and an integer value. Our programming language APIs provide predefined constants for all of these, which we recommend you use. These constants are accessed by prepending a fixed prefix (which varies slightly by language) to the opcode name. To access the `SQRT` operation code (to define the square root function) from our various APIs, for example, you would use the following:

Language | Operation Code
--- | ---
C | `GRB_OPCODE_SQRT`
C++ | `GRB_OPCODE_SQRT`
Java | `GRB.OPCODE_SQRT`
.NET | `GRB.OPCODE_SQRT`
Python [1] | `GRB.OPCODE_SQRT`

[1]

Note that in Python, we recommend you use arithmetic operators and our nonlinear function helpers to build nonlinear constraints (see `NLExpr` for details). Using these operation codes directly is considered advanced usage.

The following table lists the available operation codes:

Opcode name | Value | Arity | Data
--- | --- | --- | ---
`CONSTANT` | 0 | n/a | value of constant
`VARIABLE` | 1 | n/a | index of variable (or variable object)
`PLUS` | 2 | n-ary | \(-1.0\)
`MINUS` | 3 | binary | \(-1.0\)
`MULTIPLY` | 4 | n-ary | \(-1.0\)
`DIVIDE` | 5 | binary | \(-1.0\)
`UMINUS` | 6 | unary | \(-1.0\)
`SQUARE` | 7 | unary | \(-1.0\)
`SQRT` | 8 | unary | \(-1.0\)
`SIN` | 9 | unary | \(-1.0\)
`COS` | 10 | unary | \(-1.0\)
`TAN` | 11 | unary | \(-1.0\)
`POW` | 12 | binary | \(-1.0\)
`EXP` | 13 | unary | \(-1.0\)
`LOG` | 14 | unary | \(-1.0\)
`LOG2` | 15 | unary | \(-1.0\)
`LOG10` | 16 | unary | \(-1.0\)
`LOGISTIC` | 17 | unary | \(-1.0\)
`TANH` | 18 | unary | \(-1.0\)
`SIGNPOW` | 19 | binary | \(-1.0\)

These operation codes will also appear in MPS and LP files (using the names from the table above).

See our section Operation Codes for a detailed description of each operation code.

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support