LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/quantifiers - quant_util.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 5 80.0 %
Date: 2026-05-03 10:46:50 Functions: 4 6 66.7 %
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                 :            :  * quantifier util
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "cvc5_private.h"
      14                 :            : 
      15                 :            : #ifndef CVC5__THEORY__QUANT_UTIL_H
      16                 :            : #define CVC5__THEORY__QUANT_UTIL_H
      17                 :            : 
      18                 :            : #include <iostream>
      19                 :            : #include <map>
      20                 :            : #include <vector>
      21                 :            : 
      22                 :            : #include "expr/node.h"
      23                 :            : #include "smt/env_obj.h"
      24                 :            : #include "theory/incomplete_id.h"
      25                 :            : #include "theory/theory.h"
      26                 :            : 
      27                 :            : namespace cvc5::internal {
      28                 :            : namespace theory {
      29                 :            : 
      30                 :            : /** Quantifiers utility
      31                 :            :  *
      32                 :            :  * This is a lightweight version of a quantifiers module that does not implement
      33                 :            :  * methods for checking satisfiability.
      34                 :            :  */
      35                 :            : class QuantifiersUtil : protected EnvObj
      36                 :            : {
      37                 :            :  public:
      38                 :            :   QuantifiersUtil(Env& env);
      39                 :     304344 :   virtual ~QuantifiersUtil() {}
      40                 :            :   /**  Called at the beginning of check-sat call. */
      41                 :     200674 :   virtual void presolve() {}
      42                 :            :   /* reset
      43                 :            :    * Called at the beginning of an instantiation round
      44                 :            :    * Returns false if the reset failed. When reset fails, the utility should
      45                 :            :    * have added a lemma via a call to d_qim.addPendingLemma.
      46                 :            :    */
      47                 :          0 :   virtual bool reset(CVC5_UNUSED Theory::Effort e) { return true; }
      48                 :            :   /* Called for new quantifiers */
      49                 :      53670 :   virtual void registerQuantifier(CVC5_UNUSED Node q) {}
      50                 :            :   /** Identify this module (for debugging, dynamic configuration, etc..) */
      51                 :            :   virtual std::string identify() const = 0;
      52                 :            :   /** Check complete?
      53                 :            :    *
      54                 :            :    * Returns false if the utility's reasoning was globally incomplete
      55                 :            :    * (e.g. "sat" must be replaced with "incomplete"). If this method returns
      56                 :            :    * false, it should update incId to the reason for incompleteness.
      57                 :            :    */
      58                 :      42489 :   virtual bool checkComplete(CVC5_UNUSED IncompleteId& incId) { return true; }
      59                 :            : };
      60                 :            : 
      61                 :            : class QuantPhaseReq
      62                 :            : {
      63                 :            :  private:
      64                 :            :   /** helper functions compute phase requirements */
      65                 :            :   void computePhaseReqs(Node n, bool polarity, std::map<Node, int>& phaseReqs);
      66                 :            : 
      67                 :            :  public:
      68                 :            :   QuantPhaseReq() {}
      69                 :            :   QuantPhaseReq(Node n, bool computeEq = false);
      70                 :            :   ~QuantPhaseReq() {}
      71                 :            :   void initialize(Node n, bool computeEq);
      72                 :            :   /** is phase required */
      73                 :            :   bool isPhaseReq(Node lit)
      74                 :            :   {
      75                 :            :     return d_phase_reqs.find(lit) != d_phase_reqs.end();
      76                 :            :   }
      77                 :            :   /** get phase requirement */
      78                 :            :   bool getPhaseReq(Node lit)
      79                 :            :   {
      80                 :            :     return d_phase_reqs.find(lit) == d_phase_reqs.end() ? false
      81                 :            :                                                         : d_phase_reqs[lit];
      82                 :            :   }
      83                 :            :   /** phase requirements for each quantifier for each instantiation literal */
      84                 :            :   std::map<Node, bool> d_phase_reqs;
      85                 :            :   std::map<Node, bool> d_phase_reqs_equality;
      86                 :            :   std::map<Node, Node> d_phase_reqs_equality_term;
      87                 :            : 
      88                 :            :   /**
      89                 :            :    * Get the polarity of the child^th child of n, assuming its polarity
      90                 :            :    * is given by (hasPol, pol). A term has polarity if it is only relevant
      91                 :            :    * if asserted with one polarity. Its polarity is (typically) the number
      92                 :            :    * of negations it is beneath.
      93                 :            :    */
      94                 :            :   static void getPolarity(Node n,
      95                 :            :                           size_t child,
      96                 :            :                           bool hasPol,
      97                 :            :                           bool pol,
      98                 :            :                           bool& newHasPol,
      99                 :            :                           bool& newPol);
     100                 :            : 
     101                 :            :   /**
     102                 :            :    * Get the entailed polarity of the child^th child of n, assuming its
     103                 :            :    * entailed polarity is given by (hasPol, pol). A term has entailed polarity
     104                 :            :    * if it must be asserted with a polarity. Its polarity is (typically) the
     105                 :            :    * number of negations it is beneath.
     106                 :            :    *
     107                 :            :    * Entailed polarity and polarity above differ, e.g.:
     108                 :            :    *   (and A B): A and B have true polarity and true entailed polarity
     109                 :            :    *   (or A B): A and B have true polarity and no entailed polarity
     110                 :            :    */
     111                 :            :   static void getEntailPolarity(Node n,
     112                 :            :                                 size_t child,
     113                 :            :                                 bool hasPol,
     114                 :            :                                 bool pol,
     115                 :            :                                 bool& newHasPol,
     116                 :            :                                 bool& newPol);
     117                 :            : };
     118                 :            : 
     119                 :            : }  // namespace theory
     120                 :            : }  // namespace cvc5::internal
     121                 :            : 
     122                 :            : #endif /* CVC5__THEORY__QUANT_UTIL_H */

Generated by: LCOV version 1.14