Once. The only battle I have ever lost against game AI was the very first one when the rival got a critical hit at a bad time. I tend to have all mine around level 60 by the E4. I level grind a lot.
and lance didn't give me any trouble at all. Level 60 lugia with an Ice attack can nuke him, espiecally if you have ice beam. The team loaded with dragonites is terribly weak against one pokemon with a decent ice attack. and a decent electric attack can one hit Gyrados. You can pretty much one hit his entire team with electric and ice attacks
Honestly I was disappointed that the E4's levels were in the 40s and 50s. I mean, they are the final trainers. IMO they should at least be in the high 50s, mid 60s the first time through. and mid 70's to 80 on the rematch.