Cleanup: factor some matrix tools out of noconstrain.py.  Next goal: add withconstraint.py which has minimal code duplication with noconstraint.py.