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