Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds 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 : : * Implementation of module for processing the difficulty of input assumptions 14 : : * based on proof nodes. 15 : : */ 16 : : 17 : : #include "cvc5_private.h" 18 : : 19 : : #ifndef CVC5__SMT__DIFFICULTY_POST_PROCESSOR_H 20 : : #define CVC5__SMT__DIFFICULTY_POST_PROCESSOR_H 21 : : 22 : : #include <map> 23 : : 24 : : #include "proof/proof_node_updater.h" 25 : : 26 : : namespace cvc5::internal { 27 : : namespace smt { 28 : : 29 : : /** 30 : : * A postprocess callback that computes difficulty based on the structure 31 : : * of the proof. In particular, this class assesses what the source of an 32 : : * assertion was by considering the shape of the proof. For instance, if 33 : : * assertion A entails x=t, and this was used to derive a substitution 34 : : * { x -> t } to assertion B, then B is the source of B*{ x -> t }. The 35 : : * difficulty of this assertion is carried to B and not A. The reason is that 36 : : * A can be understood as a definition, and is eliminated, whereas B was 37 : : * persistent if B*{ x -> t } was a prepreprocessed assertion. 38 : : * 39 : : * Note that this postprocess callback is intended to be run on the proof 40 : : * of a single preprocessed assertion C. If C was derived by proof with 41 : : * free assumptions A_1, ..., A_n, then for each A_i that is a "source" as 42 : : * described above, we increment the difficulty of A_i by the difficulty value 43 : : * assigned to C. 44 : : * 45 : : * This means that the user of this method should: 46 : : * (1) assign the current difficulty we are incrementing (setCurrentDifficulty), 47 : : * (2) process the proof using a proof node updater with this callback. 48 : : * The final difficulty map is accumulated in d_accMap, which can be accessed 49 : : * at any time via getDifficultyMap. 50 : : */ 51 : : class DifficultyPostprocessCallback : public ProofNodeUpdaterCallback 52 : : { 53 : : public: 54 : : DifficultyPostprocessCallback(); 55 : 201 : ~DifficultyPostprocessCallback() {} 56 : : /** 57 : : * Set current difficulty of the next proof to process to the (integer) 58 : : * value stored in Node d. This value will be assigned to all the free 59 : : * assumptions of the proof we traverse next. This value is stored in 60 : : * d_currDifficulty. 61 : : * 62 : : * @return true if the difficulty value was successfully extracted 63 : : */ 64 : : bool setCurrentDifficulty(Node d); 65 : : /** 66 : : * Should proof pn be updated? This is used to selectively traverse to e.g. 67 : : * the source of an assertion. 68 : : */ 69 : : bool shouldUpdate(std::shared_ptr<ProofNode> pn, 70 : : const std::vector<Node>& fa, 71 : : bool& continueUpdate) override; 72 : : /** Get the (acculumated) difficulty map for the last processed proof node */ 73 : : void getDifficultyMap(std::map<Node, Node>& dmap) const; 74 : : 75 : : private: 76 : : /** 77 : : * The current difficulty of the assertion whose proof of preprocessing 78 : : * we are considering. 79 : : */ 80 : : uint64_t d_currDifficulty; 81 : : /** The current accumulated difficulty map */ 82 : : std::map<Node, uint64_t> d_accMap; 83 : : }; 84 : : 85 : : } // namespace smt 86 : : } // namespace cvc5::internal 87 : : 88 : : #endif