The Gemara said that it's good to strike a child as a punishment if he's not learning. Then it seemed to indicate that it's ok to hit the child even if he is learning?! How can that be? Shouldn't there a difference between positive behavior and negative behavior? Should someone punish his child for no reason?
First, it must be made clear that it is not necessarily an intrinsic Mitzvah of Limud Torah that the child must be hit. It is not a condition of satisfactory performance of the Mitzvah. Indeed, there are those who say that in today's climate it is much more rare that hitting will be appropriate than in olden times. What is meant is discipline, in respect of which there are many methods at one's disposal. The root "YaSaR" means verbal, spiritual, or moral pressure to constrict the behavior, akin to the root "ASaR" which refers to actual physical restriction or imprisonment. For example, "Shema Beni Musar Avicha" (Mishlei 1:8), or "Ka'asher Yeyaser Ish Es Beno..." (Devarim 8:5). See also Melachim I 1:6, "v'Lo Atzavo Aviv mi'Yamav," and see Rashi there who explains that "Lo Atavo" means "he did not anger him," and this is "to teach you that one who refrains from reprimanding his child brings him to his death."
In the Midrash (Shemos Rabah) it says that this is an example of one who is "Chosech Shivto, Sonei Veno" -- "One who holds back his stick hates his child, and he who loves him disciplines him early" (Mishlei 13:24), on which the Midrash comments, "To teach you that one who refrains from punishing his son, his son will eventually turn to evil ways and will hate him (his father). We find that David did this with Adoniyah -- he did not punish him corporally and did not castigate him, and thus he turned to evil ways."
If the boy is not learning properly, he may need guidance correction and/or discipline, one of whose facets might be the stick, either figuratively or in reality.
The verse quoted by the Gemara, however, confirms that even if he has learned, he still needs a firm hand to keep him on the correct path. This is beautifully explained by the Vilna Ga'on on Mishlei 13:24, who writes: "'One who holds back the stick' -- that is, when it is appropriate; 'And he who loves him disciplines him early' -- not that he disciplines him for that which is fitting, but rather he 'disciplines him early' by discerning whether he has done any small trace of evil, and for that he disciplines him. It is analogous to a woman who gazes in a mirror when she adorns herself, and she sees that the mirror is dirty; she chooses a nicer mirror which will show her small marks.... Likewise, one who loves his son searches more for the bad things that he does, and he disciplines him for them so that he not do them further, even the small one. Therefore, they said in Makos that even if he has learned, it is still a Mitzvah to hit him -- that is, so that there not be in him any trace of evil whatsoever."
In other words, the highest imaginable standards are required from the best quality pupils, and they have to be treated stricter than the average. It is comparable to a star athlete whose trainer will provide an enormously punishing schedule to get the very best out of him.
From this explanation of the Vilna Ga'on, the question is well-answered, and also the Gemara's proof from the verse quoted is understood. From the verse itself there would appear to be no indication that it refers to one who has already learned. It could just as well refer to one who has not yet done so. See Ritva, who asks this, and whose answer is difficult to follow, and it seems to me that there may have been a manuscript error. The Vilna Ga'on, however, implies that one who has not learned is dealt with in 13:24, so this verse in 29:17 must refer to someone else -- i.e. one who has learned.
Others suggest that the former is already covered in the same chapter (29:15): "Shevet v'Sochachas Yiten Chochmah" -- "The rod and rebuke give wisdom." The Ben Yehoyada derives the lesson from the repetition in verse 17 itself, for "Ma'adanim l'Nafshecha" is apparently synonymous with "vi'Ynichecha," so it must be mean that even a good boy who is giving Ma'adanim and Nachas to his parents still needs Musar and discipline.
The language of the Rambam (Hilchos Talmud Torah 2:2) is very instructive for our purposes:
"We bring the children to be taught.... And the teacher hits them in order to place upon them awe, but he does not hit them with an enemy's cruel blow, and therefore he should not hit... except with a small strap...."
The purpose of the strap is to control the class and instill proper respect and discipline. This is well-known to experienced teachers.
Indeed, very often the best boys become too full of themselves and begin to feel arrogant, and above correction and discipline. The Gemara teaches us that they too need cutting down to size by way of a short, sharp (but not too sharp) reminder.
Of course, positive reinforcement (as encouragement is now called) is generally far more effective that negative enforcement, but it is a mistake to abandon the latter altogether. IT is needed when appropriate in accordance with Chazal's dictum (Sanhedrin 107b), "l'Olam Tehei Semol Docheh, v'Yamin Mekareves" -- "always, the left [hand] should push away while the right [hand] brings close."
I believe it is Rav Pam z"l who says, that since the pasuk refers to two maklos, noam and chovlim, one can be NOT chosech shivto, by using the makal no'am.