> +    """Matrix Trace
> +
> +    Represents the trace of a matrix expression.
> +
> +    >>> from sympy import MatrixSymbol, Trace, eye
> +    >>> A = MatrixSymbol('A', 3, 3)
> +    >>> Trace(A)
> +    Trace(A)
> +
> +    >>> Trace(eye(3))
> +    3
> +    """
> +    is_Trace = True
> +    def __new__(cls, mat):
> +        if not mat.is_Matrix:
> +            raise TypeError("input to Trace, %s, is not a matrix"%str(mat))

I think we shouldn't be close-minded about what Trace can handle. I would 
suggest to allow other classes to define `_eval_trace` if it makes sense for 
them, instead of restricting what kind of input Trace can have. This means 
removing the check on `mat.is_Matrix` here. If `mat._eval_trace()` is defined, 
we return that, if not, return an instance of `Trace`, as below. Then anybody 
including the quantum folks will be able to use Trace without touching its 
internals, by defining `_eval_trace` for their own classes. What do you think?

---
Reply to this email directly or view it on GitHub:
https://github.com/sympy/sympy/pull/1456/files#r1332068

-- 
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patches@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-patches+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to