1. A semiconductor device comprising: a memory part that includes memory cells having different threshold values; a read circuit that reads data from a memory cell to be programmed with write data that is input; a detection circuit that compares the write data with the data read from the memory cell to thus detect a pattern in which programming of data causes erasing.