# Performing Arithmetic Operations with Locally Homogeneous Spiking Neural P Systems
## 4 An Locally Homogeneous Spiking Neural P System for Subtraction
### An LHSNP System with 1 Input Neuron for n-Subtraction  
\(\Pi_{Sub2}\) can only perform subtraction operations on \(2\)\(k\)-bit binary numbers, which has limitations in practical applications. Therefore, we have made improvements to \(\Pi_{Sub2}\). The improved LHSNP system \(\Pi_{Sub3}\) with one input neuron can perform subtraction operations on any \(n\)\(k\)-bit numbers (\(k\geq 5\)). The structure of \(\Pi_{Sub3}\) is shown in Figure 5. In Figure 5, the solid arrows represents the directed connection between two neurons. The dashed arrows indicates the omission of connections between multiple neurons. Due to the similarity between \(\Pi_{Sub3}\) and \(\Pi_{Sub2}\), the formal definition of \(\Pi_{Sub3}\) has been omitted. The design idea of \(\Pi_{Sub3}\) is as follows: 1 The system input section consists of two modules, namely the input module and the minuend cache module. The input module consists of an input auxiliary module and an input selection module. The input auxiliary module controls the minuend number to be transmitted through \(\sigma_{aux_{4}}\), and the subtrahend number to be transmitted through \(\sigma_{s}\). 2 Spiking control neuron \(\sigma_{aux_{3}}\) controls \(\sigma_{aux_{3,0}}\) and \(\sigma_{aux_{1,0}}\) to stop generating spiking output. 3 When two subtrahends are performing subtraction operations in \(\sigma_{sub}\), \(\sigma_{sub}\) sends the operation results to both the environment and the subtrahend cache module. The spiking waiting stored in the minuend cache module completes the subtraction operation with the next subtrahend in \(\sigma_{sub}\) to achieve accumulated subtract. 4 During the process of accumulating subtract, the high-order detection neuron \(\sigma_{aux_{5}}\) sends \(5\) spikings to detect whether the calculation results of the two highest orders of subtraction overflow. Five rules have been designed in \(\sigma_{sub}\) to determine whether the highest calculation result overflows. If the calculation result overflows, it sends \(4\) spikings each to the environment and overflow monitoring neuron \(\sigma_{OF}\). 5 When the calculation result overflows, \(\sigma_{OF}\) will generate spiking output to truncate the transmission of spikings in \(\Pi_{Sub3}\) and cause \(\Pi_{Sub3}\) to stop running. The rules in \(\Pi_{Sub3}\) are divided into seven groups: (1) Homogeneous neurons: auxiliary neurons, minuend cache neurons \(\sigma_{m_{i}}\) (\(1\leq i\leq k-1\)), and input neurons use rule set \(R=\{a\to a\}\). (2) Spiking control (neuron \(\sigma_{aux_{3}}\)) uses rule set \(R_{aux_{3}}=\{a^{(n-1)k}\to a\}\). (3) Binary highest bit detection (neuron \(\sigma_{aux_{3}}\)) uses rule set \(R_{aux_{3}}=\{a^{k}\to a^{5}\}\). (4) Minuend spiking adjustment (neuron \(\sigma_{m_{0}}\)) uses rule set \(R_{m}=\{a^{2}\to a^{2}\); \(a^{3}\to a\}\). (5) Subtrahend (neuron \(\sigma_{s}\)) uses rule set \(R_{s}=\{a\to crlambda\}\); \(a^{2}\to crlambda\); \(a^{3}\to a\}\). (6) Subtrahend operator (neuron \(\sigma_{Sub}\)) uses rule set \(R_{Sub}=\{a\to a\); \(a^{2}\to crlambda\}\); \(a^{3}/a^{2}\to a\); \(a^{4}/a^{3}\to crlambda\); \(a^{5}\to crlambda\); \(a^{6}\to a;a^{7}\to crlambda\); \(a^{8}\to a^{4};a^{9}\to a^{4}\}\). (7) Overflow monitoring neuron (neuron \(\sigma_{OF}\)) uses rule set \(R_{OF}=\{a\to crlambda;a^{4}\to a^{4}\}\). Analyzing the structure diagram of \(\Pi_{Sub3}\), it can be seen that \(\Pi_{Sub3}\) contains \(2k+10\) neurons with \(15\) rules, and completing the \(n\)\(k\)-bit binary number subtraction operation requires \(nk+5\) time slices. To illustrate the operation process of \(\Pi_{Sub3}\), an example is used to calculate the difference between \(13\), \(15\), and \(8\). If the current system is \(8\)-bit, i.e., \(k=8\). Then \(13-15-8\)\(=-10\) in the \(\Pi_{Sub3}\) is represented as \(00001101_{2}-00001111_{2}-00001000_{2}-00001010_{2}\) (calculation result overflow).