Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation updates #1388

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/manual/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Note that at this time array derivatives cannot be defined.

## Direct Registration API (Advanced, Experimental)

!!! warn
!!! warning

This is a lower level API which is not as stable as the macro APIs.

Expand Down
4 changes: 2 additions & 2 deletions docs/src/manual/parsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ to convert from Julia expressions to Symbolics.jl expressions for further
manipulation. Towards this end is the `parse_expr_to_symbolic` which performs
the parsing.

!!! warn
!!! warning
Take the limitations mentioned in the `parse_expr_to_symbolic` docstrings
seriously! Because Julia expressions contain no symbolic metadata, there
is limited information and thus the parsing requires heuristics to work.
is limited information and thus the parsing requires heuristics to work.

```@docs
parse_expr_to_symbolic
Expand Down
2 changes: 1 addition & 1 deletion src/Symbolics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ include("complex.jl")

Performs the substitution on `expr` according to rule(s) `s`.
# Examples
```julia
```jldoctest
julia> @variables t x y z(t)
4-element Vector{Num}:
t
Expand Down
2 changes: 1 addition & 1 deletion src/arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ end
"""
shape(s::Any)

Returns `axes(s)` or Unknown().
Returns `axes(s)` or `Unknown()`.
"""
shape(s) = axes(s)

Expand Down
112 changes: 54 additions & 58 deletions src/build_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ function throw_missing_specialization(n)
end

"""
`build_function`
build_function(ex, args...;
expression = Val{true},
target = JuliaTarget(),
parallel=nothing,
kwargs...)

Generates a numerically-usable function from a Symbolics `Num`.

```julia
build_function(ex, args...;
expression = Val{true},
target = JuliaTarget(),
parallel=nothing,
kwargs...)
```

Arguments:

- `ex`: The `Num` to compile
Expand Down Expand Up @@ -220,16 +216,16 @@ end
Build function target: `JuliaTarget`

```julia
function _build_function(target::JuliaTarget, rhss, args...;
conv = toexpr,
expression = Val{true},
checkbounds = false,
linenumbers = false,
headerfun = addheader, outputidxs=nothing,
convert_oop = true, force_SA = false,
skipzeros = outputidxs===nothing,
fillzeros = skipzeros && !(typeof(rhss)<:SparseMatrixCSC),
parallel=SerialForm(), kwargs...)
_build_function(target::JuliaTarget, rhss, args...;
conv = toexpr,
expression = Val{true},
checkbounds = false,
linenumbers = false,
headerfun = addheader, outputidxs=nothing,
convert_oop = true, force_SA = false,
skipzeros = outputidxs===nothing,
fillzeros = skipzeros && !(typeof(rhss)<:SparseMatrixCSC),
parallel=SerialForm(), kwargs...)
```

Generates a Julia function which can then be utilized for further evaluations.
Expand Down Expand Up @@ -676,11 +672,11 @@ end
Build function target: `CTarget`

```julia
function _build_function(target::CTarget, eqs::Array{<:Equation}, args...;
conv = toexpr, expression = Val{true},
fname = :diffeqf,
lhsname=:du,rhsnames=[Symbol("RHS\$i") for i in 1:length(args)],
libpath=tempname(),compiler=:gcc)
_build_function(target::CTarget, eqs::Array{<:Equation}, args...;
conv = toexpr, expression = Val{true},
fname = :diffeqf,
lhsname=:du,rhsnames=[Symbol("RHS\$i") for i in 1:length(args)],
libpath=tempname(), compiler=:gcc)
```

This builds an in-place C function. Only works on arrays of equations. If
Expand All @@ -689,7 +685,7 @@ and returns a lambda to that compiled function. These special keyword arguments
control the compilation:

- libpath: the path to store the binary. Defaults to a temporary path.
- compiler: which C compiler to use. Defaults to :gcc, which is currently the
- compiler: which C compiler to use. Defaults to `:gcc`, which is currently the
only available option.
"""
function _build_function(target::CTarget, eqs::Array{<:Equation}, args...;
Expand Down Expand Up @@ -736,15 +732,15 @@ end
Build function target: `CTarget`

```julia
function _build_function(target::CTarget, ex::AbstractArray, args...;
columnmajor = true,
conv = toexpr,
expression = Val{true},
fname = :diffeqf,
lhsname = :du,
rhsnames = [Symbol("RHS\$i") for i in 1:length(args)],
libpath = tempname(),
compiler = :gcc)
_build_function(target::CTarget, ex::AbstractArray, args...;
columnmajor = true,
conv = toexpr,
expression = Val{true},
fname = :diffeqf,
lhsname = :du,
rhsnames = [Symbol("RHS\$i") for i in 1:length(args)],
libpath = tempname(),
compiler = :gcc)
```

This builds an in-place C function. Only works on expressions. If
Expand Down Expand Up @@ -823,14 +819,14 @@ _build_function(target::CTarget, ex::Num, args...; kwargs...) = _build_function(
Build function target: `StanTarget`

```julia
function _build_function(target::StanTarget, eqs::Array{<:Equation}, vs, ps, iv;
conv = toexpr, expression = Val{true},
fname = :diffeqf, lhsname=:internal_var___du,
rhsnames=[:internal_var___u,:internal_var___p,:internal_var___t])
_build_function(target::StanTarget, eqs::Array{<:Equation}, vs, ps, iv;
conv = toexpr, expression = Val{true},
fname = :diffeqf, lhsname=:internal_var___du,
rhsnames=[:internal_var___u,:internal_var___p,:internal_var___t])
```

This builds an in-place Stan function compatible with the Stan differential equation solvers.
Unlike other build targets, this one requires (vs, ps, iv) as the function arguments.
Unlike other build targets, this one requires `(vs, ps, iv)` as the function arguments.
Only allowed on arrays of equations.
"""
function _build_function(target::StanTarget, eqs::Array{<:Equation}, vs, ps, iv;
Expand Down Expand Up @@ -862,16 +858,16 @@ end
Build function target: `StanTarget`

```julia
function _build_function(target::StanTarget, ex::AbstractArray, vs, ps, iv;
columnmajor = true,
conv = toexpr,
expression = Val{true},
fname = :diffeqf, lhsname=:internal_var___du,
rhsnames = [:internal_var___u,:internal_var___p,:internal_var___t])
_build_function(target::StanTarget, ex::AbstractArray, vs, ps, iv;
columnmajor = true,
conv = toexpr,
expression = Val{true},
fname = :diffeqf, lhsname=:internal_var___du,
rhsnames = [:internal_var___u,:internal_var___p,:internal_var___t])
```

This builds an in-place Stan function compatible with the Stan differential equation solvers.
Unlike other build targets, this one requires (vs, ps, iv) as the function arguments.
Unlike other build targets, this one requires `(vs, ps, iv)` as the function arguments.
Only allowed on expressions, and arrays of expressions.
"""
function _build_function(target::StanTarget, ex::AbstractArray, vs, ps, iv;
Expand Down Expand Up @@ -920,13 +916,13 @@ _build_function(target::StanTarget, ex::Num, vs, ps, iv; kwargs...) = _build_fun
Build function target: `MATLABTarget`

```julia
function _build_function(target::MATLABTarget, eqs::Array{<:Equation}, args...;
conv = toexpr, expression = Val{true},
lhsname=:internal_var___du,
rhsnames=[:internal_var___u,:internal_var___p,:internal_var___t])
_build_function(target::MATLABTarget, eqs::Array{<:Equation}, args...;
conv = toexpr, expression = Val{true},
lhsname=:internal_var___du,
rhsnames=[:internal_var___u,:internal_var___p,:internal_var___t])
```

This builds an out of place anonymous function @(t,rhsnames[1]) to be used in MATLAB.
This builds an out of place anonymous function `@(t,rhsnames[1])` to be used in MATLAB.
Compatible with the MATLAB differential equation solvers. Only allowed on expressions,
and arrays of expressions.
"""
Expand All @@ -953,13 +949,13 @@ end
Build function target: `MATLABTarget`

```julia
function _build_function(target::MATLABTarget, ex::AbstractArray, args...;
columnmajor = true,
conv = toexpr,
expression = Val{true},
fname = :diffeqf,
lhsname = :internal_var___du,
rhsnames = [:internal_var___u,:internal_var___p,:internal_var___t])
_build_function(target::MATLABTarget, ex::AbstractArray, args...;
columnmajor = true,
conv = toexpr,
expression = Val{true},
fname = :diffeqf,
lhsname = :internal_var___du,
rhsnames = [:internal_var___u,:internal_var___p,:internal_var___t])
```

This builds an out of place anonymous function @(t,rhsnames[1]) to be used in MATLAB.
Expand Down
6 changes: 3 additions & 3 deletions src/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ and other derivative rules to expand any derivatives it encounters.
```jldoctest
julia> @variables x y z k;

julia> f=k*(abs(x-y)/y-z)^2
julia> f = k*(abs(x-y)/y-z)^2
k*((abs(x - y) / y - z)^2)

julia> Dx=Differential(x) # Differentiate wrt x
julia> Dx = Differential(x) # Differentiate wrt x
(::Differential) (generic function with 2 methods)

julia> dfx=expand_derivatives(Dx(f))
julia> dfx = expand_derivatives(Dx(f))
(k*((2abs(x - y)) / y - 2z)*IfElse.ifelse(signbit(x - y), -1, 1)) / y
```
"""
Expand Down
2 changes: 1 addition & 1 deletion src/linear_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Currently only works if all equations are linear. `check` if the expr is linear
w.r.t `vars`.

# Examples
```julia
```jldoctest
julia> @variables x y
2-element Vector{Num}:
x
Expand Down
4 changes: 2 additions & 2 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end
Get the time (in seconds) spent in a state in a finite state machine.

When used to query the time spent in the enclosing state, the method without arguments is used, i.e.,
```
```julia
@mtkmodel FSM begin
...
@equations begin
Expand All @@ -56,7 +56,7 @@ timeInState
Get the number of ticks spent in a state in a finite state machine.

When used to query the number of ticks spent in the enclosing state, the method without arguments is used, i.e.,
```
```julia
@mtkmodel FSM begin
...
@equations begin
Expand Down
6 changes: 4 additions & 2 deletions src/rewrite-helpers.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
replacenode(expr::Symbolic, rules...)
replacenode(expr::Symbolic, rules...)

Walk the expression and replacenode subexpressions according to `rules`. `rules`
could be rules constructed with `@rule`, a function, or a pair where the
left hand side is matched with equality (using `isequal`) and is replacenoded by the right hand side.
Expand Down Expand Up @@ -75,7 +76,8 @@ function _hasnode(r, y)
end

"""
filterchildren(c, x)
filterchildren(c, x)

Returns all parts of `x` that fulfills the condition given in c. c can be a function or an expression.
If it is a function, returns everything for which the function is `true`. If c is an expression, returns
all expressions that matches it.
Expand Down
6 changes: 3 additions & 3 deletions src/taylor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Return the power series in `x` around `x0` to the powers `ns` with coefficients
Examples
========

```julia
```jldoctest
julia> @variables x y[0:3] z
3-element Vector{Any}:
x
Expand Down Expand Up @@ -47,7 +47,7 @@ Calculate the `n`-th order coefficient(s) in the Taylor series of `f` around `x

Examples
========
```julia
```jldoctest
julia> @variables x y
2-element Vector{Num}:
x
Expand Down Expand Up @@ -101,7 +101,7 @@ If `rationalize`, float coefficients are approximated as rational numbers (this

Examples
========
```julia
```jldoctest
julia> @variables x
1-element Vector{Num}:
x
Expand Down
10 changes: 5 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Return a vector of variables appearing in `e`, optionally restricting to variabl
Note that the returned variables are not wrapped in the `Num` type.

# Examples
```julia
```jldoctest
julia> @variables t x y z(t);

julia> Symbolics.get_variables(x + y + sin(z); sort = true)
Expand Down Expand Up @@ -97,7 +97,7 @@ Convert a differential variable to a `Term`. Note that it only takes a `Term`
not a `Num`.
Any upstream metadata can be passed via `x_metadata`

```julia
```jldoctest
julia> @variables x t u(x, t) z(t)[1:2]; Dt = Differential(t); Dx = Differential(x);

julia> Symbolics.diff2term(Symbolics.value(Dx(Dt(u))))
Expand Down Expand Up @@ -156,7 +156,7 @@ it will only output `y` instead of `y(t)`.

# Examples

```julia
```jldoctest
julia> @variables t z(t)
2-element Vector{Num}:
t
Expand Down Expand Up @@ -251,7 +251,7 @@ Extract the degree of `p` with respect to `sym`.

# Examples

```julia
```jldoctest
julia> @variables x;

julia> Symbolics.degree(x^0)
Expand Down Expand Up @@ -305,7 +305,7 @@ Note that `p` might need to be expanded and/or simplified with `expand` and/or `

# Examples

```julia
```jldoctest
julia> @variables a x y;

julia> Symbolics.coeff(2a, x)
Expand Down
Loading
Loading