Hadamard investigates these kinds of issues at length in his book [The psychology of invention in the mathematical field][1]. He gives several examples of famous mathematicians dreaming about solutions, including Poincare. His conclusion is that the unconscious definitely plays a decisive role in mathematics, and that sleep often has to do with it, but that it differs from person to person how to tap in to it. It is (necessarily) a bit pseudoscientific, but has some great tidbits. For example, did you know Mobius' grandson, who was a psychologist into the then-popular [phrenology][2], actually went around measuring mathematicians' heads, trying to locate the "bump" in the skull where mathematical ability should lie? [1]: https://books.google.co.uk/books?id=iikWvQgOC5AC&printsec=frontcover&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false [2]: https://en.wikipedia.org/wiki/Phrenology