An optical frequency standard based on ultracold magnesium atoms