LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arith - operator_elim.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2024-09-25 12:15:45 Functions: 1 2 50.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Andrew Reynolds, Martin Brain, 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                 :            :  * Operator elimination for arithmetic.
      14                 :            :  */
      15                 :            : 
      16                 :            : #pragma once
      17                 :            : 
      18                 :            : #include <map>
      19                 :            : 
      20                 :            : #include "expr/node.h"
      21                 :            : #include "expr/skolem_manager.h"
      22                 :            : #include "proof/eager_proof_generator.h"
      23                 :            : #include "smt/env_obj.h"
      24                 :            : #include "theory/logic_info.h"
      25                 :            : #include "theory/skolem_lemma.h"
      26                 :            : 
      27                 :            : namespace cvc5::internal {
      28                 :            : 
      29                 :            : class TConvProofGenerator;
      30                 :            : 
      31                 :            : namespace theory {
      32                 :            : namespace arith {
      33                 :            : 
      34                 :            : class OperatorElim : public EagerProofGenerator
      35                 :            : {
      36                 :            :  public:
      37                 :            :   OperatorElim(Env& env);
      38                 :      48967 :   ~OperatorElim() {}
      39                 :            :   /** Eliminate operators in this term.
      40                 :            :    *
      41                 :            :    * Eliminate operators in term n. If n has top symbol that is not a core
      42                 :            :    * one (including division, int division, mod, to_int, is_int, syntactic sugar
      43                 :            :    * transcendental functions), then we replace it by a form that eliminates
      44                 :            :    * that operator. This may involve the introduction of witness terms.
      45                 :            :    *
      46                 :            :    * @param n The node to eliminate
      47                 :            :    * @param lems The lemmas that we wish to add concerning n. It is the
      48                 :            :    * responsbility of the caller to process these lemmas.
      49                 :            :    * @param partialOnly Whether we only want to eliminate partial operators.
      50                 :            :    * @return the trust node of kind REWRITE encapsulating the eliminated form
      51                 :            :    * of n and a proof generator for proving this equivalence.
      52                 :            :    */
      53                 :            :   TrustNode eliminate(Node n,
      54                 :            :                       std::vector<SkolemLemma>& lems,
      55                 :            :                       bool partialOnly = false);
      56                 :            :   /**
      57                 :            :    * Get axiom for term n. This returns the axiom that this class uses to
      58                 :            :    * eliminate the term n, which is determined by its top-most symbol.
      59                 :            :    */
      60                 :            :   static Node getAxiomFor(Node n);
      61                 :            : 
      62                 :            :  private:
      63                 :            :   /**
      64                 :            :    * Function symbols used to implement:
      65                 :            :    * (1) Uninterpreted division-by-zero semantics.  Needed to deal with partial
      66                 :            :    * division function ("/"),
      67                 :            :    * (2) Uninterpreted int-division-by-zero semantics.  Needed to deal with
      68                 :            :    * partial function "div",
      69                 :            :    * (3) Uninterpreted mod-zero semantics.  Needed to deal with partial
      70                 :            :    * function "mod".
      71                 :            :    *
      72                 :            :    * If the option arithNoPartialFun() is enabled, then the range of this map
      73                 :            :    * stores Skolem constants instead of Skolem functions, meaning that the
      74                 :            :    * function-ness of e.g. division by zero is ignored.
      75                 :            :    *
      76                 :            :    * Note that this cache is used only for performance reasons. Conceptually,
      77                 :            :    * these skolem functions actually live in SkolemManager.
      78                 :            :    */
      79                 :            :   std::map<SkolemId, Node> d_arithSkolem;
      80                 :            :   /**
      81                 :            :    * Eliminate operators in term n. If n has top symbol that is not a core
      82                 :            :    * one (including division, int division, mod, to_int, is_int, syntactic sugar
      83                 :            :    * transcendental functions), then we replace it by a form that eliminates
      84                 :            :    * that operator. This may involve the introduction of witness terms.
      85                 :            :    *
      86                 :            :    * One exception to the above rule is that we may leave certain applications
      87                 :            :    * like (/ 4 1) unchanged, since replacing this by 4 changes its type from
      88                 :            :    * real to int. This is important for some subtyping issues during
      89                 :            :    * expandDefinition. Moreover, applications like this can be eliminated
      90                 :            :    * trivially later by rewriting.
      91                 :            :    *
      92                 :            :    * This method is called both during expandDefinition and during ppRewrite.
      93                 :            :    *
      94                 :            :    * @param n The node to eliminate operators from.
      95                 :            :    * @return The (single step) eliminated form of n.
      96                 :            :    */
      97                 :            :   Node eliminateOperators(Node n,
      98                 :            :                           std::vector<SkolemLemma>& lems,
      99                 :            :                           TConvProofGenerator* tg,
     100                 :            :                           bool partialOnly);
     101                 :            :   /** get arithmetic skolem
     102                 :            :    *
     103                 :            :    * Returns the Skolem in the above map for the given id, creating it if it
     104                 :            :    * does not already exist.
     105                 :            :    */
     106                 :            :   Node getArithSkolem(SkolemId asi);
     107                 :            :   /**
     108                 :            :    * Get the skolem lemma for lem, based on whether we are proof producing.
     109                 :            :    * A skolem lemma is a wrapper around lem that also tracks its associated
     110                 :            :    * skolem k.
     111                 :            :    *
     112                 :            :    * @param lem The lemma that axiomatizes the behavior of k
     113                 :            :    * @param k The skolem
     114                 :            :    * @return the skolem lemma corresponding to lem, annotated with k.
     115                 :            :    */
     116                 :            :   SkolemLemma mkSkolemLemma(Node lem, Node k);
     117                 :            :   /** get arithmetic skolem application
     118                 :            :    *
     119                 :            :    * By default, this returns the term f( n ), where f is the Skolem function
     120                 :            :    * for the identifier asi.
     121                 :            :    *
     122                 :            :    * If the option arithNoPartialFun is enabled, this returns f, where f is
     123                 :            :    * the Skolem constant for the identifier asi.
     124                 :            :    */
     125                 :            :   Node getArithSkolemApp(Node n, SkolemId asi);
     126                 :            : 
     127                 :            :   /**
     128                 :            :    * Called when a non-linear term n is given to this class. Throw an exception
     129                 :            :    * if the logic is linear.
     130                 :            :    */
     131                 :            :   void checkNonLinearLogic(Node term);
     132                 :            : 
     133                 :            :   /** Whether we should use a partial function for the given id */
     134                 :            :   bool usePartialFunction(SkolemId id) const;
     135                 :            : };
     136                 :            : 
     137                 :            : }  // namespace arith
     138                 :            : }  // namespace theory
     139                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14