Expression equality operator

    If *simplify* is ``True``, return a simplified expression.
777593
def Equal(*xs, simplify=True):
    
    xs = [Expression.box(x).node for x in xs]
    y = exprnode.eq(*xs)
    if simplify:
        y = y.simplify()
    return _expr(y)
380492
def solve_ifelse(expr, vars):
    """"""
    for condition, result in expr.conditions():
        if boolean.asbool(solve(condition, vars).value):
            return solve(result, vars)

    return solve(expr.default(), vars)
1164466
def ifelse(arg, true_expr, false_expr):
    
    # Result will be the result of promotion of true/false exprs. These
    # might be conflicting types; same type resolution as case expressions
    # must be used.
    case = ops.SearchedCaseBuilder()
    return case.when(arg, true_expr).else_(false_expr).end()
822642
def simplify_list(maybe_list):
    """"""
    if isinstance(maybe_list, MutableSequence):
        is_list = aslist(maybe_list)
        if len(is_list) == 1:
            return is_list[0]
    return maybe_list
669984
def simplify_scalar(self, func=sympy.simplify):
        """"""

        def element_simplify(v):
            if isinstance(v, sympy.Basic):
                return func(v)
            elif isinstance(v, QuantumExpression):
                return v.simplify_scalar(func=func)
            else:
                return v

        return self.element_wise(element_simplify)
120192
def Nor(*xs, simplify=True):
    
    xs = [Expression.box(x).node for x in xs]
    y = exprnode.not_(exprnode.or_(*xs))
    if simplify:
        y = y.simplify()
    return _expr(y)
958424
def compare_balance(self, operator, or_equals, amount):
        """"""
        amount = int(amount)
        if operator == 'less':
            if or_equals:
                self.assertLessEqual(self.balance, amount)
            else:
                self.assertLess(self.balance, amount)
        elif or_equals:
            self.assertGreaterEqual(self.balance, amount)
        else:
            self.assertGreater(self.balance, amount)
630855
def visitComparisonExpression(self, ctx):
        
        arg1, arg2 = conversions.to_same(self.visit(ctx.expression(0)), self.visit(ctx.expression(1)), self._eval_context)

        if isinstance(arg1, str):
            # string comparison is case-insensitive
            compared = (arg1.lower() > arg2.lower()) - (arg1.lower() < arg2.lower())
        else:
            compared = (arg1 > arg2) - (arg1 < arg2)

        if ctx.LTE() is not None:
            return compared <= 0
        elif ctx.LT() is not None:
            return compared < 0
        elif ctx.GTE() is not None:
            return compared >= 0
        else:  # GT
            return compared > 0
702041
def p_or_p_expression(tok):
        """"""
        if len(tok) == 4:
            tok[0] = LogicalBinOpRule(tok[2], tok[1], tok[3])
        else:
            tok[0] = tok[1]
39090
def simplify(self):
        """"""
        node = self.node.simplify()
        if node is self.node:
            return self
        else:
            return _expr(node)
20789
public Expr invertCondition(Expr expr, WyilFile.Expr elem) {
		if (expr instanceof Expr.Operator) {
			Expr.Operator binTest = (Expr.Operator) expr;
			switch (binTest.getOpcode()) {
			case WyalFile.EXPR_eq:
				return new Expr.NotEqual(binTest.getAll());
			case WyalFile.EXPR_neq:
				return new Expr.Equal(binTest.getAll());
			case WyalFile.EXPR_gteq:
				return new Expr.LessThan(binTest.getAll());
			case WyalFile.EXPR_gt:
				return new Expr.LessThanOrEqual(binTest.getAll());
			case WyalFile.EXPR_lteq:
				return new Expr.GreaterThan(binTest.getAll());
			case WyalFile.EXPR_lt:
				return new Expr.GreaterThanOrEqual(binTest.getAll());
			case WyalFile.EXPR_and: {
				Expr[] operands = invertConditions(binTest.getAll(), elem);
				return new Expr.LogicalOr(operands);
			}
			case WyalFile.EXPR_or: {
				Expr[] operands = invertConditions(binTest.getAll(), elem);
				return new Expr.LogicalAnd(operands);
			}
			}
		} else if (expr instanceof Expr.Is) {
			Expr.Is ei = (Expr.Is) expr;
			WyalFile.Type type = ei.getTestType();
			return new Expr.Is(ei.getTestExpr(), new WyalFile.Type.Negation(type));
		}
		// Otherwise, compare against false
		// FIXME: this is just wierd and needs to be fixed.
		return new Expr.LogicalNot(expr);
	}
842792
private static boolean expressionsEqual(ExpressionTree expr1, ExpressionTree expr2) {
    if (!expr1.getKind().equals(expr2.getKind())) {
      return false;
    }

    if (!expr1.getKind().equals(Kind.ARRAY_ACCESS)
        && !expr1.getKind().equals(Kind.IDENTIFIER)
        && !(expr1 instanceof LiteralTree)) {
      return false;
    }

    if (expr1.getKind() == Kind.ARRAY_ACCESS) {
      ArrayAccessTree arrayAccessTree1 = (ArrayAccessTree) expr1;
      ArrayAccessTree arrayAccessTree2 = (ArrayAccessTree) expr2;
      return expressionsEqual(arrayAccessTree1.getExpression(), arrayAccessTree2.getExpression())
          && expressionsEqual(arrayAccessTree1.getIndex(), arrayAccessTree2.getIndex());
    }

    if (expr1 instanceof LiteralTree) {
      LiteralTree literalTree1 = (LiteralTree) expr1;
      LiteralTree literalTree2 = (LiteralTree) expr2;
      return literalTree1.getValue().equals(literalTree2.getValue());
    }

    return Objects.equal(ASTHelpers.getSymbol(expr1), ASTHelpers.getSymbol(expr2));
  }
1179028
def expression(self):
        
        return operatorPrecedence(self.relation, [
            (self.unary_op, 1, opAssoc.RIGHT),
            (self.binary_op_p1, 2, opAssoc.LEFT),
            (self.binary_op_p2, 2, opAssoc.LEFT)])
255177
public static BooleanExpression any(BooleanExpression expr) {
        return Expressions.booleanOperation(Ops.AggOps.BOOLEAN_ANY, expr);
    }
724851
def simplify_expression(txt):
    """"""
    minimal = re.sub(r'\s', ' ',
                     re.sub(r'\s(?=\W)', '',
                            re.sub(r'(?<=\W)\s', '',
                                   txt.strip())))
    # add space before some "(" and after some ")"
    return re.sub(r'\)(?=\w)', ') ',
                  re.sub(r'(,|\b(?:{}))\('.format('|'.join(RESERVED_WORDS)), '\\1 (', minimal)
                  )
841636
def simx(A,B,transpose=False):
    ""
    if transpose:
        return np.dot(B,np.dot(A,B.T))
    return np.dot(B.T,np.dot(A,B))
872401
private static Selector simplifyEQ(Selector sel0, Selector sel1) {
    if (sel0.getType() != Selector.BOOLEAN)
      return new OperatorImpl(Selector.EQ, sel0, sel1);
    else
      return makeOR(makeAND(simplifyTree(sel0), simplifyTree(sel1)),
                    makeAND(simplifyNOT(sel0), simplifyNOT(sel1)));
  }