LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/proof - trust_node.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2026-07-19 10:35:57 Functions: 2 2 100.0 %
Branches: 0 0 -

           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                 :            :  * The trust node utility.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "cvc5_private.h"
      14                 :            : 
      15                 :            : #ifndef CVC5__PROOF__TRUST_NODE_H
      16                 :            : #define CVC5__PROOF__TRUST_NODE_H
      17                 :            : 
      18                 :            : #include "expr/node.h"
      19                 :            : 
      20                 :            : namespace cvc5::internal {
      21                 :            : 
      22                 :            : class Options;
      23                 :            : class ProofGenerator;
      24                 :            : class ProofNode;
      25                 :            : 
      26                 :            : /** A kind for trust nodes */
      27                 :            : enum class TrustNodeKind : uint32_t
      28                 :            : {
      29                 :            :   CONFLICT,
      30                 :            :   LEMMA,
      31                 :            :   PROP_EXP,
      32                 :            :   REWRITE,
      33                 :            :   INVALID
      34                 :            : };
      35                 :            : /**
      36                 :            :  * Converts a proof rule to a string. Note: This function is also used in
      37                 :            :  * `safe_print()`. Changing this function name or signature will result in
      38                 :            :  * `safe_print()` printing "<unsupported>" instead of the proper strings for
      39                 :            :  * the enum values.
      40                 :            :  *
      41                 :            :  * Returns a string with static lifetime: it should not be freed.
      42                 :            :  *
      43                 :            :  * @param tnk The trust node kind
      44                 :            :  * @return The name of the trust node kind
      45                 :            :  */
      46                 :            : const char* toString(TrustNodeKind tnk);
      47                 :            : 
      48                 :            : /**
      49                 :            :  * Writes a trust node kind name to a stream.
      50                 :            :  *
      51                 :            :  * @param out The stream to write to
      52                 :            :  * @param tnk The trust node kind to write to the stream
      53                 :            :  * @return The stream
      54                 :            :  */
      55                 :            : std::ostream& operator<<(std::ostream& out, TrustNodeKind tnk);
      56                 :            : 
      57                 :            : /**
      58                 :            :  * A trust node is a pair (F, G) where F is a formula and G is a proof
      59                 :            :  * generator that can construct a proof for F if asked.
      60                 :            :  *
      61                 :            :  * More generally, a trust node is any node that can be used for a specific
      62                 :            :  * purpose that requires justification, such as being passed to
      63                 :            :  * OutputChannel::lemma. That justification is intended to be given by the
      64                 :            :  * generator that is required to construct this object.
      65                 :            :  *
      66                 :            :  * They are intended to be constructed by ProofGenerator objects themselves (a
      67                 :            :  * proof generator wraps itself in TrustNode it returns) and passed
      68                 :            :  * to ProofOutputChannel by theory solvers.
      69                 :            :  *
      70                 :            :  * The static functions for constructing them check that the generator, if
      71                 :            :  * provided, is capable of proving the given conflict or lemma, or an assertion
      72                 :            :  * failure occurs. Otherwise an assertion error is given.
      73                 :            :  *
      74                 :            :  * While this is not enforced, a `TrustNode` generally encapsulates a **closed**
      75                 :            :  * proof of the formula: one without free assumptions.
      76                 :            :  */
      77                 :            : class TrustNode
      78                 :            : {
      79                 :            :  public:
      80                 :   13129204 :   TrustNode() : d_tnk(TrustNodeKind::INVALID), d_gen(nullptr) {}
      81                 :            :   /** Make a proven node for conflict */
      82                 :            :   static TrustNode mkTrustConflict(Node conf, ProofGenerator* g = nullptr);
      83                 :            :   /** Make a proven node for lemma */
      84                 :            :   static TrustNode mkTrustLemma(Node lem, ProofGenerator* g = nullptr);
      85                 :            :   /** Make a proven node for explanation of propagated literal */
      86                 :            :   static TrustNode mkTrustPropExp(TNode lit,
      87                 :            :                                   Node exp,
      88                 :            :                                   ProofGenerator* g = nullptr);
      89                 :            :   /** Make a proven node for rewrite */
      90                 :            :   static TrustNode mkTrustRewrite(TNode n,
      91                 :            :                                   Node nr,
      92                 :            :                                   ProofGenerator* g = nullptr);
      93                 :            :   /** Make a trust node, replacing the original generator */
      94                 :            :   static TrustNode mkReplaceGenTrustNode(const TrustNode& orig,
      95                 :            :                                          ProofGenerator* g);
      96                 :            :   /** Make a trust node with the given explicit arguments. */
      97                 :            :   static TrustNode mkTrustNode(TrustNodeKind tnk,
      98                 :            :                                Node p,
      99                 :            :                                ProofGenerator* g = nullptr);
     100                 :            :   /** The null proven node */
     101                 :            :   static TrustNode null();
     102                 :   66230040 :   ~TrustNode() {}
     103                 :            :   /** get kind */
     104                 :            :   TrustNodeKind getKind() const;
     105                 :            :   /** get node
     106                 :            :    *
     107                 :            :    * This is the node that is used in a common interface, either:
     108                 :            :    * (1) A T-unsat conjunction conf to pass to OutputChannel::conflict,
     109                 :            :    * (2) A valid T-formula lem to pass to OutputChannel::lemma,
     110                 :            :    * (3) A conjunction of literals exp to return in Theory::explain(lit), or
     111                 :            :    * (4) A result of rewriting a term n into an equivalent one nr.
     112                 :            :    *
     113                 :            :    * Notice that this node does not necessarily correspond to a valid formula.
     114                 :            :    * The call getProven() below retrieves a valid formula corresponding to
     115                 :            :    * the above calls.
     116                 :            :    */
     117                 :            :   Node getNode() const;
     118                 :            :   /** get proven
     119                 :            :    *
     120                 :            :    * This is the corresponding formula that is proven by the proof generator
     121                 :            :    * for the above cases:
     122                 :            :    * (1) (not conf), for conflicts,
     123                 :            :    * (2) lem, for lemmas,
     124                 :            :    * (3) (=> exp lit), for propagations from explanations,
     125                 :            :    * (4) (= n nr), for results of rewriting.
     126                 :            :    *
     127                 :            :    * When constructing this trust node, the proof generator should be able to
     128                 :            :    * provide a proof for this fact.
     129                 :            :    */
     130                 :            :   Node getProven() const;
     131                 :            :   /** get generator */
     132                 :            :   ProofGenerator* getGenerator() const;
     133                 :            :   /** is null? */
     134                 :            :   bool isNull() const;
     135                 :            :   /**
     136                 :            :    * Gets the proof node for this trust node, which is obtained by
     137                 :            :    * calling the generator's getProofFor method on the proven node.
     138                 :            :    */
     139                 :            :   std::shared_ptr<ProofNode> toProofNode() const;
     140                 :            : 
     141                 :            :   /** Get the proven formula corresponding to a conflict call */
     142                 :            :   static Node getConflictProven(Node conf);
     143                 :            :   /** Get the proven formula corresponding to a lemma call */
     144                 :            :   static Node getLemmaProven(Node lem);
     145                 :            :   /** Get the proven formula corresponding to explanations for propagation */
     146                 :            :   static Node getPropExpProven(TNode lit, Node exp);
     147                 :            :   /** Get the proven formula corresponding to a rewrite */
     148                 :            :   static Node getRewriteProven(TNode n, Node nr);
     149                 :            :   /** For debugging */
     150                 :            :   std::string identifyGenerator() const;
     151                 :            : 
     152                 :            :   /**
     153                 :            :    * debug check closed on Trace c, context ctx is string for debugging
     154                 :            :    *
     155                 :            :    * @param reqNullGen Whether we consider a null generator to be a failure.
     156                 :            :    */
     157                 :            :   void debugCheckClosed(const Options& opts,
     158                 :            :                         const char* c,
     159                 :            :                         const char* ctx,
     160                 :            :                         bool reqNullGen = true);
     161                 :            : 
     162                 :            :  private:
     163                 :            :   TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g = nullptr);
     164                 :            :   /** The kind */
     165                 :            :   TrustNodeKind d_tnk;
     166                 :            :   /** The proven node */
     167                 :            :   Node d_proven;
     168                 :            :   /** The generator */
     169                 :            :   ProofGenerator* d_gen;
     170                 :            : };
     171                 :            : 
     172                 :            : /**
     173                 :            :  * Writes a trust node to a stream.
     174                 :            :  *
     175                 :            :  * @param out The stream to write to
     176                 :            :  * @param n The trust node to write to the stream
     177                 :            :  * @return The stream
     178                 :            :  */
     179                 :            : std::ostream& operator<<(std::ostream& out, TrustNode n);
     180                 :            : 
     181                 :            : }  // namespace cvc5::internal
     182                 :            : 
     183                 :            : #endif /* CVC5__PROOF__TRUST_NODE_H */

Generated by: LCOV version 1.14