The Stable Model Semantics of Datalog with Metric Temporal Operators

We introduce negation under the stable model semantics in DatalogMTL - a temporal extension of Datalog with metric temporal operators. As a result, we obtain a rule language which combines the power of answer set programming with the temporal dimension provided by metric operators. We show that, in this setting, reasoning becomes undecidable over the rational timeline, and decidable in EXPSPACE in data complexity over the integer timeline. We also show that, if we restrict our attention to forward-propagating programs, reasoning over the integer timeline becomes PSPACE-complete in data complexity, and hence, no harder than over positive programs; however, reasoning over the rational timeline in this fragment remains undecidable. Under consideration in Theory and Practice of Logic Programming (TPLP).


Introduction
DatalogMTL (Brandt et al. 2018) extends positive Datalog (Abiteboul et al. 1995) with operators from metric temporal logic (MTL) (Koymans 1990) interpreted over the rational or the integer timeline.For example, the following DatalogMTL rule can be used to state that a bus driver should not work for more than six months (i.e., half a year) in a row: where the expression ⊟ [0,0.5]Working(x) holds at time t if Working(x) holds continuously in the time interval [t − 0.5,t].Some other examples of expressions allowed in DatalogMTL are [t 1 ,t 2 ] ϕ, which holds at time t if ϕ holds at some instant within the time interval [t − t 2 ,t − t 1 ], and ⊞ [t 1 ,t 2 ] ϕ, which uses the "future-oriented" version of the operator ⊟ and holds at time t if ϕ holds continuously in the time interval [t + t 1 ,t + t 2 ].A DatalogMTL dataset consists of facts involving intervals, such as Working(alex)@ [2022,2023], stating that Alex was working continuously in the time interval [2022,2023].DatalogMTL is thus a very expressive language which allows a user to capture complex definitions, regulations, or events involving temporal intervals.DatalogMTL is powerful enough to capture prominent temporal extensions of Datalog such as Datalog 1S (Chomicki and Imieliński 1988;Chomicki and Imieliński 1989) and Templog (Abadi and Manna 1989), and it has found applications in areas such as ontologybased data access (Brandt et al. 2018), stream reasoning (Wałęga et al. 2019), and similar ideas were explored in logic programming (Brzoska 1998).Reasoning in DatalogMTL is known to be PSPACE-complete in data complexity over both the rational (Wałęga et al. 2019) and the integer timeline (Wałęga et al. 2020a).
Motivated by a range of applications, there has recently been a growing interest in logics that combine non-monotonic negation with temporal constructs (Cabalar and Vega 2007;Aguado et al. 2013;Cabalar et al. 2018;Cabalar et al. 2020;Beck et al. 2018;Zaniolo 2012).Recently, we have proposed an extension of DatalogMTL over the rationals with stratified negation-asfailure, where rules can have negated atoms in the body, but there can be no recursion involving predicates mentioned in such atoms.With such an extension of DatalogMTL, we can express, for example, a bus company's policy that any vehicle older than 12 years must be decommissioned permanently unless it has passed a special inspection in the last year: We also showed that the additional expressive power provided by this type of negation does not increase the complexity of reasoning regardless of whether we consider the rational or the integer timeline (Tena Cucala et al. 2021).The restriction to stratifiable programs, however, significantly limits the applicability DatalogMTL to certain types of use cases.
In this paper we take a further step in this direction and consider DatalogMTL equipped with non-stratifiable negation interpreted under the stable model semantics (Gelfond and Lifschitz 1988;Brooks et al. 2007;Nogueira et al. 2001).This extension paves the way for the use of DatalogMTL in applications where derived information can be retracted in light of new evidence, minimality of models is required, or temporal inertia rules need to be formalised.For instance, consider a bus company with the policy that vehicles that have been serviced at a given time t are automatically booked for a routine service in a year's time (i.e., at time t + 1, represented by metric operator ⊞ [1,1] ), but this appointment must be cancelled if the bus is serviced again before then-that is, within the interval (t + 0,t + 1), represented by (0,1) .This policy can be written using the rule which is not stratifiable as it involves recursion via negation.
Our setting is closely related to the recent research on combining answer set programming (ASP) with temporal logics.For example, TEL (Cabalar and Vega 2007;Aguado et al. 2013;Cabalar et al. 2018) combines ASP with linear temporal logic, and LARS combines ASP with window-based temporal constructs for stream reasoning (Beck et al. 2018).The logic recently proposed by Cabalar et al. (2020) is perhaps the closest to our work, as it combines stable model semantics with propositional MTL interpreted over the natural numbers; this logic, however, is rather different from DatalogMTL, where the use of logical connectives and MTL operators is restricted in the spirit of Datalog to disallow disjunction and 'existential' MTL operators (such as diamond, since, or until operators) in rule heads.As we show in our paper, considering a language with such restrictions can lead to favourable computational behaviour.
Our contributions in this paper are summarised as follows.In Section 3 we present our extension (DatalogMTL ¬ ) of DatalogMTL with negation under stable model semantics.Our lan-guage is defined similarly to other temporal ASP formalisms; it extends both DatalogMTL with stratified negation and Datalog with stable model negation.To capture the semantics of stable models, we use interpretations similar to those of the here-and-there intuitionistic logic (Heyting 1930;Pearce 1996).The main reasoning problem we consider is the existence of a stable model for a program and a dataset.We show in Section 4 that, in this setting, reasoning over the rational timeline is undecidable; furthermore, undecidability holds even for propositional forward-propagating programs (where rules cannot propagate information towards past time points) and to data containing only bounded intervals (i.e., where endpoints of all intervals are rational numbers).To regain decidability, in Section 5 we focus on the integer timeline.We show in Section 5.1 that discreteness of the timeline has a crucial influence on the computational behaviour, as reasoning becomes decidable and in EXPSPACE in data complexity; this is shown by exploiting Büchi automata and their complements to find candidate stable models and verify their minimality.Then, in Section 5.2 we show that, when restricted to forward-propagating (or, dually, to backwards-propagating) programs and bounded datasets, reasoning becomes PSPACEcomplete and hence no harder than for negation-free DatalogMTL (Wałęga et al. 2019;Wałęga et al. 2020a).This is in stark contrast with the undecidability of the same fragment over the rational numbers.

Preliminaries
In this section we recapitulate the basics of temporal intervals over the integers or the rationals, and introduce the syntax and semantics of metric temporal operators.

Timelines and Temporal Intervals
A timeline T is either the set Q of rationals or the set Z of integers.A T-time point is an element of T. A T-interval ρ is a subset of T satisfying both of the following properties: t ∈ ρ for all t 1 ,t 2 ∈ ρ and t ∈ T such that t 1 < t < t 2 ; and -the greatest lower bound ρ − and the least upper bound ρ + of ρ are both in T ∪ {−∞, ∞}.
The bounds ρ − and ρ + are called the left and right endpoints of ρ, respectively.A T-interval is punctual if it contains exactly one T-time point, it is non-negative if it contains no negative T-time points, it is bounded if both its endpoints are in T, and it is closed if it includes both of its endpoints.In these and similar notions, we often omit the reference to T if it is clear from the context.We consider binary representations of integers and fractional representations of rationals, with an integer numerator and a positive integer denominator, encoded in binary.We use standard representations of the form ρ − , ρ + for a non-empty interval ρ (i.e., ρ ∩ T = / 0), where the left bracket is either [ or (, the right bracket is either ] or ), and, if numeric, the endpoints ρ − and ρ + are represented as explained above.Brackets [ and ] indicate that the endpoints are included in the interval, whereas ( and ) indicate that they are not included; note that, by this convention, [ and ] cannot be used with endpoints −∞ and ∞.We often abbreviate a punctual interval [t,t] as t.If it is clear from the context, we abuse notation and identify each interval representation with the interval it represents.Assume a function-free first-order vocabulary and a timeline T. A relational atom is an expression of the form P(s), where P is a predicate and s is a tuple of constants and variables of the same arity as P. A metric atom is an expression given by the following grammar, where P(s) ranges over relational atoms and ρ over non-empty, non-negative intervals: A metric atom is ground if it mentions no variables.A metric fact is an expression M@ρ, with M a ground metric atom and ρ a non-empty T-interval; it is relational if so is M. A dataset is a finite set of relational facts; it is bounded if so are all intervals it mentions.For a dataset D, we denote with t min D and t max D the smallest and the largest numbers mentioned in D; if D mentions no numbers, we let t min D = t max D = 0.An interpretation I is a function which assigns to each time point t ∈ T a set of ground relational atoms; if an atom P(c) belongs to this set, we say that P(c) is satisfied at t in I and we write I,t |= T P(c).This notion extends to other ground metric atoms as given in Table 1.Interpretation I is a model of a metric fact M@ρ, written I |= T M@ρ, if I,t |= M for all t ∈ ρ; it is a model of a set M of metric facts (e.g., a dataset) if it is a model of all facts in M .Set M entails a set M ′ of metric facts, written M |= M ′ , if every model of M is a model of M ′ .An interpretation I contains an interpretation I ′ , written I ′ ⊆ I, if for each ground relational atom P(c) and each time point t ∈ T, having I ′ ,t |= T P(c) implies I,t |= T P(c).Furthermore, I is the least interpretation in a set X of interpretations, if I ⊆ I ′ for every I ′ ∈ X.

DatalogMTL with Negation Under Stable Model Semantics
In this section we propose DatalogMTL ¬ , which extends DatalogMTL with stratified negation as defined by Tena Cucala et al. (2021), to support unstratified use of negation in rules interpreted under stable model semantics.
The syntax of DatalogMTL ¬ is the natural extension of the positive case: rule bodies are conjunctions of atoms and negated atoms, whereas rule heads are defined as in DatalogMTL.Forward-propagating DatalogMTL ¬ programs are also defined analogously to the positive case (Wałęga et al. 2019), by requiring that rule bodies and heads do not mention metric operators referring to the future and to the past, respectively.

Definition 3.1
A rule r is an expression of the form where each M i is a metric atom, and M is a metric atom specified by the following grammar, where P(s) ranges over relational atoms and ρ over non-empty non-negative intervals: The head of r is the consequent M and the body is the conjunction in the antecedent, where The definition of stable models for Datalog with negation relies on the reduct construction by Gelfond and Lifschitz (1988), which has been adapted to various extensions of ASP (Faber et al. 2004).Such reduct constructions, however, do not have a natural equivalent in DatalogMTL ¬ , where interpretations may satisfy a fact at some, but not all points of the infinite timeline, and it is thus unclear which rules or atoms should be included in the reduct.
Following the approach of Cabalar and Vega (2007) and Cabalar et al. (2020), we define stable models for DatalogMTL ¬ analogously to the models of equilibrium logic (Pearce 1996), which in turn are defined in terms of interpretations for the here-and-there intuitionistic logic (Heyting 1930).In this logic, each interpretation is an ordered pair (H, T ) of sets H ("here") and T ("there") of relational propositional (i.e. using only predicates of arity 0) atoms such that H ⊆ T .We therefore start by generalising such interpretations to the context of DatalogMTL ¬ .For the remainder of this section, we fix a timeline T, which will be implicit in all our definitions and technical results.
Finally, (H, T) is an HT-model of a program if it is an HT-model of all its rules.
An HT-interpretation is, therefore, a pair (H, T) of standard interpretations.Interpretation H is contained in T and determines whether a dataset is satisfied.Although both interpretations are used to evaluate rules, it is T which evaluates negated body atoms and thus determines when a rule with negation can be 'triggered'.When this happens, the rule ensures that if any of H or T satisfies the positive body atoms, then it will also satisfy the head.Since H ⊆ T in an HTinterpretation, all relational facts entailed by H are also entailed by T. We show next that this property can be generalised to arbitrary metric facts.

Proposition 3.3
For every HT-interpretation (H, T), metric atom M, and time point t, if H,t |= M then T,t |= M.

Proof
We proceed by induction on the structure of M. If M is ⊤ or ⊥, the claim holds trivially, and if M is a relational atom, then the claim holds by H ⊆ T. For the inductive step it suffices to consider the cases when M is of the form ⊟ ρ M 1 or M 1 S ρ M 2 , for some interval ρ and metric atoms M 1 and Hence, by the inductive hypothesis, T,t ′ |= M 1 for all t ′ such that t − t ′ ∈ ρ, and so, T,t t).By the inductive hypothesis we obtain that T,t ′ |= M 2 and T,t ′′ |= M 1 , for all Although the converse statement does not always hold, we can nonetheless prove the following result, which will underpin our definition of stable models.

Proof
We use transfinite induction to construct a sequence of interpretations H 0 , H 1 , . . ., where each interpretation is contained in T. We will then show that H ω 1 , where ω 1 is the first uncountable ordinal, is the least amongst all interpretations H such that (H, T) is an HT-model of Π and D.
Let H 0 be the least model of D. Then, for each successor ordinal α, let H α be the least interpretation satisfying the following property: for each rule of Form (1) in ground(Π), and for each time point t, if H α−1 ,t |= M i for each 1 ≤ i ≤ k and T,t |= M j for each k + 1 ≤ j ≤ m, then H α ,t |= M.Moreover, for each limit ordinal α, we define H α as β <α H β .By induction on ordinals α we can show simultaneously that H α is well-defined and that H α ⊆ T. For the basis of the induction, we recall that H 0 is the least model of D, so H 0 is well-defined.Moreover, since (T, T) is an HT-model of D, we obtain that H 0 ⊆ T. Now, consider the inductive step for a successor ordinal α.To show that H α is well-defined it suffices to show that for each rule of Form (1) in ground(Π), and for each time point t, if which contradicts the assumption that (T, T) is an HT-model of Π.Moreover, since H α−1 ⊆ T and (T, T) is an HT-model of Π, we need to have T,t |= M, so H α ⊆ T. The inductive step for a limit ordinal α holds trivially, since H α is defined as β <α H β .
We thus obtain that H ω 1 ⊆ T, and so, (H ω 1 , T) is an HT-interpretation.By construction, H ω 1 contains H 0 and therefore (H ω 1 , T) is an HT-model of D. It is also an HT-model of Π, since ω 1 rounds of rule applications are enough to ensure that H ω 1 is a fixpoint with respect to the application of the rules of Π (Brandt et al. 2017).Finally, to show that H ω 1 is the least among interpretations H such that (H, T) is an HT-model of Π and D, consider any such H.Using transfinite induction in a way similar to the previous paragraph, one can show that H α ⊆ H for each ordinal α, and thus H ω 1 ⊆ H.
Given a program Π, a dataset D, and an interpretation T such that (T, T) is an HT-model of Π, we let H T Π,D denote the least interpretation whose existence is guaranteed by Theorem 3.4.In equilibrium logic, a model of a program is a set T of relational propositional atoms that satisfies the rules of the program and for which there exists no set H T such that (H, T ) is a model of the program in here-and-there logic.This ensures that equilibrium logic implements a kind of minimal model reasoning.We next generalise this notion to DatalogMTL ¬ by building on our previous definition of the least interpretation H Next, consider a dataset with facts P@0 and Q@1, together with a propositional DatalogMTL ¬ program that consists of two rules R ← P ∧ not 1 R and R ← Q ∧ not 1 R.This dataset and program have two stable models.In the first model, P and R hold at 0, whereas Q holds at 1.In the second model, P holds at 0, whereas Q and R hold at 1.
Finally, let us consider the empty dataset and a program consisting of rules Q ← notP and P ← not Q.Syntactically, this is not only a propositional DatalogMTL ¬ program, but also a standard answer set program (ASP).According to our temporal semantics, this program and dataset admit infinitely many stable models: for each set X of time points, there is a stable model in which P holds at each time point in X and Q holds at all other time points.In contrast, the same program under the standard ASP semantics has only two stable models, namely {P} and {Q}.
We next show that our semantics for DatalogMTL ¬ also generalises the semantics of (positive) DatalogMTL programs.If a DatalogMTL program Π and a dataset D have a model, they also admit a least model (Brandt et al. 2017).This can be equivalently reformulated by stating that if the set of all interpretations {I | (I, I) is an HT-model of Π and D} is not empty, then this set contains a unique least interpretation.(Cabalar and Demri 2011;Bozzelli and Pearce 2015), and the reason why this property holds in our setting is given by Theorem 3.4.
Finally, our semantics also generalises that of stratifiable DatalogMTL ¬ programs (Tena Cucala et al. 2021), where rules do not have cyclic dependencies via negation and can be organised in strata.Each such a stratifiable, ⊥-free program Π and dataset D have a single least model constructed by applying to D rules of Π stratum by stratum in a minimal way (Tena Cucala et al. 2021).As in the case of positive programs, we can show that such least model corresponds to the single stable model of Π and D. Hence, analogously to the case of plain Datalog, positive and stratifiable DatalogMTL programs cannot have multiple stable models.Arbitrary programs, however, can have any number of stable models, which is witnessed by Example 3.6.
In the rest of the paper we study decidability and complexity of reasoning, which is (in the context of this paper) the problem of checking if a DatalogMTL ¬ program Π and a dataset D have a stable model.We focus on data complexity-that is, we assume that Π is fixed and only D forms the input-which is the most relevant measure if complexity in data intensive applications.
Before we close this section, however, it is worth pointing out the connections between the problem of checking existence of a stable model and the related problem of fact entailment, as defined next.Following the standard conventions of non-monotonic logics and answer set programming (Eiter et al. 2009), we say that a DatalogMTL ¬ program Π and a dataset D bravely entail a relational fact P(c)@ρ if I |= T P(c)@ρ for some stable model I of Π and D. and we say that Π and D cautiously entail P(c)@ρ if I |= T P(c)@ρ for all stable models I of Π and D. The problem of brave (resp.cautious) fact entailment consists in deciding whether a DatalogMTL ¬ program and a dataset bravely (resp.cautiously) entail a given relational fact.As we show next, both variants of the problem are inter-reducible with checking existence (or non-existence) of a stable model.Moreover, we argue that these reductions allow us to transfer bounds for data complexity which, for fact entailment, refers to the setting where both the program Π and the fact P(c)@ρ are fixed, and only the dataset D constitutes the input.

Proposition 3.8
In DatalogMTL ¬ , existence of a stable model can be reduced in AC 0 to (i) brave fact entailment, and to (ii) the complement of cautious fact entailment, and vice versa.Furthermore, the reductions involved do not depend on the input dataset.

Proof
We start by showing Statement (i).To check if a DatalogMTL ¬ program Π and a dataset D have a stable model, it suffices to add to D a fact P@0 with a fresh proposition P and check whether Π and the extended dataset bravely entail P@0.To check if Π and D bravely entail a relation fact P(c)@ρ, it suffices to verify that the following program Π ′ and dataset D ′ have a stable model: where P ′ is a fresh predicate of the same arity as P, x is a tuple of distinct variables, t is an arbitrary time point belonging to ρ, whereas ρ 1 and ρ 2 depend on both ρ and t; for example, if ρ = [t 1 ,t 2 ), then ρ 1 = [0,t − t 1 ] and ρ 2 = [0,t 2 − t), where if t 2 = ∞, then t 2 − t stands for ∞.
Next, we show Statement (ii).To check if Π and D have a stable model, it suffices to check if they do not cautiously entail a fact P@0, where P is a fresh proposition (Brandt et al. 2018, Proposition 3).On the other hand, to check if Π and D do not cautiously entail a relational fact P(c)@ρ, it suffices to verify that the following program Π ′′ and dataset D ′′ have a stable model: where P ′ , x, t, ρ 1 , and ρ 2 are as in the proof of Statement (i).
Finally, we observe that all the above reductions can be performed in AC 0 .Moreover, they allow us to transfer data complexity bounds, since the programs and facts we construct in the reductions do not depend on input datasets.

Undecidability over the Rational Timeline
In this section we focus on the rational timeline, so let us fix T = Q.In this setting, standard reasoning problems are PSPACE-complete in data complexity for positive programs (Wałęga et al. 2019), as well as for programs with negation, if they are stratified (Tena Cucala et al. 2021).
We next show that, in stark contrast with the positive case, reasoning in DatalogMTL ¬ is undecidable.Furthermore, undecidability holds even for programs that are propositional, forwardpropagating and considered to be fixed, and even if the input datasets are bounded.
Theorem 4.1 Checking whether a propositional DatalogMTL ¬ FP and a bounded dataset have a stable model over the rational timeline is undecidable with respect to data complexity.

Proof
Let M = (Σ, Q, δ , q init , q halt ) be a deterministic Turing machine with Σ the input alphabet, Q the set of states, δ : R} the transition function for Σ ⊔ = Σ∪{⊔} and blank symbol ⊔, L and R the symbols indicating the head movements, and q init , q halt ∈ Q the initial and halting states.Without loss of generality, we assume that M never tries to move to the left of the left-most cell of the tape.
We construct a propositional DatalogMTL ¬ FP program Π M and then reduce (in AC 0 ) every input word w to a dataset D w with only bounded intervals so that M halts on w if and only if Π M and D w do not have a stable model.We represent, for each i ≥ 1, the ith configuration in the computation of M on input w within the interval [2i, 2i + 2), as illustrated in Figure 1, where we assume that in the configuration the state is q, the head is over the jth cell, and the contents of the first |w| + i cells of the tape are symbols s 1 , . . ., s |w|+i (in the ith configuration, only the first |w| + i cells can be non-empty).The state is encoded within the first half [2i, 2i + 1] of the interval: a proposition S q holds at some time point within [2i, 2i + 1].The contents of the tape and the head position are encoded within the second half (2i + 1, 2i + 2) of the interval; in particular, |w| + i time points 2) are used so that, for each j ∈ {1, . . ., |w| + i}, proposition C s j holds at t i j , encoding the fact that s j are the contents of the jth cell in the configuration, and proposition H holds at t i j , encoding the fact that the head is over the jth cell in the configuration.We also use additional propositions: S, which holds all through [2i, 2i + 1] and ensures that these intervals are only used to encode states; N, which holds at a single new time point in (2i + 1, 2i + 2) beyond t i |w|+i and will allow us to increase the number of time points encoding cells; N and H, which simulate negations of N and H, respectively; C, which marks points not used to encode the tape contents, and L, used for encoding left-moving transitions.
The first block of rules in Π M consists of the following rules, for each X ∈ {N, H} and s ∈ Σ ⊔ : The first three rules state that, at each time point, either X or X holds.The fourth rule states that X cannot hold twice in an open interval of length 1.By the fifth rule, X and S cannot hold at the same time point.The sixth rule states that N holds in all time points encoding cells.The second to last rule states that H does not hold in time points that do not encode cells.The last rule ensures that after time point t i |w|+i encoding the last relevant cell in the ith configuration, there is another time point within (2i + 1, 2i + 2) where N holds.Note that the last rule uses conjunction within a metric operator, which is not syntactically allowed, but can be easily simulated by replacing C ∧ N with a fresh proposition P and adding a rule P ← C ∧ N; this abbreviation will be useful for simplifying other formulas used later on in the reduction.
The second block consists of the following rules, propagating propositions to the interval encoding the consequent configuration, for every s ∈ Σ ⊔ : By the first rule, S is always propagated into the future from t to t + 2. The second rule states that, if t does not encode a cell and N holds therein, then t + 2 does not encode a cell either.By the third rule, if N holds at t and this t is to the right of the time point encoding the initial state, then t + 2 encodes an empty cell.The last rule states that, if t encodes a cell with contents s and the head is not on this cell, then t + 2 also encodes a cell with contents s.
We next encode the left-moving transitions.Proposition L is used to indicate a time point encoding a cell such that the head was on it in the previous configuration and then moved to the left.Program Π M contains the following rules for every s ∈ Σ and q ∈ Q with transition δ (s, q) = (s ′ , q ′ , L), and every s * ∈ Σ: The first rule simulates the transition: H holds as intended, the state is changed from q to q ′ , and the contents of the cell under the head change from s to s ′ (the conjunction in the head is used for brevity and can be simulated by several rules).The last two rules encode the position of the head in the consequent configuration, by stating that H holds at the first time point encoding a cell to the left of the time point with L.
Similarly, for each transition δ (s, q) = (s ′ , q ′ , R) moving the head to the right and any s * ∈ Σ, program Π M has the rules Here, the first rule encodes the change of the state and the contents of the cell above which the head is.The last two rules simulate the change of the position of the head.Finally, Π M contains rule ⊥ ← S q halt , which yields an inconsistency when the halting state is reached.
We next reduce an input word w = s 1 . . .s |w| to a dataset D w .Assuming that w is non-empty, we let Intuitively, D w describes the initial configuration of M on w within [0, 2); the initial state is encoded in 1 and t 1 , . . .,t |w| encode the first |w| cells of M.Moreover, C holds in all other time points in (1, 2), whereas N and H hold in [0, 1].We next show that Π M and D w have a stable model if and only if M does not halt on w.Assume that T is a stable model of Π M and D w .Then, using induction over i ∈ N, we can prove that the ith configuration in the computation of M on w is encoded as discussed above.In particular, if q is the state of M in the ith configuration, then T,t |= S q for some t ∈ [2i, 2i + 1].Since T is a model of Π M , however, it satisfies the rule ⊥ ← S q halt ; therefore, the state q halt cannot occur in any configuration in the computation of M on w, and so M does not halt on w.
For the opposite direction assume that M does not halt on w.Then, we let T be the minimal interpretation which satisfies D w and the following statements, for every positive integer i, where we let 1 2 k for each j ∈ N (this definition ensures that there are infinitely many time points of the form t i j in interval , for j such that the head of M is above the jth cell in the ith step of its computation on w, -T,t i+1 j |= L if the head of M is above the jth cell in the ith step of its computation on w, -T,t i j + 1 |= S q if T,t i j |= H and M is in the state q in the i + 1th step of computation on w.Clearly, (T, T) is an HT-model of D w , and it can be also verified, by inspecting the rules in Π M , that (T, T) is an HT-model of Π M .Finally, to show that (T, T) is a stable model of Π M and D w , we need to show that T = H T Π M ,D w .Towards this goal, we first construct the sequence H 0 , H 1 of interpretations as in the proof of Theorem 3.4, for which it holds that H ω 1 = H T Π M ,D w .Then we can easily show, using transfinite induction, that for each i ∈ N and each relational fact M@t with t ∈ [2i, 2i + 2), T |= M@t if and only if H i |= M@t, and also that H i |= M@t if and only if H T Π M ,D w |= M@t, which together imply T = H T Π M ,D w .Observe that the reduction above shows undecidability of reasoning in DatalogMTL ¬ over the rational timeline, even if we restrict our attention to fixed propositional programs in the forwardpropagating fragment, and we consider only bounded datasets.In the next section, we turn our attention to the integer timeline and show that reasoning becomes decidable.

Decidability over the Integer Timeline
In this section we consider the integer timeline and thus we fix T = Z.We will show that, in this case, reasoning becomes decidable in EXPSPACE with respect to data complexity; furthermore, complexity drops to PSPACE if we restrict our attention to forward-propagating programs and datasets mentioning only bounded intervals-a setting well-suited for stream reasoning (Wałęga et al. 2019;Ronca et al. 2018).In this setting, the additional expressive power provided by stable models comes at no computational cost since reasoning in the corresponding positive fragment is already PSPACE-complete (Wałęga et al. 2020a;Wałęga et al. 2019).
In prior work on positive and stratifiable programs, upper bounds for reasoning have been established by constructing generalised Büchi automata that accept (words describing) models of a given program and dataset (Wałęga et al. 2020a;Tena Cucala et al. 2021).Checking existence of a stable model is more demanding, as we additionally need to ensure model minimality as in Definition 3.5; this requirement is non-trivial, and we will handle it differently for the cases of arbitrary and forward-propagating programs.
In the general case (Section 5.1), we construct two kinds of left-and right-moving automata: the first kind allows us to check existence of an HT-model of the form (T, T), while the second kind allows us to check existence of an HT-model of the form (H, T) with H = T.Then, a pair of words ← − w and − → w that are accepted, respectively, by a pair of left-and right-moving automata of the first kind, but not by any pair of left and right-moving automata of the second kind, represents a stable model.This construction is conceptually similar to that of Cabalar and Demri (2011) for a logic with linear temporal operators and involves complementing nondeterministic automata, which leads to an exponential blowup.Consequently, we obtain an EXPSPACE upper bound and thus an exponential gap in data complexity with respect to positive programs (Wałęga et al. 2020a).In the case of forward-propagating programs (Section 5.2) we propose a different construction exploiting the fact that rules propagate information in a single temporal direction.This allows us to build automata that guarantee model minimality without complementation.As a result, we can establish a tight PSPACE bound in data complexity.

General Programs
It will be convenient for our presentation to assume that programs are in a normal form analogous to that by Tena Cucala et al. ( 2021) for stratifiable programs: in each normalised rule the head is a relational atom or ⊥, there is neither nesting of metric operators nor occurrences of or in rule bodies, and the only unbounded interval allowed is [0, ∞).

Proof
To construct Π ′ we first delete all (trivial) rules having ⊤ as the head.Then, we eliminate from the remaining rule heads metric operators (i.e., boxes).To this end, we replace each rule of the form 1 ρ 1 . . .n ρ n P(s) ← B, where n ≥ 0, each i is either ⊟ or ⊞, and B is the body of the rule, with rules P ′ (s) ← B and P(s , where i = if i = ⊟ and otherwise i = , and P ′ is a fresh predicate of the same arity as P. Second, we iteratively eliminate nested temporal operators from rule bodies.To this end, consider a rule r whose body has an occurrence M of a metric atom that mentions only one temporal operator and which is in the scope of some other temporal operator.If M is of one of the forms ρ P(s), ρ P(s), ⊟ ρ P(s), or ⊞ ρ P(s), then we replace it with P ′ (s) and add a rule P ′ (s) ← M, where P ′ is a fresh predicate of the same arity as P. If M mentions S or U , we need to proceed in a special way to ensure safety of the new rules.If M is of the form P 1 (s 1 )S ρ P 2 (s 2 ), we remove r and proceed as follows (note that the conditions below are not exclusive): -if 0 ∈ ρ, we add the rule obtained by replacing M in r with P 2 (s 2 ), -if 1 ∈ ρ, we add the rule obtained by replacing M in r with ⊟ 1 P 2 (s 2 ), -we add the rule P ′ (s 1 , s 2 ) ← P 1 (s 1 )S ρ P 2 (s 2 ) ∧ [0,∞) P 1 (s 1 ) and the rule obtained by replacing M in r with P ′ (s 1 , s 2 ), where P ′ is a fresh predicate whose arity equals the sum of arities of P 1 and P 2 .
If M is of the form P 1 (s 1 )U ρ P 2 (s 2 ), we proceed analogously to the case when M is of the form P 1 (s 1 )S ρ P 2 (s 2 ), but instead of ⊟ and we use, respectively, ⊞ and in the new rules.Moreover, if M mentions ⊤ or ⊥, we treat these symbols as nullary predicates and proceed as before.
Next, we eliminate diamond operators by replacing ρ M and ρ M with, respectively, ⊤S ρ M and ⊤U ρ M. Finally, we eliminate unbounded intervals ρ different from [0, ∞) as follows.If a rule r mentions ρ P(s), we replace this ρ P(s) with t P(s) and add a rule P ′ (s) ← [0,∞) P(s), where is either ⊟ or ⊞, t is the least natural number in ρ (so t ≥ 1), and P ′ is a fresh predicate of the same arity as P. In the case of operators S and U we need to pay special attention to ensure that the new rules are safe.Assume that a rule r mentions M = P 1 (s 1 )S ρ P 2 (s 2 ) with an unbounded ρ = [0, ∞).We remove r and proceed as follows, for t the least natural number belonging to ρ: -if 1 ∈ ρ, we add the rule obtained by replacing M in r with ⊟ 1 P 2 (s 2 ), -if 1 ∈ ρ, we add the rule obtained by replacing M in r with ⊟ t P 2 (s 2 ) ∧ ⊟ (0,t) P 1 (s 1 ) -we add the rule P ′ (s 1 , s 2 ) ← P 1 (s 1 )S [0,∞) P 2 (s 2 ) ∧ P 1 (s 1 ), and the rule obtained by replacing M in r with ⊟ t P ′ (s 1 , s 2 ) ∧ ⊟ (0,t] P 1 (s 1 ), where P ′ is a fresh predicate whose arity equals the sum of arities of P 1 and P 2 .
In the case of atoms mentioning U , as well as ⊤ or ⊥, we proceed analogously.
In the remainder of this section, we fix a normalised program Π and a dataset D, and let ground(Π, D) be the subset of ground(Π) mentioning only constants from Π and D.Then, at(Π, D) is the set consisting of all relational atoms in D, all metric atoms in ground(Π, D), and all metric atoms of the forms ⊟ [0,∞) M and ⊞ [0,∞) M, with M a relational atom mentioned in ground(Π, D).
We next define the notion of a window-a fragment of an HT-interpretation over a particular interval; such windows will serve as states of our automata.

Definition 5.2
A window is a tuple (ρ, H, T, b), where ρ is a closed (and hence bounded) interval, b ∈ {0, 1}, and H and T are sets of metric facts of the form M@t satisfying the following conditions: -M ∈ at(Π, D), t ∈ ρ, and H ⊆ T ; -there exist interpretations H and T such that, for each M ∈ at(Π, D) and t ∈ ρ, -M@t ∈ H if and only if H |= M@t, and -M@t ∈ T if and only if T |= M@t.The window's length is the length of ρ.Finally, we say that a window is initial if either H = T and b = 0, or H = T and b = 1.
Intuitively, a window (ρ, H, T, b) is a fragment of an HT-interpretation (H, T) restricted to ρ, where H and T describe facts holding within ρ in H and T, respectively.Windows will serve as states of the automata recognising word representations of specific HT-interpretations, and in this process the flag b is used to distinguish between stable and non-stable models; in particular, our automata will ensure that flag b is set to 1 in each state W of a run such that H = T in either W or in some previous state of this run.
By definition, a window can be extended to an HT-interpretation.This HT-interpretation can be an HT-model of Π only if the window locally satisfies Π, which we define next.
Next, given an initial window W 0 , we define automata A ← W 0 and A → W 0 , which will allow us to recognise HT-models of Π that extend W 0 .In particular, if A ← W 0 and A → W 0 accept words ← − w and − → w respectively, then we will be able to construct an HT-model extending W 0 , for which the part located to the left of W 0 is described by ← − w , and the part to the right of W 0 by − → w .

Definition 5.4
Let W 0 = (ρ 0 , H 0 , T 0 , b 0 ) be an initial window locally satisfying Π.Then, A ← W 0 = (Q, Σ, δ , q 0 , F) is the generalised nondeterministic Büchi automaton with the following components: 1. the states Q consist of all windows of the the same length as W 0 locally satisfying Π; 2. the alphabet Σ is the set of all σ ⊆ at(Π, D); 3. the transition function δ 4. the initial state q 0 is W 0 ; 5. the accepting condition F is the family of sets of states which contains, for every atom and, for each The automaton A → W 0 is defined analogously, except that we let ρ ′ = [ρ − + 1, ρ + + 1], in the defi- nition of T ′ we replace ρ − −1 with ρ + +1, and in the definition of F we use ⊞ and U instead of ⊟ and S , respectively.
Accepting runs of these automata will correspond to HT-interpretations.Indeed, as we will show next, each HT-interpretation can be decomposed into an infinite sequence of windows . . ., W −1 , W 0 , W 1 , . . .such that W 0 , W −1 , . . .and W 0 , W 1 , . . .are accepting runs of A ← W 0 and A → W 0 , respectively.We define the decomposition of an HT-interpretation as follows.

Definition 5.5
We define the ρ-decomposition of an HT-interpretation (H, T), for a bounded interval ρ, as the sequence of tuples W i = (ρ i , H i , T i , b i ), for i ∈ Z, such that the following hold: -H i is the set of all facts M@t such that M ∈ at(Π, D), t ∈ ρ i , and H |= M@t, -T i is the set of all facts M@t such that M ∈ at(Π, D), t ∈ ρ i , and T |= M@t, b i = 1 if there exists j ∈ {0, . . ., i} such that H j = T j ; otherwise, b i = 0.

Lemma 5.6
Let ρ be a bounded interval, let a sequence of tuples

Proof
To show that Statement 1 holds, we start by observing that each W i satisfies all the conditions from Definition 5.2 of a window.Indeed, by Definition 5.5, H i and T i are sets of metric facts M@t with M ∈ at(Π, D) and t ∈ ρ i such that H i ⊆ T i , whereas b i ∈ {0, 1}; moreover, H and T witness existence of the interpretations required in Definition 5.5.Furthermore, since (H, T) is an HT-model of Π, each W i locally satisfies Π.
To prove that Statement 2, we observe that W 0 is an initial window by construction, so the automaton A ← W 0 = (Q, Σ, δ , q 0 , F) is well-defined.By the definition of the transition function δ of A ← W 0 (see Definition 5.4) as well as by the construction of W 0 , W −1 , . . .and ← − w = σ −1 σ −2 . . ., we get that W i−1 ∈ δ (W i , σ i−1 ), for each integer i ≤ 0. Thus, W 0 , W −1 , . . . is a run of A ← W 0 on ← − w .It remains to show that this run is accepting, that is, for every set S in the accepting condition F, there are infinitely many integers i < 0 such that W i ∈ S. Towards a contradiction suppose that there exists S ∈ F which does not satisfy this property.Thus, there exists i ≤ 0 such that W j / ∈ S, for all j ≤ i. Assume first that S is of one of the following forms where the interpretation I is either H or T, depending whether S is of the first or the second form presented above.This, however, contradicts the semantics of ⊟ [0,∞) .It remains to consider the case where S is of one of the following forms M 2 @t and I |= M 2 @t, for each t ≤ ρ − i , where I is either H or T, depending whether S is of the first or the second form presented above.This directly contradicts the semantics of S [0,∞) .Consequently, W 0 , W −1 , . . .needs to be an accepting run of A ← W 0 on ← − w .The proof of Statement 3 is analogous to the proof of Statement 2, due to the symmetry between the automata A ← W 0 and A → W 0 .To check existence of a stable model, however, we require automata that recognise HT-models (H, T) with H = T, and automata that recognise HT-models (H, T) with H T. The intersection of the former with the complement of the latter allows us to recognise stable models-that is, essentially, HT-models (T, T) for which there are no models (H, T) with H T. To this end, we define two more types of automata as follows: Definition 5.7 Let W 0 = (ρ 0 , H 0 , T 0 , b 0 ) be an initial window locally satisfying Π.We define non-deterministic generalised Büchi automata B ← W 0 , B → W 0 and C ← W 0 , C → W 0 as follows: -if H 0 = T 0 and b 0 = 0, the automata B ← W 0 and B → W 0 are defined as A ← W 0 and A → W 0 , respectively, except that for a window (ρ, H, T, b) to be a state we additionally require that H = T , -the automata C ← W 0 and C → W 0 are defined as A ← W 0 and A → W 0 , respectively, except that we add to the accepting condition the set Intuitively, if W 0 satisfies D, then the automata B ← W 0 and B → W 0 recognise interpretations T such that (T, T) is an HT-model of Π and D. Furthermore, interpretations T accepted by A ← W 0 and C → W 0 , or by C ← W 0 and A → W 0 are such that (H, T) is an HT-model of Π and D, for some H T. Hence, as we show next, we can use these automata to recognise stable models.This, however, requires the additional assumption that the windows in the automata are long enough to allow for capturing the semantics of metric operators occurring in a program.To this end, we will use windows of the same length as the interval ρ If the length of an initial window W 0 is as required, then we can reduce checking existence of a stable model to checking particular properties of our automata, as stated next.
Theorem 5.8 Program Π and dataset D have a stable model if and only if there exists an initial window W 0 = (ρ 0 , T 0 , T 0 , 0) locally satisfying Π with ρ 0 = ρ (Π,D ) and T 0 |= D, and there exist words ← − w and − → w over 2 at(Π,D ) such that both of the following hold:

Proof
Assume that T is a stable model of Π and D. We will show how to construct the required W 0 , ← − w , and − → w .To this end, let . . ., W −1 , W 0 , W 1 , . . .be the ρ (Π,D ) -decomposition of (T, T) with for each i ∈ Z.By Definition 5.5, we obtain that H i = T i and b i = 0, for all i ∈ Z; furthermore, W 0 locally satisfies Π by Lemma 5.6.Finally, we have ρ 0 = ρ (Π,D ) , which en- sures T 0 |= D, so W 0 satisfies the initial requirements from the theorem.Next, let ← − w , and − → w satisfy Conditions 1 and 2 from the theorem.To show that Condition 1 holds, we observe that, by Lemma 5.6, W 0 , W −1 , . . . is an accepting run of A ← W 0 on ← − w , and W 0 , W 1 , . . . is an accepting run of A → W 0 on − → w .Moreover, since H i = T i and b i = 0 for all i ∈ Z, we obtain that W 0 , W −1 , . . . is an accepting run of B ← W 0 on ← − w , and W 0 , W 1 , . . . is an accepting run of B → W 0 on − → w .Next, let us suppose towards a contradiction that there exists , for all i ∈ Z.Clearly, ρ ′ i = ρ i , for all i ∈ Z.Moreover, by the definition of the transition functions of the automata and the construction of ← − w and − → w , we obtain that T ′ i = T i , for all i ∈ Z.Therefore, T is the least model of all relational facts in i∈Z T ′ i .We let H be the least model of all relational facts in i∈Z H i ; we will show that (H, T) is an HT-model of Π and D.
Since H ′ i ⊆ T ′ i , for all i ∈ Z, we obtain that H ⊆ T, and so (H, T) is an HT-interpretation.Moreover, (H, T) is an HT-model of D, as H ′ 0 |= D. Next we will show that (H, T) is an HT-model of Π.Since each W ′ i is a window of length [t min D ,t max D + t Π ] (which is the length of ρ (Π,D ) ), it holds that H |= M@t if and only if M@t ∈ H ′ i ; as well as T |= M@t if and only if M@t ∈ T ′ i , for any M ∈ at(Π, D) and t ∈ ρ ′ i .Indeed, we have shown an analogous statement for positive (Wałęga et al. 2019, Lemma 9) and stratifiable programs (Tena Cucala et al. 2021), and the same argument applies here.Now, to show that (H, T) is a model of Π, we fix a ground rule from ground(Π, D) of Form (1) and a time point t.If H,t |= M i for all i ∈ {1, . . ., k} and T,t |= M j for all j ∈ {k + 1, . .., m}, then M i @t ∈ H ′ n for all i ∈ {1, . . ., k} and M j @t / ∈ T n for all j ∈ {k + 1, . . ., m}, for each n such that t ∈ ρ ′ n .Since W ′ n is a window locally satisfying Π, we obtain that M@t ∈ H n (where M is the head of r), which implies H,t |= M by definition of H and the fact that Π is in normal form so M is a relational atom.Similarly, if T,t |= M i for all i ∈ {1, . . ., k} and T,t |= M j for all j ∈ {k + 1, . .., m}, then we obtain that T,t |= M. Hence, (H, T) is indeed an HT-model of Π.
However, the accepting condition of C ← W ′ 0 guarantees that b ′ i = 1, for some i ≤ 0, and so Therefore, H T, and so T is not a stable model, which rises a contradiction.If ← − w and − → w are accepted by A ← W ′ 0 and C → W ′ 0 , respectively, then we construct in an analogous way a run Repeating the argumentation above, we construct an HT-model (H, T) of Π and D, and then, we show that there exists i ≥ 0 such that b ′ i = 1.
Thus, H ′ i T ′ i , so H T, and consequently, T is not a stable model, raising again a contradiction.Thus, Condition 2 holds.
For the converse implication, assume that there exist W 0 , ← − w , and − → w as described in the statement of the theorem.By Condition 1, there is an accepting run W 0 , W −1 , . . . of B ← W 0 on ← − w , and an accepting run W 0 , W 1 , . . . of B → W 0 on − → w , where W i = (ρ i , T i , T i , 0).We argue that the least model T of relational facts in i∈Z T i is a stable model of Π and D. By an argument analogous to the second to last paragraph above, (T, T) is an HT-model of Π and D. Suppose for contradiction that T is not stable, so there exists H T such that (H, T) is an HT-model of Π and D. Let . . ., , and observe that W ′ 0 is an initial window.By Lemma 5.6, accepts − → w .Thus, Condition 2 does not hold, leading to a contradiction.Theorem 5.8 reduces checking existence of a stable model to checking specific properties of our automata.We aim at showing that the latter is feasible in EXPSPACE.The main obstacle, however, is the size of states in the automata: W 0 is exponential in size with respect to D, and states of the automata from Theorem 5.8 can be arbitrarily large since time points in windows can be arbitrary integers.To remedy the first issue, we let t Π be the largest positive number mentioned in Π, and we let t Π = 1 if Π mentions no positive numbers-this choice of value is arbitrary since in this case we only need t Π to be a positive number in the timeline.Then, we show in Lemma 5.10 that it suffices to consider automata with states (i.e., windows) of length t Π , which does not depend on D. The second issue is addressed by Lemma 5.13 which tells us that, rather than considering automata with states of unbounded size (each of length t Π ), we can construct equivalent automata with polynomial-size states instead.
To state Lemma 5.10, we define the left-most and right-most fragments of length t Π of a window as follows.
Definition 5.9 For a window W = (ρ, H, T, b) of length at least t Π , we define We observe that if W is a window locally satisfying Π, then W L and W R (which are "fragments" of W ) also are windows locally satisfying Π.Furthermore, both W L and W R are initial windows by definition.Thus, if W 0 is such that X ← W 0 and X → W 0 are well-defined automata, for some X ∈ {A , B, C }, then X ← W L 0 and X → W R 0 are also well-defined automata.Moreover, we can show several equivalences between these automata.Lemma 5.10 Let X ∈ {A , B, C } and let W 0 = (ρ 0 , H 0 , T 0 , b 0 ) be a window such that X ← W 0 and X → W 0 are welldefined.Then, the following statements hold: Proof First, we show Statement 1 for X = A .Assume that W 0 , W −1 , . . . is an accepting run of A ← W 0 on a word w = σ −1 , σ −2 , . . . .We will show that there is an accepting run on the same word.To define this run, for each integer i ≤ 0, we let W L i = (ρ i , H i , T i , b i ), and we define , where b ′ i = 1 if there exists j ∈ {0, . .., i} such that H i = T i , and otherwise b ′ i = 0.In particular, W ′ 0 = W L 0 .Now, we will show that W ′ 0 , W ′ −1 , . . . is an accepting run of A ← W L 0 on w.We start by observing that since each W i is a window locally satisfying Π and since To show that they constitute a run of A ← W L 0 on w, we observe that the transition functions are the same modulo definition of states.This observation and our . .; we will show that A ← W 0 has an accepting run on w.To facilitate the definition of this run, we divide where k is the difference between the lengths of W 0 and W L 0 .In particular, for each i ∈ {0, . . ., k}, we define W 0 is well-defined, W 0 is an initial window locally satisfying Π, and as we already mentioned, by fragmenting windows locally satisfying Π we obtain windows which also locally satisfy Π. Hence all of W ′ 0 , . . ., W ′ k locally satisfy Π.Furthermore, observe that W ′ 0 = W L 0 .Next, we show how to merge the windows W ′ k , . . ., W ′ 0 , W ′ −1 , . . . to obtain an accepting run of A ← W 0 on w.To this end, for arbitrary windows W = (ρ, H, T, b) and 0, we define their union, written as W ∪ W ′ , as the tuple (ρ ∪ ρ ′ , H ∪ H ′ , T ∪ T ′ , max(b, b ′ )).We can then establish the following claim: ) be windows such that the left and right endpoints of ρ ′ succeed those of ρ, and for each t ∈ ρ ∩ ρ ′ and each X ∈ {H, T }, M@t ∈ X if and only if M@t ∈ X ′ .If both W and W ′ are of length at least t Π and locally satisfy Π, then W ∪ W ′ is a window locally satisfying Π.

Proof of Claim 5.11
If W and W ′ locally satisfy Π, then clearly W ′′ also locally satisfies Π.It remains to show that W ′′ is a window.To this end, for I an interpretation, ρ b a closed interval, and J a set of metric facts M@t with M ∈ at(Π, D) and t ∈ ρ b , we say that I corresponds to J over ρ b if, for every t ∈ ρ b and M ∈ at(Π, D), it holds that I |= M@t if and only if M@t ∈ J.To show that W ′′ is a window, the only non-trivial condition that needs to be verified is that there exist two interpretations that correspond, respectively, to H ′′ and T ′′ over ρ ′′ .We show this for H ′′ only, as the argument for T ′′ is analogous.Let H (resp. H ′ ) be an interpretation corresponding to H over ρ (resp.H ′ over ρ ′ ); such an interpretation exists, since W (resp. W ′ ) is a window.Let H ′′ be an arbitrary interpretation that coincides with H over ρ and all time points to its left, and with H ′ over ρ ′ and all time points to its right.Note that H and H ′ agree over ρ ∩ ρ ′ since, by assumption, M@t ∈ H if and only if M@t ∈ H ′ for all t ∈ ρ ∩ ρ ′ ; thus, H ′′ is well-defined.It remains to show that H ′′ corresponds to H ′′ over ρ ′′ -that is, for each M@t with M ∈ at(Π, D) and t ∈ ρ ′′ , we must show that H ′′ |= M@t if and only if M@t ∈ H ′′ .We show this explicitly for the case where M is of the form ⊟ ρ b P, for ρ b a bounded interval and P a relational atom; the remaining cases can be proved in a similar way; see (Wałęga et al. 2019), Lemma 7. Suppose that t ∈ ρ.Since H ′′ and H coincide over ρ and all time points to its left, we have that H ′′ |= ⊟ ρ b P@t if and only if H |= ⊟ ρ b P@t.Then, since H corresponds to H over ρ, it holds that H |= ⊟ ρ b P@t if and only if ⊟ ρ b P@t ∈ H. Finally, since H and H ′′ coincide over ρ, ⊟ ρ b P@t ∈ H if and only if ⊟ ρ b P@t ∈ H ′′ .Thus, by chaining together these double implications, we have that H ′′ |= ⊟ ρ b P@t if and only if ⊟ ρ b P@t ∈ H ′′ , which is the target equivalence.Suppose now that t / ∈ ρ, so t is the right endpoint of ρ ′ .By the semantics of metric atoms, H ′′ |= ⊟ ρ b P@t if and only if H ′′ |= P@t − t ′ for each t ′ ∈ ρ b .Since the length of ρ ′ is at least t Π , we have t − t ′ ∈ ρ ′ for each t ′ ∈ ρ b .Hence, since H ′′ and H ′ coincide over ρ ′ , H ′′ |= ⊟ ρ b P if and only if H ′ |= ⊟ ρ b P, and the rest follows by an argument analogous to the previous case, finishing the proof of Claim 5.11.
We resume the proof of Lemma 5.10.Now, we construct an accepting run of A ← W 0 on w as follows.For each integer i < 0, we let i+k with the exception that b i = 1 if there exists j ∈ {i, . . ., k} such that H ′ i = T ′ i and b i = 0 otherwise.Now, we will show that W 0 , W −1 , . . . is indeed an accepting run of A ← W 0 on w.To this end, we observe that each W i is a window locally satisfying Π, since so is i+k by Claim 5.11; furthermore, each W i it is of the same length as W 0 .Therefore, each W i is a state of the automaton A ← W 0 .Moreover, the definition of W i ensures that if there exists a transition on σ i−1 from W ′ i to then the bigger window W i belongs to the set corresponding to S in the accepting condition of A ← W 0 .Hence, A ← W 0 accepts the run W 0 , W −1 , . . . .The case of A → W 0 is symmetric, so we obtain that if A → W R 0 accepts a word w, then so does A → W 0 .To finish the proof of Statement 1, it remains to consider the case X = B. Recall that the only difference between the automata of the types A and B is that the latter impose additional requirement on the windows to be states (see Definition 5.7), namely for a window W = (ρ, H, T, b) to be a state, it is required that H = T .This, however, does not affect our argumentation above, and so, we obtain that B ← W 0 and B → W 0 accept the same words as To show that Statements 2 and 3 hold, we recall that the automata C differ from automata A only in the existence of an additional set , respectively, using the same argumentation as in the proof of Statement 1, except for the following difference.We use the fact that H 0 = T 0 to ensure that in an arbitrary accepting run of C ← W 0 for some word, there exists a window W i = (ρ i , H i , T i , b i ) to the left of W 0 with H i = T i , which in turn allows us to ensure that the corresponding run that we define for and hence the run is accepting.An analogous argument applies to C → W 0 .Thus, Statement 2 holds.
However, if Lemma 5.10 allows us to restrict our attention to automata with windows of polynomial length, but representations of such windows can still be unbounded, because arbitrarily large integers may occur in them.However, we will show in Lemma 5.13 that we can construct equivalent automata with states that can be represented in polynomial space, by merging "similar" states in the original automata.We use a notion of similarity given by the relation ∼ defined next: Definition 5.12 Let ∼ be the equivalence relation on windows such that W ∼ W ′ if and only if W ′ is obtained by increasing all time points mentioned in W by some integer c.Let [W ] ∼ be the equivalence class of W with respect to ∼.Then, for any X ∈ {A , B, C } and any initial window Lemma 5.13 Let X ∈ {A , B, C } and let W 0 = (ρ 0 , H 0 , T 0 , b 0 ) be an initial window locally satisfying Π such that X ← W 0 and X → W 0 are well-defined.Then, on a word w.Then, by Definition 5.12, Moreover, by the definition of the transition function and the accepting conditions of X ← For the opposite direction, let us assume that q 0 , q −1 , . . . is an accepting run of X ← word w.For each integer i < 0, we let To this end, we will show that for every integer i ≤ 0 and every symbol σ , if where δ and δ are the transition functions of X ← This, by the definition of ∼ and the fact that , by the definition of accepting conditions, we obtain that W 0 , W −1 , . . .
0 also does so.
We are now ready to show EXPSPACE data complexity of reasoning in DatalogMTL ¬ over Z.
Theorem 5.14 Checking whether a DatalogMTL ¬ program and a dataset have a stable model over the integer timeline is in EXPSPACE with respect to data complexity.

Proof
It suffices to show that checking existence of W 0 , ← − w , and − → w from Theorem 5.8 is feasible in EXPSPACE in the size of (the representation of) D. First, we observe that the length of ρ (Π,D ) is exponential, and so is the representation of windows over ρ 0 = ρ (Π,D ) .Thus, it is feasible in EXPSPACE to guess a tuple W 0 = (ρ 0 , T 0 , T 0 , 0) as well as to verify that it is an initial window locally satisfying Π and such that T 0 |= D, as required in Theorem 5.8.
Thus, it remains to check existence of ← − w and − → w satisfying Conditions 1 and 2 from Theorem 5.8.To this end, we will treat a candidate pair of words and combine pairs of corresponding automata so that they accept combined words.In particular, for automata X and Y , we let XY be an automaton which on a word w 1 w 2 simulates the run of X on w 1 and the run of Y on w 2 , simultaneously.Such an automaton XY is polynomially bigger than X and Y as its states are pairs consisting of a state of X and a state of Y .Thus, checking existence of ← − w and − → w from Theorem 5.8 reduces to checking existence of ← − w − → w such that Condition 1) and (ii) there exists no W ′ 0 (satisfying properties from Condition 2) such that ← − w − → w is accepted by By Lemmas 5.10 and 5.13, and Item (ii) reduces to checking non-existence of To perform these checks in EXPSPACE, we will characterise each initial window of the form W ′ 0 = (ρ 0 , H 0 , T 0 , b 0 ) locally satisfying Π and such that H 0 |= D-as mentioned in Condition 2 of Theorem 5.8-by a triple consisting of two initial windows (W ′ 0 ) L , (W ′ 0 ) R , and a flag b ∈ {0, 1} such that b = 1 if and only if H 0 = T 0 (so several windows can be characterised by the same triple).Now, we will show that a set T of all triples characterising all such windows W ′ 0 can be constructed in EXPSPACE.We observe that all (W ′ 0 ) L are over the same interval ρ L , which is in- dependent from the choice of the window W ′ 0 , since all W ′ 0 are over the same interval ρ (Π,D ) .Sim- ilarly, (W ′ 0 ) R are over the same interval ρ R , which is independent from the choice of W ′ 0 .Moreover, these ρ L and ρ R are polynomially long, and so, each (W ′ 0 ) L and (W ′ 0 ) R has a polynomial representation.Thus, there are exponentially many triples (W 1 , W 2 , b) which need to be checked for membership in T .Our EXPSPACE procedure iterates through all these triples.For each triple (W 1 , W 2 , b), the procedure checks if there exists an initial window We observe that checking Items (i) and (ii) reduces to checking non-emptiness of an automaton obtained by intersecting B ← with complements of all the automata corresponding to triples from T , where we say that a triple To conclude, we show that this check is feasible in EXPSPACE.Indeed, by construction, all automata mentioned above have states that can be represented in polynomial space.However, since these automata are nondeterministic, their complements have states of exponential size.To intersect the exponentially many such complemented automata, we construct an automaton whose states are exponentially long tuples, whose ith element is a state of the ith complemented automata.Such an exponentially long tuple of exponentially large states is itself exponentially representable.Thus, the obtained automaton has exponentially big states.Checking non-emptiness of this automaton is feasible in EXPSPACE using the standard on-the-fly approach, where states are guessed one-by-one (Baier and Katoen 2008).
The procedure outlined in the proof of the theorem shows that reasoning in DatalogMTL ¬ over the integer timeline is in EXPSPACE in data complexity.In the next section, we show how restricting the form of DatalogMTL ¬ programs to the forward-propagating fragment allows us to establish a tight PSPACE bound for data complexity.

Forward-Propagating Programs
In this section, we consider reasoning with forward-propagating programs (see Definition 3.1) and bounded datasets.This setting has already been studied in the context of stream reasoning (Ronca et al. 2018;Wałęga et al. 2019).
The normalisation of a DatalogMTL ¬ FP program, as defined in Section 5.1, results also in a DatalogMTL ¬ FP program; thus, for the remainder of this section, we let Π be a fixed (but arbitrary) DatalogMTL ¬ FP program in normal form and let D be a bounded dataset.Restricting ourselves to forward-propagating programs and bounded datasets will enable a simplification of the procedure in Section 5.1, where we check existence of a stable model of Π and D by looking for an initial window W 0 and a pair of words ← − w , − → w satisfying the conditions in Theorem 5.8.Towards this goal, we first show in Lemma 5.16 that we can guess the initial window W 0 over an interval located to the left of all intervals in D, instead of ρ (Π,D ) as in the previous section.Furthermore, we can use the fact that Π is forward-propagating to show that checking existence of word ← − w can be done independently of D. Finally, to check existence of word − → w , we define a new family of automata of the form F → W 0 , which can be used instead of X → W 0 , for X ∈ {A , B, C }; doing so requires no complementation, and thus we avoid the exponential blowup.As a result, the procedure becomes feasible in polynomial space.
We next define a new automaton F → W 0 as a refinement of B → W 0 .Furthermore, we impose an additional restriction on states of F → W 0 to guarantee their minimality, as described below.

Definition 5.15
We say that a window (ρ, H, T, b) locally satisfies D if M@t ∈ H for each M ∈ at(Π, D) and each t ∈ ρ such that D |= M@t.Let W 0 = (ρ 0 , T 0 , T 0 , 0) be an initial window locally satisfying Π (see Definition 5.3) and D. We define the generalised Büchi automaton F → W 0 analogously to the automaton B → W 0 in Definition 5.7, except that: -states in F → W 0 are additionally required to locally satisfy D, and -the transition function is additionally restricted so that transitions to a window (ρ, T, T, 0) are only allowed if there exists no window (ρ, H, T, 1) locally satisfying Π and D such that H and T coincide over [ρ − , ρ + − 1] and M@ρ + ∈ T \H for some relational atom M.
Note that F → W 0 is essentially deterministic since δ (W , σ ) contains at most one window for every state W and σ ∈ Σ.The following lemma provides the result analogous to Theorem 5.8 for the setting considered in this section.

Lemma 5.16
Program Π and dataset D have a stable model if and only if there exists an initial window W 0 = (ρ 0 , T 0 , T 0 , 0) locally satisfying Π and D with ρ 0 = [t min D − (t Π + 1),t min D − 1], which mentions only constants and predicates from Π, and there exist words ← − w and − → w over 2 at(Π,D ) such that all of the following conditions hold: 1. ← − w and − → w are accepted by B ← W 0 and F → W 0 , respectively, 2. there is no initial window W ′ 0 = (ρ 0 , H 0 , T 0 , b 0 ) locally satisfying Π and D such that ← − w is accepted by C ← W ′ 0 , 3. ← − w mentions only constants and predicates from Π.

Proof
Assume that T is a stable model of Π and D. To construct the required W 0 , ← − w , and − → w , we let . . ., W −1 , W 0 , W 1 , . . .be the [t min D − (t Π + 1),t min D − 1]-decomposition of HT-interpretation (T, T), and we let In what follows, we will show that the above defined W 0 , ← − w , and − → w satisfy the requirements from the lemma.First, we observe that H i = T i and b i = 0, for each i ∈ Z. Furthermore, by Lemma 5.6, each W i is a window locally satisfying Π and, since T is a stable model of Π and D, we obtain that each W i locally satisfies D. Therefore, as required in the lemma, W 0 is an initial window of the form (ρ 0 , T 0 , T 0 , 0) with ρ 0 = [t min D − (t Π + 1),t min D − 1], and it locally satisfies Π and D. Thus, it remains to show that W 0 mentions only constants and predicates from Π and that W 0 , ← − w , and − → w satisfy Conditions 1-3.To show that Condition 1 holds, we observe that, by Lemma 5.6, W 0 , W −1 , . . . is an accepting run of A ← W 0 ; moreover, since H i = T i and b i = 0 for all integers i ≤ 0, this run is also accepting for B ← W 0 .Analogously, W 0 , W 1 , . . . is an accepting run of B → W 0 .Now, suppose towards a contradiction that F → W 0 does not accept − → w .Then, by Definition 5.15, there exists a smallest integer i > 0 such that W 0 , . . ., does not have a transition from W i−1 to W i on σ i .Next, we will show how to define windows . . is an accepting run of C → W 0 on − → w , which will allow us to raise a contradiction.
Claim 5.17 There exist windows W ′ i , W ′ i+1 , . . .locally satisfying D such that W 0 , . . ., Proof of Claim 5.17 Recall that W i = (ρ i , T i , T i , 0).Since F → W 0 does not have a transition from W i−1 to W i on σ i , there exists a window W ′ = (ρ i , H ′ , T i , 1) locally satisfying Π and D such that H ′ coincides with T i over [ρ − i , ρ + i−1 ], and there exists an atom M ′ ∈ at(Π, D) satisfying M ′ @ρ + i ∈ T i \H ′ .We note also that since W ′ is a window and H ′ ⊆ T i , there exists an interpretation H ′ such that H ′ ⊆ T and both items from Definition 5.2 hold.We will use H ′ to define W ′ i , W ′ i+1 , . . . .To this end, we will say that an HT-interpretation (H * , T * ) satisfies a dataset D and program Π over an interval ρ * if and only if -for every M@ρ ∈ D and t ∈ ρ ∩ ρ * we have H * ,t |= M, and -(H * , T * ) satisfy the conditions of Definition 3.2 for each t ∈ ρ * .
We can use a construction similar to that in the proof of Theorem 3.4 to define the least interpretation H such that H ′ ⊆ H ⊆ T, H coincides with H ′ over (−∞, ρ − i ), and (H, T) satisfies D and Π over [ρ − i , ∞).An important observation is that since Π is forward-propagating and W ′ locally satisfies Π and D, interpretations H ′ and H also coincide over the interval ρ i .Now, we let . . ., , be the ρ 0 -decomposition of (H, T); hence, ρ ′ j = ρ j and T ′ j = T j , for each j.We observe also that since H coincides with H ′ over (−∞, ρ + i ], H ′ i agrees with H ′ on all relational atoms over (−∞, ρ + i ], so M ′ @t ∈ T i \H ′ i , and hence b ′ j = 1 for each j ≥ i.We will show that W 0 , . . ., W i−1 , W ′ i , W ′ i+1 , . . . is an accepting run of A → W 0 on − → w where all windows locally satisfy D, and then, we will show that this run is also accepted by C → W 0 .To this end, we observe that since W 0 , . . ., Moreover, W ′ i is an initial window, (since H ′ i = T i and b ′ i = 1) and, by an argument analogous to the proof of Lemma 5.6, each W ′ j for j ≥ i locally satisfies Π and D, and W ′ j , W ′ j+1 , . . . is an accepting run of A → W ′ i on σ i+1 , σ i+2 , . . . .Hence, to show that W 0 , . . ., W i−1 , W ′ i , W ′ i+1 , . . . is an accepting run of A → W 0 , it remains to show that A → W 0 has a transition on σ i from W i−1 to W ′ i .To do this, we first show that . Indeed, consider an arbitrary fact M@t with M ∈ at(Π, D) and t ∈ [ρ − i , ρ + i−1 ]; we will show that M@t ∈ H ′ i if and only if M@t ∈ H ′ .Note that since Π is forward-propagating, any atom M ∈ at(Π, D) is either of the form ⊞ [0,∞) P(c) for some relational fact P(c), or it does not mention future operators.Thus, if M does not mention future operators, the biconditional holds because H and H ′ coincide over the interval we conclude that ⊞ [0,∞) P(c)@t ∈ H ′ .Thus, the biconditional also holds in this case.With the above result, we can show that there is a transition in A → W 0 from W i−1 to W ′ i ; we can see this by checking that all the four conditions from Item 3 in Definition 5.4 hold.The first, third, and fourth conditions hold directly by the definition of W ′ i and the fact that ρ ′ i = ρ i , T ′ i = T i , and b ′ i = 1.The second condition states that H ′ i and H i−1 must coincide over the interval ρ i−1 ∩ ρ i .To see this, recall that H ′ i coincides with H ′ over this interval.In turn, H ′ coincides with T i over this interval by definition, and T i coincides with T i−1 over this interval by construction, but T i−1 = H i−1 , so H ′ i coincides with H i−1 and the condition holds.Therefore, W 0 , . . ., W i−1 , W ′ i , W ′ i+1 , . . . is an accepting run of A → W 0 on − → w where all windows locally satisfy D. Furthermore, W 0 , . . ., W i−1 , W ′ i , W ′ i+1 , . . . is also an accepting run of C → W 0 on − → w , since every window in the run after W ′ i has 1 as its fourth component, and so the additional accepting condition of C → W 0 is satisfied.This concludes the proof of Claim 5.17.Having proved the claim, we resume the proof of Lemma 5.16.Recall that W 0 , W −1 , . . . is an accepting run of A ← W 0 on ← − w and, as we showed in the claim above, W 0 , . . ., W i−1 , W ′ i , W ′ i+1 , . . . is an accepting run of C → W 0 on − → w .Hence, as in the proof of Theorem 5.8, we can use these runs to construct an HT-model (H ′′ , T) of Π and D such that H ′′ T; in particular, H ′′ |= D, as ρ − 0 is to the left of any integer mentioned in D and each window in the run W 0 , . . ., W i−1 , W ′ i , W ′ i+1 , . . .locally satisfies D. This, however, means that T is not a stable model of Π and D, which raises a contradiction.
To prove Condition 2, suppose towards a contradiction that there exists an initial window W ′ 0 = (ρ 0 , H 0 , T 0 , b 0 ) which locally satisfies Π and D, and such that there exits an accepting run for some set H i of metric atoms and b i ∈ {0, 1}.We consider the least model H ′ of all relational facts in i≤0 H i .The accepting conditions of C ← W ′ 0 ensure that there is an atom P(c) and a time point t ∈ (−∞, ρ + 0 ] such that H ′ ,t |= P(c) but T,t |= P(c).By an argument analogous to that in the proof of Theorem 5.8, and using the facts that W ′ 0 locally satisfies D and W ′ i locally satisfies Π for each i ≤ 0, we obtain that (H ′ , T) satisfies D and Π over (−∞, ρ + 0 ].Then, using a construction similar to that in the proof of Theorem 3.4, we can extend H ′ to the minimal interpretation H such that (H, T) is an HT-model of Π and D. Since Π is forward-propagating, and (H ′ , T) already satisfies D and Π over (−∞, ρ + 0 ], we have that H and H ′ agree over (−∞, ρ + 0 ].But then, H T since, as we have shown, there is t ∈ (−∞, ρ + 0 ] such that H ′ ,t |= P(c) but T,t |= P(c).Thus, T is not stable, which raises a contradiction.
To prove Condition 3, we define a sequence H 0 , H 1 , . . . of interpretations as follows: -H 0 is the least model of D, -H α , for a successor ordinal α, is the least interpretation such that for each rule of Form (1) in ground(Π), and for each time point t, if By the proof of Theorem 3.4, each H α is well defined and T = H ω 1 .Hence, to prove Condition 3, it suffices to show by transfinite induction that, for every ordinal α, if H α ,t |= P(c) for some relational atom P(c) and t < t min D , then P and all constants in c occur in Π.In the base case H 0 is the least model of D. Since D is bounded, all the facts it mentions are over intervals contained in [t min D , ∞), and so, the statement holds.In the inductive step for a successor ordinal α, we suppose towards a contradiction that H α ,t |= P(c) and H α−1 ,t |= P(c), for some relational atom P(c) and t < t min D , such that P or some constant in c does not occur in Π.Hence, there exists a rule r in ground(Π, D) whose head is P(c), whose positive body atoms are satisfied by H α−1 at t, and whose negated body atoms are satisfied by T at t. Thus, P appears in Π, so there exists a constant c in c which does not appear in Π.By the safety and the normal form of r, the constant c needs to occur in a relational atom M such that either M or ⊟ ρ M, or M ′ S ρ M is a positive body atom in r.Each of these cases, however, implies that H α−1 ,t ′ |= M, for some t ′ ≤ t, which violates the induction hypothesis.In the inductive step for a limit ordinal α, we have H α = β <α H β ; since the claim holds for each H β by induction hypothesis, it holds also for H α .
We observe that the above result not only shows that Condition 3 holds, but also that W 0 mentions only constants and predicates from Π, which completes the proof of the first implication from the lemma.
To show the reverse implication from Lemma 5.16, let W 0 = (ρ 0 , T 0 , T 0 , 0), ← − w , and − → w be as described in Lemma 5.16.In particular, by Condition 2, B ← W 0 has an accepting run W 0 , W −1 , . . . on ← − w and F → W 0 has an accepting run W 0 , W 1 , . . . on − → w , where we let W i = (ρ i , T i , T i , 0).We will show that the least model T of relational facts in i∈Z T i is a stable model of Π and D. Using an argument analogous to the proof of Theorem 5.8, we obtain that (T, T) is an HT-model of Π and D. Now, suppose towards a contradiction that T is not a stable model, so there is an interpretation H T such that (H, T) is an HT-model of Π and D. We let . . ., Moreover, by Definition 5.5, W ′ 0 is an initial window, and it is straightforward to verify that W ′ i locally satisfies Π and D, for each i ∈ Z. Now, by Lemma 5.6, for all j ≤ i, and so C ← W ′ 0 accepts ← − w , which contradicts Condition 2. Otherwise, let i be the least (positive) integer such that T, ρ + i |= M but H, ρ + i |= M, for some relational atom M ∈ at(Π, D).Observe that this implies H ′ j = T j for each j < i, and we have that H ′ i coincides with T i over this interval.To sum up, recall that W i is of the form (ρ i , T i , T i , 0), whereas, by construction, and there exists a relational atom M with M@ρ + ∈ T i \H ′ i .This, by Definition 5.15, implies that the automaton F → W 0 cannot have a transition to W i , and so, W 0 , W 1 , . . . is not an accepting run of F → W 0 on − → w , which raises a contradiction.Next, we use Lemma 5.16 to establish a tight PSPACE bound for reasoning in DatalogMTL ¬ FP .Theorem 5.18 Checking whether a DatalogMTL ¬ FP program and a bounded dataset have a stable model is PSPACE-complete with respect to data complexity.

Proof
For the lower bound, we observe that Wałęga et al. (2020a) showed PSPACE-hardness in data complexity of checking existence of models for a class of programs which is strictly smaller than the class of positive DatalogMTL ¬ FP programs.Their reduction can be modified in a straightforward way so that the involved dataset is bounded.Then, Theorem 3.7 directly implies that the same lower bound holds for all (i.e., not necessarily positive) DatalogMTL ¬ FP programs, as required.
For the upper bound, by Lemma 5.16, it suffices to show that checking existence of a window W 0 and words ← − w and − → w satisfying the properties described in the statement of the lemma is feasible in PSPACE.First, we observe that W 0 is over ρ 0 = [t min D − (t Π + 1),t min D − 1], so its length does not depend on D. Hence, W 0 is polynomially large (in the size of the representation of D), and so it can be guessed in PSPACE; moreover, one can check in PSPACE whether W 0 locally satisfies Π and D, and whether it mentions only constants and predicates from Π. Next, we show how to verify existence of words ← − w and − → w over 2 at(Π,D ) such that W 0 , ← − w , and − → w satisfy Conditions 1-3.To verify existence of a word ← − w accepted by B ← W 0 (first part of Condition 1) which is not accepted by any C ← W ′ 0 (Condition 2) we can use the approach from the proof of Theorem 5.14.We observe that W 0 mentions only constants and predicates from Π, and so, the same holds for windows W ′ 0 from Condition 2.Moreover, by Condition 3, ← − w also mentions only constants and predicates from Π, and so the above check can be performed independently of D.
It remains to be shown that checking existence of a word − → w accepted by F → W 0 (that is, the second part of Condition 1) is feasible in PSPACE.To this end, we check existence of an accepting run W 0 , W 1 , . . . of F → W 0 in two steps.First, we guess windows W 1 , . . ., W j one by one, where j = t max D − t min D + 2t Π + 2, and second, we check if F → W j has an accepting run.We observe that each of the windows W 1 , . . ., W j is of polynomial size, and so guessing them one by one, as well as checking that F → W 0 has transitions between consecutive windows, is feasible in PSPACE.To check non-emptiness of the language of F → W j , we construct for it an automaton F → W j in a similar way as we constructed X → W j for X → W j in the proof of Theorem 5.14.The difference, however, is that the set of states of F → W j is the quotient set of ∼ between only those states of F → W j whose first elements are intervals located entirely to the right of t max D + t Π .For any such state W i = (ρ i , T i , T i , 0), checking whether it locally satisfies D simply amounts to verifying that M@t ∈ T i for each M ∈ at(Π, D) such that M@ρ − j ∈ T j , and each t ∈ ρ i .Indeed, this follows from two observa- tions: first, for any atom M ∈ at(Π, D) and two arbitrary time points t,t ′ > t max D + t Π , D |= M@t if and only if D |= M@t ′ ; second, ρ − j > t max D + t Π , by definition of j.Then, using an argument analogous to the proof of Lemma 5.10, we can show that F → W j and F → W j are equivalent.Hence, it remains to check if the language of the latter automaton is non-empty.By construction, each state of the automaton F → W j can be represented in polynomial space, so the non-emptiness check is feasible in PSPACE using a standard on-the-fly approach.
The assumption that D is bounded has been used to ensure existence of a time point such that no fact of D holds to the left of it.Thus, our results can be extended to show that reasoning is still PSPACE in data complexity for datasets where intervals are only bounded on the left.Furthermore, none of our results in this section depend on the direction of time.Indeed, we can define the backward-propagating fragment of DatalogMTL ¬ (analogously to DatalogMTL ¬ FP ) as the set of programs where operators , ⊟, and S are disallowed in rule bodies, and operator ⊞ is disallowed in the head.Then, we can obtain an analogous set of results for the backward-propagating fragment and show that reasoning in such fragment is also PSPACE in data complexity.

Related Work
Positive DatalogMTL (Brandt et al. 2018) has been studied over both the rational (Brandt et al. 2018) and the integer (Wałęga et al. 2020a) timelines.In both cases, the main reasoning tasks are EXPSPACE-complete for combined complexity (Brandt et al. 2018) and PSPACE-complete for data complexity (Wałęga et al. 2019).Low complexity fragments (Wałęga et al. 2020b;Wałęga et al. 2021) and alternative semantics (Ryzhikov et al. 2019) have also been studied.Practical reasoning algorithms for positive DatalogMTL have been recently proposed and implemented in the MeTeoR system (Wang et al. 2022).
DatalogMTL ¬ is an extension of DatalogMTL; therefore, it also extends other prominent temporal rule languages captured by DatalogMTL such as Datalog 1S (Chomicki and Imieliński 1988;Chomicki and Imieliński 1989) and Templog (Abadi and Manna 1989).In turn, DatalogMTL ¬ Our approach is closely related to a recently proposed family of non-monotonic temporal logics which simultaneously support ASP and modal temporal operators.Temporal equilibrium logic (TEL) (Cabalar and Vega 2007;Aguado et al. 2013;Cabalar et al. 2018) combines propositional ASP with operators from linear temporal logic (Pnueli 1977).Metric equilibrium logic (MEL) (Cabalar et al. 2020) extends TEL with metric temporal operators that are roughly equivalent to our past operators S [0,k] and ⊟ k , and their future counterparts.Both logics introduce non-monotonic semantics for negation based on stable models, which are defined-as in our work-analogously to the models of equilibrium logic.However, TEL and MEL differ from our approach.First, they allow formulas supporting all Boolean connectives; therefore, they can represent disjunction between propositions, as well as 'existential' formulas using diamond operators; in contrast, in DatalogMTL ¬ the use of logical connectives and temporal operators is restricted so that all formulas are shaped as rules similar in spirit to those of Datalog (see Definition 3.1).Second, they are propositional logics, so they do not allow universally quantified variables.Finally, the semantics of TEL and MEL are defined on integer timelines with a least time point, whereas we consider both the full integer timeline as well as the dense rational timeline.In terms of complexity, checking whether a formula has a stable model is known to be PSPACE-hard for both TEL and MEL, and feasible in EXPSPACE for TEL.
Our approach is also related to the LARS language (Beck et al. 2018) for stream reasoning.LARS is also a rule-based language allowing for negation interpreted under stable model semantics.The differences between DatalogMTL ¬ and LARS are as follows.First, conjuncts in the body of LARS rules are formulas constructed using temporal operators and unrestricted combi-nations of Boolean connectives; in contrast, body conjuncts in DatalogMTL ¬ are metric atoms, which do not mention Boolean operators.Second, LARS does not allow for metric operators (only LTL-style boxes and diamonds), but it allows for window operators that have no counterpart in DatalogMTL ¬ .Third, LARS rules are meant to be interpreted at individual time points, so the notion of a stable model in LARS is always relative to a time point (e.g., a LARS interpretation can be a stable model of a program at t, but not at t + 1); in contrast, a stable model of a DatalogMTL ¬ program satisfies each rule at every time point in the timeline (see Definition 3.2).Finally, LARS interpretations are defined over bounded intervals of the integer timeline, whereas DatalogMTL ¬ interpretations are defined over the full integer or rational timeline.Checking whether a LARS program and dataset have a stable model at a time point t is PSPACE-complete.
The use of ASP for temporal reasoning has been intensively explored, especially in the context of stream reasoning.Streamlog (Zaniolo 2012) introduces a variant of Datalog with negation where atoms are 'time-stamped,' in the sense that the first term of an atom is a natural number representing the time point where the atom holds.Rules in Streamlog must be forwardpropagating in time; furthermore, programs must be locally stratified, which ensures that they have a unique stable model.Do et al. (2011) present an approach which combines a generalpurpose ASP solver with a monotonic stream reasoner to support ASP in stream reasoning; in this approach, both systems are treated as black boxes.Another approach that supports ASP on a temporal setting is time-decaying reasoning (Gebser et al. 2013), which relies on programs similar to Datalog, but where each fact and rule need to hold only over a fixed time interval; this behaviour is used to capture changing information from a sliding window over a sequence of temporal data.More recently, negation-free DatalogMTL ¬ has been applied in the context of monotonic stream reasoning (Wałęga et al. 2019), and we see our current work as providing the foundations for extending this approach with support for ASP.

Conclusion and Future Work
We extended DatalogMTL with negation-as-failure under stable model semantics and shown that reasoning in this language is undecidable over the rational timeline but EXPSPACE in data complexity over the integers.We also studied the forward-propagating fragment and shown that, although reasoning remains undecidable over the rational timeline, it is becomes PSPACE-complete in data complexity over the integers (thus no harder than in the negation-free case).
We see many avenues for future work.The more immediate challenge is to provide tight data complexity bounds for reasoning in the full language over the integer timeline, where we currently have an EXPSPACE upper bound and a PSPACE lower bound for data complexity.We also plan to consider combined complexity and identify fragments of the language where reasoning becomes decidable over the rational timeline.Finally, we are planning to develop practical algorithms and implement them as an extension the MeTeoR reasoner, that is currently allows for reasoning with positive DatalogMTL programs only (Wang et al. 2022).public copyright licence to any Author Accepted Manuscript (AAM) version arising from this submission.
Let (T, T) be an HT-model of a program Π and a dataset D. Then the set of interpretations {H | (H, T) is an HT-model of Π and D} contains a unique least interpretation.
Proposition 5.1 Each program Π can be normalised in polynomial time into a program Π ′ such that, for each dataset D, program Π and dataset D have a stable model if and only if so do Π ′ and D.
and b ′ = 1 whenever b = 1 or H ′ = T ′ , and b ′ = 0 otherwise; 1. ← − w and − → w are accepted by B ← W 0 and B → W 0 , respectively, 2. there is no initial window W ′ 0 = (ρ 0 , H 0 , T 0 , b 0 ) locally satisfying Π such that H 0 |= D, and ← − w and − → w are accepted either by C ← and H ′ 0 |= D.Moreover, we assume that ← − w and − → w are accepted by C ← . . on − → w , where we let 1 ), for any integer i ≤ 0. It remains to show that A ← accepting conditions modulo the definition of states.Next, let k be the difference between lengths of windows W 0 and W L 0 .Observe that for any integer i ≤ −k, if W i belongs to some set S from the accepting condition of A ← W 0 , then there exists j ∈ [i, i+ k] such that W ′ j belongs to a set from the accepting condition of A ← W L 0 that corresponds to S. Since each set in the accepting condition of A ← W 0 is visited infinitely often by the states in the run W 0 , W −1 , . . ., each set in the accepting condition of A ← W L 0 is also visited infinitely often by the states in the run W ′ 0 , W ′ −1 , . . . .Thus, the latter is an accepting run of A ← an analogous argumentation, we obtain that if A → W 0 accepts a word w, then so does A → and so, each window in any run of the automata C ← W 0 and C → W 0 will belong to the additional set {(ρ, H, T, b) ∈ Q | b = 1} from the accepting condition.Hence, this additional condition is trivially satisfied by any infinite run, so C ← W 0 and C → W 0 are equivalent to A ← W 0 and A → W 0 , respectively.Therefore, by Statement 1, we obtain that C ← W 0 and C → W 0 are also equivalent to A ← and b = 1 if and only if H 0 = T 0 .All these checks are feasible in EXPSPACE, and if they yield positive answers, then (W 1 , W 2 , b) ∈ T .

FP
generalises the forward-propagating fragment of DatalogMTL introduced by Wałęga et al. (2019), and it is thus related to other forward-propagating temporal logics proposed in the literature (Baldor and Niu 2012; Ronca et al. 2018; Basin et al. 2018).Our stable model semantics (Wałęga et al. 2021) extends the semantics for stratified DatalogMTL ¬ programs (Tena Cucala et al. 2021).

Table 1 .
|= T ρ M iff I,t ′ |= T M for some t ′ with t − t ′ ∈ ρ I,t |= T ρ M iff I,t ′ |= T M for some t ′ with t ′ − t ∈ ρ I,t |= T ⊟ ρ M iff I,t ′ |= T M for all t ′ with t − t ′ ∈ ρ I,t |= T ⊞ ρ M iff I,t ′ |= T M for all t ′ with t ′ − t ∈ ρ I,t |= T M 1 S ρ M 2 iff I,t ′ |= T M 2 for some t ′ with t − t ′ ∈ ρ and I,t ′′ |= T M 1 for all t ′′ ∈ (t ′ ,t) I,t |= T M 1 U ρ M 2 iff I,t ′ |= T M 2 forsome t ′ with t ′ − t ∈ ρ and I,t ′′ |= T M 1 for all t ′′ ∈ (t,t ′ ) Semantics of ground metric atoms 2.2 Syntax and Semantics of Metric Temporal Expressions M 1 , . . ., M k are its positive body atoms, and M k+1 , . . ., M m are its negated body atoms.A rule is safe if each variable it mentions in the head occurs in some positive body atom in a position other than a left operand of S or U .A rule is ground if it has no variables, and it is positive if it has no negated body atoms.A (DatalogMTL ¬ ) program is a finite set of safe rules; it is ground or positive if all its rules are.For a program Π, we let ground(Π) be the set of all ground rules that can be obtained by replacing variables in Π with constants.A program is forward-propagating (DatalogMTL ¬ FP ) if it is DatalogMTL ¬ but does not mention the operators , ⊞, and U in rule bodies, or the operator ⊟ is rule heads.
Let Π be a positive program and let D be a dataset.An interpretation I is a stable model of Π and D if and only if I is their least model.H 1 , . . . of interpretations contained in I as in the proof of Theorem 3.4, which satisfies H ω 1 = H I Π,D .Furthermore, since Π is positive, we can observe that, for every ordinal α, it holds that H α = T α Π (I D ), where T α Π (I D ) is the result of applying α times the immediate consequence operator of a positive program Π to an interpretation I D represented by D. In particular, H ω 1 = T ω 1 Π (I D ), which is the least model of Π and D (Wałęga et al. 2021; Brandt et al. 2017).Hence, H I Π,D is the least model of Π and D. Now, if I is a stable model of Π and D, then (I, I) is an HT-model of Π and D; as shown in the previous paragraph, this implies that H I Π,D is the least model of Π and D. However, since I is a stable model of Π and D, we have I = H I Π,D , and thus I is also the least model of Π and D. Conversely, if I is the least model of Π and D, then (I, I) is an HT-model of Π and D; then, as shown in the previous paragraph, I = H I Π,D , and so I is a stable model of Π and D. It follows that, if a positive program and a dataset have a model, then they have a stable model.Note, however, that this is not the case for other temporal logics with stable model semantics