Proving the law of cosines