As mathematicians go, Srinivasa Ramanujan isn’t exactly a household name. But his genius — the ability to divine formulas seemingly from thin air that, a century later, are informing computer development, economics and the study of black holes — has long captivated academics and artists alike.

For Matthew Brown, the writer-director behind “The Man Who Knew Infinity,” opening Friday, April 29, mathematics was merely the canvas for a tale of two beautiful minds: Mr. Ramanujan, a South Indian autodidact who believed that an equation held no meaning unless it expressed a thought of God, and G. H. Hardy, a Cambridge professor and atheist who refused to believe in what he could not prove.

Their collaboration — recreated here by Dev Patel and Jeremy Irons — was “the one romantic incident in my life,” Mr. Hardy would later recall.

In 1913, Mr. Ramanujan (pronounced rah-MAH-new-jin), an impoverished shipping clerk with little formal education, wrote to Mr. Hardy, a lecturer at Trinity College, in the hope of having his work published. The nine-page letter, filled with astonishing formulas that, as Mr. Hardy wrote, “seemed scarcely possible to believe,” prompted him to wonder if Mr. Ramanujan were a fraud. But after discussions with his colleague J. E. Littlewood, Mr. Hardy declared the young man’s brilliance on par with that of the renowned mathematicians Leonhard Euler and Carl Jacobi, and invited Mr. Ramanujan to Cambridge in the hope of seeing proof of his assertions.