I guess you cannot implement certain systems that heavily depend on the underlying hardwares features and traits using formal mathematics (not counting the programming language as one here)
But the "non optimized"/brute force algorithm which you are implementing in the above, or a simple mostly-mathematical algorithm, will be more cumbersome to get working by assembling the system in your head and throwing in a couple of operators until it works, than it would if you used proper math to derieve the formulas.
Personally i see it as follows:
1. Obtain formula (through knowledge, google or derieving it yourself)
2. Transform formula into non-brute-force form by applying random optimizations and a couple of tree based operations here and there
3. Implement optimized formula
The only reason we cannot or should not use "formal" mathematics from the start to the end is because:
*Simpler algorithms are sometimes easier to figure out without a language at all
*Mathematics stops being useful when you want to move from the brute force version to the optimized one (a significant part of the program can be about the optimizations, especially the large scale ones where you save precalculated values and handle their storage etc.)
Eg. what formal mathematics give us is a brute force algorithm for figuring out what the physically correct color of a pixel is. Then one needs to modify this formula by cutting insignificant parts out, approximating others, parallelizing it, taking into account temporal/spatial coherence etc.
The latter part is usually dependent on the hardware and things like appriximation are often subjective, so it doesnt fit into formal mathematics as well as the first part does. I am not saying it couldnt be a part of formal mathematics however, maybe we just lack the language for that stuff, and even if we had a language, it would be very specific and thus probably not widely used outside of professional/academia.