how to estimate RAM usage of math functions

If that’s the whole code then something else must have been going on, the maths functions you use do not add so much RAM pressure at all. Are you sure you had the serial console at the right speed in the first test?

I can’t test your first code for the moment but will give it à go later