Course of action after failing a (non-maths) course in hopes of entering grad school for maths?
In my experience, this should not have much/any impact on your grad school applications (assuming you do well in all of your other courses).  A single failed class in an unrelated area just doesn't say anything about your ability to do research in mathematics.  (This is predicated on all of your other grades being very good, and the F being unrelated to any sort of academic misconduct, of course.)  As for course of action, I think you've already identified it: make sure this is a single F in an otherwise excellent transcript, particularly high marks in challenging courses related to your intended area of graduate study.

Personal anecdote:

I am currently in my first year of a pure math phd program in a (roughly) top 20-25 program, and I failed a non-math class in my junior year of undergraduate (something to do with neural networks) for reasons along the lines of yours.  My overall GPA by the time I applied was a 3.75 or so.  I didn't say anything about the F in my applications since it was not particularly relevant to mathematical research.  (In my Statement of Purpose, I wrote about research I had done and areas I was interested in pursuing further research.  A failed neural networks class didn't seem worth noting.)  I did get rejected from two top 10 programs, and maybe that was the reason, though I doubt it.

Hopefully some people who have served on graduate admissions committees in math departments will weigh in on this since my experience may not generalize.