Higher order interpretations for higher order complexity: extended abstract Emmanuel Hainry12 and Romain Péchoux13 1 INRIA project Carte, LORIA and Université de Lorraine 2 [email protected] 3 [email protected] Abstract We design an interpretation-based theory of higher order functions that is well-suited for the complexity analysis of a standard higher order functional language à la ML. We manage to express the interpretation of a given program in terms of a least fixpoint and we show that when restricted to functions bounded by higher order polynomials, they characterize exactly classes of tractable functions known as Basic Feasible Functions at any order. 1 Functional language Syntax. The language considered in this paper consists in a lambda calculus with constructors, primitive operators, a ππππ construct for pattern matching and a ππππππ instruction for (recursive) function definitions. It can be seen as an extension of PCF to inductive data types. A term of our language is defined by the following syntax: πΌ, π½ βΆβΆ= π‘ | π | ππ | πΌ π½ | ππ‘.πΌ | ππππππ π = πΌ | ππππ πΌ ππ π1 (βββ π‘β1 ) β πΌ1 |...|ππ (βββ π‘βπ ) β πΌπ In the above syntax, π, π1 , β― , ππ are constructor symbols of fixed arity and ππ is an operator of fixed arity. Given a constructor or operator symbol π, we write ππ(π) = π whenever π is of arity π. π‘, π are variables in ξ and π‘βββπ is a sequence of ππ(ππ ) variables. The free variables πΉ π (πΌ) of a term πΌ are defined as usual. Finally, a closed term will consist in a term πΌ such that πΉ π (πΌ) = β (i.e. with no free variables). A substitution {π½1 βπ‘1 , β― , π½π βπ‘π } is a partial function mapping variables π‘1 , β― , π‘π to terms π½1 , β― , π½π . Semantics. The semantics of our language is described by a relation βξΏ between two terms defined by βξΏ =βπ½ βͺ βππππ βͺ βππ βͺ βππππππ β’ βπ½ is the standard π½-reduction defined by ππ‘.πΌ π½ βπ½ πΌ{π½βπ‘}, β’ βππππ corresponds to pattern matching and is defined by: ββββπ ) of β¦ | ππ (βββ ββββπ ββββ case ππ (π½ π‘βπ ) β πΌπ | β¦ βππππ πΌπ {π½ π‘βπ }, β’ βππππππ is a fixpoint evaluation defined by ππππππ π = πΌ βππππππ πΌ{ππππππ π = πΌβπ}, β’ βππ is an operator evaluation defined by ππ πΌ1 β¦ πΌπ βππ πΌ, provided that ππ is a primitive operator of arity π whose semantics JππK, fixed by the language implementation, is a total function that satisfies JππK(πΌ1 , β¦ , πΌπ ) = πΌ. In the particular case, where the pattern matching on the ππππ first argument fails (i.e. ¬βπ, πΌ = ββββπ )), we extend the relation βπΌ , πΌ β {π½, ππππ, ππππππ, ππ}, by if πΌ βπΌ π½ then case πΌ of β¦ βπΌ ππ (π½ case π½ of β¦ . In what follows, we will fix a left-most outermost evaluation strategy with respect to, β{π½,ππππ,ππππππ,ππ} , noted β. Let βπ be the k-fold self composition of the relation β wrt such a strategy. Higher order interpretations for higher order complexity Ξ(π‘) = π (Var) Ξ; Ξ β’ π‘ βΆβΆ π Hainry and Péchoux Ξ(π) = π (Cons) Ξ; Ξ β’ π βΆβΆ π Ξ(ππ) = π (Op) Ξ; Ξ β’ ππ βΆβΆ π Ξ; Ξ β’ πΌ βΆβΆ π1 βΆ π2 Ξ; Ξ β’ π½ βΆβΆ π1 (App) Ξ; Ξ β’ πΌ π½ βΆβΆ π2 Ξ, π‘ βΆβΆ π1 ; Ξ β’ πΌ βΆβΆ π2 (Abs) Ξ; Ξ β’ ππ‘.πΌ βΆβΆ π1 β π2 Ξ, π βΆβΆ π; Ξ β’ πΌ βΆβΆ π (Let) Ξ; Ξ β’ ππππππ π = πΌ βΆβΆ π Ξ; Ξ β’ ππ βΆβΆ bβββπ βΆ b Ξ, π‘βββπ βΆβΆ bβββπ ; Ξ β’ πΌπ βΆβΆ π (1 β€ π β€ π) (Case) Ξ; Ξ β’ ππππ πΌ ππ π1 (βββ π‘β1 ) β πΌ1 |...|ππ (βββ π‘βπ ) β πΌπ βΆβΆ π Ξ; Ξ β’ πΌ βΆβΆ b Figure 1: Type system Moreover, let |πΌ βπ π½| be the number of reductions distinct from βππ in a given a derivation πΌ βπ π½. |πΌ βπ π½| β€ π always holds. JπΌK is a notation for the term computed by πΌ (if it exists), i.e. βπ, πΌ βπ JπΌK and βπ½, JπΌK β π½. A (first order) value π is defined inductively by either π = π, if ππ(π) = 0, or π = π πββ, for ππ(π) > 0 values πββ, otherwise. Type system. We fix a set B of basic inductive types b described by their constructor set ξ―b . For example, the type of natural numbers π½ππ is described by ξ―π½ππ = {0, +π·}. The set of simple types is defined by π βΆβΆ= b | π βΆ π, with b β B. As usual βΆ associates to the right. In what follows, we will consider only well-typed terms. The type system assigns types to all the syntactic constructions of the language and ensures that a program does not go wrong. Notice that the typing discipline does not prevent a program from diverging. The type system is described in Figure 1 and proves judgments of the shape Ξ; Ξ β’ πΌ βΆβΆ π meaning that the term πΌ has type π under the variable and constructor (and operator) symbol contexts Ξ and Ξ respectively ; a variable (a constructor or operator symbol) context being a partial function that assigns types to variables (respectively constructors or operators). As usual, the input type and output type of constructors and operators of arity π will be restricted to basic types. Consequently, their types are of the shape b1 βΆ β¦ βΆ bπ βΆ b. A welltyped term will consist in a term πΌ such that β ; Ξ β’ πΌ βΆβΆ π (Consequently, it is mandatory for a term to be closed in order to be well-typed). Given a term πΌ of type π, i.e. β ; Ξ β’ πΌ βΆβΆ π, the order of πΌ, noted πππ(πΌ), is equal to the order of π, noted πππ(π) and defined inductively by: πππ(b) = 0, if b β B, and πππ(π βΆ πβ² ) = max(πππ(π) + 1, πππ(πβ² )) otherwise.. Example 1. Consider the following term πΌ that maps a function to a list given as inputs: ππππππ π = πg.ππ‘.ππππ π‘ ππ π(π’, π£) β π(g π’)(π g π£) | πππ β πππ Suppose that [π½ππ] is the base type for lists of natural numbers of constructor and set ξ―[π½ππ] = {πππ, π}. The term πΌ can be typed by (π½ππ βΆ π½ππ) βΆ [π½ππ] βΆ [π½ππ]. Consequently, πππ(πΌ) = 2. 2 Higher order interpretations for higher order complexity 2 Hainry and Péchoux Interpretations In this section, we define the interpretation tools that will allow us to control the complexity of closed terms of our language. Types. We briefly recall some basic definitions that are very close from the notions used in denotational semantics (See [Win93]) since, as we shall see later, our notion of interpretation also allows us to obtain fixpoints. Let (β, β€, β, β) be the set of natural numbers equipped with the usual ordering β€, a max operator β and min operator β and let β be β βͺ {β€}, where βπ β β, π β€ β€, π β β€ = β€ β π = β€ and π β β€ = β€ β π = π. The strict order relation over natural numbers < will also be used in the sequel and is extended in a somewhat unusual manner, by β€ < β€. The interpretation of a type is defined by: if b is a basic type, β¦bβ¦ = β, β² β β² β¦π βΆ π β¦ = β¦πβ¦ βΆ β¦π β¦, otherwise, where β¦πβ¦ βΆβ β¦πβ² β¦ denotes the set of total strictly monotonic functions from β¦πβ¦ to β¦πβ² β¦. A function πΉ from the set π΄ to the set π΅ being strictly monotonic if for each π, π β π΄, π <π΄ π implies πΉ (π) <π΅ πΉ (π ), where <π΄ is the usual pointwise ordering induced by < and defined by: π <β π iff π < π and πΉ <π΄βΆβ π΅ πΊ iff βπ β π΄, πΉ (π) <π΅ πΊ(π) Example 2. The type π = (π½ππ βΆ π½ππ) βΆ [π½ππ] βΆ [π½ππ] of the term ππππππ π = πΌ in Example 1 is interpreted by: β¦πβ¦ = (β βΆβ β) βΆβ (β βΆβ β). βββ of π terms in the interpretation domain and a sequence πββ of π In what follows, given a sequence π ββββββ ββ β types, the notation π β β¦πβ¦ means that both π = π and βπ β [1, π], π π β β¦ππ β¦. Terms. Each closed term of type π will be interpreted by a functional in β¦πβ¦. The application is denoted as usual whereas we use the notation Ξ for abstraction on this function space in order to avoid confusion between terms of our calculus and objects of the interpretation domain. Variables of the interpretation domain will be denoted using upper case letters. Moreover, we will sometimes use Church typing discipline in order to highlight the type of the bound variable in a lambda abstraction. An important distinction between the terms of our language and the objects of the interpretation domain lies in the fact that beta-reduction is considered as an equivalence relation on (closed terms of) the interpretation domain, i.e. Ξπ.πΉ πΊ = πΉ {πΊβπ} underlying that Ξπ.πΉ πΊ and πΉ {πΊβπ} are distinct notations that represent the same higher order function. The same property holds for π-reduction, i.e. Ξπ.πΉ π and πΉ denote the same function. Since we are interested in complete lattices, we need to complete each type β¦πβ¦ by a lower bound β₯β¦πβ¦ and an upper bound β€β¦πβ¦ as follows: β₯β = 0 β₯β¦πβΆπβ² β¦ = Ξπ β€β = β€ β¦πβ¦ .β₯β¦πβ² β¦ β€β¦πβΆπβ² β¦ = Ξπ β¦πβ¦ .β€β¦πβ² β¦ We can show by an easy structural induction on types that for each πΉ β β¦πβ¦, β₯β¦πβ¦ β€β¦πβ¦ πΉ β€β¦πβ¦ β€β¦πβ¦ . Notice that for each type π it also holds that β€β¦πβ¦ <β¦πβ¦ β€β¦πβ¦ , by an easy induction. 3 Higher order interpretations for higher order complexity Hainry and Péchoux In the same spirit, we extend inductively the max and min operators β (and β) over β to arbitrary higher order functions πΉ , πΊ of type β¦πβ¦ βΆβ β¦πβ² β¦ by: ββ¦πβ¦βΆ β β¦πβ² β¦ (πΉ , πΊ) = Ξπ β¦πβ¦ . ββ¦π β¦ (πΉ (π), πΊ(π)) β² ββ¦πβ¦βΆ β β¦πβ² β¦ (πΉ , πΊ) = Ξπ β¦πβ¦ . ββ¦π β¦ (πΉ (π), πΊ(π)) β² In the following, we use the notations β₯, β€, β€, <, β and β instead of β₯β¦πβ¦ , β€β¦πβ¦ , β€β¦πβ¦ , <β¦πβ¦ , ββ¦πβ¦ and ββ¦πβ¦ , respectively, when β¦πβ¦ is clear from the typing context. Lemma 1. For each type π, (β¦πβ¦, β€, β, β, β€, β₯) is a complete lattice. Now we need to define a unit (or constant) cost function for any interpretation of type π in order to take the cost of recursive calls into account. For that purpose, let + denote natural number addition extended to β by βπ, β€ + π = π + β€ = β€. For each type β¦πβ¦, we define a dyadic sum function ββ¦πβ¦ by: π β ββ π β = π + π πΉ ββ¦πβΆπβ² β¦ πΊ = Ξπ β¦πβ¦ .(πΉ (π) ββ¦πβ² β¦ πΊ(π)) Let us also define the constant function πβ¦πβ¦ , for each type π and each integer π β₯ 1, by πβ = π and πβ¦πβΆπβ² β¦ = Ξπ β¦πβ¦ .πβ¦πβ² β¦ Once again, we will omit the type when it is unambiguous using the notation πβ to denote the function πβ¦πβ¦ ββ¦πβ¦ when β¦πβ¦ is clear from the typing context. Now we are ready to define the notions of variable assignment and interpretation of a term πΌ: Definition 1 (Interpretation). β’ A variable assignment, denoted π, is a map associating to each π β ξ of type π a variable πΉ of type β¦πβ¦. β’ Given a variable assignment π, an interpretation is the extension of π to well-typed terms, mapping each term of type π to an object in β¦πβ¦ and defined in Figure 2, where β¦ππβ¦π is a sup-interpretation, i.e. a total function such that: βπΌ1 , β¦ , βπΌπ , β¦ππ πΌ1 β¦ πΌπ β¦π β₯ β¦JππK(πΌ1 , β¦ , πΌπ )β¦π . Notice that, contrarily to other program constructs, operators may have non monotonic interpretations. This is the reason why we have fixed a left-most outermost strategy (we never reduce the operator operands) and operators are supposed to be total functions. Example 3. Consider the following term πΌ βΆβΆ π½ππ βΆ π½ππ computing the double of a unary number given as input ππππππ π = ππ‘.ππππ π‘ ππ +π·(π’) β +π·(+π·(π π’)) | 0 β 0. We can see in Figure 3 how the interpretation rules of Figure 2 are applied on such a term. At the end we search for the minimal strictly monotonic function πΉ greater than Ξπ.(5 β (πΉ (π β 1))) β 4, for π > 1. That is Ξπ.5π β 4. The interpretation of a term is always defined. Indeed, in Definition 1, β¦ππππππ π = πΌβ¦π is defined in terms of the least fixpoint of the function Ξπ β¦πβ¦ .1ββ¦πβ¦ (Ξβ¦πβ¦π .β¦πΌβ¦π π) and, consequently, we obtain the following result as a direct consequence of Knaster-Tarski [Tar55, KS01] Fixpoint Theorem: Proposition 1. Each term πΌ of type π has an interpretation. We can also show that the length of a derivation is bounded by the interpretation of the initial term: ββ such that β ; Ξ β’ πΌ π½ββ βΆβΆ π, if πΌ π½ββ βπ πΌβ² then β¦πΌβ¦π β¦π½β¦ ββ π β₯ |πΌ π½ββ βπ Lemma 2. For all terms, πΌ, π½, πΌβ² | β β¦πΌβ² β¦π . 4 Higher order interpretations for higher order complexity Hainry and Péchoux β’ β¦πβ¦π = π(π), if π β ξ, β’ β¦πβ¦π = 1 β (Ξπ1 . β¦ .Ξππ . βπ π=1 ππ ), if ππ(π) = π, β’ β¦πΌπ½β¦π = β¦πΌβ¦π β¦π½β¦π , β’ β¦ππ‘.πΌβ¦π = 1 β (Ξβ¦π‘β¦π .β¦πΌβ¦π ), βββββββββ β ββββπ ββ¦π‘ ββββ β’ β¦ππππ πΌ ππ π1 (βββ π‘β1 ) β πΌ1 |...|ππ (βββ π‘βπ ) β πΌπ β¦π = 1 β β1β€πβ€π {β¦πΌπ β¦π {π π β¦π } | βπ π s.t. β¦πΌβ¦π β₯ ββββπ }, β¦ππ β¦π π β’ β¦ππππππ π = πΌβ¦π = β{πΉ β β¦πβ¦ | πΉ β₯ 1 β Ξβ¦πβ¦π .β¦πΌβ¦π πΉ }. Figure 2: Interpretation of a term of type π β¦πΌβ¦π = β{πΉ β β¦πβ¦ | πΉ β₯ 1 β Ξβ¦πβ¦π .β¦ππ‘.ππππ π‘ ππ +π·(π’) β +π·(+π·(π π’))| 0 β 0β¦π πΉ } = β{πΉ β β¦πβ¦ | πΉ β₯ 2 β (Ξβ¦πβ¦π .Ξβ¦π‘β¦π .β¦ππππ π‘ ππ +π·(π’) β +π·(+π·(π π’))| 0 β 0β¦π πΉ )} = β{πΉ β β¦πβ¦ | πΉ β₯ 3 β (Ξβ¦πβ¦π .Ξβ¦π‘β¦π .(ββ¦π‘β¦π β₯β¦+π·(π’)β¦π β¦+π·(+π·(π π’))β¦π ) β (ββ¦π‘β¦π β₯β¦0β¦π β¦0β¦π )πΉ )} = β{πΉ β β¦πβ¦ | πΉ β₯ 3 β (Ξβ¦πβ¦π .Ξβ¦π‘β¦π .(ββ¦π‘β¦π β₯1ββ¦π’β¦π 2 β (β¦πβ¦π β¦π’β¦π )) β (ββ¦π‘β¦π β₯1 1)πΉ )} = β{πΉ β β¦πβ¦ | πΉ β₯ 3 β (Ξβ¦π‘β¦π .(ββ¦π‘β¦π β₯1ββ¦π’β¦π 2 β (πΉ β¦π’β¦π )) β (1))} = β{πΉ β β¦πβ¦ | πΉ β₯ 3 β (Ξβ¦π‘β¦π .(2 β (πΉ (β¦π‘β¦π β 1))) β (1))}, β¦π‘β¦π β 1 β₯ 0 = β{πΉ β β¦πβ¦ | πΉ β₯ Ξπ.(5 β (πΉ (π β 1))) β (4)} = Ξπ.5π + 4 Figure 3: Example of interpretation 2.1 Higher Order Polynomial Interpretations At the present time, the interpretation of a term of type π can be any total functional over β¦πβ¦. In the next section, we will concentrate our efforts to study polynomial time at higher order. Consequently, we need to restrict the shape of the admissible interpretations. For that purpose, we introduce higher order polynomials which are the higher order counterpart to polynomials in this theory of complexity. Definition 2. Let ππ denote a polynomial of order π and let ππ denote an order π variable. Higher order (order 1 and order i+1) polynomials can be defined by the following grammar (π β β): π1 βΆβΆ= π|π0 |π1 + π1 |π1 × π1 ππ+1 βΆβΆ= ππ |ππ+1 + ππ+1 |ππ+1 × ππ+1 |ππ (ππ+1 ) Clearly, the set of order π polynomials is strictly included in the set of order π + 1 polynomials by the above definition. Moreover, by definition, a higher order polynomial ππ+1 has variables of order at most 5 Higher order interpretations for higher order complexity Hainry and Péchoux βββ is the sequence of such variables ordered by decreasing order, we will treat the polynomial ππ+1 π. If π βββ π+1 (π). βββ as total functions Ξπ.π We are now ready to define the class of functions computed by terms admitting an interpretation that is (higher order) polynomially bounded: Definition 3. Let FPπ , π > 0, be the class of polynomial functionals at order π that consist in functionals computed by terms πΌ over the basic type ξ―π½ππ and such that πππ(πΌ) = π and β¦πΌβ¦π is bounded by an order π polynomial (i.e. βππ , β¦πΌβ¦π β€ ππ ). 3 A characterization of Safe Feasible Functionals of any order BTLP is a higher order language defined in [IKR02] based on loops of the shape Loop π£π³0 with π£π³1 do {πΌ β }. The operational semantics of BTLP procedures is standard: parameters are passed by call-by-value and each loop statement is evaluated by iterating |π£0 |-many times the loop body instruction under the following restriction: if an assignment π£ βΆ= πΈ is to be executed within the loop body, we check if the value obtained by evaluating πΈ is of size smaller than the size of the loop bound |π£1 |. If not then the result of evaluating this assignment is to assign 0 to π£. Definition 4 (BFFπ ). For any π β₯ 1, BFFπ is the class of order π functionals computable by a BTLP procedure (see [IKR02])1 . It is straightforward that BFF1 = FPTIME and BFF2 =BFF. Now we restrict the domain of BFFπ classes to inputs in BFFπ for π < π, the obtained classes are named SFF for Safe Feasible Functionals. Definition 5 (SFFπ ). SFF1 is defined to be the class of order 1 functionals computable by BTLP a procedure and, for any π β₯ 1, SFFπ+1 is the class of order π + 1 functionals computable by BTLP a procedure on the input domain SFFπ . In other words, SFF1 =BFF1 , βπ β₯ 1, SFFπ+1 =BFFπ+1βΎSFFπ Theorem 1. For any order π β₯ 1, the class of functions in FPπ over FPπ , π < π, is exactly the class of functionals in SFFπ . In other words, SFFπ β‘ FPπβΎ(βͺπβ€π FPπ ) , for all π β₯ 1. Proof. Soundness relies on Lemma 2. Completeness is shown by simulating a BTLP procedure by a functional program admitting an interpretation. References [IKR02] Robert J. Irwin, Bruce M. Kapron, and James S. Royer. On characterizations of the basic feasible functionals (part II). Technical report, Syracuse University, 2002. [KS01] William A. Kirk and Brailey Sims. Handbook of metric fixed point theory. Springer, 2001. [Tar55] Alfred Tarski. A lattice-theoretical fixpoint theorem and its applications. Pacific journal of Mathematics, 5(2):285β309, 1955. [Win93] Glynn Winskel. The formal semantics of programming languages: an introduction. MIT press, 1993. 1 As 6 demonstrated in [IKR02], all types in the procedure can be restricted to be of order at most π without any distinction.
© Copyright 2026 Paperzz