I am trying to understand how to get the discrete gradient of a mesh that is being used as the input of some function $$f$$. In other words for every vertex $$v$$ there is a scalar quantity $$s$$ associated with it.

I am trying to understand how to compute the discrete gradient of $$f$$ on the surface. For that purpose I was checking these slides:

http://www.hao-li.com/cs599-ss2015/slides/Lecture04.1.pdf

But it's not clicking. The piece wise notation I am assuming is just an attempt at formalizing "we have no idea what the values at the triangles would be, so we are just going to linearly interpolate using Barycentric coordinates".

But then the slides reach this final formula for the gradient: I kinda understand the bottom part, which seems to say the gradient basis at $$i$$ is a vector orthogonal to the opposite edge divided by 2 times the area of the triangle (I assume), but how was the top formula derived?

It's defining the gradient in terms of barycentric coordinates. It is similar to the derivation in this answer, only rearranged a bit algebraically using the fact that the three barycentric coordinates sum to one. \begin{aligned} f(\mathbf{u}) &= f_i B_i(\mathbf{u}) + f_j B_j(\mathbf{u}) + f_k B_k(\mathbf{u}) \\ &= f_i (1 - B_j(\mathbf{u}) - B_k(\mathbf{u})) + f_j B_j(\mathbf{u}) + f_k B_k(\mathbf{u}) \\ &= f_i + (f_j - f_i) B_j(\mathbf{u}) + (f_k - f_i) B_k(\mathbf{u}) \\ \nabla f(\mathbf{u}) &= (f_j - f_i) \nabla B_j(\mathbf{u}) + (f_k - f_i) \nabla B_k(\mathbf{u}) \\ \end{aligned}