def _flatten_add_f(expr01, cof_list, cof_dict, vector_add): if len(expr01.args) > 0: if isinstance(expr01, sympy.Add): arg_list = [] for i, argi in enumerate(expr01.args): argi_new = _flatten_add_f(argi, cof_list, cof_dict, vector_add) if isinstance(argi_new, M3): if vector_add: arg_list.append(argi_new) # except with both W and V else: wi = sympy.Symbol("W%s" % len(cof_list)) arg_list.append(sympy.Mul(wi, argi_new)) cof_list.append(wi) elif not argi_new.is_number: wi = sympy.Symbol("W%s" % len(cof_list)) arg_list.append(sympy.Mul(wi, argi_new)) cof_list.append(wi) else: arg_list.append(argi_new) return sympy.Add(*arg_list) elif isinstance(expr01, sympy.Mul): if NegativeOne() in expr01.args and len(expr01.args) == 2: argi = [i for i in expr01.args if i is not NegativeOne()][0] argi_new = _flatten_add_f(argi, cof_list, cof_dict, vector_add) return sympy.Mul(NegativeOne(), argi_new) else: return expr01 elif isinstance(expr01, M3): if vector_add: conu = expr01.conu if conu > 1: Wi = sympy.Symbol("V%s" % len(cof_dict)) argi = expr01.args[0] argi_new = _flatten_add_f(argi, cof_list, cof_dict, vector_add) expr02 = expr01.func(sympy.Mul(Wi, argi_new)) cof_dict[Wi] = conu return expr02 else: return expr01 else: return expr01 else: return expr01 else: return expr01
def test_core_numbers(): for c in (Catalan, Catalan(), ComplexInfinity, ComplexInfinity(), EulerGamma, EulerGamma(), Exp1, Exp1(), GoldenRatio, GoldenRatio(), Half, Half(), ImaginaryUnit, ImaginaryUnit(), Infinity, Infinity(), Integer, Integer(2), NaN, NaN(), NegativeInfinity, NegativeInfinity(), NegativeOne, NegativeOne(), Number, Number(15), NumberSymbol, NumberSymbol(), One, One(), Pi, Pi(), Rational, Rational(1,2), Real, Real("1.2"), Zero, Zero()): check(c)
def _represent_ZGate(self, basis, **options): """ Represent the OracleGate in the computational basis. """ nbasis = 2**self.nqubits # compute it only once matrixOracle = eye(nbasis) # Flip the sign given the output of the oracle function for i in range(nbasis): if self.search_function(IntQubit(i, nqubits=self.nqubits)): matrixOracle[i, i] = NegativeOne() return matrixOracle
def test_sympy__core__numbers__NegativeOne(): from sympy.core.numbers import NegativeOne assert _test_args(NegativeOne())