There is a mathematical language that actually describes a program, or rather, its operations. You take the initial state, and then transform this state until you reach the desired target state. Conversions give the program code that must be executed.
See the Wikipedia article on Hoar logic .
The basic idea is that for each function (regardless of whether you put it in a class or in an old-style function), you have a pre-condition and a post-condition. For example, a precondition may be that you have an array with >= 0 elements. The post-condition is that each element [i] must be equal to <= element [j] for each i <= j.
The usual description would be "function sorts array". But mathematical terms allow you to convert an input (which must correspond to a precondition) into output (which must correspond to a postcondition).
This is a bit cumbersome to use, especially for more complex programs, but some of the examples are pretty impressive. Often you get really compact code as a result, which looks rather complicated, but works on the first try.
source share