1 Introduction
One of the extensions of answer set programming (ASP; Lifschitz Reference Lifschitz1999) that is frequently demanded for practical applications is constraint ASP (CASP; Mellarkod et al. Reference Mellarkod, Gelfond and Zhang2008; Lierler Reference Lierler2023). Many domains require efficient numerical computations that exceed the capabilities of state-of-the-art ASP tools for combinatorial problem solving. These tools typically divide their computation into a grounding phase (removing variables by instantiation) and a solving phase (getting the answer sets of a propositional program). In this schema, numerical constraints are solved by considering all the possible instantiations of the involved numerical variables during the grounding phase. This strategy has a serious problem of scalability: a simple change of measurement in some quantity (e.g., moving from meters to centimeters) causes a blow-up in the grounding of the program that immediately leads to intractability. The basic idea of CASP is delegating numerical computation to a back-end constraint solver, following the spirit of Satisfiability Modulo Theory (SMT; Nieuwenhuis et al. Reference Nieuwenhuis, Oliveras and Tinelli2005). Thus, the ASP program is extended with constraint atoms that express the numerical restrictions associated with the problem at hand.
While this method mitigates grounding inefficiencies, it introduces a significant modeling challenge: the specification of constraint atoms often aligns more closely with the operational requirements of the numerical backend than with the standard ASP paradigm. Consequently, several high-level declarative features, such as default value declarations, undefined attributes, non-deterministic assignments via choice rules, and complex aggregates, are no longer directly accessible when these attributes are represented as constraint atoms. Just to put a simple example, consider the recent situation in which the default tariff for products from EU in the USA is fixed to 15%. This is a default that may have exceptions, such as the case of steel (with a tariff of 25%) or aircraft products, that are exempt. A possible representationFootnote 1 of this problem in clingo could look like:

where predicate
$\mathtt {sales(P,C,X)}$
reflects the total amount
$\mathtt {X}$
of sales of products from country (or market)
$\mathtt {C}$
of type
$\mathtt {P}$
. Moreover, suppose we want to collect the total income from taxes as follows:
If we decide to represent the tariff as a numerical constraint variable, default values are usually lost, since reasoning with constraint atoms is typically monotonic. Additionally, we cannot compute the tax income with an ASP aggregate, since the latter is defined in terms of logical variables which, in general, cannot retrieve computations from numerical constraints (otherwise, the grounding gain is lost). Finally, the ASP code above can easily accommodate lack of information: for instance, our database may contain a fact like sales(cars,us,30000) without having to define any tariff for the USA itself, or may include information about the tariff for Canadian cars tariff(cars,ca,25) without knowing the tariff for the rest of products from that country. Declaring tariffs as constraint variables tariff(steel,ca), tariff(food,ca), etc forces us to explicitly assign them numerical values.
One approach in the literature that allowed undefinedness and default values for constraint variables was the logic of Here-and-There with constraints (
$\textrm {HT}_{\!c}$
) proposed by Cabalar et al. (Reference Cabalar, Kaminski, Ostrowski and Schaub2016). In that work, a first prototype lc2casp was presented as a proof of concept, but was still far from extrapolating standard ASP representational features to constraints. Later on, another of those common ASP features, aggregates, was also incorporated into constraint atoms (Cabalar et al. Reference Cabalar, Fandinno, Schaub and Wanko2020a, Reference Cabalar, Fandinno, Schaub and Wankob) under a semantics based on
$\textrm {HT}_{\!c}$
, although a proper language definition and the corresponding tool implementation was still missing.
In this paper, we introduce the flingo system, a comprehensive extension of clingo that enables the specification of undefined variables, default values, non-deterministic choices, and aggregates within constraint atoms. These features are handled uniformly with respect to the standard ASP paradigm, maintaining a consistent modeling experience. We formalize the semantics of the flingo language in terms of
$\textrm {HT}_{\!c}$
, illustrate its application through various examples, and provide a translation into regular CASP programs following the clingcon input format (Banbara et al. Reference Banbara, Kaufmann, Ostrowski and Schaub2017).
The rest of the paper is organized as follows. The next section contains the background, including first an overview of
$\textrm {HT}_{\!c}$
, followed by a brief description of systems clingo and clingcon, on which flingo is based. Section 3 describes the flingo language, defining its input syntax, the associated semantics and some useful abbreviations. In Section 4, we provide details about the implementation of the flingo solver, which mainly relies on a translation into clingcon, used as a back-end. Finally, Section 5 summarizes our paper.
2 Background
2.1 The logic of here-and-there with constraints
The logic of Here-and-there with constraints (
$\textrm {HT}_{\!c}$
; Cabalar et al. Reference Cabalar, Kaminski, Ostrowski and Schaub2016) is an extension of the logic of Here-and-There (HT; Heyting Reference Heyting1930). Analogously to Equilibrium Logic (Pearce Reference Pearce1997), a model selection is defined on
$\textrm {HT}_{\!c}$
models, which provides the logical foundations for constraint satisfaction problems (CSPs) in the setting of ASP. In
$\textrm {HT}_{\!c}$
, a CSP is expressed as a triple
$\langle \mathcal{X},{\mathcal{D}},{\mathcal{C}} \rangle$
, also called signature, where
$\mathcal{X}$
is a set of variables over some non-empty domain
$\mathcal{D}$
, and
$\mathcal{C}$
is a set of constraint atoms. We assume a partition of the set of variables
$\mathcal{X}$
into two disjoint sets: propositional,
$\mathcal{X}^p$
, and non-propositional variables,
$\mathcal{X}^n$
. Similarly, the set of constraint atoms
$\mathcal{C}$
is also partitioned into two disjoint sets: propositional,
${\mathcal{C}}^p$
, and non-propositional atoms,
${\mathcal{C}}^n$
. The set of propositional atoms
${\mathcal{C}}^p$
contains a constraint atom
$\mathtt {p}$
for each propositional variable
$p\in \mathcal{X}^p$
, that is,
${\mathcal{C}} ^p = \{ \mathtt {p} \mid p \in \mathcal{X}^p\}$
. Note that we use different fonts to distinguish the propositional variable
$p$
from the propositional atom
$\mathtt {p}$
. We also assume that the domain
$\mathcal{D}$
contains the element
$\mathbf{t}$
, which is used to denote the truth value true of propositional variables. A propositional formula over
${\mathcal{C}}^p$
is defined by the grammar:
Non-propositional atoms can be arbitrary strings, in which we distinguish substrings called terms. Terms are divided into basic and conditional terms. We assume a set of basic terms
${\mathcal{T}}^b$
that contains all the variables, domain elements, and the special symbol
$\boldsymbol{u}$
, representing an undefined value. A conditional term is an expression of the form
where
$s_1$
and
$s_2$
are basic terms, and
$\varphi$
is a propositional formula. As an example,
is a non-propositional atom, where
$x$
is a variable,
$1$
and
$2$
are domain elements, and
$p$
and
$q$
are propositional variables. The variables, the domain elements and the string
$3*x$
are basic terms.
$({3*x|1}{\,:\,}p)$
and
$({2|x}{\,:\,}q)$
are conditional terms. Intuitively, the conditional term
$({3*x|1}{\,:\,}p)$
means that if
$p$
is true, then the value of the term is
$3*x$
, otherwise it is
$1$
. Similarly, the conditional term
$({2|x}{\,:\,}q)$
means that if
$q$
is true, then the value of the term is
$2$
, otherwise its value is
$x$
. The value of the two conditional terms is then added up (
$\mathtt {sum}$
) and compared to
$3$
.
A formula over
$\mathcal{C}$
is defined by the grammar:
Hence, all propositional formulas are also formulas. As usual, we define
$\top$
as
$\bot \to \bot$
,
$\neg \varphi$
as
$\varphi \to \bot$
, and let
$\varphi _1\leftrightarrow \varphi _2$
stand for
$(\varphi _1\to \varphi _2) \land (\varphi _2\to \varphi _1)$
. For every expression
$e$
, we let
$\mathit{vars}(e)$
denote the set of non-propositional variables occurring in
$e$
.
For the semantics, we start by defining an extended domain as
$\mathcal{D}_{\boldsymbol{u}} \stackrel {\scriptscriptstyle \mathrm{def}}{=} \mathcal{D} \cup \{\boldsymbol{u}\}$
. A valuation
$v$
over
$\mathcal{X},\mathcal{D}$
is a function
$v:\mathcal{X}\rightarrow \mathcal{D}_{\boldsymbol{u}}$
where
$v(x)=\boldsymbol{u}$
represents that variable
$x$
is left undefined. Moreover, if
$X \subseteq \mathcal{X}$
is a set of variables, valuation
$v|_X: X\rightarrow \mathcal{D}_{\boldsymbol{u}}$
stands for the projection of
$v$
on
$X$
. A valuation
$v$
can alternatively be seen as the set of pairs
$\{ (x \mapsto v(x)) \mid x \in \mathcal{X}, v(x)\in \mathcal{D}\}$
so that no pair in the set maps a variable to
$\boldsymbol{u}$
. This representation allows us to use standard set inclusion for comparison. We thus write
$v\subseteq v'$
to mean that
$v$
and
$v'$
agree on all variables defined by
$v$
, but
$v'$
may define additional variables. By
$\mathcal{V}$
we denote the set of valuations over
$\mathcal{X},{\mathcal{D}}$
.
A constraint atom or formula is basic if it does not contain conditional terms. By
${\mathcal{C}}^b$
we denote the set of basic constraint atoms. The semantics of basic constraint atoms is defined by a denotation
$[\![ \, \cdot \, ]\!] : {\mathcal{C}}^b \to 2^{\mathcal{V}}$
mapping each basic constraint atom
$c$
to the set of valuations satisfying
$c$
. For each propositional atom
$\mathtt {p} \in {\mathcal{C}}^p$
, we assume that its denotation satisfies
$ [\![ \, \mathtt {p} \, ]\!] \, \stackrel {\scriptscriptstyle \mathrm{def}}{=} \, \{ v \in \mathcal{V} \mid v(p) = \mathbf{t} \}$
. In
$\textrm {HT}_{\!c}$
, an ht-interpretation over
$\mathcal{X},{\mathcal{D}}$
is a pair
$\langle h,t \rangle$
of valuations over
$\mathcal{X},{\mathcal{D}}$
such that
$h\subseteq t$
.
Definition 1. Given a denotation
$[\![ \, \cdot \, ]\!]$
, an interpretation
$\langle h,t \rangle$
satisfies a formula
$\varphi$
, written
$\langle h,t \rangle \models \varphi$
, if
-
1.
$\langle h,t \rangle \models c \text{ if } h\in [\![ \, \mathit{eval}_{\langle h,t\rangle }(c) \, ]\!]$
-
2.
$\langle h,t\rangle \models \varphi \land \psi \text{ if } \langle h,t\rangle \models \varphi \text{ and } \langle h,t\rangle \models \psi$
-
3.
$\langle h,t\rangle \models \varphi \lor \psi \text{ if } \langle h,t\rangle \models \varphi \text{ or } \langle h,t\rangle \models \psi$
-
4.
$\langle h,t\rangle \models \varphi \rightarrow \psi \text{ if }\langle w,t\rangle \not \models \varphi \text{ or } \langle w,t\rangle \models \psi \text{ for all }w\in \{h,t\}$
where
$\mathit{eval}_{\langle h,t\rangle }(c)$
is the result of replacing each conditional term of the form
$({s_1|s_2}{\,:\,}\varphi )$
in
$c$
with
$\mathit{eval}_{\langle h,t\rangle }({s_1|s_2}{\,:\,}\varphi )$
, which is defined as follows:
\begin{align*} \mathit{eval}_{\langle h,t\rangle }({s_1|s_2}{\,:\,}\varphi ) \, &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \, \left \{ \begin{array}{ll} s_1 & \text{if } \langle h,t\rangle \models \varphi \\ s_2 & \text{if } \,\langle t,t\rangle \not \models \varphi \\ \boldsymbol{u} & \text{otherwise} \end{array} \right . \end{align*}
When
$\langle h,t \rangle \models \varphi$
holds, we say that
$\langle h,t \rangle$
is an ht-model of
$\varphi$
. We write
$t \models \varphi$
if
$\langle t,t \rangle \models \varphi$
, and we say that
$t$
is a model of
$\varphi$
. A (ht-)model of a set
$\Gamma$
of formulas is a (ht-)model of all formulas in
$\Gamma$
. A model
$t$
of a set
$\Gamma$
is a stable model of
$\Gamma$
if there is no
$h \subset t$
such that
$\langle h,t \rangle \models \Gamma$
.
2.2 ASP system clingo and CASP system clingcon
Clingo (Gebser et al. Reference Gebser, Kaminski, Kaufmann, Ostrowski, Schaub and Wanko2016) is an ASP system that provides a powerful interface for integrating external theories. It allows us to extend the basic ASP solver with new theory atoms by providing a theory grammar defining their syntax and an implementation of their semantics via so-called theory propagators. The CASP system clingcon (Banbara et al. Reference Banbara, Kaufmann, Ostrowski and Schaub2017) uses this clingo interface to enrich the ASP language with linear constraint atoms over integers of the form
where each
$k_i$
is an integer, each
$x_i$
is a (non-propositional) integer variable, and
$\prec$
is one of the relations
$\mathtt {\lt =}, \mathtt {=}, \mathtt {!=}, \mathtt {\lt }, \mathtt {\gt }, \mathtt {\gt =}$
Recently, it has been shown that the semantics of many of the systems built using clingo’s theory interface, including clingcon, can be nicely described in terms of
$\textrm {HT}_{\!c}$
by associating a denotation with each theory atom (Cabalar et al. Reference Cabalar, Fandinno, Schaub and Wanko2025). Clingcon assumes a finiteFootnote
2
domain of integers
$\mathbb{Z}_{\mathit{cl}} \subseteq \mathbb{Z}$
with a minimum,
$\mathit{min}_{\mathit{cl}}$
, and a maximum value,
$\mathit{max}_{\mathit{cl}}$
. Consequently, the
$\textrm {HT}_{\!c}$
domain to capture clingcon’s semantics is
${\mathcal{D}}_{\!\mathit{cl}} = \mathbb{Z}_{\mathit{cl}} \cup \{\mathbf{t}\}$
. The set of all valuations with domain
${\mathcal{D}}_{\!\mathit{cl}}$
is given by
$\mathcal{V}_{\!\mathit{cl}}$
. With it, the denotation of atom (5) is defined as follows:
Let us now recall the syntax of clingcon programs (Banbara et al. Reference Banbara, Kaufmann, Ostrowski and Schaub2017). A clingcon atom is either a propositional atom or a constraint atom of form (5). A clingcon literal is any clingcon atom
$a$
or its single or double negation,
${\mathtt {not}}\ a$
or
${\mathtt {not}}\ {\mathtt {not}}\ a$
, respectively. A clingcon rule is an expression of the form
where
$a$
is a clingcon atom or the symbol
$\bot$
denoting falsity, and each
$l_i$
is a clingcon literal. An expression of the form
where
$\mathtt {p}$
is a propositional atom, is called a choice rule, and it is an abbreviation for the rule ‘
$ \mathtt {p} \, \mathtt {:-} \, l_1, \ldots , l_n,\, {\mathtt {not}}\,{\mathtt {not}}\, \mathtt {p}$
’. Moreover, clingcon accepts all the constructs of clingo, including disjunctive rules, aggregates, and weak constraints.
We define the semantics of clingcon programs via a translation
$\tau$
into
$\textrm {HT}_{\!c}$
. For each clingcon literal
$l$
, we denote by
$\tau l$
the corresponding
$\textrm {HT}_{\!c}$
literal, that is,
$\tau ({\mathtt {not}}\ {\mathtt {not}}\ a) \stackrel {\scriptscriptstyle \mathrm{def}}{=} \neg \neg a$
,
$\tau ({\mathtt {not}}\ a) = \neg a$
, and
$\tau a \stackrel {\scriptscriptstyle \mathrm{def}}{=} a$
for any atom
$a$
. For each rule
$r$
of form (7), we denote by
$\tau r$
the formula
Furthermore, we need to introduce new constraints in
$\textrm {HT}_{\!c}$
, which are not available in clingcon. These constraint atoms are of the form
$\mathtt {\&df}(x)$
and
$\mathtt {\&int}(x)$
, where
$x$
is a variable. These atoms are associated with the following denotations:
\begin{align*} [\![ \, \mathtt {\&df}(x) \, ]\!] &\ \stackrel {\scriptscriptstyle \mathrm{def}}{=} \, \{ v \in \mathcal{V}_{\!\mathit{cl}} \mid v(x)\neq \boldsymbol{u} \} \\ [\![ \, \mathtt {\&int}(x) \, ]\!] &\ \stackrel {\scriptscriptstyle \mathrm{def}}{=} \, \{ v \in \mathcal{V}_{\!\mathit{cl}} \mid v(x) \in \mathbb{Z}_{\mathit{cl}} \} \end{align*}
For a set
$P$
of clingcon rules, we define
$\mathit{cl}(P)$
as the set of
$\textrm {HT}_{\!c}$
formulas containing formula
$\tau r$
for each rule
$r \in P$
as well as formulas of the form
Formulas (10) and (11) ensure that variables only take their intended values: propositional variables are either undefined or take the value
$\mathbf{t}$
, while integer variables are always defined and can take any integer value. There is a one-to-one correspondence between the stable models of a clingcon program
$P$
and the stable models of the
$\textrm {HT}_{\!c}$
theory
$\mathit{cl}(P)$
as shown in (Cabalar et al. Reference Cabalar, Fandinno, Schaub and Wanko2025, Theorem 4).
3 The flingo language
Flingo is a CASP system that, much like clingcon, enriches the ASP language with integer constraint atoms. The main feature of flingo is that the values assigned to integer variables need to be founded. Recall that in ASP, propositional atoms are false by default and true propositional atoms need to be founded (Van Gelder et al. Reference Van Gelder, Ross and Schlipf1991), that is, derived from the facts via the rules of the program. Analogously, in flingo, integer variables are undefined by default and any defined integer variable needs to occur in a founded constraint atom. This behavior is inspired by
$\textrm {HT}_{\!c}$
and is significantly different from other existing CASP solvers. As an example, consider the programFootnote
3
which has exactly two stable models in flingo: one where
$\mathtt {a}$
is false and
$x$
is undefined, and another where
$\mathtt {a}$
is true and
$x$
is assigned the value
$1$
. Both of these are also clingcon stable models, but clingcon has infinitely many stable models where
$\mathtt {a}$
is false and
$x$
is assigned any integer. The second distinct feature of flingo is its support of aggregates over integer variables, something that is not supported by other existing CASP solvers.
3.1 Syntax
As mentioned above, flingo supports an enriched syntax compared to clingcon. We start by describing flingo’s conditional terms, which are inspired by aggregate elements in ASP and conditional terms in
$\textrm {HT}_{\!c}$
. A product term is either an integer, an integer variable, or an expression of the form
$n * x$
where
$n$
is an integer and
$x$
is an integer variable. In flingo, a conditional term is an expression of the form
where
$s$
is a product term and
$l_1, \ldots , l_n$
is a comma separated list of propositional literals. There are two main differences with respect to conditional terms in
$\textrm {HT}_{\!c}$
. First, the condition is restricted to be a conjunction of propositional literals instead of an arbitrary propositional formula, as common in ASP. Second, conditional terms have no alternative term in flingo. The term
$s$
is the one considered when the condition
$l_1, \ldots , l_n$
is satisfied, otherwise a default term is used. This default term is context-dependent and discussed below with the semantics of flingo. With these changes, we bring
$\textrm {HT}_{\!c}$
conditional terms closer to the usual logic programming syntax for aggregates.
A flingo term is either a product term or a flingo conditional term. The language of flingo supports the following constraint atoms:
where each
$t_i$
is a flingo term,
$s$
is a product term,
$x$
is an integer variable, and
$\prec$
is one of the following relations
$\mathtt {\lt =}, \mathtt {=}, \mathtt {!=}, \mathtt {\lt }, \mathtt {\gt }, \mathtt {\gt =}$
. The operation
$\mathtt {sus}$
stands for strict sum (more precisely,
$\mathtt {sus}$
stands for su
m s
trict), while
$\mathtt {sum}$
is its non-strict version, similar to the one used in ASP. Intuitively, the non-strict version of sum discards undefined variables, while the strict does not. If any variable is undefined, the constraint atom with strict sum is false. As an example, consider the valuation
$v = \{ x_1 \mapsto 1 \}$
and the constraint atoms
In this valuation, variable
$x_2$
is undefined. Atom (18) is satisfied by valuation
$v$
because
$v(x_1) = 1 \leq 3$
, while
$x_2$
is undefined and thus discarded from the sum. In contrast, atom (19) is not satisfied simply because
$x_2$
is undefined. Operation
$\mathtt {min}$
always work in a non-strict way: for instance,
$\mathtt {min}$
always returns the minimum value among the defined terms in the set.
A flingo atom is either a propositional atom or a constraint atom of the forms (14–17). A flingo literal is any flingo atom
$a$
or its single or double default negation,
${\mathtt {not}}\ a$
or
${\mathtt {not}}\ {\mathtt {not}}\ a$
, respectively. A flingo rule is an expression of the form
where
$a$
is a flingo atom or the symbol
$\bot$
denoting falsity, and each
$l_i$
is a flingo literal. Note that, syntactically, every clingcon rule is also a flingo rule.
3.2 Semantics
The semantics of flingo is defined using
$\textrm {HT}_{\!c}$
similar to clingcon but it uses a different denotation for constraint atoms, and a slightly different translation.
We start by defining a neutral element for each constraint atom operation
Both sum operations use
$0$
as their neutral element, while
$\mathtt {max}$
and
$\mathtt {min}$
use the minimum and maximum elements of the integer domain, respectively. We define the denotation of the basic constraint atoms as follows:
\begin{align*} [\![ \, {\mathtt {\&sum}}\{t_1 ; \ldots ; t_n \} \prec s \, ]\!] &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \big \{ v \in \mathcal{V}_{\!\mathit{cl}} \mid v^{\mathtt {sum}}(t_i) \in \mathbb{Z}\text{ for } 1\leq i \leq n , \textstyle \sum _{1\leq i \leq n} v^{\mathtt {sum}}(t_i) \prec v(s) \big \} \\ [\![ \, {\mathtt {\&sus}}\{t_1 ; \ldots ; t_n \} \prec s \, ]\!] &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \big \{ v \in \mathcal{V}_{\!\mathit{cl}} \mid v(t_i) \in \mathbb{Z}\text{ for } 1\leq i \leq n , \textstyle \sum _{1\leq i \leq n} v(t_i) \prec v(s) \big \} \\ [\![ \, {\mathtt {\&min}}\{t_1 ; \ldots ; t_n \} \prec s \, ]\!] &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \big \{ v \in \mathcal{V}_{\!\mathit{cl}} \mid \textstyle \min _{1 \leq i \leq n} v^{\mathtt {min}}(t_i) \prec v(s) \big \} \\ [\![ \, {\mathtt {\&df}}(x) \, ]\!] &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \big \{ v \in \mathcal{V}_{\!\mathit{cl}} \mid v(x)\neq \boldsymbol{u} \big \} \end{align*}
where
\begin{align*} v(n) &\stackrel {\scriptscriptstyle \mathrm{def}}{=} n &\hspace {5pt} v(n * x) &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \begin{cases} n * v(x) &\text{if } v(x) \in \mathbb{Z} \\ \boldsymbol{u} &\text{otherwise} \end{cases} &\hspace {5pt} v^{\mathit{fun}}(t) &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \begin{cases} v(t) &\text{if } v(t) \in \mathbb{Z} \\ 0^{\mathit{fun}} &\text{otherwise} \end{cases} \end{align*}
The denotation of
$\mathtt {\&sus}$
requires all its terms to be defined, following the intuition of strict sum described above. In contrast, the denotation of
$\mathtt {\&sum}$
uses the neutral element
$0^{\mathtt {sum}} = 0$
to evaluate undefined terms. This has the same effect as discarding undefined terms from the sum, as done in ASP. We can now explain the difference between
$\mathtt {\&sus}$
and
$\mathtt {\&sum}$
in formal terms. Let us reconsider constraint atoms (18) and (19). On the one hand, we have
$v^{\mathtt {sum}}(x_1) = v(x_1) = 1$
but
$v^{\mathtt {sum}}(x_2) = 0$
because
$v(x_2)$
is undefined. Hence, for atom (18), we have
$1 + 0 \leq 3$
, and thus
$v \in [\![ \, \mathtt {sum}\{x_1 ; x_2\} \,\mathtt {\lt =}\, 3 \, ]\!]$
. In contrast, for atom (19), we get
$v(x_2) \notin \mathbb{Z}$
and, thus, we immediately have
$v \notin [\![ \, \mathtt {sus}\{x_1 ; x_2\} \,\mathtt {\lt =}\, 3 \, ]\!]$
. As mentioned above,
$\mathtt {min}$
always behaves in a non-strict way, and accordingly, their denotations use their neutral elements to evaluate undefined terms.
${\mathtt {\&df}}(x)$
expresses that the variable
$x$
is defined.
We now define the translation of flingo programs into sets of formulas in
$\textrm {HT}_{\!c}$
. Recall that flingo constraint atoms have conditional terms of the form
$s : l_1, \ldots , l_n$
, which do not have the syntactic form of
$\textrm {HT}_{\!c}$
conditional terms. Hence, the translation of flingo programs into
$\textrm {HT}_{\!c}$
needs to replace flingo conditional terms with
$\textrm {HT}_{\!c}$
conditional terms. This translation is context-sensitive, as it is determined by the specific constraint atom containing the conditional term. Hence, for each flingo term
$t$
, we define a corresponding term
$[t]^{\mathit{fun}}$
in
$\textrm {HT}_{\!c}$
where
$\mathit{fun}$
is one of the functions
$\mathtt {sum}$
,
$\mathtt {sus}$
,
$\mathtt {max}$
, or
$\mathtt {min}$
. This translation is defined as follows:
\begin{align*} [t]^{\mathit{fun}} \, &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \, t &&\text{if } t \text{ is a product term } \\ [t]^{\mathit{fun}} \, &\stackrel {\scriptscriptstyle \mathrm{def}}{=} \, ({s\,|\,0^{\mathit{fun}}\,}{\,:\,}\,\tau l_1 \land \ldots \land \tau l_n) &&\text{if } t \text{ is of the form } s : l_1, \ldots , l_n \end{align*}
Whenever the condition is false, each term is evaluated to the corresponding neutral element of the function. Next, we define the translation
$\mu$
of flingo atoms into
$\textrm {HT}_{\!c}$
atoms. For each atom
$c$
that is propositional or of the form
${\mathtt {\&df}}\{x\}$
, its translation
$\mu c$
is just
$c$
itself. For any flingo constraint atom
$c$
of the form &
$\mathit{fun}\{t_1 ; \ldots ; t_n\} \prec s$
with
$\mathit{fun}$
among
$\{\mathtt {sum},\, \mathtt {sus},\, \mathtt {max},\, \mathtt {min}\}$
, we define
$\mu c$
as
The following proposition shows that
$\mathtt {sum}$
and
$\mathtt {sus}$
only differ when they contain undefined integer variables, that is, they are equivalent when all their integer variables are defined.
Proposition 1. Let
$c_1$
and
$c_2$
stand for the flingo constraint atoms
and let
$\langle h,t \rangle$
be an ht-interpretation satisfying
$\mathtt {\&int}(x)$
for each integer variable
$x$
in
$\mathit{vars}(c_1)$
and
$\mathit{vars}(c_2)$
. Then,
$\langle h,t \rangle \models \mu c_1$
if and only if
$\langle h,t \rangle \models \mu c_2$
.
We extend the translation
$\mu$
to flingo literals in the usual way, that is,
$\mu \, {\mathtt {not}}\ c$
is
$\neg \mu c$
, and
$\mu \, {\mathtt {not}}\ {\mathtt {not}}\ c$
is
$\neg \neg \mu c$
. Finally, we extend the translation
$\mu$
to flingo rules (20) as
For a set
$P$
of flingo rules, we define
${\mathit{fl}}(P)$
as the set of
$\textrm {HT}_{\!c}$
formulas containing formula
$\mu r$
for each rule
$r \in P$
as well as formulas of the form
Formulas (10) and (23) ensure that variables only take their intended values: propositional variables are either undefined or take the value
$\mathbf{t}$
, while integer variables must take an integer value when defined. The formulas for propositional variables in (10) are the same as in clingcon, while the ones for integer variables in (23) are weaker than in (11), which ensures that integer variables are assigned integer values when defined, but crucially they remain undefined otherwise. Recall that in clingcon, the formulas in (11) ensure that integer variables are always defined.
Syntactically, every clingcon program
$P$
is a flingo program and, thus, we can also interpret it as a flingo program by using the corresponding translation
${\mathit{fl}}(P)$
. Furthermore, every clingcon atom
$c$
has no conditional terms, and, thus,
$\mu c$
is just
$c$
itself. Hence, for a clingcon program
$P$
, there are two differences between
${\mathit{fl}}(P)$
and
$\mathit{cl}(P)$
: the denotation of
$\mathtt {\&sum}$
atoms and that the latter uses the formulas in (11) for integer variables, while the former uses the ones in (23).
While the denotation of
$\mathtt {\&sum}$
atoms in clingcon coincides with that of
$\mathtt {\&sus}$
atoms in flingo, we maintain a deliberate syntactic distinction. This choice is driven by our goal to align flingo as closely as possible with standard ASP aggregate conventions. In particular, since standard ASP aggregates adhere to non-strict semantics, flingo adopts a notation that reflects this established behavior. For instance, the flingo program
has a single stable model in which
$\mathtt {a}$
and
$\mathtt {p}$
are true and
$\mathtt {x}$
is undefined. However, if we replace
$\mathtt {\&sum}$
with
$\mathtt {\&sus}$
, the resulting program leaves
$\mathtt {a}$
undefined. This program can be rewritten in ASP using the aggregate
$\mathtt {\#sum}$
as follows:
The unique stable model of this program is
$\{ \mathtt {a},\mathtt {p} \}$
(as all instances of
$\mathtt {val(X)}$
are false).
To illustrate the use of strict versus non-strict sums for knowledge representation, we revisit next our running example about tariffs from the introduction. A possible representation of the example in flingo could be:

Notice how the rule for expressing the default value (lines 2–3) uses
$\mathtt {\&sus}$
in the body to check that
$\mathtt {tariff(P,eu)}$
does not have some specific value different from 15. If we used
$\mathtt {\&sum}$
instead, an undefined tariff would count as
$0^{\mathtt {sum}}=0$
in the sum, and this is always different from 15, so the rule would not be applied, leaving the tariff undefined. Notice, however, that in the computation of the
$\mathtt {taxincome}$
(line 6), it is more convenient to use
$\mathtt {\&sum}$
rather than
$\mathtt {\&sus}$
. This is because we might have facts like
$\mathtt {sales(food,ca,10000)}$
without having defined a tariff for Canadian food in the database. By using
$\mathtt {\&sum}$
, an undefined tariff in the aggregate just counts as 0 in the total sum (as would also happen in our standard ASP representation of the problem without constraints).
The following proposition shows the relation between the ht-models and stable models of
$\mathit{cl}(P)$
and
${\mathit{fl}}(P^*)$
where
$P^*$
is the result of replacing each occurrence of
$\mathtt {\&sum}$
with
$\mathtt {\&sus}$
in a clingcon program
$P$
.
Proposition 2. Let
$P$
be a clingcon program and
$P^*$
be the result of replacing each occurrence of
$\mathtt {\&sum}$
with
$\mathtt {\&sus}$
in
$P$
. Then,
-
(a) every ht-model of
$\mathit{cl}(P)$
is also an ht-model of
${\mathit{fl}}(P^*)$
; and -
(b) every stable model of
${\mathit{fl}}(P^*)$
without undefined integer variables is also a stable model of
$\mathit{cl}(P)$
.
The relationship between flingo and clingcon described in Proposition2(b) parallels the one between stable and classical models, with the caveat that we must restrict our focus to stable models devoid of undefined integer variables. Just as every stable model is a classical model, though not vice versa, the presence of undefined variables in flingo allows for stable models that lack a counterpart in clingcon. To illustrate, consider the clingcon program
$\{\mathtt {a} \, \mathtt {:-} \, {\mathtt {\&sum}}\{x \} = x\}$
versus the corresponding flingo program
$\{\mathtt {a} \, \mathtt {:-} \, {\mathtt {\&sus}}\{x \} = x\}$
. The former yields infinitely many stable models where
$\mathtt {a}$
is true and
$x$
is assigned an arbitrary integer. In contrast, the flingo program results in a unique stable model where
$\mathtt {a}$
is false and
$x$
remains undefined.
Continuing with the analogy between stable and classical models, in the latter, we can capture all models of a propositional theory by adding choice rules for each propositional variable. Similarly, we can capture all stable models of a clingcon program by adding facts of the form
${\mathtt {\&sum}}\{x\} = x$
(aka
$x=x$
) for each integer variable
$x$
. These facts act as a kind of choice rule for integer variables, allowing them to pick any value.
Proposition 3. Let
$P$
be a clingcon program and let
$F$
be the set of facts consisting of
${\mathtt {\&sum}}\{x\} = x$
for each integer variable
$x \in \mathcal{X}^n$
.
Then, the set of ht- and stable models of
$\mathit{cl}(P)$
,
${\mathit{fl}}(P^*\cup F)$
, and
${\mathit{fl}}(P \cup F)$
coincide.
We can further push this analogy by showing that flingo allows a form of non-monotonic reasoning for integer variables that is impossible in clingcon. Note that clingcon is not monotonic in the sense of propositional logic because it is an extension of the stable model semantics. Thus, we can just write a program containing propositional rules that is non-monotonic. However, we can show its non-monotonicity comes only from the propositional part of the program, while the integer part is monotonic.
Proposition 4. Let
$P$
and
$F$
be two clingcon programs such that
$F$
has no propositional variables. Then, every stable model of
$\mathit{cl}(P\cup F)$
is also a stable model of
$\mathit{cl}(P)$
.
The language of flingo is not monotonic in the sense of Proposition4. For instance, consider the program consisting of the single rule
$\mathtt {x}= 1 \, \mathtt {:-} \, {\mathtt {\&sus}}\{ \mathtt {y} \} = 1$
, whose unique stable model leaves both
$x$
and
$y$
undefined. If we add the fact
${\mathtt {\&sus}}\{ \mathtt {y} \} = 1$
, which does not contain propositional variables, then the resulting program’s unique stable model assigns
$1$
to both
$x$
and
$y$
.
In addition to the basic constraint atoms defined above, flingo also supports
$\mathtt {\&max}$
constraint atoms of the form
${\mathtt {\&max}}\{t_1 ; \ldots ; t_n\} \prec s$
, which are syntactic sugar for
${\mathtt {\&min}}\{-t_1 ; \ldots ; -t_n\} \succ -s$
where
$\succ$
is the dual operator of
$\prec$
defined as follows:
\begin{align*} \succ \, &\text{ is } \, \begin{cases} \, \mathtt {\gt =} &\text{if } \prec \text{ is } \mathtt {\lt =} \\[-1ex] \, \mathtt {\lt =} &\text{if } \prec \text{ is } \mathtt {\gt =} \\[-1ex] \, \mathtt {\gt } &\text{if } \prec \text{ is } \mathtt {\lt } \\[-1ex] \, \mathtt {\lt } &\text{if } \prec \text{ is } \mathtt {\gt } \\[-1ex] \, \prec &\text{otherwise } \end{cases} \end{align*}
A common pattern in flingo programs is to allow integer variables to take values within a given range. This can be expressed using choice rules for integer variables of the form
where
$s_1$
and
$s_2$
are product terms,
$x$
is an integer variable and
$l_1, \ldots , l_m$
are flingo literals. Formally, a choice rule as in (24) is an abbreviation for the rules
where
$x_1, \ldots , x_k$
are all the integer variables occurring in
$s_1$
and
$s_2$
.
Besides this syntactic sugar, flingo also supports another common pattern for defining and constraining integer variables that work on the rule level. This pattern consists on defining a variable in terms of other variables. Constraint atoms (14–17) do not make any difference between the variables occurring on them. Assignment rules allow us to naturally express this pattern. An assignment rule is an expression of the formFootnote 4
where each
$t_i$
is a flingo term,
$s$
is a product term,
$\mathit{fun}$
is one of the operations
$\mathtt {sum}$
,
$\mathtt {sus}$
,
$\mathtt {max}$
, or
$\mathtt {min}$
, and each
$l_i$
is a flingo literal. Such rules only define the variables in
$s$
, so that the constraint atom obtained by replacing the assignment operator
$\mathtt {=:}$
with equality
$\mathtt {=}$
is satisfied. However, it does not define any variables in
$t_1, \ldots , t_n$
. For instance, the assignment rule
$\mathtt {{\mathtt {\&sus}}\{x ; y\} \mathtt {=:}\ z}$
ensures that
$z$
is defined as the sum of
$x$
and
$y$
, whenever both
$x$
and
$y$
are defined. However, if
$x$
or
$y$
are undefined, then the rule has no effect on the value assigned to
$z$
. So, if we add facts
$\mathtt {x = 1}$
and
$\mathtt {y = 2}$
to the above assignment, then the resulting program has a single stable model where
$x$
,
$y$
, and
$z$
are assigned
$1$
,
$2$
, and
$3$
, respectively. If instead, we add only the fact
$\mathtt {x = 1}$
, then the resulting program has a single stable model where
$x$
is assigned
$1$
, while
$y$
and
$z$
are undefined. And if we add instead the facts
$\mathtt {x = 1}$
and
$\mathtt {z = 5}$
, then the resulting program has a single stable model where
$x$
and
$z$
are assigned
$1$
and
$5$
, respectively, while
$y$
is undefined.
Formally, an assignment rule as in (27) where each
$t_i$
is a product term is an abbreviation for the rule:
where
$x_1, \ldots , x_k$
are all the integer variables occurring in
$t_1,\dotsc , t_n$
. When some
$t_i$
is a conditional term, conditions are first removed as explained in the next section.
4 The flingo system
We have implemented a new system called flingo as an extension of clingo (Gebser et al. Reference Gebser, Kaminski, Kaufmann, Ostrowski, Schaub and Wanko2016) with the integer constraint atoms as described in Section 3. The syntax uses clingo theory atoms starting with ‘&’ to denote integer constraint atoms, and grounding of logic program variables is handled using clingo’s native capabilities. Logic program variables are different from integer variables. Such variables start with a lowercase letter and can only occur inside integer constraint atoms. As usual in ASP, logic program variables start with an uppercase letter and can be used anywhere in the program. Logic program variables are grounded before the solving process starts, while integer constraint variables are handled during solving. Flingo uses clingcon as backend for handling integer constraints during solving. A grounded flingo program is translated into a clingcon program by a series of rewriting transformations detailed below. These transformations are based on ideas to compile away aggregates with constraints (Cabalar et al. Reference Cabalar, Fandinno, Schaub and Wanko2020a) and to compile integer constraints allowing undefined integer variables into standard integer constraints (Cabalar et al. Reference Cabalar, Kaminski, Ostrowski and Schaub2016), but adapted to the richer setting of flingo.
Our transformation consists of eight steps. The first step is to replace in the scope of a constraint atom whose operation is not
$\mathtt {\&sus}$
, each conditional term of the form
$s : l_1, \ldots , l_m$
by
where
$x_1, \ldots , x_k$
are all the integer variables occurring in
$s$
. Similarly, a product term
$s$
is replaced by the conditional term
$s : {\mathtt {\&df}}(x_1), \dotsc , {\mathtt {\&df}}(x_k)$
. After that, all occurrences of
$\mathtt {\&sum}$
atoms are replaced by
$\mathtt {\&sus}$
atoms.
The second step consists of replacing all conditional terms of the form (13) by conditional terms of the form
$s : a$
where
$a$
is a propositional atom. This is done by introducing fresh propositional atoms
$a$
to represent the condition and adding rule
$a \,$
:-
$ \, l_1, \ldots , l_m$
to define this fresh atom.
The third step consists of removing conditions in constraint atoms. We replace each conditional constraint term of the form
$s : a$
by a fresh integer variable
$y$
, and we add rules
\begin{align*} {\mathtt {\&sus}}\{s\} = y \, &\mathtt {:-} \, a,\, {\mathtt {\&df}}(x_{1}), \dotsc , {\mathtt {\&df}}(x_{k}) \\ {\mathtt {\&sus}}\{s\} = y \, &\mathtt {:-} \, a,\, {\mathtt {\&df}}(y) \\ {\mathtt {\&sus}}\{ 0^{\mathit{fun}}\} = y \, &\mathtt {:-} \, \mathtt {not}\text{ } a \\ \{a\} \, &\mathtt {:-} \, {\mathtt {\&df}}(y) \end{align*}
where
$x_{1},\dotsc ,x_{k}$
are all integer variables in
$s$
, and
$0^{\mathit{fun}}$
depends on the operation
$\mathit{fun}$
where the conditional constraint term occurs as described in Section 3.
The fourth step is to rewrite all abbreviations described in the previous section: assignment and choice rules, and all occurrences of
$\mathtt {max}$
constraint atoms.
The fifth step is to replace each constraint atom of the form
$\mathtt {\&}\mathit{fun}\{s_1 ; \ldots ; s_n \} \prec s$
by a fresh propositional atom
$\mathtt {\&}\mathit{fun}(\mathit{hb})\{s_1 ; \ldots ; s_n \} \prec s$
where
$\mathit{hb}$
is either
$\mathtt {head}$
or
$\mathtt {body}$
depending on whether the atom occurs in the head or the body, respectively. Clingcon only recognizes constraint atoms whose operation is
$\mathtt {\&sum}$
, thus these atoms with operation
$\mathtt {\&}\mathit{fun}(hb)$
are treated as regular propositional atoms by clingcon. We add later rules that relate the value of the fresh propositional atoms and the integer variables.
The sixth step is to define
$\mathtt {\&min}$
atoms in terms of
$\mathtt {\&sus}$
atoms as follows. For every constraint atom of the form
${\mathtt {\&min}}(hb)\{s_1 ; \ldots ; s_n\} \prec s$
, we add the rule
where
$m$
is a fresh integer variable representing the minimum of
$s_1,\dotsc ,s_n$
, and
$\mathit{def}$
and
$\mathit{member}$
are fresh propositional atoms defined by the following rules for each
$i=1,\dotsc ,n$
:
\begin{align*} &\mathit{def} \, \mathtt {:-} \, {\mathtt {\&df}}(x_{i_1}), \dotsc , {\mathtt {\&df}}(x_{i_k}) \\ &{\mathtt {\&df}}\{m\} \, \mathtt {:-} \, \mathit{def} \\ &\mathtt {:-} \, {\mathtt {\&sus}}(\mathtt {body})\{ s_i \} \, \mathtt { \lt } \, m \\ &\mathit{member} \, \mathtt {:-} \, {\mathtt {\&sus}}(\mathtt {body})\{ s_i \} \, \mathtt { =} \, m \end{align*}
with
$x_{i_1},\dotsc ,x_{i_k}$
are all integer variables occurring in
$s_i$
. In addition, if
$hb$
is
$\mathtt {head}$
, we add the rule
while if
$hb$
is
$\mathtt {body}$
, we add the rule
In the seventh step, we relate the fresh propositional atoms introduced in step five with the integer variables. For every integer variable
$x$
occurring in the program, we add
This rule ensures that undefined integer variables are assigned a unique value and, thus, avoids multiple stable models that only differ in the value assigned to undefined integer variables. For every constraint atom
${\mathtt {\&sus}}(\mathtt {head})\{s_1 ; \ldots ; s_n\} \prec s$
, we add the rules
\begin{align*} &\mathtt {:-} \, {\mathtt {\&sus}}(\mathtt {head})\{s_1 ; \ldots ; s_n\} \prec s, \, \mathtt {not }\text{ } {\mathtt {\&sum}}\{s_1 ; \ldots ; s_n\} \prec s \\ &\mathit{aux} \, \mathtt {:-} \, {\mathtt {\&sus}}(\mathtt {head})\{s_1 ; \ldots ; s_n\} \prec s \\ &{\mathtt {\&df}}(x_1) \, \mathtt {:-} \, \mathit{aux} \qquad \qquad \ldots \qquad \qquad {\mathtt {\&df}}(x_k) \, \mathtt {:-} \, \mathit{aux} \end{align*}
where
$x_1,\dotsc ,x_k$
are all integer variables occurring in
$s_1,\dotsc ,s_n, s$
, and
$\textit {aux}$
is a fresh propositional atom. For every constraint atom of the form
${\mathtt {\&sus}}($
body
$)\{s_1 ; \ldots ; s_n\} \prec s$
, we add the rule
where
$x_1,\dotsc ,x_k$
are all integer variables occurring in
$s_1,\dotsc ,s_n,s$
.
The final step replaces each atom of the form
${\mathtt {\&df}}(x)$
by a new propositional atom
$\mathtt {def(x)}$
, so clingcon does not assume these atoms to be in the scope of a choice rule.
Every step of this transformation is feasible in linear time with respect to the size of the program. Thus, the overall transformation is linear as well.
Flingo supports the same useful modeling features for the ASP methodology as clingo, such as choice rules, defaults, and aggregates, now lifted to linear integer arithmetic. In Listing 1, we show a flingo program that models the configuration of a bike that consists of a frame and an optional bag, and the calculation of the total price.

Listing 1. Bike configuration with flingo
Lines 1 and 2 define the problem instance. Lines 3-6 provide the general problem encoding. Line 3 defines the price of a selected component as the one in the instance, when provided. Lines 4-5 define the price of a selected component using the default range defined in the instance: unless the price is provably outside the default range, the price of a selected component is defined by the default range. Finally, Line 6 defines the total price as the sum of the prices of the selected components. This example illustrates how flingo allows for a natural encoding of configuration problems with numeric attributes, where defaults, choices, and aggregates are common modeling features. Flingo has been used to model and solve configuration problems formulated in the Coom configuration language (Baumeister et al. Reference Baumeister, Hahn, Herud, Ostrowski, Reutelshoefer, Rühling, Schaub and Wanko2026), where the empirical evaluation demonstrates its effectiveness in solving configuration problems with numeric attributes featuring large domains, where it significantly outperforms clingo.
5 Discussion
We have introduced flingo, a novel CASP system designed to bridge the gap between high-level ASP modeling and the operational requirements of numeric constraint solving.
Our contributions can be summarized as follows: (i) We presented a logic programming language that integrates default values, choice rules, and aggregates directly into constraint atoms. This preserves the standard ASP “look and feel” while leveraging the power of numeric backends. (ii) We defined the semantics of flingo, distinguishing between strict (
$\mathtt {\&sus}$
) and non-strict (
$\mathtt {\&sum}$
) operations to accommodate both traditional CASP behavior and ASP-style aggregates. (iii) We developed a translation from flingo to clingcon, combining the effectiveness of state-of-the-art CASP solvers with ASP declarativeness.
Lierler (Reference Lierler2023) analyzes an extensive list of CASP systems from the literature, including the already mentioned clingcon. None of these systems described there allows for leaving constraint variables undefined, representing default values, or the use of aggregates involving both constraints variables and arbitrary conditions. Perhaps the closest system to flingo regarding these features is clingo{f}Footnote 5 (Balduccini Reference Balduccini2013), which deals with non-Herbrand numerical functions, and allows for undefinedness and default values. However, clingo{f} does not perform numerical constraint solving. System s(CASP) (Arias et al. Reference Arias, Carro, Salatar, Marple and Gupta2018) also mixes ASP with numerical constraints, but unlike standard CASP approaches based on grounding and solving, it follows a goal-directed evaluation as in Prolog. Under this paradigm, problems are modeled and solved in a substantially different way, so transferring examples from the ASP/CASP literature to s(CASP) is not always straightforward. If we wanted to extrapolate s(CASP) constraints to grounding-based CASP, their use would actually occur during the grounding phase, rather than in the solving phase as happens in the rest of CASP systems. Finally, aggregates are not directly representable inside s(CASP) constraints, but must be encoded through other Prolog predicates.
While the current implementation of flingo relies on clingo’s theory grammar, future work will focus on making the input language more natural and exploring further optimizations in the translation process to enhance scalability. The flingo system is publicly available at https://github.com/potassco/flingo.
Competing interests
The authors declare none.