An inversion algorithm for P-functions with applications to multi-energy CT. (7th February 2022)