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

Generated by: LCOV version 1.14