StructureShy Programming Ahmed Traversal StructureShy Programming Traversal Strategy

  • Slides: 18
Download presentation
Structure-Shy “Programming” Ahmed

Structure-Shy “Programming” Ahmed

Traversal Structure-Shy “Programming” Traversal Strategy Structure “from. . To. . ” Object o; Object.

Traversal Structure-Shy “Programming” Traversal Strategy Structure “from. . To. . ” Object o; Object. Graph. Slice Visitor • Well defined event generation semantics • DFS Traversal • Generates two types of events: • Before visiting node • after visiting node • A set of Event handlers. Visitor is tied to events rather than structure. Structure-shyness through Indirection!

“Programming” Vs. Traversal • “Programming” = Traversal + Search + Transformation + … •

“Programming” Vs. Traversal • “Programming” = Traversal + Search + Transformation + … • Traversal can be used to implement search. Therefore, structure-shy traversal => structureshy search. • Traversal can be used to implement transformation. Therefore, structure-shy traversal => structure-shy transformation. • Traversal can be used for “programming”. Therefore, structure-shy traversal => structureshy “Programming”.

But, • Is it convenient to implement search, transformation, … using traversals? • “Visitor

But, • Is it convenient to implement search, transformation, … using traversals? • “Visitor Formula. Reduce(Formula F, Lit lit) = Copy. Visitor(F) except { • • -----remove Lit thiz if lit != thiz replace literal thiz by truelit if lit == thiz Replace literal thiz by falselit if lit. samevar(thiz) replace Clause c by All. True if exists (from c to true. Lit) replace Clause c by All. False if not exists (from c to Lit) } These 4 lines are intended to replace the one page program in the GPCE – Karl Lieberherr, 2007 • After Pos: … submission. ”

But, • Is it convenient to implement search, transformation, … using traversals? • “Visitor

But, • Is it convenient to implement search, transformation, … using traversals? • “Visitor Formula. Reduce(Formula F, Lit lit) = Copy. Visitor(F) except { • • -----remove Lit thiz if lit != thiz replace literal thiz by truelit if lit == thiz Replace literal thiz by falselit if lit. samevar(thiz) replace Clause c by All. True if !empty(from c to true. Lit) replace Clause c by All. False if empty(from c to Lit) } empty(from Clause: c? to Lit) replace c by All. False After These 4 lines are intended to replace the one page program in the GPCE submission. ” replace –=Karl Lieberherr, 2007 Have multiple pattern variables and multiple replace After match is found; after all matches, before any match, after replacement Update formula type after reduction Length of clause

Structure-Shy Search Pattern Descriptor Structure ? ? Object o; ? ? Visitor • Well

Structure-Shy Search Pattern Descriptor Structure ? ? Object o; ? ? Visitor • Well defined event generation semantics • ? ? • Generates ? ? types of events: • ? ? • A set of Event handlers. Visitor is tied to events rather than structure. Structure-shyness through Indirection!

Structure-Shy Search • Event generation semantics: CSP. • Events: – Before any matches/After all

Structure-Shy Search • Event generation semantics: CSP. • Events: – Before any matches/After all matches – Before/After match – … • Pattern: Since we are using CSP as our “well defined” semantics, we’d expect the pattern to be a set of: Variables, Unary Constraints (Domains/types), n-ary Constraints, constraint propagators.

Structural Patterns: Example We’re setting ‘x’ to false. Any clause containing a negative ‘x’

Structural Patterns: Example We’re setting ‘x’ to false. Any clause containing a negative ‘x’ has to be deleted.

Search using Traversals • Traversal Strategy: “from Formula to Literal” • Search logic implemented

Search using Traversals • Traversal Strategy: “from Formula to Literal” • Search logic implemented inside Visitors. • Keep track of the most recent clause/Literal encountered. When a negative literal named ‘x’ is reached, turn on a flag. Delete ‘x’ when the following literal is encountered. • What if ‘x’ is the last node in the list?

Search using pattern matching ? P ? Q ? R • “A Clause or

Search using pattern matching ? P ? Q ? R • “A Clause or literal ‘P’ has-a Negative literal named ‘x’ which has-a optional literal”. • Now, generated event “Match found” has the whole pattern <? P, ? Q, ? R> as a parameter. • No need to implement the search logic inside the visitor!

Structural Patterns • A pattern specification consists of: – Variables – Unary constraints –

Structural Patterns • A pattern specification consists of: – Variables – Unary constraints – N-ary constraints – Propagators

Structural Patterns N-ary Constraints ? P ? Q Unary Constraints: ? P is either

Structural Patterns N-ary Constraints ? P ? Q Unary Constraints: ? P is either a Clause or literal, ? Q is a Negative literal named ‘x’. ? R is a maybe literal. Propagators: none ? R Variables

Propagators • Given a value for one of the variables, reduce the domain of

Propagators • Given a value for one of the variables, reduce the domain of values for other variables (inference). • Suppose that after deleting a node we need to do some housekeeping at the clause. Now, we have to use the following pattern.

Propagators Propagator • Propagator are specified at high level as “Traversal Strategies”! • Structural

Propagators Propagator • Propagator are specified at high level as “Traversal Strategies”! • Structural patterns are the general case of traversal strategies.

User-Defined Variable Types • A pattern defines a set of possible “instantiations” in the

User-Defined Variable Types • A pattern defines a set of possible “instantiations” in the host graph. • A pattern is considered as a user-defined type. • When a variable is assigned to a userdefined type, that means that the possible values that variable can assume are the possible instantiations of that pattern. • Modularity in specifying patterns.

Structure-Shy Transformation Structure Transformation Descriptor. Object o; ? ? Visitor • Well defined event

Structure-Shy Transformation Structure Transformation Descriptor. Object o; ? ? Visitor • Well defined event generation semantics • ? ? • Generates ? ? types of events: • ? ? • A set of Event handlers. Visitor is tied to events rather than structure. Structure-shyness through Indirection!

Structure-Shy Transformation • Event generation semantics: Graph Rewriting. • Events: – – – Before

Structure-Shy Transformation • Event generation semantics: Graph Rewriting. • Events: – – – Before anything/After everything Before/After delete Before/After replace Before/After rule fires Before/After structure fix … • Transformation Descriptor: A set of rewriting rules.

Structure-Shy Transformation • Essentially the same as what Karl proposed. • “Visitor Formula. Reduce(Formula

Structure-Shy Transformation • Essentially the same as what Karl proposed. • “Visitor Formula. Reduce(Formula F, Lit lit) = Copy. Visitor(F) except { remove Lit thiz if lit != thiz replace Clause c by All. True if there exists (from c to thiz: Lit) lit = thiz replace Clause c by All. False if for all (from c to thiz: Lit) lit != thiz }” • First, Do a normal copy then apply the following 3 rewriting rules to the copied formula. • remove Lit thiz if lit != thiz replace Clause c by All. True if there exists (from c to thiz: Lit) lit = thiz replace Clause c by All. False if for all (from c to thiz: Lit) lit != thiz }