Performs multiple substitutions in an expression
    :param expr: a sympy matrix or expression
    :param pairs: a list of pairs (a,b) where each a_i is to be substituted with b_i
    :return: the substituted expression
348984
def substitute_all(sp_object, pairs):
    
    if not isinstance(pairs, dict):
        dict_pairs = dict(pairs)
    else:
        dict_pairs = pairs

    # we recurse if the object was a matrix so we apply substitution to all elements
    if isinstance(sp_object, sympy.Matrix):
        return sp_object.applyfunc(lambda x: substitute_all(x, dict_pairs))

    try:
        expr = sp_object.xreplace(dict_pairs)

    # in sympy 0.7.2, this would not work, so we do it manually
    except Exception:
        expr =  sp_object
        for (a,b) in dict_pairs.items():
            expr = sympy.Subs(expr, a, b)
        expr = expr.doit()
    return expr
211631
def pairwise(values):
    
    i = iter(values)
    a = next(i)

    for b in i:
        yield (a, b)
        a = b
481609
def substitute(expr, var_map):
    
    try:
        if isinstance(expr, SympyBasic):
            sympy_var_map = {
                k: v for (k, v) in var_map.items()
                if isinstance(k, SympyBasic)}
            return expr.subs(sympy_var_map)
        else:
            return expr.substitute(var_map)
    except AttributeError:
        if expr in var_map:
            return var_map[expr]
        return expr
1365770
def p_expression_inlist(self, p):
        '''  
        '''
        _LOGGER.debug("expresion -> expresion IN lexp")

        if self._autodefine_vars:
            self._init_vars(TypedList([]), p[3])

        if p[3].type != TypedClass.LIST: raise TypeError("expected list for IN operator")
        
        retval = False
        for v in p[3].value:
            if p[1] == v:
                retval = True
                break
        
        p[0] = TypedClass(retval, TypedClass.BOOLEAN)
540702
def p_expr_new(p):
    ''
    p[0] = ast.New(p[2], p[3], lineno=p.lineno(1))
829097
def p_expr_usr(p):
    
    if p[2].type_ == TYPE.string:
        p[0] = make_builtin(p.lineno(1), 'USR_STR', p[2], type_=TYPE.uinteger)
    else:
        p[0] = make_builtin(p.lineno(1), 'USR',
                            make_typecast(TYPE.uinteger, p[2], p.lineno(1)),
                            type_=TYPE.uinteger)
1363687
def expr(self, callback):
        
        nodes = []
        for node in self.nodes:
            if callback(node):
                nodes.append(node)
        self.nodes = nodes
        return self
1275276
def p_expr_plus_expr(p):
    
    p[0] = make_binary(p.lineno(2), 'PLUS', p[1], p[3], lambda x, y: x + y)
787514
def _transformBy(self, matrix, **kwargs):
        
        t = transform.Transform(*matrix)
        transformation = t.transform(self.transformation)
        self.transformation = tuple(transformation)
774204
def _get_expr_variables(expression: z3.ExprRef) -> List[z3.ExprRef]:
    
    result = []
    if not expression.children() and not isinstance(expression, z3.BitVecNumRef):
        result.append(expression)
    for child in expression.children():
        c_children = _get_expr_variables(child)
        result.extend(c_children)
    return result
1303699
def p_expr_assign(p):
    ''''''
    if len(p) == 5:
        p[0] = ast.Assignment(p[1], p[4], True, lineno=p.lineno(2))
    else:
        p[0] = ast.Assignment(p[1], p[3], False, lineno=p.lineno(2))
1165939
def _merge_expressions(self, other):
        
        new_inputs = tuple(set(self.inputs).union(other.inputs))
        new_self_expr = self._rebind_variables(new_inputs)
        new_other_expr = other._rebind_variables(new_inputs)
        return new_self_expr, new_other_expr, new_inputs
1077805
def forward_substitute(l, s)
			raise 'l must be a lower triangular matrix' unless l.lower_triangular?

			x = Array.new s.row_size

			x.size.times do |i|
				x[i] = s[i, 0]

				i.times do |j|
					x[i] -= l[i, j] * x[j]
				end

				x[i] /= l[i, i]
			end

			Matrix.column_vector x
		end
541695
def eval_expr(expr, context):
    
    if isinstance(expr, list):
        rv = []
        for item in expr:
            rv.append(eval_expr(item, context))
        return rv
    if isinstance(expr, dict):
        rv = {}
        for k, v in expr.iteritems():
            rv[k] = eval_expr(v, context)
        kwargs = rv.pop("__kwargs", None)
        if kwargs:
            rv.update(kwargs)
        return rv
    if isinstance(expr, Expression):
        return expr.eval(context)
    return expr
997056
def p_expr_BXOR_expr(p):
    
    p[0] = make_binary(p.lineno(2), 'BXOR', p[1], p[3], lambda x, y: x ^ y)
147612
def parse_substitution_from_list(list_rep):
    
    # We are expecting [pattern, replacement [, is_multiline]]
    if type(list_rep) is not list:
        raise SyntaxError('Substitution must be a list')
    if len(list_rep) < 2:
        raise SyntaxError('Substitution must be a list of size 2')

    pattern = list_rep[0]
    replacement = list_rep[1]

    # By default, substitutions are not multiline.
    is_multiline = False
    if (len(list_rep) > 2):
        is_multiline = list_rep[2]
        if type(is_multiline) is not bool:
            raise SyntaxError('is_multiline must be a boolean')

    result = substitute.Substitution(pattern, replacement, is_multiline)
    return result
783707
@SuppressWarnings("unchecked")
    public static <T> Expression<T> list(Class<T> clazz, List<? extends Expression<?>> exprs) {
        Expression<T> rv = (Expression<T>) exprs.get(0);
        if (exprs.size() == 1) {
            rv = operation(clazz, Ops.SINGLETON, rv, exprs.get(0));
        } else {
            for (int i = 1; i < exprs.size(); i++) {
                rv = operation(clazz, Ops.LIST, rv, exprs.get(i));
            }
        }

        return rv;
    }