1 Introduction

When Ehrenfeucht and Rozenberg introduced the framework of reaction system in Ehrenfeucht and Rozenberg (2007), their motivation was to provide means for the modeling and analysis of the functioning of living cells. But it became clear soon that the framework is a novel computational model based on massive parallelism and on interaction suitable for modeling information processing in various fields beyond biochemistry (see, e.g., Brijder et al. 2011; Ehrenfeucht et al. 2017, 2011, 2017; Salomaa 2012).

The generalization of set-based reaction systems to graph-based reaction systems by Kreowski and Rozenberg in Kreowski and Rozenberg (2018, 2019) was meant as a new approach to graph transformation from the very beginning. In this paper, we continue the investigation by demonstrating that graph-based reaction systems may be useful in the modeling and analysis of NP-problems and their reductions.

The complexity class NP of decision problems solvable nondeterministically in polynomial time can be formally defined as the class of string languages that can be recognized by nondeterministic Turing machines in polynomial time, i.e., in a polynomially bounded number of computation steps. As strings may be seen as special graphs and the processing of Turing machines as a special kind of graph transformation, an alternative definition of NP is given by rule-based graph transformation systems the lengths of derivations of which are polynomially bounded (cf., e.g., Kreowski et al. 2022). The question is whether graph-based reaction systems may play a similar role.

The paper is organized as follows. Section 2 provides basic notion and notations used in this paper. In Sect. 3, we recall the basic concepts of graph-based reaction systems. In Sect. 4 we extend them by the specification of the input and output states as well as of the admitted context sequences to control the computations. Semantically, an extended reaction system models a relation between input and output states. This provides a decision semantics on the input states in addition where an input state yields TRUE if there is a computation into a output state using one of the admitted context sequences, and FALSE otherwise. If there is a single admitted context sequence, then the semantics is a partial function from the set of input states into the set of output states. In general, the computation is nondeterministic. In Sect. 5, we define families of extended graph-based reaction systems. Families of extended graph-based reaction systems can be employed to model NP-problems and reductions between them. This is discussed in Sects. 6 and 7, respectively. In Sect. 8 we show that families of extended graph-based reactions systems can simulate Turing machines. Hence, families of extended graph-based reaction systems are an universal computing model. Furthermore, the whole complexity class NP is covered. Afterwards, in Sect. 9, we discuss solving NP-problems utilizing the massive parallelism of reaction systems. Section 10 concludes the paper pointing out various directions of future work that may shed further light on the motivation of the presented work.

2 Preliminaries

In this section, the basic notions and notations to be used in this paper concerning graphs are recalled.

Let \(\Sigma \) be a set of labels with \(* \in \Sigma \). A (directed edge-labeled) graph over \(\Sigma \) is a system \(G = (V,E,s,t,l)\) where V is a finite set of vertices, E is a finite set of edges, \(s,t:E\rightarrow V\) and \(l:E\rightarrow \Sigma \) are mappings assigning a source, a target and a label to every edge \(e\in E\). An edge e with \(s(e) = t(e)\) is called a loop.

The components V, E, s, t, and l of G are also denoted by \(V_G\), \(E_G\), \(s_G\), \(t_G\), and \(l_G\), respectively. The empty graph is denoted by \(\emptyset \). The class of all directed edge-labeled graphs is denoted by \(\mathcal {G}_\Sigma \).

In drawings of sample graphs, a vertex is represented by a circle with its identifier inside, and an edge is drawn as an arrow starting at its source with the arrowhead pointing to its target and with the label besides.

We reserve a special label \(*\). An edge labeled by \(*\) can be considered as unlabeled. The label \(*\) is used only for this purpose and to simplify the notation, it is omitted in drawings when used.

A graph is unlabeled if all its edges are unlabeled, it is loop-free if none of its edges is a loop, it is simple if no two edges have the same source, the same target and the same label. Without loss of generality, a simple graph can be denoted by \(G=(V,E)\) with \(E \subseteq V \times V \times \Sigma \) where the three projections yield the source, the target and the label resp. and can be omitted therefore. Moreover, if a simple graph is unlabeled, then we omit the third component (being always \(*\)). Such a graph is undirected if E is symmetric, i.e., \((v,v') \in E\) if and only if \((v',v) \in E\). Such a pair of edges may also be denoted by \(\{v,v'\}\). In drawings, it is represented by a line without arrowhead. The loops of such graphs are also drawn without arrowhead. The class of all loop-free, simple, undirected, unlabeled graphs is denoted by \(\mathcal {G}_*^{lsu}\).

A graph H is a subgraph of a graph G, denoted by \(H \subseteq G\), if \(V_H \subseteq V_G\), \(E_H \subseteq E_G\), \(s_H(e) = s_G(e), t_H(e) = t_G(e)\), and \(l_H(e) = l_G(e)\) for all \(e \in E_H\). The set of all subgraphs of a graph G is denoted by sub(G). The empty graph \(\emptyset \) is always a subgraph of G. Moreover, sub(G) is closed under union and intersection: Let \(H,H' \in sub(G)\), then \(H \cup H' = (V_H \cup V_{H'}, E_H \cup E_{H'}, s_\cup , t_\cup , l_\cup )\) with \(s_\cup (e) = s_G(e), t_\cup (e) = t_G(e)\), and \(l_\cup (e) = l_G(e)\) for all \(e \in E_H \cup E_{H'}\) and \(H \cap H' = (V_H \cap V_{H'}, E_H \cap E_{H'}, s_\cap , t_\cap , l_\cap )\) with \(s_\cap (e) = s_G(e), t_\cap (e) = t_G(e)\), and \(l_\cap (e) = l_G(e)\) for all \(e \in E_H \cap E_{H'}\). This works because \(H, H' \in sub(G)\) implies that \(s_G\) and \(t_G\) map \(E_H \cup E_{H'}\) into \(V_H \cup V_{H'}\) and \(E_H \cap E_{H'}\) into \(V_H \cap V_{H'}\). Moreover it implies \(H \cap H' \subseteq H \subseteq H \cup H' \subseteq G\) and \(H \cap H' \subseteq H' \subseteq H \cup H' \subseteq G\).

We use \(\mathbb {N}\) to denote the set of natural numbers (including 0) and \(\mathbb {N}_+\) to denote the set of positive integers. For \(n \in \mathbb {N}, [n]=\{1,\ldots , n\}\). |X| denotes the number of elements of a finite set X. Moreover, |G| denotes the size of a graph G defined as \(|V_G| + |E_G|\).

All examples of NP-problems considered in Sect. 4 concern the class \(G^{lsu}_*\) of loop-free, simple, undirected, unlabeled graphs. In the sample reaction system, we consider subgraphs of the complete graph \(C_n = ([n], [n]^2 {\setminus } \Delta _n)\) where \(\Delta _n = \{ (i,i) \mid i \in [n] \}\) for some \(n \in \mathbb {N}\). Such a subgraph has digits as vertices and pairs of different digits as edges. As usual, we deal with graphs in this concrete way, but consider them as representatives of abstract graphs. Two graphs are considered as equal if they differ only in the naming of vertices and edges, i.e., by isomorphisms. In this sense, we have \(\mathcal {G}^{lsu}_* = \bigcup _{n \in \mathbb {N}} sub(C_n)\).

3 Graph-based reaction systems

In this section, the basic notions and notations of reaction systems on graphs are recalled. While the original notion of reaction systems is purely set-theoretic, the concept is carried over to graphs and subgraphs instead of sets and subsets. Let us first recall the original notions concerning reaction systems.

A set-based reaction system \({{\mathcal {A}}}\) consists of a finite background set B and a finite set of reactions A each of which is of the form \(b=(R,I,P)\), where RIP are non-empty subsets of B such that \(R \cap I = \emptyset \). The components RIP are called the sets of reactants, inhibitors, and products of b, respectively. States are subsets of the background set B. A reaction \(b=(R,I,P)\) is enabled by a state T if \(R \subseteq T\) and \(I \cap T = \emptyset \). The application of b to T yields the successor state which is the union of the products of all enabled reactions.

In graph-based reaction systems, the background set is replaced by a background graph, and the states and the components of reactions are replaced by subgraphs with one exception. We use both vertices and edges as inhibitors, where we may use edges as inhibitors without necessarily forbidding their sources and targets. Therefore, we define an inhibitor as a pair of subgraphs inhibiting the complement of the first one in the second one which leads to the following notion of a (graph-based) reaction.

We use the notion introduced in Kreowski and Rozenberg (2018, 2019), but we use the inhibitor concept introduced in Kreowski and Lye (2020a, 2020b). The inhibitor as a pair of subgraphs allows to avoid the introduction of "partial graphs" as the forbidden part is the difference of the two subgraphs which is usually not a subgraph.

Definition 1

Let B be a graph. A reaction over B is a triple \(b=(R,I,P)\) where R and P are non-empty subgraphs of B and and \(I=(I_1,I_2)\) is a pair of subgraphs of B with \(I_1 \subseteq I_2\) and \(I_2 \cap R \subseteq I_1\). R is called reactant graph, I is called inhibitor, and P is called product graph. The reaction b is called uninhibited if the inhibitor is empty, i.e. \(I =(\emptyset , \emptyset )\).

We use the notations \(R_b\), \( I_b\) and \(P_b\) to denote R, I and P, respectively.

Next we formalize the application of a reaction and of a set of reactions to a graph (which is a subgraph of the "universe" graph B).

Definition 2

Let B be a graph.

  1. 1.

    A state of B is a subgraph of B.

  2. 2.

    A reaction \(b=(R,(I_1,I_2),P)\) over B is enabled by a state T, denoted by \(en_b(T)\), if \(R \subseteq T\) and \(I_2 \cap T \subseteq I_1\).

  3. 3.

    The result of a reaction b on the state T is \(res_b(T)=P_b\) if \(en_b(T)\) and \(res_b(T)= \emptyset \) otherwise.

  4. 4.

    The result of a set of reactions A over B on a state T is \(res_A(T)= \bigcup _{b \in A} res_b(T)\).

Example 1

Consider the graph \(C_n^\Delta = ([n], [n]^2)\) and the set of reactions () for \(i,j \in [n], i\ne j\). The reaction wrt vertices i and j is enabled on a subgraph of \(C_n^\Delta \) if it contains i and j, which are also looped and not connected by an edge. The product is the subgraph consisting of i and j which are now unlooped and connected.

Remark 1

It is important to notice (since the union of subgraphs of B is a subgraph of B) the result of A on T is a subgraph of B.

We are ready now to define the notion of a graph-based reaction system.

Definition 3

A graph-based reaction system is a pair \({{\mathcal {A}}} = (B, A)\) where B is a graph, called the background graph of \({\mathcal {A}}\), and A is a set of reactions over B. For a state T of B, also called a state of \({{\mathcal {A}}}\), the result of \({{\mathcal {A}}}\) on T is the result of A on T, i.e., \(res_{{{\mathcal {A}}}}(T) = res_A(T)\).

Remark 2

  1. 1.

    Thus a graph-based reaction system \({{\mathcal {A}}} = (B, A)\) is basically a set of reactions A. In specifying \({{\mathcal {A}}} \), we also specify its background graph B which is a sort of a "universe" of \({{\mathcal {A}}} \), as for each reaction \(b \in A\) both \(R_b\) and \(P_b\) are subgraphs of B, and \(I_b=(I_{1b},I_{2b})\) is a pair of subgraphs. The enabling requirement \(I_{2b} \cap T \subseteq I_{1b}\) means that the complement \(I_{2b}{\setminus } I_{1b}\) is inhibited as part of the state T.

  2. 2.

    An uninhibited reaction, where the reactant and the product are the same graph, keeps this subgraph invariant. We use this terminology as a simplification inside definitions of reaction systems.

  3. 3.

    The notion of graph-based reaction systems is chosen in such a way that set-based reaction systems (where also uninhibited reactions are allowed) can be seen as the special case where the background graphs are discrete (one can forget then the empty set of edges and the set of edge labels, and the remaining set of vertices forms the background set of a set-based reaction system).

We are interested in dynamic processes associated with \({{\mathcal {A}}} \) which determine graph transformations specified by \({{\mathcal {A}}}\). Such processes are defined as follows.

Definition 4

Let \({{\mathcal {A}}} = (B, A)\) be a graph-based reaction system. An interactive process in \({{\mathcal {A}}} \) is an ordered pair \(\pi =(\gamma ,\delta )\) such that \(\gamma \), \(\delta \) are sequences of subgraphs of B, \(\gamma = C_0, \dots , C_n\) and \( \delta = D_0, \dots , D_n\) for some \(n \in \mathbb {N}_+\) where \(D_i = res_{{\mathcal {A}}}(C_{i-1} \cup D_{i-1})\) for \(i=1, \dots ,n\). The sequence \(\gamma \) is the context sequence, the sequence \(\delta \) is the result sequence, and the sequence \(\tau = T_0, \dots , T_n\) with \(T_i = C_i \cup D_i \) for \(i=0, \dots , n\) is the state sequence.

We denote by last the last state of the interactive process.

Remark 3

Since the successor state \(T'\) of a state T is the union of product graphs of all reactions enabled on T, a vertex or an edge of T is sustained, i.e., it is also present in \(T'\), only if it is produced by one of the enabled reactions. In this sense, each consecutive graph generated by an interactive process is a "new" graph.

4 Extended graph-based reaction systems

In this section, we define extended graph-based reaction systems. An extended graph-based reaction system is a graph-based reaction system accompanied with two sets of input and output states as well as a non-empty set of context sequences defining allowed computations. Semantically, an extended graph-based reaction system models a relation between input and output states. This provides a decision semantics on the input states in addition where an input state yields \( TRUE \) if there is a computation into an output state using one of the admitted context sequences, and \( FALSE \) otherwise. If there is a single admitted context sequence, then the semantics is a partial function from the set of input states into the set of output states. In general, the computation is nondeterministic. The concepts are illustrated by several examples.

Definition 5

  1. 1.

    An extended graph-based reaction system is a quintuple \(\mathcal {A} = (B, A, I, O, ctrl )\) where

    • (BA) is a graph-based reaction system,

    • \(I, O \subseteq sub(B)\) are sets of input and output states, resp, and

    • \( ctrl :I \rightarrow 2^{sub(B)^+}\) is a mapping assigning the admitted context sequences to each input.

  2. 2.

    The in-out-semantics of \(\mathcal {A}\) \( sem (\mathcal {A}) \subseteq I \times O\) defines a relation between input and output states in the following way: \((D,D') \in sem (\mathcal {A})\) if \(D \in I, D' \in O\) and \(D' = last(\pi (\gamma ,D)) \text { for some } \gamma \in ctrl (D)\). As a partial function \( sem (\mathcal {A}):I \rightarrow 2^O\) maps each input state \(D \in I\) into the set of output states \( sem (\mathcal {A})(D) = \{ D' \in O \mid D' = last(\pi (\gamma ,D)) \text { for some } \gamma \in ctrl (D) \}. \)

  3. 3.

    The decision semantics of \(\mathcal {A}\) \( dec (\mathcal {A}):I \rightarrow \mathbb {B}\) is defined by \( dec (\mathcal {A})(D) = TRUE \) if \( sem (\mathcal {A})(D) \ne \emptyset \) and \( FALSE \) otherwise.

To illustrate how the concepts of extended graph-based reaction systems work, some examples are presented.

Example 2

The following extended graph-based reaction system checks whether a loop-free simple undirected unlabeled graph with \(n \in \mathbb {N}_+\) vertices is Hamiltonian.

Problem definition: A graph G is Hamiltonian if it has a Hamiltonian cycle, i.e., if there is a permutation \(v_1... v_n\) of the n vertices such that \(\{v_i,v_{i+1}\} \in E_G\) for \(i=1,\ldots ,n\) where \(v_{n+1}=v_1\).

Extended graph-based reaction system: Let \(n \in \mathbb {N}_+\). Then

$$\begin{aligned} HAM _n= & {} (C_n^\tau , Ham_n, I( HAM )_n,\\{} & {} \Pi (Cycle_n^\tau ), (\Pi (Cycle_n^\tau ); \emptyset )) \end{aligned}$$

where

  • \(C_n^\tau \) is the complete graph \(C_n\) where each edge has a parallel \(\tau \)-edge,

  • \(Ham_n\) contains the reactions

    • [n] invariant

    • ( \(, (\emptyset , \emptyset ),\) ) for \(i,j \in [n], i\ne j\)

  • \(I( HAM )_n = \{ G \in \mathcal {G}^{lsu}_* \mid G \subseteq C_n, V_G = [n] \}\),

  • \(Cycle_n = ([n], \{(i,j) \in [n]^2 \mid |i-j| = 1 \text { or } \{ i,j\}= \{1,n\})\),

  • \(Cycle^\tau _n\) as \(Cycle_n\) with \(\tau \)-labeled edges,

  • \(\Pi \) is the set of all permutations of [n],

  • \(\pi (G) = ([n], \{(\pi (i), \pi (j)) \mid (i,j) \in E_G \})\) for \(G \in C_n\) and \(\pi \in \Pi \),

  • \(\Pi (G)=\{\pi (G) \mid \pi \in \Pi \}\).

Example interactive process: To see how this works, consider the following input graph of \( HAM _5\)

figure a

and the two admitted context sequences:

figure b

This yields the interactive processes

figure c

Correctness: \(G \in I( HAM )_n\) is Hamiltonian if and only if \( dec ( HAM _n)(G) = TRUE \).

Proof

The length of each admitted context sequence is 2 so that the semantically relevant interactive process have length 1. The start state is the union of an input graph G and a simple cycle C with \(\tau \)-edges that visits all vertices of G. The following processing step preserves all vertices using the first type of reactions and each \(\tau \)-edge that has a parallel edge using the second type of reactions. Therefore, C is computed as output state if G contains a parallel simple cycle meaning that G is Hamiltonian. Otherwise, some \(\tau \)-edges are removed so that no output state is reached. Altogether, \(dec( HAM _n)(G)= TRUE \) implies that G is Hamiltonian. Conversely, if G has a Hamiltonian cycle \(i_1 \ldots i_n\), then the counterpart C with \(\tau \)-edges followed by the empty graph is an admitted context sequence. Starting with \(C \cup G\), the computation yields C as all \(\tau \)-edges are accompanied by an unlabeled edge. This proves \(dec( HAM _n)(G)= TRUE \).

Example 3

The following extended graph-based reaction system checks whether a loop-free simple undirected unlabeled graph with \(n \in \mathbb {N}_+\) vertices has a k-clique for some k with \(1\le k \le n\), i.e., a set of k vertices such that each two of them are connected by an edge.

Problem definition: A k-clique of some graph G is a subset \(V \subseteq V_G\) with k elements such that \(\{v,v^{\prime }\} \in E_G\) for all \(v,v^{\prime } \in V\) with \(v\ne v^{\prime }\).

Extended graph-based reaction system: Let \(n,k \in \mathbb {N}_+\) with \(1 \le k \le n\). Then

$$\begin{aligned} CLIQUE _{n,k}= & {} (C_n^\Delta , Clique_n, I( CLIQUE )_n, \\{} & {} O( CLIQUE )_n, Choose_k) \end{aligned}$$

where

  • \(C_n^\Delta = ([n], [n]^2)\),

  • \(Clique_n\) contains the reactions

    • [n] invariant

    • () for \(i,j \in [n], i\ne j\)

  • \(I( CLIQUE )_n = \{ G \in \mathcal {G}^{lsu}_* \mid G \subseteq C_n, V_G = [n] \}\),

  • \(O( CLIQUE )_n = \{ ([n], \emptyset ) \}\), and

  • \(Choose_k = \{(\)

    figure d

    \(\cdots \)

    figure e

    \();\emptyset \mid 1\le i_1< \ldots < i_k \le n \}\)

Example interactive process: To see how this works, consider the sample graph \(\mathbb {G}\) of Example 2 as input of \( CLIQUE _{5,3}\) and the following two context sequences:

figure f

This yields the interactive processes

figure g

Correctness: \(G \in I( CLIQUE )_n\) has a k-clique if and only if \(dec( CLIQUE _{n,k})(G) = TRUE \).

Proof

The length of each context sequence in \(Choose_k\) is 2 so that the semantically relevant computations have length 1. The start state is a graph with the vertices \(1,\ldots ,n\) and k loops given by the chosen context sequence. The computation step preserves the vertices using the reactions of the first type. One gets the output state if no edge is produced, i.e., no reaction of the second type is enabled. In this case, none of two looped vertices are not connected by an edge. In other words, the looped vertices form a k-clique. Altogether, \(dec( CLIQUE _n,k)(G)= TRUE \) implies that G has a k-clique. Conversely, if G with k vertices has a k-clique \(\{i_1,\ldots , i_k\}\) then \(Choose_k\) contains the context sequence \(C=(\)

figure h

\(\cdots \)

figure i

\(; \emptyset )\). The computation step starting with \(C \cup G\) yields the output state as no reaction of the second type applies.

Example 4

The following extended graph-based reaction system checks whether a loop-free simple undirected unlabeled graph with \(n \in \mathbb {N}_+\) vertices has an independent set of size k for some k with \(1 \le k \le n\).

Problem definition: An independent set of some graph G is a subset \(V \subseteq V_G\) such that \(\{v,v^{\prime }\} \notin E_G\) for all \(v,v^{\prime } \in V\) with \(v\ne v^{\prime }\).

Extended graph-based reaction system: Let \(n,k \in \mathbb {N}_+\) with \(1 \le k \le n\). Then

$$\begin{aligned} INDEP _{n,k}= & {} (C^\Delta _n, Indep_n, I( INDEP )_n,\\{} & {} O( INDEP )_n, Choose_k) \end{aligned}$$

where

  • \(C^\Delta _n = ([n], [n]^2)\),

  • \(Indep_n\) contains the reactions

    • [n] invariant

    • () for \(i,j \in [n], i\ne j\)

  • \(I( INDEP )_n = I( CLIQUE )_n\) (see Example 3),

  • \(O( INDEP )_n = O( CLIQUE )_n\) (see Example 3), and

  • \(Choose_k\) as in Example 3.

Correctness: \(G \in I( INDEP )_{n}\) has an independent set with k elements if and only if \(dec( INDEP _{n,k})(G) = TRUE \).

Proof

The length of each context sequence in \(Choose_k\) is 2 so that the semantically relevant computations have length 1. The start state is a graph with the vertices \(1,\ldots ,n\) and k loops given by the chosen context sequence. The computation step preserves the vertices using the reactions of the first type. One gets the output state if no edge is produced, i.e., no reaction of the second type is enabled. In this case none of the two looped vertices are connected by an edge. Altogether, \(dec( INDEP _k)(G)= TRUE \) implies that G has an independent set with k elements. Conversely, if G with k vertices has a independent set \(\{i_1,\ldots , i_k\}\) then \(Choose_k\) contains the context sequence \(C=(\)

figure j

\(\cdots \)

figure k

\(; \emptyset )\). The computation step starting with \(C \cup G\) yields the output state as no reaction of the second type applies.

Example 5

The following extended graph-based reaction system computes the dual graph of each graph with n vertices.

Problem definition: The dual graph of some graph G has the same vertices as G but the edge set is complemented, i.e., \(dual(G) = ([n], \{(i,j) \mid (i,j) \notin E_G, i,j \in [n], i\ne j \})\).

Extended graph-based reaction system: Let \(n \in \mathbb {N}\). Then

$$\begin{aligned} DUAL _n = (C_n, Dual_n, I( DUAL _n), O( DUAL _n), \{(\emptyset , \emptyset ) \}) \end{aligned}$$

where

  • \(Dual_n\) contains the reactions

    • [n] invariant

    • (), \(i,j \in [n], i\ne j\)

  • \(I( DUAL _n) = O( DUAL _n) = \{ G \in \mathcal {G}_*^{lsu} \mid G \subseteq C_n, V_G = [n] \}\).

Example interactive process: To see how this works, consider the sample graph \(\mathbb {G}\) of Example 2 as input of \( DUAL _5\). Using the context sequence \(\emptyset ; \emptyset \), one gets the interactive process:

figure l

Correctness: \(sem( DUAL _n) = \{ (G, dual(G)) \mid G \in I(Dual_n) \}\).

Proof

The control condition requires single-step interactive processes on the input graphs. The vertices are preserved using the first kind of reactions, the edges are removed as there is no reaction to keep an edge, and one edge is added between two vertices wherever they are not connected in the input graph using the second type of reaction.

Remark 4

In all four examples, The length of admitted context sequences is 2 and the length of semantically relevant interactive processes is 1 therefore. We refer to the modeling of Turing machines in Sect. 8 for an example with longer admitted context sequences. The very short context sequences and interactive processes are due to the fact that the whole test samples (the cycles in case of \( HAM \) and the collections of vertices in the cases of \( CLIQUE \) and \( INDEP \)) can be used as contexts. If one would restrict the size of contexts, then longer sequences and processes would be forced.

5 Families of extended graph-based reaction systems

A decision problem on graphs can be defined as a mapping \(dec:\mathcal {I} \rightarrow \mathbb {B}\) of a set of graphs \(\mathcal {I}\) into the Boolean values. A typical example is the k-clique problem \(Clique_k\) for some \(k \ge 1\) that asks whether a loop-free simple undirected unlabeled graph contains a k-clique. Replacing the search for a k-clique by the search for an independent set with k elements such that no two of them are connected, defines the corresponding independent-set problem \(Indep_k\). Another well-known example is the Hamiltonian-cycle problem Ham that asks whether a loop-free simple undirected unlabeled graph contains a cycle that visits every vertex exactly once.

As an extended graph-based reaction system \(\mathcal {A} = (B,A,I,O, ctrl )\) is equipped with the decision semantics \(dec(\mathcal {A}):I \rightarrow \mathbb {B}\), it can be seen as the solution of a decision problem. But the set of input graphs is always finite in contrast to most decision problems one encounters in the literature like \(Clique_k\) and Ham. The situation is similar with respect to relations and functions on graphs. The in-out-semantics of an extended graph-based reaction system is a finite relation. Such a system fails if one wants to compute functions and relations as usual like the graph dualization \(dual:\mathcal {G}_*^{lsu} \rightarrow \mathcal {G}_*^{lsu}\) given by \(dual(G) = (V_G, \{ \{v,v'\} \mid \{v,v' \} \notin E_G, v,v' \in V_G, v\ne v' \}\). To overcome these discrepancies, one can consider families of extended graph-based reaction systems.

Definition 6

Let X be a set of indices. Let \(\mathcal {F} = (\mathcal {A}_x)_{x \in X}\) be a family of extended graph-based reaction systems \(\mathcal {A}_x = (B_x, A_x, I_x, O_x, ctrl _x)\) for \(x \in X\). Let \(\mathcal {I}(\mathcal {F}) = \bigcup _{x \in X} I_x\) and \(\mathcal {O}(\mathcal {F}) = \bigcup _{x \in X} O_x\).

  1. 1.

    Then \(\mathcal {F}\) has an in-out-semantics \(sem(\mathcal {F}) \subset \mathcal {I}(\mathcal {F}) \times \mathcal {O}(\mathcal {F})\) defined by \(sem(\mathcal {F}) = \bigcup _{x \in X} sem(\mathcal {A}_x)\).

  2. 2.

    \(\mathcal {F}\) has a decision semantics \(dec(\mathcal {F}):\mathcal {I}(\mathcal {F}) \rightarrow \mathbb {B}\) defined, for \(G \in \mathcal {I}(\mathcal {F})\), by

    • \(dec(\mathcal {F})(G) = TRUE \) if \((G,H) \in sem(\mathcal {F})\) for some \(H \in \mathcal {O}(\mathcal {F})\),

    • \(dec(\mathcal {F})(G) = FALSE \) otherwise.

Example 6

Consider the family \( HAM = \{ HAM _{n} \}_{n \in \mathbb {N}}\). Let \(G \in I_n\) for some \(n \in \mathbb {N}\). Then G has n vertices and \(G \subseteq C_n\) such that G is loop-free, simple, undirected and unlabeled. Therefore \(\bigcup _{n \in \mathbb {N}} I_n \subseteq \mathcal {G}_*^{lsu}\). Moreover, due to Example 2, \(dec( HAM )(G) = dec( HAM _n)(G) = TRUE \) if and only if G has a Hamiltonian cycle meaning that \(Ham(G) = TRUE \). Conversely, let \(G \in \mathcal {G}_*^{lsu}\) be a graph with n vertices. Then \(G \subseteq C_n\) up to isomorphism. Moreover, \(Ham(G) = TRUE \) means that \(dec( HAM )(G) = dec( HAM _n)(G) = TRUE \). Altogether, one gets \(dec( HAM ) = Ham\) such that the family of extended graph-based reaction systems \( HAM \) solves the Hamiltonian-cycle problem Ham.

Using the same arguments, one gets \(dec(CLIQUE_k)=Clique_k\) and \(dec(INDEP_k)=Indep_k\) for the two families \(CLIQUE_k=\{CLIQUE_{n,k}\}_{n \ge k}\) and \(INDEP_k=\{INDEP_{n,k}\}_{n \ge k}\).

Theorem 1

Let \(\mathcal {F} = (\mathcal {A}_x)_{x \in X}\) be a family of extended graph-based reaction systems subject to the following conditions:

  1. 1.

    The membership problems of \(\mathcal {I}(\mathcal {F})\) and \(O_x\) for each \(x \in X\) are decidable.

  2. 2.

    For each \(G \in \mathcal {I}(\mathcal {F})\), the occurrence set \(occ(G)=\{x \in X \mid G \in I_x\}\) is recursively enumerable.

  3. 3.

    For each \(x \in X\) and \(G \in I_x, ctrl _x(G)\) is recursively enumerable.

If \(\mathcal {F}\) satisfies these condition, then \(sem(\mathcal {F})\) and \(dec(\mathcal {F})\) are computable.

Proof

Let \(G \in \mathcal {G}_\Sigma \). If \(G \notin \mathcal {I}\), then G is neither in the domain of sem nor in the domain of dec. If \(G \in \mathcal {I}\), then one can enumerate occ(G), and, for each enumerated \(x \in occ(G)\), one can enumerate \( ctrl _x(G)\). For each enumerated \(\gamma \) the interactive process \(\pi (G,\gamma )\) can be executed and checked whether the last reached state H is in \(O_x\). In this case, one gets \((G,H) \in sem(\mathcal {F})\) and \(dec(\mathcal {F})(G)= TRUE \). \(\square \)

6 Modeling NP-problems

The complexity class NP of decision problems that can be solved nondeterministically in polynomial time is of great theoretical and practical importance. One of the key question is whether NP coincides with the class P of problems that are solvable deterministically in polynomial time. A key concept is the notion of reductions between NP-problems. The examples \(Clique_k\), \(Indep_k\), and Ham demonstrate that families of extended graph-based reaction systems can be employed to model NP-problems and reductions between them. But one can do much better. We can identify two classes of such families such that the decision semantics of the first one is in NP and the in-out-semantics of the second one are polynomial functions that can be used to model reductions. The latter is discussed in the following section.

Definition 7

Let \(\mathcal {F} = (\mathcal {A}_x)_{x \in X}\) be a family of extended graph-based reaction systems. Then \(\mathcal {F}\) is polynomial if the following hold:

  1. 1.

    The membership problem of \(\mathcal {I}(\mathcal {F})\) can be checked in polynomial time.

  2. 2.

    For each \(G \in \mathcal {I}(\mathcal {F})\), occ(G) is computed in polynomial time.

  3. 3.

    For each \(x \in X\) and \(G \in I_x\) the set of \( ctrl _x(G)\) is computed in exponential time, and each context sequence in \( ctrl _x(G)\) is computed in polynomial time.

  4. 4.

    For each \(x \in X\) and \(G \in I_x\), the number of reactions in \(A_x\) is polynomial in |G|.

  5. 5.

    The membership problem of \(O_x\) for each \(x \in X\) can be checked in polynomial time.

Theorem 2

Let \(\mathcal {F}\) be a polynomial family of extended graph-based reaction systems. Then \(dec(\mathcal {F}) \in NP\).

Proof

Let \(\mathcal {F} = (\mathcal {A}_x)_{x \in X}\) with \(\mathcal {A}_x = (B_x, A_x, I_x, O_x, ctrl _x)\). Let \(G \in \mathcal {I}(\mathcal {F})\) which can be checked in polynomial time by assumption 1. Then (1) compute occ(G) and (2) choose, for some \(x \in occ(G)\), some \(\gamma \in ctrl _x(G)\). Next, (3) execute \(\pi (G,\gamma )\), and (4) check \(H \in O_x\) for the resulting last state H.

(1) is polynomial by assumption 2. In particular, the number of elements of occ(G) is polynomially bounded. (2) is polynomial by assumption 3 for each x. In particular, each chosen context sequence has polynomial length. (3) is polynomial for each context sequence \(\gamma \in ctrl _x(G)\) as \(\gamma \) has polynomial length and in each step only a polynomial number of reactions are enabled by assumption 4. (4) is polynomial by assumption 5, and \(dec(\mathcal {F})(G) = TRUE \) if the last state is an output. Altogether, the computation is polynomial for each choice of context sequences. As the number of choices is exponential, \(dec(\mathcal {F}) \in NP\). \(\square \)

Example 7

The three sample families \( HAM \), \( CLIQUE _k\) and \( INDEP _k\) are polynomial. A graph is an input if it is unlabeled, undirected, loop-free and simple. The four properties can be checked by inspecting each edge once. The occurrence set of an input is a singleton set with the number of vertices as element. its computation takes linear time. The admitted context sequences in HAM are essentially the simple cycles of length n for each input with n vertices. Each of these exponentially many cycles is computed in linear time. The admitted context sequences consist essentially of a choice of k vertices out of n. There may be exponentially many choices, but each single one needs linear time at most. The number of reactions of each involved reaction system is bounded by the number of vertices plus the square number of vertices. Finally, one must check whether the last graph of an interactive process is a cycle in the case of \( HAM \) or the discrete graph in the other two cases all taking linear time.

7 Reduction

In this section, we propose a notion of reductions between polynomial families of extended graph-based reaction systems that models reactions between the NP-problems specified by the given families. Given two decision problems \(dec:\mathcal {I} \rightarrow \mathbb {B}\) and \( dec ':\mathcal {I}' \rightarrow \mathbb {B}\), a function \(red:\mathcal {I} \rightarrow \mathcal {I}'\) is a reduction from dec to \(dec'\) if the following correctness condition holds: \(dec(G) = TRUE \) if and only if \(dec'(red(G)) = TRUE \) for all \(G \in \mathcal {I}\). If \(dec, dec' \in \) NP, then one requires in addition that red can be computed in polynomial time. To carry this concept over into our framework, we provide sufficient conditions such that the in-out-semantics of a family of extended graph-based reaction systems is a function computed in polynomial time. And then we use this notion of P-functional families to define reductions on the level of polynomial families.

Definition 8

Let \(\mathcal {F} = (\mathcal {A}_x)_{x \in X}\) be a family of extended graph-based reaction systems with \(\mathcal {A}_x = (B_x, A_x, I_x, O_x, ctrl _x)\). Then \(\mathcal {F}\) is functional if, for each \(G \in \mathcal {I}(\mathcal {F})\), the following hold:

  1. 1.

    occ(G) is a singleton set the element of which is denoted by occ(G).

  2. 2.

    \( ctrl _{occ(G)}(G)\) is a singleton set the element of which is denoted by \(\gamma _G\).

  3. 3.

    \(last(\pi (G,\gamma _G)) \in O_{occ(G)}\).

\(\mathcal {F}\) is P-functional, if, in addition,

  1. 4.

    \(\gamma _G\) is a context sequence of polynomial length, and

  2. 5.

    The size of all reactants and inhibitors of \(A_{occ(G)}\) is bounded by a constant.

Theorem 3

Let \(\mathcal {F} = (\mathcal {A}_x)_{x \in X}\) be a family of extended graph-based reaction systems.

  1. 1.

    If \(\mathcal {F}\) is functional, then \(sem(\mathcal {F})\) is a function from \(\mathcal {I}(\mathcal {F})\) to \(\mathcal {O}(\mathcal {F})\).

  2. 2.

    If \(\mathcal {F}\) is P-functional, then \(sem(\mathcal {F})\) can be computed in polynomial time.

Proof

  1. 1.

    According to the conditions 1 and 2, there is only one extended graph-based reaction system in \(\mathcal {F}\) for each \(G \in \mathcal {I}(\mathcal {F})\) and a single admitted context sequence. This means that only one interactive process must be executed which is a deterministic procedure. The last reached state is an output according to the third condition. Altogether, \(sem(\mathcal {F})\) is a function as stated.

  2. 2.

    According to condition 4, the executed interactive process has polynomial length. Using condition 5, there are a polynomial number of reactions as the number of subgraphs of the background graph is polynomially bounded if the size of the subgraphs is constantly bounded and to check their enabledness takes polynomial time. \(\square \)

Definition 9

Let \(\mathcal {D}=\{\mathcal {D}_x\}_{x \in X}\) and \(\mathcal {D}'=\{\mathcal {D}'_z\}_{z \in Z}\) be two polynomial families of extended graph-based reaction systems and \(\mathcal {R}=\{\mathcal {R}_y\}_{y \in Y}\) be a P-functional family of extended graph-based reaction systems. Then \(\mathcal {R}\) is a reduction of \(\mathcal {D}\) to \(\mathcal {D}'\) if the following conditions hold:

  1. 1.

    \(\mathcal {I}(\mathcal {D})=\mathcal {I}(\mathcal {R})\).

  2. 2.

    For each \(G \in \mathcal {I}(\mathcal {D})\), \(sem(\mathcal {R})(G) \in \mathcal {I}(\mathcal {D}')\).

  3. 3.

    \(dec(\mathcal {D})(G) = TRUE \) if and only if \(dec'(\mathcal {D}')(sem(\mathcal {R})(G)) = TRUE \).

Theorem 4

Let \(\mathcal {R}=\{\mathcal {R}_y\}_{y \in Y}\) be a reduction of \(\mathcal {D}=\{\mathcal {D}_x\}_{x \in X}\) to \(\mathcal {D}'=\{\mathcal {D}'_z\}_{z \in Z}\). Then \(sem(\mathcal {R})\) provides a reduction of the NP-problem \(dec(\mathcal {D})\) to the NP-problem \(dec(\mathcal {D}')\).

Proof

According to condition 1 of the definition of reductions between polynomial families, the inputs of \(sem(\mathcal {R})\) coincide with inputs of \(\mathcal {D}\). According to condition 2, the output of \(sem(\mathcal {R})\) is in \(\mathcal {I}(\mathcal {D}')\). Both together means that \(sem(\mathcal {R})\) can be seen as a polynomial function from \(\mathcal {I}(\mathcal {D})\) to \(\mathcal {I}(\mathcal {D}')\). Then condition 3 states that this function is a reduction of \(dec(\mathcal {D})\) to \(dec(\mathcal {D}')\). \(\square \)

Example 8

Consider the family \( DUAL (k)=\{DUAL_n\}_{n \ge k}\) for some \(k\in \mathbb {N}\). Then dec(DUAL(k)) is P-functional as, for \(G \in \mathcal {I}( DUAL (k)) = \bigcup _{n\in \mathbb {N}} I( DUAL _n)\), the following hold:

  1. 1.

    \(occ(G)=|V_G|\),

  2. 2.

    \( ctrl _{occ(G)}(G)=\{(\emptyset ,\emptyset )\}\),

  3. 3.

    \(last(\pi (G,\{(\emptyset ,\emptyset )\} )) = dual(G) \subseteq C_n\) according to the correctness of \( DUAL _n\) shown in Example 5.

  4. 4.

    \(\{(\emptyset ,\emptyset )\}\) has constant length, and

  5. 5.

    The size of reactant graphs and inhibitors is bounded by 2 vertices and 3 edges.

Moreover, \( DUAL (k)\) defines a reduction of \( CLIQUE _k\) to \( INDEP _k\) because, according to the definitions in Examples 3, 4 and 5,

  1. 1.

    One has \(I( CLIQUE )_n=I( DUAL )_n\) and hence \(\mathcal {I}( CLIQUE _k)=\mathcal {I}( DUAL (k))\) being the unions over all \(n \ge k\),

  2. 2.

    If \(G\in I( CLIQUE )_n\) for some n, then G, \(dual(G) \subseteq C_n\) and \(V_G=V_{dual(G)}=[n]\) such that \(dual(G) \in I( INDEP )_n\), and

  3. 3.

    Using the correctness results in Examples 3, 4 and 5, \(dec( CLIQUE _k)(G) = TRUE \) if there are vertices \(v_{i_1},\ldots , v_{i_k}\) such that each two are connected by an edge. This means that these vertices are totally disconnected in dual(G) such that \(dec( INDEP _k)(dual(G))=dec( INDEP _k)( DUAL (k)(G))= TRUE \) and conversely.

8 Modeling Turing machines

In this section, we model Turing machines by families of extended graph-based reaction systems. Hence, families of extended graph-based reaction systems are an universal computing model. Furthermore, the whole complexity class NP is covered.

Before we discuss our model transformation, we shortly recall the notion of Turing machines (see, e.g., Turing 1936) and their recognized languages. We consider Turing machines with a designated start and accept state and one two-sided infinitely extendable (working) tape. If the empty string is left of the head and the head should move to the left, then a new cell labeled \(\square \) (the blank symbol) is added. Analogously, to the right. Formally, we define Turing machines as follows.

Definition 10

  1. 1.

    A Turing machine is a system \( TM = (Q,\Omega , \Gamma , \Delta )\), where Q is a finite set of states with two designated states \(q_{start}\) and \(q_{accept}\), \(\Omega \) is the input alphabet, \(\Gamma \) is the tape alphabet with \(\Omega \subseteq \Gamma \) and \(\square \in \Gamma {\setminus } \Omega \), and \(\Delta \subseteq (Q{\setminus } \{q_{accept}\}) \times \Gamma \times \Gamma \times \{l,n,r\} \times Q\) is the transition relation.

  2. 2.

    \( conf ( TM ) = Q \times \Gamma ^* \times \Gamma ^*\) is the set of configurations.

  3. 3.

    A step of \( TM \) is defined by the relation \(\vdash _{ TM } \subseteq conf ( TM ) \times conf ( TM )\):

    $$\begin{aligned} (p, \alpha u, x \beta )&\vdash _{ TM } (q, \alpha , u y \beta )&\text {if }&(p,x,y,l,q) \in \Delta \\ (p, \varepsilon , x \beta )&\vdash _{ TM } (q, \varepsilon , \square y \beta )&\text {if }&(p,x,y,l,q) \in \Delta \\ (p, \alpha , \varepsilon )&\vdash _{ TM } (q, \alpha , y)&\text {if }&(p,\square ,y,l,q) \in \Delta \\ (p, \alpha , x \beta )&\vdash _{ TM } (q, \alpha , y \beta )&\text {if }&(p,x,y,n,q) \in \Delta \\ (p, \alpha , x \beta )&\vdash _{ TM } (q, \alpha y, \beta )&\text {if }&(p,x,y,r,q) \in \Delta \\ (p, \alpha , \varepsilon )&\vdash _{ TM } (q, \alpha y, \varepsilon )&\text {if }&(p,\square ,y,r,q) \in \Delta \end{aligned}$$

    where \(\alpha , \beta \in \Gamma ^*, u \in \Gamma \) and \(\varepsilon \) is the empty string.

  4. 4.

    A computation of \( TM \) is a potentially infinite sequence of configurations \(c_0,c_1,\ldots \) where \(c_0 = (q_{start}, \varepsilon , w)\) is the start configuration wrt the input \(w \in \Omega ^*\), and \(c_i \vdash _{ TM } c_{i+1}\) for all \(i \in \mathbb {N}\).

  5. 5.

    The recognized language of \( TM \) is defined as \(L( TM ) = \{ w \in \Omega ^* \mid (q_{start}, \varepsilon , w) \vdash _{ TM }^* (q_{accept},\alpha ,\beta ) \},\) where \(\alpha ,\beta \in \Gamma ^*\) are arbitrary.

Remark 5

  1. 1.

    \((p,x,y,dir,q) \in \Delta \) means if the Turing machine is in state p and reads the symbol x, it can replace x by y and move the (read/write) head to the left if \(dir=l\), to the right if \(dir=r\) or leave the head stationary if \(dir=n\). Afterwards the machine is in state q.

  2. 2.

    A configuration is of the form \((q, \alpha , \beta )\) which means the machine is in state q and the contents of the tape to the left and right of the head are \(\alpha \) and \(\beta \), respectively. The machine reads the first symbol of \(\beta \) if \(\beta \ne \varepsilon \) and \(\square \) otherwise.

  3. 3.

    A computation is finite if a halting configuration is reached, i.e., if there is no possibility of continuing the computation. If the machine enters the state \(q_{accept}\), then it accepts the input.

  4. 4.

    The recognized language consists of all strings for which a computation exists such that the machine enters the accepting state \(q_{accept}\).

Turing machines can be simulated by families of extended graph-based reaction systems and their interactive processes. The construction works roughly as follows:

  1. 1.

    A Turing machine \( TM = (Q,\Omega , \Gamma , \Delta )\) is represented by the usual state graph, denoted by \(gr( TM )\). Vertices are the states \(Q \cup \{ q_{reject}\}\), where \(q_{reject}\) is an additional state we introduce for technical reasons, and the edges are the transitions in the transition relation \(\Delta \), where the set \(\Gamma \times \Gamma \times \{l,n,r\}\) is used for edge labels.

  2. 2.

    The tape is represented by a string graph, i.e., a sequence of successive edges, each labeled with symbols of the working alphabet \(\Gamma \).

  3. 3.

    The state graph and the tape are connected by an edge, called head, which indicates the current state (the current state is the source) and is attached to the current position on the tape (the target of the head-edge is the vertex in front of the edge in the tape representing the current symbol to modify).

  4. 4.

    As reaction systems are finite, we model each Turing machine \( TM \) by a family of corresponding extended graph-based reaction systems \(\mathcal {F}( TM )\), where the tape length varies. This means the tape length for each member of the family is fixed and contains \(\square \) symbols to the left and right up to the limit. Formally, the tape graph is defined as follows: Let \(i,n \in \mathbb {N}\) with \(1 \le i \le 2n-1\). i is the index of the vertex being the target of the head-edge. Let \(\alpha , \beta \in \Gamma ^*\) be some strings on the tape to the left and to the right of i. Let \(|\alpha | = k_\alpha \) and \(|\beta | = k_\beta \) with \(k_\alpha \le i\) and \(k_\beta \le 2n-i\). Then the tape graph \( tg (\alpha ,\beta ,i)_n\) is the string graph \( sg (\vartriangleright \cdot \square ^{i - k_\alpha } \cdot \alpha \cdot \beta \cdot \square ^{2n - i - k_\beta } \cdot \vartriangleleft )\). We use two delimiters \(\vartriangleright \) and \(\vartriangleleft \) to indicate the end of the tape to the left and to the right, respectively. Each tape graph \( tg (\alpha ,\beta ,i)_n\) is a subgraph of the graph \( tg _n\) consting of \(2n+1\) vertices and \((2n-1)\cdot |\Gamma | + 2\) edges representing all possible tape contents for tapes with parameter n.

  5. 5.

    The background graph is the union of \(gr( TM ), tg _n\) and \(heads( TM ,n)\), where \(heads( TM ,n)\) connects \(gr( TM )\) and \( tg _n\) by all possible head edges.

  6. 6.

    The \(\vdash _{ TM }\)-relation is modified as follows:

    $$\begin{aligned} (p, \alpha u, x \beta )&\vdash _{ TM } (q, \alpha , u y \beta )&\text {if }&(p,x,y,l,q) \in \Delta \\ (p, \vartriangleright , x \beta )&\vdash _{ TM } (q_{reject}, \vartriangleright , x \beta )&\text {if }&(p,x,y,l,q) \in \Delta \\ (p, \alpha , \vartriangleleft )&\vdash _{ TM } (q_{reject}, \alpha , \vartriangleleft )&\text {if }&(p,\square ,y,l,q) \in \Delta \\ (p, \alpha , x \beta )&\vdash _{ TM } (q, \alpha , y \beta )&\text {if }&(p,x,y,n,q) \in \Delta \\ (p, \alpha , x \beta )&\vdash _{ TM } (q, \alpha y, \beta )&\text {if }&(p,x,y,r,q) \in \Delta \\ (p, \alpha , \vartriangleleft )&\vdash _{ TM } (q_{reject}, \alpha , \vartriangleleft )&\text {if }&(p,\square ,y,r,q) \in \Delta \end{aligned}$$

    where \(\alpha , \beta \in \Gamma ^*\) and \(u \in \Gamma \). This means, if the Turing machine moves beyond one of the delimiters or wants to overwrite this symbol, it results in the state \(q_{reject}\), indicating that the computation has failed. There is no possibility to continue.

  7. 7.

    The sets of input and output states consist of graphs representing start and accepting configurations, respectively.

  8. 8.

    The computation steps are simulated by corresponding reactions enabled by the context sequence of the interactive process.

Definition 11

Let \( TM = (Q,\Omega , \Gamma , \Delta )\) be a Turing machine. Then \(\mathcal {F}( TM ) = (\mathcal {A}( TM )_n)_{n \in \mathbb {N}}\) is the corresponding family of extended graph-based reaction systems, where \(\mathcal {A}( TM )_n = (B( TM )_n, A( TM )_n, I( TM )_n, O( TM )_n, ctrl ( TM ))\) is defined as follows.

  • \(B( TM )_n = gr( TM ) \cup tg _n \cup heads( TM ,n)\), where

    • \(gr( TM ) = (Q \cup \{q_{reject} \}, \Delta , s_\Delta , t_\Delta , l_\Delta )\) where \(s_\Delta (e) = p, t_\Delta (e) = q, l_\Delta (e) = x/y/dir\) for \((p,x,y,dir,q) \in Delta\) and \(q_{reject} \notin Q\).

    • \( tg _n = ( V_{ tg _n}, E_{ tg _n}, s_{ tg _n},t_{ tg _n},l_{ tg _n})\), where \(V_{ tg _n} = \{v_{0},\ldots , v_{2n}\}, E_{ tg _n} = \{e_0, e_{1,0},\ldots ,e_{1,|\Gamma |-1},\ldots , e_{2n-1,0},\ldots ,e_{2n-1,|\Gamma |-1},e_{2n} \}\), \(s_{ tg _n}(e_0) = v_{0}, t_{ tg _n}(e_0) = v_{1}, l_{ tg _n}(e_0) = \vartriangleright \), \(s_{ tg _n}(e_{2n}) = v_{2n-1}, t_{ tg _n}(e_{2n}) = v_{2n}, l_{ tg _n}(e_{2n)} = \vartriangleleft \), and \(s_{ tg _n}(e_{i,j}) = v_{i}, t_{ tg _n}(e_{i,j}) = v_{i+1}, l_{ tg _n}(e_{i,j}) = \Gamma _j\), where \(\Gamma _j\) is the j-th symbol in \(\Gamma \).

    • \(heads( TM ,n) = (V_{gr( TM )} \times V_{ tg _n} {\setminus } \{ v_0, v_{2n} \}, V_{gr( TM )} \times V_{ tg _n} {\setminus } \{ v_0, v_{2n} \}, s_{heads( TM ,n)},t_{heads( TM ,n)},l_{heads( TM ,n)})\) with \(s((i,j)) = i, t((i,j)) = j\) and \(l((i,j)) = head\) for each \((i,j) \in V_{gr( TM )} \times V_{ tg _n} {\setminus } \{ v_0, v_{2n} \}\).

  • \(A(TM)_n\) contains the following sets of reactions.

    • \(V_{gr( TM )}\) is invariant.

    • Let i be the current index and let \(e_i\) be the edge with \(s_{ tg _n}(e_i) = i\). The tape except the edge e is invariant.

    • The transitions are realized by the reactions in Table 1, where \(i = 2,\ldots ,2n-2, u \in \Gamma \) and \((p,x,y,dir,q) \in \Delta \).

  • Let \(n \in \mathbb {N}\) and \(c = (p,\alpha ,\beta ) \in conf ( TM )\). Then \(gr(c,i)_{i \in [2n-1]}\) is the family of graphs each consisting of the vertex set Q, the tape graph \(tg(\alpha ,\beta ,i)_n\) as well as a head-edge connecting p with \(v_i\), wherever \(tg(\alpha ,\beta ,i)_n\) is defined.

    • \(I( TM )_n = \{ gr((q_{start}, \varepsilon , w),i) \mid w \in \Sigma ^*, |w| \le n, i \in [2n-1] \}\) and

    • \(O( TM )_n = \{ gr(c,i) \mid c \in conf ( TM ), pr_1(c) = q_{accept}, i \in [2n-1]\}\).

  • \( ctrl ( TM ) = gr(\Delta )^*\), where \(gr(\Delta ) = \{ gr(\delta ) \mid \delta \in \Delta \}\) and \(gr(\delta ) = (\{p,q\}, \{e\}, e \mapsto p, e\mapsto q, e \mapsto x/y/dir)\) for \(\delta = (p,x,y,dir,q) \in \Delta \).

Table 1 Reactions modeling Turing machine transitions wrt to the modified transition relation

Remark 6

  1. 1.

    \(sem(\mathcal {A}( TM )_n)\) maps each start configuration into the set of accepting configurations. Therefore, \(dec(\mathcal {A}( TM )_n)(gr((q_{start}, \varepsilon , w),i)) = TRUE \) if there exists gr(cj) such that \((gr((q_{start}, \varepsilon , w),i), gr(c,j)) \in sem(\mathcal {A}( TM )_n)\).

  2. 2.

    We say \(dec(\mathcal {F}( TM ))(gr(q_{start}, \varepsilon , w)) = TRUE \) if there exists an \(i,n \in \mathbb {N}\) such that \(dec(\mathcal {A}( TM )_n)(gr((q_{start}, \varepsilon , w),i)) = TRUE \).

Theorem 5

\(w \in L( TM )\) if and only if \(dec(\mathcal {F}( TM )(gr(q_{start}, \varepsilon , w))) = TRUE \).

Proof

Let \(w \in L( TM )\). Then there exists a run \((q_{start}, \varepsilon , w) \vdash _{ TM }^* (q_{accept},\alpha ,\beta )\). Let m be the length of the accepting run and let \(\delta _1,\ldots ,\delta _m\) be the applied transitions. Let \(usageL:conf( TM ) \rightarrow \mathbb {N}\) and \(usageR:conf( TM ) \rightarrow \mathbb {N}\) be two functions defined by \(usageL(q,x,y) = |x|\) and \(usageR(q,x,y) = |y|\), where x contains no blank to the left and y contains no blank to the right. Let max be a function calculating the maximum of a non-empty set of integers. Let \(k_{max} = max(\bigcup _{i=0}^n max( \{ usageL(c_i), usageR(c_i) \}))\). Then the extended graph-based reaction system \(\mathcal {A}(TM)_{k_{max}}\) has sufficient tape capacity to simulate the run. Moreover, \(k_{max}\) can be choosen as suitable index. The run is simulated by the context sequence \(gr(\delta _1),\ldots , gr(\delta _m)\). Hence, \(dec(\mathcal {A}( TM )_{k_{max}}(gr(q_{start}, \varepsilon , w),{k_{max}})) = TRUE \). Consequently, \(dec(\mathcal {F}( TM )(gr(q_{start}, \varepsilon , w))) = TRUE \).

Conversely, let \(dec(\mathcal {F}( TM )(gr(q_{start}, \varepsilon , w))) = TRUE \). Then there exist some \(n,i \in \mathbb {N}\) such that \(dec(\mathcal {A}(TM)_{n})(gr((q_{start}, \varepsilon , w),i)) = TRUE \). Let \(\pi \) be a successful interactive process. Then, due to the control condition, this must be of the form \(gr(\delta _1),\ldots , gr(\delta _m)\). The sequence \(\delta _1,\ldots , \delta _m\) is the accepting sequence of transitions in the Turing machine provided that w is given as input. Therefore, \(w \in L( TM )\). \(\square \)

A usual characterization of NP is deciding membership with a nondeterministic Turing machine whose computation length is polynomially bounded. One can show that the corresponding family of extended graph-based reaction systems \({{\mathcal {F}}}(TM)\) is polynomial in the sense of Definition 7.

Theorem 6

Let \( TM \) be a Turing machine whose computation length is polynomially bounded. Then \(\mathcal {F}( TM )\) is polynomial.

Proof

  1. 1.

    Membership of \(\mathcal {I}(\mathcal {F}( TM ))\) is polynomial, because for each given graph G it can be checked in polynomial time if it is of the form \(gr((q_{start}, \varepsilon , w),i)\) for some \(i \in \mathbb {N}\). This is done as follows. First, it can be checked in polynomial time if G contains \(gr( TM )\) by enumerating all vertices and edges of \(gr( TM )\). Then, in linear time it can be checked if \(E_G\) contains some edge labeled head connecting \(q_{start}\) with some vertex. Afterwards, due to the linearity of the structure, one can check in polynomial time if the remaining edges form a proper tape graph.

  2. 2.

    For each \(G \in \mathcal {I}(\mathcal {F}( TM ))\), occ(G) is computed in polynomial time, because the index can be derived from the length of the tape graph.

  3. 3.

    Let n be the computation length of \( TM \). If the out-degree of each state of the Turing machine is greater or equal to 2, then the number of path choices is lower bounded by \(2^{n}\). It is upper bounded by \(\Delta ^{n}\), which is exponential if \(|\Delta | \ge 2\). As each context contains just one edge and its source and target vertex/vertices, each context sequence in \( ctrl (G)\) can be computed in polynomial time.

  4. 4.

    For each \(n \in \mathbb {N}\) and \(G \in \mathcal {I}(\mathcal {F}( TM ))\) the number of reactions in \(A( TM )_n\) is linear in |G|, as this size only impacts the number of reactions of the second type, which is linear in the tape size. The remaining reactions are linear in the size of \( TM \).

  5. 5.

    Using the same argument as in 1, membership of \(O( TM )_n\) can be checked in polynomial time for each \(n \in \mathbb {N}\).

\(\square \)

9 Solving NP-problems by massive parallelism

Solving NP-hard problems efficiently is a great open problem of computer science. In this section, we discuss how the parallelism of reactions can be used to compute possible solutions in parallel. We define a reaction system and an interactive process for the NP-complete problem \(3 SAT \) and show that the interactive process computes all satisfying assignments. The computation length is polynomial, but the parallelism is exponential.

The basic idea is the following.

  1. 1.

    For each propositional formula there is a corresponding extended graph-based reaction system. We assume that the propositional formula is in conjunctive normal form, i.e., a conjunction of clauses, where each clause consists of the disjunction of three literals (truth variables or their negation).

  2. 2.

    We have four copies of a base set X of literals, namely \(X,\overline{X}, CX, C\overline{X}\), where X represents the positive literals, \(\overline{X}\) represents the negative literals, \(CX, C\overline{X}\) analogously, but indicate variables used in clauses.

    Because a finite family of subsets of a finite set is a hypergraph, a hypergraph-based reaction system, which is a straightforward generalization of a graph-based reaction system, is reasonable. The union of the sets \(X,\overline{X}, CX, C\overline{X}\) is the vertex set of the background hypergraph. The hyperedges are all non-empty subsets of \(2^{X \cup \overline{X}}\). As these are all different, the hypergraph is simple. Moreover, as every hyperedge contains the information to which vertices it is connected to and, furthermore, no labeling is needed, a hypergraph can be represented by the pair (VE). For technical reasons, we use the framework of extended graph-based reaction systems, i.e., each hyperedge is represented by a vertex and its attachment vertices are connected to this vertex by edges. But we make use of the hypergraph description.

  3. 3.

    The background and the reactions only depend on the set of truth variables over which the propositional formula is defined but not on the formula itself. The formula is only used in the interactive process, where the first clause is used in the start hypergraph and the remaining clauses are successively provided as context. More specifically, the interactive process corresponding to \(\phi \) is defined by the start hypergraph \((X_n \cup \overline{X}_n, 2^{\tilde{\varphi _1}}{\setminus } \emptyset )\) where \(\tilde{\varphi }_1 = \{ y_{11}, y_{12}, y_{13} \}\) are the literals of the first clause and the context sequence \(c_2,\ldots ,c_m\) is constructed from the remaining clauses \(\varphi _2,\ldots ,\varphi _m\) in such a way that \(c_i\) is the discrete hypergraph consisting of the vertices \(cy_1,cy_2,cy_3\) where \(y_1,y_2,y_3\) are the literals of \(\tilde{\varphi }_i\). Hence, the interactive process uses in each step one clause in order to compute the set of subsets of \(X \cup \overline{X}\) satisfying the provided clauses up to this point. The inhibitor checks for conflicting assignments. Consequently, only hyperedges representing subsets without conflicting assignments are produced.

Definition 12

Let \(\phi = \bigwedge _{i=1}^m \varphi _m\) be a propositional formula over n variables in conjunctive normal form. Let \(X_n = \{x_1, \ldots , x_n \}\) be the set of positive literals and \(\overline{X}_n = \{\overline{x}_1,\ldots ,\overline{x}_n\}\) the set of n corresponding negative literals. Both sets have a copy, \(CX_n = \{cx_1,\ldots ,cx_n\}\) and \(C\overline{X}_n = \{c\overline{x}_1,\ldots ,c\overline{x}_n\}\), respectively, which are used to indicate variables used in clauses. Moreover, let \(K \subseteq 2^{X_n \cup \overline{X}_n} {\setminus } \emptyset \) satisfying \(x \in K\) implies \(\overline{x} \notin K\) and \(\overline{x} \in K\) implies \(x \notin K\). Then we can define the extended graph-based reaction systems for 3SAT for \(\phi \) as follows.

$$\begin{aligned} 3 SAT _\phi= & {} (B(3 SAT )_\phi , A(3 SAT )_\phi , I(3 SAT )_\phi ,\\{} & {} O(3 SAT )_\phi , ctrl (3 SAT )_\phi ) \end{aligned}$$

where

  • \(B(3 SAT )_\phi = (\widetilde{X}_n \cup H_n, E_n, s_n, t_n)\) where \(\widetilde{X}_n = X_n \cup \overline{X}_n \cup CX_n \cup C\overline{X}_n\) and \(H_n = 2^{X_n \cup \overline{X}_n} = \{h_0,\ldots ,h_{2^{2n}-1} \}\). Each \(h_i \in H_n\) corresponds to a subset of \(X \cup \overline{X}\), denoted by \(Z_i\). For each \(z \in Z_i\) there exists an edge \(e \in E_n\) with \(s(e) = z\), \(t(e) = h_i\). We denote \(B(3 SAT )_\phi \) also by \((\widetilde{X}_n, H_n)\).

  • \(A(3 SAT )_\phi \) consists of the following set of reactions for each \(S \in K\) and \(y, y_1, y_2,y_3 \in X_n \cup \overline{X}_n\) (where \(\overline{\overline{y'}} = y'\)):

    • \(((X_n \cup \overline{X}_n \cup \{cy\},S), ((\{\overline{y},z\}, \emptyset , \emptyset , \emptyset ), (\{\overline{y},z\}, \{e\}, e \mapsto \overline{y}, e \mapsto z )), (X_n \cup \overline{X}_n,S \cup \{y\}))\),

    • \(((X_n \cup \overline{X}_n \cup \{cy_1, cy_2\},S), ((\{\overline{y_1},\overline{y_2},z\}, \emptyset , \emptyset , \emptyset ), (\{\overline{y_1},\overline{y_2},z\}, \{e_1,e_2\}, e_i \mapsto \overline{y_i}, e_i \mapsto z )), (X_n \cup \overline{X}_n,S \cup \{y_1, y_2\}))\),

    • \(((X_n \cup \overline{X}_n \cup \{cy_1, cy_2, cy_3\},S), ((\{\overline{y_1},\overline{y_2},\overline{y_3},z\}, \emptyset , \emptyset , \emptyset ), (\{\overline{y_1},\overline{y_2},\overline{y_3},z\}, \{e_1,e_2,e_3\},\) \(e_i \mapsto \overline{y_i}, e_i \mapsto z )), (X_n \cup \overline{X}_n,S \cup \{y_1, y_2, y_3\}))\).

  • \(I(3 SAT )_\phi = \{ init _\phi \}\), where \( init _\phi = (X_n \cup \overline{X}_n, 2^{\tilde{\varphi _1}}{\setminus } \emptyset )\) where \(\tilde{\varphi }_1 = \{ y_{11}, y_{12}, y_{13} \}\) be the literals of \(\varphi _1\).

  • \(O(3 SAT )_\phi = \{ (X_n \cup \overline{X}_n, S) \mid S \subseteq K \}\).

  • \( ctrl (3 SAT )_\phi = c_2,\ldots ,c_m\), where \(c_i\) is the discrete graph consisting of the vertices \(cy_{i1},cy_{i2},cy_{i3}\) where \(\tilde{\varphi }_i = \{y_{i1},y_{i2},y_{i3}\}\) are the literals of \(\varphi _i\).

Let \(\Phi \) is the set of all propositional formula in conjunctive normal form. Then \(\mathcal {F}(3SAT) = (3SAT_\phi )_{\phi \in \Phi }\).

Theorem 7

Let \(\phi \) be a propositional formula in conjunctive normal form. Then \(\phi \) is satisfiable if and only if \(dec(3SAT_\phi )( init _\phi ) = TRUE \).

Proof

The theorem is a direct consequence of the following lemma which we prove by induction. Let m be the number of clauses in \(\phi \). For \(j = 1,\ldots ,m\) the resulting hypergraph \(d_j\) in the result sequence \(\delta (\phi )\) contains exactly those hyperedges representing sets satisfying \(\phi _j = \bigwedge _{i=1}^j \varphi _m\).

Induction on m. Let \(A_j\) be the satisfying assignments for \(\phi _j\).

Induction base: Because \(\phi _1 = \varphi _1\), \(A_1 = 2^{\tilde{\varphi }_1} {\setminus } \emptyset \). By definition \(d_0\) contains exactly these hyperedges attached to the respective vertex sets.

Induction step: By definition \(\phi = \phi _{m+1} = \phi _m \wedge \varphi _{m+1}\). Further, \(A_{m+1} = \{ a_i \cup b_i \mid a_i \in A_m, b_i \subseteq \tilde{\varphi _i}, b_i \ne \emptyset , a_i \cap \overline{b}_i = \emptyset \}\), where \(\overline{b}_i\) is \(b_i\) where every literal is negated. By induction hypothesis the resulting hypergraph \(d_m\) contains exactly those hyperedges specified in \(A_m\). By definition \(d_{i+1} = res_{3SAT_\phi }(t_i)\), where \(t_i = c_i \cup d_i\). By construction of \(3SAT_\phi \) in state \(t_m\) exactly those reactions satisfying \(a_i \cap b_i = \emptyset \) are enabled, yielding a hyperedge \(a_i \cup b_i\). Conflicting assignments are inhibited and, therefore, these assignments are neither preserved nor extended. This proves the lemma.

Moreover, as \(O(3SAT)_\phi \) prohibits conflicting assignments as well as the hypergraph without hyperedges, \(dec(3SAT_\phi )( init _\phi ) = TRUE \) if and only if there is at least one hyperedge in the end. Consequently, \(\phi \) is satisfiable and converse. \(\square \)

Remark 7

Obviously, this reaction system is not polynomial. The background hypergraph consists of 4n vertices and \(2^{n+1}\) hyperedges. The size of each hyperedge is bounded by n. The cardiality of each subset of S is bounded by n. There are \(2^n\) subsets of S. Consequently, there are \(2n2^{n}\) reactions of type 1, \(2\left( {\begin{array}{c}n\\ 2\end{array}}\right) 2^{n}\) reactions of type 2 and \(2\left( {\begin{array}{c}n\\ 3\end{array}}\right) 2^{n}\) reactions of type 3.

10 Conclusion

In this paper, we have introduced the notion of families of extended based reaction systems to specify input–output relations, in particular, input–output functions as well as decision problems on infinite sets of graphs while a single reaction system can only handle a finite set. We have given sufficient condition that such a family models an NP-problem on one hand and a reduction between NP-problems on the other hand. To shed more light on the significance of our approach, further investigations are needed.

  1. 1.

    It would be interesting to look for more sophisticated case studies that may not only concern classical graph properties, but also properties which are related to reaction systems.

  2. 2.

    When Kreowski and Rozenberg (2018), Kreowski and Rozenberg (2019) introduced graph-based reaction systems, one major motivation was to come up with a novel approach to graph transformation. Old and often used results for various types of graph transformation are the local Church-Rosser theorems concerning the interchangeability of rule applications. In Kreowski et al. (2022), it is shown that these results are very useful to prove the correctness of reductions between NP-problems in a systematic and procedural way. It may be worthwhile to investigate whether corresponding results and applications work for steps of interactive processes.

  3. 3.

    In Kreowski and Lye (2020a), Kreowski and Lye (2020b), Lye (2021), we have provided a categorical framework generalizing set- and graph-based reaction systems. Many types of graphs and graph-like structures can be used as underlying structures of reactions. Moreover, we also discussed modeling decision problems like hypergraph coloring or hypergraph vertex-covering. To carry our concept of families of extended graph-based reactions systems over onto the categorical level may open up potentials.

  4. 4.

    As many practical applications involve NP-complete problems the known solutions of which are exponential, often heuristics and approximations are employed. Therefore, one may like to consider whether our approach is also meaningful in this context.

  5. 5.

    The examples HAM, CLIQUE and INDEP have admitted context sequences of length 2 and, therefore, semantically relevent single-step interactive processes, following the guess and check methodology. In contrast, the modeling of Turing machines uses interactive processes of the same length as the computation of the Turing machine. One may think of providing the whole accepting path to the Turing machine at once. Is this possible without specifying all accepting paths as reactants?

  6. 6.

    In Nobile et al. (2017), a simulator of set-based reaction systems is presented that is based on a fine-grained parallelization strategy executing all enabled reactions simultaneously on the GPU. It may be an interesting direction of future work to implement such a parallel simulator for graph-based reaction systems.