Bunched logic

From HandWiki

Bunched logic[1] is a variety of substructural logic proposed by Peter O'Hearn and David Pym. Bunched logic provides primitives for reasoning about resource composition, which aid in the compositional analysis of computer and other systems. It has category-theoretic and truth-functional semantics, which can be understood in terms of an abstract concept of resource, and a proof theory in which the contexts Γ in an entailment judgement Γ ⊢ A are tree-like structures (bunches) rather than lists or (multi)sets as in most proof calculi. Bunched logic has an associated type theory, and its first application was in providing a way to control the aliasing and other forms of interference in imperative programs.[2] The logic has seen further applications in program verification, where it is the basis of the assertion language of separation logic,[3] and in systems modelling, where it provides a way to decompose the resources used by components of a system.[4][5][6]


The deduction theorem of classical logic relates conjunction and implication:

[math]\displaystyle{ A \wedge B \vdash C \quad \mbox{iff} \quad A \vdash B \Rightarrow C }[/math]

Bunched logic has two versions of the deduction theorem:

[math]\displaystyle{ A * B \vdash C \quad \mbox{iff} \quad A \vdash B {-\!\!*} C \qquad \mbox{and also} \qquad A \wedge B \vdash C \quad \mbox{iff} \quad A \vdash B \Rightarrow C }[/math]

[math]\displaystyle{ A * B }[/math] and [math]\displaystyle{ B {-\!\!*} C }[/math] are forms of conjunction and implication that take resources into account (explained below). In addition to these connectives bunched logic has a formula, sometimes written I or emp, which is the unit of *. In the original version of bunched logic [math]\displaystyle{ \wedge }[/math] and [math]\displaystyle{ \Rightarrow }[/math] were the connectives from intuitionistic logic, while a boolean variant takes [math]\displaystyle{ \wedge }[/math] and [math]\displaystyle{ \Rightarrow }[/math] (and [math]\displaystyle{ \neg }[/math]) as from traditional boolean logic. Thus, bunched logic is compatible with constructive principles, but is in no way dependent on them.

Truth-functional Semantics (resource semantics)

The easiest way to understand these formulae is in terms of its truth-functional semantics. In this semantics a formula is true or false with respect to given resources. [math]\displaystyle{ A*B }[/math] asserts that the resource at hand can be decomposed into resources that satisfy [math]\displaystyle{ A }[/math] and [math]\displaystyle{ B }[/math]. [math]\displaystyle{ B {-\!\!*} C }[/math] says that if we compose the resource at hand with additional resource that satisfies [math]\displaystyle{ B }[/math], then the combined resource satisfies [math]\displaystyle{ C }[/math]. [math]\displaystyle{ \wedge }[/math] and [math]\displaystyle{ \Rightarrow }[/math] have their familiar meanings.

The foundation for this reading of formulae was provided by a forcing semantics [math]\displaystyle{ r \models A }[/math] advanced by Pym, where the forcing relation means 'A holds of resource r'. The semantics is analogous to Kripke's semantics of intuitionistic or modal logic, but where the elements of the model are regarded as resources that can be composed and decomposed, rather than as possible worlds that are accessible from one another. For example, the forcing semantics for the conjunction is of the form

[math]\displaystyle{ r \models A * B \quad \mbox{iff} \quad \exists r_Ar_B.\,r_A \models A,\, r_B \models B,\,\mbox{and}\,r_A \bullet r_B \leq r }[/math]

where [math]\displaystyle{ r_A \bullet r_B }[/math] is a way of combining resources and [math]\displaystyle{ \leq }[/math] is a relation of approximation.

This semantics of bunched logic draws on prior work in relevance logic (especially the operational semantics of Routley–Meyer), but differs from it by not requiring [math]\displaystyle{ r \bullet r \leq r }[/math] and by accepting the semantics of standard intuitionistic or classical versions of [math]\displaystyle{ \wedge }[/math] and [math]\displaystyle{ \Rightarrow }[/math]. The property [math]\displaystyle{ r \bullet r \leq r }[/math] is justified when thinking about relevance but denied by considerations of resource; having two copies of a resource is not the same as having one, and in some models (e.g. heap models) [math]\displaystyle{ r \bullet r }[/math] might not even be defined. The standard semantics of [math]\displaystyle{ \Rightarrow }[/math] (or of negation) is often rejected by relevantists in their bid to escape the `paradoxes of material implication', which are not a problem from the perspective of modelling resources and so not rejected by bunched logic. The semantics is also related to the 'phase semantics' of linear logic, but again is differentiated by accepting the standard (even boolean) semantics of [math]\displaystyle{ \wedge }[/math] and [math]\displaystyle{ \Rightarrow }[/math], which in linear logic is rejected in a bid to be constructive. These considerations are discussed in detail in an article on resource semantics by Pym, O'Hearn and Yang.[7]

Categorical semantics (doubly closed categories)

The double version of the deduction theorem of bunched logic has a corresponding category-theoretic structure. Proofs in intuitionistic logic can be interpreted in cartesian closed categories, that is, categories with finite products satisfying the (natural in A and C) adjunction correspondence relating hom sets:

[math]\displaystyle{ Hom(A \wedge B, C) \quad \mbox{is isomorphic to} \quad Hom(A, B \Rightarrow C) }[/math]

Bunched logic can be interpreted in categories possessing two such structures

a categorical model of bunched logic is a single category possessing two closed structures, one symmetric monoidal closed the other cartesian closed.

A host of categorial models can be given using Day's tensor product construction.[8] Additionally, the implicational fragment of bunched logic has been given a game semantics.[9]

Algebraic semantics

The algebraic semantics of bunched logic is a special case of its categorical semantics, but is simple to state and can be more approachable.

An algebraic model of bunched logic is a poset that is a Heyting algebra and that carries an additional commutative residuated lattice structure (for the same lattice as the Heyting algebra): that is, an ordered commutative monoid with an associated implication satisfying [math]\displaystyle{ A * B \leq C \quad \mbox{iff} \quad A \leq B {-\!\!*} C }[/math].

The boolean version of bunched logic has models as follows.

An algebraic model of boolean bunched logic is a poset that is a Boolean algebra and that carries an additional residuated commutative monoid structure.

Proof theory and type theory (bunches)

The proof calculus of bunched logic differs from usual sequent calculi in having a tree-like context of hypotheses instead of a flat list-like structure. In its sequent-based proof theories, the context [math]\displaystyle{ \Delta }[/math] in an entailment judgement [math]\displaystyle{ \Delta \vdash A }[/math] is a finite rooted tree whose leaves are propositions and whose internal nodes are labelled with modes of composition corresponding to the two conjunctions. The two combining operators, comma and semicolon, are used (for instance) in the introduction rules for the two implications.

[math]\displaystyle{ \frac{\Gamma,A \vdash B}{\Gamma \vdash A{-\!\!*} B} \qquad \qquad \frac{\Gamma;A \vdash B}{\Gamma \vdash A{\Rightarrow} B} }[/math]

The difference between the two composition rules comes from additional rules that apply to them.

  • Multiplicative composition [math]\displaystyle{ \Delta , \Gamma }[/math] denies the structural rules of weakening and contraction.
  • Additive composition [math]\displaystyle{ \Delta ; \Gamma }[/math] admits weakening and contraction of entire bunches.

The structural rules and other operations on bunches are often applied deep within a tree-context, and not only at the top level: it is thus in a sense a calculus of deep inference.

Corresponding to bunched logic is a type theory having two kinds of function type. Following the Curry–Howard correspondence, introduction rules for implications correspond to introduction rules for function types.

[math]\displaystyle{ \frac{\Gamma,x:A \vdash M:B}{\Gamma \vdash \lambda x.M: A{-\!\!*} B} \qquad \qquad \frac{\Gamma;x:A \vdash M: B}{\Gamma \vdash \alpha x.M:A{\Rightarrow} B} }[/math]

Here, there are two distinct binders, [math]\displaystyle{ \lambda }[/math] and [math]\displaystyle{ \alpha }[/math], one for each kind of function type.

The proof theory of bunched logic has an historical debt to the use of bunches in relevance logic.[10] But the bunched structure can in a sense be derived from the categorical and algebraic semantics: to formulate an introduction rule for [math]\displaystyle{ {-\!\!*} }[/math] we should mimick [math]\displaystyle{ * }[/math] on the left in sequents, and to introduce [math]\displaystyle{ \Rightarrow }[/math] we should mimick [math]\displaystyle{ \wedge }[/math]. This consideration leads to the use of two combining operators.

James Brotherston has done further significant work on a unified proof theory for bunched logic and variants,[11] employing Belnap's notion of display logic.[12]

Galmiche, Méry, and Pym have provided a comprehensive treatment of bunched logic, including completeness and other meta-theory, based on labelled tableaux.[13]


Interference control

In perhaps the first use of substructural type theory to control resources, John C. Reynolds showed how to use an affine type theory to control aliasing and other forms of interference in Algol-like programming languages.[14] O'Hearn used bunched type theory to extend Reynolds' system by allowing interference and non-interference to be more flexibly mixed.[2] This resolved open problems concerning recursion and jumps in Reynolds' system.

Separation logic

Separation logic is an extension of Hoare logic that facilitates reasoning about mutable data structures that use pointers. Following Hoare logic the formulae of separation logic are of the form [math]\displaystyle{ \{Pre\} program \{Post\} }[/math], but the preconditions and postconditions are formulae interpreted in a model of bunched logic. The original version of the logic was based on models as follows:

  • [math]\displaystyle{ Heaps = L \rightharpoonup_f V \qquad }[/math] (finite partial functions from locations to values)
  • [math]\displaystyle{ h_0 \bullet h_1 = }[/math] union of heaps with disjoint domains, undefined when domains overlap.

It is the undefinedness of the composition on overlapping heaps that models the separation idea. This is a model of the boolean variant of bunched logic.

Separation logic was used originally to prove properties of sequential programs, but then was extended to concurrency using a proof rule

[math]\displaystyle{ \frac{\{P_1\} C_1 \{Q_1\} \quad \{P_2\} C_2 \{Q_2\}}{\{P_1 * P_2\} C_1 \parallel C_2 \{Q_1 * Q_2\}} }[/math]

that divides the storage accessed by parallel threads.[15]

Later, the greater generality of the resource semantics was utilized: an abstract version of separation logic works for Hoare triples where the preconditions and postconditions are formulae interpreted over an arbitrary partial commutative monoid instead of a particular heap model.[16] By suitable choice of commutative monoid, it was surprisingly found that the proofs rules of abstract versions of concurrent separation logic could be used to reason about interfering concurrent processes, for example by encoding rely-guarantee and trace-based reasoning.[17][18]

Separation logic is the basis of a number of tools for automatic and semi-automatic reasoning about programs, and is used in the Infer program analyzer currently deployed at Facebook.[19]

Resources and processes

Bunched logic has been used in connection with the (synchronous) resource-process calculus SCRP[4][5][6] in order to give a (modal) logic that characterizes, in the sense of Hennessy–Milner, the compositional structure of concurrent systems.

SCRP is notable for interpreting [math]\displaystyle{ A * B }[/math] in terms of both parallel composition of systems and composition of their associated resources. The semantic clause of SCRP's process logic that corresponds to separation logic's rule for concurrency asserts that a formula [math]\displaystyle{ A * B }[/math] is true in resource-process state [math]\displaystyle{ R }[/math], [math]\displaystyle{ E }[/math] just in case there are decompositions of the resource [math]\displaystyle{ R = S \bullet T }[/math] and process [math]\displaystyle{ E }[/math] ~ [math]\displaystyle{ F \times G }[/math], where ~ denotes bisimulation, such that [math]\displaystyle{ A }[/math] is true in the resource-process state [math]\displaystyle{ S }[/math], [math]\displaystyle{ F }[/math] and [math]\displaystyle{ B }[/math] is true in the resource-process state [math]\displaystyle{ T }[/math], [math]\displaystyle{ G }[/math]; that is [math]\displaystyle{ R, E \models A }[/math] iff [math]\displaystyle{ S, F \models A }[/math] and [math]\displaystyle{ T, G \models B }[/math].

The system SCRP[4][5][6] is based directly on bunched logic's resource semantics; that is, on ordered monoids of resource elements. While direct and intuitively appealing, this choice leads to a specific technical problem: the Hennessy–Milner completeness theorem holds only for fragments of the modal logic that exclude the multiplicative implication and multiplicative modalities. This problem is solved by basing resource-process calculus on a resource semantics in which resource elements are combined using two combinators, one corresponding to concurrent composition and one corresponding to choice.[20]

Spatial logics

Cardelli, Caires, Gordon and others have investigated a series of logics of process calculi, where a conjunction is interpreted in terms of parallel composition. Unlike the work of Pym et al. in SCRP, they do not distinguish between parallel composition of systems and composition of resources accessed by the systems.

Their logics are based on instances of the resource semantics that give rise to models of the boolean variant of bunched logic. Although these logics give rise to instances of boolean bunched logic, they appear to have been arrived at independently, and in any case have significant additional structure in the way of modalities and binders. Related logics have been proposed as well for modelling XML data.

See also


  1. O'Hearn, Peter; Pym, David (1999). "The Logic of Bunched Implications". Bulletin of Symbolic Logic 5 (2): 215–244. doi:10.2307/421090. http://www.cs.ucl.ac.uk/staff/p.ohearn/papers/BI.pdf. 
  2. 2.0 2.1 O'Hearn, Peter (2003). "On Bunched Typing". Journal of Functional Programming 13 (4): 747–796. doi:10.1017/S0956796802004495. http://www0.cs.ucl.ac.uk/staff/p.ohearn/papers/BunchedTyping.pdf. 
  3. Ishtiaq, Samin; O'Hearn, Peter (2001). "BI as an assertion language for mutable data structures". POPL 28th (3): 14–26. doi:10.1145/373243.375719. http://www0.cs.ucl.ac.uk/staff/p.ohearn/papers/bi-assertion-lan.pdf. 
  4. 4.0 4.1 4.2 Pym, David; Tofts, Chris (2006). "A Calculus and logic of resources and processes". Formal Aspects of Computing 8 (4): 495–517. doi:10.1007/s00165-006-0018-z. http://www0.cs.ucl.ac.uk/staff/D.Pym/pym-tofts-fac-preprint.pdf. 
  5. 5.0 5.1 5.2 Collinson, Matthew; Pym, David (2009). "Algebra and Logic for Resource-based Systems Modelling". Mathematical Structures in Computer Science 19 (5): 959–1027. doi:10.1017/S0960129509990077. 
  6. 6.0 6.1 6.2 Collinson, Matthew; Monahan, Brian; Pym, David (2012). A Discipline of Mathematical Systems Modelling. London: College Publications. ISBN 978-1-904987-50-5. 
  7. Pym, David; O'Hearn, Peter; Yang, Hongseok (2004). "Possible worlds and resources: The semantics of BI". Theoretical Computer Science 315 (1): 257–305. doi:10.1016/j.tcs.2003.11.020. http://www.cs.ucl.ac.uk/staff/p.ohearn/papers/resource.ps. 
  8. Day, Brian (1970). "On closed categories of functors". Reports of the Midwest Category Seminar IV. Lecture Notes in Mathematics. 137. Springer. pp. 1–38. https://www.math.rochester.edu/people/faculty/doug/otherpapers/DayReport.pdf. 
  9. McCusker, Guy; Pym, David (2007). "A Games Model of Bunched Implications". Computer Science Logic. Lecture Notes in Computer Science. 4646. Springer. http://www.cs.bath.ac.uk/~gam23/papers/innocentBI.pdf. 
  10. Read, Stephen (1989). Relevant Logic: A Philosophical Examination of Inference. Wiley-Blackwell. 
  11. Brotherston, James (2012). "Bunched logics displayed". Studia Logica 100 (6): 1223–1254. doi:10.1007/s11225-012-9449-0. http://www0.cs.ucl.ac.uk/staff/J.Brotherston/StudiaLogica12/BL_display_SL_final.pdf. 
  12. Belnap, Nuel (1982). "Display logic". Journal of Philosophical Logic 11 (4): 375–417. doi:10.1007/BF00284976. 
  13. Galmiche, Didier; Méry, Daniel; Pym, David (2005). "The Semantics of BI and Resource Tableaux". Mathematical Structures in Computer Science 15 (6): 1033–1088. doi:10.1017/S0960129505004858. 
  14. Reynolds, John (1978). "Syntactic Control of Interference". Fifth Annual ACM Symposium on Principles of Programming Languages. Popl '78: 39–46. doi:10.1145/512760.512766. ISBN 9781450373487. 
  15. O'Hearn, Peter (2007). "Resources, Concurrency and Local Reasoning". Theoretical Computer Science 375 (1–3): 271–307. doi:10.1016/j.tcs.2006.12.035. http://www0.cs.ucl.ac.uk/staff/p.ohearn/papers/concur04.pdf. 
  16. Calcagno, Cristiano; O'Hearn, Peter W.; Yang, Hongseok (2007). "Local Action and Abstract Separation Logic". 22nd Annual IEEE Symposium on Logic in Computer Science (LICS 2007). pp. 366–378. doi:10.1109/LICS.2007.30. ISBN 978-0-7695-2908-0. http://www.cs.ox.ac.uk/people/hongseok.yang/paper/asl-short.pdf. 
  17. Dinsdale-Young, Thomas; Birkedal, Lars; Gardner, Philippa; Parkinson, Matthew; Yang, Hongseok (2013). "Views: Compositional Reasoning for Concurrent Programs". Proceedings of the 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages 48: 287–300. doi:10.1145/2480359.2429104. http://research.microsoft.com/pubs/180039/views.pdf. 
  18. Sergey, Ilya; Nanevski, Aleksandar; Banerjee, Anindya (2015). "Specifying and Verifying Concurrent Algorithms with Histories and Subjectivity". 24th European Symposium on Programming. Bibcode2014arXiv1410.0306S. http://ilyasergey.net/papers/histories-esop15.pdf. 
  19. Calcagno, Cristiano; Distefano, Dino; O'Hearn, Peter (2015-06-11). "Open-sourcing Facebook Infer: Identify bugs before you ship". https://code.facebook.com/posts/1648953042007882/open-sourcing-facebook-infer-identify-bugs-before-you-ship/. 
  20. Anderson, Gabrielle; Pym, David (2015). "A Calculus and Logic of Bunched Resources and Processes". Theoretical Computer Science 614: 63–96. doi:10.1016/j.tcs.2015.11.035.