LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/strings - infer_info.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 3 100.0 %
Date: 2024-09-23 10:48:02 Functions: 4 5 80.0 %
Branches: 3 4 75.0 %

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

Generated by: LCOV version 1.14