Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds 4 : : * 5 : : * This file is part of the cvc5 project. 6 : : * 7 : : * Copyright (c) 2009-2025 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 : : * Implementation of witness elimination node conversion 14 : : */ 15 : : #include "cvc5_private.h" 16 : : 17 : : #ifndef CVC5__EXPR__ELIM_WITNESS_NODE_CONVERTER_H 18 : : #define CVC5__EXPR__ELIM_WITNESS_NODE_CONVERTER_H 19 : : 20 : : #include <unordered_set> 21 : : 22 : : #include "expr/node.h" 23 : : #include "expr/node_converter.h" 24 : : #include "smt/env_obj.h" 25 : : 26 : : namespace cvc5::internal { 27 : : 28 : : /** 29 : : * Node converter to eliminate all terms of kind WITNESS. Each term replaced 30 : : * in this way is captured by a skolem that witnesses the axiom for that 31 : : * witness. 32 : : * 33 : : * Witness terms are required to track their justification as part of their 34 : : * AST. In particular, it is required that all terms of kind WITNESS are given 35 : : * an instantiation attribute of the form: 36 : : * (INST_ATTRIBUTE "witness" (SEXPR r a1 ... an)) 37 : : * where r is the (integer value of) a proof rule and a1...an are arguments 38 : : * to that proof rule. This instantiation attribute is always constructed 39 : : * assuming that ValidWitnessProofGenerator 40 : : * (proof/valid_witness_proof_generator.h) is used to construct the witness 41 : : * terms. These annotations are expected to be robust to rewriting and 42 : : * substitution, e.g. rewriting (SEXPR r a1 ... an) does not change whether 43 : : * it is a valid input to the definition of a proof rule. (Note this is not the 44 : : * case for ProofRule::EXISTS_INV_CONDITION, which is why 45 : : * ProofRule::MACRO_EXISTS_INV_CONDITION is used internally). 46 : : * 47 : : * For each witness of this form, we replace the witness by its corresponding 48 : : * skolem and collect its corresponding axiom, defining what lemma we can 49 : : * assume about it, which can be retrieved via ::getAxioms in this class. 50 : : * 51 : : * Note that we use WITNESS terms for two reasons: 52 : : * (1) (witness x (= x t)) can naturally rewrite to t, which we wish to 53 : : * infer when applicable by substitution + rewriting. 54 : : * (2) witness terms trigger this class to recognize when axioms should be 55 : : * added as lemmas. In other words, at the moment witness terms are 56 : : * eliminated, we ensure their axiom is recorded as well. 57 : : */ 58 : : class ElimWitnessNodeConverter : protected EnvObj, public NodeConverter 59 : : { 60 : : public: 61 : : /** Eliminate witness terms.*/ 62 : : ElimWitnessNodeConverter(Env& env); 63 : 765 : ~ElimWitnessNodeConverter() {} 64 : : /** 65 : : * Convert node n as described above during post-order traversal. 66 : : */ 67 : : Node postConvert(Node n) override; 68 : : /** 69 : : * Get the axioms 70 : : */ 71 : : const std::vector<Node>& getAxioms() const; 72 : : /** 73 : : * Get the normal form of a quantified formula for which we are introducing 74 : : * a skolem variable based on eliminating a witness term. 75 : : */ 76 : : virtual Node getNormalFormFor(const Node& q); 77 : : 78 : : private: 79 : : /** The list of axioms introduced by eliminating witness */ 80 : : std::vector<Node> d_axioms; 81 : : }; 82 : : 83 : : } // namespace cvc5::internal 84 : : 85 : : #endif