What does the expression “rabbit-out-of-a-hat” mean? [duplicate]

Solution 1:

Referring to proof steps as “rabbit-out-of-a-hat” or as like pulling a rabbit out of a hat is not slang, but rather a popular metaphor in mathematical writing (1,2,3,4,5,6). Generally, it refers to use of unmotivated, non-intuitive, “out of left field”, “out of the blue”, or “off the wall” techniques, that at first may seem completely unrelated to what is being proved and that may seem mysterious or magical. Rabbit-from-hat steps are denigrated when they do not illustrate a method that can be used in proving other theorems, or when the train of thought that prompted the step gets tidied away out of sight.

Solution 2:

It's an analogy to a popular magic trick. The magician shows the audience an empty top hat. They then place the hat upside-down on a table and pull a live rabbit out of it.

The implication of "rabbit-out-of-a-hat" is that the person has unexpectedly produced a desired result, with no indication of how they achieved it.