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