Rewriting, Explicit Substitutions and Normalisation

Similar documents
Termherschrijfsystemen 2003

The Lambda-Calculus Reduction System

Equational Logic. Chapter 4

07 Equational Logic and Algebraic Reasoning

Techniques de réécriture et transformations

Origin in Mathematical Logic

Cheat Sheet Equational Logic (Spring 2013) Terms. Inductive Construction. Positions: Denoting Subterms TERMS

3.2 Equivalence, Evaluation and Reduction Strategies

HORSes: format, termination and confluence

Lazy Strong Normalization

Lambda-Calculus (I) 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010

On the Standardization Theorem for λβη-calculus

The non-logical symbols determine a specific F OL language and consists of the following sets. Σ = {Σ n } n<ω

Theorem 4.18 ( Critical Pair Theorem ) A TRS R is locally confluent if and only if all its critical pairs are joinable.

Realisability methods of proof and semantics with application to expansion

Origin in Mathematical Logic

Nominal Completion for Rewrite Systems with Binders

Non- -overlappings TRSs are UN. Stefan Kahrs and Connor Smith University of Kent

Models of computation

arxiv: v1 [cs.lo] 29 May 2014

Denotational semantics: proofs

Sub-λ-calculi, Classified

Alonzo Church ( ) Lambda Calculus. λ-calculus : syntax. Grammar for terms : Inductive denition for λ-terms

Lecture 3. Lambda calculus. Iztok Savnik, FAMNIT. October, 2015.

Lambda Calculus. Andrés Sicard-Ramírez. Semester Universidad EAFIT

Reducibility proofs in λ-calculi with intersection types

Small families. (at INRIA with Gérard and in the historical λ-calculus) Jean-Jacques Lévy

Mathematical Synthesis of Equational Deduction Systems. Marcelo Fiore. Computer Laboratory University of Cambridge

Advanced Lambda Calculus. Henk Barendregt & Giulio Manzonetto ICIS Faculty of Science Radboud University Nijmegen, The Netherlands

Outline. Overview. Introduction. Well-Founded Monotone Algebras. Monotone algebras. Polynomial Interpretations. Dependency Pairs

TERESE LITE. Excerpts from the book TERM REWRITING SYSTEMS by Terese

Beyond First-Order Logic

COMP6463: λ-calculus

From Constructibility and Absoluteness to Computability and Domain Independence

Introduction to λ-calculus

Lecture 2. Lambda calculus. Iztok Savnik, FAMNIT. March, 2018.

Modularity of Confluence: A Simplified Proof

Mathematical Logic IV

Confluence and Normalization in Reduction Systems Lecture Notes

Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. Radboud University Nijmegen. March 5, 2012

Functional Programming with Coq. Yuxin Deng East China Normal University

1. Object Calculus. Object calculus is to OO languages what lambda calculus is to functional languages

Nominal Rewriting. Maribel Fernández. ISR - June King s College London

On the Complexity of the Reflected Logic of Proofs

Minimal logic for computable functionals

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification

Towards Correctness of Program Transformations Through Unification and Critical Pair Computation

Categories, Proofs and Programs

Propositional and Predicate Logic. jean/gbooks/logic.html

A REWRITING VIEW OF SIMPLE TYPING

Innermost Reductions Find All Normal Forms on Right-Linear Terminating Overlay TRSs

Classical Combinatory Logic

Jacques Fleuriot. Automated Reasoning Rewrite Rules

Computational Soundness of a Call by Name Calculus of Recursively-scoped Records. UMM Working Papers Series, Volume 2, Num. 3.

Simply Typed λ-calculus

Traditional and Non Traditional lambda calculi

Programming Language Concepts: Lecture 18

A Common Notation System for the Lambda-Calculus and Combinatory Logic

Semantics with Intersection Types

Part 2: First-Order Logic

Dependent Types and Explicit Substitutions

Solutions to Exercises. Solution to Exercise 2.4. Solution to Exercise 2.5. D. Sabel and M. Schmidt-Schauß 1

Theory of Computation

SHARING IN THE WEAK LAMBDA-CALCULUS REVISITED

Graph lambda theories

The Suspension Notation as a Calculus of Explicit Substitutions

Consequence Relations and Natural Deduction

Gödel s Incompleteness Theorem. Overview. Computability and Logic

A Polynomial Algorithm for Uniqueness of Normal Forms of Linear Shallow Term Rewrite Systems 1. Julian Zinn 2 and Rakesh Verma

06 From Propositional to Predicate Logic

Typed Lambda Calculi. Nikos Tzeveλekos Queen Mary, University of London 1 / 23

A Needed Narrowing Strategy

l-calculus and Decidability

FIXED POINTS AND EXTENSIONALITY IN TYPED FUNCTIONAL PROGRAMMING LANGUAGES

Denoting computation

From Operational Semantics to Abstract Machines

Seminaar Abstrakte Wiskunde Seminar in Abstract Mathematics Lecture notes in progress (27 March 2010)

Reduction Strategies and Acyclicity

A Geometric Proof of Confluence by Decreasing Diagrams

A Behavioural Model for Klop s Calculus

Jan A. Bergstra and Alban Ponse. Informatics Institute, section Theory of Computer Science University of Amsterdam

Decreasing Diagrams: Two Labels Suffice

Computational Logic. Davide Martinenghi. Spring Free University of Bozen-Bolzano. Computational Logic Davide Martinenghi (1/26)

Sequent Combinators: A Hilbert System for the Lambda Calculus

Proofs in classical logic as programs: a generalization of lambda calculus. A. Salibra. Università Ca Foscari Venezia

Komponenten- und Service-orientierte Softwarekonstruktion

hal , version 1-21 Oct 2009

Completeness Theorems and λ-calculus

Informal Statement Calculus

Subtyping and Intersection Types Revisited

The formal proof sketch challenge

Models of Computation,

Introduction to lambda calculus Part 2

Computability via the Lambda Calculus with Patterns

First-Order Theorem Proving and Vampire

Church s undecidability result

Discrete Mathematics. Benny George K. September 22, 2011

A Machine Checked Model of Idempotent MGU Axioms For a List of Equational Constraints

Lecture Notes on Inductive Definitions

Algebraizing Hybrid Logic. Evangelos Tzanis University of Amsterdam Institute of Logic, Language and Computation

Transcription:

Rewriting, Explicit Substitutions and Normalisation XXXVI Escola de Verão do MAT Universidade de Brasilia Part 1/3 Eduardo Bonelli LIFIA (Fac. de Informática, UNLP, Arg.) and CONICET eduardo@lifia.info.unlp.edu.ar February, 2006 Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 1 / 73

Applications Operational Semantics Mathematical Reasoning Algebraic Specification Program Transformation Rewrite Systems Protocol Security Constraint Resolution Natural Languages Hardware Design Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 2 / 73

Example - Arithmetic Natural numbers as Peano numerals: 0, s(0), s(s(0)), etc. Rewrite system Reduction sequence a(x, 0) x a(x, s(y)) s(a(x, y)) m(x, 0) 0 m(x, s(y)) a(m(x, y), x) 2 + 2 = a(s(s(0)), s(s(0))) s(a(s(s(0)), s(0))) s(s(a(s(s(0)), 0))) s(s(s(s(0)))) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 3 / 73

Example - Negation Normal Form Rewrite system Reduction sequence x = y x y (x y) x y (x y) x y x x ( (x = y) z) ( ( x y) z) (( x y) z) ((x y) z) (x y) z ( x y) z ( x y) z Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 4 / 73

Example - Combinatory Logic Rewrite system Reduction sequence ((((S x) y) z) ((x z) (y z)) ((K x) y) x (I x) x (((S I ) I ) x) ((I x) (I x)) (x (I x)) (x x) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 5 / 73

Example - Functional Programming Rewrite system map(λx.m, nil) nil map(λx.m, cons(x, T )) cons(m{x/x }, map(λx.m, T )) Reduction sequence ([n] abbreviates cons(n, nil)) map(λx.cons(x, nil), cons(1, (cons(2, nil)))) cons([1], map(λx.cons(x, nil), cons(2, nil))) cons([1], cons([2], map(λx.cons(x, nil), nil))) cons([1], cons([2], nil)) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 6 / 73

Example - Object Oriented Programming Terms M ::= x variable [l i = ς(x i )N i {1..n} i ] object M.l method invocation M.l ς(x)n method update Rewrite system (o = [l i = ς(x i )N i i {1..n} ] and j 1..n) o.l j N j {x j /o} o.l j ς(x)n [l = ς(x)n, l i = ς(x i )N i {1..n}\{j} i ] Reduction sequence [l = ς(y)(y.l ς(x)x)].l [l = ς(y)(y.l ς(x)x)].l ς(x)x [l = ς(x)x] Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 7 / 73

Bibliography - Rewriting 1 Term Rewriting Systems, TERESE, Cambridge Tracts in Theoretical Computer Science, Vol. 55, CUP, 2003. 2 Term Rewriting and All That, Franz Baader, Tobias Nipkow, CUP, 1998. 3 Advanced Topics in Rewriting, Enno Ohlebusch, Springer, 2002. More information at the rewriting home page http://rewriting.loria.fr Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 9 / 73

Bibliography - Lambda Calculus The Lambda Calculus: Its Syntax and Semantics, Henk Barendregt, North Holland, 1984. Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 10 / 73

An Aside Definitions Examples Thm/Lemma/Proof Highlights or comments Statement of Thm/Lemma and proofs Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 11 / 73

Structure of Today s Talk 1 Abstract Reduction Systems 2 First-Order Rewriting 3 Lambda Calculus Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 12 / 73

Introduction An Abstract Reduction System (ARS) is a structure A, { α α I } where A is a set { α α I } is a family of binary relations on A indexed by I The relations α are called reduction relations In the case of just one reduction relation we write Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 13 / 73

Examples 1 α 2 A = {, } + and u v for u, v A if β α u = u 1 lu 2 and v = u 1 ru 2 l, r is one of,,,, Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 14 / 73

Reduction A reduction sequence or derivation w.r.t. α is a finite or infinite sequence a 0 α a 1 α a 2 α... A reduction step is an occurrence of α in a reduction sequence Recall from above,,,, Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 15 / 73

Notation = α + α α reflexive closure of α transitive closure of α reflexive, transitive closure of α Note: a α b iff there is a finite reduction sequence a = a 0 α a 1 α... α a n = b since Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 16 / 73

Confluence Diamond Property (DP) a Weak Church Rosser (WCR) a b c b c d a, b, c s.t. a b and a c, d s.t. b d and c d d a, b, c s.t. a b and a c, d s.t. b d and c d Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 17 / 73

Confluence Confluence or Church-Rosser (CR) a b c d a, b, c s.t. a b and a c, d s.t. b d and c d Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 18 / 73

Normalization Consider an ARS (A, ). a A is a normal form if there exists no b s.t. a b a A is weakly normalizing if a b for b a normal form; is weakly normalizing (WN) if every a A is weakly normalizing a A is strongly normalizing if every reduction sequence starting from a is finite; is strongly normalizing (SN) if every a A is strongly normalizing WN, SN Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 19 / 73

Interrelation between Properties CR = WCR (trivial) Lemma WCR CR Proof (counterexample - Hindley) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 20 / 73

Interrelation between Properties Thm (Newman s Lemma) WCR and SN = CR Proof [Huet1980] By well-founded induction WCR IH IH Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 21 / 73

1 Abstract Reduction Systems 2 First-Order Rewriting Terms Unification Rewrite Systems Confluence 3 Lambda Calculus Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 22 / 73

Terms Σ set of function symbols equipped with an arity n (n IN) X set of variables T (Σ) set of Σ-terms over X x X x T (Σ) f Σ of arity n M 1,..., M n T (Σ) f (M 1,..., M n ) T (Σ) Var(M) denotes the variables in M M is closed if Var(M) = Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 23 / 73

Terms - Example Signature Terms 0 (arity 0) s (arity 1) a (arity 2) m (arity 2) s(0) a(s(0), 0) a(m(x, y), 0) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 24 / 73

Terms as Trees The term tree of a(m(x, y), 0) a m 0 x y Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 25 / 73

Positions IN set of positions, where a position is a sequence of natural numbers i 1 i 2... i n (Note: we use ɛ for the empty sequence) Example: ɛ, 13, 249 (Note: We only use sequences of single digit numbers to avoid ambiguities) pos(m): Positions of the term tree of M a 1 2 m 0 1 2 x y M = a(m(x, y), 0) pos(m) = {ɛ, 1, 2, 11, 12} Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 26 / 73

Positions - Concatenation Concatenation of positions ɛ q = q (i p) q = i (p q) Prefix preorder p q ( p is a prefix of q ) iff r IN p r = q ɛ p, for all p 1 122 21 213 21 22 (disjoint positions) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 27 / 73

Subterms at a position M p : Subterm of M at position p pos(m) M ɛ = M M i q = N i {1..n} f (M 1,..., M n ) i q = N a(m(x, y), 0) 1 = m(x, y) a(m(x, y), 0) 1 2 = y Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 28 / 73

1 Abstract Reduction Systems 2 First-Order Rewriting Terms Unification Rewrite Systems Confluence 3 Lambda Calculus Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 29 / 73

Substitution A substitution is a map σ : T (Σ) T (Σ) which satisfies σ(f (M 1,..., M n )) = f (σ(m 1 ),..., σ(m n )) We usually write M σ instead of σ(m) σ = {x 1 /M 1,..., x n /M n } determines a unique substitution (the expected one) If M = f (x, g(y)) and σ = {x/g(a), y/f (x, x)}, then M σ = f (g(a), g(f (x, x))) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 30 / 73

Unification Terms M, N are said to be unifiable iff there exists a substitution σ (unifier) s.t. M σ = N σ 1 x is always unifiable with any M (provided that x / Var(M)) 2 f (x, g(x, a)) is unifiable with f (f (a), y) with unifier σ = {x/f (a), y/g(f (a), a)} 3 f (x, g(x, a)) and f (f (a), g(b, a)) are not unifiable Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 31 / 73

Preorder on Substitutions Composition of substitutions σ, τ, written σ τ, M σ τ = (M τ ) σ Subsumption (σ is more general than τ) σ τ iff υ s.t. υ σ = τ Note: is a preorder on substitutions (upto renaming) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 32 / 73

Most General Unifier Thm If M, N are unifiable, then there exists a most general unifier (MGU) of M, N. Furthermore, this MGU is unique upto renaming. Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 33 / 73

Unification Algorithm (Martelli-Montanari) E finite set of matching equations {f (M 1,..., M n ). = f (N 1,..., N n )} E = {M 1. = N1,..., M n. = Nn } E {f (M 1,..., M n ). = g(n 1,..., N m )} E = fail {x. = x} E = E {f (M 1,..., M n ). = x} E = {x. = f (M 1,..., M n )} E {x. = f (M 1,..., M n )} E = fail if x Var(M 1,..., M n ) {x. = M} E = {x. = M} E {x/m} if x / Var(M) x Var(E) To compute MGU of M and N, begin with {M. = N} and apply rules repeatedly This process is CR and SN Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 34 / 73

1 Abstract Reduction Systems 2 First-Order Rewriting Terms Unification Rewrite Systems Confluence 3 Lambda Calculus Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 35 / 73

Example a(x, 0) x a(x, s(y)) s(a(x, y)) m(x, 0) 0 m(x, s(y)) a(m(x, y), x) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 36 / 73

Reduction Rule A reduction rule for a signature Σ is a pair l, r of terms in T (Σ) such that 1 the left-hand side l is not a variable 2 every variable occurring in the right-hand side r occurs in l as well We often write l r We sometimes give rules a name and write ρ : l r We say ρ is left-linear if l contains at most one occurrence of any variable Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 37 / 73

Context Context: Term over Σ { }. Special symbol denotes a hole. If C is a context containing exactly n holes, then C[M 1,..., M n ] denotes the term resulting from replacing the holes of C from left to right with M 1,..., M n Unless stated, we restrict to contexts with exactly one occurence of The p in C[M] p indicates C p = 1 a(m(s( ), x), 0) 2 a(0, ) 3 Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 38 / 73

Redex A ρ-redex is an instance l σ of the left-hand side of rule ρ : l r in a term M (source) We use letters r, s for redexes A redex is determined by 1 Pair of terms (source,target) 2 Rule name 3 Position 4 Substitution In some cases, not all items are necessary Redexes that have the same source are called coinitial Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 39 / 73

Redex - Example ρ : f (x) x Consider the term f (f (y)); it has two ρ-redexes Source f (f (y)) f (f (y)) Target f (y) f (y) Rule ρ ρ Position ɛ 1 Subst {x/f (y)} {x/y} Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 40 / 73

Redex Patterns The pattern of a rule ρ : l r is l ɛ where x ɛ = for all variables x. The pattern of a ρ-redex is the pattern of ρ. Let P be the pattern of a ρ-redex s. Then 1 s = l σ = P[x σ 1,..., x σ n ] (note multiple holes) and 2 x σ 1,..., x σ n are the arguments of s Pattern of a(x, s(y)) s(a(x, y)) a s Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 41 / 73

Nested, Disjoint, Overlapping Two coinitial redexes s and r are said to be 1 Disjoint: if their positions are disjoint 2 Nested (say s nests r): if r occurs in an argument of s 3 Overlapping: if their patterns share at least one symbol occurrence Consider the TRS overlapping f(g(g(a))) f (g(x)) x g(a) y nested f(g(g(a))) We say f(g(g(a))) nests g(a) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 42 / 73

Reduction Step A reduction step according to the rule ρ : l r consists of contracting a redex within an arbitrary context C[l σ ] ρ C[r σ ] Occasionally we write C[l σ ] s C[r σ ] (or even s) for this reduction step, where s is the ρ-redex l σ in C[l σ ] If s 1,..., s n are composable redexes we write s 1 ;... ; s n for the resulting derivation We sometimes give derivations names d : s 1 ;... ; s n We write d for the number of steps in d Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 43 / 73

Example ρ : a(x, 0) x a(x, s(y)) s(a(x, y)) m(x, 0) 0 m(x, s(y)) a(m(x, y), x) Reduction step (C = s( ), σ = {x/s(s(0))}) s(a(s(s(0)), s(0))) ρ s(s(a(s(s(0)), 0))) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 44 / 73

Term Rewrite System A Term Rewrite System is a pair R = Σ, R of a signature Σ and a set of reduction rules R for Σ The one-step reduction relation of R is defined as the union = { s M s N, s a ρ-redex in M, ρ R} Note: T (Σ), is an ARS Thus all concepts of ARS are applicable to TRS Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 45 / 73

1 Abstract Reduction Systems 2 First-Order Rewriting Terms Unification Rewrite Systems Confluence 3 Lambda Calculus Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 46 / 73

Confluence - Reminder Confluence (CR) a b c d a, b, c s.t. a b and a c, d s.t. b d and c d Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 47 / 73

Techniques for Proving Confluence Abstract: Formulated for Abstract Reduction Systems Concrete: Formulated for Term Rewrite Systems Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 48 / 73

Techniques for Proving Confluence Abstract: Confluence by Strong confluence Equivalence... Concrete: Confluence by Critical pairs Orthogonality... Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 49 / 73

Strong Confluence [Huet1980] f (x, x) g(x) f (x, y) g(y) g(x) f (x, a) = Beware of asymmetry! Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 50 / 73

Equivalence A, A, B, B ARS 1 A B A and 2 B strongly confluent Then A is confluent Proof 1 (1) implies A = B 2 (2) implies B confluent 3 Result follows from (1),(2) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 51 / 73

Equivalence Let R be the TRS f (x) g(x, x) g(x, y) f (y) Define as 1 Show R R 2 Show is strongly confluent 3 Conclude R is confluent x x M M f (M) f (M ) M M N N g(m, N) g(m, N ) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 52 / 73

Techniques for Proving Confluence Abstract: Confluence by Strong confluence Equivalence... Concrete: Confluence by Critical pairs Orthogonality... Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 53 / 73

Critical Pairs Overlap between two left-hand sides of rewrite rules l r and g d variable disjoint rewrite rules. A critical pair between them is a pair l σ [d σ ] p, rσ where 1 p pos(l) and l p is not a variable 2 σ is a MGU of l p and g Note: l σ = l σ [g σ ] p l σ [d σ ] p r σ Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 54 / 73

Example Rewrite system Critical pairs (are there others?) (true) false (false) true ( (x)) x and(true, x) x and(false, x) false ( (true)) (false) ( (false)) true (true) false Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 55 / 73

Example Rewrite system x (y z) (x y) z Critical pairs x (y (z w)) x ((y z) w) (x y) (z w) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 56 / 73

WCR by Critical Pairs Thm R is WCR iff every critical pair is joinable Proof ) Trivial ) Take an arbitrary peak M and consider all possible cases s 0 s 1 P 0 P 1 in which this arises Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 57 / 73

s 0 and s 1 are disjoint - Direct Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 58 / 73

s 0 and s 1 are nested - Direct The bottom-right arrow may have to perform multiple steps if the rewrite rules are not left-linear Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 59 / 73

s 0 and s 1 overlap - Use hypothesis Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 60 / 73

Decidable Case of Confluence Thm Let R be finite and SN. Then confluence is decidable. Proof 1 Generate all critical pairs 2 For each critical pair u, v reduce u and v to their normal forms u, v 1 if u v for some u, v then fail 2 Otherwise, the system is confluent Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 61 / 73

Orthogonal TRS A TRS is called orthogonal (OTRS) if it is 1 left-linear and 2 without critical pairs Thm Orthogonal TRS are confluent Note that, in contrast to the previous result, we do not require the TRS to be SN Proof relies on the fact that coinitial, diverging reduction steps can always be joined More on orthogonal TRS later Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 62 / 73

1 Abstract Reduction Systems 2 First-Order Rewriting 3 Lambda Calculus Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 63 / 73

What is the Lambda Calculus A model of computation Concise and expressive Strong connections to proof theory and category theory Shown to be equivalent to Turing Machines Considered a suitable abstract model of programming languages Lambda calculus + Your new programming construct = Good testbed Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 64 / 73

Informal Introduction Fundamental construction: abstraction λx.x + 1 Similar to f (x) = x + 1 except that it is anonymous Fundamental operation: application of functions to arguments (λx.x + 1) 2 Both of these combined in their purest form: Everything is a function! Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 65 / 73

Syntax λ-terms (T (λ)) M ::= x variable M N application λx.m abstraction In an abstraction x is the (formal) parameter and M is the body λx binds all occurrences of x in M not under another λx notion of free and bound variables similar to that of first-order logic free variables of M: fv(m) In an application N is called an argument Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 66 / 73

Examples of λ-terms λx.x x λx.x x (self-application!) λx.λy.x (λx.x)(λx.x) x y λx.x = λy.y (terms differing only in the name of bound variables are considered equal; this is called α-equivalence) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 67 / 73

Reduction β : (λx.m) N M{x/N} 1 Substitution: M{x/N} denotes the term M where all free occurrences of x are replaced by N 2 Substitution may need to rename bound variables in order to avoid variable capture (λx.y){y/x} = λx.x (λx.y){y/x} = λz.x No! Variable capture Rename. Ok! We ignore extensionality in our presentation η : λx.m x M if x / fv(m) Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 68 / 73

Example 1 I y x{x/y} = y (where I = λx.x) 2 (I y) (I y)(i y) (where is λx.x x) 3 (I y) y y y 4 (λx.z)(i y) z 5 ω ω (x x){x/ω} = ω ω (where ω = λx.x x) 6 (λx.z) (ω ω) z Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 69 / 73

Two Basic Properties Lemma β is not WN (hence not SN) Proof (counterexample) ω ω ω ω ω ω... (where ω = λx.x x) Thm β is confluent Proof Use confluence by equivalence technique Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 70 / 73

De Bruijn Indices ( I don t really like de Bruijn indices myself (N. de Bruijn)) The idea: replace variable names by reference to declaration point λx.x becomes λ1 λx.λy.x becomes λλ2 Consequence: Renaming not necessary (replaced by index adjustment) λx.(λy.λz.y) x β λx.λz.x becomes λ(λλ2) 1 βdb λ((λ2){1/1}) = λλ2{2/2} = λλ2 Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 71 / 73

De Bruijn Indices β DB : (λm) N M{{1/N}} M{{1/N}} is substitution on terms with indices β is isomorphic to β DB β is easier for study purposes β DB is easier for implementation Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 72 / 73

Lambda Calculus vs First-Order Rewriting First-Order Rewriting natural model of computation concise representation of algebraic data types X functions are not treated as data Lambda Calculus natural model for reasoning about functions can encode programs, derivations, specifications X inefficient representation of algebraic types X more complex metatheory Eduardo Bonelli (LIFIA,CONICET) Rewriting, Explicit Substitutions and Normalisation February, 2006 73 / 73