Math, science, and logic can explain a lot but not everything about how music works. The strange thing, though, is that great music almost always has a perfect logic to it. How is that possible?
When you study music—learn an instrument, how to compose, improvise, etc.—you are essentially learning a kind of mathematical language of sound moving through time. It’s a system of ratios, addition, subtraction, multiplication, and division.
We musicians may not think about this consciously, but on some level, we’re always processing the act of music-making through logical and mathematical principles. 5/8 time? We think 3+2 or 2+3. F7#9? We think of a chord based on a series of intervals that, when put together, “add” up to that chord. The chord itself can be derived from one or more scales that themselves consist of a series of intervals, which are in turn derived from acoustical ratios that make those scales (usually five or seven notes) add up. Even the way we figure out which fingers to use when playing the piano—a complex calculus that balances the physical layout of the keyboard, the relative strength and weakness of each finger, and the requirements of the music itself—involves high-level mathematical decision making.
Is this too much cold, hard math for you, dear listener? Will this ruin your experience of, say, Sweet Caroline (in a way, I mean, that the overplaying of that Neil Diamond classic hasn’t already?) **Well, here’s the cold, hard truth: you also process music this way. You may not know you’re hearing 5/8 time or an F7#9, but a part of your brain is devoted to breaking down those sonic phenomena into to the very ratios that make them pleasing (or stressful, or sad, or elusive.)
The point is, the emotional experience of music is fundamentally based on these ratios. To be sure, there are other factors—cultural, sentiment, memory—that contribute to our experience of music. But the underlying reality of music, like everything else in the universe, is a kind of math.
That doesn't render the emotional experience of listening to music a dull exercise in logic. But it does remind us that there's a lot of "data" contributing to our experience. Some of the data we can come to understand through study. The deepest levels, like the ultimate nature of reality itself, however, will always remain elusive.