By Alex Dobuzinskis

(Reuters) - Maryam Mirzakhani, the first and only woman to receive the equivalent of the Nobel Prize for mathematics, died on Saturday at age 40 after a battle with cancer, said officials at Stanford University, the California school where she taught.

The death of the Tehran-born Mirzakhani, who specialized in theoretical mathematics, came three years after she received the Fields Medal at an event in Seoul.

The prize is handed out every four years to honor mathematicians under 40 who make major contributions. Mirzakhani was 37 when in 2014 she became the first woman to win the prize, which was established in 1936 and is equivalent to the Nobel Prize for mathematics.

The mathematician received the medal for her work in understanding the symmetry of curved surfaces, Stanford officials said in 2014.

Mirzakhani at the time said she had dreamed of becoming a writer when she was young, before taking an interest in mathematical problems.

"It is fun; it's like solving a puzzle or connecting the dots in a detective case," she said in 2014.

Growing up in Iran, she attended an all-girls high school and gained recognition as a teenager in the 1994 and 1995 competitions of the International Mathematical Olympiad.

She later graduated from Sharif University in Tehran and then headed to Harvard University in Massachusetts, to obtain her doctorate in mathematics.

Mirzakhani joined the faculty at Stanford in the San Francisco Bay area in 2008.

In recent years, she worked with Alex Eskin at the University of Chicago to investigate the trajectory of a billiard ball as it bounces around a polygonal table. The complexities in the ball's movement have long bedeviled physicists.

Mirzakhani, while solving mathematical problems, often drew on large sheets of paper while scribbling formulas on the edges, an approach that her young daughter believed to be a form of painting, according to Stanford.

Mirzakhani is survived by her husband, Jan Vondrák, and a daughter, Anahita. A Stanford spokesman said he did not have any information on where Mirzakhani died.

(Reporting by Alex Dobuzinskis in Los Angeles; Editing by Cynthia Osterman)