Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds, Morgan Deters, Aina Niemetz 4 : : * 5 : : * This file is part of the cvc5 project. 6 : : * 7 : : * Copyright (c) 2009-2024 by the authors listed in the file AUTHORS 8 : : * in the top-level source directory and their institutional affiliations. 9 : : * All rights reserved. See the file COPYING in the top-level source 10 : : * directory for licensing information. 11 : : * **************************************************************************** 12 : : * 13 : : * Simple, commonly-used routines for Boolean simplification. 14 : : */ 15 : : 16 : : #include "preprocessing/util/boolean_simplification.h" 17 : : 18 : : namespace cvc5::internal { 19 : : namespace preprocessing { 20 : : 21 : 154 : bool BooleanSimplification::push_back_associative_commute_recursive( 22 : : Node n, std::vector<Node>& buffer, Kind k, Kind notK, bool negateNode) 23 : : { 24 : 154 : Node::iterator i = n.begin(), end = n.end(); 25 [ + + ]: 473 : for (; i != end; ++i) 26 : : { 27 : 319 : Node child = *i; 28 [ + + ]: 319 : if (child.getKind() == k) 29 : : { 30 [ - + ]: 5 : if (!push_back_associative_commute_recursive( 31 : : child, buffer, k, notK, negateNode)) 32 : : { 33 : 0 : return false; 34 : : } 35 : : } 36 [ + + ][ + + ]: 314 : else if (child.getKind() == Kind::NOT && child[0].getKind() == notK) [ + + ][ + + ] [ - - ] 37 : : { 38 [ - + ]: 5 : if (!push_back_associative_commute_recursive( 39 : 5 : child[0], buffer, notK, k, !negateNode)) 40 : : { 41 : 0 : return false; 42 : : } 43 : : } 44 : : else 45 : : { 46 [ + + ]: 309 : if (negateNode) 47 : : { 48 [ - + ]: 10 : if (child.isConst()) 49 : : { 50 [ - - ]: 0 : if ((k == Kind::AND && child.getConst<bool>()) 51 : 0 : || (k == Kind::OR && !child.getConst<bool>())) 52 : : { 53 : 0 : buffer.clear(); 54 : 0 : buffer.push_back(negate(child)); 55 : 0 : return false; 56 : : } 57 : : } 58 : : else 59 : : { 60 : 10 : buffer.push_back(negate(child)); 61 : : } 62 : : } 63 : : else 64 : : { 65 [ - + ]: 299 : if (child.isConst()) 66 : : { 67 [ - - ]: 0 : if ((k == Kind::OR && child.getConst<bool>()) 68 : 0 : || (k == Kind::AND && !child.getConst<bool>())) 69 : : { 70 : 0 : buffer.clear(); 71 : 0 : buffer.push_back(child); 72 : 0 : return false; 73 : : } 74 : : } 75 : : else 76 : : { 77 : 299 : buffer.push_back(child); 78 : : } 79 : : } 80 : : } 81 : : } 82 : 154 : return true; 83 : : } /* BooleanSimplification::push_back_associative_commute_recursive() */ 84 : : 85 : : } // namespace preprocessing 86 : : } // namespace cvc5::internal