Duality and distance formulas in Banach function space