@@ -290,11 +290,11 @@ Leaf nodes in the expression graph are data: they can either reference
290
290
optimization variables, or be real or complex valued numeric constants. They are
291
291
described as follows.
292
292
293
- | Head | Description | Example |
293
+ | Type | Description | Example |
294
294
| ---- | ----------- | ------- |
295
- | ` "real" ` | A real-valued numeric constant | {"type": "real", "value": 1.0} |
296
- | ` "complex" ` | A complex-valued numeric constant | {"type": "complex", "real": 1.0, "imag": 2.0} |
297
- | ` "variable" ` | A reference to an optimization variable | {"type": "variable ", "name ": "x" } |
295
+ | ` number ` | A real-valued numeric constant | 1.0 |
296
+ | ` string ` | A reference to an optimization variable | "x" |
297
+ | ` {"type": "complex"} ` | A complex-valued numeric constant | {"type": "complex ", "real ": 1.0, "imag": 2.0 } |
298
298
299
299
Nodes in the flattened list ` "node_list" ` can be referenced by an object with
300
300
the ` "type" ` field ` "node" ` and a field ` "index" ` that is the one-based index of
@@ -306,148 +306,41 @@ the node in `"node_list"`.
306
306
307
307
#### Operators
308
308
309
- All nonlinear operators in MathOptFormat are described by a JSON object with two fields:
310
-
311
- - ` "type" `
312
-
313
- A string that corresponds to the operator.
309
+ All nonlinear operators in MathOptFormat are described by a JSON object with two
310
+ fields:
314
311
315
- - ` "args" `
312
+ - ` "type" ` : A string that corresponds to the operator.
313
+ - ` "args" ` : An ordered list of nodes that are passed as arguments to the
314
+ operator.
316
315
317
- An ordered list of nodes that are passed as arguments to the operator.
318
-
319
- The number of elements in ` "args" ` depends on the arity of the operator. MathOptFormat distinguishes between three arities:
316
+ The number of elements in ` "args" ` depends on the arity of the operator.
317
+ MathOptFormat distinguishes between three arities:
320
318
321
319
- Unary operators take one argument
322
320
- Binary operators take two arguments
323
321
- N-ary operators take at least one argument
324
322
325
323
To give some examples, the unary function ` log(x) ` is encoded as:
326
324
``` json
327
- {
328
- "type" : " log" ,
329
- "args" : [
330
- {"type" : " variable" , "name" : " x" }
331
- ]
332
- }
325
+ {"type" : " log" , "args" : [" x" ]}
333
326
```
334
327
The binary function ` x^2 ` (i.e., ` ^(x, 2) ` ) is encoded as:
335
328
``` json
336
- {
337
- "type" : " ^" ,
338
- "args" : [
339
- {"type" : " variable" , "name" : " x" },
340
- {"type" : " real" , "value" : 2 }
341
- ]
342
- }
329
+ {"type" : " ^" , "args" : [" x" , 2 ]}
343
330
```
344
331
The n-ary function ` x + y + 1 ` (i.e., ` +(x, y, 1) ` ) is encoded as:
345
332
``` json
346
- {
347
- "type" : " +" ,
348
- "args" : [
349
- {"type" : " variable" , "name" : " x" },
350
- {"type" : " variable" , "name" : " y" },
351
- {"type" : " real" , "value" : 1 }
352
- ]
353
- }
333
+ {"type" : " +" , "args" : [" x" , " y" , 1.0 ]}
354
334
```
355
335
356
336
Here is a complete list of the nonlinear operators supported by MathOptFormat
357
337
and their corresponding arity.
358
338
359
- | Name | Arity |
360
- | ---- | ----- |
361
- | ` "+" ` | Unary |
362
- | ` "-" ` | Unary |
363
- | ` "abs" ` | Unary |
364
- | ` "sqrt" ` | Unary |
365
- | ` "cbrt" ` | Unary |
366
- | ` "abs2" ` | Unary |
367
- | ` "inv" ` | Unary |
368
- | ` "log" ` | Unary |
369
- | ` "log10" ` | Unary |
370
- | ` "log2" ` | Unary |
371
- | ` "log1p" ` | Unary |
372
- | ` "exp" ` | Unary |
373
- | ` "exp2" ` | Unary |
374
- | ` "expm1" ` | Unary |
375
- | ` "sin" ` | Unary |
376
- | ` "cos" ` | Unary |
377
- | ` "tan" ` | Unary |
378
- | ` "sec" ` | Unary |
379
- | ` "csc" ` | Unary |
380
- | ` "cot" ` | Unary |
381
- | ` "sind" ` | Unary |
382
- | ` "cosd" ` | Unary |
383
- | ` "tand" ` | Unary |
384
- | ` "secd" ` | Unary |
385
- | ` "cscd" ` | Unary |
386
- | ` "cotd" ` | Unary |
387
- | ` "asin" ` | Unary |
388
- | ` "acos" ` | Unary |
389
- | ` "atan" ` | Unary |
390
- | ` "asec" ` | Unary |
391
- | ` "acsc" ` | Unary |
392
- | ` "acot" ` | Unary |
393
- | ` "asind" ` | Unary |
394
- | ` "acosd" ` | Unary |
395
- | ` "atand" ` | Unary |
396
- | ` "asecd" ` | Unary |
397
- | ` "acscd" ` | Unary |
398
- | ` "acotd" ` | Unary |
399
- | ` "sinh" ` | Unary |
400
- | ` "cosh" ` | Unary |
401
- | ` "tanh" ` | Unary |
402
- | ` "sech" ` | Unary |
403
- | ` "csch" ` | Unary |
404
- | ` "coth" ` | Unary |
405
- | ` "asinh" ` | Unary |
406
- | ` "acosh" ` | Unary |
407
- | ` "atanh" ` | Unary |
408
- | ` "asech" ` | Unary |
409
- | ` "acsch" ` | Unary |
410
- | ` "acoth" ` | Unary |
411
- | ` "deg2rad" ` | Unary |
412
- | ` "rad2deg" ` | Unary |
413
- | ` "erf" ` | Unary |
414
- | ` "erfinv" ` | Unary |
415
- | ` "erfc" ` | Unary |
416
- | ` "erfcinv" ` | Unary |
417
- | ` "erfi" ` | Unary |
418
- | ` "gamma" ` | Unary |
419
- | ` "lgamma" ` | Unary |
420
- | ` "digamma" ` | Unary |
421
- | ` "invdigamma" ` | Unary |
422
- | ` "trigamma" ` | Unary |
423
- | ` "airyai" ` | Unary |
424
- | ` "airybi" ` | Unary |
425
- | ` "airyaiprime" ` | Unary |
426
- | ` "airybiprime" ` | Unary |
427
- | ` "besselj0" ` | Unary |
428
- | ` "besselj1" ` | Unary |
429
- | ` "bessely0" ` | Unary |
430
- | ` "bessely1" ` | Unary |
431
- | ` "erfcx" ` | Unary |
432
- | ` "dawson" ` | Unary |
433
- | ` "floor" ` | Unary |
434
- | ` "ceil" ` | Unary |
435
- | ` "/" ` | Binary |
436
- | ` "^" ` | Binary |
437
- | ` "atan" ` | Binary |
438
- | ` "&&" ` | Binary |
439
- | `"|| "` | Binary |
440
- | ` "<=" ` | Binary |
441
- | ` "<" ` | Binary |
442
- | ` ">=" ` | Binary |
443
- | ` ">" ` | Binary |
444
- | ` "==" ` | Binary |
445
- | ` "+" ` | N-ary |
446
- | ` "-" ` | N-ary |
447
- | ` "*" ` | N-ary |
448
- | ` "ifelse" ` | N-ary |
449
- | ` "min" ` | N-ary |
450
- | ` "max" ` | N-ary |
339
+ | Arity | Operators |
340
+ | ----- | --------- |
341
+ | Unary | ` "abs" ` , ` "sqrt" ` , ` "cbrt" ` , ` "abs2" ` , ` "inv" ` , ` "log" ` , ` "log10" ` , ` "log2" ` , ` "log1p" ` , ` "exp" ` , ` "exp2" ` , ` "expm1" ` , ` "sin" ` , ` "cos" ` , ` "tan" ` , ` "sec" ` , ` "csc" ` , ` "cot" ` , ` "sind" ` , ` "cosd" ` , ` "tand" ` , ` "secd" ` , ` "cscd" ` , ` "cotd" ` , ` "asin" ` , ` "acos" ` , ` "atan" ` , ` "asec" ` , ` "acsc" ` , ` "acot" ` , ` "asind" ` , ` "acosd" ` , ` "atand" ` , ` "asecd" ` , ` "acscd" ` , ` "acotd" ` , ` "sinh" ` , ` "cosh" ` , ` "tanh" ` , ` "sech" ` , ` "csch" ` , ` "coth" ` , ` "asinh" ` , ` "acosh" ` , ` "atanh" ` , ` "asech" ` , ` "acsch" ` , ` "acoth" ` , ` "deg2rad" ` , ` "rad2deg" ` , ` "erf" ` , ` "erfinv" ` , ` "erfc" ` , ` "erfcinv" ` , ` "erfi" ` , ` "gamma" ` , ` "lgamma" ` , ` "digamma" ` , ` "invdigamma" ` , ` "trigamma" ` , ` "airyai" ` , ` "airybi" ` , ` "airyaiprime" ` , ` "airybiprime" ` , ` "besselj0" ` , ` "besselj1" ` , ` "bessely0" ` , ` "bessely1" ` , ` "erfcx" ` , ` "dawson" ` , ` "floor" ` , ` "ceil" ` |
342
+ | Binary | ` "/" ` , ` "^" ` , ` "atan" ` , ` "&&" ` , ` "\|\|" ` , ` "<=" ` , ` "<" ` , ` ">=" ` , ` ">" ` , ` "==" ` |
343
+ | N-ary | ` "+" ` , ` "-" ` , ` "*" ` , ` "ifelse" ` , ` "min" ` , ` "max" ` |
451
344
452
345
#### Example
453
346
@@ -462,31 +355,15 @@ In MathOptFormat, this expression graph can be encoded as follows:
462
355
"type" : " ScalarNonlinearFunction" ,
463
356
"root" : {
464
357
"type" : " +" ,
465
- "args" : [
466
- {"type" : " node" , "index" : 1 },
467
- {"type" : " node" , "index" : 3 },
468
- {"type" : " variable" , "name" : " y" }
469
- ]
358
+ "args" : [{"type" : " node" , "index" : 1 }, {"type" : " node" , "index" : 3 }, " y" ]
470
359
},
471
- "node_list" : [
472
- {
473
- "type" : " *" ,
474
- "args" : [
475
- {"type" : " complex" , "real" : 1 , "imag" : 3 },
476
- {"type" : " variable" , "name" : " x" }
477
- ]
478
- }, {
479
- "type" : " sin" ,
480
- "args" : [
481
- {"type" : " variable" , "name" : " x" }
482
- ]
483
- }, {
484
- "type" : " ^" ,
485
- "args" : [
486
- {"type" : " node" , "index" : 2 },
487
- {"type" : " real" , "value" : 2 }
488
- ]
489
- }
490
- ]
360
+ "node_list" : [{
361
+ "type" : " *" ,
362
+ "args" : [{"type" : " complex" , "real" : 1 , "imag" : 3 }, " x" ]
363
+ }, {
364
+ "type" : " sin" , "args" : [" x" ]
365
+ }, {
366
+ "type" : " ^" , "args" : [{"type" : " node" , "index" : 2 }, 2 ]
367
+ }]
491
368
}
492
369
```
0 commit comments