On Data-Structure Rewriting Rachid Echahed LIG Lab, Grenoble - - PowerPoint PPT Presentation

on data structure rewriting
SMART_READER_LITE
LIVE PREVIEW

On Data-Structure Rewriting Rachid Echahed LIG Lab, Grenoble - - PowerPoint PPT Presentation

On Data-Structure Rewriting Rachid Echahed LIG Lab, Grenoble France June, 2010 Rewriting (reminder) A rewrite relation R is a binary relation R A A ( u , v ) R is read u rewrites into v and written u v Rewriting


slide-1
SLIDE 1

On Data-Structure Rewriting

Rachid Echahed LIG Lab, Grenoble France June, 2010

slide-2
SLIDE 2

Rewriting (reminder)

◮ A rewrite relation R is a binary relation

R ⊆ A × A

◮ (u, v) ∈ R is read “u rewrites into v” and written

u → v

slide-3
SLIDE 3

Rewriting (reminder)

R ⊆ A × A

◮ A = set of strings over a vocabulary (V ∗) ◮ A = set of states of the form (variables, valuation) ◮ A = set of Turing Machine configurations ◮ A = set of lambda-terms ◮ A = set of trees (or terms) ◮ A = set of clauses ◮ A = set of process terms ◮ A = . . .

slide-4
SLIDE 4

Rewriting

R ⊆ A × A

◮ How to define a rewrite relation R? ◮ How to define a run or the execution of a program?

◮ A rewrite derivation : u0 is the initial “call”

u0 → u1 → . . . → un

◮ A narrowing derivation :

w0 is the initial goal (to solve): w0 σ1 w1 . . . σn wn Where wi σ wi+1 iff σ(wi) → wi+1 wi is an element of A with partial information σ instantiates wi

slide-5
SLIDE 5

Motivation : Extension of Term Rewriting ; sharing subterms

Function definitions by means of term rewrite rules 0 + x → x succ(x) + y → succ(x + y) double(x) → x + x Very well established domain with several results : Confluence, Termination, Strategies, Proof methods (equational reasoning, induction) etc. double(x)

  • +
  • x

double

  • t
  • +
  • t
slide-6
SLIDE 6

Sharing Subterms (information) and Term Rewriting

Consider the following rules: f(a, b) → c a → b Sharing does not preserve properties of tree (term) rewriting ! f(a, a) → f(a, b) → c f

  • a
  • f
  • b

→ [Plump 99] survey on rewriting with “dags”.

slide-7
SLIDE 7

Motivation (continued)

◮ Data-structure rewriting

including cyclic data-structures with pointers such as circular lists, doubly-linked lists, etc.

◮ Data-structures are more complex than terms (Cycles,

Sharing)

◮ Difficult to encode efficiently using terms ◮ Usually described by pointers (⇒ pointer rewriting) ◮ Formally described as term-graphs

term-graphs = terms with cycles and sharing

slide-8
SLIDE 8

Term-graphs

[Barendregt et al. 87] [Plump 99, survey on acyclic term-graphs] Let Ω be a set of operation symbols. A term-graph t over Ω is defined by:

◮ a set of nodes Nt, ◮ a subset of labeled nodes NΩ t ⊆ Nt, ◮ a labeling function Lt : NΩ t → Ω, ◮ a successor function St : NΩ t → N∗ t ,

1 : f

1

  • 2
  • 3
  • 2 : b

3 : g

1

  • 2
  • 4 : •

5 : h

1

slide-9
SLIDE 9

Term-graphs

[Barendregt et al. 87] [Plump 99, survey on acyclic term-graphs] Let Ω be a set of operation symbols and F a set of feature symbols. A term-graph t over Ω and F is defined by:

◮ a set of nodes Nt, ◮ a set of edges Et ◮ a subset of labeled nodes NΩ t ⊆ Nt, ◮ a node labeling function Ln t : NΩ t → Ω, ◮ an edge labeling function Le t : Et → F ◮ a source function St : Et → Nt, ◮ a target function Tt : Et → Nt,

slide-10
SLIDE 10

(Term-)Graph Rewriting

◮ Which graphs? (Term-Graphs) ◮ Which rules? ◮ Which rewrite relation?

Two main approaches

◮ Algorithmic approaches ◮ Algebraic approaches (DPO,SPO, . . .)

slide-11
SLIDE 11

Graph Transformation

◮ Handbook of Graph Grammars and Computing by Graph

Transformation (World Scientific)

◮ Vol 1: Foundations, ed. G. Rozenberg, 1997 ◮ Vol 2: Applications, Languages and Tools

  • eds. H. Ehrig, G. Engels, H.-J. Kreowski and G.

Rozenberg, 1999

◮ Vol 3: Concurrency, Parallelism and Distribution

  • eds. H. Ehrig, H.-J. Kreowski, U. Montanari and G.

Rozenberg, 1999

◮ A Monograph in Theoretical Computer Science (An EATCS

series)

  • H. Ehrig, K. Ehrig, U. Prange, G. Taentzer: Fundamentals
  • f Algebraic Graph Transformation. Springer-Verlag, 2006
slide-12
SLIDE 12

Outline

Introduction Motivations Termgraph Rewrite Systems Confluence and Rewrite Strategies Narrowing A Modal Logic for Graph Transformation Conclusion

slide-13
SLIDE 13

Algorithmic approach

[Barendregt et al. 87] Shape of a rule: L → R where L and R are rooted term-graphs. A rule can be defined as one graph together with two roots (L + R, r1, r2) where r1 and r2 are the roots of L and R respectively Let ρ be the rule (L + R, r1, r2) We say that G rewrites to H using the rule ρ if

◮ L matches a subgraph of G (h : L → G |n) ◮ (build phase) Construct graph G1 = G + h(R) ◮ (redirection phase) G2 = [h(r1) ≫ h(r2)]G1 ◮ (garbage collection phase) H = G2 |root

A cumbersome definition, hard to deal with in practice!

slide-14
SLIDE 14

Rewrite Rules with actions

Shape of a rewrite rule : [L | C] → R

◮ L is a term-graph pattern ◮ C is a node constraint, n i=1(αi ≈ βi). ◮ R is a sequence of actions a1; a2; . . . ; an

slide-15
SLIDE 15

Actions

We consider three kinds of actions :

◮ Node definition α:f(α1, . . . , αn) ◮ Edge redirection α ≫i β ◮ Global redirection α ≫ β

slide-16
SLIDE 16

Application of actions

a[t] denotes the application of action(s) a on the term-graph t

◮ Let t = n:f(p, q :a)

n:f

1

  • 2
  • p

q :a

◮ Let t1 = p:h(p)[t] = n:f(p:h(p), q : a)

n:f

1

  • 2
  • p:h

1

  • q :a
slide-17
SLIDE 17

Application of actions

a[t] denotes the application of action(s) a on the term-graph t

◮ Let t1 = p:h(p)[t] = n:f(p:h(p), q : a)

n:f

1

  • 2
  • p:h

1

  • q :a

◮ Let t2 = n ≫2 p[t1] = n:f(p:h(p), p); q : a

n:f

1

  • 2
  • p:h

1

  • q :a
slide-18
SLIDE 18

Application of actions

a[t] denotes the application of action(s) a on the term-graph t

◮ Let t2 = n ≫2 p[t1] = n:f(p:h(p), p); q : a

n:f

1

  • 2
  • p:h

1

  • q :a

◮ Let t3 = p ≫ q[t2] = n:f(q, q); p:h(q)

n:f

1

  • 2
  • p:h

1

q :a

slide-19
SLIDE 19

Rewrite Step

Let t be a term-graph Let ρ be a rewrite rule [L | C] → R t rewrite to s at node α, t →α s iff:

◮ ∃m : L → t a homomorphism (ρ-matcher) ◮ m(rootL) = α ◮ α is reachable from roott ◮ m(C) holds ◮ s = m(R)[t]

slide-20
SLIDE 20

Term-Graph Rewrite Systems (tGRS) –Example–

Length of a circular list : r : length(p) → r : length′(p, p) r : length′(p1 : cons(n, p2), p2) → r : s(0) [r : length′(p1 : cons(n, p2), p3) | p2 ≈ p3] → r : s(q); q : length′(p2, p3) Remark: term rewrite systems are tGRS’s.

slide-21
SLIDE 21

Term-Graph Rewrite Systems –Example–

In-situ list reversal :

  • : reverse(p) → o : rev(p, nil)
  • : rev(p1 : cons(n, nil), p2) → p1 ≫2 p2; o ≫ p1
  • : rev(p1 : cons(n, p2 : cons(m, p3), p4) → p1 ≫2 p4; o ≫1

p2; o ≫2 p1 Visual Programming would help!

slide-22
SLIDE 22

DPO approach of rewrite rules with actions

A categorical approach can be found in [TERMGRAPH 06, ENTCS07, RTA07] L

m

  • K

l

  • d
  • r

R

m′

  • G

D

l′

  • r ′

H Figure: Double pushout: a rewrite step (G → H)

Redirections of edges (pointers) are handled by K = disconnection(L, E, N) and the morphisms l and r. Remark: Morphisms l and r are not injective! D is not unique!

slide-23
SLIDE 23

Confluence

f(x) → x g(x) → x The following term-graph n:f

  • q :g
  • rewrites to

n:f

  • q :g
slide-24
SLIDE 24

Confluence

α : f(β : c) → β : a; α ≫ β α : g(β : c) → β : b; α ≫ β p:f

  • q :g
  • q :c

The label of node q may end as q : a or q : b

slide-25
SLIDE 25

Computing with non-confluent

  • rthogonal Term-graph Rewrite Systems

How to evaluate the following term-graph ?

◮ addlast(length(n : [1, 2]), n) ◮ Two normal forms

◮ [1, 2, 2] (evaluate addlast after length) ◮ [1, 2, 3] (evaluate length after addlast)

slide-26
SLIDE 26

Term-graphs with Priority

[PPDP06][RTA07][RTA08]

◮ Endow Term-graphs with priorities (G, <G) to express

which node should be evaluated first

◮ m1 :addlast(m2 :length(n:[1, 2]), n); m1 < m2

◮ Priorities should not be a total order (stay declarative) ◮ Which nodes should be ordered? ◮ Solution: Order only nodes producing a “side-effect”

slide-27
SLIDE 27

Strategies and needed nodes

A strategy φ is a partial function which takes a rooted term-graph t and returns a node (position) n and a rule R, φ(t) = (n, R) such that the term-graph t can be reduced at node n using the rule R, t →n t′

slide-28
SLIDE 28

Needed Nodes

Let φ be a rewrite strategy. Let φ(t) = (p, R). The node p is needed iff for all derivations t →β1 t1 →β2 . . . tn−1 →βn tn such that tn is a value, there exists i ∈ [1..n] s.t. βi = p

slide-29
SLIDE 29

Inductively sequential Term Rewrite Systems

◮ Constitute a subclass of TRSs for which efficient rewrite

strategies are available [Antoy 92]

◮ Are as expressive as Strongly Sequential TRSs ◮ Are the basis of modern functional and logic programming

languages.

◮ Are defined by means of data-structures called Definitional

trees

slide-30
SLIDE 30

Definitional Trees -case of terms-

Let R be the following TRS f(k,nil) → R1 f(0,cons(x,l)) → R2 f(succ(n),cons(x,l)) → R3 A definitional tree of operator f is a hierarchical structure whose leaves are the rules defining f. f(k, l) f(k, nil) → R1 f(k, cons (x, u)) f(0, cons (x,u)) → R2 f(succ(y), cons (x,u)) → R3

slide-31
SLIDE 31

Definitional trees

  • case of term-graphs-

r : length′(p1 : nil, p2 : •) → rhs1 r : length′(p1 : cons(n : •, p2 : •), p2) → rhs2 [r : length′(p1 : cons(n : •, p2 : •), p3 : •) | p2 . = p3] → rhs3 A definitional tree T of the operation length′ is given bellow: r : length′(p1 : •, p2 : •) r : length′(p1 : nil, p2 : •) → rhs1 r : length′(p1 : cons(n : •, p3 : •), p2 : •) r : length′(p1 : cons(n : •, p2 : •), p2) → rhs2 [r : length′(p1 : cons(n : •, p2 : •), p3 : •) | p2 . = p3] → rhs3

slide-32
SLIDE 32

A Rewrite strategy φ

Consider the following definitional tree T of the operation g : r : g(p1 : •, p2 : •) r : g(p1 : nil, p2 : •) → rhs1 r : g(p1 : cons(n : •, p3 : •), p2 : •) r : g(p1 : cons(n : •, p2 : •), p2) → rhs2 [r : g(p1 : cons(n : •, p2 : •), p3 : •) | p2 . = p3] → rhs3 φ(1 : g (2 : g(3 : g(nil, p), q), 4 : g(nil, o))) = φ(2 : g(3 : g(nil, p), q)) = φ(3 : g(nil, p)) = (3, Rule1)

slide-33
SLIDE 33

Naive extension of TRS’s

Contrary to term rewriting, Definitional trees are not enough to ensure the neededness of positions computed by the strategy φ, in the context of term-graph rewriting. Proposition: Let SP = Ω, R be tGRS such that Ω is constructor-based and the rules of every defined operation are stored in a definitional tree. Let t be a rooted term-graph. Then,

  • 1. if φ(t) = (p, R), the node p is not needed in general.
  • 2. if φ(t) is not defined, g can still have a constructor normal

form.

slide-34
SLIDE 34

Counter-examples

r : f(p : 0) → r ≫ p r : h(p : 0, q : succ(n : •)) → q ≫ p r : f(p : succ(p′ : •)) → r ≫ p Let t = n : succ

  • r : succ
  • p : f
  • q : succ
  • s : h
  • u : 0

φ(t) = (p, r : f(p : succ(p′ : •)) → r ≫ p). However, the node p is not needed in t.

slide-35
SLIDE 35

Counter-examples

r : g(p : 0) → r ≫ p r : h(p : 0, q : succ(n : •)) → q ≫ p Let t = n : succ

  • r : succ
  • p : g
  • q : succ
  • s : h
  • u : 0

φ(t) is not defined!. However, the term-graph t rewrites to n : succ(u : 0).

slide-36
SLIDE 36

Inductively Sequential Term-Graph Rewrite Systems

Let SP = Ω, R be a tGRS. SP is called inductively sequential iff

◮ The rules of every defined operation can be stored in a

definitional tree and

◮ for all rules [L | C] → r in R, for all global (respectively,

local) redirections of the form p ≫ q (respectively, p ≫i q for some i), occurring in the right-hand side r, p = RootL.

slide-37
SLIDE 37

Main Properties of Strategy Φ

In presence of Inductively Sequential Term-Graph Rewrite Systems

◮ The positions computed by Φ are needed ◮ Φ is c-normalizing ◮ Φ is c-hyper-normalizing ◮ Derivations computed by Φ have minimal length

slide-38
SLIDE 38

Confluence

Inductively sequential tGRS are not confluent! f(p : •, p) → 0 [f(p : •, q : •) | p = q] → 1 r : g(q : •) → r ≫ q Let t = n : f

  • p : g

q : 0

There are two different derivations starting from t : t →n 1 t →p f(q : 0, q) →n 0

slide-39
SLIDE 39

Admissible term-graphs

[JICSLP98] Ω is contructor-based, i.e. Ω = D ∪ C and D ∩ C = ∅ D is a set of defined operations C is a set of constructors A term-graph is admissible if none of its cycles includes a defined operation. n:succ(n) is an admissible term-graph n:+(n, n) and n : tail(n) are not admissible

slide-40
SLIDE 40

Admissible term-graphs

The set of admissible term-graphs is not closed under rewriting n:f(m) → q :g(n); n ≫ m Let Ω = D ∪ C with C = {0, succ} and D = {f, g} n1 :f(m1 :0) → q1 :g(q1)

slide-41
SLIDE 41

Admissible Inductively sequential Term-Graph Rewrite Systems

Let SP = Ω, R be an inductively sequential tGRS. SP is called admissible iff for all rules [π | C] → r in R the following conditions are satisfied

◮ for all global (respectively, local) redirections of the form

p ≫ q (respectively, p ≫i q for some i), occurring in the right-hand side r, we have p = Rootπ and q = Rootπ.

◮ for all actions of the form α : f(β1, . . . , βn), for all i ∈ 1..n,

βi = Rootπ

◮ the set of actions of the form α : f(β1, . . . , βn), appearing in

r, do not construct a cycle including a defined operation.

◮ Constraint C includes disequations of the form p .

= q where p and q are labeled by constructor symbols.

slide-42
SLIDE 42

Admissible Inductively sequential Term-Graph Rewrite Systems

[ICGT08][JICSLP98] In presence of Admissible Inductively sequential Term-Graph Rewrite Systems

◮ The set of admissible term-graphs is closed under the

rewrite relation defined by admissible rules.

◮ Φ computes needed positions ◮ Admissible term-graphs admit unique normal forms

slide-43
SLIDE 43

Narrowing

wi σ wi+1 iff σ(wi) → wi+1

◮ Rewriting = Matching + Transformation ◮ Narrowing = Unification + Transformation

slide-44
SLIDE 44

Narrowing –Motivation–

◮ Automated deduction [Slagle 74] [Fay 79][Hullot 80] ◮ Functional and Logic Programming [Goguen and

Meseguer 84, ...]

◮ Security verification [Meadows 89, ...] ◮ Reachability Analysis [Meseguer and Thati 05, ...] ◮ ...

slide-45
SLIDE 45

Narrowing

Instantiate goal variables and apply a reduction step 0 + X → X s(X) + Y → s(X + Y) U + s(0) = s(s(0)) {U→s(V)} s(V + s(0)) = s(s(0)) {V→0} s(s(0)) = s(s(0)) Computed answer: {U → s(0)}

slide-46
SLIDE 46

Some Results

Needed Term narrowing [POPL04][JACM2000] (main operational semantics of current functionalogic programming languages) Needed Graph Narrowing [JICSLP98] Needed Collapsing Narrowing [Gratra 2000] Narrowing-based algorithm for data-structure rewriting [ICGT06]

◮ Goal

  • : equal(p : length(q), s(s(0))) = true

◮ Solution : a circular list of length two

[q : cons(n1, r : cons(n2, q)) | q ≈ r]

slide-47
SLIDE 47

Narrowing: What do we transform?

Rule

  • : f(p : a, q, r) −

→ p : b; o ≫3 q Rewrite Steps

  • 1, p1, q1 and r1 are constants (names or addresses)
  • 1 : f(p1 : a, q1 : a, r1) −

→ o1 : f(p1 : b, q1 : a, q1)

  • 1 : f(p1 : a, p1, r1) −

→ o1 : f(p1 : b, p1, p1)

slide-48
SLIDE 48

Narrowing: What do we transform?

Rule

  • : f(p : a, q, r) −

→ p : b; o ≫3 q Rewrite Steps (o1, p1, q1 and r1 are constants)

  • 1 : f(p1 : a, q1 : a, r1) −

→ o1 : f(p1 : b, q1 : a, q1)

  • 1 : f(p1 : a, p1, r1) −

→ o1 : f(p1 : b, p1, p1) Narrowing steps (o2, p2, q2 and r2 are variables)

  • 2 : f(p2, q2 : a, r2) ?

σ labels node p2 with symbol a.

  • 2 : f(p2, q2 : a, r2) σ o2 : f(p2 : b, q2 : a, q2) | p2 ≈ q2
  • 2 : f(p2, q2 : a, r2) σ∪{q2→p2} o2 : f(p2 : b, p2, p2)
slide-49
SLIDE 49

Narrowing: What do we transform?

Rule

  • : f(p : a, q, r) −

→ p : b; o ≫3 q Narrowing steps (o2, p2, q2 and r2 are variables)

  • 2 : f(p2, q2 : a, r2)

σ [apply(o2 : f(p2 : a, q2 : a, r2), p2 : b; o2 ≫3 q2)] [apply(o2 : f(p2 : a, q2 : a, r2), p2 : b; o2 ≫3 q2) | p2 ≈ q2] [apply(o2 : f(p2 : b, q2 : a, r2), o2 ≫3 q2) | p2 ≈ q2] [apply(o2 : f(p2 : a, q2 : a, q2), ǫ) | p2 ≈ q2] [o2 : f(p2 : a, q2 : a, q2) | p2 ≈ q2]

slide-50
SLIDE 50

Narrowing: What do we transform?

Rule

  • : f(p : a, q, r) −

→ p : b; o ≫3 q Narrowing steps

  • 2, p2, q2 and r2 are variables
  • 2 : f(p2, q2 : a, r2)

σ [apply(o2 : f(p2 : a, q2 : a, r2), p2 : b; o2 ≫3 q2)] {q2→p2} [apply(o2 : f(p2 : a, p2, r2), p2 : b; o2 ≫3 q2)] [apply(o2 : f(p2 : b, p2, r2), o2 ≫3 q2)] [apply(o2 : f(p2 : b, p2, p2), ǫ)]

  • 2 : f(p2 : b, p2, p2)
slide-51
SLIDE 51

g-terms

Symbolic handling of actions G is a term-graph φ is a conjunction of disequations τ is a sequence of actions [G | φ] [apply(G, τ) | φ] Example: [o2 : f(p2 : a, q2 : a, q2) | p2 ≈ q2] [apply(o2 : f(p2 : b, q2 : a, r2), o2 ≫3 q2) | p2 ≈ q2]

slide-52
SLIDE 52

Graph Narrowing Rules

Superposition rule (SUP) [G | ψ]τ SUP,ρ,θ [H | ψ′]σ(τ) If:

◮ G is a term-graph ◮ ρ is rewrite rule [L | φ] → R ◮ σ is a most general unifier of L and G such that:

◮ σ(L) and σ(G) are compatible ◮ The root of L unifies with a labeled node in G

(non-variable unification)

◮ H = apply(σ(G) ∪ σ(L), σ(R)) ◮ θ = (σ, K) with K = σ(L)\σ(G) ◮ ψ′ = σ(ψ) ∧ σ(φ) ∧ p∈affected by(σ(τ)),q∈K Ω p .

= q.

slide-53
SLIDE 53

Graph Narrowing Rules

Action rule: simplify (SIM) [apply(G, ǫ) | ψ]τ SIM [G | ψ]τ

slide-54
SLIDE 54

Graph Narrowing Rules

Action rule: execute (EXE) [apply(G, α.u) | ψ]τ EXE [apply(α[G], u) | ψ′]τ.α If:

◮ action α is not a node creation and ◮ [G | ψ] is ready for action α.

slide-55
SLIDE 55

Graph Narrowing Rules

Action rule: new node (NEW) [apply(G, n+.u) | ψ]τ NEW,σ [apply(n+[G], σ(u)) | ψ′]τ.n+ If:

◮ σ = {n → n′} where n′ is a fresh effective node ◮ ψ′ = ψ ∧ p∈V∩NG(p ≈ n′)

slide-56
SLIDE 56

Graph Narrowing Rules

Isolation rule with equality (EQU) [apply(G, α.u) | ψ]τ EQU,σ [apply(σ(G), σ(α).σ(u)) | σ(ψ)]σ(τ) If:

◮ there exists a node n ∈ affected by(α), ◮ m is not an α-isolated node in G and ◮ σ is a substitution (compatible with G) such that

σ(n) = σ(m)

  • 2 : f(p2, q2 : a, r2)

σ [apply(o2 : f(p2 : a, q2 : a, r2), p2 : b; o2 ≫3 q2)] {q2→p2} [apply(o2 : f(p2 : a, p2, r2), p2 : b; o2 ≫3 q2)]

slide-57
SLIDE 57

Graph Narrowing Rules

Isolation rule with disequality (DIS) [apply(G, α.u) | ψ]τ DIS [apply(G, α.u) | ψ ∧ n . = m]τ If:

◮ there exists a node n ∈ affected by(α), ◮ m is not an α-isolated node in G

  • 2 : f(p2, q2 : a, r2)

σ [apply(o2 : f(p2 : a, q2 : a, r2), p2 : b; o2 ≫3 q2)] [apply(o2 : f(p2 : a, q2 : a, r2), p2 : b; o2 ≫3 q2) | p2 ≈ q2]

slide-58
SLIDE 58

Computed Solutions

[G0 | True] σ1 · · · σn [Gn | φ] Computed Solution is : (σ1 · · · σn, φ) Example:

◮ Goal

  • : equal(p : length(q), s(s(0))) = true

◮ Solution

[q : cons(n1, r : cons(n2, q)) | q ≈ r]

slide-59
SLIDE 59

Graph Narrowing: Soundness and Completeness

Proposition 1: The proposed narrowing rules are sound. If [G | True] σ [H | φ] then there exists a ground substitution θ satisfying φ such that: Gσθ − →∗ Hθ Proposition 2: The proposed narrowing rules are complete. If Gσ − →∗ H, σ being irreducible. Then, there exist two substitutions θ and γ and a term-graph G′ such that :

◮ [G | True]∗θ[G′ | φ] ◮ γ satifies φ ◮ σ = θγ ◮ G′γ = H

slide-60
SLIDE 60

Modal Logic and Graph Transformation – motivations–

◮ Specify graph shapes (data-structures)

◮ Circular list ◮ Balanced tree

Graph properties can be specified within several logics, such as :

◮ Separation Logic, ◮ Monadic second order logic, ◮ Modal logics (e.g., LTL, CTL, µ-calculus, etc).

◮ Verification of graph transformation:

◮ Invariant ◮ Reachability ◮ Need to define new logics able to specify rule application

and graph transformation.

slide-61
SLIDE 61

Dynamic Logic

◮ Agents ◮ Knowledge ◮ Actions

Evaluate a formula in a model ⇒ Transform the considered model

slide-62
SLIDE 62

A Modal Logic for Graph Rewriting

◮ G |

= φ

◮ G!R |

= φ where G!R is the normal form of G

◮ G!R |

= φ iff G | = [R∗]φ

slide-63
SLIDE 63

A Modal Logic for Graph Rewriting : Lgr

Language

◮ Formulas :

φ ::= p |⊥| ¬φ | φ ∨ φ | [α]φ

◮ Actions :

α ::= a | α∗ | α; α | α ∨ α | modifiers. [α]Φ :“After performing” actions α, formula Φ holds.

slide-64
SLIDE 64

Modifiers

◮ Add a new node ◮ Add a new label (to current node) ◮ remove a label from the current node ◮ Add the label “a” to the edges going from a Φ-node to a

Ψ-node.

◮ . . . ◮ Graph modifiers :

◮ U ◮ n ◮

n

◮ φ? ◮ (ω :=g φ) ◮ (ω :=l φ) ◮ (a + (φ, ψ)) ◮ (a − (φ, ψ))

slide-65
SLIDE 65

Modifiers –Example–

[p :=g⊥][p :=l ⊤](p ∧ [a](¬p ∧ q)) p

a

  • a p, q

q ⇒

  • a
  • a q

q ⇒ p

a

  • a q

q

slide-66
SLIDE 66

Modal Logic: Lgr

Semantics (informally)

◮ Gr |

= p iff p holds at node r

◮ Gr |

= [a]ϕ iff Gn | = ϕ for all nodes n such that the edge r

a

→ n ∈ G.

◮ Gr |

= [ω :=g ⊥][ω :=l ⊤] ϕ iff Hr | = ϕ, H is obtained from G by tagging the node r by ω (ω does not hold outside node r).

slide-67
SLIDE 67

Modal Logic: Lgr

Semantics

◮ Gr |

= [a − (φ, ψ)]ϕ iff Hr | = ϕ, H is obtained from G by erasing the edges n

a

→ m, such that Gn | = φ and Gm | = ψ.

◮ Gr |

= [a + (φ, ψ)]ϕ iff Hr | = ϕ, H is obtained from G by adding the edges n

a

→ m, such that Gn | = φ and Gm | = ψ.

◮ Gr |

= [f?]ϕ iff Gr | = ϕ and f holds at node r.

◮ Gr |

= [ nw]ϕ iff Hnw | = ϕ. H is obtained from G by adding a new node nw.

slide-68
SLIDE 68

Examples of Lgr Specified Properties

◮ Class of all a-cycle-free rooted termgraphs.

[ω :=g ⊤][U][ω :=l ⊥][a+]ω

◮ Class of all a-circular rooted termgraphs

[ω :=g ⊥][U][ω :=l ⊤]a+ω.

◮ Class of all (a, b)-binary rooted termgraphs

[ω :=g ⊥][U][ω :=l ⊤][a][π :=g ⊤][(a ∪ b)⋆][π :=l ⊥][U](ω → [b][(a ∪ b)⋆]π).

◮ Let RG(a) = {(n1, n2): the edge n1 a

→ n2 ∈ G}. G | = [ω :=g ⊥][U][ω :=l ⊤][a]¬ω iff RG(a) is irreflexive.

◮ Classes of circular lists, balanced trees, . . .

slide-69
SLIDE 69

Hamiltonian Graphs

The following formula expresses the existence of a Hamiltonian cycle. α stands for a1 ∪ . . . ∪ an, where the ai’s are the possible features used in the graph (F = {a1, . . . , an}): ω :=g ⊤; π :=g ⊥; ω :=l ⊥; π :=l ⊤; (α; ω?; ω :=l ⊥)⋆ (π ∧ [U]¬ω).

slide-70
SLIDE 70

Decidability

◮ With * and without “nw” : the problem of “model checking”

(G | = Φ) is decidable.

slide-71
SLIDE 71

Modal Logic Lgr and Graph Rewriting

Expressing pattern-matching in Lgr Proposition: Let Gr be a term-graph with root r (a distinguished node). There exists a ⋆-free action αG and a

⋆-free formula φG such that for all finite rooted termgraphs G′r ′,

G′r ′ | = αGφG iff there exists a graph homomorphism from G to G′r ′. We define the action αG and the formula φG as follows:

◮ βG = (π0 :=g ⊥); . . . ; (πN−1 :=g ⊥),

(N being the number of nodes in G)

◮ for all non-negative integers i, if i < N then γi G =

(¬π0 ∧ . . . ∧ ¬πi−1)?; (πi :=l ⊤); U,

◮ αG = βG; γ0 G; . . . ; γN−1 G

,

slide-72
SLIDE 72

Modal Logic Lgr and Graph Rewriting

We define the formula φG as follows:

◮ for all non-negative integers i, if i < N then ψi G = if Ln(i) is

defined then U(πi ∧ Ln(i)) else ⊤,

◮ for all non-negative integers i, j, if i, j < N then χi,j G = if

there exists an edge e ∈ E such that S(e) = i and T (e) = j then U(πi ∧ Le(e)πj) else ⊤,

◮ φG = ψ0 G ∧ . . . ∧ ψN−1 G

∧ χ0,0

G ∧ . . . ∧ χN−1,N−1 G

.

slide-73
SLIDE 73

Modal Logic Lgr and Graph Rewriting

Actions representing the right-hand sides can be expressed by the following elementary formulas :

◮ Action n : f(a1 ⇒ n1, . . . , ak ⇒ nk)

U; πn?; (f :=l ⊤); (a1 + (πn, πn1)); . . . ; (ak + (πn, πnk)).

◮ Action n ≫a m

(a − (πn, ⊤)); (a + (πn, πm)).

◮ Action n ≫ m) (for a-edges)

(λa :=g ⊥); (λa :=g aπn); (a − (⊤, πn)); (a + (λa, πm)).

slide-74
SLIDE 74

Modal Logic Lgr and Graph Rewriting

◮ Firing a rule ρ = L → R

βρ = αL; αR

◮ Normal form of graph Gr satisfies ϕ: Let R = ( βρi)

Gr | = [R∗]([R]⊥ ⇒ ϕ)

◮ Rule ρ preserves the property ϕ:

| = (ϕ ⇒ [βρ]ϕ)

slide-75
SLIDE 75

Conclussion and perspectives

◮ Admissible termgraphs seem to be a good trade-off to

ensure confluence and efficient strategies

◮ Cloning and algebraic approaches (sesqui-pushout) ◮ Narrowing ◮ Visual Programming and Termgraph Rewriting ◮ Proof Techniques ◮ Applications