@@ -41,20 +41,22 @@ Compiler.has_extended_unionsplit(::EqStructureLattice) = true
4141
4242# ############################# Linearity #######################################
4343
44- # XXX : update docstring
4544"""
46- struct Linearity
45+ Base.@kwdef struct Linearity
46+ time_dependent::Bool = true
47+ state_dependent::Bool = true
4748 nonlinear::Bool = true
4849 end
4950
50- This struct expresses linearity information: linear or nonlinear.
51+ Together with `Float64` values in `Incidence`, this struct expresses linearity information:
52+ - Linear, coefficient is a known constant (a `Float64` value).
53+ - Linear, coefficient is an unknown constant (`linear`).
54+ - Linear, coefficient is unknown with a known state or time dependence (`linear_state_dependent`, `linear_time_dependent`).
55+ - Linear, coefficient is unknown with both state and time dependence (`linear_time_and_state_dependent`).
56+ - Nonlinear (`nonlinear` - always taints state and time dependence currently).
5157
52- Nonlinearity is similar to `missing` in that arithmetic with it is
53- saturating. When used as a coefficient in the Incidence lattice, it indicates
54- that the corresponding variable does not have a (constant) linear coefficient.
55- This may either mean that the variable in question has a non-constant linear
56- coefficient or that the variable is used non-linearly. We do not currently
57- distinguish the two situations.
58+ A known constant-coefficient contains the highest level of information. `nonlinear` contains the lowest
59+ (and most conservative) level of information, and should be assumed used by default or if uncertain.
5860"""
5961Base. @kwdef struct Linearity
6062 time_dependent:: Bool = true
@@ -68,10 +70,15 @@ Base.@kwdef struct Linearity
6870 end
6971end
7072
73+ " The variable is used linearly, with an unknown constant."
7174const linear = Linearity (time_dependent = false , state_dependent = false , nonlinear = false )
75+ " The variable is used linearly, with an unknown constant that may depend on time."
7276const linear_time_dependent = Linearity (state_dependent = false , nonlinear = false )
77+ " The variable is used linearly, with an unknown constant that may depend on time and on other states."
7378const linear_state_dependent = Linearity (time_dependent = false , nonlinear = false )
79+ " The variable is used linearly, with an unknown constant that may depend on time and on other states."
7480const linear_time_and_state_dependent = Linearity (nonlinear = false )
81+ " The variable is used nonlinearly, with a possible dependence on time and other states."
7582const nonlinear = Linearity ()
7683
7784join_linearity (a:: Linearity , b:: Real ) = a
@@ -128,6 +135,9 @@ elements are defined by subset inclusion. Note that in particular this implies
128135that plain `T` lattice elements have unknown incidence and `Const` lattice elements
129136have no incidence. A lattice element of type `T` that is known to be state-independent
130137would have lattice element `Incidence(T, {})`.
138+
139+ For convenience, you may want to use the `incidence"..."` string macro to construct an
140+ [`Incidence`](@ref) from its printed representation.
131141"""
132142struct Incidence
133143 # Considered additive to `row`. In particular, if the `typ` is Float64,
@@ -253,6 +263,11 @@ function Base.show(io::IO, inc::Incidence)
253263 print (io, " )" )
254264end
255265
266+ """
267+ incidence"a + f(∝ₛt, u₁)"
268+
269+ Construct an [`Incidence`](@ref) from its printed representation.
270+ """
256271macro incidence_str (str) generate_incidence (str) end
257272
258273function generate_incidence (str:: String )
0 commit comments