fn greater_than()

in checker/src/abstract_value.rs [2926:3011]


    fn greater_than(&self, other: Rc<AbstractValue>) -> Rc<AbstractValue> {
        // [x > c] -> c < x
        if !self.is_compile_time_constant() && other.is_compile_time_constant() {
            // Normalize binary expressions so that if only one of the operands is a constant, it is
            // always the left operand.
            return other.less_than(self.clone());
        }
        if let Some(result) = self
            .get_cached_interval()
            .greater_than(other.get_cached_interval().as_ref())
        {
            return Rc::new(result.into());
        }
        // [0 > x] -> false if x is unsigned
        if self.is_zero() && other.expression.infer_type().is_unsigned_integer() {
            return Rc::new(FALSE);
        }
        match (&self.expression, &other.expression) {
            // [(c ? v1 : v2) > c3] -> c ? (v1 > c3) : (v2 > c3)
            (
                Expression::ConditionalExpression {
                    condition: c,
                    consequent: v1,
                    alternate: v2,
                    ..
                },
                Expression::CompileTimeConstant(..),
            ) if !v1.is_top() && !v2.is_top() => {
                return c.conditional_expression(
                    v1.greater_than(other.clone()),
                    v2.greater_than(other.clone()),
                );
            }
            // [c3 > (c ? v1 : v2)] -> c ? (c3 > v1) : (c3 > v2 )
            (
                Expression::CompileTimeConstant(..),
                Expression::ConditionalExpression {
                    condition: c,
                    consequent: v1,
                    alternate: v2,
                    ..
                },
            ) if !v1.is_top() && !v2.is_top() => {
                return c.conditional_expression(
                    self.greater_than(v1.clone()),
                    self.greater_than(v2.clone()),
                );
            }
            // [(c1 * x) > c2] -> x > c2 / c1
            (Expression::Mul { left: c1, right: x }, _)
                if c1.is_compile_time_constant()
                    && other.is_compile_time_constant()
                    && other.expression.infer_type().is_integer() =>
            {
                //todo: debug_checked_assume!(!c1.is_zero()); // otherwise constant folding would have reduced the Mul
                return x.greater_than(c1.divide(other.clone()));
            }
            // [c1 > (c2 * x)] -> x <= c1 / c2
            (_, Expression::Mul { left: c2, right: x })
                if self.is_compile_time_constant()
                    && c2.is_compile_time_constant()
                    && self.expression.infer_type().is_integer() =>
            {
                debug_checked_assume!(!c2.is_zero()); // otherwise constant folding would have reduced the Mul
                return x.less_or_equal(self.divide(c2.clone()));
            }
            // [x > x] -> false
            _ => {
                if self.eq(&other) {
                    return Rc::new(FALSE);
                }
            }
        }

        self.try_to_constant_fold_and_distribute_binary_op(
            other,
            ConstantDomain::greater_than,
            Self::greater_than,
            |l, r| {
                AbstractValue::make_binary(l, r, |left, right| Expression::GreaterThan {
                    left,
                    right,
                })
            },
        )
    }