An expansion formula for differential equations