Next Article in Journal
Driver Abnormal Expression Detection Method Based on Improved Lightweight YOLOv5
Next Article in Special Issue
Reducing the Length of Dynamic and Relevant Slices by Pruning Boolean Expressions
Previous Article in Journal
Secure Change Control for Supply Chain Systems via Dynamic Event Triggered Using Reinforcement Learning under DoS Attacks
Previous Article in Special Issue
Reduction of False Positives for Runtime Errors in C/C++ Software: A Comparative Study
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Modeling and Analyzing Reaction Systems in Maude

1
Dipartimento di Scienze Matematiche, Informatiche e Fisiche, Università degli Studi di Udine, 33100 Udine, Italy
2
Dipartimento di Scienze Economiche e Aziendali, Università di Sassari, 07100 Sassari, Italy
3
Dipartimento di Ingegneria dell’Informazione e Scienze Matematiche, Università di Siena, 53100 Siena, Italy
*
Author to whom correspondence should be addressed.
Electronics 2024, 13(6), 1139; https://doi.org/10.3390/electronics13061139
Submission received: 15 February 2024 / Revised: 7 March 2024 / Accepted: 15 March 2024 / Published: 20 March 2024
(This article belongs to the Special Issue Program Slicing and Source Code Analysis: Methods and Applications)

Abstract

:
Reaction Systems (RSs) are a successful computational framework for modeling systems inspired by biochemistry. An RS defines a set of rules (reactions) over a finite set of entities (e.g., molecules, proteins, genes, etc.). A computation in this system is performed by rewriting a finite set of entities (a computation state) using all the enabled reactions in the RS, thereby producing a new set of entities (a new computation state). The number of entities in the reactions and in the computation states can be large, making the analysis of RS behavior difficult without a proper automated support. In this paper, we use the Maude language—a programming language based on rewriting logic—to define a formal executable semantics for RSs, which can be used to precisely simulate the system behavior as well as to perform reachability analysis over the system computation space. Then, by enriching the proposed semantics, we formalize a forward slicer algorithm for RSs that allows us to observe the evolution of the system on both the initial input and a fragment of it (the slicing criterion), thus facilitating the detection of forward causality and influence relations due to the absence/presence of some entities in the slicing criterion. The pursued approach is illustrated by a biological reaction system that models a gene regulation network for controlling the process of differentiation of T helper lymphocytes.

1. Introduction

Reaction systems (RSs) [1,2] are a computational framework inspired by the functioning of living cells and by biochemistry. Their constituents are a finite set of entities (a background set) and a finite set of reactions. Each reaction is a triple that consists of a set of entities whose presence is needed to enable the reaction, called reactants; a set of entities whose absence is needed to enable the reaction, called inhibitors; and a set of entities that are produced when the reaction takes place, called products. All entities must be included in a fixed background set. Applications of RSs are very general and range from the modeling of biological phenomena [3,4,5] to molecular chemistry [6]. The classical behavior of RSs is defined as a rewriting system whose states are sets of entities (those produced at the previous step, possibly joined with others provided by an external context that models the interaction with the environment).

1.1. Problem Statement

The number of entities in the reactions and in the computation states can be large and difficult to verify for its correctness by the users. Thus, automated verification and debugging tools can be very helpful.
The design of RSs for modeling some natural phenomenon is often conducted by domain experts to validate their hypotheses and requires some degree of abstraction. False assumptions or inaccuracies may be introduced as early as the design stage. Moreover, writing reactions is an error-prone activity, and verifying their behavior can be difficult even for RSs with just a few dozens of entities and reactions. For example, if some mistake is made at the design level and some inexplicable result is observed during the simulation, then an analysis of the computation may be necessary to understand the nature of the problem.

1.2. The Approach

Program slicing is a traditional method used to circumscribe the key parts of a program that may be responsible for a specific unexpected outcome. Originally, slicing was defined as a static technique by [7]. Later, Ref. [8] expanded upon this concept by introducing dynamic program slicing, which aids in the debugging process by identifying—at runtime—those fragments of a program containing the flawed code. Dynamic program slicing has been applied to several programming paradigms (see Silva [9] for a survey).
The idea explored in this paper is to define and implement a novel dynamic slicing technique, which builds on top of a formal executable semantics for RSs, suitable for analyzing RS processes. Both the RS semantics and the slicing algorithm will be specified in Maude [10]: a high-level programming language and system based on the rewriting logic framework of [11]. Maude [12] supports functional, concurrent, logic, and object-oriented computations and provides equational rewriting and reasoning modulo user-defined equations and algebraic axioms such as associativity, commutativity, and identity. Maude is well-suited to specify software systems. In fact, a Maude specification combines a set of rewrite rules R, which specifies the state transitions of a system, with an equational theory E that specifies system states as terms of an algebraic data type. The equations in E are implicitly oriented from left to right as rewrite rules and operationally used as simplification rules to perform rewriting modulo equations and axioms.

1.3. Contribution

The main contributions of this paper are listed below.
  • We provide an elegant and concise Maude specification that rigorously formalizes an executable semantics for reaction systems. We also prove correctness of our implementation with regard to the usual set-theoretic reaction system characterization.
  • We apply the previous formalization to a biological model for gene regulation and we take advantage of the rich Maude development environment [12] to support and simplify the analysis phase. More specifically, we first illustrate how the Maude built-in search facility can be used to perform reachability analysis on the model. Then, we employ the ANIMA system [13]—a visual program explorer for Maude computations that we developed in a previous work—to provide an incremental view of the evolution of a reaction system. In ANIMA, system biologists can explore the computation space of RSs in a stepwise manner by expanding state transitions one at a time, thereby focusing on selected aspects of the biological processes.
  • By enriching the reaction system semantics, we also define a forward slicing algorithm for RSs and we formally prove its correctness. Forward slicing is a powerful tool to detect (forward) causality and influence relations among the entities produced in a biological model. It shows how (parts of) an initial input affect the production of (parts of) the output and helps estimate which input data need to be modified to accomplish a change in the outcome. Similarly to [2,14], our approach considers context-independent RSs (that is, RSs where the environment only provides a set of initial entities C 0 ). More precisely, our forward slicing methodology requires the user to select a subset C 0 of the initial input C 0 specifying the entities to be observed. Then, it proceeds by producing a computation that encodes two reaction system processes that progress in parallel: the original process that stems from C 0 and a secondary process (the sliced one) that originates from C 0 and that includes only the entities and reactions which are related to the partial input C 0 . This way, the two processes can be easily compared to detect errors and/or causality relations.
  • By applying our forward slicing technique to a gene regulation model, we show how computation states can be drastically reduced in size, favoring the system comprehension and detection of influence relations among entities.

1.4. Organization

In Section 2, we recall the basics of RSs. In Section 3, we introduce some preliminary notions on rewriting logic and Maude. We assume some basic knowledge of term rewriting [15] and some familiarity with the Maude language. In Section 4, we define a Maude specification that provides a precise execution model for RSs and we formally prove its correspondence with regard to the set-theoretic representation of reaction systems presented in Section 2. In Section 5, the Maude specification in Section 4 is used to explore and analyze an RS that specifies a gene regulation network. In Section 6, we first define a forward slicing algorithm for RSs and prove its correctness. Then, we show how our forward slicing method works in practice using the gene regulation example in Section 5. We discuss some related work in Section 7 and future work in Section 8, together with concluding remarks.

2. Reaction Systems

Let us recall some basic notions about reaction systems that are relevant to this work. For a full discussion on this topic, it is possible to consult [1,2].
An entity is a generic element (e.g., molecules, ions, atoms, and other chemicals) that may be present in biochemical reactions. Let S be a finite set of entities (the background set). A reaction in S is a triple ( R , I , P ) , where R, I, and P are finite sets of entities such that R , I , P S and R I = . The sets R, I, P, respectively, model sets of reactants, inhibitors, and products of the reaction. By r a c ( S ) , we denote the set of all reactions on S.
Informally, a reaction can take place whenever all of its reactants are present in a given state while none of its inhibitors are present. If this happens, the reaction is enabled and creates its products. More formally, given a set T S , a reaction a = ( R a , I a , P a ) is enabled by T, denoted e n a ( T ) , if and only if T R a and T I a = . The result (or outcome) of a on T is defined by
r e s a ( T ) = P a if   e n a ( T ) o t h e r w i s e
We assume that for each reaction ( R , I , P ) , R, I, and P are non-empty. This guarantees that, for each reaction a, there is always at least one product of a that is produced by at least one reactant of a. Note that, if an entity in a state is not sustained by at least one reaction which produces it, then it will disappear in the following state. This behavior reflects one of the core assumption of RSs, namely, the no permanency principle [2]. In other words, an entity from a current state vanishes unless it is produced by the system.
Given a set of reactions A r a c ( S ) and a set of entities T S , the result (or outcome) of A on T is a A r e s a ( T ) . This definition assumes that there is no conflict on the available resources. Indeed, RSs enjoy the threshold supply principle [2]: either an entity is present in the state and there is “enough” of it, or an entity is not present. To put it differently, two or more reactions that are enabled by T always generate their products, even if they share some entities, because there is always a sufficient amount of reactants in T to activate all the enabled reactions. Note that this assumption implies a major difference with standard models of concurrent systems, such as Petri nets.
Definition 1.
A reaction system (RS, in short) is a pair A = ( S , A ) such that S is a finite set of entities and A r a c ( S ) .
The dynamics of reaction systems is defined through the notion of interactive process, that is, a process that may react to external stimuli. More formally,
Definition 2.
Let A = ( S , A ) be a reaction system and let n 0 be an integer, an n-step interactive process in A is a pair π = ( γ , δ ) such that γ = C 0 , C 1 , , C n and δ = D 0 , D 1 , , D n where
1.
C i , D i S , for i = 0 , , n ;
2.
D 0 = ;
3.
D i = r e s A ( D i 1 C i 1 ) , for i = 1 , , n .
The sequence γ is called context sequence and represents the environment that may interact with the RS, while δ is the result sequence which is completely determined by reactions in A and contexts in γ .
It is worth noting that Definition 2 models reaction systems as open systems that may react to external inputs which are provided by the context sequence. Therefore, distinct context sequences may lead to distinct outcomes for the same RS A , as illustrated in the following example.
Example 1.
Let A = ( S , A ) be a RS such that S = { a , b , c } and A = { a 1 , a 2 } where
a 1 = ( { a , b } , { c } , { a } ) , a 2 = ( { a } , { b } , { c } ) .
Consider a three-step interactive process π = ( γ , δ ) where γ = C 0 , C 1 , C 2 with C 0 = { a , b } , C 1 = { c } and C 2 = { b } . Then, δ = D 0 , D 1 , D 2 = , { a } , { c } .
Now, consider the three-step interactive process π = ( γ , δ ) , where the context sequence γ = C 0 , C 1 , C 2 = { a , b } , { b , c } , { b } is a slight mutation of γ. Then, we obtain δ = D 0 , D 1 , D 2 = , { a } , .
Given an interactive process π = ( γ , δ ) such that γ = C 0 , C 1 , , C n and δ = D 0 , D 1 , , D n , we say that π is a context-independent process if C i D i , for i = 1 , , n . In this special case, the result sequence δ is completely determined by the initial context C 0 . More specifically, D 1 only depends on C 0 , and D i + 1 only depends on D i , with i = 1 , , ( n 1 ) . For this reason, we often denote a context-independent process as π = ( C 0 , δ ) .

3. Software Systems in Maude

The Maude system [10,12] is a formal language and tool set based on rewriting logic. Rewriting logic  [11] is a logical formalism that is based on two simple ideas: states of a system are represented as terms of an algebraic data type, specified in a Maude equational theory, and the behavior of a system is given by local transitions between states described by rewrite rules.
An equational theory specifies data types by declaring operators whose composition builds complex data structures from simpler ones. Maude equational theories are order-sorted: this means that operators have a typed structure over a set of sorts Γ , and there exists a (possibly empty) poset (Γ, <) that models subsort relations between the sorts in Γ . An operator f in an equational theory is specified in prefix notation by using the syntax op f : s 1 s n s , n 0 , where s 1 s n denotes the sequence of argument sorts (i.e., the arity of f ), and s is the sort of the return value (the keyword ops can be used to declare multiple operators with the same type structure: e.g., ops f g h : s 1 s 2 ). When the arity of f is the empty sequence, f is called constant. An operator can be specified in mixfix notation by using underscores as place holders for the input arguments (e.g., _ _ : s 1 s 2 s ). Binary operators may have attached an axiom declaration that specifies any combinations of algebraic laws such as associativity (assoc), commutativity (comm), and identity (id). By Ax , we denote the set of all axioms attached to the operators in the equational theory. Variables are introduced together with their sort by means of the keyword var for a single variable declaration or the keyword vars for multiple declarations on a single line.
Equations in an equational theory define functions that can be used in term simplification. A term is a variable or an application of an operator to a list of terms. Assuming the equations fully define all the specified functions, each term t has a canonical form (modulo Ax ), which is denoted by t E . The canonical form t E is obtained by using the equations, oriented left to right, to rewrite t (modulo Ax ) until no more rewrites are possible. Equations are specified by using the following syntax: eq l = r , where l and r are terms whose sorts belong to the same connected component of ( Γ , < ) . An equational theory E in Maude is specified by a functional module, which is delimited by keywords fmod and endfm , that contains sort, variable, operator and equation definitions.
Example 2.
The functional module of Listing 1 specifies an equational theory that models sets of entities. Line 4 defines three atomic entities via the constants a , b , c of sort Entity . Sets are terms of sort Entities whose form is e 1 e n , where each e i is a term of sort Entity . Sets are built using the associative and commutative operator _ _ with identity empty , plus the equation in Line 10 that models idempotence to allow for multiple occurrences of the same entity to be automatically simplified. The identity empty specifies the empty set. Note that, thanks to the subsort relation of Line 3, each term of sort Entity is also a term of sort Entities ; hence, atomic entities can be also interpreted as singletons.
Finally, Lines 11–12 provide an equational definition for the Boolean function isEmpty ( E ) that verifies whether the set E is empty. Note that the attribute owise in Line 12 applies the equation in Line 12 whenever equation in Line 11 cannot be applied (that is, when E is not empty).
Canonical forms of a term t in Maude can be computed via the red command, that simplifies t using the equations and axioms in the functional module. For instance,
Maude> red a b a a c .
reduce in ENTITYSET : a b a a c .
rewrites: 2 in 0ms cpu (0ms real) (2000000 rewrites/second)
result Entities: a b c
and
Maude> red isEmpty(a b a a c) .
reduce in ENTITYSET : isEmpty(a b a a c) .
rewrites: 3 in 0ms cpu (0ms real) (3000000 rewrites/second)
result Bool: false
Listing 1. An equational theory for modeling sets of entities.
 1 fmod ENTITYSET is
 2   sorts Entity Entities .
 3   subsort Entity < Entities .
 4   ops a b c : -> Entity .
 5   op empty : -> Entities .
 6   op __ : Entities Entities -> Entities [assoc comm id: empty] .
 7   op isEmpty : Entities -> Bool .
 8   var x : Entity .
 9   var E : Entities .
10   eq x x = x .
11   eq isEmpty(empty) = true .
12   eq isEmpty(E) = false [owise] .
13 endfm
A conditional rewrite rule is an expression of the form crl [ lbl ] l = > r if C , where lbl is a label that identifies the rule, l and r are terms whose sorts belong to the same connected component of ( Γ , < ) , and C is a (possibly empty) conjunction of Boolean expressions. When the condition C is empty, we simply write rl [ lbl ] : l = > r .
A rewrite theory R consists of an equational theory E plus a set of rewrite rules R. Rewrite theories in Maude are specified by system modules (delimited by keywords mod and endm ), which include a sequence of rewrite rules and one or more functional modules encoding a given equational theory. A rewrite theory is also called Maude specification.
Concurrent as well as nondeterministic software systems can be formalized through rewrite theories.
A software system, modeled as a rewrite theory, evolves by rewriting terms using equational rewriting, i.e., rewriting with the rewrite rules in R modulo the equations and axioms in E [11]. More precisely, (system) computations correspond to (possibly infinite) rewrite sequences t 0 r 0 R , E t 1 r 1 R , E , where t r R , E t denotes a transition (modulo E ) from term t to t via the rewrite rule of R that is uniquely labeled with r . The length of a finite computation C is the number of transitions it includes. Hence, the length of the computation t 0 r 0 R , E t 1 r n 1 R , E t n is n.
Note that each single transition t r R , E t is actually implemented as a rewrite chain t E ( t E ) r t , where the prefix t E t E is an equational simplification sequence that rewrites t into its canonical form t E using E ; then, t E is rewritten to t using a rewrite rule r in R. Although advisedly omitted in our notation, all rewrites in the chain (either applying r or any of the equations in E ) are performed modulo the equational axioms of E . Terms in a computations are also called states.
Example 3.
Consider the toy rewrite theory R t o y that is encoded in the Maude system module of Listing 2. R t o y includes the equational theory E t o y of Listing 1 via the import command pr at Line 2. E t o y is used to model states as sets of entities. The rewrite theory also contains three rewrite rules that allow for the current set (state) to be modified by removing an entity ( a , b or c ) from it. For instance, the following one-step computation can be produced in R t o y :
b b a c a del a R toy , E toy b c
which is implemented by first simplifying the initial state b b a c a into the canonical form a b c by using the equation eq x x = x , associativity and commutativity of the binary operator _ _ . Then, the rewrite rule del-a is applied to the canonical form a b c to obtain b c . In symbols, b b a c a E a b c del a b c
Listing 2. A toy rewrite theory.
1 mod TOY is
2   pr ENTITYSET .
3   var S : Entities .
4   rl [del-a] : (a S) => S .
5   rl [del-b] : (b S) => S .
6   rl [del-c] : (c S) => S .
7 endm
The transition space of all computations in R from the initial state t 0 can be represented as a computation tree T R ( t 0 ) whose branches specify all of the computations in R that originate from t 0 .

4. Formalizing Reaction Systems in Maude

In this section, we show how the set-theoretic representation of reaction systems of Section 2 can be encoded in Maude. More precisely, given an RS A , we formulate a rewrite theory R A that provides an executable model for A . We call R A the (Maude) encoding of A . To achieve this goal, we proceed in two steps. First, we formulate an equational theory E A that implements the basic data structures and functionality which are required to model system states. Subsequently, we introduce a set of rewrite rule R A , which acts on top of E A , to specify the system behavior of A .
For the sake of readability, this section only describes the main code snippets of our Maude encoding. For the full implementation, please visit [16].

4.1. The Equational Theory E A

Given a reaction system A = ( S , A ) , the equational theory E A defines the type structure of the components of A via the sorts and subsort relations of Listing 3.
Listing 3. The sorts and sort poset of E A .
1 sorts Bool Entity Entities Reaction Reactions Sequence MSequence State .
2 subsort Entity < Entities < Sequence < MSequence .
3 subsort Reaction < Reactions .
The equational theory E A is then populated with operators and equations that specify the building blocks of A = ( S , A ) according to the sort poset of Listing 3.
Assuming that E A includes a constant s of sort Entity for each entity s S , Listing 4 specifies the operators required to build the following data structures: set of entities, sequences of set of entities, and multisets of sequences of set of entities.
Listing 4. Equational definition for entities.
 1 var x : Entity .
 2 vars A B S S’ : Entities .
 3 --- Sets of entities
 4 op empty : -> Entities .
 5 op __ : Entities Entities -> Entities [ assoc comm id: empty ] .
 6 eq x x = x .
 7 op _in_ : Entity Entities -> Bool .
 8 eq x in (x A) = true .
 9 eq x in A = false [ owise ] .
10 op _subset_ : Entities Entities -> Bool .
11 eq empty subset A = true .
12 eq (x A) subset B = (x in B) and (A subset B) .
13 op intersection : Entities Entities -> Entities .
14 eq intersection(A,empty) = empty .
15 eq intersection(A,B) = $intersect(A, B, empty) .
16 op $intersect : Entities Entities Entities -> Entities .
17 eq $intersect(empty, S’, A) = A .
18 eq $intersect((x S), S’, A) = $intersect(S, S’, if x in S’ then (x A) else A fi) .
19 op isDisjoint : Entities Entities -> Bool .
20 eq isDisjoint(empty,A) = true .
21 eq isDisjoint((x A), B) = if x in B then false else isDisjoint(A,B) fi .
22 --- Sequences of set of entities
23 op _,_ : Sequence Sequence -> Sequence [ assoc ] .
24 op empty : -> Sequence .
23 --- Multisets of Sequences
24 op _+_ : MSequence MSequence -> MSequence [ comm assoc ] .
More specifically, a set of entities is specified as already illustrated in Example 2, that is, using the associative and commutative operator __ with identity empty and the idempotence equation of Line 5. Hence, a set of entities is either a term e 0 e 1 e n , with e i of sort Entity , or the constant empty. Furthermore, Listing 4 provides the equational definition of some usual functions that operate over sets and whose names are self-explanatory: insubsetintersection, and isDisjoint.
Sequences of sets of entities are specified via the associative infix operator _,_ and the constant empty . Non-empty sequences are thus terms of the form C 0 , C 1 , , C m , with C i of sort Entities , while empty denotes the empty sequence. Terms of sort Sequence will be used to define context sequences that feed reaction system processes.
Similarly, the commutative and associative operator _+_ defines multisets of sequences of sort MSequence; hence, several context sequences can be encoded in a single term of sort MSequence. Note that the subsort relations in Listing 3 allow for a single entity e to be interpreted as a set of entities, a sequence of sets of entities, and a multiset of sequences of sets of entities.
Reactions and their interaction with entities are specified by Listing 5.
Listing 5. Equational definition for reactions.
 1 vars R I P T : Entities .
 2 var a : Reaction .
 3 var As : Reactions .
 4 --- A reaction is a triple of terms of sort Entities
 5 op [_,_,_] : Entities Entities Entities -> Reaction .
 6 op _;_ : Reactions Reactions -> Reactions [assoc id: empty] .
 7 op empty : -> Reactions .
 8 op en : Reaction Entities -> Bool .
 9 eq en([R,I,P],T)  = (R subset T) and isDisjoint(I,T) .
10 op apply : Reaction Entities -> Entities .
11 eq apply([R,I,P],T) = if en([R,I,P],T) then P else empty fi .
12 op applyAll : Reactions Entities -> Entities .
13 eq applyAll(empty,T) = empty .
14 eq applyAll((a ; As),T) = apply(a,T) applyAll(As,T) .
15 op <_|_|_> : Reactions MSequence Entities -> Conf .
A reaction is a term of the form [R,I,P] of sort Reaction, where R , I , P are sets of entities that, respectively, identify reactants, inhibitors, and products of the specified reaction. Lists of reactions are then modeled by means of the associative infix operator _;_ that builds terms of sort Reactions. An empty list of reactions is specified by the constant empty . Again, note that any reaction is also a list of reactions by the subsort relation Reaction < Reactions.
The application of a reaction ( R , I , P ) on a given set of entities T is defined at an equational level by means of the function apply([R,I,P],T) (Lines 10–11) that returns P if the function call en([R,I,P],T) is evaluated to be true; otherwise, it returns empty. This is a direct and straightforward encoding of the notion of reaction activation that we presented in Section 2, which is based on the set operators of Listing 4. For instance, the enabling predicate e n a ( T ) , with a = ( R , I , P ) , is specified by the equation in Line 9 that verifies reactant inclusion R T via (R subset T) and absence of inhibitors I T = via isDisjoint(I,T). Therefore, given an RS A = ( S , A ) , a reaction a = ( R , I , P ) A and T S , the function apply([R,I,P],T) computes a term representing r e s a ( T ) .
The function applyAll ( A , T ) computes the set of entities r e s A ( T ) by applying all the reactions in the reaction list A to the set of entities encoded by the term T.
Example 4.
Consider the RS A = ( S , A ) of Example 1. Then, reactions in A are encoded by the term  [ a b,c,a ] ; [ a,b,c ]  and the function
applyAll([ a b,c,a ] ; [ a,b,c ], a b)
yields the term  a, which is the term encoding the unique product created by the reaction set A on { a , b } (in symbols, r e s A ( { a , b } ) = { a } ).
Finally, the ternary operator <_|_|_> in Listing 5 defines states of a reaction system as terms of sort State with form < A | M | D >, where A is a list of reactions, M is a multiset of context sequences, and D is a set of the entities that are currently present in the system. Roughly speaking, a term of sort State provides a snapshot of the whole configuration of the reaction system at a given time instant.

4.2. The Set of Rewrite Rules R A

The dynamics of a RS A = ( S , A ) involves state transitions orchestrated by the rewrite rules process and choice of Listing 6.
Listing 6. Rewrite rules of R A .
1 var A : Reactions .
2 vars C D : Entities .
3 vars Cs : Sequence .
4 var M : MSequence .
5 rl [choice] :   < A | Cs + M | D > => < A | Cs | D > .
6 rl [process] : < A | C,Cs | D > => < A | Cs | applyAll(A, C D) > .
The process rule implements state transitions obtained by reaction applications. More precisely, given a configuration < A | C,Cs | D > where A encodes a list of reactions, (C,Cs) is a term encoding a context sequence, and D encodes the set of entities currently present in the system state, process consumes the first context C of (C,Cs) and generates a new configuration < A | Cs | D > , where D encodes the set of entities obtained by applying the reactions specified by A to the set of entities C D encoded by the term (C D) (in symbols, D = applyAll(A, C D)).
It is worth noting that the process rule precisely captures the notion of interactive process of Definition 2, as stated by the following proposition:
Proposition 1.
Let A = ( S , A ) be an RS and let R A be the Maude encoding of A .
(i) 
If π = ( γ , δ ) is an n-step interactive process in A , n 0 , such that γ = C 0 , C 1 , , C n and δ = D 0 , D 1 , , D n , then there exists the computation C A of length n in R A
< A | C 0 , C 1 , , C n | empty > process R A , E A < A | C 1 , , C n | D 1 > < A | C n 1 | D n 1 > process R A , E A < A | C n | D n >
where C 0 , C 1 , , C n is a term encoding the context sequence C 0 , C 1 , , C n and D 0 , D 1 , , D n is a term encoding the result sequence D 0 , D 1 , , D n .
(ii) 
If
< A | C 0 , C 1 , , C n | empty > process R A , E A < A | C 1 , , C n | D 1 > < A | C n 1 | D n 1 > process R A , E A < A | C n | D n >
is a computation of length n in R A , n 0 , then there exists an n-step interactive process π = ( γ , δ ) in A , with γ = C 0 , C 1 , , C n , δ = , D 1 , , D n where C 0 , C 1 , , C n and empty , D 1 , , D n are the terms encoding the sequences C 0 , C 1 , , C n and , D 1 , , D n .
Proof. 
(i) Let A = ( S , A ) be an RS and let R A be the Maude encoding of A . Let π = ( γ , δ ) be an n-step interactive process in A such that n 0 , γ = C 0 , C 1 , , C n and δ = D 0 , D 1 , , D n . To prove the proposition, we proceed by induction on n.
n = 0 .
This case is straightforward. We have π = ( γ , δ ) = ( C 0 , D 0 ) = ( C 0 , ) and the initial state < A | C 0 | empty > , where C 0 is the term encoding C 0 and empty the term encoding D 0 . Now, it suffices to consider the computation in R A of length 0 that originates from < A | C 0 | empty > .
n > 0 .
Let π = ( γ , δ ) with γ = C 0 , , C n and δ = D 0 , , D n = , , D n be an n-step interactive process in A . We consider the ( n 1 ) -step interactive process π = ( γ , δ ) with γ = C 0 , , C n 1 and δ = D 0 , , D n = , , D n 1 . By induction hypothesis, there exists a computation C A of length ( n 1 ) in R A
C A = < A | C 0 , C 1 , , C n 1 | empty > process R A , E A < A | C 1 , , C n 1 | D 1 > < A | C n 2 , C n 1 | D n 2 > process R A , E A < A | C n 1 | D n 1 >
where C 0 , C 1 , , C n 1 is a term encoding the context sequence C 0 , C 1 , , C n 1 and D 0 , D 1 , , D n 1 is a term encoding the result sequence D 0 , D 1 , , D n 1 .
Now, observe that, for any state transition
< A | C i , C i + 1 , , C n 1 | D i > process R A , E A < A | C i + 1 , , C n 1 | D i + 1 >
that occurs in C A , there also exists the state transition
< A | C i , C i + 1 , , C n 1 , C n | D i > process R A , E A < A | C i + 1 , , C n 1 , C n | D i + 1 >
where C n is the term encoding the n-th context C n of γ . This is because the application of the process rule only consumes the head of the context sequence C i , , C n 1 ; thus, adding the context C n at the end of the current context sequence C i , , C n 1 does not alter (or disable) the rule application. Thus, we also have the following computation C A of length n 1 :
C A = < A | C 0 , C 1 , , C n 1 , C n | empty > process R A , E A < A | C 1 , , C n 1 , C n | D 1 > < A | C n 2 , C n 1 , C n | D n 2 > process R A , E A < A | C n 1 , C n | D n 1 >
where C 0 , C 1 , , C n 1 , C n is a term encoding the context sequence C 0 , C 1 , , C n 1 , C n and D 0 , D 1 , , D n 1 is a term encoding the result sequence D 0 , D 1 , , D n 1 .
To conclude the proof, just note that there exists the state transition
c n = < A | C n 1 , C n | D n 1 > process R A , E A < A | C n | D n >
since it is immediate to observe that the function call applyAll ( A , C n 1 D n 1 ) yields D n , which is the encoding of the result set D n in δ . Therefore, by concatenating the computation C A with the state transition c n , we obtain a computation C A such that
C A = < A | C 0 , C 1 , , C n | empty > process R A , E A < A | C 1 , , C n | D 1 > < A | C n 1 | D n 1 > process R A , E A < A | C n | D n >
where C 0 , C 1 , , C n is a term encoding the context sequence C 0 , C 1 , , C n and D 0 , D 1 , , D n is a term encoding the result sequence D 0 , D 1 , , D n .
(ii) Proof of (ii) is similar to (i) and proceeds by induction on the length n of the computation
< A | C 0 , C 1 , , C n | empty > process R A , E A < A | C 1 , , C n | D 1 > < A | C n 1 | D n 1 > process R A , E A < A | C n | D n >
Note that the reaction set A and the context sequence γ of an RS A totally determine any interactive process on A . In other words, when A and γ are fixed, there is only one computation of length n in R A that specifies an n-step interactive process on A .
The choice rule introduces non-determinism into reaction systems by allowing for multiple context sequences to be specified within a single state. By doing so, one has the possibility to feed a reaction system with distinct external inputs as already illustrated in Example 1. More specifically, given a state < A | Cs + M | D >, the choice rule non-deterministically selects a context sequence Cs within the multiset Cs + M, thereby yielding a new configuration < A | Cs | D > which only contains the selected context sequence Cs. Therefore, in this more general scenario, a computation in R A has typically the following form:
C A = < A | ( C 0 0 C n 0 ) + + ( C 0 m C n m ) | empty > choice R A , E A < A | ( C 0 i C n i ) | empty > process R A , E A < A | ( C 1 i C n i ) | D 1 i > process R A , E A < A | C n i | D n i >
with integers m 0 , i { 0 , , m } , n i 0 . Intuitively, the first state transition uses the choice rule to select a context sequence ( C 0 i C n i ) among the ones that are available in the initial state, and then the reaction system evolves, using its reactions and the selected context sequence, by repeatedly applying the process rule.
Example 5.
Consider the RS A = ( A , S ) of Example 1. Let R A be the Maude encoding of A .
Then, the two interactive processes π and π of Example 1 are, respectively, simulated by the following two computations in R A :
< [ a b , c , a ] ; [ a , b , c ] | ( a b , c , b ) + ( a b , b c , b ) | empty > choice R A , E A < [ a b , c , a ] ; [ a , b , c ] | ( a b , c , b ) | empty > process R A , E A < [ a b , c , a ] ; [ a , b , c ] | ( c , b ) | a > process R A , E A < [ a b , c , a ] ; [ a , b , c ] | b | c >
and
< [ a b , c , a ] ; [ a , b , c ] | ( a b , c , b ) + ( a b , b c , b ) | empty > choice R A , E A < [ a b , c , a ] ; [ a , b , c ] | ( a b , b c , b ) | empty > process R A , E A < [ a b , c , a ] ; [ a , b , c ] | ( b c , b ) | a > process R A , E A < [ a b , c , a ] ; [ a , b , c ] | b | empty >

5. Exploring Computations in a Reaction System

The Maude formalization of Section 4 provides a generic, abstract framework for the execution and exploration of computations in a reaction system. Arbitrary reaction systems as well as arbitrary external context sequences can be plugged into the framework and then analyzed using the tools available in the Maude ecosystem. In the following, we illustrate such Maude capabilities using a more realistic biological example.
Example 6.
Let us consider the RS A G R = ( S G R , A G R ) of [17] that models a network for gene regulation. Roughly speaking, these networks represent the interactions among genes regulating the activation of specific cell functions. The considered RS specifies a fragment of the network for controlling the process of differentiation of T helper lymphocytes, which play a fundamental role in the immune system. Entities in S G R represent genes, gene expression levels, and other functional molecules. High and medium expression levels for the same gene are specified by two distinct constants, e.g., tbeth and tbetm represent high expression level and medium expression level for the tbet gene, respectively. Listing 7 illustrates the list of the 32 reactions that specifies A G R .
Listing 7. Reactions for controlling the differentiation of T helper (Th) lymphocytes.
op GR : -> Reactions [ctor] .
eq GR = [ stat4 , irak s4ir tbeth, ifngammam ] ;
        [ tbetm, irak s4ir, ifngammam ] ;
        [ tbetm, s4ir tbeth, ifngammam ] ;
        [ stat4 tbetm , s4ir , ifngammam  ] ;
        [ stat4 tbetm, irak tbeth, ifngammam ] ;
        [ stat4 irak, empty, ifngammah ] ;
        [ tbeth, empty, ifngammah ] ;
        [ gata3, stat1h stat1m, il4 ] ;
        [ ifngammam, empty, ifngammarm ] ;
        [ ifngammah socs1, empty, ifngammarm ] ;
        [ ifngammah, socs1, ifngammarh ] ;
        [ il4, socs1, il4r ] ;
        [ il12, stat6, il12r ] ;
        [ il18, stat6, il18r ] ;
        [ ifnbeta, empty, ifnbetar ] ;
        [ ifnbetar, ifngammarh, stat1m ] ;
        [ ifngammarm, empty, stat1m ] ;
        [ ifngammarh, empty, stat1h ] ;
        [ il4r, empty, stat6 ] ;
        [ il12r, gata3, stat4 ] ;
        [ il18r, empty, irak ] ;
        [ stat1h, empty, socs1 ] ;
        [ stat1m, empty, socs1 ] ;
        [ tbeth, empty, socs1 ] ;
        [ tbetm, empty, socs1 ] ;
        [ stat6, tbeth tbetm, gata3 ] ;
        [ gata3, tbeth tbetm, gata3 ] ;
        [ tbetm, tbeth gata3 stat1h, tbetm ] ;
        [ stat1m, tbeth gata3 stat1h, tbetm ] ;
        [ tbeth, gata3, tbeth ] ;
        [ stat1h, gata3, tbeth ] ;
        [ il12r il18r, gata3, s4ir ] .
Given the Maude encoding R A G R of A G R , interactive processes can be directly generated in R A G R using the Maude built-in command rew , that produces rewrite sequences (computations) in R A G R . More specifically, the n-step interactive process π = ( γ , δ ) , with γ = C 0 , , C n and δ = D 0 , , D n is simulated in R A G R by executing the command rew [ n ] < GR | C 0 , , C n | empty > , where GR specifies the reactions in Listing 7.
Example 7.
Consider the following initial state
init = < GR | ifngammah , empty , empty , stat 1 h il 4 , empty , empty , empty | empty >
where the external input is provided by the first context ifngammah and the fourth context stat 1 h il 4 , while the remaining contexts are empty. Then, the command
Maude> rew [7] init .
rewrite [7] in RS : < GR | ifngammah,empty,empty,stat1h il4,empty,empty,empty |
                           empty > .
rewrites: 1626 in 0ms cpu (0ms real) (8603174 rewrites/second)
result State: < [stat4,irak s4ir tbeth,ifngammam] ;
                [tbetm,irak s4ir,ifngammam]
                 ...
                [il12r il18r, gata3,s4ir] |
                                    empty |
                 tbeth stat1m ifngammarm socs1 ifngammah >
generates a computation of length 7 that models a seven-step interactive process, whose final state contains the entities tbeth, stat1m, ifngammarm, socs1, ifngammah. In particular, we can observe that the provided context sequence enforces the presence of the tbet gene (entity t b e t h ) at step 7.
The Maude system is also endowed with a search facility that allows one to explore (following a breadth-first strategy) the reachable state space originating from an initial state. Reachability queries can be specified via the search command by means of the following syntax:
search [ n , m ] st = > sp such that Cond
where n , m are, respectively, (optional) upper bounds on the number of solutions to be found and the depth of the search, st is an initial state, sp is a state pattern that models the form of the terms that must be reached, cond is an optional Boolean condition that must be satisfied by the reached states. When there is no condition, the syntax is simplified in search [ n , m ] st = > sp . A solution of the reachability query (1) is any computation from the initial state st to a state st that matches the pattern sp and meets the condition Cond .
Example 8.
Consider the initial state init of Example 7 whose initial context includes ifngammah . The following reachability query
search [ 1 , 7 ] init = > < Rs : Reactions | Cs : Sequence | tbetm T : Entities >
verifies whether there exists a computation (up to length 7) that starts from init and reaches a state that contains the entity tbetm in its products. The outcome of the query is the following:
No solution.
states: 7  rewrites: 1625 in 0ms cpu (0ms real) (5584192 rewrites/second)
Since there is no solution, we can derive that we cannot reach a medium gene expression level for tbet ( tbetm ), if we start from an initial context that includes a highly expressed gene ifngamma ( ifngammah ) using the context sequence encoded in init .
On the contrary, from ifngammah , we are always able to reach tbeth , as witnessed by the execution of the following reachability query:
search [ 1 , 7 ] init = > < Rs : Reactions | Cs : Sequence | tbeth T : Entities >
whose solution is
Solution 1 (state 3)
states: 4  rewrites: 788 in 0ms cpu (0ms real) (4581395 rewrites/second)
Rs --> [stat4,irak s4ir tbeth,ifngammam] ;
       [tbetm,irak s4ir,ifngammam] ;
       ...
       [il12r il18r,gata3,s4ir]
Cs --> stat1h il4,empty,empty,empty
T:Entities --> socs1
Therefore, starting from init , the system evolves to a state that contains tbeth and socs 1 in exactly four steps.
Although Maude rew and search commands are two powerful tools for the execution and exploration of reaction systems, they definitely lack a user-friendly interface that facilitates the inspection of reaction system behavior. A valid solution to this problem is offered by the ANIMA system [13]—a visual program explorer for Maude computations that we developed in a previous work. In ANIMA, system biologists can explore the computation space of RSs in a stepwise manner by expanding state transitions one at a time with a simple point-and-click interface, thereby producing anincremental visual representation of the whole computation tree with regard to a given initial state. Let us see an example.
Example 9.
Consider the Maude encoding R A G R of A G R together with the following initial state:
init = < GR | ifngammah , empty , empty , empty , empty + ifngammam , empty , empty , empty , empty | empty >
that includes two distinct context sequences, respectively, modeling a high gene expression level ifngammah and a medium gene expression level ifngammam in their initial contexts. By feeding  ANIMA  with R A G R and init , we can interactively generate the computation tree with regard to init by clicking on the node tree to be expanded. Figure 1a zooms into the first (non-deterministic) transition that applies the choice rule to select one of the two context sequences available in init , while Figure 1b illustrates a partial expansion of the two possible evolutions of the system that depend on the chosen context sequence.
Note that the reader can fully reproduce this example by simply accessing  ANIMA  at the  http://safe-tools.dsic.upv.es/anima, (accessed on 14 March 2024) and selecting  Gene-Regulation-RS  from the list of pre-loaded examples.
As witnessed by Example 9, computations in a Maude specification R A can be textually large, hindering the comprehension and analysis of the reaction system behavior. The next section specifies a forward slicing technique that drastically reduces the complexity of system computations and facilitates the detection of causality relations in context-independent processes.

6. Forward Slicing of Context-Independent Processes

In this section, we present a forward slicing technique for context-independent processes. Although the generalization of the proposed slicing technique to generic interactive processes is not technically difficult, we prefer to focus on context-independent processes, since their behavior is totally defined by a single input context C 0 and having such a limited input allows one to precisely study the forward causalities of a reaction system. This approach is also advocated by [2], where a rigorous notion of minimal influence distance between entities is formalized within all possible context-independent state sequences.
Given a reaction system A = ( S , A ) and a context-independent process π = ( C 0 , δ ) in A , with δ = D 0 , , D n , forward slicing aims at producing a partial view of π that only depends on a selected subset C 0 of C 0 which is called slicing criterion. Forward slicing allows one to evaluate the impact of a set of input entities across the whole process, thereby giving answers to questions such as does the presence (or the absence) of an entity e in the slicing criterion affect the production of the entity e in a later stage of π?
The forward slicing of context-independent processes can be specified by a rewrite theory R A that slightly modifies and improves the Maude encoding R A of Section 4. R A includes an extended version E A of the equational theory E A that provides a richer algebraic data type for system states, as well as a new set of rewrite rules R A that implements an augmented reaction system semantics that models both a context-independent process and its sliced counterpart. We say that R A is the forward slicing encoding for A . In the following, we present the main data structures and core functions included in R A . The full specification is available at [16].

6.1. The Equational Theory E A

The code snippet in Listing 8 illustrates the key modifications introduced by E A , with respect to E A .
Listing 8. Equational theory E A : main changes with regard to E A .
 1 sort Result .
 2 op {_|_} : Reactions Entities -> Result .
 3 vars A A’ : Reactions .
 4 var Res : Result .
 5 vars P P’ T : Entities .
 6 op fail : -> Reaction .
 7 op apply : Reaction Entities -> Reaction .
 8 eq apply([R,I,P],T) = if en([ R,I,P],T) then [ R,I,P ] else fail fi .
 9 op applyAll+ : Reactions Entities -> Result .
10 eq applyAll+(A,T) = $applyAll(A,T,{ empty | empty }) .
11 op $applyAll : Reactions Entities Result -> Result .
12 eq $applyAll(empty,T,Res) = Res .
13 eq $applyAll(([ R,I,P ] ; A), T , { A’ | P’ }) =
14          $applyAll(A, T, if apply([ R,I,P ],T) =/= fail  then
15                                   {[ R,I,P ] ; A’ | P P’}
16                            else
17                                   { A’ | P’ }
18                            fi
19                    ) .                     
20 op <_|_|_|_|_> : Reactions Entities Reactions Entities Reactions -> State .
21 op +<_|_> : Reactions Entities -> State .
22 op -<_|_> : Reactions Entities -> State .
Roughly speaking, E A extends E A into two main directions.
Firstly, the function applyAll ( A , T ) in E A , which computes the set of entities r e s A ( T ) , has been replaced by the function applyAll + ( A , T ) (see Lines 9–19 of Listing 8) whose resulting outcome is now a pair { A | T } that keeps track of both the entities T produced by applying A on T and the sublist of reactions A which only includes the reactions of A that are enabled by T and thus are responsible for the production of T . Note that, to implement this extension, we also need to slightly modify the function apply ( [ R , I , P ] , T ) (Lines 7–8), which now uses the special constant fail to explicitly signal that the reaction [ R , I , P ] cannot be applied to T . Let us see an example.
Example 10.
Consider the RS A G R = ( S G R , A G R ) of Example 6, whose reaction list is specified by the term GR . The execution of the function call applyAll + ( GR , stat 1 h gata 3 ) yields the following outcome:
Maude> red applyAll+(GR,stat1h gata3) .
reduce in FORWARDSLICER-RS : applyAll+(GR, gata3 stat1h) .
rewrites: 341 in 0ms cpu (0ms real) (341000000 rewrites/second)
result Result: {[gata3,tbeth tbetm,gata3] ; [stat1h,empty,socs1] |
         gata3 socs1}
which shows that only two reactions of GR (out of 32) are enabled by stat 1 h and gata 3 , thereby creating the new entities gata 3 and socs 1 .
Secondly, E A refines the notion of state, which we introduced in E A , by means of three novel operators (Lines 20–22) that allow system states to have multiple forms. A system state now can be
  • A term of the form < A | D | Au | D | Au > , where A , Au , Au are terms of sort Reactions and D and D are terms of sort Entities . Intuitively, a state of this form stores the current configuration of a context-independent process together with its sliced counterpart. More formally, given a reaction list A , D represents the entities which are currently present in the system, and Au is a list of reactions —included in A — that have been used to produce D . Similarly, D is the set of entities currently observed in the sliced counterpart that were produced by using the reactions in Au .
  • A term of the form < A | P > , where A is a term of sort Reactions and P is a term of sort Entities . This data structure is used to extract, from the current state, the entity set P of those entities that cannot be computed from the slicing criterion C 0 since the reactions in A did not take place. In other words, this state highlights the missing entities, that is, those entities that can be computed from the initial context C 0 but cannot be computed from the slicing criterion C 0 .
  • A term of the form + < A | P > , where A is a term of sort Reactions and P is a term of sort Entities . This data structure is used to extract, from the current state, the entity set P of those entities that can be only computed from the slicing criterion C 0 since the reactions in A did not take place in the original process. Put differently, this state identifies the spurious entities, that is, those entities that can be computed from the slicing criterion C 0 but cannot be computed from the initial context C 0 . Generation of spurious entities is typically caused by the absence of one or more inhibitors in C 0 that are instead present in C 0 . This fact allows for a given reaction to take place in the sliced process, but it is blocked in the original process.

6.2. The Set of Rewrite Rules R A

The forward slicing algorithm of context-independent processes is implemented by the three rewrite rules of Listing 9.
Listing 9. Rewrite rules of R A .
 1 vars D D’ D-new D-new’ : Entities .
 2 vars A Au Au’ Au-new Au-new’ : Reactions .
 3 crl [process-fs] : < A | D | Au | D’ | Au’ > =>
 4                    < A | D-new | Au-new Au | D-new’ | Au-new’ Au’ > if
 5                        { Au-new’ | D-new’ } := applyAll+(A,D’) /\
 6                        { Au-new  | D-new } := applyAll+(A,D) .
 7 rl [slice+] : < A | D | Au | D’ | Au’ > => +< (Au’ \ Au) | D’ \ D > .
 8 rl [slice-] : < A | D | Au | D’ | Au’ > => -< (Au \ Au’) | D \ D’ > .
The process-fs rule is the backbone of the whole forward slicing algorithm. It allows the system to transition from a state
< A | D i | Au i | D i | Au i >
to a state
< A | D i + 1 | Au i + 1 | D i + 1 | Au i + 1 >
where
  • A is a reaction list that models the reactions in the RS A = ( S , A ) ;
  • D i + 1 is a term encoding the set of entities obtained by applying the reaction list A on the set of entities encoded by D i ;
  • Au i + 1 is a reaction list that contains all and only the reactions used to produce D i + 1 ;
  • D i + 1 is a term encoding the set of entities obtained by applying the reaction list A on the set of entities encoded by D i ;
  • Au i + 1 is a reaction list that contains all and only the reactions used to produce D i + 1 ;
Note that the process fs rule uses the function applyAll + to generate the entities and reactions at step ( i + 1 ) by exploiting the information at step i.
In this scenario, all the computations of the form
< A | C 0 | empty | C 0 | empty > process fs R A , E A process fs R A , E A < A | D n | A n | D n | A n >
define two context-independent processes in A that evolve concurrently: π = ( C 0 , δ ) , with δ = D 0 , , D n and π = ( C 0 , δ ) , with δ = D 0 , , D n . When C 0 C 0 , we say that π is a sliced version of π . Basically, a sliced version π of π encodes the behavior of an RS A on the reduced set of input entities specified by the slicing criterion C 0 .
Proposition 2.
Let A = ( S , A ) be an RS and let R A be the forward slicing encoding of A . Let C 0 , C 0 be two sets of entities such that C 0 C 0 . Let C 0 and C 0 be two terms, respectively, encoding C 0 and C 0 . If
< A | C 0 | empty | C 0 | empty > process fs R A , E A < A | D 1 | A 1 | D 1 | A 1 > < A | D n 1 | A n 1 | D n 1 | A n 1 > process fs R A , E A < A | D n | A n | D n | A n >
is a computation of length n in R A , n 0 , then there exist two n-step context-independent processes π = ( C 0 , δ ) , with δ = D 0 , , D n and π = ( C 0 , δ ) , with δ = D 0 , , D n such that D 0 , , D n and D 0 , , D n are the terms encoding the result sequences D 0 , , D n and D 0 , , D n . and π is a sliced version of π.
Proof. 
The proof is by induction on the length n of the computation
C n = < Rs | C 0 | empty | C 0 | empty > process fs R A , E A < A | D 1 | A 1 | D 1 | A 1 > < A | D n 1 | A n 1 | D n 1 | A n 1 > process fs R A , E A < A | D n | A n | D n | A n >
n = 0 .
This case is trivial. The computation C 0 does not include any rewrite step and thus leaves the initial state < Rs | C 0 | empty | C 0 | empty > unchanged. Note that this state encodes two 0-step context-independent processes: π 0 = ( C 0 , δ 0 ) , with δ 0 = D 0 = and π 0 = ( C 0 , δ 0 ) , with δ 0 = D 0 = .
n > 0 .
By inductive hypothesis, there is a computation of length n 1
C n 1 = < Rs | C 0 | empty | C 0 | empty > process fs R A , E A < A | D 1 | A 1 | D 1 | A 1 > < A | D n 2 | A n 2 | D n 2 | A n 2 > process fs R A , E A < A | D n 1 | A n 1 | D n 1 | A n 1 >
such that there exist two ( n 1 ) -step context-independent processes π n 1 = ( C 0 , δ n 1 ) , with δ = D 0 , , D n 1 , and π n 1 = ( C 0 , δ n 1 ) , with δ = D 0 , , D n 1 , where D 0 , , D n 1 , and D 0 , , D n 1 are the terms that encode the result sequences D 0 , , D n 1 and D 0 , , D n 1 , respectively. Furthermore, π n 1 is a sliced version of π n 1 .
Observe also that it is always possible to perform the rewrite step
r = < A | D n 1 | A n 1 | D n 1 | A n 1 > process fs R A , E A < A | D n | A n | D n | A n >
which uses the function applyAll+ to generate D n and D n from D n 1 and D n 1 . Since D n 1 and D n 1 are the terms encoding the set of entities D n 1 and D n 1 , we have that D n and D n are the terms encoding the set of entities D n and D n . Therefore, to prove the proposition, it suffices to consider the computation C n of length n that concatenates the computation C n 1 with the rewrite step r. □
While the process-fs rule formalizes system progress in R A , the slice and slice + rules extract specific pieces of information from a given computation state st that allow for the original process π and its sliced counterpart π to be compared on st .
More precisely, given a state st = < A | D i | A i | D i | A i > , the slice rule uses the set difference operator (To be more precise, ∖ is an overloaded operator that can be applied to both entity sets and reaction lists.)\ to compute the new state < ( A i \ A i ) | D i \ D i > that isolates
  • The entities ( D i \ D i ) in st that can be computed in (the i-th step of) π but not in (the i-th step of) π .
  • The reactions ( A i \ A i ) in st that were enabled in π but not in π until the i-th step.
Note that ( A i \ A i ) represents the reason of the missing information ( D i \ D i ) : in other words, entities encoded by ( D i \ D i ) cannot be produced in the i-th step of π because reactions ( A i \ A i ) were never enabled in π up to the i-th step.
Dually, the slice + computes the new state + < ( A i \ A i ) | D i \ D i > that isolates:
  • The entities ( D i \ D i ) in st that can be computed in (the i-th step of) π but not in (the i-th step of) π .
  • The reactions ( A i \ A i ) in st that were enabled in π but not in π until the i-th step.
Intuitively, slice + collects the spurious entities ( D i \ D i ) of st , that is, those entities of st computed in π by using the reactions ( A i \ A i ) that are not enabled in π (up to the i-th step).
It is worth noting that, all the three rules process-fs, slice , and slice + can be non-deterministically applied to each system state. Therefore, at each state, the system can (i) evolve via the process-fs rule, (ii) compute the missing entities in π by applying slice , or (iii) compute the spurious entities by applying slice + . Let us see an example.
Example 11.
Let A G R = ( S G R , A G R ) be the RS of Example 6. Let C 0 = { ifngammh , g a t a 3 } be an initial context and let C 0 = { ifngammah } be a slicing criterion for C 0 . Given the initial state
init = < GR | C 0 | empty | C 0 | empty >
where GR is the reaction list encoding the 32 reactions in A G R , C 0 and C 0 are terms encoding C 0 and C 0 , the (fragment of the) computation tree T R A G R ( init ) of Figure 2 can be computed in R A G R . Note that each tree level i (except for the root level) contains three states:
(i) 
The current state s i which is produced by the application of the  process-fs  rule on the previous state s ( i 1 ) ;
(ii) 
Two states s ( i 1 ) and s ( i 1 ) + that specify the states which are computed by, respectively, applying the  slice-  and  slice+  rules to the state s ( i 1 ) .
Compact state views, which are produced by  slice-  and  slice+, allow one to immediately grasp what is going on in the process and its sliced counterpart.
For instance, by inspecting all the applications of  slice+  in the tree, we can immediately note that only state s 3 introduces a spurious entity (up to level 3); concretely, the entity  tbeth  which appears in the state
s3+ = +< [stat1h,gata3,tbeth] | tbeth >
Hence, we can infer that the gene expression tbeth can be computed for the slicing criterion C 0 but not for the full initial context C 0 in the considered tree fragment. Indeed, the reaction  [stat1h,gata3,tbeth], which occurs in s 3 + , is enabled in the sliced process π but not in the original one π. Since gata 3 belongs to C 0 but not to C 0 , we can safely say that gata 3 blocks the creation of tbeth in π.
Also, by looking at the applications of the  slice-  rule, we can easily detect the information that the slicing criterion C 0 cannot produce for a given computation state. For example, the state s 3 tells us that gata 3 , il 4 r , and stat 6 are missing entities that cannot be created in the sliced process π that reaches state s 3 . This is due to the fact that reactions  [gata3,tbeth tbetm,gata3],  [il4r,empty,stat6], and  [il4,socs1,il4r]  take place only in π but not in π .
Finally, note that theANIMAsystem, which we presented in Section 5, can also be used to interactively execute the proposed forward slicing algorithm, allowing system biologists to visually explore system states and their associated compact views in a more user-friendly and incremental way. In this regard, Figure 3 illustrates the generation of the computation tree of Figure 2 withinANIMA. To reproduce this experiment, the reader can accessANIMAat thehttp://safe-tools.dsic.upv.es/anima(accessed on 14 March 2024) and select Forward Slicing of Gene-Regulation-RS from the list of pre-loaded examples.
Figure 2. Fragment of the computation tree T R A G R ( init ) .
Figure 2. Fragment of the computation tree T R A G R ( init ) .
Electronics 13 01139 g002
Figure 3. Forward slicing of context-independent processes in ANIMA.
Figure 3. Forward slicing of context-independent processes in ANIMA.
Electronics 13 01139 g003

7. Related Work

Several tools are already available to simulate RSs or to verify that certain properties are met. In [18,19], some authors developed BioReSolve [20]: a PROLOG interpreter for reaction system analysis. The verification capabilities integrated into BioReSolve have been crafted from scratch. In contrast, our approach offers a rewriting-based modeling of RSs, leveraging the extensive functionalities of the Maude environment, which provides multiple built-in functions and third-party tools for program analysis. Other implementations of RSs include brsim [21], a Basic Reaction System Simulator written in Haskell and distributed under the terms of GNU GPLv3 license [22] whose online version WEBRSIM makes all the features of brsim available through a friendly web interface [23]; HERESY [24], a GPU-based Highly Efficient REaction SYstem simulator, that exploits the large number of computational units inside GPUs to boost performance [25]; cl-rs [26], an optimised Common Lisp simulator for RSs presented in [27].
Model checking has been deeply studied in the context of reaction systems. [28] defines rsCTL, a temporal logic for reaction systems. The logic is interpreted over the models for the context-restricted reaction systems that generalize standard reaction systems by controlling context sequences. In [29,30], a variant of Linear Time Temporal Logic that is interpreted over models of reaction systems with discrete concentrations is presented: the approach adopts a suitable encoding in SMT together with bounded model checking for the formal verification of temporal properties over RSs. The verification technique has been implemented into the ReactICS system [31]. A more theoretical work that investigates model checking of reaction systems through computational complexity lenses is also presented in [32]. This work provides several complexity results for decision procedures related to properties of central interest in biomodeling (e.g., mass conservation, steady states, stationary processes).
We believe that model-checking and (trace and program) slicing may be successfully combined together to improve the analysis and comprehension of counter-examples generated by model-checkers when properties of interest are refuted.
Notably, the Maude language has already been successfully used in the analysis of biological systems. For instance, Pathway Logic [33] is a symbolic approach to the modeling and analysis of biological systems that is implemented in Maude. This logical framework allow metabolic pathways to be simulated and formally verified.
Dynamic program slicing has been applied previously to other programming paradigms, such as imperative programming [8], functional programming [34], and term rewriting and its extensions [35,36]. None of these approaches are suitable for RSs, which have a completely different computation behavior based on the non-monotonic enabling mechanism of reactions. In [37], we extended BioReSolve with a slicing algorithm which proceeds backwards. Some entities in the last state of a computation of an RS are selected and then the algorithm proceeds backwards, simplifying the computation and leaving only the entities which are essential to derive the selected ones. Unfortunately, this way we cannot know in advance which entities of the initial state of the computation will be left in the backward sliced computation. In this paper, we define a dual forward slicing algorithm in which we observe some entities in the initial state and we proceed forward. The two (backward and forward) slicing methodologies clearly derive different information as they focus on input information from different states and apply different algorithms. While the forward slicing results in a form of impact analysis that identifies the scope and potential consequences of changing the program input, backward slicing allows for provenance analysis to be performed in search of the origins of the selected entities.

8. Conclusions and Future Work

In this paper, we have defined the first implementation of reaction systems in Maude, a language based on rewriting logic, which has a very well-developed environment with tools for program analysis and verification. Our Maude implementation provides an interpreter for RSs that supports exploration capabilities via Maude built-in commands as well as third-party systems such as the ANIMA system. Also, we have defined an algorithm for forward slicing of context-independent processes. Our implementation of forward slicing gives a parallel execution of the standard and the sliced computation, so that users can compare each state of the original computation with the corresponding sliced one, and obtain useful information to analyze and possibly debug RS processes. To evaluate the feasibility and usefulness of the proposed approach, our forward slicing algorithm has been used to analyze an example of a gene regulatory network.
As future work, we want to study the combination of the forward slicing algorithm with the backward one which we have defined in [37]. We believe that this integration can improve the quality of the analysis, allowing for more erroneous/unexpected behaviours to be detected. We also want to extend the forward slicing algorithm to a language for concurrent multiparty communications [38], and investigate possible extensions that exploit static analysis techniques [39,40,41] as well as dynamic verification methodologies [42,43].

Author Contributions

Methodology, D.B., L.B. and M.F.; Investigation, D.B., L.B. and M.F.; Writing—original draft, D.B., L.B. and M.F.; Writing—review & editing, D.B., L.B. and M.F. All authors have read and agreed to the published version of the manuscript.

Funding

This research has been partially supported by the Italian MUR PRIN 2022 project “MEDICA” (2022RNTYWZ), by the Italian MUR PRIN PNRR 2022 project “DELICE” (P20223T2MF), by the Next Generation EU programme project PNRR ECS00000017—“THE—Tuscany Health Ecosystem”—Spoke 3—CUP I53C22000780001, and by the Department Strategic Plan (PSD) of the University of Udine-Interdepartmental Project on Artificial Intelligence (2021-25).

Data Availability Statement

The data presented in this study are available in this article.

Acknowledgments

We thank the anonymous reviewers for their careful reading of the paper and suggestions that helped us to improve our paper.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Ehrenfeucht, A.; Rozenberg, G. Reaction Systems. Fundam. Informaticae 2007, 75, 263–280. [Google Scholar]
  2. Brijder, R.; Ehrenfeucht, A.; Main, M.G.; Rozenberg, G. A Tour of Reaction Systems. Int. J. Found. Comput. Sci. 2011, 22, 1499–1517. [Google Scholar] [CrossRef]
  3. Azimi, S.; Iancu, B.; Petre, I. Reaction System Models for the Heat Shock Response. Fundam. Informaticae 2014, 131, 299–312. [Google Scholar] [CrossRef]
  4. Corolli, L.; Maj, C.; Marini, F.; Besozzi, D.; Mauri, G. An excursion in reaction systems: From computer science to biology. Theor. Comput. Sci. 2012, 454, 95–108. [Google Scholar] [CrossRef]
  5. Azimi, S. Steady States of Constrained Reaction Systems. Theor. Comput. Sci. 2017, 701, 20–26. [Google Scholar] [CrossRef]
  6. Okubo, F.; Yokomori, T. The computational capability of chemical reaction automata. Nat. Comput. 2016, 15, 215–224. [Google Scholar] [CrossRef]
  7. Weiser, M. Program slicing. IEEE Trans. Softw. Eng. 1984, 10, 352–357. [Google Scholar] [CrossRef]
  8. Korel, B.; Laski, J. Dynamic Program Slicing. Inf. Process. Lett. 1988, 29, 155–163. [Google Scholar] [CrossRef]
  9. Silva, J. A Vocabulary of Program Slicing-based Techniques. ACM Comput. Surv. 2012, 44, 12:1–12:41. [Google Scholar] [CrossRef]
  10. Durán, F.; Eker, S.; Escobar, S.; Martí-Oliet, N.; Meseguer, J.; Rubio, R.; Talcott, C.L. Programming and symbolic computation in Maude. J. Log. Algebr. Methods Progr. 2020, 110, 100497. [Google Scholar] [CrossRef]
  11. Meseguer, J. Conditional Rewriting Logic as a Unified Model of Concurrency. Theor. Comput. Sci. 1992, 96, 73–155. [Google Scholar] [CrossRef]
  12. Clavel, M.; Durán, F.; Eker, S.; Escobar, S.; Lincoln, P.; Martí-Oliet, N.; Meseguer, J.; Rubio, R.; Talcott, C. Maude Manual (Version 3.2.1); Technical Report; SRI International Computer Science Laboratory: Menlo Park, CA, USA, 2022; Available online: https://maude.lcc.uma.es/maude321-manual-html/maude-manual.html (accessed on 14 March 2024).
  13. The Anima Website. 2015. Available online: http://safe-tools.dsic.upv.es/anima (accessed on 14 March 2024).
  14. Brijder, R.; Ehrenfeucht, A.; Rozenberg, G. A Note on Causalities in Reaction Systems. Electron. Commun. EASST 2010, 30, 1–9. [Google Scholar]
  15. TeReSe. Term Rewriting Systems; Cambridge University Press: Cambridge, UK, 2003. [Google Scholar]
  16. The RS-MAUDE System. 2024. Available online: https://github.com/DemisGIT/RSMaude (accessed on 14 March 2024).
  17. Barbuti, R.; Gori, R.; Milazzo, P. Encoding Boolean Networks into Reaction Dystems for Investigating Causal Dependencies in Gene Regulation. Theor. Comput. Sci. 2021, 881, 3–24. [Google Scholar] [CrossRef]
  18. Brodo, L.; Bruni, R.; Falaschi, M. Enhancing Reaction Systems: A Process Algebraic Approach. In Art of Modelling Computational Systems; Lecture Notes in Computer Science; Springer: Berlin/Heidelberg, Germany, 2019; Volume 11760, pp. 68–85. [Google Scholar] [CrossRef]
  19. Brodo, L.; Bruni, R.; Falaschi, M. A logical and graphical framework for reaction systems. Theor. Comput. Sci. 2021, 875, 1–27. [Google Scholar] [CrossRef]
  20. The BioReSolve System. 2021. Available online: http://www.di.unipi.it/~bruni/LTSRS/ (accessed on 14 March 2024).
  21. The brsim System. 2014. Available online: https://github.com/scolobb/brsim/ (accessed on 14 March 2024).
  22. Azimi, S.; Gratie, C.; Ivanov, S.; Petre, I. Dependency graphs and mass conservation in reaction systems. Theor. Comput. Sci. 2015, 598, 23–39. [Google Scholar] [CrossRef]
  23. Ivanov, S.; Rogojin, V.; Azimi, S.; Petre, I. WEBRSIM: A Web-Based Reaction Systems Simulator. In Enjoying Natural Computing—Essays Dedicated to Mario de Jesús Pérez-Jiménez on the Occasion of His 70th Birthday; Lecture Notes in Computer Science; Díaz, C.G., Riscos-Núñez, A., Paun, G., Rozenberg, G., Salomaa, A., Eds.; Springer: Berlin/Heidelberg, Germany, 2018; Volume 11270, pp. 170–181. [Google Scholar] [CrossRef]
  24. The HERESY System. 2017. Available online: https://github.com/aresio/HERESY (accessed on 14 March 2024).
  25. Nobile, M.S.; Porreca, A.E.; Spolaor, S.; Manzoni, L.; Cazzaniga, P.; Mauri, G.; Besozzi, D. Efficient Simulation of Reaction Systems on Graphics Processing Units. Fundam. Informaticae 2017, 154, 307–321. [Google Scholar] [CrossRef]
  26. The cl-rs System. 2020. Available online: https://github.com/mnzluca/cl-rs (accessed on 14 March 2024).
  27. Ferretti, C.; Leporati, A.; Manzoni, L.; Porreca, A.E. The Many Roads to the Simulation of Reaction Systems. Fundam. Informaticae 2020, 171, 175–188. [Google Scholar] [CrossRef]
  28. Meski, A.; Penczek, W.; Rozenberg, G. Model Checking Temporal Properties of Reaction Systems. Inf. Sci. 2015, 313, 22–42. [Google Scholar] [CrossRef]
  29. Meski, A.; Koutny, M.; Penczek, W. Towards Quantitative Verification of Reaction Systems. In Proceedings of the Unconventional Computation and Natural Computation—15th International Conference, UCNC 2016, Manchester, UK, 11–15 July 2016; Lecture Notes in Computer Science. Springer: Berlin/Heidelberg, Germany, 2016; Volume 9726, pp. 142–154. [Google Scholar]
  30. Meski, A.; Koutny, M.; Penczek, W. Verification of Linear-Time Temporal Properties for Reaction Systems with Discrete Concentrations. Fundam. Informaticae 2017, 154, 289–306. [Google Scholar] [CrossRef]
  31. ReactICS: Reaction Systems Verification Toolkit. 2023. Available online: https://arturmeski.github.io/reactics/ (accessed on 14 March 2024).
  32. Azimi, S.; Gratie, C.; Ivanov, S.; Manzoni, L.; Petre, I.; Porreca, A.E. Complexity of Model Checking for Reaction Systems. Theor. Comput. Sci. 2016, 623, 103–113. [Google Scholar] [CrossRef]
  33. Talcott, C. Pathway Logic. In Proceedings of the 8th International School on Formal Methods for the Design of Computer, Communication and Software Systems (SFM 2008), Bertinoro, Italy, 2–7 June 2008; Lecture Notes in Computer Science. Springer: Berlin/Heidelberg, Germany, 2008; Volume 5016, pp. 21–53. [Google Scholar]
  34. Ochoa, C.; Silva, J.; Vidal, G. Dynamic slicing of lazy functional programs based on redex trails. High. Order Symbol. Comput. 2008, 21, 147–192. [Google Scholar] [CrossRef]
  35. Field, J.; Tip, F. Dynamic dependence in term rewriting systems and its application to program slicing. Inf. Softw. Technol. 1998, 40, 609–636. [Google Scholar] [CrossRef]
  36. Alpuente, M.; Ballis, D.; Frechina, F.; Sapiña, J. Assertion-based Analysis via Slicing with ABETS. Theory Pract. Log. Progr. 2016, 16, 515–532. [Google Scholar] [CrossRef]
  37. Brodo, L.; Bruni, R.; Falaschi, M. Dynamic Slicing of Reaction Systems Based on Assertions and Monitors. In Proceedings of the Practical Aspects of Declarative Languages—25th International Symposium, PADL 2023, Boston, MA, USA, 16–17 January 2023; Hanus, M., Inclezan, D., Eds.; Lecture Notes in Computer Science. Springer: Berlin/Heidelberg, Germany, 2023; Volume 13880, pp. 107–124. [Google Scholar] [CrossRef]
  38. Brodo, L.; Olarte, C. Symbolic Semantics for Multiparty Interactions in the Link-Calculus. In Proceedings of the SOFSEM’17, Limerick, Ireland, 16–20 January 2017; Lecture Notes in Computer Science. Springer: Berlin/Heidelberg, Germany, 2017; Volume 10139, pp. 62–75. [Google Scholar] [CrossRef]
  39. Bodei, C.; Brodo, L.; Focardi, R. Static Evidences for Attack Reconstruction. In Programming Languages with Applications to Biology and Security—Essays Dedicated to Pierpaolo Degano on the Occasion of His 65th Birthday; Lecture Notes in Computer Science; Bodei, C., Ferrari, G., Priami, C., Eds.; Springer: Berlin/Heidelberg, Germany, 2015; Volume 9465, pp. 162–182. [Google Scholar] [CrossRef]
  40. Bodei, C.; Brodo, L.; Gori, R.; Levi, F.; Bernini, A.; Hermith, D. A static analysis for Brane Calculi providing global occurrence counting information. Theor. Comput. Sci. 2017, 696, 11–51. [Google Scholar] [CrossRef]
  41. Alpuente, M.; Ballis, D.; Sapiña, J. Static Correction of Maude Programs with Assertions. J. Syst. Softw. 2019, 153, 64–85. [Google Scholar] [CrossRef]
  42. Alpuente, M.; Ballis, D.; Romero, D. A Rewriting Logic Approach to the Formal Specification and Verification of Web Applications. Sci. Comput. Progr. 2014, 81, 79–107. [Google Scholar] [CrossRef]
  43. Alpuente, M.; Ballis, D.; Frechina, F.; Sapiña, J. Combining Runtime Checking and Slicing to improve Maude Error Diagnosis. In Logic, Rewriting, and Concurrency—Festschrift Symposium in Honor of José Meseguer; Lecture Notes in Computer Science; Springer: Berlin/Heidelberg, Germany, 2015; Volume 9200, pp. 72–96. [Google Scholar]
Figure 1. Visual exploration of reaction system computations in ANIMA.
Figure 1. Visual exploration of reaction system computations in ANIMA.
Electronics 13 01139 g001
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Ballis, D.; Brodo, L.; Falaschi, M. Modeling and Analyzing Reaction Systems in Maude. Electronics 2024, 13, 1139. https://doi.org/10.3390/electronics13061139

AMA Style

Ballis D, Brodo L, Falaschi M. Modeling and Analyzing Reaction Systems in Maude. Electronics. 2024; 13(6):1139. https://doi.org/10.3390/electronics13061139

Chicago/Turabian Style

Ballis, Demis, Linda Brodo, and Moreno Falaschi. 2024. "Modeling and Analyzing Reaction Systems in Maude" Electronics 13, no. 6: 1139. https://doi.org/10.3390/electronics13061139

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop