1 Introduction
We shift the QCSP (for Quantified Constraint Satisfaction Problems) framework to the QCHR (for Quantified Constraint Handling Rule) framework. Such shift is motivated by the difficulties for developing real applications in QCSP.
QCSP [8, 27, 16, 5, 23, 21, 4] are a generalization of Constraint Satisfaction Problems (CSP) in which variables may be quantified existentially (as in CSP) and universally. A QCSP is an alternation of existentially and universally quantified variables over finite domains, the binder, followed by a CSP. Universally quantified variables represent uncontrollable parameters such as meteorological events. A QCSP may be seen as a twoplayers game in which the existentially quantified variables stand for a player and universally quantified variables stand for a player . QCSP+ [5] was proposed to make QCSP more practical from the modeling point of view. QCSP+ uses restricted quantification sequences instead of standard quantification sequences. A QCSP/QCSP+ is valid if player has a strategy to win i.e. a strategy for setting the existentially quantified variables such that no matter what setting the player chooses the CSP is true. QCSP/QCSP+ is a rich modeling framework which leads to succinct modeling. But this extension also increases the complexity of solving from NPcomplete to PSPACEcomplete. To fit a real problem in a QCSP/QCSP+, one has to model every part of the problem and everything must be a priori stated. There are problems (tictactoe, reversi, connectfour) that fit this requirement, but others (checkers, chess) just do not. QCSP/QCSP+ cannot be used to model games and problems whose number of moves is not formerly known. In addition, even if everything can be statically stated, the QCSP model involves all possibles moves and overestimates the number of moves to the worst case. For example, it is difficult to encode games such that some rules constrain future moves depending on past moves [6]: the QCSP will look for solutions for any possible move of player while some of them have been made impossible by previous moves. When a QCSP/QCSP+ is defined, the solving relies on a QCSP solver [16, 4, 27]. A QCSP/QCSP+ solver is a black box program that solves a given model. As most QCSP/QCSP+ solvers are based on CSP solvers, there is no easy way to help the solving process by taking into account the specific properties of a quantified problem. In this work, we propose a new framework to model quantified problems in a dynamic way.
CHR (for Constraint Handling Rules) [10, 11, 15, 12, 13, 14] are a committedchoice language consisting of multipleheads guarded rules that replace constraints by more simple constraints until they are solved. CHR are a specialpurpose language concerned with defining declarative constraints in the sense of
Constraint logic programming
[18, 19, 20]. CHR are a language extension that allows to introduce userdefined constraints, i.e. firstorder predicates, into a given host language as Prolog, Lisp, Java, or C/C++. CHR define simplification of userdefined constraints, which replaces constraints by more simple constraints while preserving logical equivalence. CHR define also propagation over userdefined constraints that adds new constraints; this constraints are logically redundant but may cause further simplifications. CHR allow to use guards that are sequences of host language statements. CHR finally define simpagation over userdefined constraints that mixes and subsumes simplification and propagation. CHR (simpagation) rules are applied on multisets of constraints. Repeated application of those rules on a multiset of initial constraints incrementally solves these constraints. The committedchoice principle expresses a don’t care nondeterminism, which leads to efficient implementations. CHR have been extended to CHR [2] that introduces the don’t know nondeterminism in CHR [7]. This nondeterminism is freely offered when the host language is Prolog. This nondeterminism allows to specify easily problems from the NP complexity class but it is not the case for the rest of the Polynomial Hierarchy and, in general, any problem expressed with alternating quantifications (although the formalism is Turingcomplete).We propose in this paper to extend CHR with quantification. We call this new formalism QCHR (for Quantified Constraint Handling Rules). We propose to extend the simpagation rule to an existential simpagation rule but also to a universal simpagation rule. The existential (resp. universal) simpagation has the same conditions to be applied as a simpagation rule but the body is existentially (resp. universally) quantified on a variable over a (finite) domain. We obtain a formalism for which it is not necessary to declare a priori the alternation of quantifiers but where the quantifiers are generated when they are needed. This property offers an ease of programming compared to QCSP/QCSP+ where you always need to declare a finite binder. In QCHR, one can specify some potentially infinite games by recursion.
Section 2 presents intuitively the syntax of our QCHR formalism, illustrates on two emblematic examples why it is not always appropriate to model and solve with QCSP/QCSP+, and shows the ease of modeling and efficiency of solving of our new formalism. Section 3 presents our proposal, the QCHR language, with its prooftheoretical semantics. Section 4 presents a discussion about the link between QCHR and some other related works. Section 5 presents our implementation of the QCHR language into the C++ host language and some experiments. Section 6 concludes and draws some perspectives.
2 Motivating examples
Our main purpose is to be able to model quantified problems when the binder can be built dynamically during the solving. Two well known problems are used: the Nim game and the Connectfour as motivating examples. Informally, CHR formalism is extended with two new rules: the existential (simpagation QCHR) rule
and the universal (simpagation QCHR) rule
The head , the body and the of these rules are interpreted in the same way as in the CHR formalism: Constraints are kept like in propagation and constraints are deleted like in simplification; the constraints of the body are the added constraints; if , nothing is added; if , the computation fails. The two symbols and denotes, respectively, the lower bound and the upper bound of an integer interval. The variable is supposed to appear in the body . The informal semantics of those rules is as follows: The body of the existential rule leads to a success (resp. failure) if at least one value (resp. all values) taken in the interval leads the body (where the occurrences of in are replaced by ) to a success (resp. failure). In the same way, the body of the universal rule leads to a success (resp. failure) if all values (resp. at least one value) taken in the interval leads the body to a success (resp. failure). If an existential (resp. universal) QCHR rule keeps all the constraints of its multiplehead, it is an existential (resp. universal) propagation rule and is denoted by () (resp. (); if an existential (resp. universal) QCHR rule keeps none of the constraints of its multiplehead, it is an existential (resp. universal) simplification rule and is denoted by () (resp. ().
The Nim game.
The Nim game is a twoplayers game played with a heap of coins or matches. The object of the game is to take the last match. Each player can take one to three matches. With the Fibonacci variant, the minimum number is one match and the maximum on the first play is one less than the initial number of matches. Then each player may take from one to twice as many as matches as the adversary at the preceding turn. Player begins. For example with 4 matches, player takes 1 match. Then player can take 3 matches but if he does he loses immediately since he cheated. Then player can take 1 or 2 matches. But whatever he takes, he loses since player will take the remaining matches. The longest possible party has 4 turns : each player takes one match at each turn. Then QCSP has 4 quantifiers since the binder is defined statically. With an even number of matches, the QCSP specification is as follows (, resp. , is the number of matches chosen by player , resp. , at turn ): is true (player chooses between 1 and matches) and for all , , and for all , , (each player takes from one to twice as many matches as the adversary at the preceding turn) [4]:
with and Boolean variables. For each initial number of matches, one has to instantiate the general scheme. For example, with , the following QCSP is obtained:
with and Boolean variables. This QCSP is valid if the first player has a strategy for setting the existentially quantified variables such that no matter what setting the adversary chooses for its universally quantified variables, this first player wins (i.e. the CSP is true).
The following QCHR program solves the Nim game with the Fibonacci variant of an even or odd number of matches (
represents the number of matches chosen by a player and represents the remaining number of matches into the heap):These rules are built in the same way: they are existential/universal simplification rules with an omitted empty guard, the definition of the lower and upper bounds, and the body that expresses that if a player has chosen to take matches, his adversary may only choose between and matches. The first player may freely choose between and the initial number of matches minus one:
The binder is not defined statically as for QCSP but dynamically. Note that the base case of the recursion is hidden into the semantics of the universal rule when the lower bound becomes larger than the upper bound.
The Connectfour game.
The connectfour game is a twoplayers game in which the players first choose a color. It is played on a vertically suspended grid. At each turn, a player drops one colored coin from the top into a column of the grid. The coins fall straight down, occupying the lowest available slot within the column. The winner is the first player to form a horizontal, vertical, or diagonal line of four of one’s own coins.
The connectfour game can also be modeled with a QCSP. In order to model every game, a grid is built for each player turn. There are as many game turns as there are slots in the grid. As a result, the QCSP model involves grids linked with each others with constraints (see [22] more details about the QCSP model). Furthermore, constraints has to be added to detect full columns, invalid moves and winning grids. But, even if a QCSP can be used, the binder is dynamic (a player may win the game without completely filling the board) and the model is big and not very understandable. In comparison, the QCHR model is more suitable, lightweight and more readable. Let be the number of columns of the grid. The following QCHR model computes a winning strategy if such a strategy exists:
Where , and are builtin constraints: sets a coin to the given column and raises a failure if the column is full; returns if the column is full and otherwise; returns if an alignment of four coins is found and otherwise. These functions rely on a grid which is filled according to the players moves.
The binder is not defined statically as for QCSP but dynamically. As a result, the size of the binder is equal to the number of moves done during the game and not the worst possible case.
3 The QCHR language
A constraint is considered to be a firstorder predicate. Only one kind of predefined (builtin) constraint is required: the syntactic equality constraint denoted by with an equality theory denoted for variables and constants^{1}^{1}1We do not use functional symbols but the language is richer than simply variables and constants since one can use the statements of the host language that are evaluated before equality is applied on a completely instantiated expression. It is the case for arithmetic operation in the modelling of Nim game or for more ad hoc functions like and in the modelling of the ConnectFour game.. For two sequences of userdefined constraints means and for two constraints means , …, . If is a set of constraints, [] denotes the set of equality constraints of .
In order to define the (prooftheoretical) semantics of QCHR, two reserved constraints are first defined.
Definition 3.1 ( and constraints)
The and constraints are constituted (in this order) of an integer variable, two integers (the lower and upper bounds) and a sequence of userdefined constraints.
The system is based on the following kind of sequents:
Definition 3.2 ( sequent)
An sequent is a quadruple where , the down store, and , the up store, are two stores of constraints, is a sequence of CHR rules and , the goal, is a sequence of constraints.
The intuitive meaning of a sequent is to try and consume the constraints with the sequence of CHR rules thanks to the store . The elements of the store are the unconsumed constraints: the constraints of that have not been consumed and those produced by the rules applied over but not consumed during this production.
The system is based on ten inference rules. The following first five rules below are adapted from the sequent calculus system of [26] for CHR. This implies that a QCHR program may contain CHR rules. In the following, some constraints (, , ), some stores of constraints (, , , , , …) and some sequences of constraints (, ) are used.
The Apply inference rule:
with

() a rule of ;

, and there exists such that

either , ,

or , ;


( the set of variables of and );

is a sequence composed of all the elements of .
The Apply inference rule applies a QCHR rule on a constraint since there are two substores and of the store such that modulo the equality constraints of and such that the sequence of host statements and equalities of the guard, , are verified. The solving of the constraint is reduced to the solving of the goal of the CHR rule and eventually the solving of the constraints of in the case that constraints from were not consumed during the process of consumption/production of . A part of the resources is allocated to solve the goal , the rest of the constraints and those produced by but unconsumed, , are allocated to a sequence over . Since the system only applies a QCHR rule if one of the constraints of its head is focused on, the calculus of () is necessary to the completeness of w.r.t. the semantics of CHR for nonquantified CHR programs (see Example 1 where ). But, may be empty if all the resources have been consumed (see Example 2 where is empty). If the applied rule is a simplification rule (i.e. is empty) or is empty then is empty and the right above sequent is omitted (and ). The Apply inference rule realizes in fact a hidden use of the cutrule of the linearlogic sequent calculus [17]: A lemma is computed by the left subproof and used in the right subproof^{2}^{2}2see [26] for a discussion about the linearlogic properties of this rule.
The Lefteliminationofconjunction inference rule:
If the current goal is a sequence of constraints, the Lefteliminationofconjunction inference rule is applied: The first constraint of the sequence is isolated and a part of the resources are allocated to solve the constraint; the rest of the constraints and those produced by but unconsumed, , are allocated to the remaining sequence of constraints. This inference rule realizes also, in fact, a hidden use of the cutrule of the linearlogic sequent calculus: The is a lemma computed by the left subproof and used in the right subproof.
The Inactivate axiom:
with no QCHR rule () of such that , (, or , ), , ; and ( the set of variables of and ).
If there is no QCHR rule to consume the current userdefined constraint by an apply rule, the Inactivate axiom stores the constraint into the store.
The axiom:
If the current goal is the constraint then no constraint is consumed and the axiom is applied.
The Equality inference rule:
with a partition of the store such that is the set of identified userdefined constraints that contain either the variables or , a sequence over , and with the proviso that the equality constraint () is consistent with the equivalence classes [] according to .
If the current goal is only an equality constraint then no constraint is consumed and the Equality inference rule is applied: The equality constraint is added to the store of constraints and a sequence of constraints, over all the constraints of the store with occurrences of variables or , is inserted into the goal part of a sequent. Since equivalence classes for the variables are modified, some rules might be applied from now on.
Example 3.1

[label=0,ref=3.1.0]

Let be the CHR program (), () and the goal then

Let be the CHR program (), () and the goal then
Below, the five rules that are specific to manage the quantifiers are described.
The Apply inference rule:
with

() is a QCHR rule of ;

, and there exists such that

either , ,

or , ;


( the set of variables of and ).
The Apply inference rule applies, in the same conditions as an Apply rule, an existential QCHR rule but introduces only one constraint: an existential constraint since the elimination of a quantified constraint is part of the mechanism of the semantics.
The Apply inference rule:
with

() is a QCHR rule of ;

, and there exists such that

either , ,

or , ;


( the set of variables of and ).
In the same way, the Apply inference rule applies, in the same conditions as an Apply rule, an universal QCHR rule but introduces only one constraint: an universal constraint.
The elimination inference rule:
with , and .
If the goal is a unique existential constraint, then the elimination inference rule is applied: A value into the interval is chosen and assigned to the variable of the constraints , …, (this is the meaning of ). If then, there is no possible subproof from this sequent. The resulting store is ignored after the proof of the : production and consumption are local.
The elimination inference rule:
with and , .
If the goal is a unique universal constraint, then the elimination inference rule is applied and leads to two subproof trees: The lower bound of the interval , , is assigned to the variable of the constraints , …, and the sequent () has to be proved; and the lower bound is increased by 1 and the sequent () has also to be proved. The resulting stores and are ignored after the proofs of and : production and consumption are local.
The  axiom:

with .
Finally, if the goal is a unique universal constraint with , then the  axiom is applied since the logic formula is equivalent to .
Now, the sequent calculus is defined:
Definition 3.3 ( sequent calculus system)
The sequent calculus system is the given of the ten previous inference rules and axioms.
Restricted to the first four items (ie. Apply, Lefteliminationofconjunction and Inactivate inference rules and axiom), the system is equivalent to the prooftheoretical semantics of CHR of [26] lifted to first order thanks to the Equality inference rule.
Example 3.2
The QCHR program that solves the Nim game, one of the motivating examples of Section 2, is recalled ( represents the number of matches chosen by a player and represents the remaining number of matches into the heap):
and a proof of () is given:

with :

and :

4 Discussion
All the stateof theart QCSP solvers have the same drawback: they explore much larger combinatorial spaces than the natural search space of the original problem. In [4], the meaning of the “Achilles’heel” notion, initially introduced for Quantified Boolean Formulas (QBF) [9, 24, 29, 30] in [3] as the difficulty to detect that the Boolean constraints are necessarily true under some partial assignment, has been extended for QCSP to the larger problem of how to avoid the exploration of combinatorial spaces that are known to be useless by construction. This definition includes the capture of the illegal actions of the player but also for example the end of the game before the last turn that is also a source of oversized explored search space. Already cited, [5, 28] proposes the new QCSP+ language that use restricted quantification sequences instead of standard quantification sequences. Some other approaches propose to modify more or less the QCSP/QCSP+ language to overcome the different drawbacks: [6] proposes the new Strategic CSP language where universal variables adapt their domain to be compatible with previous choices; [23] proposes also a new language but restricted to Markovian GameCSP, based explicitly on the notion of state, in order to efficiently model and solve control problems for completely observable and Markovian dynamic systems. Those language are easily and efficiently expressed in QCHR (see Subsection 5 ”The Nim Game” to a discussion about states in QCHR to improve efficiency).
5 Implementation and Experiments
To evaluate the QCHR approach, three well known problems^{3}^{3}3We used the matrix game, the nimfibo game and the connectfour game to carry our experiments. are modelled and solved in QCSP and QCHR. Then, the results obtained by two solvers are compared: QuaCode [4] for the solving of the QCSP models and our solver for the solving of the QCHR models. is a QCHR solver based on the CHR++ solver^{4}^{4}4CHR++ is a CHR solver built on the top of the C++ language, it can be downloaded at https://gitlab.com/vynce/chrpp. The latter has been extended by adding two new items to its grammar: exists and forall. Item exists allows you to browse the domain of a variable by successively trying each of its values in search of success. Item forall makes it possible to browse the domain of a variable by making sure that each of the values leads to a success. They implement the elimination and elimination rules previously defined.
Each experiment has been run
times and the average of the running times and number of failures are reported in the tables. Notice that there is no random parameter or value used for both solvers. As a consequence, for a given instance, the number of failures is always the same and the standard deviation of the running times is quite low. All experiments have been run on an Intel XeonE5, 2.13.3GHz, 128GB RAM running Linux. Maximum computation time is set to
seconds. All benchmarks used here are provided with CHR++ sources.The matrix game
is a twoplayers game of turns. It is played on a square matrix of size . At each turn, player cuts the matrix in half horizontally and decides to keep the top or bottom part. Player then cuts the matrix in half vertically and keeps the left or right part. If the last cell contains a , player wins.
The matrix game is well suited to the QCSP approach because the binder does not take benefit from being defined dynamically. Indeed, the number of moves of a matrix game is fixed and only depends on the matrix size. Although it does not belong to our motivating examples, it is used as a use case to evaluate the efficiency of our approach on static binders. Let be the input matrix of size such that . The following QCHR program finds a winning strategy to the matrix game:
With and the coordinates of the upper left and lower right corners of the relevant part of the matrix. The relevant part is the remaining part after a player turn. Constraints and are builtin constraints that update the upper left and lower right corners of the relevant part of the matrix. The initial call is .
The matrix game has already been modeled as a QCSP and solved with a QCSP solver. Random matrices are used as input for the instances and computed the average execution time and number of failures of each solver. Results are reported in Table 1.
Depth  QuaCode  

Failures  Time (s)  Failures  Time (s)  
4  14  1  22  1 
6  40  1  50  1 
8  235  3.9  366  1 
9  447  59.53  705  1 
10  TL  TL  1340  1 
Both models are quite equivalent and the solving takes no benefit from propagation of QCSP constraints. The number of failures encountered by QuaCode is smaller than that of . Indeed, the propagation done in QuaCode prevents the last branching steps of search. But the cost is huge compared to the price of propagating the previous choices during the whole search. In comparison, does not propagate the choices thanks to the constraints but its model is quite simple to test and each basic operation is constant in time. Indeed, it only has to update the corner variables and to check at the end if it is a or a . That is why is able to solve the instance of depth while QuaCode reaches the time limit. As a result, we show that the QCHR model combined with is lighter and can be more efficient than a QCSP model with QuaCode.
The Nim game
is our first motivating example which has been introduced in Section 2. It can be modeled in QCHR in a very intuitive way. But the QCHR model can do even more. Indeed, thanks to its dynamic way of modeling, it is possible to make a topdown evaluation with tabling [25]. A topdown evaluation with tabling consists in storing states of subtrees already explored. If such a subtree is encountered another time, its result will be used instead of exploring it again.
For the experiments, we compare three solving approaches: QuaCode for the QCSP/QCSP+ solving, for the QCHR solving and (Mem) for the solving of the QCHR model with tabling. We first observe on Figure 1 that QuaCode cannot solve instances of more than matches without exceeding the time limit (i.e. ). We notice that QuaCode and encountered the same number of failures. Indeed, they are both based on same model and there is no constraint to propagate. But, as seen on Figure 1, performs better. We now compare with with tabling and see on Figure 1 that all instances are solved in less than second. This huge improvement is explained by the tabling process. Indeed, a Nim game state^{5}^{5}5A Nim game state is given by the player number, the number of matches can be encountered many times during the search. Recording such states will prevent the algorithm to explore them again in the future and increases a lot the efficiency of the search. As the current state of a Nim game is Markovian (i.e. the current state does not depend on the whole history of events), similar results are achieved in [23].
The connectfour game
is our second motivating example. It has been presented at Section 2. The QCSP+ model for the connectfour is big and not very understandable compared to the QCHR model. The QCHR model involves a dynamic binder which is built during the solving.
Board size  QuaCode  

Failures  Time (s)  Failures  Time (s)  
4  4  2123  1  28818  1 
4  5  26754  9.53  327561  1 
5  4  312580  105.75  5373028  2.17 
5  5  TL  TL  120470758  75.83 
For the experiments, QuaCode for the QCSP solving and for the QCHR solving are compared. As shown Table 2, the number of failures encountered by QuaCode is smaller than that of . Indeed, as for the matrix game, the propagation done in QuaCode prevents the last branching steps of search. But the cost is huge compared to the benefit of avoiding a few branching steps. The results show that performs better than QuaCode. It is more than times faster and can even find solution before the time limit on the last instance. For larger boards, computing times become enormous, exceeding the maximum allowed time.
6 Conclusion
This paper proposed the new QCHR formalism which is an extension of CHR with quantification. QCHR allows to model dynamic binders. This overcomes one of the main drawbacks of the QCSP framework. We also presented some very intuitive QCHR models and we solved them with a QCHR solver, . The experiments showed that always outperforms the QCSP solver and sometimes by many orders of magnitude.
We believe that this new formalism gives an easier way to model constrained problems with quantifications and offers a new way when the binder cannot be statically deduced. In the future, we plan to tackle problems that cannot be dealt with QCSP such as problems where a static binder cannot be found.
References
 [1]
 [2] S. Abdennadher & H. Schütz (1998): CHR: A Flexible Query Language. In: Proceedings of the 3 International Conference on Flexible Query Answering Systems, pp. 1–14, doi:http://dx.doi.org/10.1007/BFb0055987.

[3]
C. Ansotegui,
C. Gomes &
B. Selman (2005):
Achilles’ Heel of QBF.
In:
Proceedings of the 20th National Conference on Artificial Intelligence (AAAI’05)
, pp. 275–281.  [4] V. Barichard & I. Stéphan (2014): The cut tool for QCSP. In: Proceedings of the 26th IEEE International Conference on Tools with Artificial Intelligence (ICTAI’14), pp. 883–890, doi:http://dx.doi.org/10.1109/ICTAI.2014.135.
 [5] M. Benedetti, A. Lallouet & J. Vautard (2007): QCSP made Practical by virtue of Restricted Quantification. In: Proceedings of the 20th International Joint Conference on Artificial Intelligence (IJCAI’07), pp. 38–43.
 [6] C. Bessiere & G. Verger (2006): Strategic constraint satisfaction problems. In:
Comments
There are no comments yet.