Skip to content

Commit 53dac1b

Browse files
committed
update docs
1 parent cf67517 commit 53dac1b

File tree

3 files changed

+33
-39
lines changed

3 files changed

+33
-39
lines changed

docs/src/build_function.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Function Building and Compilation (build_function)
22

3-
At any time, callable functions can be generated from ModelingToolkit IR by using
4-
`convert(Expr,x)`. This performs some cleaning to return an expression without
5-
extraneous pieces that commonly matches expressions one would write in functions
6-
like those for differential equation solvers and optimization libraries. These
7-
functions can be automatically parallelize and specialize on Julia types like
8-
static arrays and sparse matrices.
3+
At any time, callable functions can be generated from ModelingToolkit IR by
4+
using `ModelingToolkit.toexpr`. This performs some cleaning to return an
5+
expression without extraneous pieces that commonly matches expressions one
6+
would write in functions like those for differential equation solvers and
7+
optimization libraries. These functions can be automatically parallelize and
8+
specialize on Julia types like static arrays and sparse matrices.
99

1010
The core compilation process of ModelingToolkit IR is `build_function`.
1111
`build_function` takes an operation or an `AbstractArray` of operations and

docs/src/highlevel.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ latexify(ex)
4242
```
4343

4444
will produce LaTeX output from ModelingToolkit models and expressions.
45-
This works on basics like `Operation` all the way to higher primitives
45+
This works on basics like `Term` all the way to higher primitives
4646
like `ODESystem` and `ReactionSystem`.
4747

4848
## The Auto-Detecting System Constructors
@@ -78,7 +78,7 @@ du
7878
```
7979

8080
```julia
81-
3-element Array{Operation,1}:
81+
3-element Array{Num,1}:
8282
10.0 * (u₂(t) - u₁(t))
8383
u₁(t) * (28.0 - u₃(t)) - u₂(t)
8484
u₁(t) * u₂(t) - 2.6666666666666665 * u₃(t)
@@ -97,7 +97,7 @@ du
9797
```
9898

9999
```julia
100-
3-element Array{Operation,1}:
100+
3-element Array{Num,1}:
101101
10.0 * (y(t) - x(t))
102102
x(t) * (28.0 - z(t)) - y(t)
103103
x(t) * y(t) - 2.6666666666666665 * z(t)
@@ -106,7 +106,7 @@ x(t) * y(t) - 2.6666666666666665 * z(t)
106106
## Intermediate Calculations
107107

108108
The system building functions can handle intermediate calculations by simply
109-
defining and using an `Operation` of `Variable`s. For example:
109+
defining and using an `Term` of `Sym`s. For example:
110110

111111
```julia
112112
@variables x y z

docs/src/tutorials/symbolic_functions.md

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ A = [x^2+y 0 2x
2424
0 0 2y
2525
y^2+x 0 0]
2626

27-
3×3 Array{Expression,2}:
28-
x ^ 2 + y Constant(0) 2x
29-
Constant(0) Constant(0) 2y
30-
y ^ 2 + x Constant(0) Constant(0)
27+
3×3 Array{Num,2}:
28+
x ^ 2 + y 0 2x
29+
0 0 2y
30+
y ^ 2 + x 0 0
3131
```
3232

3333
To better view the results, we can use [Latexify.jl](https://github.com/korsbo/Latexify.jl).
@@ -42,9 +42,9 @@ latexify(A)
4242
\begin{equation}
4343
\left[
4444
\begin{array}{ccc}
45-
x ^ 2 + y & ModelingToolkit.Constant(0) & 2x \\
46-
ModelingToolkit.Constant(0) & ModelingToolkit.Constant(0) & 2y \\
47-
y ^ 2 + x & ModelingToolkit.Constant(0) & ModelingToolkit.Constant(0) \\
45+
(x ^ 2) + y & 0 & 2 * x \\
46+
0 & 0 & 2 * y \\
47+
(y ^ 2) + x & 0 & 0 \\
4848
\end{array}
4949
\right]
5050
\end{equation}
@@ -58,10 +58,10 @@ using SparseArrays
5858
spA = sparse(A)
5959

6060
3×3 SparseMatrixCSC{Expression,Int64} with 4 stored entries:
61-
[1, 1] = x ^ 2 + y
62-
[3, 1] = y ^ 2 + x
63-
[1, 3] = 2x
64-
[2, 3] = 2y
61+
[1, 1] = (x ^ 2) + y
62+
[3, 1] = (y ^ 2) + x
63+
[1, 3] = 2 * x
64+
[2, 3] = 2 * y
6565
```
6666

6767
We can thus use normal Julia functions as generators for sparse
@@ -73,7 +73,7 @@ function f(u)
7373
end
7474
f([x,y,z]) # Recall that z = x^2 + y
7575

76-
3-element Array{Operation,1}:
76+
3-element Array{Num,1}:
7777
x - (x ^ 2 + y)
7878
x ^ 2 - y
7979
(x ^ 2 + y) + y
@@ -85,7 +85,7 @@ Or we can build array variables and use these to trace:
8585
@variables u[1:3]
8686
f(u)
8787

88-
3-element Array{Operation,1}:
88+
3-element Array{Num,1}:
8989
u₁ - u₃
9090
u₁ ^ 2 - u₂
9191
u₃ + u₂
@@ -178,7 +178,7 @@ a function via a sparse matrix. For example:
178178
N = 8
179179
A = sparse(Tridiagonal([x^i for i in 1:N-1],[x^i * y^(8-i) for i in 1:N], [y^i for i in 1:N-1]))
180180

181-
8×8 SparseMatrixCSC{Operation,Int64} with 22 stored entries:
181+
8×8 SparseMatrixCSC{Num,Int64} with 22 stored entries:
182182
[1, 1] = x ^ 1 * y ^ 7
183183
[2, 1] = x ^ 1
184184
[1, 2] = y ^ 1
@@ -338,7 +338,7 @@ This can be applied to arrays by using Julia's broadcast mechanism:
338338
B = simplify.([t^2+t+t^2 2t+4t
339339
x+y+y+2t x^2 - x^2 + y^2])
340340

341-
2×2 Array{Operation,2}:
341+
2×2 Array{Num,2}:
342342
2 * t ^ 2 + t 6t
343343
x + 2 * (t + y) y ^ 2
344344
```
@@ -348,7 +348,7 @@ We can then use `substitute` to change values of an expression around:
348348
```julia
349349
simplify.(substitute.(B,[x=>y^2]))
350350

351-
2×2 Array{Operation,2}:
351+
2×2 Array{Num,2}:
352352
2 * t ^ 2 + t 6t
353353
y ^ 2 + 2 * (t + y) y ^ 2
354354
```
@@ -380,8 +380,8 @@ the user's code. For these cases, ModelingToolkit.jl allows for fully
380380
macro-free usage. For example:
381381

382382
```julia
383-
x = Variable{Float64}(:x)()
384-
y = Variable{Float64}(:y)()
383+
x = Sym{Float64}(:x)()
384+
y = Sym{Float64}(:y)()
385385
x+y^2.0
386386
```
387387

@@ -396,23 +396,17 @@ convert the output to an `Expr`:
396396
Expr(x+y^2)
397397
```
398398

399-
## Variables as Operations
399+
## `Sym`s and callable `Sym`s
400400

401-
`Operation` is the type name the ModelingToolkit.jl gives to symbolic
402-
expressions. In ModelingToolkit.jl, essentially everything is an
403-
`Operation`. Notice that when we defined our variables above, they
404-
were represented as an `Operation` as well, which means that variables
405-
alone are an operation that can then be composed to make bigger
406-
operations.
407-
408-
But since variables are functions, we can represent their dependencies
409-
as well. For example:
401+
In the definition
410402

411403
```julia
412404
@variables t x(t) y(t)
413405
```
414406

415-
defines `t` as a dependent variable while `x(t)` and `y(t)` are
407+
`t` is of type `Sym{Real}` but the name `x` refers to an object that represents the `Term` `x(t)`. The operation of this expression is itself the object `Sym{FnType{Tuple{Real}, Real}}(:x)`. The type `Sym{FnType{...}}` represents a callable object. In this case specifically it's a function that takes 1 Real argument (noted by `Tuple{Real}`) and returns a `Real` result. You can call such a callable `Sym` with either a number or a symbolic expression of a permissible type.
408+
409+
this expression also defines `t` as a dependent variable while `x(t)` and `y(t)` are
416410
independent variables. This is accounted for in differentiation:
417411

418412
```julia

0 commit comments

Comments
 (0)