Scripture is inerrant and infallible but understanding is not. The whosoever will are those whose names are written in the book of life of the Lamb slain from the foundation of the world, chosen by God Himself unto salvation in Jesus Christ!
What you fail to see is that originally everyone's name is written in the book of life. You never read of anyone's name being written in the book of life in time, only of persons having their name blotted out. If their name is blotted out, then originally their name was in the book of life.
Exo 32:31 And Moses returned unto the LORD, and said, Oh, this people have sinned a great sin, and have made them gods of gold.
32 Yet now, if thou wilt forgive their sin--; and if not,
blot me, I pray thee, out of thy book which thou hast written.
33 And the LORD said unto Moses, Whosoever hath sinned against me, him will I
blot out of my book.
Notice in verse 32 that Moses speaks of God's book that he has written (past tense). This book was written in the past. Moses requests his name be blotted out, but God answers that whosoever hath sinned against him, his name will be blotted out. So, originally these persons were in God's book of life.
We know that person's names are blotted out in time.
Rev 3:5 He that overcometh, the same shall be clothed in white raiment;
and I will not blot out his name out of the book of life, but I will confess his name before my Father, and before his angels.
We can see from Exodus 32:33 and Revelation 3:5 that a person's name is blotted out in time. But again, a person's name must have originally been in the book of life to be blotted out, unless you believe a person can lose their salvation.
We see in Revelation 3:5 that those who overcome will not be blotted out, and Jesus will confess their name before his Father. This tells us who will be blotted out, those who deny Jesus.
Mat 10:32 Whosoever therefore shall confess me before men, him will I confess also before my Father which is in heaven.
33 But whosoever shall deny me before men, him will I also deny before my Father which is in heaven.
Now we see what determines who overcomes, this person confesses Jesus before men. This is a believer.
Rom 10:9 That if thou shalt
confess with thy mouth the Lord Jesus, and shalt believe in thine heart that God hath raised him from the dead, thou shalt be saved.
10 For with the heart man believeth unto righteousness; and with the mouth
confession is made unto salvation.
So, those who are blotted out are those who do not confess Jesus before men, and do not believe on him.
But God knew who would do this before the foundation of the world. This is foreknowledge.
Rev 17:8 The beast that thou sawest was, and is not; and shall ascend out of the bottomless pit, and go into perdition: and they that dwell on the earth shall wonder,
whose names were not written in the book of life from the foundation of the world, when they behold the beast that was, and is not, and yet is.
So, you see several things here that must not contradict itself.
#1 The scriptures always speak of a person's name being blotted out of the book of life in time. There is no mention of a person's name being added to the book of life in time.
#2 Persons who confess Jesus are those that overcometh. We know this because Jesus said he would confess their name before his Father, and Jesus said he would only confess those persons before his Father who confessed him before men. If a man denies Jesus, then Jesus will deny that man before the Father.
#3 Those who believe on Jesus from the heart and confess him are saved. A person can only believe on Jesus and confess his name in time.
#4 Those who worship the beast were not written in the book of life from the foundation of the world. There are two possibilities here, either these persons were never written in the book of life, or their names were blotted out of the book of life before the foundation of the world.
I personally believe everyone's name was originally written in the book of life. But those who sin against God and do not believe on him are blotted out. God knew who would not believe before the foundation of the world, this is when their name was blotted out.
Jhn 6:64 But there are some of you that believe not.
For Jesus knew from the beginning who they were that believed not, and who should betray him.
The only explanation for this is foreknowledge. How can a person's name be blotted out if it were not in the book of life? And we see whoever denies Jesus shall be blotted out in time. We see from Exodus 32 that a person who sins in time shall be blotted out. But we also see that some person's names were not in the book of life from the foundation of the world.
The only explanation is foreknowledge. The only other option is that some people are never written in the book of life, and that some persons who's name was written are blotted out. This would mean you could lose your salvation, that the elect could be lost.