Skip to content

Commit ed9626f

Browse files
committed
Update docstrings
1 parent c51d53b commit ed9626f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/Nonlinear/SymbolicAD/SymbolicAD.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ Return a simplified copy of the function `f`.
1818
1919
!!! warning
2020
This function is not type stable by design.
21+
22+
## Example
23+
24+
```jldoctest
25+
julia> import MathOptInterface as MOI
26+
27+
julia> x = MOI.VariableIndex(1)
28+
MOI.VariableIndex(1)
29+
30+
julia> f = MOI.ScalarNonlinearFunction(:^, Any[x, 1])
31+
^(MOI.VariableIndex(1), (1))
32+
33+
julia> MOI.Nonlinear.SymbolicAD.simplify(f)
34+
MOI.VariableIndex(1)
35+
```
2136
"""
2237
simplify(f) = simplify!(copy(f))
2338

@@ -33,6 +48,27 @@ new object if `f` can be represented in a simpler type.
3348
3449
!!! warning
3550
This function is not type stable by design.
51+
52+
## Example
53+
54+
```jldoctest
55+
julia> import MathOptInterface as MOI
56+
57+
julia> x = MOI.VariableIndex(1)
58+
MOI.VariableIndex(1)
59+
60+
julia> f = MOI.ScalarNonlinearFunction(
61+
:+,
62+
Any[MOI.ScalarNonlinearFunction(:+, Any[1.0, x]), 2.0 * x + 3.0],
63+
)
64+
+(+(1.0, MOI.VariableIndex(1)), 3.0 + 2.0 MOI.VariableIndex(1))
65+
66+
julia> MOI.Nonlinear.SymbolicAD.simplify!(f)
67+
+(1.0, MOI.VariableIndex(1), 3.0 + 2.0 MOI.VariableIndex(1))
68+
69+
julia> f
70+
+(1.0, MOI.VariableIndex(1), 3.0 + 2.0 MOI.VariableIndex(1))
71+
```
3672
"""
3773
simplify!(f) = f
3874

@@ -311,6 +347,26 @@ end
311347
variables(f::Union{Real,MOI.AbstractScalarFunction})
312348
313349
Return a sorted list of the `MOI.VariableIndex` present in the function `f`.
350+
351+
## Example
352+
353+
```jldoctest
354+
julia> import MathOptInterface as MOI
355+
356+
julia> x = MOI.VariableIndex.(1:3)
357+
3-element Vector{MathOptInterface.VariableIndex}:
358+
MOI.VariableIndex(1)
359+
MOI.VariableIndex(2)
360+
MOI.VariableIndex(3)
361+
362+
julia> f = MOI.ScalarNonlinearFunction(:atan, Any[x[3], 2.0 * x[1]])
363+
atan(MOI.VariableIndex(3), 0.0 + 2.0 MOI.VariableIndex(1))
364+
365+
julia> MOI.Nonlinear.SymbolicAD.variables(f)
366+
2-element Vector{MathOptInterface.VariableIndex}:
367+
MOI.VariableIndex(1)
368+
MOI.VariableIndex(3)
369+
```
314370
"""
315371
function variables(f::MOI.AbstractScalarFunction)
316372
ret = MOI.VariableIndex[]
@@ -398,6 +454,24 @@ like `*(false, g)` that can be trivially simplified to `false`.
398454
399455
In most cases, you should call `simplify!(derivative(f, x))` to return a
400456
simplified expression of the derivative.
457+
458+
## Example
459+
460+
```jldoctest
461+
julia> import MathOptInterface as MOI
462+
463+
julia> x = MOI.VariableIndex(1)
464+
MOI.VariableIndex(1)
465+
466+
julia> f = MOI.ScalarNonlinearFunction(:sin, Any[x])
467+
sin(MOI.VariableIndex(1))
468+
469+
julia> df_dx = MOI.Nonlinear.SymbolicAD.derivative(f, x)
470+
*(cos(MOI.VariableIndex(1)), (true))
471+
472+
julia> MOI.Nonlinear.SymbolicAD.simplify!(df_dx)
473+
cos(MOI.VariableIndex(1))
474+
```
401475
"""
402476
derivative(::Real, ::MOI.VariableIndex) = false
403477

0 commit comments

Comments
 (0)