Skip to main content Accessibility help
×
Hostname: page-component-89b8bd64d-4ws75 Total loading time: 0 Render date: 2026-05-07T12:28:38.980Z Has data issue: false hasContentIssue false

An Introduction to String Diagrams for Computer Scientists

Published online by Cambridge University Press:  01 May 2025

Robin Piedeleu
Affiliation:
University College London
Fabio Zanasi
Affiliation:
University College London

Summary

String diagrams are a powerful graphical language used to represent computational phenomena across diverse scientific fields, including computer science, physics, linguistics, amongst others. The appeal of string diagrams lies in their multi-faceted nature: they offer a simple, visual representation of complex scientific ideas, while also allowing rigorous mathematical treatment. Originating in category theory, string diagrams have since evolved into a versatile formalism, extending well beyond their abstract algebraic roots, and offering alternative entry points to their study. This text provides an accessible introduction to string diagrams from the perspective of computer science. Rather than starting from categorical concepts, the authors draw on intuitions from formal language theory, treating string diagrams as a syntax with its own semantics. They survey the basic theory, outline fundamental principles, and highlight modern applications of string diagrams in different fields. This title is also available as open access on Cambridge Core.

Information

Figure 0

Figure 1.1 Some examples of graphical formalisms: a quantum circuit, an electric circuit, a Petri net, a Bayesian network, and a neural network.

Figure 1

Figure 1.2 An example of a string diagram regarded as a (hyper)graph (a), with the side boxes signalling the interfaces for composing with other string diagrams, and the same string diagram regarded as a piece of syntax (b), with dotted boxes placed to emphasise where elementary components compose, vertically and horizontally.

Figure 2

Figure 1.3 String diagrams representing the behaviour of an electrical circuit (a) and a Petri net (b). The abstract perspective offered by the diagrammatic approach reveals that seemingly very different phenomena may be captured via the same set of elementary components.

Figure 3

Figure 1.4 A major appeal of string diagrams is resource sensitivity: they uncover any implicit assumption on how resources are handled during a computation. For instance, in these string diagrams resources x and y are being fed to processes f and g. Suppose applying g to x is an expensive computation. In the scenario where f receives the value g(x) twice, we are able to distinguish the case where we duplicate x and then feed it to g(a), and the more efficient way, where we duplicate g(x)(b). Note that traditional algebraic syntax would represent both cases as the same term, f(g(x),g(x),y).

Figure 4

(2.1)

Figure 5

(2.2)

Figure 6

Figure 2.1 An example derivation tree.

Figure 7

(2.3)

Figure 8

(2.4)

Figure 9

(2.5)

Figure 10

(2.6)

Figure 11

(2.7)

Figure 12

(2.8)

Figure 13

(2.9)

Figure 14

(3.1)

Figure 15

(4.1)

Figure 16

(4.2)

Figure 17

(4.3)

Figure 18

(4.4)

Figure 19

(4.5)

Figure 20

(4.6)

Figure 21

(4.7)

Figure 22

(4.8)

Figure 23

(4.9)

Figure 24

(4.10)

Figure 25

(5.1)

Figure 26

(5.2)

Figure 27

(5.3)

Figure 28

(5.4)

Figure 29

(5.5)

Figure 30

(5.6)

Figure 31

(5.7)

Figure 32

(5.8)

Figure 33

(5.9)

Figure 34

(5.10)

Figure 35

(5.11)

Figure 36

(5.12)

Figure 37

(5.13)

Figure 38

(5.14)

Figure 39

(6.1)

Figure 40

(6.2)

Figure 41

Figure 7.1 The quantum circuit on the left prepares the GHZ state |000⟩+|111⟩; the ZX-calculus derivation is a diagrammatic proof of this (unlabelled spiders have 0 phase and the square box is a Hadamard gate). See [109: section 5] for similar examples of ZX-calculus proofs.

Figure 42

Figure 7.2 Steps of a derivation transforming the Fibonacci generating function x1−x−x2 into a signal flow graph [21]. The x can be interpreted as derivation in the field R(x) of rational functions or as a time delay. Note that both the specification (on the left), the signal flow graph which realises it (on the right), and the intermediate steps are all string diagrams of the same calculus, and all the steps apply laws of IH over R(x).

Figure 43

Figure 7.3 Deriving textbook properties of electrical circuits by compiling them to graphical linear algebra. The black diagrams represent the voltage–current pairs enforced by elements of the circuit [11].

Figure 44

Figure 7.4 In this scenario, from [75], we seek to identify the causal effect of smoking on cancer. String diagrams represent generalised Bayesian networks, encoding causal dependencies between a set of variables. The prior is ω, the joint probability distribution of smoking (variable S), presence of tar in the lungs (variable T), and developing cancer (variable C). A tobacco company contends that, even though there is a statistical correlation between S and C, there might be some confounding factor H (perhaps genetic) which causes both smoking and cancer (decomposition of ω, on the left). How can we rule out this causal scenario, when direct intervention is impossible? We see that performing a ‘cut’ at S and replacing it with the uniform distribution, as on the right, would remove any confounding influence of H over S. In this case, we can infer from the structure of the diagram that the distribution corresponding to the resulting diagram ω′ can be computed from observational data only. If, under ω′, a smoker is still more likely to develop cancer, then we have demonstrated that there is a causal relationship between S and C.

Save element to Kindle

To save this element to your Kindle, first ensure no-reply@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

An Introduction to String Diagrams for Computer Scientists
Available formats
×

Save element to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

An Introduction to String Diagrams for Computer Scientists
Available formats
×

Save element to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

An Introduction to String Diagrams for Computer Scientists
Available formats
×