Using algorithms to explain Socialism and Capitalism

source: quotefancy

Economics is humanity’s almost vain attempt at grappling with the unfathomable complexity of everyday life. To put it into perspective, imagine taking the most complex object we know of — the human mind — and connecting billions of them in a network mediated by time, distance and scarce resources and then trying to understand the behavior of that network using only the building blocks of the network itself, the human mind. To cap it off, the human mind hasn’t come close to understanding how it works. That’s a pretty dismal start to a science.

The best and most well established attempts at understanding economics have begun with basic actors and investigated the desires and constraints faced by those actors. Here a person has an endless list of objects of desire (or preferences) such as food, friendship, sleep, clean water, fresh air, exercise, clothing, seeing other people succeed etc. That list isn’t in any way immutable. Available to the person is the ever scarce resource of time as well as a number of other scarce resources such as energy levels, strength, focus as well as some tradably scarce resources such as personal possessions, money and labour. With these scarce resources, the economic actor will attempt to achieve a realization of their preferences in some combination that hopefully pleases her. What happens from there is a field of hot debate in the economic science and I won’t go into all the schools of thought in this article. All that is necessary for now is to understand the starting state of a person with all their preferences and the means by which that person can achieve those preferences. Let’s call this the initial state.

There is another field that grapples with an ever growing complexity that I have some familiarity with: software engineering. Here the software creator is also faced with scarce resources which must be economized. The creator has a goal of some sort. It could be as ambitious as creating the next Uber or as granular as changing the font of a proprietary website. It could be a commercial endeavor or a hobby. Software engineering isn’t concerned with the eventual goal of the software but more understanding how the programmer can achieve the realization of that software under constraint. The programmer is constrained by physical resources such as the computer and network speeds and the storage space. She is also faced with the constraints of her own skills and knowledge in utilizing the physical resources. Finally the programmer is constrained by the flexibility of the end goal: can the final product deviate in some way from the original plan or is it all or nothing?

The Korean Peninsula at night

Both software engineering and economics are concerned with actors who have preferences achieving ends using scarce resources. The advantage that software engineers hold over economists is that software engineers can actually write software and test their approaches. They can run experiments and refine their approach. Economists who aren’t also dictators do not share this privilege. When testing economic theories on nations, economists can only reflect on pseudo-natural experiments and attempt to draw conclusions. For example, the impoverishment of North Korea relative to its genetically and culturally similar neighbour to the South strongly suggests that Communism in so far as it is implemented in North Korea is inferior in maximizing living standards when compared the the South’s incarnation of Capitalism. The economists can’t tweak variables or re run this test 1000 times to verify the outcome. So while economists and software engineers both face similar research problems, the economist is no where near as well equipped as the software engineer to understand and analyse their field.

It follows then that software engineers and computer scientists in general are in a much better position to understand how scarcity is economized and goals are achieved at least with respect to software than economists are with respect to social welfare. It is my belief that if we can restate economic problems as well known software engineering problems then we can use our vast body of thoroughly tested computer science knowledge to better understand economic questions. The rest of this article will do just that.

A quick intro into algorithms

Computer scientists are often faced with the task of finding the quickest and most efficient way of searching through or sorting data. To do this they’ve devised families of algorithms each with different pros and cons. An algorithms is a recipe of instructions that a computer must carry out when presented with data. As a simple example consider the unsorted list of numbers

[4,2,6,3,8,1,7,9,5,0]

Lets propose a simple algorithm to sort this list:

  1. move from left to right 1 digit at a time, considering 2 adjacent numbers at a time.
  2. if the number on the left is bigger than the number on the right, swap them.
  3. Go to Step 1 until the list is finished.

If we run this algorithm, starting with the fist pair [4,2], we’ll note that 2 and 4 must be swapped because of instruction (2) above. The list now looks like this after 1 step.

[2,4,6,3,8,1,7,9,5,0]

Instruction 3 says keep going from left to right until the list of numbers is exhausted. If we move now to the right by 1 number, we’ll see that we have the pair [4,6] to consider. That is already in order so we’ll next consider [6,3] and so on until the list is exhausted. We’ll end up with this:

[2,4,3,6,1,7,8,5,0,9]

Do it yourself to double check. As you can see the list is more sorted than at the start but it’s not properly sorted. We need a 4th instruction:

4. Count how many times a swap had to occur in executing steps 1–3. If no swaps occurred, it means the list is ordered and we can end. If 1 or more swaps occurred then the list might not be ordered. Go to step 1.

Ok so in our first pass, a number of swaps occurred so lets do the process again. After running through the list for a second pass we have:

[2,3,4,1,6,7,5,0,8,9]

We swapped 3 times. That means that, according to instruction 4 we must start again. After many passes we end up eventually with:

[0,1,2,3,4,5,6,7,8,9]

Running through the list one final time yields no swaps which means that according to step (4), the algorithm is complete.

This illustrative example is useful to demonstrate a 3 important properties of an algorithm:

  1. An algorithm is a list of instructions required to take a certain state of affairs and transform it into a more desirable state of affairs. In the example above, the purpose of the algorithm was to take an unordered list of numbers and produce an ordered list.
  2. An algorithm takes time to complete. The above process took a certain amount of steps to complete. This number of steps varies depending on the original state of affairs. In the example above the fictional computer executing the algorithm had to pass over the list a few times until the list was ordered. Imagine instead that we were presented with a perfectly ordered list. After one pass, the algorithm would be complete. Computer scientists say that algorithms have a best case time, a worst case time and an average case time. Continuing with the example, the best case is a pre-ordered list. The worst case would be a list that looked like this [9,8,7,6,5,4,3,2,1] because it would take the most amount of passes until it was ordered. The time to completion also differs from algorithm to algorithm. Imagine that instead of the above algorithm we simply randomly shuffled the numbers until they were sorted. After each shuffle we’d inspect the data and stop if it was ordered. In this case our algorithm time to completion is also random. We could shuffle a list like [9,8,7,6,5,4,3,2,1] and in 1 step end up with [1,2,3,4,5,6,7,8,9]. In this case our new algorithm is vastly faster than the original. Alternatively we could shuffle away until the Sun engulfs Earth and still not end up with a sorted list. Random chance is like that.

The time it takes to solve a computing task depends on 4 things:

  1. The power of the underlying hardware. The faster the CPU and the more memory available, the faster any given algorithm will run.
  2. The size of the data. The larger the data set, the longer a given algorithm will take to run.
  3. The nature of the data. If it is known up front that a list of data is sorted then a sorting algorithm doesn’t have to do anything. On the other hand, if a data set is completely not understood, a given algorithm will take longer to understand or sort it.
  4. The choice of algorithm. In the real wold, choosing the correct algorithm can mean the difference between solving a problem in days and solving that same problem in seconds.

Since most of the time the first 3 conditions are given, computer science has dedicated a great deal of energy to perfecting and understanding algorithms.

What follows is restating the economic calculation problem as a computing problem that needs to be solved. By doing so, I’ll be able to demonstrate that Free Market Capitalism and Pure Socialism are actually examples of very well understood algorithms.

A word of clarity before we begin…

I want to be clear that this is not reason from analogy. I’m not going to claim that socialism and capitalism are like well known algorithms. Instead I’m going to demonstrate that if it can be shown that economic optimization can be stated as a data problem then capitalism and socialism are examples of well known algorithms.

Economic Optimization Reformulated

Maslow’s Hierarchy of Needs

Society is composed of individuals. Each individual has a bundle of preferences that can be to some extent ranked from most desired and urgent to least urgent and least desired. This ranking embodies Maslow’s Hierarchy of Needs. As certain base needs are met, individuals begin to desire items further down the list of ranking. The urgency of needs changes from person to person and from moment to moment. While sitting at my computer, I’m acting to achieve the goal of writing a Medium article, arguably up in the self-actualization triangle. However, if a gang of men burst through my front door with crow bars, my desire for Safety would rocket to the top of my preferences.

At any given point in time, a society is composed of scarce resources that have to be allocated in some way. Suppose we have a society with 3 people. Person A wants food, person B wants classic literature and person C wants to sleep in a comfortable bed. This society has 3 resources: an apple, a copy of Hamlet and a sleeping bag. If we had to distribute those resources, it would be silly to give the sleeping bag to person B. Instead it should be obvious that to achieve maximum satisfaction, person A should be given the apple, person B the copy of Hamlet and person C the sleeping bag. Any other combination will result in a society that is less happy. Let’s call this state of maximum satisfaction given a set of resources, Utopia.

What happens if we don’t know the preferences of A,B,C. All that we know is that if we give them their desired resource they will smile and if we fail they’ll cry. Utopia is when all 3 smile. Now we have a data problem that can be solved and a known end state, 3 smiles. We have a starting condition: a list of unpaired resources. We can now select among different algorithms until we have 3 smiles. The algorithm that takes the fewest steps is the best.

I’ve just described the simplest example of an economy in computational terms that can be attacked with an algorithm. Of course in the real world, there is more complexity. Let’s add complexity until we have something resembling the real world and then see where that leaves us.

Production

In our example above, we have a world of given resources and a set of humans with very simple preferences. In the real world we don’t simply have a set of given resources. We also have the option of combining existing resources to make new resources. This transformative step is called production. The necessary complexity of our search algorithm has suddenly increased dramatically. We have to decide whether to just consume resources as they exist or to spend time and labour transforming them into products. The end product has to be worth more than the time and labour involved in the production step or there would be no point in expending all that energy. In some cases this is an obvious step. No one wants iron ore but plenty of people want products made from steel. On the other hand, it might not be so clear. Is a fruit smoothie preferable to a bowl of fruit? The utopia searching algorithm now has an extra step. It has to decide whether certain resources have to be produced in order to achieve utopia. If it decides that 2 or more resources must be produced, it has to factor in the labour that goes into production will possibly be considered unpleasant by the labourer. It also has to weigh the fact that some of the inputs to production could rather have been consumed but will now be committed to production instead. Since the algorithm is concerned with maximizing smiles all round, it has to factor in the negative labour preference as well as the inputs as costs and ensure that the resultant state after production is still superior than had no production occurred. If we choose the wrong algorithm we might end up with lots of things being produced that no one wants. In that case the happiness of the population is vastly reduced since the labour of production reduced happiness and was uncompensated with desirable goods. Alternatively the algorithm could produce the correct bundle of goods but distribute them incorrectly. The outcome would be equally bad. A socially optimizing algorithm has to both allocate some resources for immediate consumption and others for production in a way that brings maximum smiles, utopia. By the way, lest you think this is a quest for consumerism, goods could include well preserved nature, clean air, indigenous forests or species preservation. What brings smiles to consumers’ faces need not be maximum material pleasure. The algorithm is just concerned with achieving this state of maximum smiles.

A tale of parallel universes

The process of deciding what to produce is not a one step event. For every product produced, more items could be produced from that, unfolding a path of future production possibilities. Suppose a society desires furniture made from pine trees. In order to do this, they’ll need to produce lumber mills, cutting equipment and a group of people capable of producing quality furniture. The cutting equipment is made from steel. Now suppose that this society desires that all steel be put to use creating restaurants. Since furniture crafting tools will no longer be made, furniture production will grind to a halt. Once the restaurants have been made, no furniture will exist for restaurant seating. Clearly steel output has to be allocated in such a way that both restaurants can be built and populated with adequate furniture. Let’s suppose they get that right. But why produce restaurants at all? Suppose that restaurants have only been produced because it has been observed that architects prefer to plan buildings from the comfort of restaurants. This society wants to increase architectural inspiration. They want to create a Silicon Valley of building architects and to do that they’ve decided they need restaurants. Having produced a slew of new restaurants, architecture experiences a boom and consequently buildings start going up. Many of these buildings require the use of both wood and steel, drawing resources away from both furniture production and restaurant creation. The society now has to contemplate the tradeoffs of resource allocation in production on 3 dimensions because the boom in building production is killing the goose that lays the restaurant egg. The utopia algorithm now has to calculate the optimum production of restaurants such that the demand to build new buildings from architects inspired by said restaurants will not reduce the amount of furniture and future restaurants to such an extent that the population is less happy than had no restaurants been built. As you can imagine, the task of choosing the optimal allocation of resources for production and consumption escalates in complexity quickly with each new resource and actor added. What’s more, making small changes to one allocation can have cascading ripple effects on the rest of the economy. Suppose society notices a scarcity of lumber in building construction and decides to allocate all lumber from furniture to building construction. This of course will mean that restaurant production will halt because of a scarcity of furniture required for restaurant seating. Once restaurant production halts, buildings will stop springing up because architects will no longer be inspired and we’ll end up with a surplus of wasted lumber allocated to building construction. We went from lumber shortage to lumber scarcity in one step.

Once a society has established a complex system of production setup like the fictional one illustrated above, changing a few allocations of resources can cascade and transform the society radically into something vastly inferior.

Revealed Preferences

One final layer of complexity to add to the situation is that measuring happiness and personal preferences accurately is not really possible in the real world. This throws a spanner in the works since our algorithm relies on measuring smiles to know when utopia is achieved. So far the closest we’ve come to measuring preference is by observing consumer response to price and income changes. We can learn a lot about how much value people place on things simply by how much they put their money where their mouths are. Suppose you drive a car for leisure and eat food. You allocate all your income to both activities. Now suppose the price of fuel increases. You have to either cut back on driving or eating. The degree to which you do either says a lot about the relative value you place on each. So now we have a situation where our algorithms can’t know for sure when they’ve achieved optimum. They can only feel their way to a solution by observing proxy data such as GDP per capita, income inequality, shop inventory, price changes, revealed preferences from consumption behaviour and so on. The algorithms will never know if they’ve achieved utopia.

Heuristic Algorithms

In computer science, we’re often faced with problems that have difficult to measure or evaluate solutions. An example would be achieving human-like artificial intelligence. We don’t know what that looks like so we use benchmarks to help us test if we’re approaching that point. Can the AI beat humans at chess? Can it beat humans at Go? If you speak to AI, will it feel like you’re speaking to a human? In these cases, we often don’t have a best outcome or even a final outcome but we have a way of telling the algorithm whether some state of affairs, n, is an improvement over the previous state n-1. In some cases we can only say n is most probably better than n-1. Nonetheless we now have a way of improving the state of affairs even if we never know if we’re going to reach that perfect solution. So if economic ideology exists in this space of algorithms, we need to find some benchmark to measure it against. In the 20th century, socialist planners boasted that scientific socialism would produce a greater desirable output than laissez faire capitalism. So let’s use total output per person as our measurement. Any ideology is succeeding if the total output per person at state n is greater than the output at state n-1.

Capitalism is an evolutionary search algorithm

Free market capitalism (capitalism from now on) is a genetic algorithm that uses a fitness function to weed out bad allocations and pursue good allocations. As the name suggests, genetic algorithms are inspired by ecological natural selection. In nature, bad genes in animals are eliminated by disease and predators and good genes are selected for by the ability to accumulate resources and attract mates. Each successive generation is more likely to be fit than the previous generation. Given enough generations, species evolve increasing fitness to their surroundings. This is not to say that generation n will be fitter than n-1. Rather that generation n+k for some sufficiently large k will be more fit than generation n.

The economic belief of capitalism is that society is most likely to discover the best allocation of resources in the application of the ideas of its members. Therefore the task for capitalism is to select for the best ideas in its individual members and eliminate the bad ones. To do this, each member is allowed to pursue their own personal utopia with the condition that they cannot take resources from other members. The initial allocation of resources is not important. What matters is that in order to acquire a resource, an individual has to seek consent from its owner. Therefore, in order for utopia to be approached, many acts of consenting exchange have to take place. The quickest way to do this is through mutually beneficial trade. As resources are reallocated in a way that improves overall satisfaction, individual members attempt to anticipate the preferences of other members through empathy, allowing them to utilize that knowledge to engage in production to produce more valuable goods that can be traded away for even more resources. Members who can best anticipate the needs of others will end up producing the most valued goods, allowing them to trade them away to improve their own personal state of affairs. Similarly the consumers of these new goods will achieve a higher state of welfare by being offered desirable goods that otherwise didn’t exist. Consumers will thus gravitate towards producers who can best anticipate and empathize with their needs. When this happens, the overall state of welfare increases. Suppose, on the other hand, that some individuals fail to anticipate the desires of others. Their acts of production will result in no trade. After using up their resources and producing nothing of worth, an act of production will halt and the individual will be worse off than before. They can attempt to produce again or they can trade their labour with the successful producers in return for resources, thereby offering the owner of the bad idea a mechanism for recovery. As the successful products are more desired, the price mechanism will push up their value. As this happens, the demand for labour in producing those goods increases and the welfare of the previously unsuccessful producer will now be on a track of gradual improvement.

The selector function, then, is the profit-and-loss mechanism of the market. For every state of resource allocation, profit will draw resources toward desirable ideas away from bad ideas. Those bad ideas will cease to be implemented and the desirable ideas will increase. Over time, the ideas in a capitalist society will drift towards more and better production as consumers select away bad ideas and reinforce good ones. What’s more, the types of ideas in a capitalist economy will improve as incremental mutations are usually selected over wildly new ideas (evolution). Individuals will be encouraged to focus on higher quality ideas. There’s no way to know if capitalism approaches the best possible outcome, only that over time the total output and satisfaction will improve.

Capitalism allows individuals to generate and pursue random ideas (mutations) and then uses profit (food and sex) and loss (disease and predators) to select the best ideas. It is the selection of good ideas.

There is one big draw back to an evolutionary algorithm: it doesn’t necessarily achieve the absolute best outcome. Consider an algorithm that tries to climb mountains. It picks random moves each step and selects the one that results in a higher position. Its selector function is to pick moves that increase its height. So in step 1 it’s given a list of general instructions(go up, go up somewhat, go up a lot, go right, go left, go down, jump, roll). After testing each one, it weeds out the bad ones and ends up with (go up, go up somewhat, go up a lot) because they satisfy the requirement that state n must be higher than state n-1. And so it proceeds. Clearly this contrived example will get it to gradually ascend the mountain. But observe the picture above. If it starts at the base of the left most peak it will eventually reach the top. However, from there it has no way of getting to the middle peak which is actually the highest. In its current state it is probably faced with a list like (go very very up, go up somewhat, go up). It might even have a mutation of go down thrown in but it can’t go down because it requires state n to be higher than state n-1. So even though the best outcome is to first descend the left peak and then ascend the middle peak, this evolutionary algorithm will not permit it. This is the local optimum problem. Free market capitalism is similarly blind to the absolute best outcome. The socialists of the 20th century suspected this to be the case which is why they introduced social scientific planning as a better overall alternative.

Socialism is a brute force algorithm

When a known way of solving a sorting problem in computer science doesn’t exist, programmers sometimes attempt the brute force approach. This means that every single outcome is tested. For instance, suppose you have a list of 3 unsorted numbers [4,2,5]. The brute force approach is to list every permutation of this list and then select the ordered one:

  1. [4,2,5]
  2. [2,4,5]
  3. [2,5,4]
  4. [4,5,2]
  5. [5,4,2]
  6. [5,2,4]

If we want descending order, we pick option 5 and if we want ascending order, we pick option 2. While this works, large sets of data make this approach infeasible to the extent that programmers consider brute force search to be akin to a swear word. Brute force is so inefficient that using it is considered an admission of failure.

The socialist planner has total control over resource allocation but no selector functions. You could argue that the socialist selector function is “select the total allocation that increases output in state n over state n-1”. However, I’ll show now that this isn’t the case.

Recall the restaurant/furniture/architect example from above. It was clear that if we tweaked one resource, it would have cascading effects on the entire economy for the negative in a way that is hard to predict. For any given allocation, the socialist is surrounded by a sea of allocations that could bring ruinous starvation to the masses. Furthermore, it isn’t clear what about the current allocation is superior or inferior. Capitalism had the profit and loss heuristics to select mutations. The socialist planner doesn’t have prices or the ideas of the individuals that make up society since there is no way to draw out the good ideas. The act of reallocating wood production from furniture to restaurant production might increase production in the present as a building construction boom sets in, only to lead to furniture shortages and hence restaurant shortages in the future. Therefore, the heuristic of more output in time n-1 than in time n doesn’t imply that this output is sustained in periods n+1, n+2, n+3 ….n+k. There’s no reason that output won’t just crash in period n+6, for instance.

The socialist planner is faced with simply shuffling the cards over and over and in the end selecting the allocation that leads to the best outcome. This is the brute force approach of searching through every possible resource allocation. The benefit of this approach over capitalism is that the absolute best outcome can actually be found in theory since eventually an allocation will be found that is the universal best. Therefore, in theory, socialism has the potential to accidentally stumble on a best utopia. Of course the socialist has no way to know if such a utopia has been achieved since we’ve established that there is no good way to actually measure happiness. Hoping that once discovered, the planner sticks with the utopia is a risky proposition.

Another big draw back is that we might have a situation like the following example where a new allocation is attempted in each successive period (5 year plans?):

period 1: comfortable living standards

period 2: mass starvation

period 3: flying cars and food abundance

period 4: water shortages and rioting

period 5: armish paradise

period 6: all diseases cured

period 7: outbreak of bubonic plague

The erratic switch from suffering to prosperity is unlikely in itself to be very desirable. What’s more, the perfect outcome or even a good outcome could require 1000s of iterations spanning 10s of thousands of years. In the mean time, a capitalist economy would be gradually ascending and improving, perhaps never reaching a global perfection but never descending into some of the nightmare scenarios a brute force approach to social planning would entail.

Conclusion

We can now see how Mao’s Great Leap Forward is a highly likely outcome of such a brute force approach to resource allocation. Similarly, it’s easier to understand why the center of the software universe is in Silicon Valley and doesn’t sporadically switch to Ethiopia since evolutionary systems tend to become path dependent on previous changes and discover local optimums. Even if Ethiopia would make a better Silicon Valley in a perfect world, there’s no way to descend the California “peak” and ascend the Ethiopia “peak”.

This software engineering analysis of economic ideologies is in no way exhaustive and can benefit from a far more thorough examination. Nonetheless I hope that as we develop new ways to deal with and appreciate complexity in computation, these can gradually leak into the social sciences and economics in particular.