There are both convex and concave lenses that may form different types of images when the object is in different places. If a general formula could be found it would appear that proving it in all cases would be a long job.
Nicha, a tenth grade student at ISB, solved the problem very neatly. She argued that the seemingly endless possibilities reduce to just six when the object is real ..............
1 A real image in a convex lens
2 A virtual image in a convex lens
3 A virtual image in a concave lens
4 A real image in a concave mirror
5 A virtual image in a concave mirror
6 A virtual image in a convex mirror
..........and that the six different possibilities reduce to just three by grouping (1 and 4), (2 and 5), and (3 and 6). Her solution is reproduced here.
1 and 4 A real image with a converging lens or mirror. The well known reciprocal formula applies with all positive signs.
2 and 5 A virtual image with a converging lens or mirror. The same formula applies, with a negative image distance.
3 and 6 A virtual image with a diverging lens or mirror. The same formula applies, with two negative signs.
The lens formula is shown to be a correct description provided we remember that diverging devices have negative focal lengths and the distance to a virtual image is also negative.