Tests to see if a PauliTerm or PauliSum is a scalar multiple of identity

    :param term: Either a PauliTerm or PauliSum
    :returns: True if the PauliTerm or PauliSum is a scalar multiple of identity, False otherwise
    :rtype: bool
483571
def is_identity(term):
    
    if isinstance(term, PauliTerm):
        return (len(term) == 0) and (not np.isclose(term.coefficient, 0))
    elif isinstance(term, PauliSum):
        return (len(term.terms) == 1) and (len(term.terms[0]) == 0) and \
               (not np.isclose(term.terms[0].coefficient, 0))
    else:
        raise TypeError("is_identity only checks PauliTerms and PauliSum objects!")
859995
def _verify_multi(self, token, verifying_keys, num_required=None):
        
        headers, payload, raw_signatures, signing_inputs = _unpack_token_json(token)
        if num_required is None:
            num_required = len(raw_signatures)

        if num_required > len(verifying_keys):
            # not possible
            return False

        if len(headers) != len(raw_signatures):
            # invalid 
            raise DecodeError('Header/signature mismatch')

        verifying_keys = [load_verifying_key(vk, self.crypto_backend) for vk in verifying_keys]

        # sanity check: only support one type of key :(
        for vk in verifying_keys:
            if vk.curve.name != verifying_keys[0].curve.name:
                raise DecodeError("TODO: only support using keys from one curve per JWT")
                
        der_signatures = [raw_to_der_signature(rs, verifying_keys[0].curve) for rs in raw_signatures]

        # verify until threshold is met
        num_verified = 0
        for (signing_input, der_sig) in zip(signing_inputs, der_signatures):
            for vk in verifying_keys:
                verifier = self._get_verifier(vk, der_sig)
                verifier.update(signing_input)
                try:
                    verifier.verify()
                    num_verified += 1
                    verifying_keys.remove(vk)
                    break
                except InvalidSignature:
                    pass

            if num_verified >= num_required:
                break

        return (num_verified >= num_required)
1186512
public static boolean isIdentity(ZMatrix mat , double tol ) {
        // see if the result is an identity matrix
        Complex_F64 c = new Complex_F64();
        for (int i = 0; i < mat.getNumRows(); i++) {
            for (int j = 0; j < mat.getNumCols(); j++) {
                mat.get(i, j, c);
                if (i == j) {
                    if (!(Math.abs(c.real - 1) <= tol))
                        return false;
                    if (!(Math.abs(c.imaginary) <= tol))
                        return false;
                } else {
                    if (!(Math.abs(c.real) <= tol))
                        return false;
                    if (!(Math.abs(c.imaginary) <= tol))
                        return false;
                }
            }
        }

        return true;
    }
112359
def is_identity():
        """"""
        for index, row in enumerate(self.dta):
            if row[index] == 1:
                for num, element in enumerate(row):
                    if num != index:
                        if element != 0:
                            return False
            else:
                return False

        return True
894611
def composition
      root_terms.reduce(SignedMultiset.new) do |s, t|
        s.increment(t.atom.dim, t.exponent) if t.atom
        s
      end
    end
1363837
def scalar_term(self, st):
        """"""
        if isinstance(st, binary_type):
            return _ScalarTermS(st, self._jinja_sub)
        elif isinstance(st, text_type):
            return _ScalarTermU(st, self._jinja_sub)
        elif st is None:
            return _ScalarTermU(u(''), self._jinja_sub)
        else:
            return st
1200816
@Override
    public boolean containsTerm(Term t) {
        List<Term> terms = getTerms();
        for (int i = 0; i < terms.size(); i++) {
            Term t2 = terms.get(i);
            if (t2.equals(t))
                return true;
        }
        return false;
    }
441318
def p_scalar_namespace_name(p):
    ''''''
    if len(p) == 2:
        p[0] = ast.Constant(p[1], lineno=p.lineno(1))
    elif len(p) == 3:
        p[0] = ast.Constant(p[1] + p[2], lineno=p.lineno(1))
    else:
        p[0] = ast.Constant(p[1] + p[2] + p[3], lineno=p.lineno(1))
543697
private TernaryVector getTermIndexVector(String term) {
        TernaryVector iv = termToIndexVector.get(term);
        if (iv == null) {
            // lock in case multiple threads attempt to add it at once
            synchronized(this) {
                // recheck in case another thread added it while we were waiting
                // for the lock
                iv = termToIndexVector.get(term);
                if (iv == null) {
                    // since this is a new term, also map it to its index for
                    // later look-up when the integer documents are processed
                    termToIndex.put(term, termIndexCounter++);
                    // next, map it to its reflective vector which will be
                    // filled in process space
                    termToReflectiveSemantics.put(term, createVector());
                    // last, create an index vector for the term
                    iv = indexVectorGenerator.generate();
                    termToIndexVector.put(term, iv);                    
                }
            }
        }
        return iv;
    }
402170
function isMultiplyByOne(node) {
    return node.operator === "*" && (
        node.left.type === "Literal" && node.left.value === 1 ||
        node.right.type === "Literal" && node.right.value === 1
    );
}
1123168
def p_term_bool(self, p):
        '''  
        '''
        _LOGGER.debug("term -> TRUE/FALSE")

        if p[1].lower() == 'true':
            p[0] = TypedClass(True, TypedClass.BOOLEAN)
        else:
            p[0] = TypedClass(False, TypedClass.BOOLEAN)
1259976
def isIdentity(M, tol=1e-06):
    """"""
    for i in [0, 1, 2, 3]:
        for j in [0, 1, 2, 3]:
            e = M.GetElement(i, j)
            if i == j:
                if np.abs(e - 1) > tol:
                    return False
            elif np.abs(e) > tol:
                return False
    return True
1028807
public static boolean hasNaN( ZMatrixD1 m )
    {
        int length = m.getDataLength();

        for( int i = 0; i < length; i++ ) {
            if( Double.isNaN(m.data[i]))
                return true;
        }
        return false;
    }
800593
private static boolean validateTermWithStartValue(BytesRef term,
      ComponentTermVector termVector) {
    if (termVector.startValue == null) {
      return true;
    } else if (termVector.subComponentFunction.sortType
        .equals(CodecUtil.SORT_TERM)) {
      if (term.length > termVector.startValue.length) {
        byte[] zeroBytes = (new BytesRef("\u0000")).bytes;
        int n = (int) (Math
            .ceil(((double) (term.length - termVector.startValue.length))
                / zeroBytes.length));
        byte[] newBytes = new byte[termVector.startValue.length
            + n * zeroBytes.length];
        System.arraycopy(termVector.startValue.bytes, 0, newBytes, 0,
            termVector.startValue.length);
        for (int i = 0; i < n; i++) {
          System.arraycopy(zeroBytes, 0, newBytes,
              termVector.startValue.length + i * zeroBytes.length,
              zeroBytes.length);
        }
        termVector.startValue = new BytesRef(newBytes);
      }
      if ((termVector.subComponentFunction.sortDirection.equals(
          CodecUtil.SORT_ASC) && (termVector.startValue.compareTo(term) < 0))
          || (termVector.subComponentFunction.sortDirection
              .equals(CodecUtil.SORT_DESC)
              && (termVector.startValue.compareTo(term) > 0))) {
        return true;
      }
    }
    return false;
  }
156063
def shared_parameters(self):
        
        if len(self) == 1:  # Not a vector
            return False
        else:
            params_thusfar = []
            for component in self.values():
                vars, params = seperate_symbols(component)
                if set(params).intersection(set(params_thusfar)):
                    return True
                else:
                    params_thusfar += params
            else:
                return False
1168286
function isSymbolTerm(node, symbolName) {
  if (Node.PolynomialTerm.isPolynomialTerm(node)) {
    const polyTerm = new Node.PolynomialTerm(node);
    if (polyTerm.getSymbolName() === symbolName) {
      return true;
    }
  }
  return false;
}
590373
def __recognize_scalar(self, node: yaml.Node,
                           expected_type: Type) -> RecResult:
        
        logger.debug('Recognizing as a scalar')
        if (isinstance(node, yaml.ScalarNode)
                and node.tag == scalar_type_to_tag[expected_type]):
            return [expected_type], ''
        message = 'Failed to recognize a {}\n{}\n'.format(
            type_to_desc(expected_type), node.start_mark)
        return [], message