Here and There with Arithmetic

In the theory of answer set programming, two groups of rules are called strongly equivalent if, informally speaking, they have the same meaning in any context. The relationship between strong equivalence and the propositional logic of here-and-there allows us to establish strong equivalence by deriving rules of each group from rules of the other. In the process, rules are rewritten as propositional formulas. We extend this method of proving strong equivalence to an answer set programming language that includes operations on integers. The formula representing a rule in this language is a first-order formula that may contain comparison symbols among its predicate constants, and symbols for arithmetic operations among its function constants. The paper is under consideration for acceptance in TPLP.


Introduction
In the theory of answer set programming, two groups of rules are called strongly equivalent if, informally speaking, they have the same meaning in any context.The relationship between strong equivalence and the propositional logic of here-and-there (Lifschitz et al. 2001) allows us to establish strong equivalence by deriving rules of each group from rules of the other.In the process, rules are rewritten as propositional formulas.The head and the body of a rule become the consequent and the antecedent of an implication; negationas-failure is replaced by classical negation; and choice expressions are tranformed into excluded middle formulas.For instance, we rewrite the rule {q} :-p (1) as the formula and the rule q :-p, not not q (3) as the formula p ∧ ¬¬q → q.
(4) Formulas ( 2) and (4) can be derived from each other using the postulates of intuitionistic logic and the Hosoi axiom schema which is part of the standard axiomatization of the logic of here-and-there (Hosoi 1966).
We can conclude then that rules (1) and ( 3) are strongly equivalent to each other.
Our goal is to extend this method of proving strong equivalence to rules of minigringo-the fragment of the input language of gringo (Gebser et al. 2019) investigated in several recent publications (Lifschitz et al. 2019;Fandinno et al. 2020;Lifschitz et al. 2020;Lifschitz 2021).Since mini-gringo rules may contain variables, comparison symbols, and symbols for arithmetic operations, the formula representing a rule will be a first-order formula that may contain comparison symbols among its predicate constants, and symbols for arithmetic operations among its function constants.
The study of strong equivalence for fragments of the input language of gringo may be useful for the practice of answer set programming, because it can help the programmer to see which modifications of a rule or a group of rules preserve the set of stable models.This is important, in particular, because some features of the strong equivalence relation between gringo programs may seem counterintuitive.For instance, the rule p(1..X) :-p(1..X), q(X) appears to be trivial and strongly equivalent to the empty program, but it is not.Adding this rule to the pair of facts p(2), q(2) gives the program with a stable model that includes p(1).(The reason is that gringo treats p(1..X) in the head of a rule as a conjunction, and in the body as a disjunction.)To give another example, the one-rule programs have different stable models.
Stable models of a mini-gringo program Π are defined as stable models of the set of propositional formulas obtained from Π by the syntactic transformation τ (Lifschitz et al. 2019, Section 3).The definition of τ involves naive grounding, so that the set τ Π is infinite whenever Π contains variables.Mini-gringo programs Π 1 and Π 2 are strongly equivalent to each other if τ Π 1 is strongly equivalent to τ Π 2 , that is to say, if, for every set Ω of propositional formulas, τ Π 1 ∪ Ω has the same stable models as τ Π 2 ∪ Ω.The paper (Lifschitz et al. 2019) where this definition was proposed aimed at verifying strong equivalence of mini-gringo programs using theorem provers for classical logic.Here we study the same equivalence relation, but the goal is different: we would like to develop methods for proving strong equivalence using non-classical reasoning "manually," without assistance of automated reasoning tools.
The next section provides background information on the syntax of mini-gringo, on the logic of here-and-there, and on transforming mini-gringo rules into sentences of a first-order language.In Section 3 we describe the deductive system HTA (for "hereand-there with arithmetic"), which can be used to establish strong equivalence between mini-gringo programs.A theorem expressing this fact is stated in Section 4 and proved in Section 5. Then we show a pair of strongly equivalent mini-gringo programs to which the method proposed in this paper is not applicable (Section 6) and outline directions for future work (Section 7).

Syntax of Mini-GRINGO
Programs below are written in "abstract syntax" that disregards some details related to representing programs by strings of ASCII characters (Gebser et al. 2015).We assume that three countably infinite sets of symbols are selected: numerals, symbolic constants, and variables.We assume that a 1-1 correspondence between numerals and integers is chosen; the numeral corresponding to an integer n will be denoted by n.Precomputed terms are numerals, symbolic constants, and the symbols inf, sup.Terms allowed in a mini-gringo program are formed from precomputed terms and variables using the six operation names An atom is a symbolic constant optionally followed by a tuple of terms in parentheses.A literal is an atom possibly preceded by one or two occurrences of not.A comparison is an expression of the form t 1 ≺ t 2 , where t 1 , t 2 are program terms and ≺ is one of the six comparison symbols • Body is a conjunction (possibly empty) of literals and comparisons, and • Head is either an atom (then (9) is a basic rule), or an atom in braces (then (9) is a choice rule), or empty (then (9) is a constraint ).
A program is a finite set of rules.
As mentioned in the introduction, the semantics of mini-gringo is defined by transforming rules into sets of propositional formulas (Lifschitz et al. 2019, Section 3).

Logic of Here and There
(Propositional) formulas are formed from propositional atoms and the symbol ⊥ ("false") using the connectives ∧, ∨, →; ¬F is shorthand for F → ⊥, and F ↔ G is shorthand for (F → G) ∧ (G → F ).The deductive systems discussed in this paper are based on the version of natural deduction that operates with sequent s-expressions Γ ⇒ F , in which Γ is a finite set of formulas ("assumptions"), and F is a formula.We write sets of assumptions as lists.For instance, A 1 , A 2 ⇒ F is shorthand for {A 1 , A 2 } ⇒ F , and Γ, A ⇒ F is shorthand for Γ ∪ {A} ⇒ F .A sequent of the form ⇒ F will be identified with the formula F .
The postulates of propositional intuitionistic logic are the axiom schema F ⇒ F , the introduction and elimination rules shown in Figure 1, the contradiction rule (C) Γ ⇒ ⊥ Γ ⇒ F and the weakening rule 1. p → q ∨ ¬q ⇒ p → q ∨ ¬q -axiom 2.
p ∧ ¬¬q, ¬q ⇒ q -from 9 by (C) 10. p → q ∨ ¬q, p ∧ ¬¬q ⇒ q -from 5, 6 and 9 by (∨E) 11. p → q ∨ ¬q, ⇒ p ∧ ¬¬q → q -from 10 by (→ I) 12. ⇒ (p → q ∨ ¬q) → (p ∧ ¬¬q → q) -from 11 by (→ I) Classical propositional logic can be formalized by adding the law of the excluded middle F ∨ ¬F to this deductive system as another axiom schema.The logic of here-and-there is the result of adding a weaker axiom schema, Hosoi axiom (5).Thus the logic of hereand-there is intermediate between intuitionistic and classical.1 The implication from (2) to (4) can be proved intuitionistically (Figure 2).Informally, this proof can be summarized as follows.Assume p → q ∨ ¬q and p ∧ ¬¬q.Then p and consequently q ∨ ¬q.The second disjunctive term contradicts ¬¬q; consequently q.We have derived p ∧ ¬¬q → q from p → q ∨ ¬q.

Two-Sorted Formulas and the System Int
The target language of transformations that convert mini-gringo rules into sentences is a first-order language with two sorts: the sort generic and its subsort integer.Variables of the first sort are meant to range over arbitrary precomputed terms, and we will identify them with variables used in mini-gringo rules.Variables of the second sort are meant to range over numerals (or, equivalently, integers).The need to use a language with two sorts is explained by the fact that function symbols in a first-order language are supposed to represent total functions, and arithmetic operations are not defined on symbolic constants.We will use letters X, Y , Z to represent variables of the sort generic, M and N for variables of the sort integer, and V when the sort is irrelevant.Formulas of the two-sorted system of intuitionistic logic Int (Lifschitz 2021, Section 3) are first-order formulas of the signature σ that includes • all precomputed terms as object constants; an object constant is assigned the sort integer iff it is a numeral; • the symbols +, − and × as binary function constants; their arguments and values have the sort integer ; • pairs p/n, where p is a symbolic constant and n is a nonnegative integer, as n-ary predicate constants; • the comparison symbols =, =, <, >, ≤, ≥ as binary predicate constants.
An atomic formula (p/n)(t 1 , . . ., t n ) can be abbreviated as p(t 1 , . . ., t n ).An atomic formula ≺(t 1 , t 2 ), where ≺ is a comparison symbol, can be written as t 1 ≺ t 2 .Conjunctions of equalities and inequalities can be abbreviated as usual in algebra (for instance, Note the difference between the set of terms over σ and the set of terms allowed in mini-gringo programs.The former includes terms containing integer variables, which are not allowed in mini-gringo.On the other hand, the latter includes terms containing the symbols /, \ and .. that are not part of σ. 2Formulas over σ are formed from atomic formulas, the symbols ⊥, ∧, ∨, → and the quantifiers ∀, ∃ as usual in first-order logic.Derivable objects of Int are sequents, formed from formulas over σ as described in Section 2.2 for the propositional case.The system has two axiom schemas, F ⇒ F and t = t, where t is a term over σ.Its inference rules are the rules listed in Section 2.2 and the additional rules for quantifiers and equality shown in Figure 3.

Transforming Rules into Formulas
The translation τ * (Lifschitz et al. 2019, Section 6) transforms mini-gringo rules into sentences over the signature σ defined above.In some cases, it converts a short rule into a syntactically complex formula that can be made much shorter by intuitionistically equivalent transformations.This is related to the generality of the concept of a term in where t1 and t2 are substitutable for V in F Fig. 3.Additional rules for quantifiers and equality.By F V t we denote for the formula obtained from F by substituting the term t for all free occurrences of the variable V .In rules (∀E), (∃I) and (Eq) the terms substituted for V are required to be of the sort integer if V is of the sort integer.
the input language of gringo.Its syntax allows us to combine applications of the interval operation .. with addition and multiplication in any order.This feature is preserved in mini-gringo; we can write, for instance, ((1 .. 3) × (4 .. 6)) + (7 .. 9), and even (1 .. 3) .. 4. (The latter actually has the same meaning as 1 .. 4.) The need to translate rules that contain combinations like these may cause significant overhead when τ * is applied to less exotic rules.
This overhead can be avoided if we do not try to cover arbitrary rules (Lifschitz 2021).A mini-gringo term is a regular term of the first kind if • it contains no operation symbols other than +, −, ×, and • symbolic constants and the symbols inf, sup do not occur in it in the scope of operation symbols.
A regular term of the second kind is a term of the form t 1 .. t 2 , where t 1 and t 2 are regular terms of the first kind that contain neither symbolic constants nor the symbols inf, sup.
A rule ( 9) is regular if it satisfies the following conditions: • every term occurring in it is regular (of the first or second kind), • if a conjunctive term of Body is a literal then it does not contain terms of the second kind, • if a conjunctive term of Body is a comparison that contains a term of the second kind then it has the form t 1 = t 2 .. t 3 , where t 1 is a term of the first kind different from symbolic constants and from the symbols inf, sup.
The translation ν transforms every regular rule R into a sentence over σ such that the equivalence between νR and τ * R is provable in Int .We review here the definition of ν for the special case when the head of the rule does not contain terms of the second kind (Lifschitz 2021, Section 4).Applying the translation ν to such a rule involves substituting variables of the sort integer for the variables that occur in that rule at least once in the scope of an operation symbol or in a comparison of the second kind.Make the list X 1 , . . ., X m of all such variables, and choose m distinct integer variables N 1 , . . ., N m .Substituting N 1 , . . ., N m for X 1 , . . ., X m in a term t of the first kind that occurs in R eliminates generic variables in the scope of operation symbols, so that the result of this substitution is a term over σ.This term is denoted by p2f(t), and similarly for the result of this substitution applied to a tuple of terms.
The result of applying ν to a rule ( 9) is defined as the universal closure of the formula where Body ′ is obtained from Body by replacing • every occurence of an atom p(t) by p(p2f(t)), • every occurence of not by ¬, • every comparison t 1 ≺ t 2 of the first kind by p2f(t 1 ) ≺ p2f(t 2 ), • every comparison t 1 ≺ t 2 .. t 3 of the second kind by p2f(t 2 ) ≤ p2f(t 1 ) ≤ p2f(t 3 ); and Head ′ is For instance, rules ( 6) and ( 7) are regular, and the transformation ν turns them into the formulas The result of applying τ * to a program Π is the set (or conjunction) of the sentences τ * R for all rules R of Π, and similarly for ν.

Deductive System HTA
The system HTA is obtained from the system Int reviewed in Section 2.3 by adding the following postulates.

A. Hosoi axiom schema (5). B. The decidability axioms
for all comparison symbols ≺, and the axioms expressing that comparison symbols describe a total order with the smallest element inf and the largest element sup.Some classically equivalent formulas expressing properties of order relations are not equivalent intuitionistically; for instance But in the presence of decidability axioms (10) such formulas are interchangeable.For this reason, there is no need to go into details about the choice of axioms in this group.
C. All true formulas of the forms c 1 ≺ c 2 and ¬ (c 1 ≺ c 2 ), where c 1 , c 2 are precomputed terms and ≺ is a comparison symbol.If, for instance, strings of lowercase letters are symbolic constants and they are ordered lexicographically then ab < ac is one of the axioms in this group.D. All arithmetical sentences that are true in the domain of integers.(We call a formula arithmetical if all its atomic subformulas are comparisons between integer terms.)Examples: 2 × 2 = 4, ∀N (N × N ≥ 0).

Proving Strong Equivalence
Theorem.For any mini-gringo programs Π 1 and Π 2 , if the equivalence between τ * Π 1 and τ * Π 2 can be proved in HTA then Π 1 is strongly equivalent to Π 2 .
Since the equivalence between τ * Π i and νΠ i is provable in Int when all rules are regular, the translation τ * can be replaced by ν in this special case: Corollary.For any mini-gringo programs Π 1 and Π 2 that consist of regular rules, if the equivalence between νΠ 1 and νΠ 2 can be proved in HTA then Π 1 is strongly equivalent to Π 2 .
The examples below show how the corollary can be used to prove strong equivalence of mini-gringo programs.
Example 1.The rule {q(X)} ← p(X + 1) (11) is strongly equivalent to q(X) ← p(X + 1) ∧ not not q(X), because the result of applying ν to ( 11) is equivalent in HTA to the result of applying ν to (12).The derivation of this equivalence is parallel to the derivation of the equivalence between ( 2) and ( 4) presented in Section 2.2, with the addition of ∀-elimination and ∀-introduction steps.
An attempt to prove the conjecture that program ( 13) is strongly equivalent to its second rule fails.(From the second of formulas ( 14) we can derive ∀N (p(N ) → q(N )) by substituting N − 1 for N , but the ∀-elimination rule of Int does not sanction substituting X for N .)That conjecture is actually incorrect: adding rules (13) to the fact p(a) gives a program with the stable model {p(a), q(a)}; adding the second rule alone does not allow us to conclude q(a).
is strongly equivalent to the rule Indeed, ν transforms the first of rules (15) into and the second into The last formula is intuitionistically equivalent to On the other hand, ν transforms rule (16) into The equivalence of ( 19) to the conjunction of ( 17) and ( 18) is an intuitionistic consequence of the formula which follows from the axioms in Group B.
Example 4. The rule Indeed, ν transforms rule (20) into and rule (21) into The last formula is equivalent in HTA to (using the axiom ∀M N (M ≤ N ∨ N ≤ M ) from Group D).Consequently it is equivalent to the conjunction of ( 22) and It remains to observe that the last formula is equivalent to ( 22) by the commutativity of addition, which is an axiom in Group D.
The conditions for strong equivalence given by the theorem and the corollary are sufficient, but not necessary.A counterexample proving this fact is given in Section 6.

Proof of the Theorem
Prior to presenting the proof of the theorem from Section 4, we review the infinitary logic of here-and-there, which plays a large part in the proof.

Review: Infinitary Logic of Here-and-There
The syntax of infinitary propositional formulas (Truszczynski 2012) can be described as follows.For every nonnegative integer r, (infinitary) formulas of rank r over a given set of atomic propositions are defined recursively, as follows: • every atomic proposition is a formula of rank 0, • if H is a set of formulas, and r is the smallest nonnegative integer that is greater than the ranks of all elements of H, then H ∧ and H ∨ are formulas of rank r, • if F and G are formulas, and r is the smallest nonnegative integer that is greater than the ranks of F and G, then F → G is a formula of rank r.
We write {F, G} ∧ as F ∧ G, and {F, G} ∨ as F ∨ G.The symbol ⊥ is understood in this language as shorthand for ∅ ∧ , and ⊤ is shorthand for ∅ ∨ .These conventions allow us to treat propositional combinations of atomic propositions as a special case of infinitary formulas.
For any family {F α } α∈A of formulas whose ranks are bounded, we denote the formula {F α : α ∈ A} ∧ by α∈A F α , and similary for disjunctions.
An interpretation is a set of atomic propositions.The satisfaction relation between an interpretation and a formula is defined recursively, as follows: • For every atomic proposition p, I |= p if p ∈ I.
A formula is tautological if it is satisfied by all interpretations.
An HT-interpretation is an ordered pair I, J of interpretations such that I ⊆ J.The satisfaction relation between an HT-interpretation and an infinitary formula (Harrison et al. 2017) is defined recursively, as follows: • For every atomic proposition p, I, J |= p if p ∈ I.

Plan of the Proof
A precomputed atom is a symbolic constant optionally followed by a tuple of precomputed terms in parentheses.The proof of the theorem uses the transformation F → F prop (Lifschitz et al. 2019, Section 5) that converts every sentence over the signature σ (Section 2.3) into an infinitary formula over the set of precomputed atoms.The transformation is defined as follows: • p(t) prop is obtained from p(t) by replacing each member of t by its value; • (t 1 ≺ t 2 ) prop is ⊤ if the values of t 1 and t 2 are in the relation ≺, and ⊥ otherwise; for every binary connective ⊙; • (∀V F ) prop is the conjunction of the formulas (F V r ) prop over all precomputed terms r if V is generic, and over all numerals r if V is integer ; • (∃V F ) prop is the disjunction of the formulas (F V r ) prop over all precomputed terms r if V is generic, and over all numerals r if V is integer.
Lemma 2 (Harrison et al. 2017, Theorem 3).Two infinitary formulas are strongly equivalent to each other iff they are satisfied by the same HT-interpretations.
We extend the definition of F prop to sequents as follows: (Here Γ ∧ is the conjunction of all formulas in Γ; ∀ is the universal closure operation).
Lemma 3. If a sequent S can be derived from sequents S 1 , . . ., S k by one application of an inference rule of Int then every HT-interpretation satisfying (S 1 ) prop , . . ., (S k ) prop satisfies S prop .Lemma 4. For every axiom S of HTA, S prop is satisfied by all HT-interpretations.
To derive the theorem from the lemmas, we reason as follows.From Lemmas 3 and 4 we can conclude that if a sequent S can be derived from sequents S 1 , . . ., S k in HTA then every HT-interpretation satisfying (S 1 ) prop , . . ., (S k ) prop satisfies S prop .In particular, the assumption that τ * Π 1 and τ * Π 2 can be derived from each other in HTA implies that (τ * Π 1 ) prop and (τ * Π 2 ) prop are satisfied by the same HT-interpretations.By Lemma 2, it follows then that (τ * Π 1 ) prop is strongly equivalent to (τ * Π 2 ) prop .Then, by Lemma 1, Π 1 is strongly equivalent to Π 2 .
To complete the proof of the theorem, we need to prove Lemmas 3 and 4.

Proof of Lemma 3 (sketch)
We show here how to prove the assertion of the lemma for two of the inference rules of Int .One is implication elimination: prop (m ranges over integers).It is sufficient to show that for all r, n, if an HT-interpretation satisfies Since t is substitutable for N in F , formula ( 27) can be also written as This is the disjunctive term of ( 28) for which m is the value of t V,N r, n .

Proof of Lemma 4
For the axiom schemas F ⇒ F and t = t of Int , the assertion of the lemma is obvious.For axioms of Group A, it is verified in the same way as the validity of Hosoi axioms in the logic of here-and-there.
The images of the axioms of Groups B-D under the transformation F → F prop belong to the class of negative infinitary formulas, which is defined recursively: • H ∧ and H ∨ are negative if every formula in H is negative; Every negative tautological formula is satisfied by all HT-interpretations (Harrison et al. 2017, Theorem 1).Consequently we only need to check that the images of all axioms of Groups B-D are tautological.For Groups B and C, this property is obvious.For Group D, it is easy to check by induction that for any arithmetical sentence F , F prop is tautological if F is true in the domain of integers, and ¬F prop is tautological otherwise.

HTA Is Incomplete for Strong Equivalence
The sufficient conditions for strong equivalence of mini-gringo given by the theorem from Section 4 and its corollary are not necessary.Indeed, consider the program Π 1 consisting of the rules p(0), p(X + 1) ← p(X) and the program Π 2 , obtained from Π 1 by adding the rule p(X) ← X + 1 > 0. (29) These programs are strongly equivalent to each other.Indeed, the transformation τ (Lifschitz et al. 2019, Section 3) converts Π 1 into a set of formulas that contains p(0) and the implications p(n) → p(n + 1) for all integers n.Rule ( 29) is transformed by τ into the set consisting of (i) the formulas for all nonnegative integers n, and (ii) some implications with the antecedent ⊥. 3 It is clear that τ Π 2 can be derived from τ Π 1 in propositional intuitionistic logic.
We will show now that the formula which is obtained from rule (29) by applying the transformation ν, cannot be derived in HTA from the formulas p(0), ∀N (p(N ) → p(N + 1)), (32) which are obtained by applying ν to the rules of Π 1 .In fact, formula (31) cannot be derived from νΠ 1 even in the classical theory obtained from HTA by replacing the Hosoi axiom schema (Group A) by the law of the excluded middle.Call this classical first-order theory T .Let M be a model of T in which the integer universe is nonstandard, that is, has an element that does not correspond to a numeral.Since the sentence is an axiom of T , the integer universe of M has an element that does not correspond to a numeral and is nonnegative; call it α.Let M ′ be obtained from M by reinterpreting p so that the extent of p in M ′ is the set of objects represented by nonnegative numerals.Since p does not occur in any of the axioms B-D, M ′ is a model of T as well.It is clear that M ′ satisfies (32) but does not satisfy (31): α is a counterexample.

Future Work
The incompleteness of HTA as a tool for establishing strong equivalence of mini-gringo programs suggests one direction for future work: making HTA stronger.Adding an induction axiom schema that is not restricted to arithmetical formulas may allow us to handle the example of programs Π 1 , Π 2 from Section 6.Another possible addition to HTA is the axiom schema familiar from research on strong equivalence of logic programs with variables (Lifschitz et al. 2007, Section 3).Will these or similar additions make HTA complete for strong equivalence in mini-gringo?On the other hand, it is not clear how useful such additional axioms are going to be from the programmer's perspective.The stable model of Π 1 , Π 2 is infinite; these programs cannot be processed by grounders, such as gringo.Do there exist similar examples with finite stable models?
It would be perhaps more useful to extend the syntax of mini-gringo by aggregates, such as counting, which play an important role in the practice of answer set programming, and then extend the translations τ * and ν and the system HTA accordingly.