LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arith - theory_arith.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 3 66.7 %
Date: 2024-11-12 12:40:27 Functions: 1 2 50.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Andrew Reynolds, Gereon Kremer, Tim King
       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                 :            :  * Arithmetic theory.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "cvc5_private.h"
      17                 :            : 
      18                 :            : #pragma once
      19                 :            : 
      20                 :            : #include "expr/node.h"
      21                 :            : #include "theory/arith/arith_preprocess.h"
      22                 :            : #include "theory/arith/arith_rewriter.h"
      23                 :            : #include "theory/arith/arith_subs.h"
      24                 :            : #include "theory/arith/branch_and_bound.h"
      25                 :            : #include "theory/arith/inference_manager.h"
      26                 :            : #include "theory/arith/linear/linear_solver.h"
      27                 :            : #include "theory/arith/pp_rewrite_eq.h"
      28                 :            : #include "theory/arith/proof_checker.h"
      29                 :            : #include "theory/theory.h"
      30                 :            : #include "theory/theory_state.h"
      31                 :            : 
      32                 :            : namespace cvc5::internal {
      33                 :            : namespace theory {
      34                 :            : namespace arith {
      35                 :            : namespace nl {
      36                 :            : class NonlinearExtension;
      37                 :            : }
      38                 :            : 
      39                 :            : class EqualitySolver;
      40                 :            : 
      41                 :            : /**
      42                 :            :  * Implementation of linear and non-linear integer and real arithmetic.
      43                 :            :  * The linear arithmetic solver is based upon:
      44                 :            :  * http://research.microsoft.com/en-us/um/people/leonardo/cav06.pdf
      45                 :            :  */
      46                 :            : class TheoryArith : public Theory {
      47                 :            :  public:
      48                 :            :   TheoryArith(Env& env, OutputChannel& out, Valuation valuation);
      49                 :            :   virtual ~TheoryArith();
      50                 :            : 
      51                 :            :   //--------------------------------- initialization
      52                 :            :   /** get the official theory rewriter of this theory */
      53                 :            :   TheoryRewriter* getTheoryRewriter() override;
      54                 :            :   /** get the proof checker of this theory */
      55                 :            :   ProofRuleChecker* getProofChecker() override;
      56                 :            :   /**
      57                 :            :    * Returns true if this theory needs an equality engine, which is assigned
      58                 :            :    * to it (d_equalityEngine) by the equality engine manager during
      59                 :            :    * TheoryEngine::finishInit, prior to calling finishInit for this theory.
      60                 :            :    * If this method returns true, it stores instructions for the notifications
      61                 :            :    * this Theory wishes to receive from its equality engine.
      62                 :            :    */
      63                 :            :   bool needsEqualityEngine(EeSetupInfo& esi) override;
      64                 :            :   /** finish initialization */
      65                 :            :   void finishInit() override;
      66                 :            :   //--------------------------------- end initialization
      67                 :            :   /**
      68                 :            :    * Does non-context dependent setup for a node connected to a theory.
      69                 :            :    */
      70                 :            :   void preRegisterTerm(TNode n) override;
      71                 :            : 
      72                 :            :   //--------------------------------- standard check
      73                 :            :   /** Pre-check, called before the fact queue of the theory is processed. */
      74                 :            :   bool preCheck(Effort level) override;
      75                 :            :   /** Post-check, called after the fact queue of the theory is processed. */
      76                 :            :   void postCheck(Effort level) override;
      77                 :            :   /** Pre-notify fact, return true if processed. */
      78                 :            :   bool preNotifyFact(TNode atom,
      79                 :            :                      bool pol,
      80                 :            :                      TNode fact,
      81                 :            :                      bool isPrereg,
      82                 :            :                      bool isInternal) override;
      83                 :            :   //--------------------------------- end standard check
      84                 :            :   bool needsCheckLastEffort() override;
      85                 :            :   void propagate(Effort e) override;
      86                 :            :   TrustNode explain(TNode n) override;
      87                 :            : 
      88                 :            :   bool collectModelInfo(TheoryModel* m, const std::set<Node>& termSet) override;
      89                 :            :   /**
      90                 :            :    * Collect model values in m based on the relevant terms given by termSet.
      91                 :            :    */
      92                 :            :   bool collectModelValues(TheoryModel* m,
      93                 :            :                           const std::set<Node>& termSet) override;
      94                 :            : 
      95                 :            :   void presolve() override;
      96                 :            :   void notifyRestart() override;
      97                 :            :   PPAssertStatus ppAssert(TrustNode tin,
      98                 :            :                           TrustSubstitutionMap& outSubstitutions) override;
      99                 :            :   /**
     100                 :            :    * Preprocess rewrite terms, return the trust node encapsulating the
     101                 :            :    * preprocessed form of n, and the proof generator that can provide the
     102                 :            :    * proof for the equivalence of n and this term.
     103                 :            :    *
     104                 :            :    * This calls the operator elimination utility to eliminate extended
     105                 :            :    * symbols.
     106                 :            :    */
     107                 :            :   TrustNode ppRewrite(TNode atom, std::vector<SkolemLemma>& lems) override;
     108                 :            :   TrustNode ppStaticRewrite(TNode atom) override;
     109                 :            :   void ppStaticLearn(TNode in, NodeBuilder& learned) override;
     110                 :            : 
     111                 :          0 :   std::string identify() const override { return std::string("TheoryArith"); }
     112                 :            : 
     113                 :            :   EqualityStatus getEqualityStatus(TNode a, TNode b) override;
     114                 :            : 
     115                 :            :   void notifySharedTerm(TNode n) override;
     116                 :            : 
     117                 :            :   Node getCandidateModelValue(TNode var) override;
     118                 :            : 
     119                 :            :   std::pair<bool, Node> entailmentCheck(TNode lit) override;
     120                 :            : 
     121                 :            :   /** Return a reference to the arith::InferenceManager. */
     122                 :      32265 :   InferenceManager& getInferenceManager()
     123                 :            :   {
     124                 :      32265 :     return d_im;
     125                 :            :   }
     126                 :            : 
     127                 :            :  private:
     128                 :            :   /**
     129                 :            :    * Update d_arithModelCache (if it is empty right now) and compute the termSet
     130                 :            :    * by calling collectAssertedTerms.
     131                 :            :    */
     132                 :            :   void updateModelCache(std::set<Node>& termSet);
     133                 :            :   /**
     134                 :            :    * Update d_arithModelCache (if it is empty right now) using the given
     135                 :            :    * termSet.
     136                 :            :    */
     137                 :            :   void updateModelCacheInternal(const std::set<Node>& termSet);
     138                 :            :   /**
     139                 :            :    * Finalized model cache. Called after d_arithModelCache is finalized during
     140                 :            :    * a full effort check. It computes d_arithModelCacheSubs/Vars, which are
     141                 :            :    * used during theory combination, for getEqualityStatus.
     142                 :            :    */
     143                 :            :   void finalizeModelCache();
     144                 :            :   /**
     145                 :            :    * Perform a sanity check on the model that all integer variables are assigned
     146                 :            :    * to integer values. If an integer variables is assigned to a non-integer
     147                 :            :    * value, but the respective lemma can not be added (i.e. it has already been
     148                 :            :    * added) an assertion triggers. Otherwise teturns true if a lemma was added,
     149                 :            :    * false otherwise.
     150                 :            :    */
     151                 :            :   bool sanityCheckIntegerModel();
     152                 :            : 
     153                 :            :   /** Get the proof equality engine */
     154                 :            :   eq::ProofEqEngine* getProofEqEngine();
     155                 :            :   /** Timer for ppRewrite */
     156                 :            :   TimerStat d_ppRewriteTimer;
     157                 :            :   /** The state object  */
     158                 :            :   TheoryState d_astate;
     159                 :            :   /** The arith::InferenceManager. */
     160                 :            :   InferenceManager d_im;
     161                 :            :   /** The preprocess rewriter for equality */
     162                 :            :   PreprocessRewriteEq d_ppre;
     163                 :            :   /** The branch and bound utility */
     164                 :            :   BranchAndBound d_bab;
     165                 :            :   /** The equality solver */
     166                 :            :   std::unique_ptr<EqualitySolver> d_eqSolver;
     167                 :            :   /** The (old) linear arithmetic solver */
     168                 :            :   linear::LinearSolver d_internal;
     169                 :            : 
     170                 :            :   /**
     171                 :            :    * The non-linear extension, responsible for all approaches for non-linear
     172                 :            :    * arithmetic.
     173                 :            :    */
     174                 :            :   std::unique_ptr<nl::NonlinearExtension> d_nonlinearExtension;
     175                 :            :   /** The operator elimination utility */
     176                 :            :   OperatorElim d_opElim;
     177                 :            :   /** The preprocess utility */
     178                 :            :   ArithPreprocess d_arithPreproc;
     179                 :            :   /** The theory rewriter for this theory. */
     180                 :            :   ArithRewriter d_rewriter;
     181                 :            : 
     182                 :            :   /**
     183                 :            :    * Caches the current arithmetic model with the following life cycle:
     184                 :            :    * postCheck retrieves the model from arith_private and puts it into the
     185                 :            :    * cache. If nonlinear reasoning is enabled, the cache is used for (and
     186                 :            :    * possibly updated by) model-based refinement in postCheck.
     187                 :            :    * In collectModelValues, the cache is filtered for the termSet and then
     188                 :            :    * used to augment the TheoryModel.
     189                 :            :    */
     190                 :            :   std::map<Node, Node> d_arithModelCache;
     191                 :            :   /** Component of the above that was ill-typed */
     192                 :            :   std::map<Node, Node> d_arithModelCacheIllTyped;
     193                 :            :   /** The above model cache, in substitution form. */
     194                 :            :   ArithSubs d_arithModelCacheSubs;
     195                 :            :   /** Is the above map computed? */
     196                 :            :   bool d_arithModelCacheSet;
     197                 :            :   /** Checks the proof rules of this theory. */
     198                 :            :   ArithProofRuleChecker d_checker;
     199                 :            : 
     200                 :            : };/* class TheoryArith */
     201                 :            : 
     202                 :            : }  // namespace arith
     203                 :            : }  // namespace theory
     204                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14