The Markov Chain Reference Bible

You've probably heard of the Thompson Chain Reference Bible, which is my personal favourite study tool when studying Scripture, but what is this Markov Chain Reference Bible, you ask? Well, here is the explanation. Please note that I hold the Scripture in the highest regard and it is not my intention to cause offense - This post is about exploring Markov Chains using a text corpus that is both familiar to me and free of copyright.

Ok, so I made a Markov Chain generator. To tell you what a Markov Chain is, you need to understand what a Finite State Machine is. Understand the following diagram:

This is a finite state machine (FSM) for making 25 cents using quarters, dimes and nickels. Each circle is called a "State" and each arrow is called a "Transition". There is one "Initial" state (the blue one), and one "Final" state (the yellow one). Starting at the blue state, we start out with 0 cents, then, if we add a nickel we go to state "0.05", adding a dime then takes us to state "0.2", and finally adding another nickel takes us to the final state "0.25". The key thing to note here is that if we knew that we were currently in state "0.1", we wouldn't know exactly for sure how we got there. Did we come directly from the initial state with a dime, or did we go through state "0.05" first. It is a machine that has no memory, only future possibilities.

Now, this simple FSM is nothing exciting, so now here's a FSM using some phrases from Ecclesiastes chapter 3. A transition between words is possible if the words appear in successive order in the text:

Run through it and you can recreate all of the original verses. The thing to note here is that if you are in the current state "die", you can only go to state "a", but you have multiple options from state "to", as is to be expected from the text.

So, what's a Markov Chain? Simply a finite state machine whose transitions are probabilities. Here's a Markov Chain for playing the lotto 6/49:

One thing to note about probabilities is that they are always between 0 (never happens) and 1.0 (must happen). So we can see that if you start out buying a ticket, there's a 99% chance that you will choose numbers and only a 1% chance you decide that you have probably sinned and shouldn't tempt yourself any longer and throw your ticket away in a moment of great repentence and strength, which, in the FSM is a final state and you are free. If you, however, choose to continue in your gambling addiction and actually choose numbers, then there is a 99.999... % chance you will lose. If that happens, you are 99.9% likely to buy another ticket. (Note: these numbers save the actual win/lose probabilities are completely made up in my own mind right now)

The one requirement Markov Chains have is that the sum of all arrows pointing out of a state has to equal 1.0 - this corresponds to the fact that no matter where you are, as long as it's not a final state, something has to happen - you can't stay where you are.

Alright. So, what I did was to read in the complete text of the KJV Bible and create a list of words that follow every other word, along with probabilites. The following diagram should suffice. Pretend that you find yourself at the word "strengtheneth" somewhere in the Scriptures and ask yourself "What is the next most likely word?"


This tells us that every time the word "strengtheneth" appears in Scripture, it is followed by "the" 28% percent of the time and by "himself", "her", "for", "me", and "man's" each 14% of the time. Choosing one of these options randomly, then, one would expect to the phrase "strengtheneth the" twice as often as "strengtheneth me" or "strengtheneth himself". This also tells us that we will never find "strengtheneth Peter" anywhere in Scripture (only the six words above are possible). 

So, what I did was create the complete FSM for all words in Scripture and randomly move from one word to the next using the probabilities to pick the next word. The final state for my FSM is whenever a "." is reached. The result can be quite humourous at times:


Yea, whether they shall fly as Christ: and how the midst of man hath bought in those things: and said unto his sayings were sanctified, and the ground: as one told him, even the slayer shall speak ye shall be to king, and shew thee the LORD was come near, to him.

His children of the land of Moab saw heaven to pass, if Christ, to give them away by the word.

And thou art good and seven weeks, and it shall ask counsel of God: A garden, of flies.

And the son of the field shall kill, and Aquila and that were come unto her purifying himself, my bow, and be acceptable in the fruit that he did my servant to the faith unfeigned faith is, neither be as gold; and let them to provoke him and Jehoshaphat said unto the house of hosts, and the crumbs which came to save all the house with wonders in the gate.

And he was no sustenance.


As you can see, much of it is nonsense, but locally, each word is followed by a word that actually follows it somewhere in scripture, and thus, the text is somewhat readable.

The next logical extension to this idea is rather than using only the previous word to pick the next word, use the previous two words to pick the next word. Here's a sample FSM for number of words = 2:


Now, if you are ever in the state "the going", the next word will be either "up", "forth", or "down". As you can see by the probabilities, most likely the word chosen will be "up", and the least likely candidate will be "forth", but the idea here is that we will have three words in a row that actual appear together in Scripture somewhere. Since before we only had two in a row, we can expect more coherent sentences. Read the few samples below and make up your own mind about this:


Here is the reason of the cloud and darkness was upon the high priest, saying, This do; Speak unto the root of the children of Israel will gather them to Troas in five days; afterward I rose in the valley of Jehoshaphat, Did not ye judge uprightly, O my people.

Forsake me not away, I will certainly make my judgment, and bewail my virginity, I prayed therefore unto the LORD shall judge the people answered him, Prophesy unto the people upon mount Sinai, and his kingdom that which was committed unto him, Lord, thou hast given him the pound, and shall fell every good piece of a king shall do this great evil against me: for the ships.

Our God shall wipe away all the people sent to call them, that he himself also so to me? For though we thus speak.

Quench not the record of John were departed, and Shillem.

Four tables were written, Behold, I will bring their fears upon them.


Every group of three words appears together in Scripture, and the sentences are making more sense. Looking at the previous three words gives even better results:


Doubtless ye shall not cover your lips, nor eat the bread of his God is upon thee, which shall not be heir with the son of Jonathan the scribe, and the captains cast them out in the rock: and he was eaten of worms, and stank: and Moses went up into the mount, and take it, and baketh bread; yea, those nations shall be gathered unto my people: and they that have been before thee, as the appearance of the likeness of God made he man.

Thus David the son of Joash king of Judah went out to go his way: but wickedness overthroweth the sinner.

Then charged he his disciples that they should come and smite the earth with you; for the LORD is greater than man.

And Daniel continued even unto the two handmaids.

And Eber lived after he begat Terah an hundred and fifty: and so they marvelled; they were afraid.


And using the previous four:


And Abimelech took sheep, and oxen, and sheep abundantly: for there was a deadly destruction throughout all the city; the hand of God was to give them one heart, and I will avenge the blood of his cross, by him to reconcile all things unto himself.

And Achish believed David, saying, The messenger came to them, and said thus, Hew down the tree, and cast it before Pharaoh, and it shall be always upon his forehead, that they may eat: for thus saith the LORD of hosts, the God of Israel; Wherefore commit ye this great evil against your souls, to cut off the house of Ahab like the house of Jeroboam the son of Nebat, and like the appearance of lamps: it went up and down among the living creatures; and the fire that saith not, It is enough, stay now thine hand.

A man shall eat good by the fruit of his loins, and faithfulness the girdle of his loins, according to the commandment of Moses, on the sabbaths, and for the people of the land, and all thy company before the LORD, And his deeds, first and last, are they not written in the book of the chronicles of the kings of Israel and Judah, that whosoever heareth it will say, There is a slaughter among the people, and sanctified the people; and much people of the city was called Hormah.

Our God shall come, and make me equal, and compare me, that we may obtain mercy, and find grace to help in time of need.

And Jesse took an ass laden with bread, and a good conscience; that, whereas they speak evil of you, as ye have said.


At this point I was having a lot of fun and decided to go even further, but, as everything else in this universe, there were limits. As the number of previous words considered grew past four, the phrases became too specific, duplicating larger portions of actual Scripture. The previous five words:


He shall enter also into the glorious land, and many countries shall be overthrown: but these shall escape out of his hand.

And with him was Aholiab, son of Ahisamach, of the tribe of Aser: she was of a great age, and had lived with an husband seven years from her virginity; And she was a widow of about fourscore and four years, which departed not from the temple, but served God with fastings and prayers night and day.

Woe to the multitude of many people, which make a noise like the noise of the seas, the noise of their waves, and the tumult of the people.

Now we command you, brethren, in the name of our God we will set up our banners: the LORD fulfil all thy petitions.

And the disciples came, and said unto him, The LORD saith thus; Behold, that which I have built will I break down, and that which I was afraid of is come unto me.


And six:


The LORD will cut off the man that doeth this, and the son of man that layeth hold on it; that keepeth the sabbath from polluting it, and taketh hold of my covenant; Even them will I bring to my holy mountain, and make them joyful in my house of prayer: their burnt offerings and their sacrifices shall be accepted upon mine altar; for mine house shall be called an house of prayer for all people.

Wait on the LORD : be of good courage, and do it: fear not, nor be dismayed; to morrow go out against them: for the LORD will be with you.

And their father gave them great gifts of silver, and of gold, and of precious things, with fenced cities in Judah: but the kingdom gave he to Jehoram; because he was the firstborn.

And from thence they went to Beer: that is the well whereof the LORD spake unto Moses, saying, Take the Levites instead of all the firstlings among the cattle of the children of Israel died not one.

Go ye forth of Babylon, flee ye from the Chaldeans, with a voice of singing declare ye, tell this, utter it even to the end of the earth; he breaketh the bow, and cutteth the spear in sunder; he burneth the chariot in the fire.


In my opinion, there is a global maximum in the humourous rating at Number of Words = 4. When #words < 4, the sentences are quite choppy and don't make reading sense, and when #words > 4, the sentences become duplications of actual sentences in Scripture.

Awesome - what was the point of all this? Markov Chains are cool.

Have a nice day!

Joey