@@ -43,11 +43,10 @@ eqs = [D(x) ~ σ*(y-x),
4343
4444Each operation builds an ` Operation ` type, and thus ` eqs ` is an array of
4545` Operation ` and ` Variable ` s. This holds a tree of the full system that can be
46- analyzed by other programs. We can turn this into a ` DiffEqSystem ` via:
46+ analyzed by other programs. We can turn this into a ` ODESystem ` via:
4747
4848``` julia
49- de = DiffEqSystem (eqs,t,[x,y,z],[σ,ρ,β])
50- de = DiffEqSystem (eqs)
49+ de = ODESystem (eqs)
5150```
5251
5352where we tell it the variable types and ordering in the first version, or let it
@@ -56,7 +55,7 @@ This can then generate the function. For example, we can see the
5655generated code via:
5756
5857``` julia
59- generate_function (de)
58+ generate_function (de, [x,y,z], [σ,ρ,β] )
6059
6160# # Which returns:
6261:((# #363, u, p, t)->begin
@@ -71,7 +70,7 @@ generate_function(de)
7170and get the generated function via:
7271
7372``` julia
74- f = ODEFunction (de)
73+ f = ODEFunction (de, [x,y,z], [σ,ρ,β] )
7574```
7675
7776### Example: Nonlinear System
@@ -88,8 +87,8 @@ derivatives are zero. We use (unknown) variables for our nonlinear system.
8887eqs = [0 ~ σ* (y- x),
8988 0 ~ x* (ρ- z)- y,
9089 0 ~ x* y - β* z]
91- ns = NonlinearSystem (eqs)
92- nlsys_func = generate_function (ns)
90+ ns = NonlinearSystem (eqs, [x,y,z] )
91+ nlsys_func = generate_function (ns, [x,y,z], [ρ,σ,β] )
9392```
9493
9594which generates:
@@ -130,17 +129,49 @@ In this section we define the core pieces of the IR and what they mean.
130129
131130### Variables
132131
133- The most fundamental part of the IR is the `Variable`. The `Variable` is the
132+ The most fundamental part of the IR is the `Variable`. In order to mirror the
133+ intention of solving for variables and representing function-like parameters,
134+ we treat each instance of `Variable` as a function which is called on its
135+ arguments using the natural syntax. Rather than having additional mechanisms
136+ for handling constant variables and parameters, we simply represent them as
137+ constant functions.
138+
139+ The `Variable` is the
134140context-aware single variable of the IR. Its fields are described as follows:
135141
136142- `name`: the name of the `Variable`. Note that this is not necessarily
137143 the same as the name of the Julia variable. But this symbol itself is considered
138144 the core identifier of the `Variable` in the sense of equality.
139145- `known`: the main denotation of context, storing whether or not the value of
140146 the variable is known.
141- - `dependents`: the vector of variables on which the current variable
142- is dependent. For example, `u(t,x)` has dependents `[t,x]`. Derivatives thus
143- require this information in order to simplify down.
147+
148+ For example, the following code defines an independent variable `t`, a parameter
149+ `α`, a function parameter `σ`, a variable `x` which depends on `t`, a variable
150+ `y` with no dependents, and a variable `z` which depends on `t`, `α`, and `x(t)`.
151+
152+ ``` julia
153+ t = Variable (:t ; known = true )() # independent variables are treated as known
154+ α = Variable (:α ; known = true )() # parameters are known
155+ σ = Variable (:σ ; known = true ) # left uncalled, since it is used as a function
156+ w = Variable (:w ; known = false ) # unknown, left uncalled
157+ x = Variable (:x ; known = false )(t) # unknown, depends on `t`
158+ y = Variable (:y ; known = false )() # unknown, no dependents
159+ z = Variable (:z ; known = false )(t, α, x) # unknown, multiple arguments
160+
161+ expr = x + y^ α + σ (3 ) * (z - t) - w (t - 1 )
162+ ```
163+
164+ We can rewrite this more concisely using macros. Note the difference between
165+ including and excluding empty parentheses. When in call format, variables are
166+ aliased to the given call, allowing implicit use of dependents for convenience.
167+
168+ ``` julia
169+ @parameters t () α () σ
170+ @variables w x (t) y () z (t, α, x)
171+
172+ expr = x + y^ α + σ (3 ) * (z - t) - w (t - 1 )
173+ ```
174+
144175
145176### Constants
146177
@@ -243,37 +274,37 @@ is accessible via a function-based interface. This means that all macros are
243274syntactic sugar in some form. For example, the variable construction:
244275
245276``` julia
246- @parameters t σ ρ β
277+ @parameters t () σ ρ () β ()
247278@variables x (t) y (t) z (t)
248279@derivatives D' ~ t
249280```
250281
251282is syntactic sugar for:
252283
253284``` julia
254- t = Variable (:t ; known = true )
255- x = Variable (:x , [t])
256- y = Variable (:y , [t])
257- z = Variable (:z , [t])
258- D = Differential (t)
285+ t = Variable (:t ; known = true )()
259286σ = Variable (:σ ; known = true )
260- ρ = Variable (:ρ ; known = true )
261- β = Variable (:β ; known = true )
287+ ρ = Variable (:ρ ; known = true )()
288+ β = Variable (:β ; known = true )()
289+ x = Variable (:x )(t)
290+ y = Variable (:y )(t)
291+ z = Variable (:z )(t)
292+ D = Differential (t)
262293```
263294
264295### Intermediate Calculations
265296
266297The system building functions can handle intermediate calculations. For example,
267298
268299``` julia
269- @variables x y z
270- @parameters σ ρ β
300+ @variables x () y () z ()
301+ @parameters σ () ρ () β ()
271302a = y - x
272303eqs = [0 ~ σ* a,
273304 0 ~ x* (ρ- z)- y,
274305 0 ~ x* y - β* z]
275- ns = NonlinearSystem (eqs,[x,y,z],[σ,ρ,β ])
276- nlsys_func = generate_function (ns)
306+ ns = NonlinearSystem (eqs, [x,y,z])
307+ nlsys_func = generate_function (ns, [x,y,z], [σ,ρ,β] )
277308```
278309
279310expands to:
0 commit comments