LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/smt - preprocess_proof_generator.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2025-03-22 11:41:52 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Andrew Reynolds, Gereon Kremer, Aina Niemetz
       4                 :            :  *
       5                 :            :  * This file is part of the cvc5 project.
       6                 :            :  *
       7                 :            :  * Copyright (c) 2009-2025 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                 :            :  * The module for proofs for preprocessing in an SMT engine.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "cvc5_private.h"
      17                 :            : 
      18                 :            : #ifndef CVC5__SMT__PREPROCESS_PROOF_GENERATOR_H
      19                 :            : #define CVC5__SMT__PREPROCESS_PROOF_GENERATOR_H
      20                 :            : 
      21                 :            : #include "context/cdhashmap.h"
      22                 :            : #include "proof/lazy_proof.h"
      23                 :            : #include "proof/proof.h"
      24                 :            : #include "proof/proof_generator.h"
      25                 :            : #include "proof/proof_set.h"
      26                 :            : #include "proof/trust_id.h"
      27                 :            : #include "proof/trust_node.h"
      28                 :            : #include "smt/env_obj.h"
      29                 :            : 
      30                 :            : namespace cvc5::internal {
      31                 :            : 
      32                 :            : class LazyCDProof;
      33                 :            : class ProofNodeManager;
      34                 :            : 
      35                 :            : namespace smt {
      36                 :            : 
      37                 :            : /**
      38                 :            :  * This is a proof generator that manages proofs for a set of formulas that
      39                 :            :  * may be replaced over time. This set of formulas is implicit; formulas that
      40                 :            :  * are not notified as assertions to this class are treated as assumptions.
      41                 :            :  *
      42                 :            :  * The main use case of this proof generator is for proofs of preprocessing,
      43                 :            :  * although it can be used in other scenarios where proofs for an evolving set
      44                 :            :  * of formulas is maintained. In the remainder of the description here, we
      45                 :            :  * describe its role as a proof generator for proofs of preprocessing.
      46                 :            :  *
      47                 :            :  * This class has two main interfaces during solving:
      48                 :            :  * (1) notifyNewAssert, for assertions that are not part of the input and are
      49                 :            :  * added to the assertion pipeline by preprocessing passes,
      50                 :            :  * (2) notifyPreprocessed, which is called when a preprocessing pass rewrites
      51                 :            :  * an assertion into another.
      52                 :            :  * Notice that input assertions do not need to be provided to this class.
      53                 :            :  *
      54                 :            :  * Its getProofFor method produces a proof for a preprocessed assertion
      55                 :            :  * whose free assumptions are intended to be input assertions, which are
      56                 :            :  * implictly all assertions that are not notified to this class.
      57                 :            :  */
      58                 :            : class PreprocessProofGenerator : protected EnvObj, public ProofGenerator
      59                 :            : {
      60                 :            :   typedef context::CDHashMap<Node, TrustNode> NodeTrustNodeMap;
      61                 :            : 
      62                 :            :  public:
      63                 :            :   /**
      64                 :            :    * @param env Reference to the environment
      65                 :            :    * @param c The context this class depends on
      66                 :            :    * @param name The name of this generator (for debugging)
      67                 :            :    */
      68                 :            :   PreprocessProofGenerator(Env& env,
      69                 :            :                            context::Context* c = nullptr,
      70                 :            :                            std::string name = "PreprocessProofGenerator");
      71                 :      82124 :   ~PreprocessProofGenerator() {}
      72                 :            :   /**
      73                 :            :    * Notify that n is an input (its proof is ASSUME).
      74                 :            :    */
      75                 :            :   void notifyInput(Node n);
      76                 :            :   /**
      77                 :            :    * Notify that n is a new assertion, where pg can provide a proof of n.
      78                 :            :    *
      79                 :            :    * @param n The formula to assert.
      80                 :            :    * @param pg The proof generator that may provide a proof of n.
      81                 :            :    * @param id The trust id to use, if pg is nullptr.
      82                 :            :    */
      83                 :            :   void notifyNewAssert(Node n,
      84                 :            :                        ProofGenerator* pg,
      85                 :            :                        TrustId id = TrustId::UNKNOWN_PREPROCESS_LEMMA);
      86                 :            :   /**
      87                 :            :    * Notify a new assertion, trust node version.
      88                 :            :    *
      89                 :            :    * @param tn The trust node
      90                 :            :    * @param id The trust id to use, if the generator of the trust node is null.
      91                 :            :    */
      92                 :            :   void notifyNewTrustedAssert(TrustNode tn,
      93                 :            :                               TrustId id = TrustId::UNKNOWN_PREPROCESS_LEMMA);
      94                 :            :   /**
      95                 :            :    * Notify that n was replaced by np due to preprocessing, where pg can
      96                 :            :    * provide a proof of the equality n=np.
      97                 :            :    * @param n The original formula.
      98                 :            :    * @param np The preprocessed formula.
      99                 :            :    * @param pg The proof generator that may provide a proof of (= n np).
     100                 :            :    * @param id The trust id to use, if the proof generator is null.
     101                 :            :    */
     102                 :            :   void notifyPreprocessed(Node n,
     103                 :            :                           Node np,
     104                 :            :                           ProofGenerator* pg,
     105                 :            :                           TrustId id = TrustId::UNKNOWN_PREPROCESS);
     106                 :            :   /** Notify preprocessed, trust node version */
     107                 :            :   void notifyTrustedPreprocessed(TrustNode tnp,
     108                 :            :                                  TrustId id = TrustId::UNKNOWN_PREPROCESS);
     109                 :            :   /**
     110                 :            :    * Get proof for f, which returns a proof based on proving an equality based
     111                 :            :    * on transitivity of preprocessing steps, and then using the original
     112                 :            :    * assertion with EQ_RESOLVE to obtain the proof of the ending assertion f.
     113                 :            :    */
     114                 :            :   std::shared_ptr<ProofNode> getProofFor(Node f) override;
     115                 :            :   /** Identify */
     116                 :            :   std::string identify() const override;
     117                 :            :   /**
     118                 :            :    * Allocate a helper proof. This returns a fresh lazy proof object that
     119                 :            :    * remains alive in the context. This feature is used to construct
     120                 :            :    * helper proofs for preprocessing, e.g. to support the skeleton of proofs
     121                 :            :    * that connect AssertionPipeline::conjoin steps.
     122                 :            :    */
     123                 :            :   LazyCDProof* allocateHelperProof();
     124                 :            : 
     125                 :            :  private:
     126                 :            :   /**
     127                 :            :    * Possibly check pedantic failure for null proof generator provided
     128                 :            :    * to this class.
     129                 :            :    */
     130                 :            :   void checkEagerPedantic(TrustId r);
     131                 :            :   /** A dummy context used by this class if none is provided */
     132                 :            :   context::Context d_context;
     133                 :            :   /** The context used here */
     134                 :            :   context::Context* d_ctx;
     135                 :            :   /**
     136                 :            :    * The trust node that was the source of each node constructed during
     137                 :            :    * preprocessing. For each n, d_src[n] is a trust node whose node is n. This
     138                 :            :    * can either be:
     139                 :            :    * (1) A trust node REWRITE proving (n_src = n) for some n_src, or
     140                 :            :    * (2) A trust node LEMMA proving n.
     141                 :            :    */
     142                 :            :   NodeTrustNodeMap d_src;
     143                 :            :   /** A context-dependent list of LazyCDProof, allocated for conjoin steps */
     144                 :            :   CDProofSet<LazyCDProof> d_helperProofs;
     145                 :            :   /**
     146                 :            :    * A cd proof for input assertions, this is an empty proof that intentionally
     147                 :            :    * returns (ASSUME f) for all f.
     148                 :            :    */
     149                 :            :   CDProof d_inputPf;
     150                 :            :   /**
     151                 :            :    * A cd proof used for when preprocessing steps are not given justification.
     152                 :            :    * Stores only trust steps.
     153                 :            :    */
     154                 :            :   CDProof d_trustPf;
     155                 :            :   /** Name for debugging */
     156                 :            :   std::string d_name;
     157                 :            : };
     158                 :            : 
     159                 :            : }  // namespace smt
     160                 :            : }  // namespace cvc5::internal
     161                 :            : 
     162                 :            : #endif

Generated by: LCOV version 1.14