More on Graph Rewriting With Contextual Refinement Berthold Hoffmann, Universität Bremen Workshop on Graph Computational Models 2014 York, 21. July 2014 1/18
Motivation GRGEN has been the starting point ◮ a very efficient graph rewriting tool ◮ with expressive rules: ◮ Attributes ◮ Subtyping (labels, attributes) ◮ Nested application conditions (with recursive refinement) ◮ Recursive rule refinement ◮ Other graph rewriting tools support analysis and verfification ◮ This provides an enormous “additional value” ◮ We want to support analysis of GRGEN rules ◮ We concentrate on rule refinement ◮ We translate refinement into simple rules (which are used with a strategy) 2/18
Outline of this Talk Rewriting... ...of Graphs ...of Rules Rule Schemata Meta-Rules (Based on Contextual Hyperedge Replacement) Translation to Simple Rules Correctness Termination Conclusions Related and Future Work 3/18
Refactoring Program Graphs ◮ If all subclasses of a class override the same method, ◮ Pull up one method, remove the others C C C C C C S C C S B B S B B B S E ⇒ E V E E E E V E V V E E E V V V 4/18
Refactoring Program Graphs ◮ If all subclasses of a class override the same method, ◮ Pull up one method, remove the others ◮ A simple rule has a fixed pattern S C C C C C C C B B C C S C C S B B S E E E E B S B B B S E V E ⇒ E E E E V E E E E V E V V V E E E V V V 4/18
Refactoring Program Graphs ◮ If all subclasses of a class C override the same method, 1 ... C B k ◮ Pull up one method, remove the C C ... S others B ... B B ... ◮ A simple rule has a fixed pattern Bdy 0 Bdy 0 Bdy 1 ◮ A schema generates ⇓ ∗ a language of patterns S C C C C C C C B B C C S C C S B B S E E E E B S B B B S E V E ⇒ E E E E V E E E E V E V V V E E E V V V 4/18
Graph Rewriting – the dual way Body Replacement Pattern Clip Glue Target Source Union ◮ All morphisms are monos 5/18
Rule Rewriting ◮ Rule morphisms r → r ′ are triples of commuting graph morphisms r : P B R r ′ : P ′ B ′ R ′ ◮ Rule rewriting is defined by pushouts of rules and rule morphisms p b r δ : s u t 6/18
Pull Up Method – Schema and Meta-Rules Bdy 0 Exp 0 Exp 0 Exp 0 C 1 ... C B k B E E E C C ... S 1 n 1 n ... E ... E B ... B E V E V E S B ... · · · · · · Exp 0 Exp 0 Exp 0 Exp 0 Exp 0 Exp i Bdy 0 Bdy 0 Bdy 1 ◮ Method bodies are geneated by contextual rules 7/18
Pull Up Method – Schema and Meta-Rules Bdy 0 Exp 0 Exp 0 Exp 0 C 1 ... C B k B E E E C C ... S 1 n 1 n ... E ... E B ... B E V E V E S B ... · · · · · · Exp 0 Exp 0 Exp 0 Exp 0 Exp 0 Exp i Bdy 0 Bdy 0 Bdy 1 ◮ Method bodies are geneated by contextual rules ◮ Meta-rules delete / copy a method body (up to its context) 7/18
Pull Up Method – Schema and Meta-Rules Bdy 0 Exp 0 Exp 0 Exp 0 C 1 ... C B k B E E E C C ... S 1 n 1 n ... E ... E B ... B E V E V E S B ... · · · · · · Exp 0 Exp 0 Exp 0 Exp 0 Exp 0 Exp i Bdy 0 Bdy 0 Bdy 1 ◮ Method bodies are geneated by contextual rules ◮ Meta-rules delete / copy a method body (up to its context) ◮ Context nodes may be in the schema, or in the source graph 7/18
Pull Up Method – Schema and Meta-Rules Bdy 0 Exp 0 Exp 0 Exp 0 C 1 ... C B k B E E E C C ... S 1 n 1 n ... E ... E B ... B E V E V E S B ... · · · · · · Exp 0 Exp 0 Exp 0 Exp 0 Exp 0 Exp i Bdy 0 Bdy 0 Bdy 1 Bdy 1 Exp 1 Exp 1 Exp 1 B B E E E E E E 1 1 1 n 1 n 1 n 1 n ... E ... E ... E ... E E E V E V E E S E Exp 1 · · · Exp 1 · · · Exp 1 Exp 1 Exp 1 Exp 1 · · · ◮ Method bodies are geneated by contextual rules ◮ Meta-rules delete / copy a method body (up to its context) ◮ Context nodes may be in the schema, or in the source graph 7/18
A Refinement of Pull up Method C C C C C S B C C C S B B B E B B E Exp 1 E E E V E E E Exp 0 Exp 1 E E E V E Exp 0 Exp 1 Exp 1 ◮ Context node V does not occur in the source schema ◮ With the context-free meta-rule, we “delay” matching to the source graph 8/18
Schema Refinement ◮ A schema is a rule s : ( P → B ← R ) where meta-variables appear only in the body B ◮ A meta rule is a rule rewrite rule δ : ( p → b ← r ) where the body rule δ B : ( B p → B b ← R b ) is contextual ◮ A finite set ∆ of meta-rules generates rules (instances) ∆( s ) = { r | s ∗ ⇒ ∆ r , r is meta-variable-free } ∆ shall also contain “less contextual variations” ◮ Rewriting with refinement : S ◦ s , ∆ T if S ⇒ r T for some ⇒ r ∈ ∆( s ) Assumption ◮ ∆ generates a non-empty set of rules 9/18
Incremental Rules for Pull-Up Method Exp 1 Exp 1 C 1 ... C B k E E E E C C ... S E V E E V E B ... B B ... Exp 1 Exp 1 Bdy 0 Bdy 0 Bdy 1 Exp 1 Exp 1 C 1 ... C B k E E E E E E C C ... S B ... B E V E V B Exp 1 Exp Exp 1 Exp Bdy 0 Bdy 0 Bdy 1 10/18
Translation to Simple Rules Incremental Rules ◮ Schemata: Turn meta-variables into variables of the replacement (with their attachments) ◮ Meta-rules: Turn meta-variables into variables of the pattern and replacement Residual Rewriting ( ◦ ⇒ ) ◮ Matches of incremental meta-rules must overlap only in variables and their attachments ◮ Incremental meta-rules have priority over incremental schemata: ! s S ′ S ◦ ⇒ ◦ ⇒ T ˜ ˜ ∆ 11/18
Correctness ◮ Refinement s corresponds to ˜ s compositions of δ 1 m incremental rules m ˜ t = ˜ ˜ s ◦ m , ¯ δ 1 t ◮ If r is meta-variable-free, ∆ ∗ ˜ r = r by construction s ◦ ˜ δ 1 · · · ◦ ˜ r = ˜ r ˜ δ n ◮ Rewriting with a composed incremental ˜ r rule corresponds to S T residual rewrite ◦ sequences with ∗ incremental rules ◦ S ′ s ˜ ˜ ∆ 12/18
C C C C C S B C C C S B B B E B B E Exp 1 E E E V E E E Exp 0 Exp 1 E E E V E Exp 0 Exp 1 Exp 1 Exp 1 C C ← − E E C C C S B C C C S B d ↓ B B E Exp 1 B B E E E E V E E E E ◦ d = Exp 0 Exp 1 E E E V Exp 0 Exp 1 Exp 1 Exp 13/18
Termination of Residual Rewriting ◮ A meta-rule ( p ֒ ֓ r ) refines its pattern → b ← ◮ if it adds terminal nodes or edges to B p , or ◮ if B b does not contain meta-variables Theorem For a schema s and a set ∆ of pattern-refining meta-rules, residual rewriting of incremental rules terminates ◮ The replicative meta-rules for Pull Up Method refine their patterns 14/18
Summary ◮ Rules with contextual refinement ◮ match, ◮ delete, ◮ replicate, and ◮ transform subgraphs of arbitrary size and varying shape ◮ They are entirely rule-based ◮ They translate to simple graph rewrite rules used with ◮ residual matches and ◮ priority to meta-rules 15/18
Related Work Rules with variables ◮ Substitutive transformation (Plump-Habel:96) ◮ HR-shaped (hierarchical) graph transformation (Hoffmann:01) ◮ ASR-shaped graph transformation (Drewes et al:07) ◮ NCE rewriting (Janssen:83) can be modeled by refinement Analysis of graph rewrite systems ◮ Verification: Augur, Raven (Duisburg) ◮ State space exploration: Groove (Twente) ◮ Termination: ?? (Duisburg) ◮ Local confluence (critical pair analysis) ◮ AGG (TU Berlin) ◮ GP2 (York, work in progress) 16/18
Future Work Next steps ◮ Combination with nested application conditions and attributes (This should be straight-forward) ◮ What about recursively refined conditions? (Habel-Radke) Our Overall Aim ◮ Critical pair analysis ◮ Impossible in general! ◮ Possible for graph rewriting preserving unambiguous shapes? 17/18
Thank You! 18/18
Recommend
More recommend