Let's say I have an algorithm something like as follows:
1 eliminate stuff from a list called reactions
2 for each element in reactions:
3 if one thing is computable:
4 compute it
5 else:
6 eliminate element from reactions, GOTO 1
Can I change it too
1 eliminate stuff from a list called reactions
2 while length of reactions is > 0:
3 while thing is computable:
4 for each element in reactions
5 compute it and append it to list called relevant_reactions
6 eliminate element from reactions
7 eliminate element from reactions
without any changes in efficiency? If there are any ways to improve the efficiency please let me know.
For reference, this algorithm is from page 8 of the paper Reachability Problems for Continuous Chemical Reaction Networks. The reason this question is important is because the main result of this paper is showing that the algorithm runs in polynomial time.
The reason the 6th and 7th lines are the same is to eliminate both those elements where the thing is not computable and those where it is computable (those are moved to a new list). I feel like there's a better way to do that part, however, so any advice there would be appreciated.
I should point out that the main reason I am rewriting the algorithm is to remove the GOTO 1
. It's hard to implement in Python 3 (my language of choice) and it seems to be generally considered bad practice.
I should also point out what exactly the "thing is computable" is for sake of context/completeness. Basically, that line is computing a vector (that must be $\in \mathbb{Q}^R_{\geq 0}$) that is multiplied by a matrix and when added to another vector should equal another vector. The vector elements are concentrations of chemicals. The matrix contains the net change of various reactions. It would look something like this: (vector that represents current state of the system) + (matrix of net change of every reaction in the list reactions)*(vector we are solving for) = (vector representing current state) and the element in reactions (the one in the iteration of the for loop, also in the vector we are solving for) must be greater than 0. If you found that confusing, no wonder, I did too (especially the last part). The relevant part in the paper is line 3 of Algorithm 1 in section 3. The exact line is
Compute a vector $F_{\rho}\in\mathbb{Q}^R_{\geq 0}$ such that $\mathbf{c}+\mathbf{M}F_{\rho} = \mathbf{d}$ and $F_{\rho}(\rho) > 0$, if one exists