Ad function to compute power of a matrix