Is there any alternative ddx ddy for calculating normals when use DistanceToNearSurface?

Yes, when you are creating offsets using math functions, you can mathematically derive the normal. This thread shows the formula and an example of this being done using a Sine wave, just needs some minor teaks to work with cosine (or you could switch your wave to be based one sine).