About reversibility in sP colonies and reaction systems

In this paper, we study reversibility in sP colonies and in reaction systems. sP colony is a bio-inspired computational model formed from an environment and a finite set of agents. The current state of the environment is represented by a finite set of objects and the current state of the agent is given by a finite multiset of objects. By execution of a program from a set of programs associated with the agent, the agent can change the objects in its own state and possibly in the environment, too. Reaction systems are a bio-inspired computational model where reactants are transformed into products only if some inhibitors are not present. We define sP colonies without input influence and prove that to any reversible sP colony of such type an inverse sP colony can be constructed that performs inverse computation. In the second part of the paper, we show that the concept of a reversible reaction system and the notion of an inverse reaction system can be defined in a similar way, and partially reversible reaction systems can simulate reversible logic gates and reversible Turing machines.


Introduction
P colonies (introduced in Kelemen et al. (2004)) are particular variants of P systems (or membrane systems), inspired by collections of reactive agents acting in a joint, dynamically changing environment. The notion was also motivated by colonies of formal grammars. The interested reader can be referred to Pȃun et al. (2010) for detailed information on P systems and to Kelemen and Kelemenová (1992) as well as Csuhaj-Varjú et al. (1994) for more information on colonies in grammar systems theory. Detailed summaries on P colonies can be found in Kelemenová (2010) and Ciencialová et al. (2019).
A P colony consists of a finite number of agents and their shared environment. Both the current state of the environment and the current state of each agent are represented by a finite multiset of objects (over the same alphabet). The agents are equipped with programs consisting of rules. The rules are of two types: the evolution rules which change the objects of the agents, and the communication rules which are used for an interaction between the agent and the environment.
In this paper, we deal with variants of P colonies where the current state of the environment is a set (instead of a multiset). They are called sP colonies and they were introduced in Ciencialová et al. (2020). Notice that while in case of P colonies, quantitative properties of the environment are significant (the number of copies of the same object), in case of sP colonies, only the occurrence of an object is important, which is a qualitative property.
The computation of an sP colony starts with its initial configuration where the environment and each agent is in its own initial state. The computation step means a maximally parallel action of the active agents: the agent is active if it is able to perform at least one of its programs, and the joint action of the agents is maximally parallel when no more active agent can be added to the synchronously acting agents. The computation ends if there is no more applicable program in the system. Reaction systems (or R systems) were proposed as a computational device with the components that represent basic chemical reactions in Ehrenfeucht and Rozenberg (2005). Informally, a reaction system is composed of a finite set of objects that can be considered as chemicals and a finite set of reactions. Each reaction is a triplet of sets, that is, the reactants, inhibitors, and products. Let T be a set of reactants. A reaction can be applied to T if all reactants are present in T and there are no inhibitors present. Then the reactants are replaced by the products. All enabled reactions are applied in parallel. The obtained set of products is the union of all single sets of products of each reaction which is enabled in T.
It is easy too see that reaction systems are a qualitative model. Reaction systems and P colonies are related; in Ciencialová et al. (2020), it was shown that for any reaction system, a simulating P colony can be constructed.
In this paper, we continue studying sP colonies and reaction systems, with focus on their reversible variants. The notion of reversibility and inverse functions is an essential and well-studied part of mathematics and computer science (see, for example, Morita (2017)). Reversible computing systems are defined as systems for which each of their computational configurations has one predecessor at most. Therefore, they are ''backward deterministic'' systems.
In the paper, we introduce the sP colonies without an input influence (during computation) and the set condition of existence of an inverse sP colony to an sP colony. In the second part of the paper, we focus on the reaction systems that work in a way similar to sP colonies. As for reaction systems, we show that for every reversible reaction system, there exists an inverse reaction system. In the last part of the paper, reaction systems simulating reversible logic gates and reversible Turing machines are presented. The properties of reversible reaction systems were studied in Bagossy and Vaszil (2020b) and .

Preliminaries
Throughout the paper, we assume the reader to be familiar with the basics of the formal language theory by Rozenberg and Salomaa (1997). We introduce the notions and notations used in the sequel.
The family of recursively enumerable sets of natural numbers is denoted by NÁRE and N denotes the set of natural numbers.
An alphabet is a finite non-empty set. Let R Ã be the set of all words over alphabet R (including the empty word, e). For the length of the word w 2 R Ã , we use the notation w j j and the number of occurrences of symbol a 2 R in w is denoted by w j j a . A multiset of objects M is a pair M ¼ ðV; f Þ, where V is an arbitrary (not necessarily finite) set of objects and f is a mapping where f : V ! N. The mapping f assigns to each object in V its multiplicity in M. The set of all multisets over the set of objects V is denoted by V Ã . The set V 0 is called the support of M and is denoted by supp(M) if f ðxÞ 6 ¼ 0 for all x 2 V 0 . The cardinality of M, denoted by card(M), is defined by cardðMÞ ¼ P a2V f ðaÞ. Any multiset of objects M ¼ ðV; f Þ where V ¼ fa 1 ; . . .; a n g can be represented as a string w over the alphabet V with w j j a i ¼ f ða i Þ, 1 i n. Obviously, all words obtained from w by permuting the letters also represent M, and e represents the empty multiset.
Let g be a mapping g : A ! M where A is a finite set, and M ¼ ðA; f Þ is a finite multiset where f ðaÞ ¼ 1 for every a 2 A. Informally, g is a mapping that ''converts'' a set to a multiset with objects with multiplicity 1. If no confusion arises, a finite set X can also be represented by a word and notations jXj, and jXj a can also be used.
A directed graph is an ordered pair G ¼ ðV; EÞ according to Diestel (2005) where V is a set whose elements are called vertices, nodes, or points. A is a set of ordered pairs of vertices, called arrows, directed edges, directed arcs, or directed lines. With each edge e of G, let there be associated a real number w(e), called its weight. Then G, together with these weights on its edges, is called a weighted graph. If the edge is associated with a unique label, then we speak of a labeled graph. A vertex x k is connected with vertex x 0 if there exists a sequence of vertices x 0 x 1 . . .x k such that for two vertices e i ¼ ðx i x iþ1 Þ 2 E for each i 2 f0; 1; . . .; k À 1g: The out-degree is the number of the outgoing edges from a vertex, and the indegree is the number of the incoming edges onto a vertex.

sP colonies
The notion of an sP colony was introduced in Ciencialová et al. (2020). In this section, we define a slightly modified version of the original concept. We will also introduce some further notions, such as a deterministic, inverse, and reversible sP colony, together with a transition graph of a reversible sP colony. We show that to any reversible sP colony, we can effectively construct an inverse sP colony performing inverse computation.
First, we give the definition of the sP colony, then we focus on explaining how the sP colony performs the computation.
Definition 1 An sP colony (of degree n and capacity k, where n; k ! 1) is a construct where • V is an alphabet, its elements are called objects, • f 2 V, called the final object of the sP colony, • V E;0 V, called the initial state (or initial content) of the environment, • B i ; 1 i n, is the agent of the sP colony. Each agent B i ¼ w i;0 ; P i À Á is defined as follows: w i;0 is a multiset over V with k elements, called the initial state (or initial content) of B i , -P i ¼ p i;1 ; . . .; p i;m i È É , m i ! 1, is a finite set of programs, where each program consists of k rules. Each rule is in one of the following forms: A computation of the sP colony P is based on changing its configuration. A configuration of the sP colony consists of the current state of the environment and the current states of the agents.
Formally, the configuration of the sP colony P is given by ðw 1 ; . . .; w n ; V E Þ, where w i is a multiset of objects in V, and V E is a non-empty subset of V. The multiset w i represents all the objects present inside the i-th agent, and V E 2 2 V represents the set of all objects in the environment. Furthermore, jw i j ¼ k; 1 i n. The set of all possible configurations of P is denoted by C, and Notice that C can be the set of all possible configurations of more than one sP colony. While standard P colonies may have an infinite number of configurations, the number of all possible configurations of any sP colony is finite.
The functioning of an sP colony starts from its initial configuration (an initial state). The initial configuration of the sP colony is the ðn þ 1Þ-tuple ðw 1;0 ; . . .; w n;0 ; V E;0 Þ, where w i;0 , 1 i n is the initial state of the agent B i , and V E;0 is the initial state of the environment.
The change of the configuration is performed by actions of the agents. This means that the agents apply the rules that are contained in the executed program.
The first type of the rules associated to the programs of the agents, the evolution rules, are of the form a ! b. This means that an object a inside the agent is rewritten to (evolves to be) an object b.
The second type of rules, the communication rules, are of the form c $ d. If a communication rule is performed, then an object c inside the agent and an object d in the environment swap their locations. Thus, after executing the rule, the object d appears inside the agent and the object c appears in the environment.
Notice that since the environment is represented by a set, one or more rules can introduce the same object in the environment. The configuration change does not have to be done by agents only. At each step, some objects may be added to the environment as input. The notion of input of the sP colony will be explained later.
Next, we define the notion of an applicable program. Let us consider that each program in the sP colony P has its own unique identifier (a unique label) p i;j . This notation refers to the j-th program in the set of programs P i of the ith agent, B i .
To define a configuration transition, we set the following mappings: Let p j ¼ r j1 ; . . .; r jk be a program. For every rule r jl ; 1 l k, we construct functions w : X ! Y, where Y V, X is the set of all rules over V in p j , and w 2 forig; new; in; outg is defined as follows: For the evolution rule, r jl ¼ a ! b origðr j;l Þ ¼ fag; newðr j;l Þ ¼ fbg; inðr jl Þ ¼ ;; outðr j;l Þ ¼ ;; and for the communication rule, r j;l ¼ a $ b origðr j;l Þ ¼ ;; newðr j;l Þ ¼ ;; inðr j;l Þ ¼ fbg; outðr j;l Þ ¼ fag: For a program p i;j ¼ r i;j;1 ; . . .; r i;j;k 2 P i and a configuration c ¼ ðw 1 ; . . .; w n ; w e Þ, we define app p i;j ðcÞ , w i ¼ S k l¼1 forigðr i;j;l Þ [ outðr i;j;l Þĝ S k l¼1 inðr i;j;l Þ V e app p i;j ðcÞ is true if and only if the program p i;j is applicable in configuration c.
A set of applicable programs associated with the agent B i ¼ ðw i ; P i Þ in a configuration c, denoted by App i ðcÞ, is defined as If App i ðcÞ contains more than one program, then a nondeterministically chosen one is applied. For the configuration c, let P c be the set of programs applicable in the configuration c satisfying the following conditions: there is at most one program from App i ðcÞ for every i, 1 i n; and P c [ App i ðcÞ ¼ ; if and only if App i ðcÞ is equal to the empty set.
The sP colony P is called deterministic if and only if jApp i ðcÞj 1 for all c 2 C and for all agents B i , 1 i n, in P. As a result, there exists only one possible P c for every configuration c.
Next, we define the notion of computation of (length m) in the sP colony working with an input sequence (with an input, for short).
A computation of a length m, m ! 1, in the sP colony P working with input sequence c ¼ in 0 ; in 1 ; in 2 ; . . .; in m is a sequence of ðn þ 1Þ-tuples ðw 1;j ; . . .; w n;j ; ðV E;j [ in j ÞÞ, 0 j m, where w 1;j ; . . .w n:j ; V E;j is a configuration of P, in j V; 1 j m. For j ¼ 0 and in 0 ¼ ;, the configuration is the initial configuration. Therefore, the initial configuration of P is available at the beginning of the computation and then in each of the first m steps, an input set of elements of V is inserted into the environment. Notice that in j can be empty for some j, 1 j n.
Also notice that in case of standard P colonies, no input is inserted in the environment, as it is changed only by the actions of the agents.
As we mentioned above, the computation of the sP colony passes from one configuration to another one. This change is done by an execution of at most one applicable program per agent and by inserting a set of input objects into the environment from an input sequence. The computation is defined to be collision-free. All agents having an applicable program should perform exactly one of its applicable programs.
We distinguish between two computational modes: a forgetting mode and a non-forgetting mode. If the new content (state) of the environment obtained by a transition is the union of the set of the objects put into the environment by agents, and the input in the current step, then we speak of the computation in the forgetting mode (or the forgetting computation, f mode). The computation is nonforgetting (in the non-forgetting mode, nf mode) if those elements of the environment that did not take part the in action of any agent and were not the elements of the input, remain the elements of the environment.
Next, we provide a formal definition of a transition (a computation step).
We say that in a t-th step of computation, where t ! 1, the current configuration c directly changes for configuration c 0 (or there is a transition between these two configurations), written as . . .; r i;j;k 2 P c being the chosen program applied by the i-th agent or w 0 i ¼ w i if the i-th agent has no applicable program in the configuration c, i.e., App i ðcÞ ¼ ;.
Furthermore, in case of the forgetting computation, and, in case of the non-forgetting computation, The computation ends by halting after performing more than m steps, where m þ 1 is the length of the input set sequence.
The result of a computation with input sequence c can be defined in several ways.
The first way is based on the fact that the sP colony can be seen as an accepting device, and so the input sequence can be accepted if the computation halts after processing the whole input sequence, i.e., no more transition can be performed.
The second way is closer to the definition of the original model of the P colonies. We say that the number d is computed by the sP colony working with the input sequence c if the computation with c halts and is a number of steps of the computation and V E s is the content of the environment after s steps of the computation. Since the sP colony is a nondeterministic computing device, with one input sequence, there can exist halting and also non-halting computations.
The third way of defining the result of the computation is to assign a set to the computation and the input sequence; the result set is the content of the environment in a halting configuration.
The family of all sets of numbers NðPÞ computed as above by the sP colonies of a capacity at most k ! 0, degree at most n ! 0 and height at most h ! 0 is denoted by NsPCOLðk; n; hÞ. The maximal number of programs of an agent of P is called the height of P. If one of the parameters n or h is not bounded, then we replace it with Ã.
Example 1 Our example is based on some ideas presented as an example in Ciencialová et al. (2020). Let m and p be natural numbers such that 1\p m=2. We can construct an sP colony with one agent that decides whether m is divisible by p for an input sequence of the length m . The input sequence (except of the in 0 ) is formed of sets of objects, each set has only one object as element. It means that the sP colony will accept one object per step of the computation. The natural number m is represented as m sets fg followed by a special set f#g. The last object that enters the system is the indicator of the end of the input. The agent in the sP colony corresponds to the divisor by the number p. The state of the agent p corresponds to the result of an operation ''h mod p'', where h is the number of consumed objects and p is the prime number. At each step of the forgetting computation, the agent consumes the object from the input set and changes its state in the same way as a finite state machine verifies that the number of symbols in a word is divisible by a given number. After consuming the object #, the agent generates the final object (if it is in the state corresponding to 0), or it enters an infinite loop.
Let P 1 ¼ ðV; f ; v E ; B 1 Þ be an sP colony with the capacity 2 and with 1 agent such that The set of programs P 1 consists of the following programs: The sP colony works as accepting device. The input sequence corresponding to a number m is accepted only if the computation halts after all input sets enter the system, which implies that m is divisible by p.

Reversible sP colonies
In this section, we will focus on the process of computation, namely, we aim to deal with the determinism and reversibility of the computation in sP colonies and define the concept of an inverse sP colony. First, we define the notion of a transition graph for the sP colony working without an input sequence. Notice that in this case, no external additional objects are added to the set of environmental objects during the computational steps.
Definition 2 Let P be the sP colony working without the input sequence in an x-mode, where the x 2 fnf ; f g, and let C be the set of of all configurations of P. A directed graph G x ðPÞ ¼ ðV G ; EÞ is called the transition graph of P working in mode x, if V G ¼ C, and e ¼ ðc 1 ; c 2 Þ 2 E if and only if there is the transition c 1 ' c 2 in some step of the xmode computation of P.
If the out-degree of each edge of the transition graph of the sP colony is at most one, then it is called deterministic. Formally, Definition 3 Let P be the sP colony working without the input sequence in an x-mode, where the x 2 fnf ; f g, let C be the set of all possible configurations of P and let G x ðPÞ ¼ ðV G ; EÞ be the transition graph of P. Then P is called deterministic (in the x-mode) if and only if ðc; c 0 Þ 2 E^ðc; c 00 Þ 2 E ) c 0 ¼ c 00 : Next, we provide the conditions for reversibility in the sP colonies working without the input sequence.
. . .; B n Þ be the sP colony with a capacity k, working without the input sequence in an x mode, where the x 2 ff ; nf g. Let C be the set of all of its possible configurations and let G x ðPÞ ¼ ðV G ; EÞ be the transition graph of P. Then P is called reversible (in the xmode) if and only if the following conditions are satisfied: 1. App i ðcÞ j j 1 for 1 i n and for all c 2 C, i.e., P is deterministic; 2. for every c 2 C there is at most one ðc 0 ; cÞ 2 E, i.e., the in-degree of each node is at most one.
The conditions in Definition 4 ensure that the transition is a bijective relation in reversible sP colonies.
Definition 5 Let P be the sP colony working without the input sequence and in an x mode, where the x 2 ff ; nf g. If there exists the sP colonyP working without the input sequence and in the x mode such that for any computation c 1 ' c 2 Á Á Á ' c m in P, where m ! 1, there exists a computation c m ' c 2 Á Á Á ' c 1 inP; and, reversely, thenP is called an inverse (sP colony) of P.
If an sP colony P working without input is reversible, then we can effectively construct an inverse sP colonyP to P.
. . .; B n Þ be a reversible sP colony with a capacity k and working without the input and in the x mode, where the x 2 ff ; nf g. Then there exists an inverse sP colonyP ¼ ðV; f ; V E ;B 1 ; . . .;B n Þ such that the set of programP i of agentB i , 1 i n, is given as Proof From the construction of rules ofP, it is easy to see that: If r i;j;l ¼ a ! b )r i;j;l ¼ b ! a ) origðr i;j;l Þ ¼ newðr i;j;l Þ; newðr i;j;l Þ ¼ origðr i;j;l Þ; outðr i;j;l Þ ¼ inðr i;j;l Þ ¼ ;; inðr i;j;l Þ ¼ outðr i;j;l Þ ¼ ; i;j;l Þ ¼ inðr i;j;l Þ; inðr i;j;l Þ ¼ outðr i;j;l Þ; origðr i;j;l Þ ¼ newðr i;j;l Þ ¼ ;; newðr i;j;l Þ ¼ origðr i;j;l Þ ¼ ; We have to prove that c 1 ' c 2 ' . . . ' c m is a computation in the sP colony P if and only if there exists the The initial configurations of the computations in the sP colonies are c 1 and c m ¼ĉ 1 , respectively. Let us focus on one step of the computation in both systems. Let us consider c s ' c sþ1 ; 1 s m, i.e. the s-th step of the computation in the sP colony P. Since P is reversible, to perform the transition, there is only one set of programs P c s where there exists at most one program for each agent in P. Let c s ¼ ðw 1 ; . . .w n ; V E Þ and c s ¼ ðw 0 for p i;j 2 P c s and 1 i n (if for given i p i;j 2 P c s , otherwise App i ðc s Þ ¼ ; for agent B i ). By substituting the functions, we obtain S k l¼1 fnewðr i;j;l Þ [ inðr i;j;l Þg ¼ Regarding the change of the environment, we remember that P i is without the input, consequently S Then, in the case of the forgetting computation, we obtain S k l¼1 inðr i;j;l Þ and, in case of the non-forgetting computation, we get The previous relations are true only if sets P c s andP c sþ1 are formed from the corresponding programs. If the program p i;j is in P c s , then the programp i;j is applicable in the configuration c sþ1 and, as a result, it is inP c sþ1 . If the programp x 2 P i is applicable in the configuration c sþ1 and the corresponding program p x is not applicable in c s thenbecause P is deterministic -there exists a configuration c x for which c x ' c sþ1 holds. But this is not possible because P is reversible, and therefore Condition 2 of Definition 4 should hold. h

Reaction systems
In this section we recall the basic notions concerning reaction systems, introduced in Ehrenfeucht and Rozenberg (2005). Let S be a finite non-empty set (its elements are defined as objects or molecules). A triplet a ¼ ðR; I; PÞ where R, I, P are non-empty subsets of S and R \ I ¼ ; is called a reaction in S. S is called the background set, R is called the set of reactants (or the reactant set), I is the set of inhibitors (or the inhibitor set), and P is called the set of products (or the product set) of reaction a. The set of all reactions in S is denoted by rac(S). The sets R, I, P are also denoted by R a ; I a ; P a , respectively.
A reaction system is an ordered pair A ¼ ðS; AÞ, where S is the background set and A is the non-empty set of reactions in S.
Reaction systems work with performing their reactions on a non-empty set of objects from the background set that is called the current state of the reaction system.
Let S be a background set, let X S, and let a be a reaction in S. Then, a is enabled by X, denoted by en a ðXÞ, if R a X and I a \ X ¼ ; holds. The result of a on X, denoted by res a ðXÞ, is defined by res a ðXÞ ¼ P a if en a ðXÞ, and res a ðXÞ ¼ ;, otherwise.
The effect of a set of reactions on a state is cumulative. Let S be a background set, let X S, and let A be a nonempty set of reactions in S. A is called enabled by X, denoted by en(A, X), and it is defined by enðA; XÞ ¼ fa 2 A j en a ðXÞg. The result of A on X, denoted by res(A, X), is defined by resðA; XÞ ¼ fres a ðXÞ j a 2 Ag. The set of those reactions in A that generate a product set included in X is defined as prodðA; XÞ ¼ fa 2 A j P a XÞg.
The behavior of the reaction system is described by an interactive process defined as follows.
The sequences C 0 ; . . .; C nÀ1 , and D 1 ; . . .; D n are the context and result sequences of p, respectively.The context C 0 represents the initial state of p (the state in which the interactive process starts), and the contexts C 1 ; . . .; C nÀ1 represent the influence of the environment on the computation. If C 0 6 ¼ ; and C i ¼ ; for all i ! 1, then the reaction system is said to be working without the influence of the environment (or without the environment influence).
The sequence stsðpÞ ¼ W 0 ; . . .; W n denotes the state sequence of p, where W 0 ¼ C 0 (the initial state), and W i ¼ D i [ C i for all 1 i n. The sequence actðpÞ ¼ E 0 ; . . .; E nÀ1 of subsets of A such that E i ¼ enðA; W i Þ for all 0 i n À 1 represents the activity sequence of p.
Consequently, the evolution of the state sequence of A starting from W 0 is If E n ¼ enðA; W n Þ ¼ ;, then the interactive process terminates.
To describe the evolution, we can define a mapping d : 2 S Â 2 S ! 2 S such that the following conditions are satisfied: If a reaction system works without the environment influence, then for every i ! 1 dðD i ; ;Þ ¼ D iþ1 .
In this case, we can simplify the definition of the transition mapping as follows: d 0 : 2 S ! 2 S where d 0 ðWÞ ¼ W 0 . If we have to indicate that the transition mapping is associated with a certain reaction system, then we write d 0 A ðW 0 Þ ¼ d 0 A ðW 00 Þ: For every reaction system working without the environment influence, we can construct a labeled directed graph G A ¼ ðV; E; labÞ called the transition graph with a set of nodes V 2 S À f;g and a set of directed edges E such that there is a directed edge e ¼ ðX; YÞ if and only if enðA; XÞ 6 ¼ ;, resðA; XÞ ¼ Y and labðeÞ ¼ S a2enðA;XÞ I a . Because of the determinism of the evolution, every node of the transition graph has out-degree at most one.

Reversible reaction systems
In this section, we deal with the reversibility of reaction systems working without the environment influence.
First, we present some notions we will use in the rest of the paper.
Let S be a background set and let a ¼ ðR a ; I a ; P a Þ be a reaction in S. IfÂ ¼ ðP a ; I a ; R a Þ is a reaction in S, thenÂ is called an inverse reaction of a. For a reaction a ¼ ðR a ; I a ; P a Þ, we also may refer to R a and P a by lhs(a) and rhs(a), respectively. For the reaction system A ¼ ðA; SÞ and for the set of reactants X & S, let us define reacðA; XÞ ¼ fa 2 A j R a Xg. Now we define the notion of a reversible reaction system. 4. for every node Y of the transition graph G A ¼ ðV; E; wÞ of the reaction system A, there is at most one edge e ¼ ðX; YÞ; i.e., each node of G A has at most one indegree.

Definition 6 A reaction system
The first condition ensures that the inverse reaction of the reaction a will is in the required form. The second condition is met if the reactions that take place in generating of some (non-empty) subset of S are not in conflict, i.e., there is no reactant of such a reaction that is an inhibitor of some other reaction. The third condition means that if the set of reactions is enabled on some non-empty subset of S, then there is no product of any of the inverse reactions which is an inhibitor of any inverse reaction. The fourth condition assures that the transition mapping d is injective.
Each component of the transition graph of the reversible reaction system is either a cycle or it forms a line.
Proof We should prove that if x p is the interactive process in the reaction system A, then there exists an interactive process xp in the reversed reaction system meeting the following condition: if . .À! E 0 W 0 is an evolution inÂ (corresponds topÞ, withÊ i ¼ fâ j a 2 E i g; 0 i n À 1. By definition, the reversible reaction system A is without the environment influence, and C 0 6 ¼ ;^C i ¼ ;; i ! 1 for a sequence C 0 ; C 1 ; . . .; C n of any interactive process in A. Because every node (state) has an in-degree at most one (the fourth condition of Definition 6), the (simplified) transition mapping d 0 A is injective. For an i-th step of the evolution x p , i ! 1, there exists a transition d 0 Let us assume that d 0Â ðW i Þ ¼ W. We construct a set E iÀ1 of inverse reactions from E iÀ1 . Because rhsðE iÀ1 Þ ¼ lhsðÊ iÀ1 Þ and the third condition of Definition 6 holds, such state exists and We first consider the case W 6 ¼ W i . Since inclusion (1) holds, W i W follows. Letb be a reaction from a set of reactionsÂ such thatb 2 enðÂ; W i Þ andb 6 2Ê iÀ1 . Since b 2 prodðA; W i Þ and the second condition of Definition 6 holds, there is no inhibitor of reaction b 2 A (b 6 2 E iÀ1 ) in any set of reactants of the reactions from E iÀ1 . The only reason why reaction b is not in E iÀ1 can be if R b À W iÀ1 6 ¼ ; holds. Therefore, Because of the fourth condition of Definition 6, there is at most one transition leading to every state, then Y ¼ W i : It remains to prove that enðÂ; W i Þ ¼Ê iÀ1 . Because of the second condition of Definition 6, inverse reactions to all reactions from E iÀ1 are enabled. Suppose that there exists a reactionb 2Â such thatb 6 2Ê iÀ1 and b 2 enðÂ; W i Þ. This means that the reaction b 2 A is not enabled by W iÀ1 , because the state contains some object which is an inhibitor of a reaction. But, we have already proven that this cannot happen because of the missing a2prodðA;W i Þ R a ¼ ; (second condition of Definition 6). Subsequently, any inhibitor s in I b is not in a set of reactants of any reaction enðA; W iÀ1 Þ, it is not processed by any reaction from enðA; W iÀ1 Þ, and it disappears from the state after one step. Then, there exists a state X ¼ But the simplified transition mapping is injective and, as a result, W iÀ1 \ I b ¼ ;: h Theorem 3 Let A ¼ ðA; SÞ be a reversible reaction system and letÂ ¼ ðÂ; SÞ be a reaction system inverse to A. Then A is reversible, too.
Proof BecauseÂ is the inverse reaction system to A, for the reactionâ, the following equalities hold: Let us focus to the four conditions of Definition 6 that must hold for the reversible reaction systems.
1. By definition, the set of products and the set of inhibitors of every reaction must be disjoint. This condition holds: see equalities a) and c) above. 2. By the second condition of Definition 6, the following statement should be true. For every state X 2 2 S such that prodðA; XÞ 6 ¼ ; [ holds, too. 4. The fourth condition of Definition 6 is met as well.
Because of the determinism of every interactive process of A, every state of transition graph has an in-degree at most one. For every edge e ¼ ðX; YÞ of the transition graph G A , there is one edgeê ¼ ðY; XÞ of the transition graph GÂ of the inverse reaction system and vice versa. Subsequently, every node of the transition graph GÂ has an out-degree at most one. h Next, we introduce the notion of a reaction system with a restricted input and the notion of a partially reversible reaction system.
A reaction system with a restricted input is a triplet A In ¼ ðA; S; InÞ such as A ¼ ðA; SÞ is a reaction system, and In 2 S is a finite non-empty set of input sets.
In an interactive process, every C i ; i ! 0 is an element of the set In. If a reaction system works without the environment influence, then the In contains all possible inputs C 0 for an initialization of an interactive process.
If the A In satisfies conditions 1.-4. of Definition 6, then the reaction system is called partially reversible. Let the A In be a partially reversible reaction system and G A In be its transition graph. A set of the vertices of G A In contains such states that are connected with the states from the In, and the following holds: If there is a state X 2 V with an in-degree equal to zero, then X 2 In. Every node of the G A In with an in-degree at least one can be in the input set of the inverse reaction systemÂ.
Remark 1 As we mentioned in the Introduction, in Ciencialová et al. (2020), we proved that for any reaction system, the simulating P colony can be constructed. Based on the previous considerations, it can be shown that for any reversible sP colony without the input influence and working in the forgetting mode, the simulating reaction system can be constructed. Notice that the reversible sP colony is deterministic and the in-degree of its transition graph is 1. We sketch the idea of the construction. Suppose that P is a reversible sP colony without the input influence that works in the forgetting mode. Let V be a set of objects of P and let it have n agents of capacity k. Then any configuration c ¼ ðw 1 ; . . .; w n ; V E Þ of P can be represented by the ðn þ 1Þ-tuple ða w 1 ;1 ; . . .; a w n ;n ; a V E Þ, where the a w j ;j is an element of the background set S of A representing that the state of the jth agent is w j , and a V E denotes that the state of the environment is V E . Since the number of all possible configurations is finite, we can easily define such an alphabet S that codes the components of the configurations in a unique manner. Then, a transition of P from the configuration c to c 0 , where c ¼ ða w 1 ;1 ; . . .; a w n ;n ; a V E Þ and c 0 ¼ ða w 0 1 ;1 ; . . .; a w 0 n ;n ; a V 0 E Þ can be considered as a reaction ðfa w 1 ;1 ; . . .; a w n ;n ; a V E g; fXg; fa w 0 1 ;1 1; . . .;a w 0 n ;n ; a V 0 E gÞ, where X is a special symbol used as an inhibitor. Since P is deterministic, c 0 is unique; consequently, the coded versions of transitions form a reaction set, and the evolution in A correspond to a computation in P.

Reversible reaction systems and models of computation
In the following section, we provide two examples where partially reversible reaction systems are used for simulating well-known models as logic gates, circuits, and Turing machines.

Reaction systems, reversible logic gates, and circuits
The Fredkin gate is one of the reversible logic gates. It was proposed by Fredkin and Toffoli in Fredkin and Toffoli (1982) as a logical gate that realizes the logical function f F : f0; 1g 3 ! f0; 1g 3 such that f F : f0; 1g 3 ! f0; 1g 3 such that f F : ðc; p; qÞ ! c; c^p ð Þ_ :c^q ð Þ; c^q ð Þ ð _ :c^p ð ÞÞ: Further information can be found for instance in Morita (2017). First, we provide the basic notions we will use in this particular section.
A pictorial representation and operations of the Fredkin gate are demonstrated by Figs. 2 and 3. The truth table of the logical function f F of the Fredkin gate is presented in Table 1.
Connecting reversible logic gates, a logic circuit can be composed. We define a reversible combinatorial logic circuit that realizes an injective logical function.
Definition 7 Let S be a finite set of reversible logic gates. A reversible combinatorial logic circuit F over S is a system composed of a finite number of copies of reversible logic gates taken from S, which are connected under the following constraints.
1. Each output of a gate can be connected to at most one input of some other gate, i.e., a fan-out of the output is inhibited. 2. Two or more outputs should not be connected to one input port of some other gate, i.e., the merging of outputs is inhibited. 3. The circuit should not contain a closed path, i.e., no feedback loop is allowed.
We show that we can effectively construct a partially reversible reaction system simulating the functioning of the Fredkin gate. The background set of the reaction system is formed from elements denoting the truth value (0 or 1) with an index of the input or the output of the Fredkin gate (see Fig. 2). The set of reactions contains such reactions that ensure a transformation of the input values into the output ones.
Let A In ¼ ðS; A; InÞ where • S ¼ X z j X 2 f0; 1g^z 2 fc; p; q; 1; 2; 3g f g [ fIg and • A ¼ fðf0 c ; X p ; Y q g; fIg; f0 1 ; Y 2 ; X 3 gÞ; ðf1 c ; X p ; Y q g; fIg; f1 1 ; X 2 ; Y 3 gÞ j X; Y 2 f0; 1gg Since we consider only valid inputs from the set In for the construction of the transition graph, the reaction system A In satisfies all conditions to be a partially reversible reaction system and, subsequently, we can construct an inverse reaction systemÂ In 0 . LetÂ In 0 ¼ ðS;Â; In 0 Þ where • S ¼ X z j X 2 f0; 1g^z 2 fc; p; q; 1; 2; 3g f g [ fIg and To design the circuit, we have to distinguish individual connections between logic gates. We use the labels of inputs and outputs of particular gates in such a way that the input of some gate has the same label as the output of its connected gate. The labeling of the connections is possible because of the conditions set in Definition 7, i.e., in the definition of the reversible combinatorial logic circuit. The last problem to solve is that all three inputs must arrive at the gate at the same time. If they do not arrive at the same moment, the reaction system has no reaction to process them; as a result, they are erased. To prevent these outputs from being erased, we add the following reactions to the reaction system: Let I 1 ; I 2 ; I 3 be the inputs of the Fredkin gate. Let ðfI 1 ; I 2 g; fI 3 g; fI 1 ; I 2 gÞ; ðfI 2 ; I 3 g; fI 1 g;fI 2 ; I 3 gÞ; ðfI 1 ; I 3 g; fI 2 g; fI 1 ; I 3 gÞ; ðfI 1 g; fI 2 ; I 3 g; fI 1 gÞ; ðfI 2 g; fI 1 ; I 3 g; fI 2 gÞ; ðfI 3 g; fI 1 ; I 2 g; fI 3 gÞ However, these reactions do not meet the second condition for reversible reaction system (see Definition 6). A solution for the timing problem mentioned above can be obtained by modifying the circuit. This can be done by adding delay units to each input that arrives ''early''. Each delay unit provides the output with the same value as the input after n time units (n ! 1 ).
Let U j be the output of the Fredkin gate that has to be delivered to another gate as I k after n steps of evolution. We add the following reactions to the set A:  Table 1 The truth table of  simulating delay units as well. There is no reaction to the case that all outputs are present in the environment, and the interactive process terminates in this state. For all the valid inputs, there is no state M S with M À lhsðenðA; MÞÞ 6 ¼ ; and enðA; MÞ 6 ¼ ;. Because of the construction of the reactions (reactants, inhibitors, and products), the system is reversible.

Reaction systems and deterministic reversible Turing machines
In the following part of the paper, we show how the computations by deterministic reversible Turing machines can be simulated by the reaction systems. For more detailed information on the reversible Turing machines, see Morita (2017). A one-tape Turing machine (a TM, for short) is defined by a sixtuple T ¼ ðQ; R; q 0 ; F; B; dÞ where the Q is a nonempty finite set of states, R is a non-empty finite set of tape symbols, q 0 is an initial state ðq 0 2 QÞ, F is a set of final states ðF QÞ, and B is a special blank symbol ðB 2 RÞ. The sixth item d is a move relation, which is a subset of ðQ Â R Â R Â QÞ [ ðQ Â feg Â fÀ1; 0; þ1g Â QÞ.
The symbol e means that T does not read the tape symbol. The symbols À1, 0, and þ1 are shift directions of the head, which are used for the ''left-shift'', ''zero-shift'', and ''right-shift'', respectively. Each element of the d is a quadruple of the form ðp; s; s 0 ; qÞ 2 ðQ Â R Â R Â QÞ, or ðp; e; d; qÞ 2 ðQ Â feg ÂfÀ1; 0; þ1g Â QÞ. The quadruple ðp; s; s 0 ; qÞ is called a read-write quadruple or a read-write rule. It means that if T reads the symbol s in the state p, then T writes s 0 , and enters the state q. The quadruple ðp; e; d; qÞ is called a shift quadruple or a shift rule. This means that if T is in the state p, then it shifts the head to the direction d and enters the state q. Each state q f 2 F is a halting state, i.e., there is no quadruple of the form ðq f ; x; y; qÞ in d.
Let T ¼ ðQ; R; q 0 ; F; B; dÞ be a TM. T is called deterministic, if for any pair of distinct quadruples ðp 1 ; x 1 ; y 1 ; q 1 Þ and ðp 2 ; x 2 ; y 2 ; q 2 Þ in d, the following conditions are met: This means that for any pair of distinct rules, if their present states are the same, the rules are both read-write rules and the symbols read by them are different.
We call the T a reversible TM (RTM), if any pair of distinct quadruples ðp 1 ; x 1 ; y 1 ; q 1 Þ and ðp 2 ; x 2 ; y 2 ; q 2 Þ in d satisfies the following: That is, for any pair of distinct rules, if their next states are the same, then they are both read-write rules, and the written symbols are different. This is called the reversibility condition for Turing machines (given in the sixtuple form).
Theorem 4 For every linear bounded deterministic reversible Turing machine T and input x, there exists a partially reversible reaction system A In which simulates the computation of the T on the x.
Proof If a deterministic reversible Turing machine is linear bounded, then there is a linear function such that for every input word of a length n, the space needed to process the word by the Turing machine is bounded by this linear function.
At this point, we provide the component the partially reversible reaction system A In . We start with defining the background set, S.
Let x be a maxðOðnÞÞ for an input word of the length n. Let us label all positions on the tape from 1 to x. We use these labels as indices of symbols in an alphabet, i.e., the a i means that the symbol a is on the i-th place of the tape. Because the simulation of one step of the Turing machine will take two steps done by the reaction system, we need to distinguish between them, and therefore we use the symbol a 0 i in every second step. The position of the reading-writing head is marked as a part of a symbol of a working set of a reaction system. If the head reads the i-th symbol of the tape, then there is the symbol a i in a working set. Let fa i ; a 0 i ; a i j i 2 f1; . . .; xg^a 2 Rg S: If the head of the TM performs a move, then we need to remove a bar from one symbol and add it to another one. A generated symbol a can be done because the special symbols M a or W a are present. Let fM a i ; W a i j i 2 f1; . . .; xg^a 2 Rg S: Finally, we add a set of symbols denoting the states of the TM to S, let fq; q 0 j q 2 Qg S: in the reaction set A, where y ¼ i þ d and i 2 f1; . . .n À 1g for d ¼ þ1, i 2 f2; . . .ng for d ¼ À1 and i 2 f1; . . .ng for d ¼ 0.
In the second step of the simulation, the reactions that are enabled rewrite the symbols with primes into the symbols without primes, and one special symbol corresponding to the position of the reading-writing head into bar symbol. Let these reactions be given as follows: The computation of the reaction system A In starts with C 0 ¼ fa 1 ; a 2 ; . . .; a n ; B nþ1 ; . . .; B x ; q 0 g where x ¼ a 1 . . .a n , and there is one reaction r having q 0 2 R r as well as x À 1 reactions in the form ðfa i g; fIg; fa 0 i gÞ; 2 i x in the set E 0 ¼ enðA; C 0 Þ. The next state of an interactive process W 1 is formed from prime symbols, i.e., the symbols on the tape and the state of the TM, and there is the symbol W a i (for the read-write rule) or M b y (for the shift rule) in the set W 1 . Because the TM is deterministic, there is only one such rule that can be executed.
The set W 1 enables the only subset of reactions of the S W or S M containing the state of the TM q 0 and the symbol for the head positioning in the set of reactants. For every symbol on the input tape, there is one reaction. If the position (index) of a symbol is different from the position of the head, then the prime symbol is evolved into a nonprime symbol. If the position is the position of the head, the prime symbol is changed to a bar symbol. In the case of the read-write rule, the symbol on the tape is changed as well. The set W 2 contains symbols with information about their position such that for every position, there is exactly one symbol (one of them has a bar) and a symbol for the current state of the TM.
We have to check whether the constructed reaction system, A In , is partially reversible. The first condition (P a \ I a ¼ ;) is met for all reactions. Because the inhibitor I is not used as a reactant or product in any reaction, the second and the third conditions of the definition are also met. The states of the reaction system are of two types. The first type of states corresponds to the configuration of the TM, i.e., the content of the tape with the position of the head is indicated by the bar symbol and the current state of the TM. The second type of states is associated with the configuration of the TM, that is, to every symbol on the tape, there is the prime symbol; it contains the symbol of the next state and a special symbol determining what should be done with the position of the head, and -in the case of the read-write rule -with the currently read symbol. Let c 1 and c 2 be two configurations of the TM having the same state, and let r 1 ¼ ðp 1 ; x 1 ; y 1 ; qÞ and r 2 ¼ ðp 2 ; x 2 ; y 2 ; qÞ be the rules that were used by the TM to enter these configurations. Because of the reversibility of the TM, if p 1 ¼ p 2 , then the rules cannot be shift rules and they must have y 1 6 ¼ y 2 and x 1 6 ¼ x 2 (it is a deterministic TM). The state of the TM and the symbol determining what action is done by the execution of a rule (M somewhere or W something ) uniquely identifies the rule that was used in the previous step of the computation. In consequence, it also determines a subset of all reactions that was enabled by the previous state of the TM. Because of the reversibility of the TM, this holds for the pair (a state, a symbol in the position of the head) too. Therefore, there is only one state W iÀ1 such that resðA; W iÀ1 Þ ¼ W i , and the fourth condition is fulfilled. As a result, the reaction system A In is partially reversible. The members of the input set for the inverse reaction system correspond to the final configurations of the TM. Hereby, the statement of the theorem holds.h

Conclusion
In this paper, we introduced the sP colonies without the input influence (during computation) and set the condition of the existence of the inverse sP colony to the SP colony. In the second part of the paper, we focused on the reaction systems that work in a way similar to sP colonies. For reaction systems, we showed that for every reversible reaction system, there exists the inverse reaction system. In the last part of the paper, reaction systems simulating reversible logic gates and reversible Turing machines were presented. In the future work, we plan not only to continue our investigations of the connections between the sP systems and reaction systems but also to study further properties of sP systems.
Funding Open access funding provided by Eötvös Loránd University.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons. org/licenses/by/4.0/.