On Higher-Order Reachability Games vs May Reachability
Abstract
We consider the reachability problem for higher-order functional programs and study the relationship between reachability games (i.e., the reachability problem for programs with angelic and demonic nondeterminism) and may-reachability (i.e., the reachability problem for programs with only angelic nondeterminism). We show that reachability games for order- programs can be reduced to may-reachability problems for order-() programs, and vice versa. We formalize the reductions by using higher-order fixpoint logic and prove their correctness. We also discuss applications of the reductions to higher-order program verification.
keywords:
Higher-order programs, reachability games, may-reachabilityHigher-Order Reachability Games vs May Reachability
1 Introduction
This paper considers the reachability problem for simply-typed, call-by-name higher-order functional programs with integers, recursion, and two kinds of non-deterministic branches (angelic and demonic ones). The problem of solving reachability games (hereafter, simply called the reachability game problem) asks, given a higher-order functional program and a specific control point of the program, whether there exists a sequence of choices on angelic non-determinism that makes the program reach no matter what choices are made on demonic non-determinism. Thus, our reachability game problem is just a special case of the notion of two-player reachability games [1], where the game arena is specified as a higher-order functional program. (An important restriction compared to the general notion of reachability games is that each vertex may have only a finite number of outgoing edges, although there can be infinitely many vertices.)Various program verification problems can be reduced to the reachability game problem. For example, the termination problem, which asks whether a given program terminates for any sequence of non-deterministic choices, is a special case of the reachability game problem, where all the non-deterministic branches are demonic, and all the termination points are expressed by . The safety verification problem, which asks whether a given program may fall into an error state after some sequence of non-deterministic choices, is also a special case, where all the non-deterministic branches are angelic, and error states are expressed by .
We establish relations between the reachability game problem and the may-reachability problem, a special case of the reachability game problem where all the non-deterministic choices are angelic (hence, may-reachability is a one-player game). We show mutual translations between the reachability game problem for order- programs and the may-reachability problem for order-() programs. (Here, the order of a program is defined as the type-theoretic order; the order of a function that takes only integers is 0, and the order of a function that takes an order-0 function is 1, etc.) The translations are size-preserving in the sense that for any order- program , one can effectively construct an order-() program such that the answer to the reachability game problem for is the same as the answer to the may-reachability problem for , and the size of is polynomial in that of ; and vice versa.
The translation from reachability games to may-reachability allows us to use higher-order program verification tools specialized to may-reachability (or, unreachability to error states) such as MoCHi [2] and Liquid types [3] to check a wider class of properties represented as reachability games. Conversely, the translation from may-reachability to reachability games allows us, for example, to use verification tools that can solve reachability games for order-0 programs, such as CHC solvers [4, 5, 6] to check may-reachability of order-1 programs.
We formalize our translations for HFL(Z), which is a fragment HFL(Z) [7] without greatest fixpoint operators and modal operators, where HFL(Z) is an extension of Viswanathan and Viswanathan’s higher-order fixpoint logic [8] with integers. The use of higher-order fixpoint formulas rather than higher-order programs in the formalization of the translations is justified by the result of Kobayashi et al. [7, 9], that there is a direct correspondence between the reachability problem for higher-order programs and the validity problem for the corresponding higher-order fixpoint formulas, where angelic and demonic branches in programs correspond to disjunctions and conjunctions respectively.
The rest of this paper is structured as follows. Section 2 introduces HFL(Z), and clarifies the relationship between the validity checking problem for HFL(Z) and the reachability problem for higher-order programs. Section 3 formalizes a reduction from the order- reachability game problem to the order-() may-reachability problem (as a translation of HFL(Z) formulas), and proves its correctness. Section 4 formalizes a reduction in the opposite direction, from the order-() may-reachability problem to the order- reachability game problem, and proves its correctness. Section 5 discusses applications of the reductions and reports some experimental results. Section 6 discusses related work and Section 7 concludes the paper. This is an extended and revised version of the paper that appeared in Proceedings of RP 2022 [10]. We have added definitions, examples and full proofs.
2 HFL(Z) and Reachability Problems
In this section, we first introduce HFL(Z), a fragment of higher-order fixpoint logic HFL(Z) [7] (which is in turn an extension of Viswanathan and Viswanathan’s higher-order fixpoint logic [8] with integers) without greatest fixpoint operators. We then review the relationship between HFL(Z) and reachability problems, and state the main theorem of this paper.
2.1 Syntax
The set of (simple) types, ranged over by , is given by:
For a type , the order and arity of , written and respectively, are defined by:
For example, and .111Defining the order of as is a bit unusual, but convenient for stating our technical result.
The set of HFL(Z) formulas, ranged over by , is given by:
Intuitively, denotes the least predicate of type such that . We write and for and respectively. For a formula , the order of is defined as: . We call a HFL(Z) formula disjunctive if the conjunction occurs in only in the form of (i.e., the left-hand side of is a primitive constraint on integers).
We write for a sequence of formulas ; it denotes an empty sequence if . We often omit the subscript and just write for when the subscript is not important. Similarly, we also write and for sequences of expressions and types respectively. We use the metavariables , , and to denote either a formula or an integer expression.
The simple type system for HFL(Z) formulas is defined in Figure 1. Henceforth, we consider only well-typed formulas (i.e., formulas such that for some and ). A formula is called a closed formula of type if .
(T-Var)
(T-Or)
(T-And)
(T-Mu)
(T-App)
(T-Abs)
(T-AppInt)
(T-Le)
(T-Int)
(T-Plus)
(T-Mult)
2.2 Semantics of HFL(Z) Formulas
For each simple type , we define the partially ordered set where by:
Here, denotes the set of integers. For each , (but not ) forms a complete lattice. We write () for the least (greatest, resp.) element of , and (, resp.) for the greatest lower bound (least upper bound, resp.) operation with respect to . We also define the least fixpoint operator by:
For a simple type environment , we write for the set of maps such that and for each .
For each valid type judgment , its semantics is defined by:
For a closed formula of type , we just write for . The validity checking problem for HFL(Z) is the problem of deciding whether , given a closed HFL(Z) formula of type . Note that the validity checking problem is undecidable.
For closed formulas, the following alternative semantics is sometimes convenient. Let us define the reduction relation by the following rules.
Here, denotes an evaluation context, defined by:
We write for the reflexive and transitive closure of . We have the following fact (see, e.g., [11]).
Fact 1
Suppose . Then, if and only if .
Due to the fact above, the validity checking problem is equivalent to the problem of deciding whether , given a closed HFL(Z) formula of type .
Example 2.1
Suppose . Then,
just if for some . Thus, the formula represents .
The example above indicates that existential quantifiers on integers are expressible in HFL(Z). Below, we treat existential quantifiers as if they were primitives.
2.3 Relationship with Reachability Problems
We consider reachability problems for a call-by-name, simply-typed -calculus extended with two kinds of non-determinism ( and ) and a special term , which represents that the designated target has been reached.222In the context of program verification, we are often interested in (un)reachability to bad states. Thus, in that context, in this section is actually interpreted as an error state, and the terms “angelic” and “demonic” below are swapped. The sets of types and terms, ranged over by and respectively, are defined by:
Here, the meta-variable ranges over the set of integer expressions as defined in Section 2.1. The term denotes a recursive function of type such that . The term denotes a demonic choice between and , where the choice is up to the environment (or, the opponent of the reachability game), and denotes an angelic choice between and , where the choice is up to the term (or, the player of the reachability game). The term first checks whether holds and if so, proceeds to evaluate ; otherwise aborts the evaluation of the whole term. Using , we can express a conditional expression as .
A simple type system for the language is given in Figure 2. In the figure, denotes the type environment obtained by restricting to bindings on , i.e., . Henceforth, we consider only well-typed terms.
(LT-Unit)
(LT-Succ)
(LT-Var)
(T-Abs)
(LT-App)
(LT-AppInt)
(LT-Fix)
(LT-DChoice)
(LT-AChoice)
(LT-Assume)
The order of a type is defined by:
The order of a term is defined as the largest order of type such that has a subterm of the form . We write for .
For a closed simply-typed term of type , a play is a (possibly infinite) sequence of reductions of . The play is won by the player if it ends with ; otherwise the play is won by the opponent . The reachability game for is the problem of deciding which player ( or ) has a winning strategy. For the general notion of reachability games and strategies, we refer the reader to [1]. As a special case of the translation of Watanabe et al. [9] from temporal properties of programs to HFL(Z) formulas, we obtain the following translation from reachability games to HFL(Z) formulas.
The following is a special case of the result of Watanabe et al. [9].
Theorem 2.2 ([9])
For any closed simply-typed term of type and order , is a closed HFL(Z) formula of type and order . The player wins the reachability game for , if and only if, .
Based on the result above, we focus on the validity checking problem for HFL(Z) formulas, instead of directly discussing the reachability problem. Note that the may-reachability problem (of asking whether, given a closed term of which all the branches are angelic, there exists a reduction sequence from to ) corresponds to the validity checking problem for disjunctive HFL(Z) formulas.
Example 2.3
Let us consider the following OCaml program.
let rec sum x k = assert(x>=0); if x=0 then k 0 else sum(x-1)(fun y-> k(x+y)) in sum n (fun r -> assert(r>=n))
Suppose we are interested in checking whether the program suffers from an assertion failure. It is modeled as the reachability problem for the term , where is:
Here, note that an assertion failure is modeled as in our language. By Theorem 2.2, the above term is reachable to just if the (disjunctive) HFL(Z) formula is valid, where is:
The formula is valid only if , which implies that the OCaml program suffers from an assertion failure just if . ∎
2.4 Main Theorem
The main theorem of this paper is stated as follows.
Theorem 2.4
There exist polynomial-time translations and between order- HFL(Z) formulas and order- disjunctive HFL(Z) formulas that satisfy the following properties.
-
(i)
For any order- closed HFL(Z) formula , is an order-() closed disjunctive HFL(Z) formula such that .
-
(ii)
For any order-() closed disjunctive HFL(Z) formula , is an order- closed HFL(Z) formula such that .
Due to the connection between reachability problems and HFL(Z) validity checking problems discussed in Section 2.3, the theorem above implies that any order- reachability game can be converted in polynomial time to order-() may-reachability problem, and vice versa. The result allows us to use a tool for checking the may-reachability of higher-order programs (such as MoCHi [2]) to solve the reachability game, and conversely, to use a tool for solving the order- reachability game (such as HFL(Z) validity checkers [12, 13] and a HoCHC solver [14]) to check the may-reachability of order-() programs; see Section 5 for more discussion on the applications.
3 From Order- Reachability Games to Order-() May-Reachability
In this section, we show the translation from order- HFL(Z) formulas to order-() disjunctive HFL(Z) formulas. The idea is to transform each proposition (i.e. a formula of type ) to a predicate of type , so that and are respectively converted to the identity function and the constant function . We can then encode the conjunction as , which is equivalent to the identity function if both and are so, and is equivalent to if one of and is so.
The translation for formulas and types is defined as follows.
Example 3.1
Consider the formula (where is an integer constant). We obtain the following formula as :
By simplifying the formula with -reductions, we obtain:
The following theorem states the correctness of the translation.
Theorem 3.2
If is an order- closed HFL(Z) formula, then is an order-() closed disjunctive HFL(Z) formula, and .
To show the theorem above, we first extend the translation of types to that of type environments by: .
The following lemma guarantees that the translation preserves typing.
Lemma 3.3
If , then .
Proof 3.4
Straightforward induction on the derivation of .
Corollary 3.5
If is an order- closed HFL(Z) formula of type , then is an order-() closed disjunctive HFL(Z) formula of type .
Proof 3.6
Suppose is an order- closed HFL(Z) formula. By Lemma 3.3, we have , which implies . Since each -formula in is translated to and , is an order-() formula. Furthermore, all the conjunctions in are of the form ; hence it is disjunctive.
To prove the latter part of the theorem (i.e., ), we define the relation between the values of the source and the target of the translation, by induction on .
We extend pointwise to the relation on environments by:
We first prepare the following lemma.
Lemma 3.7
If , then .
Proof 3.8
By Cousot and Cousot’s fixpoint theorem [15], there exists an ordinal such that and . Here, is defined by:
Thus, it suffices to show by induction on . The case where or is trivial. Suppose is a limit ordinal. Suppose , and for . It suffices to show
By the induction hypothesis, we have for any . Thus, we have:
Theorem 3.2 is an immediate corollary of the following lemma.
Lemma 3.9
Suppose . Then implies .
Proof 3.10
The proof proceeds by induction on the derivation of . Since the other cases are similar or trivial, we show only the main cases.
-
•
Case T-And: In this case, and , with and . By the induction hypothesis, we have for . If , then for both and . Thus, for both and . Therefore, we have as required. Otherwise, i.e., if , then for or . Thus, for such . Therefore, we have as required.
-
•
Case T-Mu: In this case, and with and . By the induction hypothesis, we have for any , which implies . Thus, the required result follows by Lemma 3.7.
4 From Order-() May-Reachability to Order- Reachability Games
In this section, we show the translation from order-() disjunctive HFL(Z) formulas to order- HFL(Z) formulas. The translation is much more involved than the translation . We first give some intuitions on the first-order case in Section 4.1. We then give the translation for the general case in Section 4.2, and prove the correctness in Section 4.3.
4.1 Intuitions for the Order-1 Case
Let us recall the formula in Example 2.3, where is:
Note that the order of the formula above is . We wish to construct a formula of order , such that . Recall that, by Fact 1, just if . There are two cases where the formula may be reduced to : (i) is reduced to without the order-0 argument being called; and (ii) is reduced to for some , and then is reduced to . Let be the condition for the first case to occur, and let be the condition that is reduced to . Then, and can be expressed as follows.
To understand the formula , notice that is reduced to just if is first reduced to for some (the condition for which is expressed by ), and holds.
Using and above, the formula can be translated to:
Note that the order of is . In general, if is an order-1 (disjunctive) formula of type
and () is a formula of type , then can be translated to an order-0 formula of the form:
where the part expresses the condition for to be reduced to without being called, and the part expresses the condition for to be reduced to .
4.2 Translation for the General Case
For higher-order formulas, the translation is more involved. To simplify the formalization, we assume that a formula as an input or output of our translation is given in the form , called an equation system; here is a set of mutually recursive fixpoint equations of the form and is the type environment for . We sometimes omit and just write . Here, each () should be fixpoint-free, is well-typed under , and () should have some type under the type environment , where and . The HFL(Z) formula represented by is defined by:
We write for .
For an equation system as an input of our translation, we further assume, without loss of generality, the following conditions.
-
(I)
Each () on the right-hand side of a definition in has type and is generated by the following grammar (where the metavariable may be a fixpoint variable or its parameters):
(1) In particular, (i) is a disjunctive HFL(Z) formula, (ii) contains neither -abstractions nor fixpoint operators, and (iii) a formula of the form may occur only in the form .
-
(II)
Every integer predicate (i.e., a formula of type of the form with ) that occurs in an argument position has the same arity . In other words, in any function type , either , or .
-
(III)
The “main formula” is a formula of the form .
Note that the assumption above does not lose generality. Given an order- disjunctive HFL(Z) formula , it can be first transformed to a formula of the form , where does not occur on the right-hand side of any conjunction in . We then set to the largest arity of integer predicates that occur in argument positions in , and raise the arity of every integer predicate argument to by adding dummy arguments. For example, given
we can set to , and replace the formula with:
Here, we have inserted dummy (actual and formal) parameters and to increase the arities of and the argument of . We can then apply -lifting to remove -abstractions and generate a set of top-level definitions .
The formula given earlier in this section is represented as: , where consists of the following equations. Here, is set to .
and is:
We translate each equation in as follows. We first decompose the formal parameters to two parts: and , where the orders of (the types of) are at most , and the order of is at least ; note that the sequences and are possibly empty. We further decompose into order-0 variables and integer variables (thus, ). Formally, the decomposition of formal parameters is defined by:
Here, decomposes the sequence of variables and returns a triple , where is the type environment for , is the sequence of integer predicate variables, and is the sequence of integer variables.
For example, given an equation , where , the formal parameters are decomposed as follows.
Given an equation where with , we generate equations for new fixpoint variables . As in the order-1 case, for , represents the condition for to be reduced to (where is the sequence of formulas obtained by translating in a recursive manner, and is a sequence obtained by shuffling and ). is a new component required to deal with higher-order formulas; it is used to compute the condition for to be reduced to for some order-0 predicate , which has been passed through higher-order parameters . For example, consider a formula where . Then, the condition for to be reduced to is computed by using , while the condition for to be reduced to is computed by using ; see Example 4.1 for a concrete version of this example.
To compute , we translate each subformula of the body of to:
where is the type of , and denotes the number of order-0 arguments passed after the last argument of order greater than . More precisely, we define the decomposition of types as follows.
Then, denotes when . For example, for , ; hence . Here, are analogous to : they are used for computing the condition for to be reduced to . Similarly, (where ) is used for computing the condition for to be reduced to , where is the -th order-0 argument of . The component is analogous to , and used to compute the condition for to be reduced to , where is an order-0 predicate passed through higher-order arguments of . The other component is similar to , but the target order-0 predicate may have already been set inside .
Based on the intuition above, we formalize the translation of a formula as the relation:
Here, denotes the type environment for fixpoint variables defined by . If is a subformula of the body of , and is defined by , then and are set to and respectively, where .
The output of the translation has type under the type environment , where the translations of types and type environments are defined by:
(if ) | ||
Here, we have extended simple types with product types; we extend the definition of the order of a type by: . Note that the translation of a type decreases the order of the type by one, i.e., .
(Tr-VarG)
(Tr-Var)
(Tr-VarF)
(Tr-Le)
(Tr-App)
(Tr-AppG)
(Tr-AppI)
(Tr-Disj)
(Tr-Def)
(Tr-Main)
The translation rules are given in Figure 3. We explain the main rules below. In the rule Tr-VarG for an order-0 variable (which should disappear after the translation), should represent the condition for ; thus is defined so that is equivalent to just if and . In the rule Tr-Var for a variable in , the output of the translation is constructed from , whose values will be provided by the environment. Because the environment does not know order-0 variables , we use to compute the condition for to be reduced to . The rule Tr-VarF for fixpoint variables is almost the same as Tr-Var, except that the component is reused for . The rationale for this is as follows: both and are used for computing the condition for a target order-0 predicate variable (which is set by the environment) to be reached, and the only difference between them is that the target predicate may have already been set in , but since is a closed formula, such distinction does not make any difference; hence and need not be distinguished from each other.
In the rule Tr-App, the first two components ( and ) are used for computing the condition for some target predicates (set by the environment) to be reached, and the next components () are used for computing the condition for predicate to be reached. The rule Tr-AppG is another rule for applications, where the argument is an order-0 predicate. The component of the output is used for computing the condition for the predicate to be reached (i.e., the condition for a formula of the form to be reduced to , where consists of order-0 predicates and integer arguments ). The formula may be reduced to if either (i) without being called, or (ii) is reduced to for some , and then is reduced to . The part represents the former condition, and the part represents the latter condition. In the rule Tr-Def for definitions, the bodies of the definitions for are set to the corresponding components of the translation of the body of .
Example 4.1
Consider , where is defined by:
There are the following two ways for to be reduced to for some :
The output of our transformations (with some simplification) is where:
Notice that the formula has the following two reduction sequences that lead to the conditions of the form for some .
The former reduction sequence corresponds to the reduction sequence of the original formula where embedded in the first argument of (in ) is called, and the latter reduction sequence corresponds to the reduction sequence where the second argument of (in ) is called. Note that the first condition has been computed by using , and the second condition has been computed by using . ∎
Example 4.2
Recall the example of given earlier in this section. The following is the output of the translation (with some simplification by -reductions and simple quantifier eliminations).
Although the output may look complicated, since the order of the resulting formula is , we can directly translate its validity checking problem to a CHC solving problem using the method of [16], for which various automated solvers are available [4, 5, 6]. ∎
Example 4.3
Let us consider the formula 333Taken from [12]., where:
It is translated to , where:444This is a mechanically generated output based on the transformation rules, followed by slight manual simplification.
The order of the original formula is (since ), while the order of the formula obtained by the translation is ; note that . By further simplifications (note that the -components actually return ), we obtain:
∎
4.3 Correctness
We show the correctness of the translation.
The following lemma states that the output of the translation is well-typed.
Lemma 4.4
If , then . Also, for , does not occur free in .
Proof 4.5
Straightforward induction on the derivation of .
The following theorem states the correctness of the translation.
Theorem 4.6
If , then .
The rest of this section is devoted to the proof of Theorem 4.6. The proof consists of the following two steps: (i) we first reduce the proof of Theorem 4.6 to the case where a given equation system is recursion-free (in Section 4.3.1), by using a standard technique of finite approximation, and then (ii) we show the recursion-free case (in Section 4.3.3, with some preparation in Section 4.3.2).
For an equation system , we define as follows: if . For , we may drop the subscript and write if there is no confusion. We write for the substitution .
4.3.1 Reduction to the Recursion-free Case
Here we briefly explain how we can reduce Theorem 4.6 to the recursion-free case.
For an equation system and , the -th approximation is defined as follows:
For above, we use rather than , in order to keep the form of Equation 1. By the technique in [17, Appendix B.1], we can show that
An equation system is called recursion free if there is no cyclic dependency on . More precisely, we define a binary relation on as follows: iff where and is defined by the following:
Then is recursion free if the transitive closure of is irreflexive (i.e., for no ). Clearly is recursion-free.
Now, since our translation is compositional, we can easily show the following:
Lemma 4.7
If , then .
Then we can reduce the proof of Theorem 4.6 to the recursion-free case as follows. Let and ; then
where for the second equation we assume the recursion-free case.
4.3.2 Reduction Relation with Explicit Substitution
In our proof of the recursion-free case, we show a subject reduction property. To this end, we modify the reduction strategy by using explicit substitution, keeping the adequacy for the semantics. For this modification, we first extend the syntax of formulas as follows:
(2) | ||||
Here is called an explicit substitution, and limited to ground types as follows:
(T-ESub)
Its meaning is given through
Thus explicit substitution has the same meaning as ordinary substitution, but delays substitution until we need for further reduction. As in the definition of below, while we use ordinary substitutions for -redex to which we can apply Tr-App and Tr-AppI, we use explicit substitution for those corresponding to Tr-AppG because, the argument after the translation by Tr-AppG is never substituted.
We extend the translation by adding the following rule for explicit substitutions:
(Tr-ESub)
In the rest of this section, by a formula we mean a formula that may contain extended substitutions, except for formulas in an equation system and except for the case where we explain explicitly. Note that output formulas of the extended translation never contain explicit substitutions.
Let be an equation system. For decomposing actual arguments of a function —recall that ranges over formulas and integer expressions—we define in the same way as as follows:
Now we define the modified reduction relation for a formula such that holds for some . We define the set of evaluation contexts by:
Then is defined by the following rules:
Note that the above reduction preserves the form of (2) and hence the applicability of the translation . For any , is a normal form with respect to iff is generated by:
(3) |
Clearly we have:
Lemma 4.8
If , then .
4.3.3 Correctness in the Recursion-free Case
It remains to show the correctness in the recursion-free case, which follows from the subject reduction property below. For a type , we write for .
Lemma 4.9 (subject reduction)
Suppose that we have . If and
then there exist such that
and for each .
As the proof of the above lemma is quite technical and long, we defer it to Appendix A.
The following lemma states the correctness in the recursion-free case, from which Theorem 4.6 follows.
Lemma 4.10
Suppose that is a recursion-free equation system. If , then .
Proof 4.11
Let the rule of be ; then has the rule where and has type . Since , it suffices to show
Since is recursion-free, has a normal form with respect to . We have and let ; then by subject reduction (Lemma 4.9), we have and . Also, we have by Lemma 4.8, and hence . Therefore we can assume that is a normal form without loss of generality.
Then we can directly check by induction on the structure of normal forms (3) in Section 4.3.2.
5 Applications
As mentioned already, the translation from order- reachability games to order-() may-reachability enables us to use automated (un)reachability checkers for solving the reachability game problem, and the translation in the other direction enables us to use, for example, reachability game solvers for non-higher-order programs as a may-reachability checker for order-1 programs.
As a direct application of the former translation, we have applied it to the HFL(Z) solver ReTHFL [13], which is a refinement-type-based validity checker for formulas of HFL(Z), the fragment of HFL(Z) without least fixpoint operators (but with greatest fixpoint operators). The fragment HFL(Z) is dual to HFL(Z), in the sense that, for every closed formula of type of HFL(Z), there exists a HFL(Z) formula such that is valid if and only if is invalid, and vice versa; is obtained from by just replacing each logical operator (including fixpoint operators) with its de Morgan dual, and with . Using a refinement type system, ReTHFL reduces the validity of a given HFL(Z) formula in a sound (but incomplete) manner to an extended CHC (constraint Horn clauses) problem, where disjunction is allowed in the head of each clause, and passes the problem to an extended CHC solver called PCSat [18]. For a fragment of HFL(Z) corresponding to disjunctive HFL(Z), however, the reduced problem is actually an ordinary CHC problem, for which more efficient tools [4, 5, 6] can be invoked. Thus, we can use the translation in Section 3 to improve the efficiency of ReTHFL.
From the benchmark suite of ReTHFL [13] (which originates from [12], https://github.com/Hogeyama/hfl-benchmark/tree/master/inputs/hfl/HO-nontermination), we picked the “non-termination” benchmark set, which consists of formulas obtained from non-termination verification of higher-order programs. All the formulas in that benchmark set do not belong to (the dual of) disjunctive HFL(Z) (in contrast, the problems in the other benchmark sets belong to disjunctive HFL(Z), hence our translation is not required). We have implemented the translation in Section 3, applied it to the problems in the “non-termination” benchmark set, and then ran ReTHFL with a CHC solver HoIce [6, 19] as the back-end solver. We have compared the result with plain ReTHFL (without the transformation), which uses the extended CHC solver PCSat.
input | ReTHFL | ReTHFL+i.s. | ReTHFL+ tr. |
---|---|---|---|
fixpoint_nonterm | 11.579 | 0.054 | 0.102 |
unfoldr_nonterm | timeout | unknown | 4.22 |
indirect_e | 16.832 | 0.035 | 0.066 |
alternate | unknown | unknown | unknown |
fib_CPS_nonterm | timeout | 0.047 | 0.075 |
foldr_nonterm | 8.447 | unknown | 0.122 |
passing_cond | 116.423 | unknown | 0.444 |
indirectHO_e | 11.582 | 0.044 | 0.073 |
inf_closure | timeout | 20.171 | 9.080 |
loopHO | timeout | 0.026 | 0.121 |
The results are summarized in Table 1. The column ’ReTHFL’ shows the result of plain ReTHFL with PCSat as the back-end extended CHC solver (since ordinary CHC solvers are inapplicable to this benchmark set, as explained above). The column ’ReTHFL+i.s.’ show the result of ReTHFL where the subtyping relation has been replaced by the imprecise one (equivalent to that of Horus [14], a HoCHC solver that can also be viewed as a HFL(Z) solver) so that the type checking problem is reduced to ordinary CHC solving. The column ’ReTHFL+tr.’ shows the result of ReTHFL with our translation. In both ’ReTHFL+i.s.’ and ’ReTHFL+tr.’, HoIce was used as the back-end CHC solver. The entry “unknown” indicates that the solver terminated with the answer “ill-typed”, in which case, we do not know whether the formula is valid or invalid, due to the incompleteness of the underlying refinement type system.555Although the understanding of the refinement type systems ReTHFL is not required below, interested readers may wish to consult [13]. The refinement type system used in ’ReTHFL+i.s.’ is less precise than the one used in ReTHFL; hence, it returns more unknowns. As clear from the table, our translation significantly improved the efficiency of ReTHFL.
The translation in the other direction given in Section 4 also helps ReTHFL, especially for relaxing the limitation caused by the incompleteness of the underlying refinement type system. For example, consider the formula , where:
The formula is invalid, but ReTHFL (nor Horus [14], a higher-order CHC solver based on a refinement type system) cannot prove the validity of the dual formula, due to the incompleteness of the refinement type system (which is related to the incompleteness of a refinement type system addressed by [20] by inserting extra arguments). The translation in Section 4 yields the following order-0 formula:666We have implemented a prototype translator, but have not yet integrated it into ReTHFL. For readability, here we show the formula obtained by some manual simplification of the automatically generated formula.
Here, intuitively means that can be reduced to . The underlying type system of ReTHFL is complete for order-0 formulas, and indeed, the order-0 formula above can automatically be proved invalid by ReTHFL.
6 Related Work
The relationship between order- reachability games and order-() may-reachability has some deep connection to the relationship between order- tree languages and order-( word languages [21, 22, 23], intuitively because the may-reachability problem is concerned about the set of “paths” of the execution tree of a given program, whereas the reachability game problem is also concerned about the branching structures of the execution tree. Indeed, our translations (especially, the use of and components in the translation in Section 4) have been inspired by Asada and Kobayashi’s translations between tree and word languages [23]. Kobayashi et al. [24] have also used a similar idea for a characterization of termination probabilities of higher-order probabilistic programs.
For finite-data programs (programs in Section 2.3 without integers), according to the complexity results on HORS model checking [25, 26], both the order- reachability game problem and the order-() may-reachability game problem are -EXPTIME complete, which imply that there are mutual translations between them. Concrete translations have, however, not been given (except unnatural translations through Turing machines). Also, the complexity-theoretic argument for the existence of translations does not apply in the presence of integers.
For HORS model checking, Parys [27] developed an order-decreasing transformation for higher-order grammars, which shares some ideas with our translation in Section 4. The details of the translations are however quite different. His translation makes use of finiteness in a crucial manner, and is not applicable in the presence of integers. Also, his translation is not size-preserving.
For order-1 programs, Kobayashi et al. [16] have shown that linear-time omega regular properties can be translated to order-0 HFL(Z) formulas. Our translation in Section 4 may be viewed as a higher-order extension of their translation, while the properties are restricted to may-reachability.
The fragment HFL(Z) (or its dual fragment HFL(Z)) is essentially (modulo the restriction of data domains to integers) equivalent to HoCHC [14], a higher-order extension of CHC. Therefore, the result of this paper should be useful also for improving HoCHC solvers.
7 Conclusion
We have shown translations between order- reachability games and order-() may-reachability, and proved their correctness. We have applied the translations to higher-order program verification, and obtained promising results in preliminary experiments. As mentioned in Section 6, our results are closely related to the correspondence between higher-order word and tree languages [23]. A deeper investigation of the relationship and generalization of the translations that subsume the related translations [23, 24] are left for future work.
Acknowledgments
We would like to thank anonymous referees for useful comments. This work was supported by JSPS KAKENHI Grant Number JP20H05703, JP24K14814 and JST SPRING Grant Number JPMJSP2108.
References
- [1] Grädel E, Thomas W, Wilke T (eds.). Automata, Logics, and Infinite Games: A Guide to Current Research, volume 2500 of LNCS. Springer, 2002.
- [2] Kobayashi N, Sato R, Unno H. Predicate Abstraction and CEGAR for Higher-Order Model Checking. In: PLDI 2011. ACM Press, 2011 pp. 222–233.
- [3] Rondon PM, Kawaguchi M, Jhala R. Liquid types. In: PLDI 2008. 2008 pp. 159–169.
- [4] Komuravelli A, Gurfinkel A, Chaki S. SMT-based model checking for recursive programs. Formal Methods Syst. Des., 2016. 48(3):175–205. URL https://doi.org/10.1007/s10703-016-0249-4.
- [5] Hojjat H, Rümmer P. The ELDARICA Horn Solver. In: 2018 Formal Methods in Computer Aided Design (FMCAD). 2018 pp. 1–7.
- [6] Champion A, Chiba T, Kobayashi N, Sato R. ICE-Based Refinement Type Discovery for Higher-Order Functional Programs. J. Autom. Reason., 2020. 64(7):1393–1418. URL https://doi.org/10.1007/s10817-020-09571-y.
- [7] Kobayashi N, Tsukada T, Watanabe K. Higher-Order Program Verification via HFL Model Checking. In: Ahmed A (ed.), Programming Languages and Systems - 27th European Symposium on Programming, ESOP 2018, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2018, Thessaloniki, Greece, April 14-20, 2018, Proceedings, volume 10801 of Lecture Notes in Computer Science. Springer, 2018 pp. 711–738. 10.1007/978-3-319-89884-1_25.
- [8] Viswanathan M, Viswanathan R. A Higher Order Modal Fixed Point Logic. In: CONCUR, volume 3170 of LNCS. Springer, 2004 pp. 512–528.
- [9] Watanabe K, Tsukada T, Oshikawa H, Kobayashi N. Reduction from branching-time property verification of higher-order programs to HFL validity checking. In: Hermenegildo MV, Igarashi A (eds.), Proceedings of the 2019 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM@POPL 2019, Cascais, Portugal, January 14-15, 2019. ACM, 2019 pp. 22–34. 10.1145/3294032.3294077.
- [10] Asada K, Katsura H, Kobayashi N. On Higher-Order Reachability Games Vs May Reachability. In: Lin AW, Zetzsche G, Potapov I (eds.), Reachability Problems - 16th International Conference, RP 2022, Kaiserslautern, Germany, October 17-21, 2022, Proceedings, volume 13608 of Lecture Notes in Computer Science. Springer, 2022 pp. 108–124. 10.1007/978-3-031-19135-0_8. URL https://doi.org/10.1007/978-3-031-19135-0_8.
- [11] Tsukada T. On Computability of Logical Approaches to Branching-Time Property Verification of Programs. In: Hermanns H, Zhang L, Kobayashi N, Miller D (eds.), LICS ’20: 35th Annual ACM/IEEE Symposium on Logic in Computer Science, Saarbrücken, Germany, July 8-11, 2020. ACM, 2020 pp. 886–899. 10.1145/3373718.3394766.
- [12] Iwayama N, Kobayashi N, Suzuki R, Tsukada T. Predicate Abstraction and CEGAR for HFLZ Validity Checking. In: Pichardie D, Sighireanu M (eds.), Static Analysis - 27th International Symposium, SAS 2020, Virtual Event, November 18-20, 2020, Proceedings, volume 12389 of Lecture Notes in Computer Science. Springer, 2020 pp. 134–155. 10.1007/978-3-030-65474-0_7.
- [13] Katsura H, Iwayama N, Kobayashi N, Tsukada T. A New Refinement Type System for Automated HFLZ Validity Checking. In: d S Oliveira BC (ed.), Programming Languages and Systems - 18th Asian Symposium, APLAS 2020, Fukuoka, Japan, November 30 - December 2, 2020, Proceedings, volume 12470 of Lecture Notes in Computer Science. Springer, 2020 pp. 86–104. 10.1007/978-3-030-64437-6_5.
- [14] Burn TC, Ong CL, Ramsay SJ. Higher-order constrained Horn clauses for verification. Proc. ACM Program. Lang., 2018. 2(POPL):11:1–11:28. 10.1145/3158099.
- [15] Cousot P, Cousot R. Constructive Versions of Tarski’s Fixed Point Theorems. Pacific Journal of Mathematics, 1979. 81(1):43–57.
- [16] Kobayashi N, Nishikawa T, Igarashi A, Unno H. Temporal Verification of Programs via First-Order Fixpoint Logic. In: Chang BE (ed.), Static Analysis - 26th International Symposium, SAS 2019, Porto, Portugal, October 8-11, 2019, Proceedings, volume 11822 of Lecture Notes in Computer Science. Springer, 2019 pp. 413–436. 10.1007/978-3-030-32304-2_20.
- [17] Kobayashi N, Tsukada T, Watanabe K. Higher-Order Program Verification via HFL Model Checking. CoRR, 2017. abs/1710.08614. A short version appeared in Proceedings of ESOP 2018.
- [18] Satake Y, Unno H, Yanagi H. Probabilistic Inference for Predicate Constraint Satisfaction. In: The Thirty-Fourth AAAI Conference on Artificial Intelligence, AAAI 2020, The Thirty-Second Innovative Applications of Artificial Intelligence Conference, IAAI 2020, The Tenth AAAI Symposium on Educational Advances in Artificial Intelligence, EAAI 2020. AAAI Press, 2020 pp. 1644–1651.
- [19] Champion A, Kobayashi N, Sato R. HoIce: An ICE-Based Non-linear Horn Clause Solver. In: Ryu S (ed.), Programming Languages and Systems - 16th Asian Symposium, APLAS 2018, Wellington, New Zealand, December 2-6, 2018, Proceedings, volume 11275 of Lecture Notes in Computer Science. Springer, 2018 pp. 146–156. 10.1007/978-3-030-02768-1_8.
- [20] Unno H, Satake Y, Terauchi T. Relatively complete refinement type system for verification of higher-order non-deterministic programs. Proc. ACM Program. Lang., 2018. 2(POPL):12:1–12:29. 10.1145/3158100.
- [21] Damm W. The IO- and OI-Hierarchies. Theor. Comput. Sci., 1982. 20:95–207.
- [22] Asada K, Kobayashi N. On Word and Frontier Languages of Unsafe Higher-Order Grammars. In: Chatzigiannakis I, Mitzenmacher M, Rabani Y, Sangiorgi D (eds.), 43rd International Colloquium on Automata, Languages, and Programming, ICALP 2016, July 11-15, 2016, Rome, Italy, volume 55 of LIPIcs. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik. ISBN 978-3-95977-013-2, 2016 pp. 111:1–111:13. 10.4230/LIPIcs.ICALP.2016.111.
- [23] Asada K, Kobayashi N. Size-Preserving Translations from Order-(n+1) Word Grammars to Order-n Tree Grammars. In: Ariola ZM (ed.), 5th International Conference on Formal Structures for Computation and Deduction, FSCD 2020, June 29-July 6, 2020, Paris, France (Virtual Conference), volume 167 of LIPIcs. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2020 pp. 22:1–22:22. 10.4230/LIPIcs.FSCD.2020.22.
- [24] Kobayashi N, Dal Lago U, Grellois C. On the Termination Problem for Probabilistic Higher-Order Recursive Programs. In: Proceedings of LICS 2019. IEEE, 2019 .
- [25] Ong CHL. On Model-Checking Trees Generated by Higher-Order Recursion Schemes. In: LICS 2006. IEEE Computer Society Press, 2006 pp. 81–90.
- [26] Kobayashi N, Ong CHL. Complexity of Model Checking Recursion Schemes for Fragments of the Modal Mu-Calculus. LMCS, 2011. 7(4).
- [27] Parys P. Higher-Order Model Checking Step by Step. In: Bansal N, Merelli E, Worrell J (eds.), 48th International Colloquium on Automata, Languages, and Programming, ICALP 2021, July 12-16, 2021, Glasgow, Scotland (Virtual Conference), volume 198 of LIPIcs. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2021 pp. 140:1–140:16. 10.4230/LIPIcs.ICALP.2021.140.
Appendix
Appendix A Proof of Lemma 4.9
We first prepare two substitution lemmas that correspond to the application rules Tr-App and Tr-AppI.
The following is the substitution lemma corresponding to Tr-AppI:
Lemma A.1 (Substitution lemma (integer))
Let be a formula that does not contain an explicit substitution, be a closed integer expression, and
where . Then we have
Proof A.2
By straightforward induction on .
Next we show the substitution lemma corresponding to Tr-App. First we prepare some definitions and a lemma.
For a formula , we write for . Note that the translation result of in Tr-App in Figure 3 can be written as the following:
, | ||||||
The following can be shown easily by induction on .
Lemma A.3 (weakening)
If
then
Now we show the substitution lemma. Here we consider simultaneous substitution, because we cannot apply this lemma repeatedly since below may contain an explicit substitution.
Lemma A.4 (Substitution lemma (higher-order))
Let be a formula that does not contain an explicit substitution, and
Then we have:
-
1.
.
-
2.
Proof A.5
We can show Item 1 easily by induction on and case analysis on the last rule used for the derivation . We show Item 2 by the same induction and case analysis. Basically the proof is straightforward, where we use the latter part of Lemma 4.4. Here we show only the cases of Tr-Var and Tr-App; in the latter case, we use Item 1.
Case of Tr-Var: Let the last rule be the following, where :