There is a project in which you need to have a lot of relatively simple mathematical transformations. Also for each transformation it is necessary to create and store the inverse transformation. I want to have a tool that would automatically build the inverse transform. For example, so that the 5 * x + 10 transformation is written as
transformation = Transformation(MultiplyBy(5), Add(10)) transformed_4 = transformation(4) but at the same time, so that the inverse transformation could be done like this
restored_4 = transformation.restore(transformed_4) assert restored_4 == 4 # не будем учитывать пока ошибки округления Perhaps there are ready-made solutions for such a task?