MODULAR ELLIPTIC CURVES AND FERMAT'S LAST THEOREM 451 little work on it.I checked that one could make the appropriate adiustments to the theory in order to describe deformation theories at the minimal level.in the fall of 1989,I set Ramakrishna,then a student of mine at Princeton,the task of proving the existence of a deformation theory associated to representations arising from finite flat group schemes over Zn.This was needed in order to e the restriction to the ordinary case.These developments are described in the first section of Chapter 1 although the work of Ramakrishna was not completed until the fall of 1991.For a long time the ring-theoretic version of the problem,although more natural,did not look any simpler.The usual methods of Iwasawa theory when translated into the ring-theoretic language seemed to require unknown principles of base change.One needed to know the exact relations between the Hecke rings for different fields in the cyclotomic Zp-extension of Q,and not just the relations up to torsion The turning point in this and indeed in the whole proof came in the spring of 1991.In searching for a clue from commutative algebra I had been particularly struck some y s earlier by a paper of Kunz [Ku2).I had already needed to verify that the Hecke rings were Gorenstein in order to compute the congruences developed in Chapter 2.This property had first been proved by Mazur in the case of prime level and his argument had already been extended by other authors as the need arose. Kunz's paper suggested the use of an invariant (the n-invariant of the appendix)which I saw could be used to test for isomorphisms between Gorenstein rings.A different invariant (the p/p2. invarian of the appendix)I had already o observed could be used to test fo isomorphisms between complete intersections.It was only on reading Section 6 of [Ti2]that I learned that it followed from Tate's account of Grothendieck dualty theory for complete intersections that these two invariants were eq for such rings.Not long afterwards I realized that,unlikely though it seemed at first,the equality of these invariants was actually a criterion for a Gorenstein ring to be a complete intersection.These argu nts are given in the appendix The impact of this result on the main problem was enormous.Firstly,th relationship between the hecke rings and the deformation rings could be tested just using these two invariants.In particular I could provide the inductive ar gument of Section 3 of Chapter 2 to show that if all lifting with restricted ramification are modular then all liftings are modular.This i had been trying to do for a long time but without success until the breakthrough in commuta tive algebra.Secondly, by means of a calculation of Hida sur amarized in Hi2 the main problem could be transformed into a problem about class numbers of a type well-known in Iwasawa theory.In particular,I could check this in the ordinary CM case using the recent theorems of Rubin and Kolyvagin.This is the content of Chapter 4.Thirdly,it meant that for the first time it could be verified that infinitely many j-invariants were modular.Finally,it meant that i could focus on the minimal level where the estimates given by my earlierMODULAR ELLIPTIC CURVES AND FERMAT'S LAST THEOREM 451 little work on it. I checked that one could make the appropriate adjustments to the theory in order to describe deformation theories at the minimal level. In the fall of 1989, I set Ramakrishna, then a student of mine at Princeton, the task of proving the existence of a deformation theory associated to representations arising from finite flat group schemes over Zp. This was needed in order to remove the restriction to the ordinary case. These developments are described in the first section of Chapter 1 although the work of Ramakrishna was not completed until the fall of 1991. For a long time the ring-theoretic version of the problem, although more natural, did not look any simpler. The usual methods of Iwasawa theory when translated into the ring-theoretic language seemed to require unknown principles of base change. One needed to know the exact relations between the Hecke rings for different fields in the cyclotomic Zp-extension of Q, and not just the relations up to torsion. The turning point in this and indeed in the whole proof came in the spring of 1991. In searching for a clue from commutative algebra I had been particularly struck some years earlier by a paper of Kunz [Ku~]. I had already needed to verify that the Hecke rings were Gorenstein in order to compute the congruences developed in Chapter 2. This property had first been proved by Mazur in the case of prime level and his argument had already been extended by other authors as the need arose. Kunz's paper suggested the use of an invariant (the rl-invariant of the appendix) which I saw could be used to test for isomorphisms between Gorenstein rings. A different invariant (the p/p2- invariant of the appendix) I had already observed could be used to test for isomorphisms between complete intersections. It was only on reading Section 6 of [Ti21 that I learned that it followed from Tate's account of Grothendieck duality theory for complete intersections that these two invariants were equal for such rings. Not long afterwards I realized that, unlikely though it seemed at first, the equality of these invariants was actually a criterion for a Gorenstein ring to be a complete intersection. These arguments are given in the appendix. The impact of this result on the main problem was enormous. Firstly, the relationship between the Hecke rings and the deformation rings could be tested just using these two invariants. In particular I could provide the inductive argument of Section 3 of Chapter 2 to show that if all liftings with restricted ramification are modular then all liftings are modular. This I had been trying to do for a long time but without success until the breakthrough in commutative algebra. Secondly, by means of a calculation of Hida summarized in [Hi21 the main problem could be transformed into a problem about class numbers of a type well-known in Iwasawa theory. In particular, I could check this in the ordinary CM case using the recent theorems of Rubin and Kolyvagin. This is the content of Chapter 4. Thirdly, it meant that for the first time it could be verified that infinitely many j-invariants were modular. Finally, it meant that I could focus on the minimal level where the estimates given by my earlier