Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Alex Ozdemir 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 : : * utilities 14 : : */ 15 : : 16 : : #include "cvc5_private.h" 17 : : 18 : : #ifndef CVC5__THEORY__FF__UTIL_H 19 : : #define CVC5__THEORY__FF__UTIL_H 20 : : 21 : : // external includes 22 : : #ifdef CVC5_USE_COCOA 23 : : #include <CoCoA/ring.H> 24 : : #endif /* CVC5_USE_COCOA */ 25 : : 26 : : // std includes 27 : : #include <exception> 28 : : #include <unordered_map> 29 : : 30 : : // internal includes 31 : : #include "expr/node.h" 32 : : #include "util/finite_field_value.h" 33 : : 34 : : namespace cvc5::internal { 35 : : namespace theory { 36 : : namespace ff { 37 : : 38 : : /** A finite field model */ 39 : : using FfModel = std::unordered_map<Node, FiniteFieldValue>; 40 : : 41 : : /** 42 : : * A class associated with a specific field (for inheritting). 43 : : * 44 : : * A FieldObj is constructed from an FfSize, and provides various helper 45 : : * functions for the field of that size. 46 : : * */ 47 : : class FieldObj 48 : : { 49 : : public: 50 : : FieldObj(const FfSize& size); 51 : : /** create a sum (with as few as 0 elements); accepts Nodes or TNodes */ 52 : : template <bool ref_count> 53 : : Node mkAdd(const std::vector<NodeTemplate<ref_count>>& summands); 54 : : /** create a product (with as few as 0 elements); accepts Nodes or TNodes */ 55 : : template <bool ref_count> 56 : : Node mkMul(const std::vector<NodeTemplate<ref_count>>& summands); 57 : : /** the one constant in this field */ 58 : : const Node& one() const { return d_one; } 59 : : /** the zero constant in this field */ 60 : : const Node& zero() const { return d_zero; } 61 : : /** the size of this field */ 62 : 521660 : const FfSize& size() const { return d_size; } 63 : : #ifdef CVC5_USE_COCOA 64 : : /** the CoCoA ring of integers modulo this field's size */ 65 : 4455 : const CoCoA::ring& coeffRing() const { return d_coeffRing; } 66 : : #endif /* CVC5_USE_COCOA */ 67 : : 68 : : private: 69 : : FfSize d_size; 70 : : NodeManager* d_nm; 71 : : Node d_zero; 72 : : Node d_one; 73 : : #ifdef CVC5_USE_COCOA 74 : : CoCoA::ring d_coeffRing; 75 : : #endif /* CVC5_USE_COCOA */ 76 : : }; 77 : : 78 : : /** Testing whether something is related to (any) FF */ 79 : : 80 : : /** Is this a field term with non-field kind? */ 81 : : bool isFfLeaf(const Node& n); 82 : : /** Is this a field term? */ 83 : : bool isFfTerm(const Node& n); 84 : : /** Is this a field fact (equality of disequality)? */ 85 : : bool isFfFact(const Node& n); 86 : : 87 : : /** Used to signal check timeouts */ 88 : : class FfTimeoutException : public Exception 89 : : { 90 : : public: 91 : : FfTimeoutException(const std::string& where); 92 : : ~FfTimeoutException() override; 93 : : }; 94 : : /** Testing whether something is related to (this specific) FF */ 95 : : 96 : : /** Is this a (this) field term with non-field kind? */ 97 : : bool isFfLeaf(const Node& n, const FfSize& field); 98 : : /** Is this a (this) field term? */ 99 : : bool isFfTerm(const Node& n, const FfSize& field); 100 : : /** Is this a (this) field fact (equality of disequality)? */ 101 : : bool isFfFact(const Node& n, const FfSize& field); 102 : : 103 : : } // namespace ff 104 : : } // namespace theory 105 : : } // namespace cvc5::internal 106 : : 107 : : #endif /* CVC5__THEORY__FF__UTIL_H */