Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Arithmetic evaluator. 11 : : */ 12 : : #include "theory/arith/arith_evaluator.h" 13 : : 14 : : #include "theory/arith/nl/poly_conversion.h" 15 : : #include "theory/rewriter.h" 16 : : #include "theory/theory.h" 17 : : #include "util/real_algebraic_number.h" 18 : : 19 : : namespace cvc5::internal { 20 : : namespace theory { 21 : : namespace arith { 22 : : 23 : 1627862 : std::optional<bool> isExpressionZero(Env& env, 24 : : Node expr, 25 : : const ArithSubs& subs, 26 : : bool traverseNlMult) 27 : : { 28 : : // Substitute constants and rewrite 29 : 1627862 : expr = env.getRewriter()->rewrite(expr); 30 [ + + ]: 1627862 : if (expr.isConst()) 31 : : { 32 : 628785 : return expr.getConst<Rational>().isZero(); 33 : : } 34 : : // we use an arithmetic substitution, which does not traverse into 35 : : // terms that do not belong to the core theory of arithmetic. 36 : 999077 : expr = subs.applyArith(expr, traverseNlMult); 37 : 999077 : expr = env.getRewriter()->rewrite(expr); 38 [ + + ]: 999077 : if (expr.isConst()) 39 : : { 40 : 997485 : return expr.getConst<Rational>().isZero(); 41 : : } 42 [ + + ]: 1592 : if (expr.getKind() == Kind::REAL_ALGEBRAIC_NUMBER) 43 : : { 44 : 4 : return expr.getOperator().getConst<RealAlgebraicNumber>().isZero(); 45 : : } 46 : 1588 : return std::nullopt; 47 : : } 48 : : 49 : : } // namespace arith 50 : : } // namespace theory 51 : : } // namespace cvc5::internal