Makes it possible to custom define inverses on only one side

This also adds a cache to inverseFor
Refactor inverseFor cache
Merge pull request #2293 from eniolopes/improve-inverse-for

Adds caching to inverseFor and implements look for inverses on the other side