LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arrays - inference_manager.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 63 64 98.4 %
Date: 2024-11-02 11:39:27 Functions: 4 4 100.0 %
Branches: 24 44 54.5 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Andrew Reynolds, Hans-Joerg Schurr, Gereon Kremer
       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                 :            :  * Arrays inference manager.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "theory/arrays/inference_manager.h"
      17                 :            : 
      18                 :            : #include "options/smt_options.h"
      19                 :            : #include "proof/trust_id.h"
      20                 :            : #include "theory/builtin/proof_checker.h"
      21                 :            : #include "theory/theory.h"
      22                 :            : #include "theory/theory_state.h"
      23                 :            : #include "theory/uf/equality_engine.h"
      24                 :            : 
      25                 :            : using namespace cvc5::internal::kind;
      26                 :            : 
      27                 :            : namespace cvc5::internal {
      28                 :            : namespace theory {
      29                 :            : namespace arrays {
      30                 :            : 
      31                 :      49772 : InferenceManager::InferenceManager(Env& env, Theory& t, TheoryState& state)
      32                 :            :     : TheoryInferenceManager(env, t, state, "theory::arrays::", false),
      33                 :      99544 :       d_lemmaPg(isProofEnabled() ? new EagerProofGenerator(
      34                 :      20760 :                     env, userContext(), "ArrayLemmaProofGenerator")
      35                 :      70532 :                                  : nullptr)
      36                 :            : {
      37                 :      49772 : }
      38                 :            : 
      39                 :      22298 : bool InferenceManager::assertInference(
      40                 :            :     TNode atom, bool polarity, InferenceId id, TNode reason, ProofRule pfr)
      41                 :            : {
      42         [ +  - ]:      44596 :   Trace("arrays-infer") << "TheoryArrays::assertInference: "
      43 [ -  - ][ -  + ]:      22298 :                         << (polarity ? Node(atom) : atom.notNode()) << " by "
                 [ -  - ]
      44                 :      22298 :                         << reason << "; " << id << std::endl;
      45 [ -  + ][ -  + ]:      22298 :   Assert(atom.getKind() == Kind::EQUAL);
                 [ -  - ]
      46                 :            :   // if proofs are enabled, we determine which proof rule to add, otherwise
      47                 :            :   // we simply assert the internal fact
      48         [ +  + ]:      22298 :   if (isProofEnabled())
      49                 :            :   {
      50         [ +  + ]:      13076 :     Node fact = polarity ? Node(atom) : atom.notNode();
      51                 :      13076 :     std::vector<Node> children;
      52                 :       6538 :     std::vector<Node> args;
      53                 :            :     // convert to proof rule application
      54                 :       6538 :     convert(pfr, fact, reason, children, args);
      55                 :       6538 :     return assertInternalFact(atom, polarity, id, pfr, children, args);
      56                 :            :   }
      57                 :      15760 :   return assertInternalFact(atom, polarity, id, reason);
      58                 :            : }
      59                 :            : 
      60                 :       7060 : bool InferenceManager::arrayLemma(
      61                 :            :     Node conc, InferenceId id, Node exp, ProofRule pfr, LemmaProperty p)
      62                 :            : {
      63         [ +  - ]:      14120 :   Trace("arrays-infer") << "TheoryArrays::arrayLemma: " << conc << " by " << exp
      64                 :       7060 :                         << "; " << id << std::endl;
      65                 :       7060 :   NodeManager* nm = nodeManager();
      66         [ +  + ]:       7060 :   if (isProofEnabled())
      67                 :            :   {
      68                 :       5392 :     std::vector<Node> children;
      69                 :       5392 :     std::vector<Node> args;
      70                 :            :     // convert to proof rule application
      71                 :       2696 :     convert(pfr, conc, exp, children, args);
      72                 :            :     // make the trusted lemma based on the eager proof generator and send
      73                 :       5392 :     TrustNode tlem = d_lemmaPg->mkTrustNode(conc, pfr, children, args);
      74                 :       2696 :     return trustedLemma(tlem, id, p);
      75                 :            :   }
      76                 :            :   // send lemma without proofs
      77                 :       8728 :   Node lem = nm->mkNode(Kind::IMPLIES, exp, conc);
      78                 :       4364 :   return lemma(lem, id, p);
      79                 :            : }
      80                 :            : 
      81                 :       9234 : void InferenceManager::convert(ProofRule& id,
      82                 :            :                                Node conc,
      83                 :            :                                Node exp,
      84                 :            :                                std::vector<Node>& children,
      85                 :            :                                std::vector<Node>& args)
      86                 :            : {
      87                 :            :   // note that children must contain something equivalent to exp,
      88                 :            :   // regardless of the ProofRule.
      89 [ +  + ][ +  + ]:       9234 :   switch (id)
                 [ +  + ]
      90                 :            :   {
      91                 :        753 :     case ProofRule::MACRO_SR_PRED_INTRO:
      92 [ -  + ][ -  + ]:        753 :       Assert(exp.isConst());
                 [ -  - ]
      93                 :        753 :       args.push_back(conc);
      94                 :        753 :       break;
      95                 :       6969 :     case ProofRule::ARRAYS_READ_OVER_WRITE:
      96         [ +  + ]:       6969 :       if (exp.isConst())
      97                 :            :       {
      98                 :            :         // Premise can be shown by rewriting, use standard predicate intro rule.
      99                 :            :         // This is the case where we have 2 constant indices.
     100                 :        868 :         id = ProofRule::MACRO_SR_PRED_INTRO;
     101                 :        868 :         args.push_back(conc);
     102                 :            :       }
     103                 :            :       else
     104                 :            :       {
     105                 :       6101 :         children.push_back(exp);
     106                 :       6101 :         args.push_back(conc[0]);
     107                 :            :       }
     108                 :       6969 :       break;
     109                 :          6 :     case ProofRule::ARRAYS_READ_OVER_WRITE_CONTRA:
     110                 :          6 :       children.push_back(exp);
     111                 :          6 :       break;
     112                 :        846 :     case ProofRule::ARRAYS_READ_OVER_WRITE_1:
     113 [ -  + ][ -  + ]:        846 :       Assert(exp.isConst());
                 [ -  - ]
     114                 :        846 :       args.push_back(conc[0]);
     115                 :        846 :       break;
     116                 :        625 :     case ProofRule::ARRAYS_EXT:
     117                 :            :       // since this rule depends on the ARRAY_DEQ_DIFF skolem which sorts
     118                 :            :       // indices, we assert that the equality is ordered here, which it should
     119                 :            :       // be based on the standard order for equality.
     120                 :       1250 :       Assert(exp.getKind() == Kind::NOT && exp[0].getKind() == Kind::EQUAL
     121                 :            :              && exp[0][0] < exp[0][1]);
     122                 :        625 :       children.push_back(exp);
     123                 :        625 :       break;
     124                 :         35 :     default:
     125         [ -  + ]:         35 :       if (id != ProofRule::TRUST)
     126                 :            :       {
     127                 :          0 :         Assert(false) << "Unknown rule " << id << "\n";
     128                 :            :       }
     129                 :         35 :       children.push_back(exp);
     130                 :         35 :       args.push_back(mkTrustId(TrustId::THEORY_INFERENCE));
     131                 :         35 :       args.push_back(conc);
     132                 :         35 :       args.push_back(
     133                 :         70 :           builtin::BuiltinProofRuleChecker::mkTheoryIdNode(THEORY_ARRAYS));
     134                 :         35 :       id = ProofRule::TRUST;
     135                 :         35 :       break;
     136                 :            :   }
     137                 :       9234 : }
     138                 :            : 
     139                 :            : }  // namespace arrays
     140                 :            : }  // namespace theory
     141                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14