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 : : * Finite fields theory. 14 : : * 15 : : * There is a subtheory for each prime p that handles the field Fp. Essentially 16 : : * the common theory just multiplexes the sub-theories. 17 : : * 18 : : * NB: while most of FF does not build without CoCoA, this class does. So, it 19 : : * has many ifdef blocks that throw errors without CoCoA. 20 : : */ 21 : : 22 : : #include "cvc5_private.h" 23 : : 24 : : #ifndef CVC5__THEORY__FF__THEORY_FF_H 25 : : #define CVC5__THEORY__FF__THEORY_FF_H 26 : : 27 : : #include <memory> 28 : : 29 : : #include "smt/logic_exception.h" 30 : : #include "theory/care_pair_argument_callback.h" 31 : : #include "theory/ff/stats.h" 32 : : #include "theory/ff/sub_theory.h" 33 : : #include "theory/ff/theory_ff_rewriter.h" 34 : : #include "theory/theory.h" 35 : : #include "theory/theory_eq_notify.h" 36 : : #include "theory/theory_inference_manager.h" 37 : : #include "theory/theory_state.h" 38 : : 39 : : namespace cvc5::internal { 40 : : namespace theory { 41 : : namespace ff { 42 : : 43 : : class TheoryFiniteFields : public Theory 44 : : { 45 : : public: 46 : : /** Constructs a new instance of TheoryFiniteFields */ 47 : : TheoryFiniteFields(Env& env, OutputChannel& out, Valuation valuation); 48 : : ~TheoryFiniteFields() override; 49 : : 50 : : //--------------------------------- initialization 51 : : /** get the official theory rewriter of this theory */ 52 : : TheoryRewriter* getTheoryRewriter() override; 53 : : /** get the proof checker of this theory */ 54 : : ProofRuleChecker* getProofChecker() override; 55 : : /** 56 : : * Returns true if we need an equality engine. If so, we initialize the 57 : : * information regarding how it should be setup. For details, see the 58 : : * documentation in Theory::needsEqualityEngine. 59 : : */ 60 : : bool needsEqualityEngine(EeSetupInfo& esi) override; 61 : : /** finish initialization */ 62 : : void finishInit() override; 63 : : //--------------------------------- end initialization 64 : : 65 : : //--------------------------------- standard check 66 : : /** Post-check, called after the fact queue of the theory is processed. */ 67 : : void postCheck(Effort level) override; 68 : : /** The subtheory saves this for later (postCheck) */ 69 : : void notifyFact(TNode atom, bool pol, TNode fact, bool isInternal) override; 70 : : //--------------------------------- end standard check 71 : : /** Lift the common polynomial root to a model */ 72 : : bool collectModelValues(TheoryModel* m, 73 : : const std::set<Node>& termSet) override; 74 : 0 : std::string identify() const override { return "THEORY_FF"; } 75 : : /** preRegister this term or equality with the eq engine */ 76 : : void preRegisterWithEe(TNode node); 77 : : /** 78 : : * Trigers the creation of new-subtheories, and used to track the variables of 79 : : * the polynomial ring that we will build. 80 : : * 81 : : * 1. Registers term with the equality engine 82 : : * 2. Creates a new sub-theory for this term’s sort (if needed) 83 : : * 3. Gives this term to that sub-theory 84 : : * * Maintains a list of all theory leaves (for the variable set X) 85 : : */ 86 : : void preRegisterTerm(TNode node) override; 87 : : TrustNode explain(TNode n) override; 88 : : 89 : : private: 90 : : TheoryFiniteFieldsRewriter d_rewriter; 91 : : 92 : : /** The state of the ff solver at full effort */ 93 : : TheoryState d_state; 94 : : 95 : : /** The inference manager */ 96 : : TheoryInferenceManager d_im; 97 : : 98 : : /** Manages notifications from our equality engine */ 99 : : TheoryEqNotifyClass d_eqNotify; 100 : : 101 : : #ifdef CVC5_USE_COCOA 102 : : /** 103 : : * Map from field types to sub-theories. 104 : : */ 105 : : std::unordered_map<TypeNode, SubTheory> d_subTheories; 106 : : #endif /* CVC5_USE_COCOA */ 107 : : 108 : : std::unique_ptr<FfStatistics> d_stats; 109 : : }; /* class TheoryFiniteFields */ 110 : : 111 : : } // namespace ff 112 : : } // namespace theory 113 : : } // namespace cvc5::internal 114 : : 115 : : #endif /* CVC5__THEORY__FF__THEORY_FF_H */