locus · bigraph tutorial · Problems for Chapter II

II Problems: Rules, Reactions and CCS

Solved and supplementary problems on Chapter II, at the level of a graduate course, with problems in Lean. Every computed answer is a theorem in Bigraph/Problems/ChII.lean, every figure is drawn from a Lean term, and each solution says what it argues on paper only.

How to read this page. "Definition II.4" means the fourth definition of Chapter II, and likewise for its theorems and figures; "Law I.1" and "Definition I.16" point into Chapter I. A problem uses only what Chapters I and II define or prove, and says so in its last line. Several problems follow exercises of Milner's book [Mil08], restated for the signatures of Chapter II; the solutions are our own.

What is checked. Every computed answer is a Lean theorem, and so is every instance a solution works. A general argument is checked when the library proves its statement; otherwise the last line of the solution says what is argued on paper only.

This book holds the solved problems, II.1 to II.7; the supplementary problems, II.8 to II.22, with their answers at the end; and the problems in Lean, II.23 to II.26.

Solved problems

Problem II.1 (Activity of a composite). Let F : I → J and G : J → K.

  1. Show that G ◦ F is active at a site s exactly when F is active at s and G is active at its site r, where r is the region of F that s lies in.
  2. Let A be an active ion and B a passive one, each with one site. Let F = A ⊗ 1, where 1 = merge 0 is one empty region, and G = merge 2 ◦ (A ⊗ B). Show that G ◦ F is active and G is not.

After [Mil08, Exercise 7.1].

Solution.

  1. Follow the parents up from s in G ◦ F (Definition I.6). First come the nodes of F above s, up to region r of F. That region fills site r of G, so next come the nodes of G above site r. These are all the nodes above s, and Definition II.1 asks that every one be active. The region r exists, since every chain of parents ends at a region, by acyclicity.
  2. G is not active: its site 1 lies inside B. In G ◦ F, the one site lies inside F's A, in region 0 of F; that region fills site 0 of G, inside G's A. Both are active, so by (a) G ◦ F is active. Site 1 of G is filled by region 1 of F, which is empty, so nothing ends up inside B (Figure 1).

Activity of a composite depends only on the sites of the outer factor that the inner one actually fills with something. A passive node with nothing below it blocks nothing.

Figure 1. Problem II.1(b): G above F, unplugged, and G ◦ F. F's region 0, with the site inside its A, fills the site inside G's A; its empty region 1 fills the site inside B.
abbrev F : Bg Examples.sig (Iface.ofWidth (Name := Nat) 1) (Iface.ofWidth 1 ⊗ᵢ Iface.ofWidth 1) :=
  A ⊗ (merge Examples.sig 0 : Bg Examples.sig (Iface.ofWidth (Name := Nat) 0) (Iface.ofWidth 1))

abbrev G : Bg Examples.sig (Iface.ofWidth (Name := Nat) 1 ⊗ᵢ Iface.ofWidth 1) (Iface.ofWidth 1) :=
  merge Examples.sig 2 ◦ (A ⊗ B)

Uses Definitions I.5, I.6, I.8, I.12 and II.1. In Lean: (b), as Problem II.23 (G_not_active, GF_active), and one half of (a) for all sites at once (Active.comp: if F and G are active, so is G ◦ F). On paper: (a) in full.

Problem II.2 (Reaction in an active context).

  1. Prove Theorem II.1 from Definition II.2: if a ⊿ b and E is active, then E ◦ a ⊿ E ◦ b.
  2. Show from the toy of Chapter II that E must be active.

Solution.

  1. By Definition II.2, a = ⟪D ◦ r⟫ and b = ⟪D ◦ r′⟫ for a rule (r, r′) and an active D. By Law I.1, E ◦ (D ◦ r) = (E ◦ D) ◦ r, and likewise with r′. By Problem II.1(a), E ◦ D is active: each site of D is active in D, and the region it lies in fills a site of E, active in E. So the same rule, in the context E ◦ D, gives E ◦ a ⊿ E ◦ b. When the faces of E and a are the same only as sets, a renaming wiring goes between, and it has no nodes, so it changes no activity.
  2. ping ⊿ pong by the ping rule, in the identity context. Put the ping in the hidden panel: the only occurrence of the redex now has the passive hidden above it, so it is no reaction. The chapter's run shows it: the hidden ping waits until a toggle makes its panel active.

Uses Definitions I.6, II.1 and II.2, Law I.1, Theorem II.1 and Problem II.1. In Lean: (a), as the library's React.comp, and as Problem II.24 for contexts that compose on the nose; (b), as the chapter's hidden_waits.

Problem II.3 (Absence cannot be tested).

  1. Let a, b : ε → ⟨1, X⟩ with a ⊿ b, and let c : ε → ⟨1, Y⟩ be an agent for which a ∣ c is defined. Show that a ∣ c ⊿ b ∣ c.
  2. Deduce that no set of rules makes add v react exactly when no cell v is present, and explain how the list of Chapter II gets round it.

Solution.

  1. As abstract bigraphs, a ∣ c is (𝟙 ⟨1, X⟩ ∣ c) ◦ a: the context 𝟙 ⟨1, X⟩ ∣ c holds a site beside c, in one region, and a fills the site (Definitions I.11 and I.12). The context is active: its one site has no node above it. So Theorem II.1 gives (𝟙 ∣ c) ◦ a ⊿ (𝟙 ∣ c) ◦ b.
  2. Suppose a set of rules made add v react in an agent a with no cell v. By (a) it would react in a ∣ cell v too, where a cell v is present. A rule applies where its redex occurs and says nothing about what does not occur. The list does not test absence: it tests presence, of the sentinel stop, at the end of a walk along the links. The walk passes every cell of the list, and the rule that moves on exists only for cells w ≠ v, so reaching stop shows that no cell of the list holds v. A cell v beside the list, not linked into it, does not stop the append, and should not: the set is the list.

Uses Definitions I.11, I.12 and II.2, and Theorem II.1. On paper: (a), whose first step is the abstract equation a ∣ c = (𝟙 ∣ c) ◦ a, and (b).

Problem II.4 (Copying and discarding).

  1. The server rule has ϱ = (0, 0, 1). For the parameter d = d₀ ∥ d₁ ∥ d₂, write ϱ(d).
  2. For each of the three CCS rules of Definition II.8, give ϱ and say which regions of the parameter are copied, which are kept once and which are discarded.
  3. Show that instantiating by ϱ′ and then by ϱ is instantiating by ϱ′ ∘ ϱ (Theorem II.2), and say why the order is reversed.

Solution.

  1. Region j of ϱ(d) holds a copy of region ϱ j of d (Definition II.4), so ϱ(d) = d₀ ∥ d₀ ∥ d₁. The body d₀ is copied: one copy stays in the server, one runs. The continuation d₁ is kept, and d₂, the other summands, is discarded.
  2. Two sums, ϱ = (0, 2): the chosen continuations, regions 0 and 2, are kept once; the other summands, 1 and 3, are discarded. Server and sum, ϱ = (0, 0, 1): as in (a). Two servers, ϱ = (0, 1, 0, 1): both bodies are copied, each server keeping one copy, and nothing is discarded.
  3. Region k of ϱ(ϱ′(d)) holds a copy of region ϱ k of ϱ′(d), which holds a copy of region ϱ′ (ϱ k) of d. So the composite instantiation is k ↦ ϱ′ (ϱ k), that is ϱ′ ∘ ϱ. An instantiation maps the sites of the reactum back to the sites of the redex, so maps compose the other way round from the instantiations, as substitutions do.
theorem inst_maps :
    (List.ofFn Bigraph.Shapes.ssInst).map Fin.val = [0, 2] ∧ (List.ofFn rsInst).map Fin.val = [0, 0, 1] ∧
    (List.ofFn rrInst).map Fin.val = [0, 1, 0, 1] := by decide

Uses Definitions II.3–II.5 and II.8, and Theorem II.2. In Lean: the three maps (inst_maps), and (c) in general (the library's inst_comp). On paper: (a) and the reading of (b).

Problem II.5 (Designing rules for the office). In the office of Chapter I every control is active.

  1. Give parametric rules leave and enter that let an agent on any name x leave a room for the place around it, and enter a room beside it.
  2. Give five invariants of the office under these rules: properties of every agent the office can reach.
  3. Replace leave by a rule hangUp under which an agent that leaves a room also closes its link. Which invariant of (b) fails, and what new one holds?

After [Mil08, Exercise 1.2].

Solution.

  1. For each name x, with one site each and ϱ = (0):
    leave_x : room.(agent_x ∣ □₀)  ⟶  agent_x ∣ room.□₀
    enter_x : agent_x ∣ room.□₀  ⟶  room.(agent_x ∣ □₀)
    The site keeps the rest of the room's contents in the room. The rules are families indexed by the name, like the list's families indexed by a value.
  2. Among others: the building, the rooms and the laptops are never created, destroyed or moved; there are always three agents; each agent keeps its name, since neither rule touches a link; every agent is in the building, directly or in a room, since the rules move an agent only between a room and its parent, which is the building; and no node is ever inside an agent, since agents are atoms.
  3. hangUp_x : room.(agent_x ∣ □₀)  ⟶  /e(agent_e) ∣ room.□₀
    The reactum keeps x as an idle outer name (its outer face is the redex's), and the agent's port goes to a new edge. "Each agent keeps its name" fails. A new invariant holds: an agent on an edge is never again on a name, since no rule links a port to a name. An agent that hangs up never rejoins its call.

Uses Definitions I.5, I.9, I.12 and II.1–II.5. On paper: all of it. The rules are not in Lean.

Problem II.6 (Removing from the list).

  1. Show that a reaction never joins two links of the context: if a rule's redex has distinct outer names p and q, the points of the context linked to p and to q are on different links after the reaction, as they were before.
  2. Design rules for a request rm v that removes cell v from the list and joins its neighbours.
  3. Why does rm v need no scan, when add v does? What happens to rm v when v is absent?

Solution.

  1. In D ◦ r, a point of D is linked as D links it, and the inner names p and q of D go wherever D sends them (Chapter I, how names meet). Reaction replaces r by r′ and keeps D, so the points of D keep their links in D. The reactum can put its own points on p and q, but cannot make p and q one link: they are distinct outer names of r′. So rm v ∣ cell v[p, q] ⟶ 1 would cut the list: the predecessor stays on p's link, the successor on q's.
  2. Put the predecessor in the redex, so that the reactum can relink it. For every w:
    rm v ∣ head[p] ∣ cell v[p, q]       ⟶  head[q]
    rm v ∣ cell w[o, p] ∣ cell v[p, q]  ⟶  cell w[o, q]
    In the reactum p is idle, and the edge the context gave it is left with no points, which abstract bigraphs forget.
  3. Removing needs a cell v, which is a presence, so a redex can find it directly. Adding needed an absence, which only the walk to stop establishes (Problem II.3). When v is absent, rm v never reacts: the request waits. To make it disappear instead, it would need the scan of add after all.

Uses Definitions I.6, I.9, I.15 and II.2, and Problem II.3. On paper: all of it. The rules are not in Lean.

Problem II.7 (The ground rule of a CCS reaction). The process (ā.0 + b.0) | a.c̄.0 reduces to 0 | c̄.0, encoded over {a, b, c}. Give the parametric rule (R, R′, ϱ) that the reaction uses, the parameter d, the ground rule (r, r′) and the context, and the interfaces of R, R′, d, r and r′.

After [Mil08, Exercise 8.1].

Solution. The two-sums rule on a, the first sum sending:

R  = alt.(snd_a.□₀ ∣ □₁) ∣ alt.(rcv_a.□₂ ∣ □₃) : ⟨4, ∅⟩ → ⟨1, {a}⟩
R′ = a ∣ □₀ ∣ □₁                                : ⟨2, ∅⟩ → ⟨1, {a}⟩,   ϱ = (0, 2)

Here a in R′ is the empty substitution of Theorem I.3: the reactum keeps a as an idle outer name (Definition II.2). The parameter d = d₀ ∥ d₁ ∥ d₂ ∥ d₃ : ε → ⟨4, {b, c}⟩ has: d₀ empty, the continuation of ā; d₁ the other summand, a rcv node on b; d₂ the continuation c̄.0, an alt node holding a snd node on c; and d₃ empty, since the second sum has no other summand. Then, by Definition II.5,

r  = (R ∥ 𝟙 ⟨0, {b, c}⟩) ◦ d             : ε → ⟨1, {a, b, c}⟩
r′ = (R′ ∥ 𝟙 ⟨0, {b, c}⟩) ◦ (d₀ ∥ d₂)     : ε → ⟨1, {a, b, c}⟩

The whole process is the redex, so the context is the identity on ⟨1, {a, b, c}⟩. The parameter uses no edge, as Definition II.5 asks.

theorem rule_faces :
    (ssRule true 0).m = 4 ∧ (ssRule true 0).m' = 2 ∧ (ssRule true 0).J.width = 1 ∧
      (ssRule true 0).J.names.names = [0] ∧ (rsRule true 0).m = 3 ∧ (rsRule true 0).m' = 3 ∧
      (rrRule true 0).m = 2 ∧ (rrRule true 0).m' = 4 := by decide

Uses Definitions II.2–II.5, II.7 and II.8, and Theorem II.7. In Lean: the faces of the rule (rule_faces, with a the channel 0), and the reaction itself (the chapter's react_choice, by Theorem II.7). On paper: the parameter.

Supplementary problems

Answers are at the end of the page. A and B are the active and the passive ion of Problem II.1.

Activity and reaction

Problem II.8 (Active sites). Which sites are active in (a) B ◦ A, (b) A ◦ B, (c) A ⊗ B, (d) merge 2 ◦ (A ⊗ B)?

Problem II.9 (One outer face). In the rule of the finite check, the reactum keeps the channel a as an idle outer name. Why must it, and what would go wrong if its outer face were ⟨1, ∅⟩?

Problem II.10 (Injective, surjective). Which of the instantiations of the three CCS rules, the toggle and the ping rule are injective, and which surjective? What does each property say about the parameter?

Problem II.11 (The trivial instantiations). What is the instance of d : ε → ⟨m, X⟩ under the identity map on m, and under the empty map from 0?

The toy

Problem II.12 (Two toggles). Place two toggles beside the panels of Chapter II after the shown ping has reacted. Which states can the panels end in?

Problem II.13 (Found at once). Place add 1 in the list 1, 3. How many reactions follow, and what is the list after them?

Problem II.14 (Adding again). In the list 1, 3, 2 that the chapter's run leaves, place add 2 again. How many reactions follow, and which rule fires last?

CCS and its encoding

Problem II.15 (Counting nodes). How many nodes and edges do the encodings of ā.0 + b.c̄.0, !a.b̄.0 and νy.(ȳ.0 | y.0) have?

Problem II.16 (Two clients of one server). Give the reductions of !a.b̄.0 | ā.0 | ā.0, up to congruence, and show that one of them is a reaction.

Problem II.17 (The fragment). Which of νy.(ȳ.0 | y.0), νy.!a.ȳ.0 and !a.νy.ȳ.0 are in the fragment of Definition II.6?

Problem II.18 (Closed processes). Which of νy.(ȳ.0 | y.0), a.0 and ȳ.0 are closed (Definition II.9)? For one that is not, say what an environment does with it.

Problem II.19 (Only at the top). Show that the agent of a.(b̄.0 | b.0) has no reaction, although that of b̄.0 | b.0 has one.

Problem II.20 (Scope extrusion). Show that a.0 | νy.ȳ.0 and νy.(a.0 | ȳ.0) have one agent.

Problem II.21 (The converse, again). In the finite check, show that a.(b̄.0 | 0) and a.b̄.0 have one agent, and say why they are not congruent there.

Problem II.22 (Binding-discrete). Which of these parameters are binding-discrete (Definition II.11)? (a) One region holding a nu node and a snd node, both ports on one edge. (b) Two regions, each holding a snd node on one shared edge, with a nu node in region 0 on it. (c) One region holding a snd node on an edge, and no nu node.

Problems in Lean

The problems below are stated in Lean in the exercise file ChII.lean, each with sorry for its proof. The statements are there to read; working them needs the library, which is not public. The file is cut mechanically from the solutions, so its statements are exactly the ones below, which are checked. Every solution uses the axioms propext and Quot.sound at most. A problem marked ⋆ is longer.

Problem II.23 ⋆ (Milner's activity example). Prove Problem II.1(b): (a) G is not active; (b) G ◦ F is.

theorem G_not_active : ¬ G.Active

theorem GF_active : (G ◦ F).Active

Hint: the nodes of a composite list those of the inner factor first. For (b), show first that the passive node is above nothing, by induction on the ancestor relation Anc; every other node is active by computation.

Uses Definitions I.6 and II.1, and Problem II.1. Solution: G_not_active, 3 lines; GF_active, 18 lines.

Problem II.24 (A rule in two active contexts). Prove Theorem II.1 for a rule placed in an active context D, then in an active context E.

theorem react_two_contexts {Ctrl Name : Type} {S : Sig Ctrl} [DecidableEq Name]
    {R : Rules S Name} {ρ : GroundRule S Name} (h : R ρ) {K L : Iface Name}
    (D : Bg S ρ.J K) (E : Bg S K L) (hD : D.Active) (hE : E.Active) :
    React R ⟪E ◦ (D ◦ ρ.redex)⟫ ⟪E ◦ (D ◦ ρ.reactum)⟫

Hint: regroup with Abstract.comp_assoc (Law I.1); then React.in_context and Active.comp.

Uses Definitions II.1 and II.2, Law I.1 and Problem II.2. Solution: react_two_contexts, 2 lines.

Problem II.25 (A reduction that needs congruence). Prove that (ā.0 | b̄.0) | a.0 reduces to (0 | 0) | b̄.0, and deduce that its agent reacts.

def pApart : Proc := .par (.par (pre0 (.snd a)) (pre0 (.snd b))) (pre0 (.rcv a))

def qApart : Proc := .par (.par .nil .nil) (pre0 (.snd b))

theorem red_apart : Red pApart qApart

theorem react_apart :
    React ccsRules (agent Xabc ρ0 pApart (by decide)) (agent Xabc ρ0 qApart (by decide))

Hint: the partners are not side by side, so the reduction needs Red.struct and a chain of structural congruences (parComm, parAssoc, parCong). The reaction then follows by Theorem II.7 (red_sound); the chapter's react_choice shows the form.

Uses Definitions II.6 and II.7, and Theorem II.7. Solution: red_apart, 2 lines; react_apart, 1 line.

Problem II.26 (Not closed). Prove that ȳ.0, a send on a dangling index, is not closed.

def pDangling : Proc := pre0 (.snd y)

theorem dangling_not_closed : ¬ Bigraph.CCSFull.Closed pDangling

Hint: Definition II.9 quantifies over two environments; pick two that name the index differently.

Uses Definition II.9 and Problem II.18. Solution: dangling_not_closed, 3 lines.

Answers to the supplementary problems

Each answer ends, as the solutions do, with what Lean checks and what is argued on paper only.

II.8 (a) None: the one site lies inside A, which lies inside the passive B. (b) None: the site lies inside B. (c) Site 0, inside A, is active; site 1, inside B, is not. (d) The same as (c): the merge adds no node.

In Lean: (a) (the library's box_pas_act_not_active), and site 1 of (d) (G_not_active, Problem II.23). On paper: the rest.

II.9 A ground rule's redex and reactum must have the same outer face (Definition II.2), because one context D is composed with both. The redex has the outer name a, so D's inner face has it, and D ◦ r′ is defined only if r′ has it too. Abstract bigraphs keep idle names (Chapter I), so the reduct's agent still has a as an outer name, unused.

On paper: all of it.

II.10 Two sums, (0, 2): injective, not surjective. Server and sum, (0, 0, 1): neither. Two servers, (0, 1, 0, 1): surjective, not injective. The toggle, (0, 1): both. The ping rule has no sites, and its empty map is both. Injective means no region of the parameter is copied; surjective, none is discarded. Chapter V calls a rule with an injective instantiation linear.

In Lean: the CCS maps (inst_maps). On paper: the rest.

II.11 Under the identity, region j holds a copy of region j, so the instance is d itself, up to the identities of its nodes. Under the empty map the instance has no regions, so it has no nodes either, and it keeps the names X, all idle.

In Lean: the first (the library's inst_id). On paper: the second.

II.12 Two end states. In both, the shown panel holds a pong. If the toggles fire one after the other, the hidden panel still holds its ping; if the released ping reacts between them, it holds a pong (Figure 2). There are four interleavings, two of each. A toggle replaces both panel nodes and moves their contents across, so "the first panel" names nothing that lasts; the contents are what persist.

Figure 2. The two end states of Problem II.12, each drawn from the state the run reaches.

In Lean: all of it (two_toggles), over every interleaving.

II.13 Two: the request starts a scan, and the scan meets cell 1 at once and ends. The list is still 1, 3.

In Lean: all of it (add_one_present).

II.14 Four: the start, two moves past 1 and 3, and the found rule at cell 2. The list stays 1, 3, 2.

In Lean: all of it (add_two_again).

II.15 Five nodes and no edge: an alt node, the prefix nodes snd on a and rcv on b, and inside the second the continuation c̄.0, itself a sum, so an alt node with a snd node. Three nodes: the rrcv node, and the body's alt and snd. Four nodes and one edge: two sums, each an alt node with a prefix node, both prefixes on the edge of νy. The continuation 0 adds nothing.

In Lean: the counts (encode_counts).

II.16 Either client can be served first, and the two results are congruent: !a.b̄.0 | b̄.0 | ā.0, up to 0. Then the other client is served: !a.b̄.0 | b̄.0 | b̄.0. The first step is a reaction of the server rule, by Theorem II.7.

In Lean: the first step, as a reduction and as a reaction (red_two, react_two). On paper: the list of reductions.

II.17 The first two are in the fragment: the first has no replication, and in the second the ν is outside the replicated body. The third is not: its replicated body contains a ν.

In Lean: all of it (fragment).

II.18 νy.(ȳ.0 | y.0) is closed: its one index is bound. a.0 is closed: its channel is free. ȳ.0 is not: the index escapes every binder, so the environment names it, and two environments name it differently.

In Lean: the last (Problem II.26). On paper: the first two.

II.19 Every control of the CCS signature is passive (Chapter II, on activity), so an active context has no node above its sites. The only occurrence of a redex in the agent of a.(b̄.0 | b.0) lies inside the alt and rcv nodes of the prefix, so no active context places it. In b̄.0 | b.0 the two sums are at the top, and the two-sums rule applies.

Uses Definitions II.1, II.2 and II.7. On paper: all of it. Theorem II.8 gives the same answer from the absence of a reduction.

II.20 They are congruent by scope extrusion: a.0 uses no bound name, and shifting it changes nothing, since its channel is free. Congruent processes have one agent (Theorem II.6).

In Lean: all of it (extrusion_agent).

II.21 0 is the empty region, so b̄.0 | 0 and b̄.0 have the same nodes, places and links, and so do the two prefixed processes. The finite check's congruence has no rule that rearranges under a prefix, so they are not congruent there, as for the chapter's pair (Theorem II.3).

On paper: all of it. The chapter proves its own pair in Lean (sc_not_complete).

II.22 (a) Yes: the edge is bound by the parameter's own nu node and lies in one region. (b) No: the edge lies in two regions, so a copy of one region could not own it. (c) No: the edge is bound by no binder of the parameter.

Uses Definitions II.10 and II.11. On paper: all of it.

References

  1. [Mil08]Robin Milner. The Space and Motion of Communicating Agents, author's draft of 1 December 2008, with its Appendix B, "Solutions to exercises". The exercises are transcribed in docs/sources/11-milner-exercises.md. The book was published by Cambridge University Press in 2009.