Semantics of Temporal Operators
Lilo adopts a semantics for temporal logic that is slightly non-standard, in the sense that it takes into account both a discrete and a continuous notion of time.
Background
Let T be a type. A sample of type T is a pair {time : Real, value : T}. A signal of type T is a finite sequence of at-least two samples of type T such that the time values are strictly increasing. We write Signal[T] to be the set of all signals of type T. We do not require the first sample of a signal to be at time 0. Given a signal Ο, we denote the elements of Ο as Ο[0], Ο[1], β¦, Ο[n-1] where n is the number of samples of Ο. Note that we distinguish between the number of samples of Ο and the duration of Ο (which is Ο[n-1].time - Ο[0].time).
The support of a signal Ο, denoted support(Ο), is the set of time values associated with the samples of Ο, i.e., support(Ο) = {Ο[i].time | 0 β€ i < n}. Two different notations are used to index samples in signals. We write Ο[time = t] to denote the value of Ο at time t, i.e., Ο[time = t] = Ο[i].value where i is such that Ο[i].time = t. Note that Ο[time = t] is only defined for t β support(Ο).
Consider, for example, the signals
v : Intandb : Booldefined by the following samples:v = [{time: 1.0, value: 10}, {time: 3.0, value: 20}, {time: 4.0, value: 20}, {time: 5.0, value: 30}, {time: 7.5, value: 40}, {time: 10.0, value: 20}, {time: 11.0, value: 10}, {time: 12.0, value: 10}] b = [{time: 1.0, value: true}, {time: 3.0, value: false}, {time: 4.0, value: false}, {time: 5.0, value: true}, {time: 7.5, value: false}, {time: 10.0, value: true}, {time: 11.0, value: true}, {time: 12.0, value: true}]They can be visualized as follows
Both
vandbhave 8 samples numbered from0to7. The support of both signals is{1.0, 3.0, 4.0, 5.0, 7.5, 10.0, 11.0, 12.0}. The same sample with value30can be indexed asv[time = 5.0]orv[3].
Each Lilo formula Ο is judged to be of some type T (written Ο : T), by the Lilo type system. The semantics of a Lilo formula of type T is understood as a function of type Signal[S] β Signal[T], where S is the type of the input signals described by the system. This function is defined to be support-preserving, i.e., the output signal is defined on exactly the same time values as the input signal. For a formula Ο of type T, we write γΟγ to denote this function.
Atemporal operators include the standard Boolean operators, arithmetic operators, comparison operators, conditionals and so on. A formula is said to be a pointwise formula if for any fixed time value t, the value of the output signal γΟγ(Ο)[time = t] depends only on the value of the input signal Ο[time = t]. A lilo expression is said to be atemporal if its intepretation does not depend on the input signals, and are therefore constant over time. Thus, a pointwise formula is built from input signals and atemporal operators, and an atemporal expression is built from params, constants and atemporal operators.
Consider the following lilo system
system main signal v : Int signal b : Bool param p : IntHere, the formula
v * 2is pointwise, while the formulap * 2is atemporal. The formulaeventually [0, 5] (v > p)is neither pointwise nor atemporal.
An interval of real numbers is written as a pair [a, b] where a: Real and b: Real | infinity with 0 β€ a β€ b. If b is infinity, we say that the interval is unbounded, and otherwise we say that the interval is bounded. For a time point t and an interval I, we write t + I or t - I to denote {t + x | x β I} or {t - x | x β I} respectively.
Note that the intervals t + I or t - I may be completely or partially outside the support of the input signal, possibly overshooting its upper and lower bounds. However, since our temporal operators are support-preserving, and are defined in terms of the intersection of these intervals with the support, this is of no consequence.
Temporal Operators and their Semantics
Temporal operators in Lilo, with some exceptions, are annotated with an interval. Given Ο : Bool, we define the following temporal operators.
- Always:
γalways[I] Ογ(Ο)[time = t] = true, if for allt' β (t + I) β© support(Ο),γΟγ(Ο)[time = t'] = true. - Eventually:
γeventually[I] Ογ(Ο)[time = t] = true, if there existst' β (t + I) β© support(Ο)such thatγΟγ(Ο)[time = t'] = true. - Historically:
γhistorically[I] Ογ(Ο)[time = t] = true, if for allt' β (t - I) β© support(Ο),γΟγ(Ο)[time = t'] = true. - Past:
γpast[I] Ογ(Ο)[time = t] = true, if there existst' β (t - I) β© support(Ο)such thatγΟγ(Ο)[time = t'] = true. - Until:
γΟ until[I] Ογ(Ο)[time = t] = true, if there existst' β (t + I) β© support(Ο)such thatγΟγ(Ο)[time = t'] = trueand for allt'' β support(Ο)satisfyingt β€ t'' < t',γΟγ(Ο)[time = t''] = true. - Since:
γΟ since[I] Ογ(Ο)[time = t] = true, if there existst' β (t - I) β© support(Ο)such thatγΟγ(Ο)[time = t'] = trueand for allt'' β support(Ο)satisfyingt' < t'' β€ t,γΟγ(Ο)[time = t''] = true.
Considering the signal
bfrom the running example, the formulasalways [1,2] bandeventually [1,2] bevaluate to the following.The formula
(v >= 20) until [1, 2] bevaluates to the following.
Note that the always and eventually operators are logical duals of each other. The logical dual of until is releases, i.e., Ο releases[I] Ο is defined as !(!Ο until[I] !Ο). The operators since, historically and past are the past-time counterparts of until, always and eventually respectively.
The operators will_change and did_change are defined for any well-typed Ο : T for which equality is defined (all non-function types, in practice) as follows.
- Will Change:
γwill_change[I] Ογ(Ο)[time = t] = true, if there exist two pointst', t'' β (t + I) β© support(Ο)such thatγΟγ(Ο)[time = t'] β γΟγ(Ο)[time = t'']. - Did Change:
γdid_change[I] Ογ(Ο)[time = t] = true, if there exist two pointst', t'' β (t - I) β© support(Ο)such thatγΟγ(Ο)[time = t'] β γΟγ(Ο)[time = t''].
The following operators cannot be annotated with an interval. And importantly, they are defined on the discrete time-semantics, i.e., they depend on the discrete index associated with the samples rather than the associated time. If the base formula Ο is of type T, then so are the formulas next Ο and previous Ο. We write n to denote the number of samples of the input signal Ο.
- Next:
γnext Ογ(Ο)[i] = γΟγ(Ο)[i + 1]for0 β€ i < n - 1andγnext Ογ(Ο)[n - 1] = γΟγ(Ο)[n - 1]. - Previous:
γprevious Ογ(Ο)[i] = γΟγ(Ο)[i - 1]for0 < i < nandγprevious Ογ(Ο)[0] = γΟγ(Ο)[0].
The following sliding window operators are defined for any Ο whose value is a numeric type. Note also that the associated interval must be of the form [0, b] where b is possibly infinity.
- Future Maximum:
γmax_future [0, a] Ογ(Ο)[time = t] = max{γΟγ(Ο)[time = t'] | t' β support(Ο), t β€ t' β€ t + a}. - Past Maximum:
γmax_past [0, a] Ογ(Ο)[time = t] = max{γΟγ(Ο)[time = t'] | t' β support(Ο), t - a β€ t' β€ t}. - Future Minimum:
γmin_future [0, a] Ογ(Ο)[time = t] = min{γΟγ(Ο)[time = t'] | t' β support(Ο), t β€ t' β€ t + a}. - Past Minimum:
γmin_past [0, a] Ογ(Ο)[time = t] = min{γΟγ(Ο)[time = t'] | t' β support(Ο), t - a β€ t' β€ t}.
Behavior of Temporal Operators at Signal Boundaries
At some time = t, the interval t + I or t - I may be completely or partially outside the support of the input signal Ο. We clarify the behavior of the temporal operators in such cases.
- Eventually, Past: For
eventually[I] Οorpast[I] Οto be true, a witness ofΟbeing true must exist. Specifically, if(t + I) β© support(Ο) = βor(t - I) β© support(Ο) = β, thenγeventually[I] Ογ(Ο)[time = t] = falseandγpast[I] Ογ(Ο)[time = t] = false. - Always, Historically: The formulas
always[I] Οorhistorically[I] Οare determined by the truth ofΟeverywhere in our intersection of interest with the support. When empty, the formulas are vacuously true. Formally, if(t + I) β© support(Ο) = βor(t - I) β© support(Ο) = β, thenγalways[I] Ογ(Ο)[time = t] = trueandγhistorically[I] Ογ(Ο)[time = t] = true. - Until, Since: In the case of the formulas
Ο until[I] ΟorΟ since[I] Ο, the witness forΟmust exist. If(t + I) β© support(Ο) = βor(t - I) β© support(Ο) = β, thenγΟ until[I] Ογ(Ο)[time = t] = falseandγΟ since[I] Ογ(Ο)[time = t] = false. On the other hand, if there are no time points insupport(Ο)betweentand the witness forΟ, then the formula does not require the truth ofΟanywhere. - Next, Previous: The values of
next Οandprevious Οare defined by the closest sample in the direction of interest. We haveγprevious Ογ(Ο)[0] = γΟγ(Ο)[0]. If the signal hasnsamples, then the last sample satisfiesγnext Ογ(Ο)[n - 1] = γΟγ(Ο)[n - 1]. - Will Change, Did Change: The formulas
will_change[I] Οanddid_change[I] Οrequire two distinct time points in the intersection of interest with the support. If(t + I) β© support(Ο)or(t - I) β© support(Ο)has only one time point or no time points, thenγwill_change[I] Ογ(Ο)[time = t] = falseandγdid_change[I] Ογ(Ο)[time = t] = false. - Maximum, Minimum: The intervals allowed in the formulas
{max,min}_{future,past}are required to begin with0. Therefore, ift β support(Ο), thentalso satisfiest β ((t + I) β© support(Ο)), and hence it cannot be empty. If this set is a singleton, the formula evaluates to the value ofΟat the timetitself.
Consider the values of the formulas
always [1, 2] bandeventually [1, 2] bin the illustration above. At timest = 5,7.5, and12, the intervalst + [1, 2]are[6, 7],[8.5, 9.5], and[13, 14]respectively. The intersection of these intervals with the support ofbis empty, as shown in the timeline below. Thus, no witness foreventuallyexists, and the formulaeventually [1, 2] bevaluates tofalseon all of these points. On the other hand, the formulaalways [1, 2] bevaluates totrueon all of these points, since it is vacuously true (i.e., there are no points in the support ofbon which the formula imposes a constraint).
Similarly, in the formula
(v >= 20) until [1, 2] b, at timest = 5,t = 7.5andt = 12, the formula evaluates tofalsesince there is no witness forbin the intervals of interest.