This December, Martin Lersch, a Norwegian chemist and a passionate cook, rolled out his homemade gingerbread dough and got to work. He flipped his cookie cutter to and fro repeatedly, creating a quilt of cookies in the shape of Christmas trees. But Lersch’s main goal wasn’t simply a batch of delicious holiday cookies. He wanted to bake mathematically perfect ones. For the last few years, Lersch has attempted to solve a problem that often bedevils cookie bakers. “You want to make best possible use of the dough without having to…