Minimal case given. In Sage `hash(matrix())`

will not allow hashing probably because `PyObject_Hash`

will fail and to prevent that. The fail happens in Pynac nevertheless because the check is avoided due to function expansion and there leads to the crash.

One part of the fix is preventing Sage from crashing. Surrounding the call to Pynac in `Expression::__nonzero__`

with guards:

sig_on()
pynac_result = relational_to_bool(self._gobj)
sig_off()

leads to:

sage: bool(f(x)==f(x))
terminate called after throwing an instance of 'std::runtime_error'
what(): Number_T::hash() python function (__hash__) raised exception
---------------------------------------------------------------------------
TypeError: mutable matrices are unhashable

which is the same you get with `hash(matrix())`

, so quite sensible. What more? Why are matrices generated by `vector*vector`

(the original case) or those in a function definition (like above) mutable at all?