Skip to content

Commit 951e35f

Browse files
committed
Expand on arity
1 parent 9a8ded4 commit 951e35f

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

README.md

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ Here is a summary of the functions defined by MathOptFormat.
174174
| `"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"}]} |
175175
| `"Nonlinear"` | An expression graph representing a scalar function. | |
176176

177+
178+
For more information on `"Nonlinear"` functions, see
179+
[Nonlinear functions](@ref).
180+
177181
#### Vector Functions
178182

179183
| Name | Description | Example |
@@ -192,7 +196,7 @@ The expression graph is stored as an object with three required fields:
192196
`"head"`, which must be `"Nonlinear"`, as well as `"root"` and `"node_list"`.
193197

194198
`"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
196200
elaborate on permissible nodes and how to store them in the following
197201
subsections.
198202

@@ -216,7 +220,57 @@ the node in `"node_list"`.
216220
| ---- | ----------- | ------- |
217221
| `"node"` | A pointer to a (1-indexed) element in the `node_list` field in a nonlinear function | {"head": "node", "index": 2} |
218222

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.
220274

221275
| Name | Arity |
222276
| ---- | ----- |
@@ -250,9 +304,10 @@ the node in `"node_list"`.
250304
##### Example
251305

252306
As an example, consider the function `f(x, y) = (1 + 3i) ⋅ x + sin^2(x) + y`.
307+
253308
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+
256311
In MathOptFormat, this expression graph can be encoded as follows:
257312
```json
258313
{

0 commit comments

Comments
 (0)