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 : : * Implementation of bit-vectors proof checker. 11 : : */ 12 : : 13 : : #include "theory/bv/proof_checker.h" 14 : : 15 : : #include "theory/arith/arith_poly_norm.h" 16 : : #include "theory/bv/theory_bv_utils.h" 17 : : #include "util/bitvector.h" 18 : : 19 : : namespace cvc5::internal { 20 : : namespace theory { 21 : : namespace bv { 22 : : 23 : 91100 : BVProofRuleChecker::BVProofRuleChecker(NodeManager* nm) : ProofRuleChecker(nm) 24 : : { 25 : 91100 : } 26 : 19689 : void BVProofRuleChecker::registerTo(ProofChecker* pc) 27 : : { 28 : 19689 : pc->registerTrustedChecker(ProofRule::MACRO_BV_BITBLAST, this, 2); 29 : 19689 : pc->registerChecker(ProofRule::BV_BITBLAST_STEP, this); 30 : 19689 : pc->registerChecker(ProofRule::BV_POLY_NORM, this); 31 : 19689 : pc->registerChecker(ProofRule::BV_POLY_NORM_EQ, this); 32 : 19689 : pc->registerChecker(ProofRule::BV_EAGER_ATOM, this); 33 : 19689 : } 34 : : 35 : 20513 : Node BVProofRuleChecker::checkInternal(ProofRule id, 36 : : const std::vector<Node>& children, 37 : : const std::vector<Node>& args) 38 : : { 39 [ - + ]: 20513 : if (id == ProofRule::MACRO_BV_BITBLAST) 40 : : { 41 : 0 : Assert(children.empty()); 42 : 0 : Assert(args.size() == 1); 43 : 0 : Assert(args[0].getKind() == Kind::EQUAL); 44 : 0 : return args[0]; 45 : : } 46 [ + + ]: 20513 : else if (id == ProofRule::BV_BITBLAST_STEP) 47 : : { 48 [ - + ][ - + ]: 14856 : Assert(children.empty()); [ - - ] 49 [ - + ][ - + ]: 14856 : Assert(args.size() == 1); [ - - ] 50 [ - + ][ - + ]: 14856 : Assert(args[0].getKind() == Kind::EQUAL); [ - - ] 51 : 14856 : return args[0]; 52 : : } 53 [ + + ]: 5657 : else if (id == ProofRule::BV_EAGER_ATOM) 54 : : { 55 [ - + ][ - + ]: 274 : Assert(children.empty()); [ - - ] 56 [ - + ][ - + ]: 274 : Assert(args.size() == 1); [ - - ] 57 [ - + ][ - + ]: 274 : Assert(args[0].getKind() == Kind::BITVECTOR_EAGER_ATOM); [ - - ] 58 : 274 : return args[0].eqNode(args[0][0]); 59 : : } 60 [ + + ]: 5383 : else if (id == ProofRule::BV_POLY_NORM) 61 : : { 62 [ - + ][ - + ]: 2856 : Assert(children.empty()); [ - - ] 63 [ - + ][ - + ]: 2856 : Assert(args.size() == 1); [ - - ] 64 : 2856 : if (args[0].getKind() != Kind::EQUAL || !args[0][0].getType().isBitVector()) 65 : : { 66 : 0 : return Node::null(); 67 : : } 68 [ - + ]: 2856 : if (!arith::PolyNorm::isArithPolyNorm(args[0][0], args[0][1])) 69 : : { 70 : 0 : return Node::null(); 71 : : } 72 : 2856 : return args[0]; 73 : : } 74 [ + - ]: 2527 : else if (id == ProofRule::BV_POLY_NORM_EQ) 75 : : { 76 [ - + ][ - + ]: 2527 : Assert(children.size() == 1); [ - - ] 77 [ - + ][ - + ]: 2527 : Assert(args.size() == 1); [ - - ] 78 [ - + ]: 2527 : if (args[0].getKind() != Kind::EQUAL) 79 : : { 80 : 0 : return Node::null(); 81 : : } 82 : 2527 : Kind k = args[0][0].getKind(); 83 [ - + ]: 2527 : if (k != Kind::EQUAL) 84 : : { 85 : 0 : return Node::null(); 86 : : } 87 [ - + ]: 2527 : if (children[0].getKind() != Kind::EQUAL) 88 : : { 89 : 0 : return Node::null(); 90 : : } 91 : 2527 : Node l = children[0][0]; 92 : 2527 : Node r = children[0][1]; 93 [ + - ][ - + ]: 2527 : if (l.getKind() != Kind::BITVECTOR_MULT || r.getKind() != Kind::BITVECTOR_MULT) [ - + ] 94 : : { 95 : 0 : return Node::null(); 96 : : } 97 : 2527 : Node cx = l[0]; 98 : 2527 : Node lr = l[1]; 99 : 2527 : Node cy = r[0]; 100 : 2527 : Node rr = r[1]; 101 : 2527 : if (lr.getKind() != Kind::BITVECTOR_SUB 102 [ + - ][ - + ]: 2527 : || rr.getKind() != Kind::BITVECTOR_SUB) [ - + ] 103 : : { 104 : 0 : return Node::null(); 105 : : } 106 : 2527 : if (cx.getKind() == Kind::CONST_BITVECTOR 107 [ + - ][ + - ]: 2527 : && cy.getKind() == Kind::CONST_BITVECTOR) [ + - ] 108 : : { 109 : : // must be odd 110 : 2527 : if (!bv::utils::getBit(cx, 0) || !bv::utils::getBit(cy, 0)) 111 : : { 112 : 0 : return Node::null(); 113 : : } 114 : : } 115 : : else 116 : : { 117 : 0 : return Node::null(); 118 : : } 119 : 2527 : Node x1 = lr[0]; 120 : 2527 : Node x2 = lr[1]; 121 : 2527 : Node y1 = rr[0]; 122 : 2527 : Node y2 = rr[1]; 123 : 2527 : NodeManager* nm = nodeManager(); 124 : 5054 : Node ret = nm->mkNode(k, x1, x2).eqNode(nm->mkNode(k, y1, y2)); 125 [ - + ]: 2527 : if (ret != args[0]) 126 : : { 127 : 0 : return Node::null(); 128 : : } 129 : 2527 : return ret; 130 : 2527 : } 131 : : // no rule 132 : 0 : return Node::null(); 133 : : } 134 : : 135 : : } // namespace bv 136 : : } // namespace theory 137 : : } // namespace cvc5::internal