(self, **hints)
Distribute TensorProducts across addition.
Distribute TensorProducts across addition.
Distribute TensorProducts across addition .
def _eval_expand_tensorproduct(self, **hints):
        """Distribute TensorProducts across addition."""
        args = self.args
        add_args = []
        stop = False
        for i in range(len(args)):
            if isinstance(args[i], Add):
                for aa in args[i].args:
                    tp = TensorProduct(*args[:i] + (aa,) + args[i + 1:])
                    if isinstance(tp, TensorProduct):
                        tp = tp._eval_expand_tensorproduct()
                    add_args.append(tp)
                break

        if add_args:
            return Add(*add_args)
        else:
            return self
def _eval_expand_tensorproduct ( self , * * hints ) : args = self . args add_args = [ ] stop = False for i in range ( len ( args ) ) : if isinstance ( args [ i ] , Add ) : for aa in args [ i ] . args : tp = TensorProduct ( * args [ : i ] + ( aa , ) + args [ i + 1 : ] ) if isinstance ( tp , TensorProduct ) : tp = tp . _eval_expand_tensorproduct ( ) add_args . append ( tp ) break if add_args : return Add ( * add_args ) else : return self