most of the code

pretty much finished. probably some problem with the ginv line. not
correct for H_n(R_k), n>3, k=3. not tested for other k.