Bigraphs and (Reactive) XML an XML-centric model of computation

Thomas Hildebrandt Dept. of Theoretical Computer Science, ITU

February 8, 2005 (ITU Technical report: TR-2005-56)

COPLAS Seminar -February 8, 2005- DIKU Background and context of the presented work:

Bigraphical Reactive Systems: and Ole H. Jensen • Theoretical meta-model for reactive systems with semi structured state See tech reports: UCAM-CL-TR-580 and UCAM-CL-TR-581, 2004

Reactive XML: MSc. thesis by Jacob W. Winther, nov, 2004. • 1. Develop an XML meta-model for process calculi and their reaction semantics, inspired by the theory of bigraphical reactive systems. 2. Implement a prototype tool allowing to rewrite XML processes.

The Bigraphical Programming Languages (BPL) project at ITU •

COPLAS Seminar -February 8, 2005- DIKU 1 Road Map

Bigraphical reactive systems - briefly • Ground bigraphs and XML • – Signatures – A process calculus for (open) ground bigraphs – From bigraphs to XML and back

Contexts and reactions • Reactive XML implementation - evaluation contexts and matching • Future work •

COPLAS Seminar -February 8, 2005- DIKU 2 Bigraphical reactive systems - briefly

Bigraph: Topo graph + Link graph. • Topo graph: Tuple of finite unordered trees. • Each node is typed with a control and has a number of ports

Link graph: Hyper-edges between ports and names in interface(s). • Graphical notation for a (ground) bigraph Rooms with two regions:

hilde office hniss jww

Room PDA PDA Room Room

COPLAS Seminar -February 8, 2005- DIKU 3 Bigraph contexts

A bigraph may have an ordered set of holes among leaves of topo graph. • Names in inner- and outer-face used to connect links in composition •

Graphical notation for a bigraph (context) Building with two holes:

hniss hilde office jww

Floor

PDA hole1 hole2 Lift Room Floor

hniss hilde office jww

COPLAS Seminar -February 8, 2005- DIKU 4 Bigraph composition

Bigraphs with matching inner and outer-faces can be composed: •

PDA hniss hilde office jww

Floor hniss hilde office PDA jww hole1 hole2

Lift Floor Room Floor PDA

PDA PDA hniss hilde office jww = Room Lift Room Room Floor hilde office hniss jww

Room PDA PDA Room Room

COPLAS Seminar -February 8, 2005- DIKU 5 Bigraph reactions

A bigraph reaction rule is essentially a pair (L, R) of contexts: •

Floor Floor

hole3 hole3 hole1 hole2 hole1 hole2 Lift Lift Floor Floor

Reaction: G E R P if G E L P and E an evaluation context • → ◦ ◦ ≡ ◦ ◦ In general parameters may contain extra links, be copied and discarded. •

COPLAS Seminar -February 8, 2005- DIKU 6 Bigraph theory [Milner, Jensen]

Closed links and ”structural congruence as graph isomorphism” • Labelled transition systems from RPO’s and congruence • Axiomatisations (DNF and CNF) • Binding bigraphs and π-calculus • Local bigraphs and lambda calculus •

COPLAS Seminar -February 8, 2005- DIKU 7 Road Map

Bigraphical reactive systems - briefly • Ground bigraphs and XML → – Signatures – A process calculus for (open) ground bigraphs – From bigraphs to XML and back

Contexts and reactions • Reactive XML implementation - evaluation contexts and matching • Future work •

COPLAS Seminar -February 8, 2005- DIKU 8 Signatures

A signature is a tuple (Σ, Att, ar), where • – Σ is a set of element names – Att is a set of finite sets (of attribute names) – ar : Σ Att assign a finite attribute set to each element. → Bigraph signatures have Att = ω • (where ω is the set 0, . . . , n 1 n 0 of finite ordinals.) { − } | ≥ Bigraphs generalise !trivially to named ports."

COPLAS Seminar -February 8, 2005- DIKU 9 Process calculus for bigraphs

We use a process calculus notation for bigraphs inspired by Milner’s CNF:

Assume an infinite set N of names • For a signature Σ = (Σ, Att, ar) define for any finite set of names • X N respectively the ⊂

t ::= κ i : xi i ar(κ).p Σ-process expressions { } ∈ p ::= t p p 1 Prime Σ-process expressions | | | r ::= r r p 0 Wide Σ-process expressions ' | | with names X, for κ Σ and x X. ∈ i ∈

COPLAS Seminar -February 8, 2005- DIKU 10 Structural congruence and interfaces

Structural congruence is the least congruence such that ≡ p (p p ) (p p ) p p 1 p 1 p p p q q p 1| 2| 3 ≡ 1| 2 | 3 | ≡ | ≡ | ≡ | and r (r r ) (r r ) r r 0 r 0 r r 1 ' 2 ' 3 ≡ 1 ' 2 ' 3 ' ≡ ' ≡

We say that r ΠΠi n pi has width n, and • ≡ ∈ explicit type processes with the interface r : n, X for fn(r) X • ) * ⊆

COPLAS Seminar -February 8, 2005- DIKU 11 Denotation

The denotation of process expressions is straightforward:

[[r r"]] = [[r]] [[r"]] ' ' [[κ i : ni i ar(κ).p]] = (κ i:ni i ar(κ) idfn(p)) [[p]] { } ∈ { } ∈ | ◦ [[p p"]] = [[p]] [[p"]] | | [[0]] = 0 [[1]] = 1 where 0 is the empty bigraph, 1 is the barren region bigraph, and κ i:n { i}i ar(κ) is the ion bigraph. ∈

COPLAS Seminar -February 8, 2005- DIKU 12 Bigraph XML documents

A Σ-XML document D with interface n, x1, . . . , xk is a valid document of the form ) { }*

D := < root x1 = ”id1 ” . . . xk = ”idk ” > R1 . . . Rn < /root > R := < region > P < /region >

P := T1 . . . Th

T := < κ a1 = ”v1 ” . . . aj = ”vj ” >P < /κ > where root, region Σ, xi are ID attributes and ai are IDREF attributes, κ Σ and ar(κ) =,∈ a , . . . , a . ∈ { 1 j}

COPLAS Seminar -February 8, 2005- DIKU 13 Bigraph process expressions as XML

Define

[[r : n, x , . . . , x ]] = [[r]] X ) { 1 k}* 1 1 k k X [[p r]] = [[p]] [[r]] X ' X X [[p q]] = [[p]] [[q]] X | X X [[κ ai : xi" a ar(κ).p]] = <κ a1 = ”$x1" ” . . . aj = ”$xj"”> [[p]] X { } i∈ X [[0]] = [[1]] = $ X X where $ is the empty document.

COPLAS Seminar -February 8, 2005- DIKU 14 From XML to process calculi expressions

[[ R1 . . . Rn ]] = ΠΠi n [[Ri]]σ : n, x¯ P ∈ P ) * [[P ]] = [[P ]] P σ P σ [[T1 . . . Tm]] = Πi m [[Ti]]σ P ∈ P [[<κ a¯ = w¯> P < /κ >]]σ = κ ai : σ(wi) a ar(κ). [[P ]]σ P { } i∈ P for σ(vi) = xi.

Proposition: [[ [[r : n, X ]]]] r : n, X • P X ) * ≡ ) *

COPLAS Seminar -February 8, 2005- DIKU 15 Examples

room type : office, name : hilde . { } (person name : hilde person name : hniss ) { }| { } ' room type : office, name : hniss : 2, office, hilde, jww, hniss { } ) { }*

COPLAS Seminar -February 8, 2005- DIKU 16 Examples the CCS-like process expression

act ch : a .act ch : b coact ch : a : a, b { } { } | { } { } is represented by the XML document

COPLAS Seminar -February 8, 2005- DIKU 17 Road Map

Bigraphical reactive systems - briefly • Ground bigraphs and XML • – Signatures – A process calculus for (open) ground bigraphs – From bigraphs to XML and back

Contexts and reactions → Reactive XML implementation - evaluation contexts and matching • Future work •

COPLAS Seminar -February 8, 2005- DIKU 18 Contexts

For X, Y N and n, m 0 define • ⊆ ≥

P ::= κ i : xi i ar(κ).P P P [ ]j 1 { } ∈ | | | | R ::= R R P 0 ' | | W ::= σ R ' where κ Σ, x X and j m and σ : Y X is a map from Y to X. ∈ i ∈ ∈ → W : m, Y n, X is linear if every index j m appears exactly once • ) * → ) * ∈ Write W for the wide contexts over signature Σ. • Σ

COPLAS Seminar -February 8, 2005- DIKU 19 Compositions

For W : m, Y n, X and W " : n, X n", X" define ) * → ) * ) * → ) * W " W : m, Y n", X" = σ" σ R"[j : Pjσ"]j n, if ◦ ) * → ) * ◦ ' ∈

W = σ ΠΠj n Pj, • ' ∈

W " = σ" R" • '

P σ" denotes substitution of x X in P with σ"(x) X" and • j ∈ j ∈

R"[j : Pjσ"]j n denotes insertion of Pjσ" in all holes of R" with index j. • ∈ Positive (monotone) web service: W (D) = [[W [[D]]]]. X ◦ P

COPLAS Seminar -February 8, 2005- DIKU 20 Reactions

Parametric reaction rule: (R : m, X n, X , R" : m, X n, X ) • for R linear. ) * → ) * ) * → ) *

For a set S of parametric reaction rules and Ξ Σ of active prefixes define ⊆

React = L, E (id R") r L E (id R) r, S,Ξ ◦ Y ' ◦ | ≡ ◦ Y ' ◦ (R, R" : n, X m, X ) S, !# $ ) * → ) * ∈ E : m, Y m", Z WΞ and r : )n, Y *fo→r X) Y * ∈ ) * ⊆ " and D D", if ( [[D]], R") React and [[R"]] = D". → P ∈ S,Ξ X ReactS,Ξ is typically infinite...not very operational...!

COPLAS Seminar -February 8, 2005- DIKU 21 Road Map

Bigraphical reactive systems - briefly • Ground bigraphs and XML • – Signatures – A process calculus for (open) ground bigraphs – From bigraphs to XML and back

Contexts and reactions • Reactive XML implementation - evaluation contexts and matching → Future work •

COPLAS Seminar -February 8, 2005- DIKU 22 Reactive XML Implementation

To compute a reaction we must

1. Find (R, R" : n, X 1, X ) S, ) * → ) * ∈ 2. an evaluation context σ R : 1, Y m, Z W and ' E ) * → ) * ∈ Ξ

3. a wide process expression r = ΠΠj n pj such that ∈

[[D]] = RE[R[j : pj]j nσ] P ∈

4. compute the document D" = [[RE[R"[j : pj]j nσ]]]. X ∈

COPLAS Seminar -February 8, 2005- DIKU 23 Computing the match

RE[R[j : pj]j nσ] = RE[Rσ[j : pjσ]j n] = RE Rσ rσ • ∈ ∈ ◦ ◦ ”Find sub process: Rσ rσ in active (evaluation) context” • ◦ Evaluation contexts R W are identified by the XPath expression • E ∈ Ξ //*[not(ancestor-or-self::*[name()=’X_1’ .. or name()=’X_k’])]

for Σ Ξ = X , X , . . . , X . \ { 1 2 k} Allows us to use standard XML routines •

COPLAS Seminar -February 8, 2005- DIKU 24 Matching - a few more details

Generalisation of unordered subtree problem (Twig matching) • Need to treat holes and variables. •

S T r r V = [($1,a)]

b a c $1 b

a $1

and a trick: add hole as sibling to roots in rewrite rule. •

COPLAS Seminar -February 8, 2005- DIKU 25 Reactive XML prototype

Implemented in .NET (rich XML support and easy GUI). •

COPLAS Seminar -February 8, 2005- DIKU 26 XML contexts

Use a reserved element name hole with attribute name • E.g. the context act($a).[ ] coact($a).[ ] is represented by • 1 ' 2

COPLAS Seminar -February 8, 2005- DIKU 27 Example: Ambients rule Sin = (Lin, Rin)

L = $beingMoved in $moveT o.[ ] [ ] $moveT o [ ] • in - 0| 1 .| - 2 .

COPLAS Seminar -February 8, 2005- DIKU 28 Ambients rule Sin = (Lin, Rin) continued

R = $moveT o $beingMoved [ ] [ ] [ ] • in - - 0| 1 .| 2 . %

COPLAS Seminar -February 8, 2005- DIKU 29 Reactive XML prototype

MrW in c open m.0 c MrP 0 MrG 0 m in MrW.0 • - | .| - - .| - .| - . .

COPLAS Seminar -February 8, 2005- DIKU 30 Reactive XML prototype

c MrW open m.0 MrP 0 MrG 0 m in MrW.0 • → - - .| - .| - .| - . .

COPLAS Seminar -February 8, 2005- DIKU 31 Future work

Binding and closed links (XML IDs and IDREFs) • Distributed Reactive XML using XML store • Improve implementation • (efficient algorithms, proper name spaces, XML Schema etc.)

Applications, e.g. context-dependent systems • Reactive XML LTS bisimulation congruences, Bigraphs as XML cospans • Spatial (bigraph) logics and model checking •

COPLAS Seminar -February 8, 2005- DIKU 32 Some additional references

Semistructured Computation, L. Cardelli, DBPL’99, LNCS 1949 • Reactive XML, J. W. Winther, MSc thesis, ITU, 2004 • Bigraphical Logics for XML, G. Conforti, D. Macedonio, V. Sassone • Bilogics: Spatial-nominal logics for bigraphs, -——-, 2004 • Prototype of Reactive XML store, M. Olsen, ITU, 2005 • Meta* and Poly*, H. Makholm and J. Wells, ESOP 2005 • Axiomatisation of binding bigraphs, T. Damgaard and L. Birkedal, 2005 •

COPLAS Seminar -February 8, 2005- DIKU 33