NN. Kobayashi (Ed.): Eighth Workshopon Intersection Types and Related Systems (ITRS 2016).EPTCS 242, 2017, pp. 48–63, doi:10.4204/EPTCS.242.6 c (cid:13)
P. ParysThis work is licensed under theCreative Commons Attribution License.
Intersection Types and Counting ∗ Paweł Parys
University of Warsaw, Poland [email protected]
We present a new approach to the following meta-problem: given a quantitative property of trees,design a type system such that the desired property for the tree generated by an infinitary ground λ -term corresponds to some property of a derivation of a type for this λ -term, in this type system.Our approach is presented in the particular case of the language finiteness problem for nondeter-ministic higher-order recursion schemes (HORSes): given a nondeterministic HORS, decide whetherthe set of all finite trees generated by this HORS is finite. We give a type system such that the HORScan generate a tree of an arbitrarily large finite size if and only if in the type system we can ob-tain derivations that are arbitrarily large, in an appropriate sense; the latter condition can be easilydecided. In this paper we consider λ Y -calculus, which is an extension of the simply typed λ -calculus by a fixed-point operator Y . A term P of λ Y -calculus that is of sort o can be used to generate an infinite tree BT ( P ) , called the Böhm tree of P . Trees generated by terms of λ Y -calculus can be used to faithfullyrepresent the control flow of programs in languages with higher-order functions. Traditionally, HigherOrder Recursive Schemes (HORSes) are used for this purpose [8, 12, 17, 16]; this formalism is equivalentto λ Y -calculus, and the translation between them is rather straightforward [22]. Collapsible PushdownSystems [10] and Ordered Tree-Pushdown Systems [7] are other equivalent formalisms.Intersection type systems were intensively used in the context of HORSes, for several purposes likemodel-checking [13, 16, 5, 21], pumping [14], transformations of HORSes [15, 6], etc. Interestingly,constructions very similar to intersection types were used also on the side of collapsible pushdown sys-tems; they were alternating stack automata [4], and types of stacks [19, 11].In this paper we show how intersection types can be used for deciding quantitative properties oftrees generated by λ Y -terms. We concentrate on the language finiteness problem for nondeterministicHORSes: given a nondeterministic HORS, decide whether the set of all finite trees generated by thisHORS is finite.This problem can be restated in the world of λ Y -terms (or standard, deterministic HORSes), gen-erating a single infinite tree. Here, instead of resolving nondeterministic choices during the generationprocess, we leave them in the resulting tree. Those nondeterministic choices are denoted by a distin-guished br (“branch”) symbol, below which we put options that could be chosen. Then to obtain a finitetree generated by the original HORS we just need to recursively choose in every br -labeled node which ofthe two subtrees we want to consider. Thus, in this setting, the language finiteness problem asks whetherthe set of all finite trees obtained this way is finite. ∗ Work supported by the National Science Center (decision DEC-2012/07/D/ST6/02443). A full version of this paper isavailable [20] We use the word “sort” instead of the usual “type” to avoid confusion with intersection types introduced in this paper. .Parys 49The difficulty of this problem lies in the fact that sometimes the same finite tree may be found ininfinitely many different places of BT ( P ) (i.e., generated by a nondeterministic HORS in many ways);thus the actual property to decide is whether there is a common bound on the size of each of these trees.This makes the problem inaccessible for standard methods used for analyzing HORSes, as they usuallyconcern only regular properties of the Böhm tree, while boundedness is a problem of different kind. Thesame difficulty was observed in [14], where they prove a pumping lemma for deterministic HORSes,while admitting (Remark 2.2) that their method is too weak to reason about nondeterministic HORSes.In order to solve the language finiteness problem, we present an appropriate intersection type system,where derivations are annotated by flags and markers of multiple kinds. The key property of this typesystem is that the number of flags in a type derivation for a λ Y -term P approximates the size of some finitetree obtained by resolving nondeterministic choices in the infinite tree BT ( P ) . In consequence, there aretype derivations using arbitrarily many flags if, and only if, the answer to the language finiteness problemis “no”.The language finiteness problem was first attacked in [1] (for safe HORSes only), but their algorithmturned out to be incorrect [2]. To our knowledge, the only known solution of this problem follows froma recent decidability result for the diagonal problem [9, 6]. This problem asks, given a nondeterministicHORS and a set of letters Σ , whether for every n ∈ N the HORS generates a finite tree in which everyletter from Σ appears at least n times. Clearly, a nondeterministic HORS generates arbitrarily large treesexactly when for some letter a it generates trees having arbitrarily many a letters, i.e., when the answerto the diagonal problem for Σ = { a } is “yes”.Our type system is, to some extent, motivated by the algorithm of [6] solving the diagonal problem.This algorithm works by repeating two kinds of transformations of HORSes. The first of them turns theHORS into a HORS generating trees having only a fixed number of branches, one per each letter from Σ (i.e., one branch in our case of | Σ | = a ∈ Σ there is a choice witnessing that a appeared many timesin the original tree. Then such a HORS of the special form is turned into a HORS that is of order lowerby one, and generates trees having the same nodes as trees generated by the original HORS, but arrangeddifferently (in particular, the new trees may have again arbitrarily many branches). After finitely manyrepetitions of this procedure, a HORS of order 0 is obtained, and the diagonal problem becomes easilydecidable. In some sense we want to do the same, but instead of applying all these transformations oneby one, we simulate all of them simultaneously in a single type derivation. In this derivation, for eachorder n , we allow to place arbitrarily one marker “of order n ”; this corresponds to the nondeterministicchoice of one branch in the n -th step of the previous algorithm. We also place some flags “of order n ”,in places that correspond to nodes remaining after the n -th step of the previous algorithm.The idea of using intersection types for counting is not completely new. Paper [18] presents a typesystem that, essentially, allows to estimate the size of the β -normal form of a λ -term just by looking at(the number of some flags in) a derivation of a type for this term. A similar idea, but for higher-orderpushdown automata, is present in [19], where we can estimate the number of ♯ symbols appearing on aparticular, deterministically chosen branch of the generated tree. This previous approach also uses inter-section types, where the derivations are marked with just one kind of flags, denoting “productive” placesof a λ -term (oppositely to our approach, where we have different flags for different orders, and we alsohave markers). The trouble with the “one-flag” approach is that it works well only in a completely deter-ministic setting, where looking independently at each node of the Böhm tree we know how it contributesto the result; the method stops working (or at least we do not know how to prove that it works) in oursituation, where we first nondeterministically perform some guesses in the Böhm tree, and only after thatwe want to count something that depends on the chosen values.0 Intersection Typesand Counting Acknowledgements.
I would like to thank Szymon Toru´nczyk for stimulating discussions, and anony-mous reviewers for useful comments.
Trees.
Let Σ be a ranked alphabet , i.e., a set of symbols together with a rank function assigning anonnegative integer to each of the symbols. We assume that Σ contains a distinguished symbol br ofrank 2, used to denote nondeterministic choices. A Σ -labeled tree is a tree that is rooted (there is adistinguished root node), node-labeled (every node has a label from Σ ), ranked (a node with label of rank n has exactly n children), and ordered (children of a node of rank n are numbered from 1 to n ).When t is a Σ -labeled tree t , by L ( t ) we denote the set of all finite trees that can be obtaining bychoosing in every br -labeled node of t which of the two subtrees we want to consider. More formally,we consider the following relation → br : we have t → br u if u can be obtained from t by choosing in t a br -labeled node x and its child y , and replacing the subtree starting in x by the subtree starting in y (whichremoves x and the other subtree of x ). Let → ∗ br be the reflexive transitive closure of → br . Then L ( t ) contains all trees u that do not use the br label, are finite, and such that t → ∗ br u . Infinitary λ -calculus. The set of sorts (a.k.a. simple types), constructed from a unique basic sort o using a binary operation → , is defined as usual. The order of a sort is defined by: ord ( o ) =
0, and ord ( α → β ) = max ( + ord ( α ) , ord ( β )) .We consider infinitary, sorted λ -calculus. Infinitary λ -terms (or just λ -terms ) are defined by coin-duction, according to the following rules: • if a ∈ Σ is a symbol of rank r , and P o , . . . , P or are λ -terms, then ( a P o . . . P or ) o is a λ -term, • for every sort α there are infinitely many variables x α , y α , z α , . . . ; each of them is a λ -term, • if P α → β and Q α are λ -terms, then ( P α → β Q α ) β is a λ -term, and • if P β is a λ -term and x α is a variable, then ( λ x α . P β ) α → β is a λ -term.We naturally identify λ -terms differing only in names of bound variables. We often omit the sort anno-tations of λ -terms, but we keep in mind that every λ -term (and every variable) has a particular sort. A λ -term P is closed if it has no free variables. Notice that, for technical convenience, a symbol of positiverank is not a λ -term itself, but always comes with arguments. This is not a restriction, since e.g. insteadof a unary symbol a one may use the term λ x . a x .The order of a λ -term is just the order of its sort. The complexity of a λ -term P is the smallest number m such that the order of every subterm of P is at most m . We restrict ourselves to λ -terms that have finitecomplexity.A β -reduction is defined as usual. We say that a β -reduction P → β Q is of order n if it concernsa redex ( λ x . R ) S such that ord ( λ x . R ) = n . In this situation the order of x is at most n −
1, but may besmaller (when other arguments of R are of order n − Böhm Trees.
We consider Böhm trees only for closed λ -terms of sort o . For such a term P , its Böhmtree BT ( P ) is constructed by coinduction, as follows: if there is a sequence of β -reductions from P to a λ -term of the form a P . . . P r (where a is a symbol), then the root of the tree t has label a and r children,and the subtree starting in the i -th child is BT ( P i ) . If there is no sequence of β -reductions from P to a.Parys 51 λ -term of the above form, then BT ( P ) is the full binary tree with all nodes labeled by br . By L ( P ) wedenote L ( BT ( P )) . λ Y -calculus. The syntax of λ Y -calculus is the same as that of finite λ -calculus, extended by symbols Y ( α → α ) → α , for each sort α . A term of λ Y -calculus is seen as a term of infinitary λ -calculus if wereplace each symbol Y ( α → α ) → α by the unique infinite λ -term Z such that Z is syntactically the same as λ x α → α . x ( Z x ) . In this way, we view λ Y -calculus as a fragment of infinitary λ -calculus.It is standard to convert a nondeterministic HORS G into a closed λ Y -term P o such that L ( P ) isexactly the set of all finite trees generated by G . The following theorem, which is our main result, statesthat the language finiteness problem is decidable. Theorem 1.
Given a closed λ Y -term P of sort o, one can decide whether L ( P ) is finite. In this section we introduce a type system that allows to determine the desired property: whether in L ( P ) there is an arbitrarily large tree. Intuitions.
The main novelty of our type system is in using flags and markers, which may label nodesof derivation trees. To every flag and marker we assign a number, called an order. While deriving a typefor a λ -term of complexity m , we may place in every derivation tree at most one marker of each order n ∈ { , . . . , m − } , and arbitrarily many flags of each order n ∈ { , . . . , m } .Consider first a λ -term M of complexity 0. Such a term actually equals its Böhm tree. Our aim isto describe some finite tree t in L ( M ) , i.e., obtained from M by resolving nondeterministic choices insome way. We thus just put flags of order 0 in all those (appearances of) symbols in M that contributeto this tree t ; the type system ensures that indeed all symbols of some finite tree in L ( M ) are labeledby a flag. Then clearly we have the desired property that there is a derivation with arbitrarily many flagsif, and only if, there are arbitrarily large trees in L ( M ) .Next, consider a λ -term M that is of complexity 1, and reduces to M . Of course every finite treefrom L ( M ) is composed of symbols appearing already in M ; we can thus already in M label (by order-0 flags) all symbols that contribute to some tree t ∈ L ( M ) (and an intersection type system can easilycheck correctness of such labeling). There is, however, one problem: a single appearance of a symbol in M may result in many appearances in M (since a function may use its argument many times). Due tothis, the number of order-0 flags in M does not correspond to the size of t . We rescue ourselves in thefollowing way. In t we choose one leaf, we label it by an order-0 marker, and on the path leading fromthe root to this marker we place order-1 flags. On the one hand, L ( M ) contains arbitrarily large treesif, and only if, it contains trees with arbitrarily long paths, i.e., trees with arbitrarily many order-1 flags.On the other hand, we can perform the whole labeling (and the type system can check its correctness)already in M , and the number of order-1 flags in M will be precisely the same as it would be in M .Indeed, in M we have only order-1 functions, i.e., functions that take trees and use them as subtrees oflarger trees; although a tree coming as an argument may be duplicated, the order-0 marker can be placedin at most one copy. This means that, while reducing M to M , every symbol of M can result in at most Usually one uses a special label ⊥ of rank 0 for this purpose, but from the perspective of our problem both definitions areequivalent. M lying on the selected path to the order-0 marker (beside of arbitrarily many symbolsoutside of this path).This procedure can be repeated for M of complexity 2 that reduces to M via β -reductions of order 2(and so on for higher orders). We now place a marker of order 1 in some leaf of M ; afterwards, we placean order-2 flag in every node that is on the path to the marked leaf, and that has a child outside of this pathwhose some descendant is labeled by an order-1 flag. In effect, for some choice of a leaf to be marked,the number of order-2 flags approximates the number of order-1 flags, up to logarithm. Moreover, thewhole labeling can be done in M instead of in M , without changing the number of order-2 flags.In this intuitive description we have talked about labeling “nodes of a λ -term”, but formally we labelnodes of a derivation tree that derives a type for the term, in our type system. Every such node containsa type judgment for some subterm of the term. Type Judgments.
For every sort α we define the set T α of types of sort α , and the set F α of fulltypes of sort α . This is done as follows, where P denotes the powerset: T α → β = P ( F α ord ( α → β ) ) × T β , T o = o , F α k = { ( k , F , M , τ ) | F , M ⊆ { , . . . , k − } , F ∩ M = /0 , τ ∈ T α } , F α = [ k ∈ N F α k . Notice that the sets T α and F α k are finite (unlike F α ). A type ( T , τ ) ∈ T α → β is denoted as T → τ . Afull type ˆ τ = ( k , F , M , τ ) ∈ F α k consists of its order k , a set F of flag orders, a set M of marker orders,and a type τ ; we write ord ( ˆ τ ) = k . In order to distinguish types from full types, the latter are denoted byletters with a hat, like ˆ τ .A type judgment is of the form Γ ⊢ P : ˆ τ ⊲ c , where Γ , called a type environment , is a function thatmaps every variable x α to a subset of F α , P is a λ -term, ˆ τ is a full type of the same sort as P (i.e.,ˆ τ ∈ F β when P is of sort β ), and c ∈ N .As usual for intersection types, the intuitive meaning of a type T → τ is that a λ -term having this typecan return a λ -term having type τ , while taking an argument for which we can derive all full types from T . Moreover, in T o there is just one type o , which can be assigned to every λ -term of sort o . Supposethat we have derived a type judgment Γ ⊢ P : ˆ τ ⊲ c with ˆ τ = ( m , F , M , τ ) . Then • τ is the type derived for P ; • Γ contains full types that could be used for free variables of P in the derivation; • m bounds the order of flags and markers that could be used in the derivation: flags could be oforder at most m , and markers of order at most m − • M ⊆ { , . . . , m − } contains the orders of markers used in the derivation, together with those pro-vided by free variables (i.e., we imagine that some derivations, specified by the type environment,are already substituted in our derivation for free variables); we, however, do not include markersprovided by arguments of the term (i.e., coming from the sets T i when τ = T → . . . → T k → o ); • F contains those numbers n ∈ { , . . . , m − } (excluding n = m ) for which a flag of order n is placedin the derivation itself, or provided by a free variable, or provided by an argument; for technicalconvenience we, however, remove n from F whenever n ∈ M (when n ∈ M , the information aboutorder- n flags results in placing an order- ( n + ) flag, and need not to be further propagated); • c , called a flag counter , counts the number of order- m flags present in the derivation..Parys 53 Type System.
Before giving rules of the type system, we need a few definitions. We use the symbol ⊎ to denote disjoint union. When A ⊆ N and n ∈ N , we write A ↾ < n for { k ∈ A | k < n } , and similarly A ↾ ≥ n for { k ∈ A | k ≥ n } . By ε we denote the type environment mapping every variable to /0, and by Γ [ x T ] the type environment mapping x to T and every other variable y to Γ ( y ) .Let us now say how a type environment Γ from the conclusion of a rule may be split into type envi-ronments ( Γ i ) i ∈ I used in premisses of the rule: we say that Split ( Γ | ( Γ i ) i ∈ I ) holds if and only if for everyvariable x it holds Γ i ( x ) ⊆ Γ ( x ) for every i ∈ I , and every full type from Γ ( x ) providing some markers(i.e., ( k , F , M , τ ) with M = /0) appears in some Γ i ( x ) . Full types with empty M may be discarded and du-plicated freely. This definition forbids to discard full types with nonempty M , and from elsewhere it willfollow that they cannot be duplicated. As a special case Split ( Γ | Γ ′ ) describes how a type environmentcan be weakened.All type derivations are assumed to be finite (although we derive types mostly for infinite λ -terms,each type derivation analyzes only a finite part of a term). Rules of the type system will guarantee thatthe order m of derived full types will be the same in the whole derivation (although in type environmentsthere may be full types of different orders).We are ready to give the first three rules of our type system: Γ ⊢ P i : ˆ τ ⊲ c i ∈ { , } Γ ⊢ br P P : ˆ τ ⊲ c (B R ) Split ( Γ | ε [ x
7→ { ( k , F , M ′ , τ ) } ]) M ↾ < k = M ′ Γ ⊢ x : ( m , F , M , τ ) ⊲ (V AR ) Γ ′ [ x T ] ⊢ P : ( m , F , M , τ ) ⊲ c Split ( Γ | Γ ′ ) Γ ′ ( x ) = /0 Γ ⊢ λ x . P : ( m , F , M \ [ ( k , F ′ , M ′ , σ ) ∈ T M ′ , T → τ ) ⊲ c ( λ ) We see that to derive a type for the nondeterministic choice br P P , we need to derive it either for P or for P .The (V AR ) rule allows to have in the resulting set M some numbers that do not come from the set M ′ assigned to x by the type environment; these are the orders of markers placed in the leaf using this rule.Notice, however, that we allow here only orders not smaller than k (which is the order of the superterm λ x . P binding this variable x ). This is consistent with the intuitive description of the type system (page51), which says that a marker of order n can be put in a place that will be a leaf after performing all β -reductions of orders greater than n . Indeed, the variable x remains a leaf after performing β -reductions oforders greater than k , but while performing β -reductions of order k this leaf will be replaced by a subtermsubstituted for x . Recall also that, by definition of a type judgment, we require that ( k , F , M ′ , τ ) ∈ F α k and ( m , F , M , τ ) ∈ F α m , for appropriate sort α ; this introduces a bound on maximal numbers that mayappear in the sets F and M . Example 1.
Denoting ˆ ρ = ( , /0 , { } , o ) we can derive: ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { } , o ) ⊲ (V AR ) ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { , } , o ) ⊲ (V AR ) In the derivation on the right, the marker of order 1 is placed in the conclusion of the rule.The ( λ ) rule allows to use (in a subderivation concerning the λ -term P ) the variable x with all fulltypes given in the set T . When the sort of λ x . P is α → β , by definition of T α → β we have that all fulltypes in T have the same order k = ord ( α → β ) (since ( T → τ ) ∈ T α → β ). Recall that we intend to store inthe set M the markers contained in the derivation itself and those provided by free variables, but not thoseprovided by arguments. Because of this, in the conclusion of the rule we remove from M the markersprovided by x . This operation makes sense only because there is at most one marker of each order, so4 Intersection Typesand Countingmarkers provided by x cannot be provided by any other free variable nor placed in the derivation itself.The set F , unlike M , stores also flags provided by arguments, so we do not need to remove anything from F . Example 2.
The ( λ ) rule can be used, e.g., in the following way (where a is a symbol of rank 1): ε [ x
7→ { ˆ ρ } ] ⊢ a x : ( , { } , { } , o ) ⊲ ε ⊢ λ x . a x : ( , { } , /0 , { ˆ ρ }→ o ) ⊲ ( λ ) ε [ x
7→ { ˆ ρ } ] ⊢ a x : ( , /0 , { , } , o ) ⊲ ε ⊢ λ x . a x : ( , /0 , { } , { ˆ ρ }→ o ) ⊲ ( λ ) Notice that in the conclusion of the rule, in both examples, we remove 0 from the set of marker orders,because the order-0 marker is provided by x .The next two rules use a predicate Comp m , saying how flags and markers from premisses contributeto the conclusion. It takes “as input” pairs ( F i , c i ) for i ∈ I ; each of them consists of the set of flagorders F i and of the flag counter c i from some premiss. Moreover, the predicate takes a set of markerorders M from the current type judgment (it contains orders of markers used in the derivation, includingthose provided by free variables). The goal is to compute the set of flag orders F and the flag counter c that should be placed in the current type judgment. First, for each n ∈ { , . . . , m } consecutively, wedecide whether a flag of order n should be placed on the current type judgment. We follow here the rulesmentioned in the intuitive description. Namely, we place a flag of order n if we are on the path leadingto the marker of order n − n − ∈ M ), and simultaneously we receive an information about aflag of order n −
1. By receiving this information we mean that either a flag of order n − n − F i . Actually, we place multiple flags of order n :one per each flag of order n − F i containing n −
1. Then, we compute F and c . In c we store the number of flags of the maximal order m : we sum allthe numbers c i , and we add the number of order- m flags placed on the current type judgment. In F wekeep elements of all F i , and we add the orders n of flags that were placed on the current type judgment.We, however, remove from F all elements of M . This is because every flag of some order n − n , in the closest ancestor that lies on the path leading to themarker of order n −
1. If we have created an order- n flag on the current type judgment, i.e., if n − ∈ M ,we do not want to do this again in the parent.Below we give a formal definition, in which f ′ n contains the number of order- n flags placed on thecurrent type judgment, while f n additionally counts the number of premisses for which n ∈ F i . We saythat Comp m ( M ; (( F i , c i )) i ∈ I ) = ( F , c ) when F = { n ∈ { , . . . , m − } | f n > ∧ n M } , c = f ′ m + ∑ i ∈ I c i , where, for n ∈ { , . . . , m } , f n = f ′ n + ∑ i ∈ I | F i ∩ { n }| , f ′ n = (cid:26) f n − if n − ∈ M , br : Γ i ⊢ P i : ( m , F i , M i , o ) ⊲ c i for each i ∈ { , . . . , r } M = M ′ ⊎ M ⊎ · · · ⊎ M r ( m = ) ⇒ ( F ′ = /0 ∧ c ′ = ) ( m > ) ⇒ ( F ′ = { } ∧ c ′ = ) ( r > ) ⇒ ( M ′ = /0 ) a = br Split ( Γ | Γ , . . . , Γ r ) Comp m ( M ; ( F ′ , c ′ ) , ( F , c ) , . . . , ( F r , c r )) = ( F , c ) Γ ⊢ a P . . . P r : ( m , F , M , o ) ⊲ c (C ON ) Here, the conditions in the second line say that in a node using the (C ON ) rule we always place aflag of order 0 (via F ′ or via c ′ , depending on m ), and that if the node is a leaf (i.e., r = M ′ ). Then to the Comp m predicate, beside of pairs ( F i , c i ) coming from premisses, we also pass the information ( F ′ , c ′ ) about the order-0 flag placed in thecurrent node; this predicate decides whether we should place also some flags of positive orders. Let usemphasize that in this rule (and similarly in the next rule) we have a disjoint union M ′ ⊎ M ⊎ · · · ⊎ M r ,which ensures that a marker of any order may be placed only in one node of a derivation. Example 3.
The (C ON ) rule may be instantiated in the following way: ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { } , o ) ⊲ ε [ x
7→ { ˆ ρ } ] ⊢ a x : ( , { } , { } , o ) ⊲ (C ON ) ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { , } , o ) ⊲ ε [ x
7→ { ˆ ρ } ] ⊢ a x : ( , /0 , { , } , o ) ⊲ (C ON ) In the left example, flags of order 0 and 1 are placed in the conclusion of the rule (a flag of order 0 iscreated because we are in a constant; since the marker of order 0 is visible, we do not put 0 into the set offlag orders, but instead we create a flag of order 1). In the right example, a marker of order 1 is visible,which causes that this time flags of order 0, 1, and 2 are placed in the conclusion of the (C ON ) rule (again,we do not put 0 nor 1 into the set of flag orders, because of 0 and 1 in the set of marker orders).The next rule describes application: Γ ′ ⊢ P : ( m , F ′ , M ′ , { ( ord ( P ) , F i ↾ < ord ( P ) , M i ↾ < ord ( P ) , τ i ) | i ∈ I }→ τ ) ⊲ c ′ Γ i ⊢ Q : ( m , F i , M i , τ i ) ⊲ c i for each i ∈ I M = M ′ ⊎ ] i ∈ I M i ord ( P ) ≤ m Split ( Γ | Γ ′ , ( Γ i ) i ∈ I ) Comp m ( M ; ( F ′ , c ′ ) , (( F i ↾ ≥ ord ( P ) , c i )) i ∈ I ) = ( F , c ) Γ ⊢ P Q : ( m , F , M , τ ) ⊲ c (@) In this rule, it is allowed (but in fact useless) that for two different i ∈ I the full types ( m , F i , M i , τ i ) are equal. It is also allowed that I = /0, in which case no type needs to be derived for Q . Observehow flags and markers coming from premisses concerning Q are propagated: only flags and markersof order n < ord ( P ) are visible to P , while only flags of order n ≥ ord ( P ) are passed to the Comp m predicate. This can be justified if we recall the intuitions staying behind the type system (see page 51).Indeed, while considering flags and markers of order n , we should imagine the λ -term obtained from thecurrent λ -term by performing all β -reductions of all orders greater than n ; the distribution of flags andmarkers of order n in the current λ -term actually simulates their distribution in this imaginary λ -term.Thus, if n < ord ( P ) , then our application will disappear in this imaginary λ -term, and Q will be alreadysubstituted somewhere in P ; for this reason we need to pass the information about flags and markers oforder n from Q to P . Conversely, if n ≥ ord ( P ) , then in the imaginary λ -term the considered applicationwill be still present, and in consequence the subterm corresponding to P will not see flags and markersof order n placed in the subterm corresponding to Q . Example 4.
Denote by ˆ τ f and ˆ τ m the types derived in Example 2:ˆ τ f = ( , { } , /0 , { ˆ ρ }→ o ) , and ˆ τ m = ( , /0 , { } , { ˆ ρ }→ o ) . Then, using the (@) rule, we can derive (where e is a symbol of rank 0, and f a variable): ε [ f
7→ { ˆ τ m } ] ⊢ f : ˆ τ m ⊲ (V AR ) ε ⊢ e : ( , { } , { } , o ) ⊲ (C ON ) ε [ f
7→ { ˆ τ f , ˆ τ m } ] ⊢ f e : ( , /0 , { , } , o ) ⊲ (@) Recall that ˆ ρ = ( , /0 , { } , o ) . In the conclusion of the (@) rule the information about a flag of order 1(from the second premiss) meets the information about the marker of order 1 (from the first premiss), and6 Intersection Typesand Countingthus a flag of order 2 is placed, which increases the flag counter. Notice that we have discarded the fulltype ˆ τ f assigned to f in the type environment; this is allowed because ˆ τ f provides no markers (equallywell ˆ τ f could be assigned to f also in one or two of the premisses, and discarded there). On the otherhand, the full type ˆ τ m provides markers, so it cannot be discarded nor duplicated (in particular, we couldnot pass it to the conclusion of the (C ON ) rule).The key property of the type system is described by the following theorem. Theorem 2.
Let P be a closed λ -term of sort o and complexity m. Then L ( P ) is infinite if and only iffor arbitrarily large c we can derive ε ⊢ P : ˆ ρ m ⊲ c, where ˆ ρ m = ( m , /0 , { , . . . , m − } , o ) . The left-to-right implication of Theorem 2 (completeness of the type system) is shown in Section4, while the opposite implication (soundness of the type system) in Section 5. In Section 6 we discusshow Theorem 1 follows from Theorem 2. Before all that, we give a few more examples of derivations,illustrating the type system and Theorem 2.
Example 5.
In this example we analyze the λ -term P = R ( λ x . a x ) , where R is defined by coinductionas R = ( λ f . br ( f e ) ( R ( λ x . f ( f x )))) . As previously, a and e are symbols of rank 1 and 0, respectively.In L ( P ) there are trees that consist of a branch of a symbols ended with an e symbol, but only thosewhere the number of a symbols is 2 k for some k ∈ N . Notice that the complexity of P is 2.Continuing Example 4, we derive the full type ˆ σ R = ( , /0 , { } , { ˆ τ f , ˆ τ m }→ o ) for R : ε [ f
7→ { ˆ τ f , ˆ τ m } ] ⊢ f e : ( , /0 , { , } , o ) ⊲ ε [ f
7→ { ˆ τ f , ˆ τ m } ] ⊢ br ( f e ) ( R ( λ x . f ( f x ))) : ( , /0 , { , } , o ) ⊲ (B R ) ε ⊢ R : ˆ σ R ⊲ ( λ ) Next, we derive the same full type for R , but using the second argument of the br symbol; this resultsin greater values of the flag counter. We start by deriving the full type ˆ τ f for the subterm λ x . f ( f x ) : ε [ f
7→ { ˆ τ f } ] ⊢ f : ˆ τ f ⊲ ε [ f
7→ { ˆ τ f } ] ⊢ f : ˆ τ f ⊲ ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { } , o ) ⊲ ε [ f
7→ { ˆ τ f } , x
7→ { ˆ ρ } ] ⊢ f x : ( , { } , { } , o ) ⊲ (@) ε [ f
7→ { ˆ τ f } , x
7→ { ˆ ρ } ] ⊢ f ( f x ) : ( , { } , { } , o ) ⊲ (@) ε [ f
7→ { ˆ τ f } ] ⊢ λ x . f ( f x ) : ˆ τ f ⊲ ( λ ) In the above derivation there are no flags nor markers. Next, we derive ˆ τ m for the same subterm: ε [ f
7→ { ˆ τ f } ] ⊢ f : ˆ τ f ⊲ ε [ f
7→ { ˆ τ m } ] ⊢ f : ˆ τ m ⊲ ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { } , o ) ⊲ ε [ f
7→ { ˆ τ m } , x
7→ { ˆ ρ } ] ⊢ f x : ( , /0 , { , } , o ) ⊲ (@) ε [ f
7→ { ˆ τ f , ˆ τ m } , x
7→ { ˆ ρ } ] ⊢ f ( f x ) : ( , /0 , { , } , o ) ⊲ (@) ε [ f
7→ { ˆ τ f , ˆ τ m } ] ⊢ λ x . f ( f x ) : ˆ τ m ⊲ ( λ ) Below the lower (@) rule the information about a flag of order 1 meets the information about the markerof order 1, and thus a flag of order 2 is placed, which increases the flag counter. We continue with the λ -term R : ε ⊢ R : ˆ σ R ⊲ c ε [ f
7→ { ˆ τ f } ] ⊢ λ x . f ( f x ) : ˆ τ f ⊲ ε [ f
7→ { ˆ τ f , ˆ τ m } ] ⊢ λ x . f ( f x ) : ˆ τ m ⊲ ε [ f
7→ { ˆ τ f , ˆ τ m } ] ⊢ R ( λ x . f ( f x )) : ( , /0 , { , } , o ) ⊲ c + (@) ε [ f
7→ { ˆ τ f , ˆ τ m } ] ⊢ br ( f e ) ( R ( λ x . f ( f x ))) : ( , /0 , { , } , o ) ⊲ c + (B R ) ε ⊢ R : ˆ σ R ⊲ c + ( λ ) .Parys 57In this fragment of a derivation no flag nor marker is placed. In particular, there is no order-2 flag inconclusion of the (@) rule, although its second premiss provides a flag of order 1 while the third premissprovides the marker of order 1. We recall from the definition of the (@) rule that the information aboutflags and markers coming from the arguments is divided into two parts. Numbers smaller than the orderof the operator ( ord ( R ) = ≥ Comp predicate.By composing the above fragments of a derivation, we can derive ε ⊢ R : ˆ σ R ⊲ c for every c ≥ ε ⊢ λ x . a x : ˆ τ f ⊲ ε ⊢ λ x . a x : ˆ τ m ⊲
1. Together with theabove, this allows to derive for P the full type ˆ ρ = ( , /0 , { , } , o ) (appearing in Theorem 2): ε ⊢ R : ˆ σ R ⊲ c ε ⊢ λ x . a x : ˆ τ f ⊲ ε ⊢ λ x . a x : ˆ τ m ⊲ ε ⊢ P : ˆ ρ ⊲ c + (@) We can notice a correspondence between a derivation with flag counter c + L ( P ) of size2 c − +
1. We remark that in every of these derivations only three flags of order 0 and only three flags oforder 1 are present, in the three nodes using the (C ON ) rule. Example 6.
Consider a similar λ -term P = R ( λ x . b x x ) , where R is as previously, and b is a symbol ofrank 2. In L ( P ) we have, for every k ∈ N , a full binary tree in which every branch consist of 2 k symbols b and ends with an e symbol.This time for the subterm λ x . b x x we need to derive three full types:ˆ τ ′ = ( , { } , /0 , { ( , { } , /0 , o ) }→ o ) , ˆ τ ′ f = ( , { } , /0 , { ( , { } , /0 , o ) , ˆ ρ }→ o ) , andˆ τ ′ m = ( , /0 , { } , { ( , { } , /0 , o ) , ˆ ρ }→ o ) . The last one is derived with flag counter 1. Notice that ˆ τ ′ f and ˆ τ ′ m need now two full types for the argument x ; the new one ( , { } , /0 , o ) describes the subtree that is not on the path to the order-0 marker. We alsohave a new full type ˆ τ ′ that describes the use of λ x . b x x outside of the path to the order-0 marker.Then, similarly as in the previous example, for every c ≥ ε ⊢ R : ˆ σ ′ R ⊲ c , whereˆ σ ′ R = ( , /0 , { } , { ˆ τ ′ , ˆ τ ′ f , ˆ τ ′ m }→ o ) . Again, this allows to derive ε ⊢ P : ˆ ρ ⊲ c +
1. This time a derivationwith flag counter c + L ( P ) of size 2 h − h = c − + Example 7.
Next, consider the λ -term P = R ( λ x . x ) . The only tree in L ( P ) consists of a single e node.Let us see how the derivation from Example 5 has to be modified. The full type ˆ τ m can still be derivedfor λ x . x (although with flag counter 0 now), but instead of ˆ τ f we have to use ˆ τ ′′ f = ( , /0 , /0 , { ˆ ρ }→ o ) thatprovides no flag of order 1: ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { } , o ) ⊲ (V AR ) ε ⊢ λ x . x : ˆ τ ′′ f ⊲ ( λ ) ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { , } , o ) ⊲ (V AR ) ε ⊢ λ x . x : ˆ τ m ⊲ ( λ ) Next, for R we want to derive the full type ˆ σ ′′ R = ( , /0 , { } , { ˆ τ ′′ f , ˆ τ m }→ o ) . We can easily adopt everyof the previous derivations for ε ⊢ R : ˆ σ R ⊲ c : we basically replace every ˆ τ f by ˆ τ ′′ f . The key point isthat while deriving the full type ˆ τ m for the subterm λ x . f ( f x ) , previously in the lower (@) rule we havereceived information about an order-1 flag, and thus we have created an order-2 flag and increased theflag counter; this time there is no information about an order-1 flag, and thus we do not create an order-2flag and do not increase the flag counter. In consequence, even if this part of the derivation is repeatedarbitrarily many times, the value of the flag counter of the whole derivation remains 1.8 Intersection Typesand Counting Example 8.
Finally, consider the λ -term P = ( λ g . P ) ( λ x . a ( a ( . . . ( a x ) . . . )) , which β -reduces to P .Notice that we can create the following derivation: ε [ x
7→ { ˆ ρ } ] ⊢ x : ( , /0 , { } , o ) ⊲ (V AR ) ε [ x
7→ { ˆ ρ } ] ⊢ a x : ( , { } , { } , o ) ⊲ (C ON ) ... (C ON ) ε [ x
7→ { ˆ ρ } ] ⊢ a ( a ( . . . ( a x ) . . . )) : ( , { } , { } , o ) ⊲ (C ON ) ε ⊢ λ x . a ( a ( . . . ( a x ) . . . )) : ˆ τ f ⊲ ( λ ) Every (C ON ) rule used in this derivation places in its conclusion an order-0 flag and an order-1 flag. Thisderivation can be used as a part of a derivation for P : ε [ g
7→ { ˆ τ f } ] ⊢ P : ˆ ρ ⊲ ε ⊢ λ g . P : ( , /0 , { , } , { ˆ τ f }→ o ) ⊲ ( λ ) ε ⊢ λ x . a ( a ( . . . ( a x ) . . . )) : ˆ τ f ⊲ ε ⊢ P : ˆ ρ ⊲ (@) Because ˆ τ f provides no markers, it can be removed from the type environment and thus for P we canuse the derivation from the previous example. We thus obtain a derivation for P in which there are manyorder-0 and order-1 flags (but only one flag of order 2). This shows that in the flag counter we indeedneed to count only the number of flags of the maximal order (not, say, the total number of flags of allorders). The proof of the left-to-right implication of Theorem 2 is divided into the following three lemmata.Recall that a β -reduction P → β Q is of order n if it concerns a redex ( λ x . R ) S such that ord ( λ x . R ) = n .The number of nodes of a tree t is denoted | t | . As in Theorem 2, we denote ˆ ρ m = ( m , /0 , { , . . . , m − } , o ) . Lemma 3.
Let P be a closed λ -term of sort o and complexity m, and let t ∈ L ( P ) . Then there exist λ -terms Q m , Q m − , . . . , Q such that P = Q m , and for every k ∈ { , . . . , m } the term Q k − can be reachedfrom Q k using only β -reductions of order k, and we can derive ε ⊢ Q : ˆ ρ ⊲ | t | . Lemma 4.
Suppose that we can derive ε ⊢ P : ˆ ρ m ⊲ c. Then we can also derive ε ⊢ P : ˆ ρ m + ⊲ c ′ for somec ′ ≥ log c. Lemma 5.
Suppose that P → β Q is a β -reduction of order m, and we can derive Γ ⊢ Q : ˆ τ ⊲ c withord ( ˆ τ ) = m. Then we can also derive Γ ⊢ P : ˆ τ ⊲ c. Now the left-to-right implication of Theorem 2 easily follows. Indeed, take a closed λ -term P ofsort o and complexity m such that L ( P ) is infinite, and take any c ∈ N . By log k we denote the k -foldapplication of the logarithm: log x = x and log k + x = log ( log k x ) . Since L ( P ) is infinite, it containsa tree t so big that log m | t | ≥ c . We apply Lemma 3 to this tree, obtaining λ -terms Q m , Q m − , . . . , Q and a derivation of ε ⊢ Q : ˆ ρ ⊲ | t | . Then repeatedly for every k ∈ { , . . . , m } we apply Lemma 4,obtaining a derivation of ε ⊢ Q k − : ˆ ρ k ⊲ c k for some c k ≥ log k | t | , and Lemma 5 for every β -reduction(of order k ) between Q k and Q k − , obtaining a derivation of ε ⊢ Q k : ˆ ρ k ⊲ c k . We end with a derivationof ε ⊢ P : ˆ ρ m ⊲ c m , where c m ≥ log m | t | ≥ c , as needed. In the remaining part of this section we prove thethree lemmata..Parys 59 Proof of Lemma 3 (sketch).
Recall that t ∈ L ( P ) is a finite tree, thus it can be found in some finiteprefix of the Böhm tree of P . By definition, this prefix will be already expanded after performing somefinite number of β -reductions from P . We need to observe that these β -reductions can be rearranged,so that those of higher order are performed first. The key point is to observe that when we perform a β -reduction of some order k , then no new β -redexes of higher order appear in the term. Indeed, supposethat ( λ x . R ) S is changed into R [ S / x ] somewhere in a term, where ord ( λ x . R ) = k . One new redex thatmay appear is when R starts with a λ , and to the whole R [ S / x ] some argument is applied; this redex isof order ord ( R ) ≤ k . Some other redexes may appear when S starts with a λ , and is substituted for suchappearance of x to which some argument is applied; but this redex is of order ord ( S ) < k .We can thus find a sequence of β -reductions in which β -reductions are arranged according to theirorder, that leads from P to some Q such that t can be found in the prefix of Q that is already expandedto a tree. It is now a routine to use the rules of our type system and derive ε ⊢ Q : ˆ ρ ⊲ | t | : in every br -labeled node we choose the subtree in which t continues, and this effects in counting the number ofnodes of t in the flag counter. Proof of Lemma 4.
Consider some derivation of ε ⊢ P : ˆ ρ m ⊲ c . In this derivation we choose a leaf inwhich we will put the order- m marker, as follows. Starting from the root of the derivation, we repeatedlygo to this premiss in which the flag counter is the greatest (arbitrarily in the case of a tie). In every nodethat is not on the path to the selected leaf, we replace the current type judgment Γ ⊢ Q : ( m , F , M , τ ) ⊲ d by Γ ⊢ Q : ( m + , F ′ , M , τ ) ⊲
0, where F ′ = F ∪ { m } if d >
0, and F ′ = F otherwise. In the selected leafand all its ancestors, we change the order from m to m +
1, we add m to the set of marker orders, and werecalculate the flag counter.Let us see how such transformation changes the flag counter on the path to the selected leaf. Wewill prove (by induction) that the previous value d and the new value d ′ of the flag counter in everynode on this path satisfy d ′ ≥ log d . In the selected leaf itself, the flag counter (being either 0 or1) remains unchanged; we have d ′ = d ≥ log d . Next, consider any proper ancestor of the selectednode. Let k be the number of those of its children in which the flag counter was positive, plus thenumber of order- m flags placed in the considered node itself. Let also d max and d ′ max be the previousvalue and the new value of the flag counter in this child that is in the direction of the selected leaf.By construction, the flag counter in this child was maximal, which implies k · d max ≥ d , while by theinduction assumption d ′ max ≥ log d max . To d ′ we take the flag counter only from the special child, whilefor other children with positive flag counter we add 1, i.e., d ′ = k − + d ′ max . Altogether we obtain d ′ = k − + d ′ max ≥ k − + log d max ≥ log ( k · d max ) ≥ log d , as required. Proof of Lemma 5.
We consider the base case when P = ( λ x . R ) S and Q = R [ S / x ] ; the general situation(redex being deeper in P ) is easily reduced to this one. In the derivation of Γ ⊢ Q : ˆ τ ⊲ c we identify theset I of places (nodes) where we derive a type for S substituted for x . For i ∈ I , let Σ i ⊢ S : ˆ σ i ⊲ d i be thetype judgment in i . We change the nodes in I into leaves, where we instead derive ε [ x
7→ { ˆ σ i } ] ⊢ x : ˆ σ i ⊲ S by x in λ -terms, and decreasing flag counters. In this way we obtain derivations of Σ i ⊢ S : ˆ σ i ⊲ d i for every i ∈ I , and a derivation of Σ ′ ⊢ R : ˆ τ ⊲ d , where Σ ′ = Σ [ x
7→ { ˆ σ i | i ∈ I } ] with Σ ( x ) = /0, and Split ( Γ | Σ , ( Σ i ) i ∈ I ) , and c = d + Σ i ∈ I d i . To the latter type judgment we apply the ( λ ) rule, and then wemerge it with the type judgments for S using the (@) rule, which results in a derivation for Γ ⊢ P : ˆ τ ⊲ c .We remark that different i ∈ I may give identical type judgments for S (as long as the set of markersin ˆ σ i is empty); this is not a problem. The (@) rule requires that ord ( ˆ σ i ) = ord ( λ x . R ) ; we have that ord ( ˆ σ i ) = ord ( ˆ τ ) , and ord ( ˆ τ ) = m = ord ( λ x . R ) by assumption.0 Intersection Typesand Counting In this section we sketch the proof of the right-to-left implication of Theorem 2. We, basically, need toreverse the proof from the previous section. The following new fact is now needed.
Lemma 6.
If we can derive Γ ⊢ P : ( m , F , M , τ ) ⊲ c with m − M and ord ( P ) ≤ m − , then c = . A simple inductive proof is based on the following idea: flags of order m are created only when amarker of order m − m − M ), and the arguments, i.e. sets T , . . . , T k in τ = T → . . . → T k → o , may provide only markers oforder at most ord ( P ) − ≤ m − m can be created.We say that a λ -term of the form P Q is an application of order n when ord ( P ) = n , and that an (@) rule is of order n if it derives a type for an application of order n . We can successively removeapplications of the maximal order from a type derivation. Lemma 7.
Suppose that ε ⊢ P : ˆ ρ m ⊲ c for m > is derived by a derivation D in which the (@) rule oforder m is used n times. Then there exists Q such that P → β Q and ε ⊢ Q : ˆ ρ m ⊲ c can be derived by aderivation D ′ in which the (@) rule of order m is used less than n times. Recall from the definition of the type system that the (@) rule of orders higher than m cannot beused while deriving a full type of order m . Thus in D we have type judgments only for subterms of P of order at most m (although P may also have subterms of higher orders), and in type environments weonly have variables of order at most m −
1. In order to prove Lemma 7 we choose in P a subterm R S with ord ( R ) = m such that there is a type judgment for R S in some nodes of D (at least one), but nodescendants of those nodes use the (@) rule of order m . Since R is of order m , it cannot be an application(then we would choose it instead of R S ) nor a variable; thus R = λ x . R ′ . We obtain Q by reducing theredex ( λ x . R ′ ) S ; the derivation D ′ is obtained by performing a surgery on D similar to that in the proofof Lemma 5 (but in the opposite direction). Notice that every full type ( m , F , M , τ ) (derived for S ) withnonempty M is used for exactly one appearance of x in the derivation for R ′ ; full types with empty M maybe used many times, or not used at all, but thanks to Lemma 6 duplicating or removing the correspondingderivations for S does not change the flag counter. In the derivations for R ′ [ S / x ] no (@) rule of order m may appear, and the application R S disappears, so the total number of (@) rules of order m decreases.When all (@) rules of order m are eliminated, we can decrease m . Lemma 8.
Suppose that ε ⊢ P : ˆ ρ m ⊲ c for m > is derived by a derivation D in which the (@) rule oforder m is not used. Then we can also derive ε ⊢ P : ˆ ρ m − ⊲ c ′ for some c ′ ≥ c. The proof is easy; we simply decrease the order m of all derived full types by 1, and we ignore flagsof order m and markers of order m −
1. To obtain the inequality c ′ ≥ c we observe that when no (@) ruleof order m is used, the information about flags of order m − m is created because of a different flag of order m − ε ⊢ P : ˆ ρ m ⊲ c we obtain aderivation of ε ⊢ Q : ˆ ρ ⊲ c ′ , where P → ∗ β Q and c ′ ≥ c . Since ˆ ρ is of order 0, using the latter derivation itis easy to find in the already expanded part of Q (and thus in L ( Q ) = L ( P ) ) a tree t such that | t | = c ′ ≥ c . Finally, we show how Theorem 1 follows from Theorem 2, i.e., how given a λ Y -term P of complexity m we can check whether ε ⊢ P : ˆ ρ m ⊲ c can be derived for arbitrarily large c . We say that two type judgmentsare equivalent if they differ only in the value of the flag counter. Let us consider a set D of all derivations.Parys 61of ε ⊢ P : ˆ ρ m ⊲ c in which on each branch (i.e., each root-leaf path) there are at most three type judgmentsfrom every equivalence class, and among premisses of each (@) rule there is at most one type judgmentfrom every equivalence class. These derivations use only type judgments Γ ⊢ Q : ˆ τ ⊲ d with Q being asubterm of P and with Γ ( x ) = /0 only for variables x appearing in P . Since a finite λ Y -term, even whenseen as an infinitary λ -term, has only finitely many subterms, this introduces a common bound on theheight of all derivations in D , and on their degree (i.e., on the maximal number of premisses of a rule).It follows that there are only finitely many derivations in D , and thus we can compute all of them.We claim that ε ⊢ P : ˆ ρ m ⊲ c can be derived for arbitrarily large c if and only if in D there is aderivation in which on some branch there are two equivalent type judgments with different values of theflag counter (and the latter condition can be easily checked). Indeed, having such a derivation, we canrepeat its fragment between the two equivalent type judgments, obtaining derivations of ε ⊢ P : ˆ ρ m ⊲ c with arbitrarily large c . We use here an additivity property of our type system: if out of Γ ⊢ Q : ˆ τ ⊲ d we can derive Γ ′ ⊢ Q ′ : ˆ τ ′ ⊲ d ′ , then out of Γ ⊢ Q : ˆ τ ⊲ d + k we can derive Γ ′ ⊢ Q ′ : ˆ τ ′ ⊲ d ′ + k , for every k ≥ − d . Conversely, take a derivation of ε ⊢ P : ˆ ρ m ⊲ c for some large enough c . Suppose that some ofits (@) rules uses two equivalent premisses. These premisses concern the argument subterm, which isof smaller order than the operator subterm, and thus of order at most m −
1. The set of marker ordersin these premisses has to be empty, as the sets of marker orders from all premisses have to be disjoint.Thus, by Lemma 6, the flag counter in our two premisses is 0. In consequence, we can remove one ofthe premisses, without changing anything in the remaining part of the derivation, even the flag counters.In this way we clean the whole derivation, so that at the end among premisses of each (@) rule there isat most one type judgment from every equivalence class. The degree is now bounded, and at each nodethe flag counter grows only by a constant above the sum of flag counters from the children. Thus, if c is large enough, we can find on some branch two equivalent type judgments with different values of theflag counter. Then, for some pairs of equivalent type judgments, we remove the part of the derivationbetween these type judgments (and we adopt appropriately the flag counters in the remaining part). It itnot difficult to perform this cleaning so that the resulting derivation will be in D , and simultaneously onsome branch there will remain two equivalent type judgments with different values of the flag counter. In this paper, we have shown an approach for expressing quantitative properties of Böhm trees usingan intersection type system, on the example of the finiteness problem. It is an ongoing work to applythis approach to the diagonal problem, which should give a better complexity than that of the algorithmfrom [6]. Another ongoing work is to obtain an algorithm for model checking Böhm trees with respectto the Weak MSO+U logic [3]. This logic extends Weak MSO by a new quantifier U, expressing thata subformula holds for arbitrarily large finite sets. Furthermore, it seems feasible that our methods mayhelp in proving a pumping lemma for nondeterministic HORSes.
References [1] Achim Blumensath (2008):
On the Structure of Graphs in the Caucal Hierarchy . Theor.Comput.Sci.400(1-3), pp. 19–45, doi:10.1016/j.tcs.2008.01.053.[2] Achim Blumensath (2013):
Erratum to "On the Structure of Graphs in the Caucal Hierarchy" [Theoret.Comput. Sci 400 (2008) 19-45] . Theor.Comput.Sci. 475, pp. 126–127, doi:10.1016/j.tcs.2012.12.044. [3] Mikołaj Boja´nczyk & Szymon Toru´nczyk (2012):
Weak MSO+U over Infinite Trees . In Christoph Dürr &Thomas Wilke, editors: 29thInternationalSymposiumonTheoreticalAspectsofComputerScience,STACS2012, February 29th - March 3rd, 2012, Paris, France, LIPIcs 14, Schloss Dagstuhl - Leibniz-Zentrum fuerInformatik, pp. 648–660, doi:10.4230/LIPIcs.STACS.2012.648.[4] Christopher H. Broadbent, Arnaud Carayol, Matthew Hague & Olivier Serre (2012):
A Saturation Methodfor Collapsible Pushdown Systems . In Artur Czumaj, Kurt Mehlhorn, Andrew M. Pitts & Roger Wattenhofer,editors: Automata, Languages, and Programming- 39th InternationalColloquium, ICALP 2012, Warwick,UK,July9-13,2012,Proceedings,PartII, LectureNotesinComputerScience 7392, Springer, pp. 165–176,doi:10.1007/978-3-642-31585-5_18.[5] Christopher H. Broadbent & Naoki Kobayashi (2013):
Saturation-Based Model Checking of Higher-OrderRecursion Schemes . In Simona Ronchi Della Rocca, editor: ComputerScienceLogic2013(CSL2013),CSL2013, September 2-5, 2013, Torino, Italy, LIPIcs 23, Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik,pp. 129–148, doi:10.4230/LIPIcs.CSL.2013.129.[6] Lorenzo Clemente, Pawel Parys, Sylvain Salvati & Igor Walukiewicz (2016):
The Diagonal Problem forHigher-Order Recursion Schemes is Decidable . In Martin Grohe, Eric Koskinen & Natarajan Shankar, edi-tors: Proceedingsofthe31stAnnualACM/IEEESymposiumonLogicinComputerScience,LICS’16,NewYork,NY,USA,July5-8,2016, ACM, pp. 96–105, doi:10.1145/2933575.2934527.[7] Lorenzo Clemente, Paweł Parys, Sylvain Salvati & Igor Walukiewicz (2015):
Ordered Tree-PushdownSystems . In Prahladh Harsha & G. Ramalingam, editors: 35th IARCS Annual Conference on Foun-dation of Software Technology and Theoretical Computer Science, FSTTCS 2015, December 16-18,2015, Bangalore, India, LIPIcs 45, Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, pp. 163–177,doi:10.4230/LIPIcs.FSTTCS.2015.163.[8] Werner Damm (1982):
The IO- and OI-Hierarchies . Theor. Comput. Sci. 20, pp. 95–207,doi:10.1016/0304-3975(82)90009-3.[9] Matthew Hague, Jonathan Kochems & C.-H. Luke Ong (2016):
Unboundedness and Downward Closuresof Higher-Order Pushdown Automata . In Rastislav Bodík & Rupak Majumdar, editors: Proceedingsof the43rdAnnualACMSIGPLAN-SIGACTSymposiumonPrinciplesofProgrammingLanguages,POPL2016,St.Petersburg,FL,USA,January20-22,2016, ACM, pp. 151–163, doi:10.1145/2837614.2837627.[10] Matthew Hague, Andrzej S. Murawski, C.-H. Luke Ong & Olivier Serre (2008):
Collapsible PushdownAutomata and Recursion Schemes . In: ProceedingsoftheTwenty-ThirdAnnualIEEESymposiumonLogicinComputerScience,LICS2008,24-27June2008,Pittsburgh,PA,USA, IEEE Computer Society, pp. 452–461, doi:10.1109/LICS.2008.34.[11] Alexander Kartzow & Paweł Parys (2012):
Strictness of the Collapsible Pushdown Hierarchy . In BranislavRovan, Vladimiro Sassone & Peter Widmayer, editors: Mathematical Foundations of Computer Science2012- 37thInternationalSymposium,MFCS 2012,Bratislava, Slovakia,August27-31,2012.Proceedings,LectureNotesinComputerScience 7464, Springer, pp. 566–577, doi:10.1007/978-3-642-32589-2_50.[12] Teodor Knapik, Damian Niwi´nski & Paweł Urzyczyn (2002):
Higher-Order Pushdown Trees Are Easy . InMogens Nielsen & Uffe Engberg, editors: Foundations of Software Science and Computation Structures,5th International Conference, FOSSACS 2002. Held as Part of the Joint European Conferences on Theoryand Practice of Software, ETAPS 2002 Grenoble, France, April 8-12, 2002, Proceedings, Lecture Notes inComputerScience 2303, Springer, pp. 205–222, doi:10.1007/3-540-45931-6_15.[13] Naoki Kobayashi (2009):
Types and Higher-Order Recursion Schemes for Verification of Higher-Order Pro-grams . In Zhong Shao & Benjamin C. Pierce, editors: Proceedings of the 36th ACM SIGPLAN-SIGACTSymposium on Principles of Programming Languages, POPL 2009, Savannah, GA, USA, January 21-23,2009, ACM, pp. 416–428, doi:10.1145/1480881.1480933.[14] Naoki Kobayashi (2013):
Pumping by Typing . In: 28th Annual ACM/IEEE Symposium on Logic in Com-puterScience,LICS2013,NewOrleans,LA,USA,June25-28,2013, IEEE Computer Society, pp. 398–407,doi:10.1109/LICS.2013.46. .Parys 63 [15] Naoki Kobayashi, Kazuhiro Inaba & Takeshi Tsukada (2014):
Unsafe Order-2 Tree Languages Are Context-Sensitive . In Anca Muscholl, editor: Foundations of Software Science and Computation Structures - 17thInternationalConference, FOSSACS 2014, Held as Part of the European Joint Conferences on Theory andPracticeofSoftware,ETAPS2014,Grenoble,France,April5-13,2014,Proceedings, LectureNotesinCom-puterScience 8412, Springer, pp. 149–163, doi:10.1007/978-3-642-54830-7_10.[16] Naoki Kobayashi & C.-H. Luke Ong (2009):
A Type System Equivalent to the Modal Mu-Calculus ModelChecking of Higher-Order Recursion Schemes . In: Proceedings of the 24th Annual IEEE Symposium onLogicinComputerScience,LICS2009,11-14August2009,LosAngeles,CA,USA, IEEE Computer Soci-ety, pp. 179–188, doi:10.1109/LICS.2009.29.[17] C.-H. Luke Ong (2006):
On Model-Checking Trees Generated by Higher-Order Recursion Schemes . In:21thIEEESymposiumonLogicinComputerScience(LICS2006),12-15August2006,Seattle,WA,USA,Proceedings, IEEE Computer Society, pp. 81–90, doi:10.1109/LICS.2006.38.[18] Pawel Parys (2016):
A Characterization of Lambda-Terms Transforming Numerals . J. Funct. Program. 26,p. e12, doi:10.1017/S0956796816000113.[19] Paweł Parys (2012):
On the Significance of the Collapse Operation . In: Proceedings of the 27th AnnualIEEE Symposiumon Logicin ComputerScience, LICS 2012,Dubrovnik,Croatia, June25-28,2012, IEEEComputer Society, pp. 521–530, doi:10.1109/LICS.2012.62.[20] Paweł Parys (2017):
Intersection Types and Counting . CoRR abs/1701.05303v1. Available at http://arxiv.org/abs/1701.05303v1 .[21] Steven J. Ramsay, Robin P. Neatherway & C.-H. Luke Ong (2014):
A Type-Directed Abstraction RefinementApproach to Higher-Order Model Checking . In Suresh Jagannathan & Peter Sewell, editors: The41stAnnualACMSIGPLAN-SIGACTSymposiumonPrinciplesofProgrammingLanguages,POPL’14,SanDiego,CA,USA,January20-21,2014, ACM, pp. 61–72, doi:10.1145/2535838.2535873.[22] Sylvain Salvati & Igor Walukiewicz (2016):