express that the arguments have not the shape required by the normal rules. The default rules also impose universal quantications over the free variab

Size: px
Start display at page:

Download "express that the arguments have not the shape required by the normal rules. The default rules also impose universal quantications over the free variab"

Transcription

1 Default Rules: An Extension of Constructive Negation for Narrowing-based Languages Juan Jose Moreno-Navarro U. Politecnica, Facultad de Informatica, Campus de Montegancedo, Boadilla del Monte, Madrid, Spain, Abstract In this paper an extension of narrowing-based functional logic languages is proposed: Every partial denition of a function can be completed with a default rule. In a concrete function call, the default rule is applicable when the normal ones determine that they cannot compute the value of the call. The use of the default rule, in the presence of a goal with variables, is constructive. The operational semantics provides constraints to the variables to make the default rule applicable. Narrowing semantics are modied extending the technique of constructive negation [3, 4, 17]. 1 Introduction Narrowing is a unication based parameter passing mechanism which subsumes rewriting and SLD resolution. Dierent versions of narrowing have been used as the operational semantics of programming languages. In particular, so called functional logic languages retain functional syntax but use narrowing as operational semantics. They have been proposed to combine the functional and logic programming paradigms. As in pure functional programming, the functions dened by the program can be partially dened. A computation fails when a function call cannot be solved. "Exceptions" (see [14] for their use in ML) allows to handle these cases, giving, for instance, a default value. However this solution is not so easy to achieve in the case of functional logic languages because the logical component of the language allows to search values for applying the function. The default value can be returned only if the other rules cannot apply what imposes some constraints on the calling parameters. The denition of partial functions is implicitly used in PROLOG to carry out negation. Under the Closed World Assumption (CWA) a predicate p is f alse for all the tuples which are not positively dened by the clauses of p. In this paper we extend this notion of completion for a functional logic language. Every (partial) denition of a function with a number of rules can be completed by an extra default rule. The default rule establishes the function value for all the tuples that are not nitely dened by the previous rules. In particular we have incorporated the default value feature to BABEL [15] with disequality constraints over the Herbrand Universe [10], resulting a new language called Def-BABEL. However, it is clear that the techniques are independent of the chosen narrowing based language. In order to manage default rules, symbolic constraints are needed to

2 express that the arguments have not the shape required by the normal rules. The default rules also impose universal quantications over the free variables of the normal rules. The operational mechanism is a natural extension of constructive negation proposed for PROLOG [3, 4, 17] which incorporates constraints as the answers into negative subgoals. The narrowing mechanism can be adapted to compute default values: in order to detect if a function call f (e 1 ; : : : ; e n ) is dened we start a narrowing computation with f (e 1 ; : : : ; e n ) as goal. Any frontier of this computation denes where the expression is dened, hence the complement of this frontier denes where it is undened. The paper also includes the formal meaning of these default rules by dening the declarative semantics of Def-BABEL programs. The domain distinguishes between nite failure and the? value, which denotes divergence, in the style of Kunen's 3-valued semantics [11]. This semantics allows us to express soundness and completeness results. 2 A Functional Logic Language with Default Rules This section denes Def-BABEL programs and gives some examples. We assume a ranked set T C = [ n2in T C n of type constructors (e.g. nat=0; list=1) and a countably innite set TVar of type variables ;, etc. (denoted in programs by capital letters). Any algebraic term built from type constructors and type variables { e.g. list(nat); list() { is a data type. A data type is polymorphic if it includes type variables, and monomorphic otherwise. We also assume a set DC of data constructors d=n with declared principal types: d : 1 : : : n!, e.g. s: nat! nat. In practice, type constructors and data constructors can be introduced through type declarations and some types like list, nat or bool = truejf alse are assumed to be predened. Next, we assume a countably innite set VS of (typed) data variables (denoted by capital letters) and a set FS of function symbols f =n with declared principal types: f : 1 : : : n!, for example subs : nat nat! nat. Terms t and expressions e are dened as follows: e ::= X t ::= X % X 2 V S j d (t 1 ; ::; t n ) % d=n 2 DC j d (e 1 ; ::; e n ) % d=n 2 DC j f (e 1 ; ::; e n ) % f 2 F S and all of them must be well typed (following Milner's type system). The syntax allows to build expressions involving some primitive function symbols: :b (negation), (b 1 ; b 2 ) (conjunction), (b 1 ; b 2 ) (disjunction), (b! e) (guarded expression, meaning: if b then e else undened), (b! e 1 2e 2 ) (conditional, meaning: if b then e 1 else e 2 ), and (e 1 = e 2 ) (weak equality, both expressions denote the same object), where b is a boolean expression. BABEL programs consist of declarations of types and dening or default rules for every function symbol f : 1 : : : n!, with the following shape, where guards are optional: f (t 1 ; : : : ; t n ) {z } left hand side Dening rules := fb!g {z } guard e {z} body {z } right hand side Default rules default f (X 1 ; : : : ; X n ) := b! e

3 BABEL functions are functions in the mathematical sense. In order to ensure conuence, some syntactical restrictions are imposed: 1. Data Patterns and Left Linearity: t i 's are terms and every lhs does not contain multiple variable occurrences. 2. Restrictions on free variables: Variables occurring in the rhs but not in the lhs are only allowed in the guard. 3. Well Typedness: It must be possible to check the types i for each t i (1 i n), the type bool for b, and the type for e. 4. Nonambiguity: Given two dierent dening rules in the same function, either their left hand sides are not uniable or if the lhs's unify with m.g.u., after applying to both bodies, either they are identical or their guards are incompatible 1. Now, we can intuitively dene the meaning of a function denition. The left column shows a set of function rules and the right column their meaning: f(t 1 (X 1 )) := b 1 (X 1 ; Y 1 )! e 1 : : : f(t n (X n )) := b n (X n ; Y n )! e n default f(x) := b(x; Y )! e 8 >< f(z) = >: e 1 if 9X 1 (Z = t 1 ^ 9 Y 1 b 1 )... e n if 9X n (Z = t n ^ 9 Y n b n ) e if 9Y b ^ (f(z)) where is the denitionless operator that means that the dening rules for f do not dene f (Z). Example 2.1 The following program computes the substraction of natural numbers. The partially dened version is completed with a default rule in order to return an integer. Integers are dened as signed numbers. type nat := 0 j s(nat). fun subs : nat nat! int. type int := + nat j { nat. subs (Y, 0) := + Y. fun invert: int! int. subs (s (Y),s (X)) := subs (Y, X). invert(+ Y) := { Y. default subs (Y, X) := invert({ Y) := + Y. invert (subs (X, Y)). eval subs (s (0), X). > result + s (0) answer X = 0 > result + 0 answer X = s (0) > result { X' answer X = s (X'), X' 6= 0 > no (more) solutions. Example 2.2 The second example involves variable quantication. A natural number is even if it is the double of another natural number. Otherwise the number is odd. This last statement correspond to a default rule which involves an implicit universal quantication. type list A := []j[ajlist A]. fun plus: nat nat! nat. type parity type := evenjodd. plus (0, Y) := X. fun <: nat nat! bool. plus (s (X), Y) := s (plus (X, Y)). % Some rules for <. fun parity: nat! parity type. parity (X) := (Y < X, plus (Y, Y) = X)! even. default parity (X) := odd. 1 Incompatibility [10] is a decidable syntactical property between two boolean expressions in order to ensure that they cannot be simultaneously reduced to true.

4 eval [parity (1), parity (2), parity (3), parity (4)]. > result [odd, even, odd, even] > no (more) solutions. 3 Declarative Semantics of Default Rules This section is devoted to the declarative semantics of Def-BABEL. Since pure BABEL is a subset of our language some technical details (present in [15]) will be skipped or simplied. We start with the denition of the domain. Polymorphism is treated in the simplest way: every polymorphic function is replicated for each particular monomorphic application. Denition 3.1 Herbrand Universe H is the correctly typed Herbrand universe built up with the constructors of the types dened in the program These terms are called concrete elements. We also add to H two values for failure: f ail (to indicate nite failure) and? (for divergence). We assume the following ordering in H? v d for every d fail v d for every concrete element d Notice the similarities between our model and Kunen's 3-valued semantics [11]. However, our semantics needs two values for failure because f alse is a correct result for functions and predicates. Now we proceed with the denition of interpretations. Denition 3.2 Interpretations and environments A Herbrand interpretation I is a collection of well typed monotonic functions f I : H n! H, one for every function f =n in F S such that f I (?) =? and f I (f ail) = f ail. Interpretations can be equipped with the partial ordering: I v J i for all f=n 2 F S f I (s) v f J (s) for all s 2 H n The domain of Herbrand interpretations is noted H?IN T. An environment is any mapping : V S! H? ff ail;?g such that (X) has the same type of the variable X. Now, we just can dene the valuation [e] I () for a given well typed expression e into a concrete interpretation I under an environment by induction on the syntactical structure of the expression. Denition 3.3 Valuation [X ] I () = (X) for X 2 V S [d (e 1 ; ::; e n )] I () = d ([e 1 ] I (); ::; [e n ] I ()) for d=n 2 CS; n 0 [f (e 1 ; ::; e n )] I () = f I ([e 1 ] I (); ::; [e n ] I ()) for f=n 2 F S; n 0 [e 1 = e 2 ] I () = eq([e 1 ] I (); [e 2 ] I ()) [:b] I () = not([b] I ()) [b 1 ; b 2 ] I () = and([b 1 ] I (); [b 2 ] I ()) [b 1 ; b 2 ] I () = or([b 1 ] I (); [b 2 ] I ()) [b! e] I () = if([b] I (); [e] I ()) [b! e 1 2e 2 ] I () = if else([b] I (); [e 1 ] I (); [e 2 ] I ()) where the semantics functions and, not, or, if, if else, and eq are dened as follows:

5 and? f ail false true????? fail? fail fail fail false? f ail false false true? f ail false true not?? fail fail false true true false 8 s >< fail if(b; s) = >: or? f ail false true????? fail? fail fail fail false? f ail false true true? f ail true true 8 true if s >< 1 ; s 2 concrete ^ s 1 = s 2 false if s 1 ; s 2 concrete ^ s 1 6= s 2 eq(s 1 ; s 2 ) = fail if s >: 1 = s 2 = fail? otherwise if b = true if b = false or b = fail? otherwise 8 s >< 1 if b = true s 2 if b = false if else(b; s 1 ; s 2 ) = fail if b = fail >:? otherwise Knowing how to evaluate expressions, any dening rule can be interpreted as the statement whose value for the lhs is always as least as dened as the rhs value. To formally dene the meaning of a default rule we need some auxiliary denitions: Denition 3.4 Denitionless function Given a function f =n, a program, and a Herbrand interpretation I we dene the functions T I (f); TI b (f) : H n! P(H) as follows: T I (f)(s 1 ; ::; s n ) = f[r ] I ()=f (t 1 ; ::; t n ) := R 2 ; (t i ) = s i g bt I (f)(s 1 ; ::; s n ) = f[r ] I ()=defaultf (t 1 ; ::; t n ) := R 2 ; (t i ) = s i g where is an environment. We also dene the denitionless function I (f) : H n! bool such that 8 < I (f)(s) = : if T I (f)(s) = ; or T I (f)(s) = ffailg true? if? 2 T I (f)(s) f alse otherwise. The function establishes where the function f has not a denition using the dening rules. Notice that the denitions of T I and involve some implicit universal quantication if a dening rule contains free variables in the guard. Now, we can dene when an interpretation is a model of a program. Denition 3.5 Models An interpretation I is a model of a program (in symbols I j= ) if a).- I is a model of every dening rule in, and b).- for every default rule f (X 1 ; : : : ; X n ) := e in f I ((X)) = [e] I () if I (f)((x)) = true for any environment. I is a Herbrand model of a dening rule L := R i [L] I () w [R] I () for all environments. We can prove now the existence of a least Herbrand model for any given program. As it is done in classical logic programming, minimal models are obtained as least xpoints of monotonic interpretation transformers.

6 Denition 3.6 The interpretation transformer associated to is the mapping T : H?IN T! H?IN T dened as follows: for any interpretation I, T (I) is the Herbrand interpretation J such that for any f =n 2 F S and well typed elements s 1 ; : : : ; s n 2 H 8 < f J (s) = : m if m = fail where n if I (f)(s) = true m = max T I (f)(s)? otherwise n = max TI b (f)(s) Proposition 3.1 T is well dened and monotonic. Proof: T is well dened as an immediate consequence of the conuence property, syntactically established. As the set T I (f)(s) can only have a single concrete value, then the maximum exists. Monotonicity can be easily proven from the denition of the transformer. The distinction between f ail and? means the key point in the proof. The unknown values are denoted by? and they cannot be used in a default rule. Only when a nite failure is calculated the value f ail is used and the default rules can be applied. The main result of the declarative semantics establishes the existence of a least Herbrand model I for every BABEL program. It is deduced from Proposition 3.1 by using the well known Tarski's theorem. Theorem 3.1 There exists a least xpoint I of T, that can be computed as the limit of the sequence I 0 = I? and I i+1 = T (I i ) where I? is the interpretation that assigns? as denotational value for every function. Moreover, I is the least Herbrand model in H?IN T. Once the existence of I has been proven, some of the denitions for interpretations can be instantiated for it. In particular we will call, simply, to the function I. We will also use the complement of this function, called. Intuitively (f (e 1 ; : : : ; e n )) means that the expression f (e 1 ; : : : ; e n ) is positively dened, i.e. can be calculated without the default rule. More formally: (f (s)) = not (f)(s) 4 Operational Semantics For simplicity of presentation, we restrict ourselves to an innermost version of narrowing working with symbolic constraints. In order to provide a stepwise denition for all the concepts we will rst present how innermost narrowing works with constraints. In the next subsection the denition of innermost narrowing will be extended in order to cope with default rules. The main idea is to obtain the function syntactically. Finally we will describe the simplication of symbolic constraints. 4.1 Innermost Narrowing with Constraints over the Herbrand Universe A computation involves a constraint c and an expression e. The constraint c contains equalities and disequalities of terms. The equalities collected into

7 the constraint can be seen as the substitutions in usual narrowing, similarly as it is done within the CLP scheme [9]. A more abstract and general description of the operational semantics of the constraint functional logic programming paradigm can be found in [12]. To obtain a formal denition of BABEL's innermost narrowing semantics we need a notion of expression normal form (nf): the canonical representation of values. We say that an expression e is in nf i e is a variable X, e is a nullary constructor d, or e is of the form d(e 1 ; ::; e m ), where d=n 2 DC and e 1 ; ::; e m are in nf Moreover, we need a notion of normal form also for constraints. A disequation d(x; a) 6= d(b; Y ) implies a disjunction X 6= b _ Y 6= a. So, we use conjunctions of disjunctions of disequations as normal forms. On the other hand, we will produce disequations by means of the negation of an equation X = t(y ). This fact produces the universal quantication of the free variables Y, unless a more external quantication aects them. The negation of such equation is 8Y X 6= t(y ). Also, universally quantied disequations are allowed in the constraints. More precisely, the normal form of constraints is: ^ (X i = t i ) ^ 8 Z 1 j {z } (Y j 1 6= s1 j ) ^ : : : ^ 8 Zj n (Y l n 6= s n l ) j l positive information {z } negative information where each X i appears only in X i = t i, none s r r k is equal to Yk and the universal quantication could be empty (leaving a simple disequality). The notation c ` c 0 indicates that the constraint c 0 is the simplication (normal form) of c. c ` f alse means that the constraint c is unsatisable. The rules for ` will be presented in subsection 4.3. The one step narrowing relation is denoted c [] e =) c 0 [] e 0, where c' is not f alse. It is specied by the following rules 2 : 1. Rule application c [] f (e 1 ; : : : ; e n ) =) c 0 [] e 0 if e 1 ; : : : ; e n are in nf, there is a variant f (t 1 ; : : : ; t n ) := fb!ge of one rule in the program (sharing no variables with the goal) such that f (t 1 ; : : : ; t n ) and f (e 1 ; : : : ; e n ) are uniable with m.g.u. = in _[ out (where in collects the bindings for variables in the t i and out records the bindings for variables in the e i ), and e 0 is (fb!ge) in c ^ V(X i = s i ) ` c 0, where out = f: : : ; X i =s i ; : : :g c 2. Inner narrowing step [] e i =) c 0 [] e 0 i c [] k(e 1 ; ::; e i ; ::; e n ) =) c 00 [] k(e 1 ; ::; e 0 i ; ::; e n) if k=n 2 DC [ F S; 1 i n and c ^ c 0 ` c Rules for guards and conditionals c [] b =) c 0 [] b 0 c [] (true! e) =) c [] e c [] (true! e 1 2 e 2 ) =) c [] e 1 c [] (false! e 1 2 e 2 ) =) c [] e 2 c [] (b!e)=) c 00 [] (b 0!e) if b is not in nf and c ^ c 0 ` c 00 c [] b=)c [] b 0 c [] (b!e 1 2e 2 )=) c 00 [] (b 0!e 1 2e 2 ) if b is not in nf, c ^ c 0 ` c 00 2 The rules assume that the condition holds, i.e. the resulting constraint is not f alse

8 4. Rules for the equality c [] (e 1 = e 2 ) =) c 0 [] true if e 1 ; e 2 are in nf, and c ^ (e 1 = e 2 ) ` c 0 c [] (e 1 = e 2 ) =) c 0 [] false if e 1 ; e 2 are in nf, and c ^ (e 1 6= e 2 ) ` c 0 c [] e 1 =) c 0 [] e 0 1 c [] (e 1 = e 2 ) =) c 00 [] (e 0 1 = e 2) if e 1 is not in nf and c ^ c 0 ` c 00 c [] e 2 =) c 0 [] e 0 2 c [] (e 1 = e 2 ) =) c 00 [] (e 1 = e 0 2 ) if e 2 is not in nf and c ^ c 0 ` c 00 The rest of the primitive functions can be computed by some predened rules (see [15]) or, alternatively, by including some explicit narrowing rules. It allows to have a lazy (short-circuit) denition of the logical connectives. The notation c [] e c 0 [] e 0 =) : : : c i [] e i : : : =) c n [] e n c 0 [] e 0, or simply c [] e =) c 0 [] e 0 denotes the narrowing relation (composition of several narrowing steps). There is some degree of freedom in the previous scheme. A redex is the point where one of the previous rules is applicable. The selected expression to be reduced into a construction (rule 2) or an equality (rule 4) should be xed by a computation rule R. The usual implemented rule is the selection of the left-most redex that it is not yet in normal form. However, this is not the only cause of nondeterminism: several applicable rules for a given expression could be done. Denition 4.1 Children and Narrowing Tree Given a constraint expression c [] e, a program and a computation rule R we call any possible application of the one step narrowing relation guided by R a child of c [] e on. All the possible narrowing reductions of a constraint expression c [] e given a program and a computation rule R form the narrowing tree for c [] e. Every node is labelled with a constraint expression 3. Performing narrowing with a BABEL goal expression c [] e may lead to several situations, which classify the paths into the narrowing tree: Success: c [] e =) c 0 [] t with t 2 Term and c 0 satisable. Failure: c [] e =) c 0 [] e 0, e 0 62 Term and e 0 is not further narrowable or c 0 unsatisable. Nontermination: In this case we may still have c [] e =) c 0 [] e 0 where e 0 62 Term and e 0 's constructors give a partial result. When a succesful narrowing relation reaches a term c 0 [] t we speak of a computation for the goal c [] e with result t and answer c 0. A very important notion for our purpose is the concept of frontier of a narrowing tree. 3 In the following we will omit the reference to the program and the computation rule R when no ambiguity is possible.

9 Denition 4.2 Frontier A frontier of c [] e is a nite set of nodes of the narrowing tree such that every narrowing reduction of c [] e is either a failure or passes through exactly one node in the set. We will denote a frontier F as a set fc 1 [] e 1 ; : : : ; c m [] e m g. Example 4.1 A frontier of the expression true [] subs(s(0); X) in example 1.1 could be fx = 0 ^ Y = s(0) [] + s(0); Y = 0 ^ X = s(x 0 ) [] subs(0; X 0 )g following the narrowing tree: true [] subs(s(0); X) 9 X XX X XXz X = 0 ^ Y = s(0) [] + s(0) Y = 0 ^ X = s(x 0 ) [] subs(0; X 0 ) 4.2 Narrowing for default rules The next step is the computation of default rules. The main idea is to manage the function syntactically. However, let us remember that the semantical denition of the function includes an implicit universal quantication. They are moved to explicit 8-quantications. We will work with expressions of the form 8 X (c [] e) (where c [] e is a constraint expression) that must be read \under the constraint c, e is undened using the dening rules". In the previous section we have dened how an expression is computed with the dening rules by using narrowing. We can narrow the expression in every possible way until we get all the solutions and then we can negate them. This yields to a condition that is equivalent to the function. However, the narrowing tree could be innite and the process will not terminate. An eective solution consists of the use of a frontier of the narrowing tree (which is always nite) to produce a condition equivalent to the function. The process is based in the following result: Proposition 4.1 If is a BABEL program and F = fc 1 [] e 1 ; : : : ; c n [] e n g is a frontier of c [] e then (c [] e) $ 9 X 1 (c 1 ^ (e 1 )) _ : : : _ 9 X n (c n ^ (e n )) where X i are the free variables in c i [] e i which are not in c [] e. As the function is the negation of the function, this result can be used to calculate a expression by the negation of the right hand side formula. The notion of complement of a frontier is used for this purpose. Denition 4.3 Complement of a frontier Let F = fc 1 [] e 1 ; : : : ; c n [] e n g be the frontier of a constraint expression c [] e and V a set of variables (denoting the free variables in the goal expression). The complements of F under V are all the possible conjunctions of complements of each c i [] e i under V : c 0 1 ^ : : : ^ c0 m [] b 1 ; : : : ; b m is a complement of F i each c 0 i [] b i is a complement of c i [] e i under V.

10 In order to dene the complement of a constraint expression c [] e, let us briey discuss the quantication of variables. First, we only need to focus on those useful variables, i.e. those that are free in the goal expression. We collect them in the set V. A variable X appearing in the positive part of the constraint as X = t can be eliminated. If t is a variable X 0 2 V we substitute X for X 0 in c [] e. Otherwise, the equation is irrelevant. Next, we identify the variables that will have a universal quantication when the complement is calculated. They are the free variables in e that are neither in V nor in the positive part (that have an implicit quantication). We collect them in the set U. The disjunction of inequalities with variables in U cannot be separated from e. The rest of the disjunctions can be negated separately from e. When a disjunction of disequalities is negated it is moved into a conjunction of equalities. These equalities have not quantication even if the original disequation are not quantied because the free variables are (implicitly) quantied outside. In summary, we can organize the simplication of c as: c = m^ (X i = t i ) ^ i=1 n^ n _ j j=1 k=1 8 Z j k (Y j k 6= sj k ) ^ c0 where c 0 collects all the inequalities with a variable in U. Denition 4.4 Complements of a constraint expression The complements of c [] e under V are: W m 8 1=1 Z i (X i 6= t i ) [] true, where Z i are the variables of t i that are not quantied outside, i.e. var(t i ) \ V. V m i=1 (X i = t i ) ^ Vn l k=1 (Y l k = s k l ) ^ Vl?1 j=1 all l < n. V m i=1 (X i = t i ) ^ Vn variables in U. j=1 W nj 8 k=1 Zj k (Y j k 6= sj k ) [] true, for W nj k=1 8 Zj k (Y j k 6= sj k ) [] 8 Z (c0 [] e), where Z are the The last component in the denition 4.4 includes the computation of the denitionless operation. This -expression can be simplied when the expression e is a constructor application or a predened function. Due to the lack of space we omit some rules for the simplication. Some examples are: 8 X (c [] :b) 8 X (c [] b), 8 X (c [] (b! e)) (c [] b); 8 X (c [] b! e2true), if X is empty or they appear only in e, or 8 X (c [] (e 1 = e 2 )) 8 X (c [] e 1 ); 8 X (c [] e 2 ). The simplication rules try to minimize the computational eort. For instance, in the case of the equality the rule avoids to compute the real value of the equality and it just computes the denitionless operation of both expressions. Usually a very big expression generates a complicate search space, and it is better to consider the denitionless of the subexpressions one by one. Example 4.2 In order to compute the complement of the frontier of example 4.1, the complement of each constraint expression of the frontier is computed. X is the single goal variable, so the equations for the variable Y are eliminated.

11 The complements of X = 0 [] + s(0) are: X 6= 0 [] true and X = 0 [] (true [] + s(0)) but the second one is equivalent to f alse after applying -simplication rules. The complements of X = s(x 0 ) [] subs(0; X 0 ) are: 8 X 0 X 6= s(x 0 ) [] true and X = s(x 0 ) [] (true [] subs(0; X 0 )). Finally, the complements of the frontier of true [] subs(s(0); X) are obtained by combining the previous complements: 1. X 6= 0 [] true; 8 X 0 (X 6= s(x 0 ) [] true 2. X 6= 0 [] true; X = s(x 0 ) [] (subs(0; X 0 ) As we will see, the rst expression yields to a constraint that is unsatisable in the domain of the natural number and will be discarded. Now, we complete the narrowing rules to use the default rule (if present) and to compute a (c [] e) expression. The new rules are: (c [] f (e 5. Default rule 1 ; : : : ; e n ) =) c 0 [] true c [] f (e 1 ; : : : ; e n ) =) c 00 [] e where default f (X 1 ; : : : ; X n ) := e 2 and e 1 ; : : : ; e n are in nf, = f::; X i =e i ; ::g and c ^ c 0 ` c Denitionless expressions rule Let F be a frontier of the narrowing tree of c [] e using rules 1,..., 4 for the rst step, and let V be the set of free variables of c [] e that are not in X. 8 X (c [] e) =) true if F = ; 8 X (c [] e) =) c [] b if F 6= ; and (c [] b) is a complement of F under V For each complement of F we have a dierent child in the narrowing tree. 4.3 Management of symbolic constraints This subsection discusses how to check the satisability of constraints and how to maintain their normal forms. In the literature there are also simpler normal forms as a simple conjunction of equalities and disequalities (see [5, 13, 4] for papers devoted to this and related subjects). Disjunctions of disequality constraints can be handled by backtracking. We have used a more compact representation to simplify the search space. The most complicate part in the simplication of a constraint is the addition of an equality or a disequality. The unication algorithm can be used to detect if they are satisable and to help in this simplication. Another important point is the fact that our domains (types) for constraints have a nite number of constructors. We need to add a rule to detect inconsistencies like X 6= 0 ^ 8 Y (X 6= s(y )) for the nat type. To apply this rule we need some previous notions. Denition 4.5 Covering A set of terms t 1 ; : : : ; t n (none a variable) is complete for a variable X on a monomorphic type i for all the concrete elements s 2 H with type there exists i and a substitution such that s = t i. A covering for on X is the constraint built as the negation of a complete set of terms : : : ; t i (Y i ); : : : for X on : : : : ^ 8Y i X 6= t i ^ : : :

12 Example 4.3 X 6= 0 ^ 8 Y (X 6= s(y )) are coverings for nat on X. X 6= 0 ^ X 6= s(0) ^ 8 Y (X 6= s(s(y ))) A covering is unsatisable on H, what means that every constraint with a covering can be reduced to f alse. Now, we dene the rules to combine a constraint in normal form with a new constraint. In the following the substitution denotes the positive part of the constraint, i.e. = fx 1 =t 1 ; : : : ; X n =t n g. Addition of an equation t = s ^ V(X i = t i ) ^ c ` false if c has only disequalities, t; s are not uniable t = s ^ ^(X i = t i ) ^ c ` ^(X i = t i ) ^ ^(X 0 j = t0 j ) ^ c0 if c has only disequalities, = m:g:u:(t; s) = fx 0 1 = t0 1 ; : : : ; X m 0 = t0 mg, c ` c 0 Addition of a disequation 8 Zt 6= s ^ ^(X i = t i ) ^ c ` ^(X i = t i ) ^ c if c has only disequalities and t; s are not uniable 8 Z t 6= s ^ ^(X i = t i ) ^ c ` ^(X i = t i ) ^ _(X 0 j 6= t 0 j ) ^ c0 if c has only disequalities, and = m:g:u:(t; s) = f::; X 0 i = t0 i ; ::g 8 Z t 6= s ^ ^(X i = t i ) ^ c ` false if c has only disequalities and = m:g:u:(t; s) only binds variables in Z Note: The universal quantication on Z should be empty. Simplication rules true ^ c ` c false ^ c ` false c 1 : : : ^ c n ` false if it contains a covering c ^ c 1 :: ^ c n ` c ^ c 0 1 ^ :: ^ c 0 n if c contains the equalities and c i 's the disequalities of the whole constraint c ^ c i ` c 0 i, for each i c ^ c 1 _ :: _ c n ` c ^ c 0 1 ^ :: ^ c 0 n if c has equalities and the c i 's are single disequalities c ^ c i ` c 0 i, for each i Example 4.4 In previous examples we have computed the complements of a frontier of the expression true [] subs(s(0); X). Now, rule 5. can be applied to obtain: (true [] subs(s(0); X)) =) Rule 7 X 6= 0 [] true; X = s(x 0 ) [] (true [] subs(0; X 0 )) =) Rules for ; ` X = s(x 0 ) [] (true [] subs(0; X 0 )) The only frontier for (true [] subs(0; X 0 )) is fx 0 = 0 [] + 0g, which has an unique useful complement X 0 6= 0. X = s(x 0 ) [] (true [] subs(0; X 0 )) =) Rule 6 X = s(x 0 ) ^ X 0 6= 0 [] true Now, the narrowing sequence can be completed as follows: : : : =) Rule 5 X = s(x 0 ) ^ X 0 6= 0 [] invert(subs(s(x 0 ); s(0))) =)?X 0

13 4.4 Soundness and Completeness Finally, we can establish the soundness and completeness of our narrowing semantics. Due to the lack of space we will omit the proofs. Theorem 4.1 Soundness Let be a program. Any narrowing sequence c [] e sound outcome in the sense that =) c 0 [] e 0 computes a [c; c 0! e] I () w [c 0! e 0 ] I () for all environments : Notice that if e 0 is a term its valuation corresponds with the term itself (except the variables), giving the expected soundness result for succesful computations. The interpretation of a constraint c as an expression is obvious. Theorem 4.2 Completeness Let be a program, e an expression, c a constraint, s an element in H and a substitution that binds any variable of c; e into a ground term (ground substitution). If [(c! e) ] w s then there exists a narrowing sequence c [] e =) c 0 [] t, (with t a term), and a ground substitution such that t = s, and c ^ c ^ c 0 is satisable (where c ; c denote the constraints with positive part ; and no negative part). Proof Idea: The proof combines the ideas of the completeness of innermost narrowing, using the T operator, with the completeness proof of [17]. In fact the result is, in some sense, a corollary of this last one. 5 Related work The work uses some of the techniques developed for constructive negation [3, 4, 17]. However, they are adapted to a more general framework. Our more complex notion of constraint normal form forces us to redene the notion of complement used in Chan's papers. Chan's method to obtain constraint information from a frontier relies in the following property: :9Y ; Z(X = s ^ Q) $ 8Y (X 6= s) _ 9Y (X = s ^ :9Z)Q while Stuckey abstracts, into the CLP framework, to: :9Y ; c ^ Q $ (:9Y c) _ (:9Y c ^ Q) (see [17]). Our method uses a mixture of both of them, adding the rules for simplication of -expressions. These rules generalize the double negation simplication of Chan (which cannot be used in Stuckey's approach). The narrowing rule for default rules has an advantage with respect to Chan's work: The whole constraint is passed to the denitionless expression, what reduces the search space. This idea was pointed by Stuckey instead of the use only of the positive constraint (substitution) in Chan's paper. Only some few papers have been devoted to the combination of constructive negation with narrowing. [16] treats a dierent problem: to compute the answers to a disequation f(t) 6= s by computing the results for f(t) = s and then negating the resulting formula. The undened values for f(t) are not

14 taken into account (or f must be total). In our framework we can compute all the values for f(t), by bactracking, and then compare them with s. It is valid even if f(t) is undened, by adding a default rule default f(x) := r, with r 6= s. However, if f(t) has innitely many solutions the method is not eective, while negating a frontier of f(t) = s is. [6] denes a narrowing procedure to compute disunication (i.e. disequations over the Herbrand universe modulo an equational theory). It is complete when the equational theory is dened by a basic term rewriting system. The problem is also dierent from the treated in this paper. Another trend of work which makes use of innermost narrowing and negative information is present in the languages SLOG [7] and ALF [8]. Narrowing is combined with simplication using some rules by pure rewriting. In some cases, under the CWA, it is possible to dene a rewriting rule indicating when a function fails. This could optimize the computation and also can transform an innite computation (?) into a nite failure (f ail). The technique is independent of our work an can be used to optimize it. Another interesting approach to negation in PROLOG is the transformational one [1, 2]. New predicates are added in order to express the negative information. Informally, the complement of head terms of the positive clauses are computed and they are used later as the head of the negated predicate. However, in some cases, the new program contains some kind of universal quantication construct hard to be eciently implemented. In our case, this approach can be adapted when the program has no guards or guards without free variables. The default rule can be expressed as a normal rule. For instance, in the subs example, the new rule is: subs (0, Y) := Y 6= 0! { Y. However, in the presence of a constraint X 6= Y the program will produce innitely many solutions (if the type has a non constant constructor). 6 Conclusion In this paper we have studied the completion of partial functions with a default rule in functional logic languages. The narrowing rule has been modied to cope with these new rules. The used techniques are an extension of constructive negation: subderivations are used to detect when a function call will nitely fail by using the dening rules. Pure PROLOG can be interpreted as a subset of BABEL when predicates are implemented as boolean functions. By using default rules, PROLOG programs with negation are subsumed by Def-BABEL. The negated part of a predicate is obtained by using a default rule with body false. Furthermore, in our language, the programmer can freely use explicit negation and negation as failure. Kowalski pointed out the advantages of this distinction for knowledge representation. The paper has focused on the extension of narrowing based languages using a constructor discipline. This restricts our constraint system to the

15 Herbrand Universe. However, we agree [17] that it is more general (and natural) to study the problem in a CLP framework. Although there are few paper addressing the integration of functions, predicates and constraints, we believe that default rules can be best described in the context of Constraint Functional Logic Programming [12]. As a future work, we plan to incorporate these techniques to lazy narrowing. The coroutining implementation technique reported in [3, 4] can be seen as an application of lazy evaluation. Acknowledgements This research was supported in part by the spanish project TIC/ C References [1] R. Barbuti, D. Mancarella, D. Pedreschi, F. Turini. Intensional Negation of Logic Programs. Proc. TAPSOFT'87, Springer LNCS 250, , [2] R. Barbuti, D. Mancarella, D. Pedreschi, F. Turini. A Transformational Approach to Negation in Logic Programming. Journal of Logic Programming, 8(3): , [3] D. Chan. Constructive Negation Based on the Complete Database Proc. Int. Conference on Logic Programming'89, The MIT Press, , [4] D. Chan. An Extension of Constructive Negation and its Application in Coroutining. Proc. NACLP'89, The MIT Press, [5] H. Comon, P. Lescanne. Equational Problems and Disunication. Journal of Symbolic Computation, 7: , [6] M. Fernandez. Narrowing Based Procedures for Equational Disunication. Applicable Algebras in Eng. Communications and Computing, 3:1-26, [7] L. Fribourg. SLOG: A Logic Programming Language Interpreter based on Clausal Superposition and Rewriting. Proc. Symp. on Logic Programming, IEEE Comp. Soc. Press, [8] M. Hanus. Compiling Logic Programs with Equality. Proc. PLILP'90, Springer LNCS, [9] J. Jaar, J.L. Lassez. Constraint Logic Programming. Proc. 14th ACM Symp. on Princ. of Prog. Lang., , [10] H. Kuchen, F. Lopez-Fraguas, J.J. Moreno-Navarro, M. Rodrguez-Artalejo. Implementing a Lazy Functional Logic Language with Disequality Constraints. Joint International Conference and Symposium on Logic Programming, The MIT Press, , [11] K. Kunen. Negation in Logic Programming. Journal of Logic Programming 4: , [12] F.J. Lopez-Fraguas. A General Scheme for Constraint Functional Logic Programming. Proc. ALP'92, Springer LNCS, [13] M. Maher. Complete Axiomatization of the Algebras of Finite, Rational and Innite Trees. Proc. 3rd Symp. on Logic in Computer Science, , [14] R. Milner, M. Tofte, R. Harper. The Denition of Standard ML. The MIT Press, [15] J.J. Moreno Navarro, M. Rodrguez Artalejo. Logic Programming with Functions and Predicates: The Language BABEL. Journal of Logic Programming 12: , 1992.

16 [16] M.J. Ramrez, M. Falaschi. Conditional Narrowing with Constructive Negation. Proc. 3rd Int'l Workshop on Extension of Logic Programming ELP'92, Springer LNCS 660, 59-79, [17] P. Stuckey. Constructive Negation for Constraint Logic Programming Proc. IEEE Symp. on Logic in Computer Science, IEEE Comp. Soc. Press, 1991.

Logic Language with Disequality. RWTH Aachen, Lehrstuhl fur Informatik II, Ahornstrae 55

Logic Language with Disequality. RWTH Aachen, Lehrstuhl fur Informatik II, Ahornstrae 55 Implementing a Lazy Functional Logic Language with Disequality Constraints Herbert Kuchen RWTH Aachen, Lehrstuhl fur Informatik II, Ahornstrae 55 D-5100 Aachen, Germany, herbert@zeus.informatik.rwth-aachen.de

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

reduction of functional expressions to normal form. Then we dene six typical provably

reduction of functional expressions to normal form. Then we dene six typical provably 1 A model for mathematical analysis of functional logic programs and their implementations Egon Borger a, Francisco J. Lopez-Fraguas and Mario Rodrguez-Artalejo b y a Dip. di Informatica, Universita di

More information

Multi-paradigm Declarative Languages

Multi-paradigm Declarative Languages Michael Hanus (CAU Kiel) Multi-paradigm Declarative Languages ICLP 2007 1 Multi-paradigm Declarative Languages Michael Hanus Christian-Albrechts-University of Kiel Programming Languages and Compiler Construction

More information

Higher-Order Conditional Term Rewriting. In this paper, we extend the notions of rst-order conditional rewrite systems

Higher-Order Conditional Term Rewriting. In this paper, we extend the notions of rst-order conditional rewrite systems Higher-Order Conditional Term Rewriting in the L Logic Programming Language Preliminary Results Amy Felty AT&T Bell Laboratories 600 Mountain Avenue Murray Hill, NJ 07974 Abstract In this paper, we extend

More information

,, 1{48 () c Kluwer Academic Publishers, Boston. Manufactured in The Netherlands. Optimal Representations of Polymorphic Types with Subtyping * ALEXAN

,, 1{48 () c Kluwer Academic Publishers, Boston. Manufactured in The Netherlands. Optimal Representations of Polymorphic Types with Subtyping * ALEXAN ,, 1{48 () c Kluwer Academic Publishers, Boston. Manufactured in The Netherlands. Optimal Representations of Polymorphic Types with Subtyping * ALEXANDER AIKEN aiken@cs.berkeley.edu EECS Department, University

More information

Lambda Calculus and Type Inference

Lambda Calculus and Type Inference Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ October 13, 2004 Lambda Calculus and Type

More information

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic 3.4 Deduction and Evaluation: Tools 3.4.1 Conditional-Equational Logic The general definition of a formal specification from above was based on the existence of a precisely defined semantics for the syntax

More information

CS4215 Programming Language Implementation. Martin Henz

CS4215 Programming Language Implementation. Martin Henz CS4215 Programming Language Implementation Martin Henz Thursday 26 January, 2012 2 Chapter 4 The Language simpl In this chapter, we are exting the language epl in order to provide a more powerful programming

More information

Functional Logic Programming: From Theory to Curry

Functional Logic Programming: From Theory to Curry Functional Logic Programming: From Theory to Curry Michael Hanus Institut für Informatik, CAU Kiel, D-24098 Kiel, Germany. mh@informatik.uni-kiel.de Abstract. Functional logic programming languages combine

More information

Algebra of Logic Programming Silvija Seres Michael Spivey Tony Hoare Oxford University Computing Laboratory Wolfson Building, Parks Road, Oxford OX1 3

Algebra of Logic Programming Silvija Seres Michael Spivey Tony Hoare Oxford University Computing Laboratory Wolfson Building, Parks Road, Oxford OX1 3 Algebra of Logic Programming Silvija Seres Michael Spivey Tony Hoare Oxford University Computing Laboratory Wolfson Building, Parks Road, Oxford OX1 3QD, U.K. Abstract A declarative programming language

More information

Functional Logic Programming. Kristjan Vedel

Functional Logic Programming. Kristjan Vedel Functional Logic Programming Kristjan Vedel Imperative vs Declarative Algorithm = Logic + Control Imperative How? Explicit Control Sequences of commands for the computer to execute Declarative What? Implicit

More information

Multi-paradigm Declarative Languages

Multi-paradigm Declarative Languages c Springer-Verlag In Proc. of the International Conference on Logic Programming, ICLP 2007. Springer LNCS 4670, pp. 45-75, 2007 Multi-paradigm Declarative Languages Michael Hanus Institut für Informatik,

More information

Tidying up the Mess around the Subsumption Theorem in Inductive Logic Programming Shan-Hwei Nienhuys-Cheng Ronald de Wolf bidewolf

Tidying up the Mess around the Subsumption Theorem in Inductive Logic Programming Shan-Hwei Nienhuys-Cheng Ronald de Wolf bidewolf Tidying up the Mess around the Subsumption Theorem in Inductive Logic Programming Shan-Hwei Nienhuys-Cheng cheng@cs.few.eur.nl Ronald de Wolf bidewolf@cs.few.eur.nl Department of Computer Science, H4-19

More information

sketchy and presupposes knowledge of semantic trees. This makes that proof harder to understand than the proof we will give here, which only needs the

sketchy and presupposes knowledge of semantic trees. This makes that proof harder to understand than the proof we will give here, which only needs the The Subsumption Theorem in Inductive Logic Programming: Facts and Fallacies Shan-Hwei Nienhuys-Cheng Ronald de Wolf cheng@cs.few.eur.nl bidewolf@cs.few.eur.nl Department of Computer Science, H4-19 Erasmus

More information

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m. CS 6110 S18 Lecture 8 Structural Operational Semantics and IMP Today we introduce a very simple imperative language, IMP, along with two systems of rules for evaluation called small-step and big-step semantics.

More information

1 INTRODUCTION 2 Represent a multiset as an association list, where the rst argument of a pair is an item and the second argument is the multiplicity

1 INTRODUCTION 2 Represent a multiset as an association list, where the rst argument of a pair is an item and the second argument is the multiplicity Programming with Multisets J.W. Lloyd Department of Computer Science University of Bristol Bristol BS8 1UB, UK Abstract This paper proposes a novel way of introducing multisets into declarative programming

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language

More information

Algebraic Properties of CSP Model Operators? Y.C. Law and J.H.M. Lee. The Chinese University of Hong Kong.

Algebraic Properties of CSP Model Operators? Y.C. Law and J.H.M. Lee. The Chinese University of Hong Kong. Algebraic Properties of CSP Model Operators? Y.C. Law and J.H.M. Lee Department of Computer Science and Engineering The Chinese University of Hong Kong Shatin, N.T., Hong Kong SAR, China fyclaw,jleeg@cse.cuhk.edu.hk

More information

A Boolean Expression. Reachability Analysis or Bisimulation. Equation Solver. Boolean. equations.

A Boolean Expression. Reachability Analysis or Bisimulation. Equation Solver. Boolean. equations. A Framework for Embedded Real-time System Design? Jin-Young Choi 1, Hee-Hwan Kwak 2, and Insup Lee 2 1 Department of Computer Science and Engineering, Korea Univerity choi@formal.korea.ac.kr 2 Department

More information

Functional Logic Programming Language Curry

Functional Logic Programming Language Curry Functional Logic Programming Language Curry Xiang Yin Department of Computer Science McMaster University November 9, 2010 Outline Functional Logic Programming Language 1 Functional Logic Programming Language

More information

SOFTWARE ENGINEERING DESIGN I

SOFTWARE ENGINEERING DESIGN I 2 SOFTWARE ENGINEERING DESIGN I 3. Schemas and Theories The aim of this course is to learn how to write formal specifications of computer systems, using classical logic. The key descriptional technique

More information

LP attracted two kinds of enthousiasts engineers/programmers \Never had I experienced such ease in getting a complex program coded and running" D.H.D.

LP attracted two kinds of enthousiasts engineers/programmers \Never had I experienced such ease in getting a complex program coded and running D.H.D. Logic Programming Revisited Logic Programs as Inductive Denitions An engineers' view Maurice Bruynooghe Katholieke Universiteit Leuven, Belgium Partly based on work of Marc Denecker In the beginning (1974),

More information

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions. CS 6110 S18 Lecture 18 Denotational Semantics 1 What is Denotational Semantics? So far we have looked at operational semantics involving rules for state transitions, definitional semantics involving translations

More information

the application rule M : x:a: B N : A M N : (x:a: B) N and the reduction rule (x: A: B) N! Bfx := Ng. Their algorithm is not fully satisfactory in the

the application rule M : x:a: B N : A M N : (x:a: B) N and the reduction rule (x: A: B) N! Bfx := Ng. Their algorithm is not fully satisfactory in the The Semi-Full Closure of Pure Type Systems? Gilles Barthe Institutionen for Datavetenskap, Chalmers Tekniska Hogskola, Goteborg, Sweden Departamento de Informatica, Universidade do Minho, Braga, Portugal

More information

Safe Stratified Datalog With Integer Order Does not Have Syntax

Safe Stratified Datalog With Integer Order Does not Have Syntax Safe Stratified Datalog With Integer Order Does not Have Syntax Alexei P. Stolboushkin Department of Mathematics UCLA Los Angeles, CA 90024-1555 aps@math.ucla.edu Michael A. Taitslin Department of Computer

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

SORT INFERENCE \coregular" signatures, they derive an algorithm for computing a most general typing for expressions e which is only slightly more comp

SORT INFERENCE \coregular signatures, they derive an algorithm for computing a most general typing for expressions e which is only slightly more comp Haskell Overloading is DEXPTIME{complete Helmut Seidl Fachbereich Informatik Universitat des Saarlandes Postfach 151150 D{66041 Saarbrucken Germany seidl@cs.uni-sb.de Febr., 1994 Keywords: Haskell type

More information

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution Foundations of AI 9. Predicate Logic Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution Wolfram Burgard, Andreas Karwath, Bernhard Nebel, and Martin Riedmiller 09/1 Contents Motivation

More information

MAX-PLANCK-INSTITUT F UR. Ordered Semantic Hyper-Linking. David A. Plaisted. MPI{I{94{235 August 1994 INFORMATIK. Im Stadtwald. D Saarbrucken

MAX-PLANCK-INSTITUT F UR. Ordered Semantic Hyper-Linking. David A. Plaisted. MPI{I{94{235 August 1994 INFORMATIK. Im Stadtwald. D Saarbrucken MAX-PLANCK-INSTITUT F UR INFORMATIK Ordered Semantic Hyper-Linking David A. Plaisted MPI{I{94{235 August 1994 k I N F O R M A T I K Im Stadtwald D 66123 Saarbrucken Germany Authors' Addresses David Plaisted

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

Chapter 2 The Language PCF

Chapter 2 The Language PCF Chapter 2 The Language PCF We will illustrate the various styles of semantics of programming languages with an example: the language PCF Programming language for computable functions, also called Mini-ML.

More information

Lambda Calculus and Type Inference

Lambda Calculus and Type Inference Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ August 17, 2007 Lambda Calculus and Type

More information

Propositional Logic. Part I

Propositional Logic. Part I Part I Propositional Logic 1 Classical Logic and the Material Conditional 1.1 Introduction 1.1.1 The first purpose of this chapter is to review classical propositional logic, including semantic tableaux.

More information

Adding Constraint Handling Rules to Curry Extended Abstract

Adding Constraint Handling Rules to Curry Extended Abstract Adding Constraint Handling Rules to Curry Extended Abstract Michael Hanus Institut für Informatik, CAU Kiel, D-24098 Kiel, Germany. mh@informatik.uni-kiel.de Abstract. This paper proposes an integration

More information

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur Module 6 Knowledge Representation and Logic (First Order Logic) 6.1 Instructional Objective Students should understand the advantages of first order logic as a knowledge representation language Students

More information

Towards a Logical Reconstruction of Relational Database Theory

Towards a Logical Reconstruction of Relational Database Theory Towards a Logical Reconstruction of Relational Database Theory On Conceptual Modelling, Lecture Notes in Computer Science. 1984 Raymond Reiter Summary by C. Rey November 27, 2008-1 / 63 Foreword DB: 2

More information

Chapter 3: Propositional Languages

Chapter 3: Propositional Languages Chapter 3: Propositional Languages We define here a general notion of a propositional language. We show how to obtain, as specific cases, various languages for propositional classical logic and some non-classical

More information

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Semantics via Syntax. f (4) = if define f (x) =2 x + 55. 1 Semantics via Syntax The specification of a programming language starts with its syntax. As every programmer knows, the syntax of a language comes in the shape of a variant of a BNF (Backus-Naur Form)

More information

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

1 Introduction. 3 Syntax

1 Introduction. 3 Syntax CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,

More information

Part I Logic programming paradigm

Part I Logic programming paradigm Part I Logic programming paradigm 1 Logic programming and pure Prolog 1.1 Introduction 3 1.2 Syntax 4 1.3 The meaning of a program 7 1.4 Computing with equations 9 1.5 Prolog: the first steps 15 1.6 Two

More information

Type Processing by Constraint Reasoning

Type Processing by Constraint Reasoning , Martin Sulzmann, Jeremy Wazny 8th November 2006 Chameleon Chameleon is Haskell-style language treats type problems using constraints gives expressive error messages has a programmable type system Developers:

More information

Overloading, Type Classes, and Algebraic Datatypes

Overloading, Type Classes, and Algebraic Datatypes Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827

More information

Lecture 1: Conjunctive Queries

Lecture 1: Conjunctive Queries CS 784: Foundations of Data Management Spring 2017 Instructor: Paris Koutris Lecture 1: Conjunctive Queries A database schema R is a set of relations: we will typically use the symbols R, S, T,... to denote

More information

Infinite Derivations as Failures

Infinite Derivations as Failures Infinite Derivations as Failures Andrea Corradi and Federico Frassetto DIBRIS, Università di Genova, Italy name.surname@dibris.unige.it Abstract. When operating on cyclic data, programmers have to take

More information

Term Algebras with Length Function and Bounded Quantifier Elimination

Term Algebras with Length Function and Bounded Quantifier Elimination with Length Function and Bounded Ting Zhang, Henny B Sipma, Zohar Manna Stanford University tingz,sipma,zm@csstanfordedu STeP Group, September 3, 2004 TPHOLs 2004 - p 1/37 Motivation: Program Verification

More information

Type Checking and Type Inference

Type Checking and Type Inference Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

More information

Functions. Def. Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A.

Functions. Def. Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A. Functions functions 1 Def. Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A. a A! b B b is assigned to a a A! b B f ( a) = b Notation: If

More information

Tilings of the Euclidean plane

Tilings of the Euclidean plane Tilings of the Euclidean plane Yan Der, Robin, Cécile January 9, 2017 Abstract This document gives a quick overview of a eld of mathematics which lies in the intersection of geometry and algebra : tilings.

More information

Introduction to SML Getting Started

Introduction to SML Getting Started Introduction to SML Getting Started Michael R. Hansen mrh@imm.dtu.dk Informatics and Mathematical Modelling Technical University of Denmark c Michael R. Hansen, Fall 2004 p.1/15 Background Standard Meta

More information

What does my program mean?

What does my program mean? September 16, 2015 L02-1 What does my program mean? Armando Solar Lezama Computer Science and Artificial Intelligence Laboratory M.I.T. Adapted from Arvind 2010. Used with permission. September 16, 2015

More information

Constructive negation with the well-founded semantics for CLP

Constructive negation with the well-founded semantics for CLP Constructive negation with the well-founded semantics for CLP Włodek Drabent Institute of Computer Science Polish Academy of Sciences, Warszawa, and IDA, Linköping University Jan Maluszynski, Jakob Henriksson

More information

Multi-Paradigm Programming

Multi-Paradigm Programming ETAPS 2000 Multi-Paradigm Programming Michael Hanus Christian-Albrechts-Universität Kiel Extend functional languages with features for ➀ logic (constraint) programming ➁ object-oriented programming ➂ concurrent

More information

Functions. How is this definition written in symbolic logic notation?

Functions. How is this definition written in symbolic logic notation? functions 1 Functions Def. Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A. We write f(a) = b if b is the unique element of B assigned by

More information

Induction and Semantics in Dafny

Induction and Semantics in Dafny 15-414 Lecture 11 1 Instructor: Matt Fredrikson Induction and Semantics in Dafny TA: Ryan Wagner Encoding the syntax of Imp Recall the abstract syntax of Imp: a AExp ::= n Z x Var a 1 + a 2 b BExp ::=

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

The Programming Language Core

The Programming Language Core The Programming Language Core Wolfgang Schreiner Research Institute for Symbolic Computation (RISC-Linz) Johannes Kepler University, A-4040 Linz, Austria Wolfgang.Schreiner@risc.uni-linz.ac.at http://www.risc.uni-linz.ac.at/people/schreine

More information

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen Formal semantics of loosely typed languages Joep Verkoelen Vincent Driessen June, 2004 ii Contents 1 Introduction 3 2 Syntax 5 2.1 Formalities.............................. 5 2.2 Example language LooselyWhile.................

More information

SAT solver of Howe & King as a logic program

SAT solver of Howe & King as a logic program SAT solver of Howe & King as a logic program W lodzimierz Drabent June 6, 2011 Howe and King [HK11b, HK11a] presented a SAT solver which is an elegant and concise Prolog program of 22 lines. It is not

More information

Program Design in PVS. Eindhoven University of Technology. Abstract. Hoare triples (precondition, program, postcondition) have

Program Design in PVS. Eindhoven University of Technology. Abstract. Hoare triples (precondition, program, postcondition) have Program Design in PVS Jozef Hooman Dept. of Computing Science Eindhoven University of Technology P.O. Box 513, 5600 MB Eindhoven, The Netherlands e-mail: wsinjh@win.tue.nl Abstract. Hoare triples (precondition,

More information

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor COSC252: Programming Languages: Semantic Specification Jeremy Bolton, PhD Adjunct Professor Outline I. What happens after syntactic analysis (parsing)? II. Attribute Grammars: bridging the gap III. Semantic

More information

Program Analysis: Lecture 02 Page 1 of 32

Program Analysis: Lecture 02 Page 1 of 32 Program Analysis: Lecture 02 Page 1 of 32 Program Analysis/ Mooly Sagiv Lecture 1, 31/10/2012 Operational Semantics Notes by: Kalev Alpernas As background to the subject of Program Analysis, we will first

More information

Taxonomic Syntax for First Order Inference. Abstract: We identify a new polynomial time decidable fragment of rst order

Taxonomic Syntax for First Order Inference. Abstract: We identify a new polynomial time decidable fragment of rst order Taxonomic Syntax for First Order Inference DAVID MCALLESTER and ROBERT GIVAN Massachusetts Institute of Technology, Cambridge Massachusetts Abstract: We identify a new polynomial time decidable fragment

More information

Handout 9: Imperative Programs and State

Handout 9: Imperative Programs and State 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 9: Imperative Programs and State Imperative

More information

Towards a Safe Partial Evaluation of Lazy Functional Logic Programs

Towards a Safe Partial Evaluation of Lazy Functional Logic Programs WFLP 2007 Towards a Safe Partial Evaluation of Lazy Functional Logic Programs Sebastian Fischer 1 Department of Computer Science, University of Kiel Olshausenstr. 40, D-24098, Kiel, Germany Josep Silva

More information

Fall Lecture 3 September 4. Stephen Brookes

Fall Lecture 3 September 4. Stephen Brookes 15-150 Fall 2018 Lecture 3 September 4 Stephen Brookes Today A brief remark about equality types Using patterns Specifying what a function does equality in ML e1 = e2 Only for expressions whose type is

More information

Discrete Optimization. Lecture Notes 2

Discrete Optimization. Lecture Notes 2 Discrete Optimization. Lecture Notes 2 Disjunctive Constraints Defining variables and formulating linear constraints can be straightforward or more sophisticated, depending on the problem structure. The

More information

LOGIC AND DISCRETE MATHEMATICS

LOGIC AND DISCRETE MATHEMATICS LOGIC AND DISCRETE MATHEMATICS A Computer Science Perspective WINFRIED KARL GRASSMANN Department of Computer Science University of Saskatchewan JEAN-PAUL TREMBLAY Department of Computer Science University

More information

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,

More information

Constrained Types and their Expressiveness

Constrained Types and their Expressiveness Constrained Types and their Expressiveness JENS PALSBERG Massachusetts Institute of Technology and SCOTT SMITH Johns Hopkins University A constrained type consists of both a standard type and a constraint

More information

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Massachusetts Institute of Technology Language Definition Problem How to precisely define language Layered structure

More information

such internal data dependencies can be formally specied. A possible approach to specify

such internal data dependencies can be formally specied. A possible approach to specify Chapter 6 Specication and generation of valid data unit instantiations In this chapter, we discuss the problem of generating valid data unit instantiations. As valid data unit instantiations must adhere

More information

Simplifying subtyping constraints Francois Pottier Ecole Normale Superieure { INRIA Abstract This paper studies type inferen

Simplifying subtyping constraints Francois Pottier Ecole Normale Superieure { INRIA Abstract This paper studies type inferen Simplifying subtyping constraints Francois Pottier Ecole Normale Superieure { INRIA Francois.Pottier@inria.fr Abstract This paper studies type inference for a functional, ML-style language with subtyping,

More information

Functional Logic Design Patterns

Functional Logic Design Patterns FLOPS 2002 Functional Logic Design Patterns Michael Hanus Christian-Albrechts-Universität Kiel joint work with Sergio Antoy Portland State University 1 SOME HISTORY AND MOTIVATION 1993 ([POPL 94, JACM

More information

EXTENDING LOGIC PROGRAMMING WITH COINDUCTION APPROVED BY SUPERVISORY COMMITTEE: Gopal Gupta, Chair. Dung T. Huynh. R. Chandrasekaran.

EXTENDING LOGIC PROGRAMMING WITH COINDUCTION APPROVED BY SUPERVISORY COMMITTEE: Gopal Gupta, Chair. Dung T. Huynh. R. Chandrasekaran. EXTENDING LOGIC PROGRAMMING WITH COINDUCTION APPROVED BY SUPERVISORY COMMITTEE: Gopal Gupta, Chair Dung T. Huynh R. Chandrasekaran Neeraj Mittal Copyright 2006 Luke Evans Simon All Rights Reserved To my

More information

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

MIT Specifying Languages with Regular Expressions and Context-Free Grammars MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Language Definition Problem How to precisely

More information

when a process of the form if be then p else q is executed and also when an output action is performed. 1. Unnecessary substitution: Let p = c!25 c?x:

when a process of the form if be then p else q is executed and also when an output action is performed. 1. Unnecessary substitution: Let p = c!25 c?x: URL: http://www.elsevier.nl/locate/entcs/volume27.html 7 pages Towards Veried Lazy Implementation of Concurrent Value-Passing Languages (Abstract) Anna Ingolfsdottir (annai@cs.auc.dk) BRICS, Dept. of Computer

More information

Data Types The ML Type System

Data Types The ML Type System 7 Data Types 7.2.4 The ML Type System The following is an ML version of the tail-recursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let

More information

Big-step Operational Semantics Revisited

Big-step Operational Semantics Revisited Fundamenta Informaticae XXI (2001) 1001 1035 1001 IOS Press Big-step Operational Semantics Revisited Jarosław ominik Mateusz Kuśmierek Institute of Informatics Warsaw University, Poland jdk@google.com

More information

Chapter 3. Describing Syntax and Semantics

Chapter 3. Describing Syntax and Semantics Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings of Programs:

More information

Efficient Implementation of General Negation Using Abstract Interpretation

Efficient Implementation of General Negation Using Abstract Interpretation Efficient Implementation of General Negation Using Abstract Interpretation Susana Muñoz Juan José Moreno Manuel Hermenegildo Abstract While negation has been a very active área of research in logic programming,

More information

The design of a programming language for provably correct programs: success and failure

The design of a programming language for provably correct programs: success and failure The design of a programming language for provably correct programs: success and failure Don Sannella Laboratory for Foundations of Computer Science School of Informatics, University of Edinburgh http://homepages.inf.ed.ac.uk/dts

More information

On Meaning Preservation of a Calculus of Records

On Meaning Preservation of a Calculus of Records On Meaning Preservation of a Calculus of Records Emily Christiansen and Elena Machkasova Computer Science Discipline University of Minnesota, Morris Morris, MN 56267 chri1101, elenam@morris.umn.edu Abstract

More information

nfn2dlp: A Normal Form Nested Programs Compiler

nfn2dlp: A Normal Form Nested Programs Compiler nfn2dlp: A Normal Form Nested Programs Compiler Annamaria Bria, Wolfgang Faber, and Nicola Leone Department of Mathematics, University of Calabria, 87036 Rende (CS), Italy {a.bria,faber,leone}@mat.unical.it

More information

Flang typechecker Due: February 27, 2015

Flang typechecker Due: February 27, 2015 CMSC 22610 Winter 2015 Implementation of Computer Languages I Flang typechecker Due: February 27, 2015 Project 3 February 9, 2015 1 Introduction The third project is to implement a type checker for Flang,

More information

Where is ML type inference headed?

Where is ML type inference headed? 1 Constraint solving meets local shape inference September 2005 2 Types are good A type is a concise description of the behavior of a program fragment. Typechecking provides safety or security guarantees.

More information

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 11 p. 1/38

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 11 p. 1/38 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 11 p. 1/38 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science

More information

Subtyping and Overloading in a Functional Programming Language. Wilhelm-Schickard-Institut, Universitat Tubingen, Sand 13. D Tubingen. matching.

Subtyping and Overloading in a Functional Programming Language. Wilhelm-Schickard-Institut, Universitat Tubingen, Sand 13. D Tubingen. matching. Subtyping and Overloading in a Functional Programming Language Martin Plumicke and Herbert Klaeren Wilhelm-Schickard-Institut, Universitat Tubingen, Sand 13 D-72076 Tubingen pluemick@informatik.uni-tuebingen.de

More information

Chapter 15. Functional Programming. Topics. Currying. Currying: example. Currying: example. Reduction

Chapter 15. Functional Programming. Topics. Currying. Currying: example. Currying: example. Reduction Topics Chapter 15 Functional Programming Reduction and Currying Recursive definitions Local definitions Type Systems Strict typing Polymorphism Classes Booleans Characters Enumerations Tuples Strings 2

More information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

More information

3.7 Denotational Semantics

3.7 Denotational Semantics 3.7 Denotational Semantics Denotational semantics, also known as fixed-point semantics, associates to each programming language construct a well-defined and rigorously understood mathematical object. These

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

HANDBOOK OF LOGIC IN ARTIFICIAL INTELLIGENCE AND LOGIC PROGRAMMING

HANDBOOK OF LOGIC IN ARTIFICIAL INTELLIGENCE AND LOGIC PROGRAMMING HANDBOOK OF LOGIC IN ARTIFICIAL INTELLIGENCE AND LOGIC PROGRAMMING Volume 5 Logic Programming Edited by DOV M. GABBAY and C. J. HOGGER Imperial College of Science, Technology and Medicine London and J.

More information

CSC Discrete Math I, Spring Sets

CSC Discrete Math I, Spring Sets CSC 125 - Discrete Math I, Spring 2017 Sets Sets A set is well-defined, unordered collection of objects The objects in a set are called the elements, or members, of the set A set is said to contain its

More information

Conjunctive queries. Many computational problems are much easier for conjunctive queries than for general first-order queries.

Conjunctive queries. Many computational problems are much easier for conjunctive queries than for general first-order queries. Conjunctive queries Relational calculus queries without negation and disjunction. Conjunctive queries have a normal form: ( y 1 ) ( y n )(p 1 (x 1,..., x m, y 1,..., y n ) p k (x 1,..., x m, y 1,..., y

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

The CIFF Proof Procedure for Abductive Logic Programming with Constraints

The CIFF Proof Procedure for Abductive Logic Programming with Constraints The CIFF Proof Procedure for Abductive Logic Programming with Constraints U. Endriss 1, P. Mancarella 2, F. Sadri 1, G. Terreni 2, and F. Toni 1,2 1 Department of Computing, Imperial College London Email:

More information

Evaluation Trees for Proposition Algebra

Evaluation Trees for Proposition Algebra Evaluation Trees for Proposition Algebra Alban Ponse joined work with Jan A. Bergstra section Theory of Computer Science Informatics Institute, University of Amsterdam https://staff.fnwi.uva.nl/a.ponse/

More information