You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-4Lines changed: 59 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -174,6 +174,10 @@ Here is a summary of the functions defined by MathOptFormat.
174
174
|`"ScalarQuadraticFunction"`| The function `0.5x'Qx + a'x + b`, where `a` is a sparse vector of `ScalarAffineTerm`s in `affine_terms`, `b` is the scalar `constant`, and `Q` is a symmetric matrix specified by a list of `ScalarQuadraticTerm`s in `quadratic_terms`. Duplicate indices in `affine_terms` and `quadratic` are accepted, and the corresponding coefficients are summed together. Mirrored indices in `quadratic_terms` (i.e., `(i,j)` and `(j, i)`) are considered duplicates; only one need to be specified. | {"head": "ScalarAffineFunction", "constant": 1.0, "affine_terms": [{"coefficient": 2.5, "variable": "x"}], "quadratic_terms": [{"coefficient": 2.0, "variable_1": "x", "variable_2": "y"}]} |
175
175
|`"Nonlinear"`| An expression graph representing a scalar function. ||
176
176
177
+
178
+
For more information on `"Nonlinear"` functions, see
179
+
[Nonlinear functions](@ref).
180
+
177
181
#### Vector Functions
178
182
179
183
| Name | Description | Example |
@@ -192,7 +196,7 @@ The expression graph is stored as an object with three required fields:
192
196
`"head"`, which must be `"Nonlinear"`, as well as `"root"` and `"node_list"`.
193
197
194
198
`"root"` contains an object defining the root node of the expression graph. All
195
-
other nodes are stored as a flattened list in the `"node\_list"` field. We
199
+
other nodes are stored as a flattened list in the `"node_list"` field. We
196
200
elaborate on permissible nodes and how to store them in the following
197
201
subsections.
198
202
@@ -216,7 +220,57 @@ the node in `"node_list"`.
216
220
| ---- | ----------- | ------- |
217
221
|`"node"`| A pointer to a (1-indexed) element in the `node_list` field in a nonlinear function | {"head": "node", "index": 2} |
218
222
219
-
##### Other nodes
223
+
##### Operators
224
+
225
+
All nonlinear operators in MathOptFormat are described by a JSON object with two fields:
226
+
227
+
-`"head"`
228
+
229
+
A string that corresponds to the operator.
230
+
231
+
-`"args"`
232
+
233
+
An ordered list of nodes that are passed as arguments to the operator.
234
+
235
+
The number of elements in `"args"` depends on the arity of the operator. MathOptFormat distinguishes between three arities:
236
+
237
+
- Unary operators take one argument
238
+
- Binary operators take two arguments
239
+
- N-ary operators take at least one argument
240
+
241
+
To give some examples, the unary function `log(x)` is encoded as:
242
+
```json
243
+
{
244
+
"head": "log",
245
+
"args": [
246
+
{"head": "variable", "name": "x"}
247
+
]
248
+
}
249
+
```
250
+
The binary function `x^2` (i.e., `^(x, 2)`) is encoded as:
251
+
```json
252
+
{
253
+
"head": "^",
254
+
"args": [
255
+
{"head": "variable", "name": "x"},
256
+
{"head": "real", "value": 2},
257
+
]
258
+
}
259
+
```
260
+
The n-ary function `x + y + 1` (i.e., `+(x, y, 1)`) is encoded as:
261
+
```json
262
+
{
263
+
"head": "+",
264
+
"args": [
265
+
{"head": "variable", "name": "x"},
266
+
{"head": "variable", "name": "y"},
267
+
{"head": "real", "value": 1},
268
+
]
269
+
}
270
+
```
271
+
272
+
Here is a complete list of the nonlinear operators supported by MathOptFormat
273
+
and their corresponding arity.
220
274
221
275
| Name | Arity |
222
276
| ---- | ----- |
@@ -250,9 +304,10 @@ the node in `"node_list"`.
250
304
##### Example
251
305
252
306
As an example, consider the function `f(x, y) = (1 + 3i) ⋅ x + sin^2(x) + y`.
307
+
253
308
In Polish notation, the expression graph is:
254
-
```f(x, y) = +(1 + 3i, ^(sin(x), 2), y)
255
-
```
309
+
`f(x, y) = +(1 + 3i, ^(sin(x), 2), y)`.
310
+
256
311
In MathOptFormat, this expression graph can be encoded as follows:
0 commit comments