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 : : * utilities 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__FF__UTIL_H 16 : : #define CVC5__THEORY__FF__UTIL_H 17 : : 18 : : // std includes 19 : : #include <unordered_map> 20 : : #include <variant> 21 : : #include <vector> 22 : : 23 : : // internal includes 24 : : #include "expr/node.h" 25 : : #include "util/finite_field_value.h" 26 : : 27 : : namespace cvc5::internal { 28 : : namespace theory { 29 : : namespace ff { 30 : : 31 : : /** A finite field model */ 32 : : using FfModel = std::unordered_map<Node, FiniteFieldValue>; 33 : : /** A finite field conflict core */ 34 : : using FfCore = std::vector<Node>; 35 : : /** Indicates an unknown result in FfResult. */ 36 : : using FfUnknown = std::monostate; 37 : : /** The result of a subprocedure: either unknown, a model, or a conflict core */ 38 : : using FfResult = std::variant<FfUnknown, FfModel, FfCore>; 39 : : 40 : : /** 41 : : * A class associated with a specific field (for inheritting). 42 : : * 43 : : * A FieldObj is constructed from an FfSize, and provides various helper 44 : : * functions for the field of that size. 45 : : * */ 46 : : class FieldObj 47 : : { 48 : : public: 49 : : FieldObj(NodeManager* nm, FfSize size); 50 : : /** create a sum (with as few as 0 elements); accepts Nodes or TNodes */ 51 : : template <bool ref_count> 52 : : Node mkAdd(const std::vector<NodeTemplate<ref_count>>& summands); 53 : : /** create a product (with as few as 0 elements); accepts Nodes or TNodes */ 54 : : template <bool ref_count> 55 : : Node mkMul(const std::vector<NodeTemplate<ref_count>>& summands); 56 : : /** the one constant in this field */ 57 : : const Node& one() const { return d_one; } 58 : : /** the zero constant in this field */ 59 : : const Node& zero() const { return d_zero; } 60 : : /** the size of this field */ 61 : 462436 : const FfSize& size() const { return d_size; } 62 : : 63 : : private: 64 : : FfSize d_size; 65 : : NodeManager* d_nm; 66 : : Node d_zero; 67 : : Node d_one; 68 : : }; 69 : : 70 : : /** Testing whether something is related to (any) FF */ 71 : : 72 : : /** Is this a field term with non-field kind? */ 73 : : bool isFfLeaf(const Node& n); 74 : : /** Is this a field term? */ 75 : : bool isFfTerm(const Node& n); 76 : : /** Is this a field fact (equality of disequality)? */ 77 : : bool isFfFact(const Node& n); 78 : : 79 : : /** Used to signal check timeouts */ 80 : : class FfTimeoutException : public Exception 81 : : { 82 : : public: 83 : : explicit FfTimeoutException(const std::string& where); 84 : : ~FfTimeoutException() override; 85 : : }; 86 : : /** Testing whether something is related to (this specific) FF */ 87 : : 88 : : /** Is this a (this) field term with non-field kind? */ 89 : : bool isFfLeaf(const Node& n, const FfSize& field); 90 : : /** Is this a (this) field term? */ 91 : : bool isFfTerm(const Node& n, const FfSize& field); 92 : : /** Is this a (this) field fact (equality of disequality)? */ 93 : : bool isFfFact(const Node& n, const FfSize& field); 94 : : 95 : : } // namespace ff 96 : : } // namespace theory 97 : : } // namespace cvc5::internal 98 : : 99 : : #endif /* CVC5__THEORY__FF__UTIL_H */