A computer-implemented method for obtaining a detection or a prediction about a state of a physical system, the method comprising: - retrieving a mathematical tool for machine learning, wherein the mathematical tool processes a plurality of input values to provide one or more output values and wherein the mathematical tool is an artificial neural network, - converting the mathematical tool into one or more mathematical functions, wherein each mathematical function maps the plurality of input values to a function value that coincides with one of the one or more output values; - applying at least one patch to at least one of the one or more mathematical functions, wherein the at least one patch comprises at least one mathematical expression that acts on the function value of the at least one patched mathematical function and has the potential to modify it; - retrieving a plurality of state input values related to the physical system; - computing one or more state function values by feeding the plurality of state input values to the one or more mathematical functions including the at least one patched mathematical function; - obtaining the detection or prediction from the one or more state function values; wherein the one or more mathematical functions comprise a plurality of weights of the artificial neural network and the at least one patch does not modify the plurality of weights, wherein: the physical system is a binary image, the plurality of state input values are greyscale of pixels, the detection includes character recognition, and the at least one mathematical expression comprises a conditional statement on a number of non-white pixels in the binary image, or the physical system is a battery, the plurality of state input values are values for resistance, voltage, current, battery temperature and environment temperature, the prediction includes forecasting battery duration, and the at least one mathematical expression takes into consideration usage data of the battery. - retrieving a mathematical tool for machine learning, wherein the mathematical tool processes a plurality of input values to provide one or more output values and wherein the mathematical tool is an artificial neural network, - converting the mathematical tool into one or more mathematical functions, wherein each mathematical function maps the plurality of input values to a function value that coincides with one of the one or more output values; - applying at least one patch to at least one of the one or more mathematical functions, wherein the at least one patch comprises at least one mathematical expression that acts on the function value of the at least one patched mathematical function and has the potential to modify it; - retrieving a plurality of state input values related to the physical system; - computing one or more state function values by feeding the plurality of state input values to the one or more mathematical functions including the at least one patched mathematical function; - obtaining the detection or prediction from the one or more state function values; wherein the one or more mathematical functions comprise a plurality of weights of the artificial neural network and the at least one patch does not modify the plurality of weights, wherein: the physical system is a binary image, the plurality of state input values are greyscale of pixels, the detection includes character recognition, and the at least one mathematical expression comprises a conditional statement on a number of non-white pixels in the binary image, or the physical system is a battery, the plurality of state input values are values for resistance, voltage, current, battery temperature and environment temperature, the prediction includes forecasting battery duration, and the at least one mathematical expression takes into consideration usage data of the battery. the physical system is a binary image, the plurality of state input values are greyscale of pixels, the detection includes character recognition, and the at least one mathematical expression comprises a conditional statement on a number of non-white pixels in the binary image, or the physical system is a battery, the plurality of state input values are values for resistance, voltage, current, battery temperature and environment temperature, the prediction includes forecasting battery duration, and the at least one mathematical expression takes into consideration usage data of the battery.