General mean value and remainder theorems with applications to mechanical differentiation and quadrature