Rewriting Abstract Reduction Relations
Total Page:16
File Type:pdf, Size:1020Kb
A Change in Notation From now on, when we write Γ j= ', 22c:295 Seminar in AI — Decision Procedures we will assume that all the free variables of ' and of each formula in Γ are universally quantified. Rewriting This is done for convenience, but note that it does change the Cesare Tinelli meaning of j= for non-closed formulas. [email protected] Example The University of Iowa Without implicit quantifiers: p(x) 6j= p(y). With the implicit quantifiers: p(x) j= p(y). Copyright 2004-05 — Cesare Tinelli and Clark Barrett. a a These notes were developed from a set of lecture notes originally written by Clark Barrett at New York University. These notes are copyrighted material and may not be used in other course settings outside of the University of Iowa in their current form or modified form without the express written permission of the copyright holders. Spring 04, 22c:295 Notes: Rewriting – p.1/25 Spring 04, 22c:295 Notes: Rewriting – p.3/25 Outline Rewriting • Rewriting Consider the general problem of establishing E j= s = t where E • Termination is a set of equations. • Completion Congruence closure handles the case when all equations are ground. (How?) Sources: There cannot be a simple procedure for the more general case Harrison, John. Introduction to Logic and Automated because first order logic with equality is, in general, undecidable. Theorem Proving. Unpublished manuscript. Used by permission. However, often the kind of equational reasoning needed is straightforward: equations are used in a predictable direction to simplify expressions. Using equations in a directional fashion is called rewriting, and there are indeed cases when this technique gives us a decision procedure. Spring 04, 22c:295 Notes: Rewriting – p.2/25 Spring 04, 22c:295 Notes: Rewriting – p.4/25 Rewriting Abstract Reduction Relations Suppose t is a term and l = r is an equation. An abstract reduction relation is any binary relation on a set X. 0 We will denote a generic abstract reduction relation by −!. We say that t results from rewriting t with l = r iff there is a subterm s of t and a substitution θ such that Every set R of rewrite rules induces an reduction relation on terms. We will denote that relation by . 1. s = θ(l), −!R 2. s0 = θ(r) and We will also denote by • 3. t0 is the result of replacing an occurrence of s by s0 in t. − the inverse of −! (i.e. x −! y iff y − x). • −!+ the transitive closure of −!. We call rewrite rules any (oriented) equations like l = r above. • −!∗ the reflexive-transitive closure of −!. 0 Given a set R of rewrite rules, we write t −! t iff there is some ∗ R • ! the reflexive-symmetric-transitive closure of −!. rule (l = r) 2 R which rewrites t to t0. Spring 04, 22c:295 Notes: Rewriting – p.5/25 Spring 04, 22c:295 Notes: Rewriting – p.7/25 Rewriting Abstract Reduction Relations 0 0 Theorem (Soundness or Rewriting) If t −!R t , then R j= t = t . Let −! be an abstract reduction relation on some set X. Proof Every rewrite can be duplicated by a single instantiation An element x 2 X is said to be in normal form (NF) with respect followed by a chain of congruences. 2 to −! iff there is no y 2 X such that x −! y. What about completeness? The relation −! is said to be terminating, strongly normalizing It depends on the rewrite rules. (SN), or noetherian iff there is no infinite reduction sequence: When a set of (oriented) equations R is canonical, the question x0 −! · · · −! xn −! · · · of whether R j= s = t for two terms s and t can be answered by rewriting. Note that −! is terminating iff − is well-founded. We will make this more precise later. Spring 04, 22c:295 Notes: Rewriting – p.6/25 Spring 04, 22c:295 Notes: Rewriting – p.8/25 Con¯uence Canonical Rewrite Systems Let −! be an abstract reduction relation on some set X. Theorem If R is a set of rewrite rules, then for all terms s and t, ∗ s !R t iff R j= s = t. • −! has the diamond property iff whenever x −! y and 0 0 Let s #R t denote that s and t are joinable, i.e., there exists a z x −! y , there is a z such that y −! z and y −! z. ∗ ∗ such that s −!R u and t −!R y. • −! is confluent or Church-Rosser (CR) if −!∗ has the ∗ diamond property. Theorem If −!R is confluent, then for any s and t, s !R t iff s # t. • −! is canonical if it is confluent and terminating. R • −! is weakly confluent or weakly Church-Rosser (WCR) if Corollary If −!R is terminating and weakly confluent, then it is whenever x −! y and x −! y0, there is a z such that canonical. Therefore, R j= s = t can be decided by rewriting s y −!∗ z and y0 −!∗ z. and t to normal forms and comparing them. Proof By Newman's Lemma, termination and weak con¯uence imply These notions are closely related: For instance, the diamond con¯uence. Also, termination implies the existence of normal forms. Thus, by property implies confluence which implies weak confluence. the above theorems, s and t have the same normal forms iff s #R t iff ∗ 2 s !R t iff R j= s = t. Spring 04, 22c:295 Notes: Rewriting – p.9/25 Spring 04, 22c:295 Notes: Rewriting – p.11/25 Con¯uence Reduction Orderings Weak confluence does not in general imply confluence, but A binary relation > on terms is said to be a rewrite ordering if it adding termination changes the story. is an ordering (i.e., an irreflexive and transitive relation) and is closed under instantiation and simple congruences, i.e. Newman's Lemma If −! is terminating and weakly confluent, then it is confluent. • It is never the case that t > t. ∗ ∗ 0 0 • Proof It suf®ces to show that if x −! y and x −! y with y and y in If s > t and t > u, then s > u. 0 normal form, then y = y . (Why?) This can be proved by well-founded • If s > t, then θ(s) > θ(t) for any substitution θ. 0 induction on −. Assume x writes to two normal forms: y and y . The only 0 • If s > t, then f(u1; : : : ; ui−1; s; ui+1; : : : ; un) > interesting case is when x differs from both y and y . (Why?) In that case, ∗ 0 ∗ 0 f(u1; : : : ; u −1; t; u +1; : : : ; u ). x −! w −! y and x −! w −! y . By weak con¯uence, there must i i n ∗ 0 ∗ 0 be a z such that w −! z and w −! z. Since w and w are A rewrite ordering > whose converse < is well-founded is said predecessors of x wrt −, by well-founded induction there must be a u such ∗ ∗ 0 ∗ 0 0 ∗ 0 to be a reduction ordering. that y −! u and z −! u, and a u such that z −! u and y −! u . 0 0 0 But y and y are in normal form, so it must be that y = u = z = u = y . 2 Spring 04, 22c:295 Notes: Rewriting – p.10/25 Spring 04, 22c:295 Notes: Rewriting – p.12/25 Reduction Orderings In Search of Less Partial Reduction Orderings Lemma If > is a reduction ordering and l > r for each equation The simple reduction ordering we defined earlier is not total. For l = r in R, then the rewrite relation −!R is terminating. instance, it does not order the following pairs of terms: Proof It is not hard to see that if s −!R t, then s > t. Thus, • (x ∗ y) ∗ z; x ∗ (y ∗ z) because < is well-founded, −!R must be terminating. 2 • x ∗ (y + z); x ∗ y + x ∗ z By this lemma, reduction orderings are very useful for proving To order such terms, we need more sophisticated orderings. the termination of a rewrite system R. Note While it is unreasonable to expect a reduction ordering to be total on arbitrary terms, reduction orderings that order more pairs of terms are preferable. Spring 04, 22c:295 Notes: Rewriting – p.13/25 Spring 04, 22c:295 Notes: Rewriting – p.15/25 Measure-based Orderings Lexicographic Path Orderings (simpli®ed version) Let us denote by jtj the number of variables and function symbol A sequence s1; : : : ; sm is lexicographically greater than a occurrences in t. sequence t1; : : : ; tm with respect to an ordering > on terms if there is some 1 ≤ n ≤ m such that s = t for all i < n and We might hope to define a reduction ordering s > t by jsj > jtj. i i s > t . However, this fails the instantiation property: n n Let be an ordering over function symbols. The lexicographic If s > t, then θ(s) > θ(t) for any substitution θ. path ordering lpo on terms induced by is defined as follows: Example Let θ = fy 7! f(x; x; x)g. • f(s1; : : : ; sm) lpo f(t1; : : : ; tm) if s1; : : : ; sm is f(x; x; x) > g(x; y) but θ(f(x; x; x)) 6> θ(g(x; y)). lexicographically greater than t1; : : : ; tm wrt lpo; What can we do to fix this? • f(s1; : : : ; sm) lpo t if si lpo t for some 1 ≤ i ≤ m; Let jtjx denote the number of occurrences of x in t. • f(s1; : : : ; sm) lpo g(t1; : : : ; tn) if f g and Define s > t if jsj > jtj and jsjx > jtjx for each variable x in t.