コード例 #1
0
    def __new__(cls, *args, **assumptions):
        if assumptions.get('evaluate') is False:
            args = map(_sympify, args)
            obj = Expr.__new__(cls, *args, **assumptions)
            obj.is_commutative = all(arg.is_commutative for arg in args)
            return obj
        if len(args)==0:
            return cls.identity
        if len(args)==1:
            return _sympify(args[0])
        c_part, nc_part, order_symbols = cls.flatten(map(_sympify, args))
        if len(c_part) + len(nc_part) <= 1:
            if c_part:
                obj = c_part[0]
            elif nc_part:
                obj = nc_part[0]
            else:
                obj = cls.identity
        else:
            obj = Expr.__new__(cls, *(c_part + nc_part), **assumptions)
            obj.is_commutative = not nc_part

        if order_symbols is not None:
            obj = C.Order(obj, *order_symbols)
        return obj
コード例 #2
0
ファイル: gate.py プロジェクト: rainly/sympy
 def _eval_args(cls, args):
     targets = args[0]
     if not isinstance(targets, (list, tuple, Tuple)):
         targets = (targets,)
     targets = Gate._eval_args(targets)
     _validate_targets_controls(targets)
     mat = args[1]
     if not isinstance(mat, Matrix):
         raise TypeError("Matrix expected, got: %r" % mat)
     dim = 2 ** len(targets)
     if not all([dim == shape for shape in mat.shape]):
         raise IndexError("Number of targets must match the matrix size: %r %r" % (targets, mat))
     return (targets, mat)
コード例 #3
0
ファイル: gate.py プロジェクト: yuri-karadzhov/sympy
 def _eval_args(cls, args):
     targets = args[0]
     if not isinstance(targets, (list, tuple, Tuple)):
         targets = (targets, )
     targets = Gate._eval_args(targets)
     _validate_targets_controls(targets)
     mat = args[1]
     if not isinstance(mat, Matrix):
         raise TypeError('Matrix expected, got: %r' % mat)
     dim = 2**len(targets)
     if not all([dim == shape for shape in mat.shape]):
         raise IndexError(
             'Number of targets must match the matrix size: %r %r' %\
             (targets, mat)
         )
     return (targets, mat)
コード例 #4
0
ファイル: gate.py プロジェクト: fxkr/sympy
 def _eval_args(cls, args):
     targets = args[0]
     if not ordered_iter(targets, include=Tuple):
         targets = (targets,)
     targets = Gate._eval_args(targets)
     _validate_targets_controls(targets)
     mat = args[1]
     if not isinstance(mat, Matrix):
         raise TypeError('Matrix expected, got: %r' % mat)
     dim = 2**len(targets)
     if not all([dim == shape for shape in mat.shape]):
         raise IndexError(
             'Number of targets must match the matrix size: %r %r' %\
             (targets, mat)
         )
     return (targets, mat)
コード例 #5
0
ファイル: gate.py プロジェクト: yuri-karadzhov/sympy
 def eval_controls(self, qubit):
     """Return True/False to indicate if the controls are satisfied."""
     return all([qubit[bit] == self.control_value for bit in self.controls])
コード例 #6
0
ファイル: gate.py プロジェクト: fxkr/sympy
 def eval_controls(self, qubit):
     """Return True/False to indicate if the controls are satisfied."""
     return all([qubit[bit]==self.control_value for bit in self.controls])
コード例 #7
0
ファイル: algorithms.py プロジェクト: laudehenri/rSymPy
 def independent(h):
     return all(not monom[0] for monom in h.monoms)
コード例 #8
0
ファイル: algorithms.py プロジェクト: gnulinooks/sympy
 def independent(h):
     return all(not monom[0] for monom in h.monoms)