# Can most programs (except the IO part) be re-written as a sequence of matrix operations?

I got this idea recently. If we do not consider the data IO part of software, imagine the data is in the memory and we need to come out with some decision (which product to recommend to a user, how to render the 3D world in a game) by processing the data in memory. All of these tasks could be done through a sequence (probably a graph) of matrix and vector operations, such as multiply, add, sum, etc.

For instance, I used to work for a car pool company, there was a piece of code to decide which car should respond to user. That logic was implemented with c++ stl containers and flow controls like if/else/break. Then I realized that it can be re-written as logistic regression (the business logic is stored in the linear predictive model) , with certain precision.

In this sense, matrix operation is a programming language by itself.

Can anyone share any thoughts here? Is there any introductory discussion wiki that I can read ?

• You should define your "matrix operation language" more precisely. More concretely, how do you achieve a (possibly unbounded) loop in that? E.g. how do you perform a certain operation until a certain condition is false? Note that, when you have a way to perform arbitrary loops, you need only very basic arithmetic operations to simulate any program. If you did not already, you should read some introductory material about Turing completeness and computability. – chi Sep 27 '19 at 15:53

If you regard the output of a program as a function of its input then matrices can be used to represent some programs, namely those where the output is a linear function of the input. So a program that takes two arguments $$a$$ and $$b$$ and returns $$a+b$$ and $$a-b$$ could be represented by the matrix
$$\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}$$
But most programs are not linear functions. For example, if the program instead returns $$a^2+b^2$$ and $$a^2-b^2$$ how will you represent that as a matrix ?