Should non mathematicians learn mathematics "just in time" or ahead of time? I am wondering how someone that is not exclusively interested in mathematics (but nevertheless aims to become a decent applied mathematician), but for example, a theoretical computer scientist, should go about learning higher level mathematics? 
Would it be optimal to learn some interesting topics in mathematics that they think they may need ahead of time (in isolation to their field) or would it be better to just learn their field (theoretical CS for example), and dive into learning the relevant math only when encountering some topic that needs it. 
I think that learning mathematics "just in time" would be the way to go, since the practicality of the subject is known beforehand and the concepts can be applied immediately, thus reinforcing the learned material. For example, if one takes 2 semesters of advanced linear algebra without practicing it much after that, a year (months even!) later most of the material is forgotten. However, when one only learns linear algebra thoroughly when he discovers that he needs it to complete a project in machine learning, he might learn the mathematics more optimally. 
The question arose because I'm considering if I should just take a lot of advanced math courses this semester or concentrate on CS subjects (for example cryptography), and learn the required math individually (for example number theory) when the relevant concepts are encountered. 
Thank you. 
PS. Mind you, the question really isn't about learning just enough mathematics to understand the CS concepts in hand. It is more about how a computer scientist should go about learning mathematics, when he ALSO aims to become a decent mathematician. 
 A: I expect that there are quite a few people on this site
(myself included) who have earned degrees in mathematics and computer science
at separate times and have experience both with the "just in time" learning
and covering things far in advance of applying them.
Even if you do a complete undergraduate math degree before getting
seriously into CS, I believe you would still find that you'll be
learning a lot of the math you need for CS on a "just in time" basis.
That was my experience, at any rate.  Many years afterward
I still find myself learning applicable mathematics from time to time.
On the other hand, if you're going to need much in the way of math
to do your CS work, it's highly desirable to be able to teach yourself
what you need to know "just in time."
(Otherwise, you'll be hard pressed to learn it in time at all.)
If you pick up a graduate-level math textbook,
or even one for upper-level undergraduates, 
how difficult will it be to navigate your way through it
and glean a sufficient understanding of the things you need to know?
Just painstakingly difficult, or apparently-insurmountably difficult?
When you're self-teaching, there's a lot to be said for already being
comfortable with the way higher-level math is presented and with the
kinds of thought processes that are involved.
You may pick up these things differently than I do, but I personally
find that needing something in a hurry to use in a particular application
is not a conducive situation for picking up on the deeper levels of thought
in a mathematical paper or book.
So at some point (not necessarily this semester) it might be wise to
take some math courses where you have to work out some
relatively abstract material by your own effort.
Exactly what courses those would be is something you'd have to discuss
with an adviser at your university who knows the field and knows the
nature of the courses offered there.
Linear algebra, for example, could be the perfect course to take or
completely the wrong course.
Besides, if you actually like any kind of math, 
and can find the right courses 
at your university, the math should be interesting for its own sake,
even if you don't see an immediate payback in your CS work.
(I think it's likely there would be some immediate payback, 
though it might not
be a direct and obvious application of the math you learned.)
A: In my experience, learning "just in time" has several advantages:


*

*The leaner has the incentive to learn, seeing the near need

*Having applications at hand, specifically applications of immediate interest to the learner, makes understanding easier

*Learning at the hand of concrete examples avoids being led astray, concentrating on the correct way to apply the learned material

*Learning "ahead of time" might mean that, by the time the use comes around, the material is already forgotten

