Decision making in railway interlocking systems based on calculating the remainder of dividing a polynomial by a set of polynomials

: Decision-making in a railway station regarding the compatibility of the positions of the switches of the turnouts and the indications (proceed / stop) of the railway colour light signals is a safety-critical issue that is considered very labor-intensive. Di ff erent authors have proposed alternative solutions to automate its supervision, which is performed by the so-called railway interlocking systems. The classic railway interlocking systems are route-based and their compatibility is predetermined (usually by human experts): only some chosen routes are simultaneously allowed. Some modern railway interlocking systems are geographical and make decisions on the fly, but are unsuitable if the station is very large and the number of trains is high. In this paper, we present a completely new algebraic model for decision-making in railway interlocking systems, based on other computer algebra techniques, that bypasses the disadvantages of the approaches mentioned above (its performance does not depend on the number of trains in the railway station and can be used in large railway stations). The main goal of this work is to provide a mathematical solution to the interlocking problems. We prove that our approach solves it in linear time. Although our approach is interesting from a theoretical perspective, it has a significant limitation: it can hardly be adopted in an actual interlocking implementation, mainly due to the heavy certification requirements for this kind of safety-critical application. Nevertheless, the results may be useful for simulations that do not require certification credit.


Introduction
Rail transportation is an important mode of transportation around the world.It is a reliable and efficient way to transport goods and people over long distances.According to a literature review on resilience in railway transport systems, rail transportation is a critical infrastructure that plays a vital role in the economy and society [1,2].
Railway interlocking is a safety-critical system that ensures trains do not collide on the tracks.It is a complex problem that has been studied extensively in the literature.One source that provides an overview of railway signalling principles is Pachl [3].Recent research has explored the use of artificial intelligence to detect faults in railway signal interlocking systems [4].Other researchers have compared different methods for verifying the safety of railway interlockings [5].There has also been work on developing formal model-based methodologies to support railway engineers in specifying and verifying interlocking systems [6].Overall, the railway interlocking problem is an important and active area of research with many different approaches being explored.
Ensuring the compatibility of switch positions and signal indications at a railway station is crucial for safety.Interlocking is a safety measure that prevents improper changes to traffic signals and turnout switches.A railway station consists of sections connected by traffic signals and turnouts, which define the possible movement of trains.A route is a sequence of connected sections that a train can travel along partitioned into several blocks.To prevent collisions and dangerous situations, two trains may never be in the same block of a route.Two intersection routes (or the relevant blocks thereof) must be allocated to trains at the same time, to prevent collisions.Once a route is set and a train receives the signal to proceed, all switches and signals along the route are locked until the train has passed through.
A possible classification of computer-based railway interlocking systems could be as follows: • Route-table based: For every route request, an algorithm checks its feasibility using a "control table".The software consists of a single algorithm, independent of the topology.• Geographical: The interlocking program is made up of instances of software objects that mimic the behavior of physical objects.The configuration of this program depends on the topology.Within this category, we can distinguish between: -Route-based: Routes are defined a priori, and their definitions constitute data shared by the instantiated objects.-On-demand route definition: There is no a priori definition of routes.Instead, a train's request to the interlocking system is given only as the final destination that the train must reach.Instantiated software objects are responsible for exploring possible routes to the destination and choosing one of them.Our approach lies in this category.
Classical railway interlocking systems are route-based and the compatibility of routes is decided (usually by human experts) in advance [7] (although unacceptable errors have been found in real railway interlocking systems [8]).
Some modern railway interlocking systems can make decisions on the fly.This makes them more flexible as routes are not predetermined.However, before authorizing any changes to signals or switch positions, it is necessary to check if two trains would travel on intersecting routes (including the same route) and potentially collide.If this is the case, changes are not made and it may be necessary to wait for a train to leave the station.
The first railway interlocking systems were developed in the nineteenth century (they were complex mechanical devices with levers and interacting bars).Typical railway interlocking systems of the mid twentieth century were based on the use of electric relays and needed complicated electric circuits translating the connectivity of the railway station.In the 1980's, the first computer-controlled railway interlocking systems are installed [9][10][11][12].The first geographical railway interlocking system installed in Spain is dated on 1993 [13].
All modern railway interlocking systems are computer based (either geographical or route-based).Naive implementations of geographical algorithms may run into exponential complexity problems concerning the running time needed for finding safe routes through the railway network.Efficient data validation for geographical interlocking systems has also been studied [14].Another approach to verifying geographically distributed interlocking systems is through model checking using UMC [15].The approach presented here describes the configuration of the railway station through a single algebraic structure in which safety can be checked by a single algebraic operation.The main goal of our work is mainly theoretical.Nevertheless, it has the limitation that it cannot be certified and applied in practice.However we think that our approach can also be used for simulations that do not require certification credit and it is interesting from a theoretical point of view.Indeed, our approach represents a step on our research on proposing algorithms to solve railway interlocking problems for any railway station using an algebraic model similar to those used in Artificial Intelligence for implementing expert systems based on polynomials, ideals, and Groebner basis [16].Our proposal offers significant advantages over previous approaches.The motivation for our work is as follows: • Our approach relates two seemingly different fields: computational algebra and interlocking problems.Indeed the model we propose here proves that an interlocking problem can be solved by applying a division algorithm.This relation is not only interesting and inspiring from a theoretical point of view, but also has certain practical benefits: a possible proposal for improvement in the division algorithm in the field of computational algebra directly results in faster performance in solving interlocking problems.• By expressing the interlocking problem as an algebraic system similar to those used in expert systems, we can address problems related to expert systems in railway stations.We believe that once the problem is described in algebraic terms, it will be possible to develop expert systems based on these algebraic systems to solve more complex problems in the future.For example, such systems could detect which signals and switches cannot change the state due to safety concerns and provide recommendations for changing the configuration of switches and signals to allow trains to move safely to specific locations.• Unlike our previously proposed models that used algebraic systems [17][18][19], the model we propose now has great advantages over the others: -It eliminates the need for calculating Groebner bases, a task that is known to be very slow due to its exponential complexity.Indeed, in contrast to our previous approaches, the present model guarantees a linear complexity.-As a result, our new model is much faster than our previous models and has been shown to have linear complexity.-In contrast to our previous approaches, we use different polynomials to represent the static and dynamic topology of the railway station.The static topology is represented by a set of polynomials while the dynamic topology is represented by a monomial.Another monomial is used to represent the position of trains.This allows for immediate updates to the polynomials representing the problem when there are changes in train positions or the configuration of the railway station.
The paper is structured as follows.In Section 2 we discuss other approaches related to the one proposed here.In Section 3 we propose a possible formalisation of the concepts related to a railway interlocking system.In Section 4 we describe our method (as a black box) for determining the safety of a proposed situation in a railway interlocking system.In Section 5 the worst case complexity of the new model in calculated.In Section 6 the extension of the model to trains occupying more than one section of the layout is detailed.In Section 7 we show that the new model is much faster than previous ones.Finally, in Section 8 we set our conclusions.

Related works
An overview of different existing approaches to decision making in a railway interlocking system is given afterwards.
The paths (lists of consecutive sections) along the railway station are called routes.An example can be a route from an entrance of a station to a given track beside a certain platform.Establishing a route requires setting the turnouts and colour light signals along the route appropriately.
Many approaches have been applied to decision making in a railway interlocking system.Although out of date, [20] includes an interesting annotated bibliography.
In the classic approaches, the routes of the railway interlocking system are predefined.Moreover, the compatibility of routes is determined in advance (traditionally by human experts).They are usually denoted tabular railway interlocking systems.
The railway interlocking system is usually denoted geographical if the problem is translated into computational notation and decisions are made on the fly.
Geographical approaches do not depend on the track layout of the railway station.An inference engine extracts knowledge in a rule-based expert system and is independent of the given rules and facts stated as true.Similarly, a geographical railway interlocking system can decide upon the safety of any proposed situation in any given railway station.
The [21] uses a theorem prover implemented in a higher-order logic to decide on the safety of a situation.This work is revisited using an annotated logic program with temporal reasoning in [22].
Meanwhile, [7] uses ordered binary decision diagrams to model railway interlocking systems.
A specific work for the Slovak National Railways is [23], that uses Z notation.Another specific work, in this case for the Danish State Railways is [24], that uses the Vienna Development Method (VDM).
The [25] presents an early but sophisticated formal model that can deal with complex topologies including reversing loops and reversing triangles.It uses Petri nets and graphs and is implemented in Objective-C and PROLOG.
Another model (component-based) is used in the interesting approach [26][27][28].The railway station is abstracted as a set of connected components.
Another example is [29], where CAD, RailML, and logic programming are used.It is applied to a Norwegian railways station.
A very interesting approach that also uses RailML to describe the topology of the railway station and UML class diagrams and is applied to a Dutch station is [30].
We will describe afterwards some models for decision making in railway interlocking systems designed and implemented by the authors.All these models are topologically-independent and do not have restrictions on the direction of the trains.
• Model based on the use of graphs [31]: Our approach is based on graph theory and Boolean matrices (adjacency matrices).This approach is slow and can only be applied to small railways stations because, although the matrices are sparse, their number of rows and columns is the number of sections of the network.• Algebraic model [17,32]: Here, our approach is based on algebraic terms which requires calculating a Groebner basis [33,34] of a polynomial ideal.Since the algorithm for calculating this Groebner basis involves a long time, this approach is not suitable for large stations.• Model based on Boolean propositional logic [35]: This approach is based on propositional logic: sections are represented by Boolean propositional variables and connectivity between sections are represented by a Boolean propositional formula.The safety of a railway station is detected by solving a SAT problem for each section in the railway station.All techniques, like DPLL [36], to solve a SAT problem involve exponential complexity.However, the high number of SAT problems required in this approach makes it impossible for large stations.• Logic-algebraic model [18]: The advantage with respect to the algebraic model mentioned above is that in this case, the polynomial ring where computations take place is Boolean and consequently, Groebner bases and normal forms calculations required are much faster.In fact, this model is much faster than the three previous ones.However, the algorithm for calculating a Groebner basis involves high complexity computations and therefore, this approach is not suitable for large stations.• ASP model [37]: This approach is based on the answer set programming (ASP) paradigm.Connectivity and safety relations are defined by relations and derived relations through logic programming.This approach is further more efficient than previous ones and may be suitable for larger railway stations.However, this is not a polynomial complexity approach and consequently, it is not scalable.• Model based on preprocess and Boolean Polynomials: An algebraic approach that represents the proposed configuration of the railway station and the position of the trains using Boolean polynomials and Groebner bases is detailed in [19].The set of polynomials for which the Groebner basis is computed does not depend on the position of the trains.A new Groebner basis has to be computed if any changes in the aspect of the colour light signals or the position switches take place.
Although faster than previous approaches, it can still be slow if the railway station is really large.
As may be seen, many of these approaches are based on translating the topology of the railway station into polynomials with several variables and require calculating Groebner bases since they are usually required to solve many algebraic problems involving polynomials with several variables.Unfortunately, calculating a Groebner basis requires a very long time, and consequently, all these approaches are not suitable for very large railway stations with many trains since they need a long time to make a decision upon the safety of the proposed situation.
In this paper, we propose a completely new algebraic approach that does not require computing Groebner bases and is much faster than our previous ones.In our approach, the computational complexity of deciding upon the safety of a proposed situation is linear with respect to the number of sections and trains in the railway station (see Section 5).Therefore, it is completely suitable for very large railway stations (even if there are many trains involved).
3. A formalisation of the safety of a proposed situation in a railway station In this section we will define some formal concepts that allow us to prove the validity of our approach.
A railway station is a set of sections {S 1 . . .S N } and a binary relation defining the connection between sections by means of colour light signals and turnouts.There may be trains placed in the sections of a railway station.In this paper, we will initially consider that each train is placed in just one section.Nevertheless, we will generalize our results for the general case that a train can be placed in different sections in Section 6.
A colour light signal is defined as (S i , S j ), a pair of connected sections.If the indication of the colour light signal is proceed, then a train may pass from section S i to section S j .If the indication of the colour light signal is stop, then trains are not allowed to pass from section S i to section S j .
A turnout is defined as (S i , S j , S k ), an array of three connected sections.If the switch of the turnout is in the direct track position, then a train may pass from section S i to section S j (and conversely).If the switch of the turnout is in the diverted track position, then a train may pass from section S i to S k (and conversely).
The potential connectivity of a railway station derives from the situation of the colour light signals and the situation of the turnouts (that is, from the so called topology of the station).We define the relation E for describing the potential connectivity between sections.Formally, E is a set of pair of sections (i, j) indicating that the section S i is connected to section S j (by means of a colour light signal and/or a turnout).Definition 3.1.We define the set E ⊂ Z × Z as: E = {(i, j)|S i is connected to S j or S j is connected to S i by means of a colour light signal or a turnout} Consequently, the relation E is symmetric.
Remark 3.1.In the case that there are a series of n turnouts, we assume the presence of intermediate sections between them.Consequently, in a railway station, each section is connected to a maximum of three other sections on each extreme through a turnout.This means that each section can be connected to a maximum of six other sections.Therefore, the size of E is less than or equal to 6 • N where N is the number of sections.As a result, the number of elements in E, is O(N).
The indications of the colour light signals and the position of the switches of the turnouts (that is, the configuration of the railway station) define if a section is reachable from another.A configuration of the railway station is defined by a subset P ⊆ E. (S i , S j ) ∈ P if and only if it is possible to pass from the section S i to the section S j according to the indications of the colour light signals and the position of the switches of the turnouts (obviously a necessary condition is that section S i is connected to section S j ).Remark 3.2.In this model of railway interlocking systems we assume that if the switch of the turnout (S i , S j , S k ) is in the direct track position, a train is not allowed to pass from S k to S i .Similarly, if the switch of the turnout (S i , S j , S k ) is in the diverted track position, a train should not try to pass from S j to S i .We will consider that turnouts are always properly protected by colour light signals.
Remark 3.3.Two sections are connected by means of either a colour light signal or a turnout, but not both.If the latter was the case, we introduce a section in between (like S 9 between S 10 and (S 2 , S 3 , S 9 ) in Figure 3.2).Similarly, we include sections between two semaphores or turnouts.
Remark 3.4.Note that, despite the fact that turnouts can be long apparatuses, they are not considered sections in this model, but connections between sections.
The set P determines the possible paths of the railway station.A path is a list of sections [u 1 . . .u n ] such that for every i (u i , u i+1 ) ∈ P. The set P fulfills the following important property: For every pair of sections i and j, there is at most one path in P from section i to section j.Remark 3.5.For the property in the previous paragraph to hold we are considering paths defined by P (not by E).Besides, we are considering in this model only "usual" railway terminus stations or railway overtaking stations (unlike toy trains where one side of the overtaking station is connected to the other side).In these "usual" stations, we have that for every pair of sections i and j, there is at most one path in P from section i to section j.As may be seen, the railway station is divided into sections S 1 . . .S 11 and there are seven colour light signals (for example, there is a colour light signal between sections S 1 and S 2 ) and two turnouts (for example, a turnout connecting sections S 2 , S 3 and S 9 ).Note that signalling is on the right hand side of the track.
Let us consider the configuration depicted in Figure 3.2.The position of the switches of the turnouts is represented by: • a small segment, if the switch is in the direct track position (see for instance the turnout between sections S 2 and S 3 , S 9 in Figure 3.
• a small angle, if the switch is in the diverted track position (see for instance the turnout between sections S 6 and S 5 , S 11 in Figure 3.2).In view that the figures are printed in black and white, the aspect of the colour light signals will be represented by a black circle (indication stop) or white circle (indication proceed).
We would like to emphasize here that remark 3.5 holds in Figure 3.2.Although it is apparent that there are sections connected by more than one path, there are no loops once P is defined.That is to say, for every sections i and j there is at most one path in P from i to j.
Let us formally define the set P. Definition 3.2.We define the subset P ⊆ E as the set of (i, j) ∈ E such that exactly one of these conditions holds (with the conditions imposed in this model the conditions are mutually exclusive): • It is always possible to pass from section S i to section S j (regardless of the configuration of the railway station).For example, (2, 1) ∈ P in the configuration of Figure 3.2 since it is always possible to pass from section S 2 to section S 1 .• There is a colour light signal (S i , S j ) and its indication is proceed.
For example, (1, 2) ∈ P in the configuration of Figure 3.2 since the indication of the colour light signal (S 1 , S 2 ) (controlling the pass from section S 1 to section S 2 ) is proceed.• There is a turnout (S i , S j , S k ) or a turnout (S j , S i , S k ) and its switch is in the direct track position.
For example, (2, 3) ∈ P and (3, 2) ∈ P in the configuration of Figure 3.2 since the switch of the turnout (S 2 , S 3 , S 9 ) is in the direct track position.• There is a turnout (S i , S k , S j ) or a turnout (S j , S k , S i ) and its switch is in the diverted track position.
For example, (6, 11) ∈ P and (11, 6) ∈ P in the configuration of Figure 3.2 since the switch of the turnout (S 6 , S 5 , S 11 ) is in the diverted track position.
Definition 3.3.We define the multiset Q as the set of sections in which a train is placed: the number of times that element i appears in Q represents the number of trains located in section S i .
We will consider that Q is a multiset instead of a set, since Q will have repeated elements in case that two different trains are placed in the same section (which is dangerous).Definition 3.4.Let us consider a railway station and let the relation E describe its potential connectivity (see Definition 3.1).A railway interlocking problem is an ordered pair (P, Q), where P is the set of Definition 3.2, describing a certain configuration of the elements of the railway station (indications of the colour light signals and positions of the switches of the turnouts) and Q is the multiset of Definition 3.3, describing the positions of the trains.Definition 3.5.We will say that the railway interlocking problem (P, Q) is in a dangerous situation if and only if there are two lists of integers [u 1 , . . .u n ] and [v 1 , . . .v m ] such that all the following conditions hold: (1) For all 0 < i < n, we have that (u i , u i+1 ) ∈ P. That is to say, consecutive sections in the list [u 1 , . . .u n ] must be connected.( 2) For all 0 < j < m, we have that (v j , v j+1 ) ∈ P. That is to say, consecutive sections in the list That is to say, there must be a train in u 1 and v 1 .(4) u n = v m .That is to say, both paths reach the same section (there is a possible collision).
(5) For all 1 < i < n u i Q and for all 1 < j < m v j Q.That is to say, intermediate sections in the list must be free of trains so that trains from from section u 1 and section v 1 may reach section u n = v m .(6) For all 1 < i < n and for all 1 < j < m we have u i v j .That is to say, the possible collision happens at the end of the paths.( 7) For all i j we have u i u j .That is to say, the path [u 1 , . . .u n ] does not contain cycles.(8) For all i j we have v i v j .That is to say, the path [v 1 , . . .v m ] does not contain cycles.
We will say that the railway interlocking problem (P, Q) is in a safe situation if and only if (P, Q) is not in a dangerous situation.Clearly, this situation is safe: • the train located in section S 1 could stay in section S 1 or move to sections S 1 , S 2 , S 3 , S 4 , • the train located in section S 10 could stay in section S 10 or move to sections S 11 , S 6 , S 7 , S 8 .

Overview of the new approach
In this section we will extensively describe our algebraic approach based on the use of polynomials.As we will see, the potential connectivity of a railway station is represented by a set of polynomials with coefficients in the field Z 2 .A specific configuration of the railway station is represented by a polynomial with coefficients in the same field.The same happens with a specific placement of trains in the railway station.In order to detect whether a proposed situation is dangerous or not, we only need to check if the remainder of dividing a polynomial by a set of polynomials is zero or not.

The algebraic model
Our approach is based on defining a set of polynomials in the variables t i , l i j and m i j , where: • t i : a variable t i is considered for each section S i in the railway station.
• l i j , m i j : two variables, l i j and m i j , are considered for each pair of sections S i and S j when (i, j) ∈ E.
That is to say, we consider the variables l i j and m i j if the topology of the station allows to pass from section S i to section S j (in some configuration of the railway station).
We will work hereinafter in the polynomial ring and we will use the lexicographical order given by l i j > m i j > t i .The set of polynomials representing the potential connectivity of the railway station, the polynomial describing the specific configuration of the railway station and the polynomial describing the specific placement of trains in the railway station are constructed as follows.
The list of polynomials E representing the railway station.Through the set E (see Definition 3.1, the set of ordered pairs of integer numbers describing the potential connectivity of a railway station, we will define E as the list of polynomials of A formed by: • ∀(i, j) ∈ E, the two polynomials: As may be seen, the list of polynomials E depends only on E and, therefore, it is defined independently from the specific configuration of the elements of the railway station (from indications of the colour light signals and the position of the switches of the turnouts).
The polynomial p representing a given configuration of the railway station.For each set of ordered pairs of integers P ⊆ E representing a given configuration of the railway station (see Definition 3.2), we will consider the monomial p ∈ A: As may be seen, this monomial is defined according to the configuration of the railway station in the following way (note that the symbol | represents the relation is a divisor of or divides, for example, xz|xyz because xz divides xyz): • If it is always possible to pass from section S i to section S j (regardless of the configuration of the railway station), then l i j |p.• If there is a colour light signal between section S i and section S j , then: if the indication of the colour light signal is proceed, then l i j |p.
if the indication of the colour light signal is stop, then m i j |p.• If there is a turnout connecting section S i to either section S j or section S k then: if the switch is in the straight track position, then l i j l ji m ik m ki |p.
if the switch is in the diverted track position, then l ik l ki m i j m ji |p.
As may be seen, a variable l i j in p represents that it is possible to pass from section S i to section S j .In the same way, a variable m i j in p represents that it is not possible to pass from section S i to section S j Electronic Research Archive Volume 31, Issue 10, 6160-6196.
The polynomial q representing the placement of the trains.Let us consider that there are trains placed in sections S i 1 , . . ., S i m .We define the monomial q ∈ A: As may be seen, a variable t i in q represents that there is a train in section S i .

Decision making in the algebraic model
Here we will summarize the steps required to solve a railway interlocking problem.
Step 1.Given a railway station by the set describing its potential connectivity, E, we obtain the list E.
We would like to emphasize that this list E is calculated only once for every railway interlocking problem associated to E. We do not need to recalculate this set if there are movements of trains or if there are changes in the configuration of the railway station.Besides, this set only contains 2K + N polynomials (where K is the size of E and N is the number of sections).
Step 2. Given a configuration of the railway station, P, we calculate the monomial p.
As may be seen, for every change of the configuration in the railway station, we need to calculate p, but this monomial contains K variables where K is O(N).
Step 3. Given a placement of the trains, Q, we need to calculate the monomial q.
As may be seen, for every change of the placement of the trains, we need to calculate q, but this monomial contains at most N variables.
Step 4. In order to solve the (P, Q) railway interlocking problem we need to compute: where NR represents the remainder of the monomial pq respect to the list E. If this value is 0, the railway interlocking problem is in a dangerous situation, otherwise it is in a safe situation (see Theorem A.11).This may be calculated with any Computer Algebra System (CAS).In this paper we will use the CAS CoCoA 5.2 [38,39].
As we will see in Section 7, all these steps can be completed in less than 1 s for very large railway stations using a conventional computer.

Intuition of our approach
In this section, we will provide the intuition behind the choice of polynomials and the reason why the division algorithm provides the solution for detecting whether an interlocking problem is in a dangerous situation or not.
As may be seen in the previous section, in order to detect if an interlocking problem (P, Q) is in a dangerous situation we need to check if NR(pq, E) = 0.Although the definition NR is not simple and requires many technical details, we provide the intuition behind the value NR(pq, E): the remainder of the polynomial, pq by a list of polynomials E.
In the same way as ordinary division (for polynomials with one variable and natural numbers), the division of a polynomial p (with several variables) by a list of polynomials G = [ f 1 . . .f m ] is p = α 1 f 1 + . . .α m f m + r.The value NR(p, G) just denotes r, the remainder of the division.
The algorithm for calculating NR(p, G),in the same way as ordinary division, involves calculating intermediate dividends: it sets r 0 = pq and for each step i, it choose a polynomial f ∈ G and obtain a new intermediate dividend r i+1 , fulfilling where z i+1 is another polynomial.The new intermediate dividend r i+1 is a polynomial 'simpler' * than r i .The last intermediate dividend r n is one such that it not possible to obtain a polynomial r n+1 simpler than r n .By definition, the value NR(pq, E) is the last intermediate dividend r n .That is to say, NR(p, G) = r n .In Definition A.6 in Appendix A we give more details of this operator.
In our approach, we calculate NR(pq, E) where pq represents the interlocking problem (P, Q).As we will see in Appendix A, each intermediate dividend r i is a polynomial with the form p i q i such that r i represents an interlocking problem (P i , Q i ).This interlocking problem (P i , Q i ) is strongly related to (P, Q).Indeed, (P i , Q i ) is in a dangerous situation if and only if (P, Q) is in a dangerous situation.By means of this property, we can, consequently, detect if (P, Q) is in a dangerous situation by checking if (P n , Q n ) (the interlocking problem associated to r n = NR(pq, E)) is in a dangerous situation.Besides, we will prove in Appendix A another important property: the interlocking problem (P n , Q n ) is in a dangerous situation if and only if r n = 0.By means of these two properties we conclude that (P, Q) is in a dangerous situation if and only if NR(pq, E) = 0. We will prove all these previous results in Appendix A.
We will illustrate all these ideas by means of an example.We will consider the intermediate dividends of NR(pq, E) for the interlocking problem in Figure 3.4 and the interlocking problems associated to them in Figure 4.1.
• The interlocking problem A in Figure 4.1 is the same as the interlocking problem in Figure 3.4.
The monomial p A and q A are the following: p A = l 1,2 m 2,9 l 9,10 l 10,11 l 11,6 l 2,3 l 3,4 m 4,5 m 5,6 l 6,7 l 7,8 l 2,1 m 9,2 m 10,9 l 11,10 l 6,11 l 3,2 m 4,3 l 5,4 m 6,5 m 7,6 l 8,7 q A = t 1 t 10 t 8 • In the interlocking problem A in Figure 4.1 there is a train located in section s 10 that can pass from s 10 to s 11 .We can use the polynomial g 10,11 = l 10,11 l 11,10 t 10 + m 10,11 m 11,10 t 10 t 11 ∈ E in the algorithm of division and we have that: where: - where: - * q D = t 1 t 10 t 8 t 11 t 7 t 6 In the same way, the interlocking problems C and D are closely related: C is in a dangerous situation if and only if D is in dangerous situation.• In the interlocking problem D in Figure 4.1 there is a train located in section s 7 that can pass from s 7 to s 6 .We can use the polynomial g ′ 6,7 = l 6,7 m 7,6 t 6 + m 6,7 m 7,6 t 7 t 6 ∈ E in the algorithm of division and we have that: where: - The monomial z E is irrelevant for our purpose.r 4 = p E q E is the fourth intermediate dividend, where p E and q E are monomials describing the interlocking problem E in Figure 4.1: • In the interlocking problem E in Figure 4.1 there are two trains located in section s 6 (we will say that it as a trivial interlocking problem), and, therefore, the interlocking problem E is in a dangerous situation.Consequently, our original interlocking problem A is also in a dangerous situation.We can use the polynomial t 2 6 ∈ E in the algorithm of division and we have that: where The monomial z E is irrelevant for our purpose.r 5 = 0.
We have that r 5 is the last intermediate dividend.Therefore, NR(p A q A , E) = r 5 = 0.

Worst case computational complexity
In this section we will discuss that the complexity of every step of our approach is linear.We will consider that N is the number of sections in the railway station and K is the size of the set E (see Definition 3.1).
Step 1. Obtaining E. The number of variables of the polynomial ring is N + 3K.Since K is O(N), we have that the number of variables is O(N).The number of polynomials in E ′ is N + 2K.Since K is O(N) (see Remark 3.1), we have that the number of polynomials is O(N).Each polynomials is the sum of two monomials at most.Consequently, the time complexity of this step is O(N).
Step 2. Calculating the polynomial p.Since the number of variables in the polynomial ring is O(N), we have that the time complexity of this step is O(N).
Step 3. Calculating the polynomial q.Since the number of variables in the polynomial ring is O(N), we have that the time complexity of this step is O(N).
Step 4. Checking NR(pq, E) = 0.The complexity of generic algorithms for calculating the normal remainder of a polynomial pq with respect to a list of polynomials like E strongly depends on the structure used for representing the polynomials and the kind of polynomials in the list (E in our case).The polynomials in E are just sum of two monomials with a constant number of variables and pq is a monomial with a high number of variables.In Appendix B we describe an algorithm with complexity O(N) for calculating this task when pq and the polynomials in E fulfill these characteristics.

Model extension for trains occupying more than one section at the same time
Till now, we have analysed the case where trains are placed just in one section.Here we will see that the railway interlocking problems for trains placed in more than one section can be reduced to railway interlocking problems for trains placed in one section.

Experimental evaluation
In this section we analyse the performance of the approach presented in this paper, comparing it with other previous algebraic approaches.Indeed, we have made a comparison between the times required to decide upon the safety of a proposed situation in very large stations, with different numbers of sections (N) and trains (M).As may be seen, the new method proposed is always much more efficient than the other approaches proposed by the authors.This is possible because the present approach has worst case linear complexity (see Section 5).
In Table 1, we show the times required to decide upon the safety of different proposed situations (we have not included model in [31] because its performance is very poor bad for large stations).These times refer to the average performance of ten different configurations (both safe and unsafe) of a railway station with N sections and M trains involved.Indeed, our new approach takes always less than 1 second to decide upon the safety of the proposed situation, even when the number of sections is huge, while the other approaches are much slower.In this case the first column corresponds to the track layout of a former Spanish railway station.The next columns correspond to concatenating that station with itself several times (we have observed that there are no significant changes in the performance of our approach if we add these stations in parallel by means of turnouts).Time of our approach include the four steps in Section 4.2: it includes the calculation of the polynomials of the polynomials for the topology, configuration and trains.
Table 1.Time comparative of different methods implemented for deciding upon the safety of a situation proposed to a railway interlocking system in certain railway stations with N sections and M trains involved.Madrid-Chamartín-Clara Campoamor is the biggest railway station in Spain.Now it has 21 passing tracks of two gauges (15 of the Iberian gauge, traditionally used in Spain and Portugal, and 6 of the standard gauge, used in the Spanish high-speed lines) [40].The railway station is under renovation and it will have in the next future 25 passing tracks (13 of Iberian gauge and 12 of standard gauge) [41].We have considered in Table 2 the track layout of this railway station when all its tracks were of Iberian gauge (in order to consider a real world example as big as possible).This stations contains 250 sections, 81 semaphores, 100 turnouts.Table 2. Time comparative of different methods implemented for deciding upon the safety of a situation proposed to a railway interlocking system in Madrid Chamartin railway station when all its tracks were Iberian gauge (and there are M trains involved).The models [17,18,35] are not used because their timings are too long.[37] 646 ms 799 ms 1045 ms 1124 ms 1522 ms Model described in [19] 2340 ms 2340 ms 2340 ms 2340 ms 2340 ms Our approach 0.14 ms 0.14 ms 0.14 ms 0.14 ms 0.14 ms

Conclusions
In this paper we have presented a new algebraic model for detecting dangerous situation in a railway station.According to this model, the position of trains in a railway station configuration is considered unsafe if and only if the remainder of a certain monomial (representing the configuration and the cur-
rent position of the trains) divided by a list of polynomials vanishes.This connects two seemingly different fields: computer algebra and interlocking problems.Not only is this interesting from a theoretical perspective, but it also offers practical advantages.We have implemented this in CoCoA, resulting in very short program code.In this way, any improvement in the implementation of division algorithms immediately results in faster performance in our program.We have compared execution times with other fast models previously implemented by the authors and found that our approach eliminates the need to calculate a Groebner basis.Besides, our approach can be used as 'accelerated-time simulations', allowing for the analysis of different modifications in a railway network without the need to physically implement them with the enormous cost that it would require [42][43][44][45].However, our approach has a significant limitation.While it is mathematically interesting, Computer Algebra Systems have not been certified for use in safety-critical implementations [46].Obtaining ad hoc certification is much more costly than certifying a search engine over a table.As a result, our approach currently has no chance of being implemented in real-world systems.Nevertheless, we believe that our approach has value from a mathematical perspective and can be extended in several directions: • Develop a library that allows for easy definition of the list E for any topology; that defines switch changes and semaphore colors through functions and train movements.Updates to the polynomials p and q through multiplication and division of variables.• Develop a graphical environment that allows for the visual design of a station and obtains the polynomials in E, p, and q in a computer algebra system like CoCoA.• Extend our model.Although usual stations do not contain cycles and for each pair of sections there is only one path, it would be interesting from a theoretical point of view to extend the model so that this restriction is not necessary.• Study alternatives for general graphs, not just those derived from railway stations.
• Extend the interlocking problem to include other problems related to expert systems in railway stations, such as automatically detecting which semaphores and switches cannot be changed because they would imply a dangerous situation.Since our approach expresses the interlocking problem as an algebraic system similar to those used for implementing expert systems [16], we believe that our model can be easily integrated into these expert systems.

Use of AI tools declaration
The authors declare they have not used Artificial Intelligence (AI) tools in the creation of this article.
Case ∃k < n such that u k = i and u k+1 = j.Since i ∈ Q 1 , by (5) in Definition 3.5, we have that u 1 = i.We will consider the following subcases: ] fulfil all conditions in Definition 3.5 for (P 2 , Q 2 ).
v 1 i.Since u 1 = i, by ( 6) in Definition 3.5, we have that for every 1 ≤ k ′ < m, v k ′ i. Besides, we have that v m i since v m = u n u 1 = i, by ( 4) and ( 7) in Definition 3.5 (since we are considering that n > 1 in this case).Therefore, (v k ′ , v k ′ +1 ) {(i, j), ( j, i)}.
Case ∃k ′ such that v k ′ = i and v k ′ +1 = j.It is analogous to the previous case.
Case for every 1 ≤ k < n (u k , u k+1 ) {(i, j), ( j, i)} and for every We will consider the following cases: We have that [i, j] and [ j] are paths fulfilling Definition 3.5 for (P 1 , Q 1 ).
Although every trivial railway interlocking problem is in a dangerous situation, not all railway interlocking problems in a dangerous situations are trivial ones.However, a trivial railway interlocking problem can be derived from any railway interlocking problem in a dangerous situation (Theorem A.1).
Theorem A.1.A railway interlocking problem (P, Q) is in a dangerous situation if and only if a trivial railway interlocking problem is derived from (P, Q).
Proof.⇒) Let us suppose that (P, Q) is in a dangerous situation.Let [u 1 , . . ., u n ] and [v 1 , . . ., v m ] be paths fulfilling Definition 3.5.That is to say, we have that We'll proceed by induction on the sum of the lengths of the two paths, n + m.
Case n = m = 1: The paths are [u 1 ] and [v 1 ].Since u 1 = v 1 we have that this is a trivial railway interlocking problem.
According to the proof [34] (pp.62-64), we have: The following theorem allows to verify if G is a Groebner basis: Theorem A.4.Let I be a polynomial ideal in K[x 1 , . . ., x N ] and let G = { f 1 , . . ., f m } be a basis of I. Then: (where G * is an an ordered m-list of the polynomials in G, ordered in some way).

The railway interlocking problem in algebraic terms
Given a railway station and the description, E, of its potential connectivity between sections (see Definition 3.1), we will define the list E ′ from the list E (see Section 4.1) as follows:
Lemma A.5.Let E be the description of the potential connectivity between sections of a railway station.Then: = 0.But the elements of E ′ are of the form g i j or g ′ i j or t 2 i or m 2 i j , and, although tedious, it can be easily checked by hand or using a CAS, that in the 4 2 possible combinations, the S-polynomial vanishes.
Hereinafter, p and q are the polynomials representing the given configuration of the railway station, P, and the placement of the trains, Q, respectively (see Section 4.1).
Lemma A.6.Let (P, Q) be a railway interlocking problem for a railway station whose connectivity is described by E. Let r 0 , r 1 . . .r n be the first-intermediate-dividends of pq on division by any chosen ordering of the elements E ′ .Then: i) ∀i ∈ {0, . . ., n − 1} there is a railway interlocking problem (P i , Q i ) derived from (P, Q) such that r i = p i q i .ii) If NR(pq, E ′ ) = 0 the railway interlocking problem (P, Q) is in a dangerous situation.

Proof.
i) For i = 0, we have that r 0 = pq and, therefore, (P 0 , Q 0 ) = (P, Q) is a railway interlocking problem derived from (P, Q).Suppose that 0 < i < n, r i−1 = p i−1 q i−1 and (P i−1 , Q i−1 ) is a railway interlocking problem derived from (P, Q).We will prove that r i represents a railway interlocking problem, (P i , Q i ), derived from (P, Q).According to Definition A.6, we have that: where f k is a polynomial in E ′ such that LT( f k )| LT(r i−1 ).We have also that LT(r i−1 ) = LT(p i−1 q i−1 ) = p i−1 q i−1 , where p i−1 is a monomial that contains only variables of the kind l xy and m xy , and q i−1 is a monomial that contains only variables of the kind t x (see Section 4.1).
We have that f k t 2 k .Otherwise, we would have that r i = 0, and therefore, i = n (but we have supposed that i < n).We have that f k m 2 xy because pq is a monomial where the exponent of the m xy variables is at most 1.Consequently, there are two cases left: Case f k = g xy .We have that g xy is of the form: g xy = l xy l yx t x + m xy m yx t x t y .Since LT( f k )| LT(r i−1 ) we have that LT(g x,y ) = l xy l yx t x |p i−1 q i−1 .Thus, we have that l xy l yx |p i and t x |q i (remember that p i−1 is a monomial that contains only variables of the kind l xy and m xy , and q i−1 is a monomial that contains only variables of the kind t x ).Consequently: p i−1 is of the form p i−1 = p ′ • l xy l yx where p ′ is a monomial.
q i−1 is of the form q i−1 = q ′ • t x where q ′ is a monomial.
Therefore, we have that We define: Just observe that p i is a monomial that contains the same variables as p i−1 except that l x,y and l y,x in p i−1 have respectively turned to be m x,y and m y,x .In the same way, q i is a monomial that contains all the variables in q i−1 and also the variable t y .Consequently, we have that r i = p i q i are polynomials representing the railway interlocking problem (P i , Q i ) where Case f k = g ′ x,y .We have that g ′ xy is of the form: g ′ xy = l xy m yx t x + m xy m yx t x t y .Since LT( f k )| LT(r i−1 ) we have that LT(g ′ x,y ) = l xy m yx t x |p i−1 q i−1 .Thus, we have that l xy m yx |p i and t x |q (remember that p i−1 is a monomial that contains only variables of the kind l xy and m xy , and q i−1 is a monomial that contains only variables of the kind t x ).Consequently: p i−1 is of the form p i−1 = p ′ • l xy m yx where p ′ is a monomial q i−1 is of the form q i−1 = q ′ • t x where q ′ is a monomial Therefore, we have that: We define: Just observe that p i is a monomial that contains the same variables as p i−1 except that l x,y in p i−1 has turned to be m x,y .In the same way, q i is a monomial that contains all the variables in q i−1 and also the variable t y .Consequently, we have that r i = p i q i is a monomial representing the railway interlocking problem (P i , Q i ) where P i = P i−1 − {(x, y)} = P i−1 − {(x, y), (y, x)} (just observe that (y, x) P i−1 ) and Consequently, we have that r i = p i q i represents that the interlocking problem (P i , Q i ) is derived from (P i−1 , Q i−1 ).By the transitivity property of the derived relation between railway interlocking problems (see Definition A.2), we have that (P i , Q i ) is also derived from (P, Q). ii) According to Proposition A.3, we have that r n = NR(pq, E ′ ) = 0. Consequently, That is to say, p n−1 q n−1 = p n−1 q n−1 LT( f k ) f k Since p n−1 q n−1 is a monomial, we have that f k must be also a monomial.Consequently, f k cannot be either of the form g i j or the form g ′ i j .Besides, f k cannot be either of the form m 2 i since pq is a monomial where the exponent of the m i j variables is at most 1.Therefore, we have that f k = t 2 x .Since LT( f k )| LT(r n−1 ), we have that t 2 x |p n−1 q n−1 , and consequently, the interlocking problem (P n−1 , Q n−1 ) is a trivial railway interlocking because Q n−1 contains a repeated element x.Therefore,(P n−1 , Q n−1 ) is in a dangerous situation.By i) we have that (P n−1 , Q n−1 ) is derived from (P, Q).Since (P n−1 , Q n−1 ) is in a dangerous situation, by Theorem A.1, we have that (P, Q) is also in a dangerous situation.
Lemma A.7.Let (P, Q) be a railway interlocking problem for a railway station described by E. We have that: NR(pq, E) = NR(pq, E ′ ) Proof.Since the algorithm for calculating NR(pq, E ′ ) in Lemma A.6 discards the case f k = m 2 i j , we have that NR(pq, E) = NR(pq, E ′ ).
According to previous results (see ii in Lemmas A.6 and A.7), we have a sufficient condition to detect if an interlocking problem (P, Q) is in a dangerous situation: if NR(pq, E) = 0 then the interlocking problem (P, Q) is in a dangerous situation.Now, we will prove that this is also a necessary condition: if the interlocking problem (P, Q) is in a dangerous situation, then NR(pq, E) = 0.This proof is more complicated and requires translating the problem in terms of a ideal membership problem.An important result for the proof will be that E ′ is a Groebner basis.
Lemma A.8. Let (P 0 , Q 0 ) be a trivial railway interlocking problem for a railway station described by E. We have that: p 0 q 0 ∈ ⟨E ′ ⟩ Proof.According to Definition A.1, i must appear more than once in Q 0 .Let k be the number of times i appears in Q 0 .Since k ≥ 2, we have that k = m + 2 where m ≥ 0. Therefore, we have that q 0 is of the form q 0 = q ′ • t k i = q ′ • t m+2 i = q ′ • t m i • t 2 i where q ′ is a monomial.Consequently, p 0 q 0 = p 0 • q ′ • t m i • t 2 i ∈ ⟨E ′ ⟩ since t 2 i ∈ E ′ .Lemma A.9. Let (P 1 , Q 1 ) and (P 2 , Q 2 ) be two railway interlocking problems for a railway station described by E such that (P 2 , Q 2 ) is derived from (P 1 , Q 1 ).We have that: p 1 q 1 ∈ ⟨E ′ ⟩ ⇔ p 2 q 2 ∈ ⟨E ′ ⟩ Proof.Let (i, j) ∈ P 1 be such that i ∈ Q 1 and P 2 = P 1 − {(i, j), ( j, i)} and Q 2 = Q 1 ∪ { j}.Since i ∈ Q 1 and Q 2 = Q 1 ∪ { j}, we have that q 1 and q 2 are of the form (for a certain monomial q): q 1 = q • t i q 2 = q • t i t j Since (i, j) ∈ P 1 we have that l i |p 1 .
We will consider two cases: Case ( j, i) ∈ P 1 .We have that l ji |p 1 .Since P 2 = P 1 ∪ {(i, j)( j, i)}, we have that p 1 and p 2 are of the form (for a certain monomial p): p 1 = p • l i j l ji p 2 = p • m i j m ji Besides, we have that g i j = l i j l ji t i + m i j m ji t i t j ∈ E ′ .Therefore, we have that: pq • g i j = pq • l i j l ji t i + pq • m i j m ji t i t j = p 1 q 1 + p 2 q 2 Consequently, p 1 q 1 ∈ ⟨E ′ ⟩ ⇔ p 2 q 2 ∈ ⟨E ′ ⟩ Case ( j, i) P 1 .We have that m ji |p 1 .Since P 2 = P 1 ∪ {(i, j), ( j, i)}, we have that the monomials p 1 , p 2 are of the form (where p is a certain monomials): p 1 = p • l i j m ji p 2 = p • m i j m ji Besides, we have that g ′ i j = l i j m ji t i + m i j m ji t i t j ∈ E ′ .Therefore, we have that: pq • g ′ i j = pq • l i j m ji t i + pq • m i j m ji t i t j = p 1 q 1 + p 2 q 2 Consequently, p 1 q 1 ∈ ⟨E ′ ⟩ ⇔ p 2 q 2 ∈ ⟨E ′ ⟩ We have the following theorem: Theorem A.10.Let (P, Q) be a railway interlocking problem for a railway station described by E.
(P, Q) is in a dangerous situation ⇔ pq ∈ ⟨E ′ ⟩ Proof.⇒) Let (P, Q) be a railway interlocking problem in a dangerous situation.According to Theorem A.1, we have that a trivial railway interlocking problem is derived from (P, Q).According to Lemmas A.8 and A.9, we have that pq ∈ ⟨E ′ ⟩. ⇐) Suppose that pq ∈ ⟨E ′ ⟩.Since E ′ is a Groebner basis (see Lemma A.5), we have, by Theorem A.3, that NR(pq, E ′ ) = 0. Consequently, by Lemma A.6, we have that (P, Q) is in a dangerous situation.
Since the list E ′ is indeed a Groebner basis (see Lemma A.5), the ideal membership problem of the previous theorem can be easily solved (see Theorem A.11).
Theorem A.11.Let (P, Q) be a railway interlocking problem for a railway station described by E. We have that: (P, Q) is in a dangerous situation ⇔ NR(pq, E) = 0 Proof.This is a immediate consequence of Theorem A.3, Lemma A.5, Theorem A.10 and Lemma A.7.

B. A linear algorithm for calculating NR for our algebraic approach
Here we will propose an efficient algorithm for calculating NR(p, E) for the specific case that: • The coefficients of polynomials lie in Z 2 .
• p is a monomial.
• E = {g i } is a list of polynomials such that each g i is the sum of two monomials p i and q i .That is to say, g i = p i + q i where p i > q i .We will use the notation LT(g i ) = p i and M(g i ) = q i .
In this specific case, the general algorithm for calculating NR can be simplified since all intermediate dividends are monomials and the algorithm can run in O(N) if we use appropriate data structures:

Figure 3 . 2 .
Figure 3.2.A possible configuration of the railway station of Figure 3.1.

Example 3 . 2 .Figure 3 . 3 .
Figure 3.3.A possible placement of trains in the configuration of the railway station of Figure 3.1 shown in Figure 3.2.

Figure 3 . 4 .Figure 3 . 5 .
Figure 3.4.Another possible placement of trains in the configuration of the railway station of Figure 3.1.The proposed situation is dangerous.

Example 4 . 1 .
Let us recall the potential connectivity of the railway station of Example 3.1.Let us remember that in this case:

Example 4 . 3 .
Let us now consider the placement of trains of Example 3.3 (Figure3.4)instead: a new train is placed in section S 8 .We only need to perform Steps 3 and 4.

Example 4 . 4 .
If the aspect of the colour light signal between section S 10 and section S 11 were changed, now indicating stop (see Figure3.5 in Example 3.4), we would only need to recompute Steps 2 and 4.