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 : : * Inference information utility. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__STRINGS__INFER_INFO_H 16 : : #define CVC5__THEORY__STRINGS__INFER_INFO_H 17 : : 18 : : #include <map> 19 : : #include <vector> 20 : : 21 : : #include "expr/node.h" 22 : : #include "theory/inference_id.h" 23 : : #include "theory/theory_inference.h" 24 : : #include "util/safe_print.h" 25 : : 26 : : namespace cvc5::internal { 27 : : namespace theory { 28 : : namespace strings { 29 : : 30 : : /** 31 : : * Length status, used for indicating the length constraints for Skolems 32 : : * introduced by the theory of strings. 33 : : */ 34 : : enum LengthStatus 35 : : { 36 : : // The length of the Skolem should not be constrained. This should be 37 : : // used for Skolems whose length is already implied. 38 : : LENGTH_IGNORE, 39 : : // The length of the Skolem is not specified, and should be split on. 40 : : LENGTH_SPLIT, 41 : : // The length of the Skolem is exactly one. 42 : : LENGTH_ONE, 43 : : // The length of the Skolem is greater than or equal to one. 44 : : LENGTH_GEQ_ONE 45 : : }; 46 : : 47 : : class InferInfo; 48 : : 49 : : class InferSideEffectProcess 50 : : { 51 : : public: 52 : 153144 : InferSideEffectProcess() {} 53 : 152109 : virtual ~InferSideEffectProcess() {} 54 : : /** Process lemma */ 55 : : virtual TrustNode processLemma(InferInfo& ii, LemmaProperty& p) = 0; 56 : : /** Called when ii is ready to be processed as a fact */ 57 : : virtual void processFact(InferInfo& ii, ProofGenerator*& pg) = 0; 58 : : }; 59 : : 60 : : /** 61 : : * An inference. This is a class to track an unprocessed call to either 62 : : * send a fact, lemma, or conflict that is waiting to be asserted to the 63 : : * equality engine or sent on the output channel. 64 : : * 65 : : * For the sake of proofs, the premises in InferInfo have a particular 66 : : * ordering for many of the core strings rules, which is expected by 67 : : * InferProofCons for constructing proofs of F_CONST, F_UNIFY, N_CONST, etc. 68 : : * which apply to a pair of string terms t and s. At a high level, the ordering 69 : : * expected in d_ant is: 70 : : * (1) (multiple) literals that explain why t and s have the same prefix/suffix, 71 : : * (2) t = s, 72 : : * (3) (optionally) a length constraint. 73 : : * For example, say we have: 74 : : * { x ++ y ++ v1 = z ++ w ++ v2, x = z ++ u, u = "", len(y) = len(w) } 75 : : * We can conclude y = w by the N_UNIFY rule from the left side. The premise 76 : : * has the following form: 77 : : * - (prefix up to y/w equal) x = z ++ u, u = "", 78 : : * - (main equality) x ++ y ++ v1 = z ++ w ++ v2, 79 : : * - (length constraint) len(y) = len(w). 80 : : */ 81 : : class InferInfo : public TheoryInference 82 : : { 83 : : public: 84 : : InferInfo(InferenceId id); 85 [ + - ][ + + ]: 1530838 : ~InferInfo() {} 86 : : /** Process lemma */ 87 : : TrustNode processLemma(LemmaProperty& p) override; 88 : : /** Process internal fact */ 89 : : Node processFact(std::vector<Node>& exp, ProofGenerator*& pg) override; 90 : : /** Pointer to the class used for processing this info */ 91 : : InferSideEffectProcess* d_sim; 92 : : /** Whether it is the reverse form of the above id */ 93 : : bool d_idRev; 94 : : /** The conclusion */ 95 : : Node d_conc; 96 : : /** 97 : : * The premise(s) of the inference, interpreted conjunctively. These are 98 : : * literals that currently hold in the equality engine. 99 : : */ 100 : : std::vector<Node> d_premises; 101 : : /** 102 : : * The "new literal" premise(s) of the inference, interpreted 103 : : * conjunctively. These are literals that were needed to show the conclusion 104 : : * but do not currently hold in the equality engine. These should be a subset 105 : : * of d_ant. In other words, premises that are not explained are stored 106 : : * in *both* d_ant and d_noExplain. 107 : : */ 108 : : std::vector<Node> d_noExplain; 109 : : /** 110 : : * A list of new skolems introduced as a result of this inference. They 111 : : * are mapped to by a length status, indicating the length constraint that 112 : : * can be assumed for them. 113 : : */ 114 : : std::map<LengthStatus, std::vector<Node> > d_skolems; 115 : : /** 116 : : * The pending phase requirements, see InferenceManager::sendPhaseRequirement. 117 : : */ 118 : : std::map<Node, bool> d_pendingPhase; 119 : : /** 120 : : * The normal form pair that is cached as a result of this inference. 121 : : */ 122 : : Node d_nfPair[2]; 123 : : /** Is this infer info trivial? True if d_conc is true. */ 124 : : bool isTrivial() const; 125 : : /** 126 : : * Does this infer info correspond to a conflict? True if d_conc is false 127 : : * and it has no new premises (d_noExplain). 128 : : */ 129 : : bool isConflict() const; 130 : : /** 131 : : * Does this infer info correspond to a "fact". A fact is an inference whose 132 : : * conclusion should be added as an equality or predicate to the equality 133 : : * engine with no new external premises (d_noExplain). 134 : : */ 135 : : bool isFact() const; 136 : : /** Get premises */ 137 : : Node getPremises(NodeManager* nm) const; 138 : : }; 139 : : 140 : : /** 141 : : * Writes an inference info to a stream. 142 : : * 143 : : * @param out The stream to write to 144 : : * @param ii The inference info to write to the stream 145 : : * @return The stream 146 : : */ 147 : : std::ostream& operator<<(std::ostream& out, const InferInfo& ii); 148 : : 149 : : } // namespace strings 150 : : } // namespace theory 151 : : } // namespace cvc5::internal 152 : : 153 : : #endif /* CVC5__THEORY__STRINGS__INFER_INFO_H */