Gravity and electrical force are both conservative forces. Mathematically, that means that a vector field of gravitational or electric force is conservative. You can prove this rather easily if you know vector calculus. What this means is that the integral of the force vector dotted with the differential of the displacement vector of an object (in other words, force times displacement, or work) is the same between any two points, regardless of path. This means we can define a scalar-valued "potential function" (say, p(X), where X is a position vector) for the field such that the work done by the object moving from point A to point B is p(B)-p(A), regardless of path.

Now, let's look at the effect that force has on an object. If an object of mass m is moving at v

_{1}, then is subject to a force over a displacement, it can be shown mathematically that it will end up moving at some velocity v

_{2}such that [math]\frac{1}{2} mv_2^2 =\frac{1}{2} mv_1^2 - \int_{position 1}^{position 2} force \cdot d(displacement)[/math] You should recognize the integral in that equation as the one I describe in my second paragraph. Per what I wrote in that paragraph, we can rewrite that equation as [math]\frac{1}{2} mv_2^2 =\frac{1}{2} mv_1^2 + p(position 1)-p(position 2)[/math] We rearrange that to get [math]\frac{1}{2} mv_2^2 + p(position 2)=\frac{1}{2} mv_1^2 + p(position 1)[/math] If we set the left hand equal to a constant (basically making position 1 a reference position), we get [imath]\frac{1}{2} mv_2^2 + p(position 2)= c[/imath] for any value of position 2! In other words, the sum of (.5mv

^{2}) and the value of the potential function of an object is the same regardless of position. Because it's convenient to give the terms in this equation names, we call .5mv

^{2}kinetic energy and we call the value of the potential function potential energy. We say that total energy, the sum of potential energy and kinetic energy, is conserved.

Up until this point, I was talking about only one force field. Will these same principles apply to the real world where there are innumerable electric and gravitational fields emanating from every subatomic particle? Yes, because it so happens that the sum of two conservative vector fields is conservative, and its potential function is the sum of the two fields' potential functions. Therefore, the net force on an object is always conservative, and energy is always conserved.

At this point, you may want to offer friction or some other "non-conservative" force as a counter-example to my above wall of text. In actuality, friction only appears non-conservative at the (useful) macroscopic level. Force is transferred in friction using electric forces, so the energy is still conserved and converted to heat. Heat is merely the kinetic and potential energy of molecules.