rewrite rules automated reasoning
play

Rewrite Rules Automated Reasoning Recall: Equation used from lhs to - PowerPoint PPT Presentation


  1. ☛ � ☞ ✄ ☛ ✂ ✌ ☞ ☛ ✌ ✁ ✌ � ☞ � ✌ ✁ ☛ ☛ � ☎ ☎ ✞ ☎ ✟ ☎ ✠ ✠ ☞ ✡ ☞ ☛ ✌ ☎ ☛ ☎ ✠ ✠ ✆ ✒ ✒ � ✒ � ✒ ✁ � ✒ ✒ � ✒ ✁ ✒ � ✒ � ✁ � ✁ ✍ � ✎ � ✍ � ✎ ✎ ✑ � ✏ � ✎ � ✑ � ✝ Rewrite Rules Automated Reasoning Recall: Equation used from lhs to rhs For example, for a e a a e a first rewrite, use: a b e a b b b a b Rewrite Rules b e b a b Rewrite terms on either side of = to be identical b a a b a b Each step is justified by a rewrite rule b a e Jacques Fleuriot like an equation but used only in one direction: b a makes use of matching Lecture XII computationally efficient: little search Importance of common in mathematics rewrite rules: can deal with inequalities as well ( ) e.g. can also deal with propositional equivalence Terminology: A term with no variables is said to be ground Algebraic Simplification Overview 1. X 0 0 Sample set of rewrite rules Multiplication Motivation for rewriting 2. 1 X X lhs rhs Definition of rewrite rule of inference 0 3. X 1 Always used in this direction We will look at examples in several familiar domains 0 4. X X e.g. Propositional logic and Peano Arithmetic Example: 2 0 5 0 a b Redexes: match with lhs of a rule and replace with corresponding 0 5 0 Rule 1 a b instance of rhs Of interest when dealing with sets of rewrite rules: 1 5 0 Rule 3 b 5 0 Rule 2 b Termination 5 0 Rule 1 Church-Rosser and canonical properties 5 Strategies for applying rewrite rules Terminology: A redex is a subexpression that can be rewritten There is a search tree There is some choice: in this example, it is AND Methods for proving Church-Rosser and canonical properties which subexpression to rewrite choice: so does not matter notions of critical pairs and confluence which rule to use not always AND choice

  2. ✘ ✪ ★ ✏ ✧ ✎ ★ ✧ ★ ✌ ✦ ✍ ✩ ✌ ✩ ✦ ✫ ☛ ✪ ☞ ✩ ☛ ✫ ✡ ✫ ✬ ✪ ✭ ✝ ✑ ✧ ✙ ✣ ✚ ✘ ✛ ✘ ✜ ✙ ✖ ✚ ✗ ✚ ✖ ✢ ✕ ✦ ✢ ✔ ✘ � ✕ ✤ ✔ ✥ ✤ ✦ ✓ ✧ ✒ ✮ ✠ ✯ ☎ ☎ ✾ ☎ ✿ ❀ ☎ ❀ ✆ ❀ ☎ ❁ ❀ ❀ ✟ ☎ ❀ ❂ ❃ ✄ ✂ ❄ ✁ ❄ � ❅ � ❂ ✽ ✼ ✻ ✞ ✮ ✟ ✰ ✞ ✱ ✝ ✲ ✠ ✱ ✟ ✲ ✟ ✳ ✴ ✷ ✵ ✝ ✶ ✠ ✷ ✟ ✸ ✟ ✹ ✞ ✺ ✝ ✚ Numeric Calculations To Rewrite From Lecture 3: Peano axioms can be viewed as rewrite rules Example axiom: s X Y s X Y find a subexpression t Set of rewrite rules (addition and multiplication): find a rule whose LHS matches t with substitution Cases for 0 and 0 X X replace subexpression t with RHS successor s X Y s X Y 0 0 X Refer to example again: s X Y X Y Y Calculations: Subexpression t s s 0 s 0 s 0 s 0 s 0 For ground expressions that only expression 0 s 0 s 0 s 0 contain the constant 0, rewriting s 0 s a s b evaluates the expression to a value s X Y s X Y s s 0 s 0 s a s b In general, we may not get a value for ground expressions using where X , s 0 s 0 s X Y a Y s a rewriting. e.g., s 0 s a s s a X , s 0 X , s 0 s 0 This is known as symbolic evaluation : still contains variables RHS a Y s X Y a Y s a Rewrite Rule of Inference Partial Rewrite Search Tree 2 0 exp[sub] 5 0 a b Note: special case of paramodulation: rewrite rule lhs rhs of inference uses matching not unification 2 0 5 0 a 0 exp[ rhs ] where lhs sub 5 0 a b 0 5 0 0 5 0 a a pattern target 2 0 5 1 5 0 a b subexpression Example: expression s 0 s a s b s X Y s X Y What evaluation strategy should be used? s 0 s a s b where X ,s 0 s 0 s X Y a Y s a innermost (inside-out)/leftmost redex e.g. apply to 0 s 0 s 0 s 0 0 0 X A rewrite rule must satisfy the following restrictions: outermost (outside-in)/leftmost redex is not a variable 1 X X e.g. e.g. apply to is not allowed – matches anything and so hard to control 0 s 0 s 0 s 0 X s Y s X Y vars vars Questions: is the tree finite i.e. will the rewriting terminate? 0 0 X e.g. is not allowed - if we start rewriting a ground term, we will are all the leaf nodes the same i.e. does order of rewrites matter always have a ground term

  3. ✆ ✝ ☛ ✡ ☞ ☛ ✡ ✟ ✠ ✟ ✞ ✞ ✆ ✡ ✆ ☎ ✆ ☎ ✂ ✄ ✂ ✂ ✁ ✂ ✡ ☛ ✁ ✑ ✘ ✗ ✔ ✔ ✔ ✔ ✓ ✒ ✑ ✏ ✏ ✡ ✑ � ✏ � ✎ � ✍ ✌ ☛ ✡ ☞ Termination Important Properties II Nice property that we want: application of rules cannot go on forever Definitions: Normal Form: No more rewrite rules can be applied algebraic rules 1. X 0 0 Canonical: all normal forms are identical 2. 1 X X non-negative: so cannot 0 s 1 3. X decrease forever 4. X 0 X No need to search since result To show termination, we need some sort of measure of expression that same in the end for all choices strictly decreases each time rule is applied of rewrites Example: depth of expression tree decreases for all instances t t t t t t t t Let DEPTH be the measure function then t leaves of tree: normal forms DEPTH X 0 DEPTH 0 DEPTH 1 X DEPTH X therefore, rules terminate DEPTH X 0 DEPTH 1 Therefore, t is the canonical form of s DEPTH X 0 DEPTH X two rules together: non termination Church Rosser implies canonical Typically, we look for a termination argument It is not always possible to ensure set of rewrite rules is canonical There are problem cases: X Y Z X Y X Z X Y Y X X Y X Z X Y Z Important Properties I Confluence Church-Rosser: A set of rewrite rules is Church-Rosser when equal exp Confluence expressions have a common rewriting * zero or more rewrite steps * Notation: means zero or more rewrite steps int2 int1 one step rewriting * * reflexive transitive closure of comm a b b c Expression exp rewrites in two different ways, and in zero or more steps, to intermediate a a a c expressions int1 and int2 which can both be rewritten to some common rewriting comm Local Confluence exp Formally: if t Choice of one step rewrites i 1 i 2 i n s Church-Rosser for exp. Questions: ✔✖✕ one rewrite step - when is there a choice? then - does that choice matter? int2 t u s int1 ✘✚✙ for some u immediate rewriting Diagram: t Proof needs notion of * s t * comm critical pairs * * * * * if then * * Theorem: if terminating and locally confluent then confluent s u

  4. ✜ ✜ ✤ ✡ ☛ ☞ ✣ ✢ ✌ ✍ ✎ ✣ ✢ ✞ ✆ ✏ ✛ ✗ ✚ ✑ ✒ ✓ ✖ ✑ ✒ ✕ ✙ ✘ ✔ ✖ ✕ ✕ ✤ ✥ ✥ ✂ ✩ ✪ ☎ ✫ ✫ ✄ ✫ ✩ ✬ ✁ � ✬ ✬ ✬ ☎ ★ ✦ ✦ ✧ ✦ ✠ ✟ � ✧ ★ ✞ ✝ ✆ ✦ ✦ ✖ Example: Critical Pairs * Critical Pairs How can choices arise in rewriting? x [ y ]: y is a subexpression of x exp"[ sub 1 [ sub 2 ]"] Two separate subexpressions are both a redex lhs 2 rhs 2 lhs 1 rhs 1 Need to rewrite one AND the other: Order does not matter One subexpression can be rewritten in two different ways ] exp"[ sub 1 [ rhs 2 ]"] exp"[ rhs 1 One redex is a subexpression of the other redex: Must rewrite one redex OR the other: Choice may matter where Examples: 0 0 0 1. X 1 1 , 0 lhs i Each is instantiation of : sub i rewrite rules: 2. 0 Y 0 1 2 lhs 1 sub 1 and lhs 2 sub 2 1 0 critical pairs lhs 1 sub 2 part ( bit ) of must match X e Z lhs 1 [ bit ] sub 1 [ sub 2 ] 1. W X Z ,X e Z so, making things explicit: e W 2. X Y Z X Y Z bit ' sub 2 and sub 2 lhs 2 2 1 lhs 2 X e Z bit and must be unifiable with mgu X Z bit lhs 2 i.e. subexpression of rule1 unifies with lhs of rule2 Question: Can we conflate all the possible rewritings? Critical Pairs (ii) Testing for Church-Rosser lhs 1 [ bit ] lhs 1 lhs 1 A set of rewrite rules is Church-Rosser (C-R) iff it is confluent lhs 2 rhs 2 lhs 1 rhs 1 A set of terminating rules is confluent iff it is locally confluent lhs 1 [ rhs 2 ] Local confluence is decidable : due to Knuth and Bendix rhs 1 Need notion of critical pair comm , lhs 1 [ rhs 2 ] Critical pair: rhs 1

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend