cvc5-cvc5-1.2.0.src.rewriter.rewrite_proof_rule.h Maven / Gradle / Ivy
The newest version!
/******************************************************************************
* Top contributors (to current version):
* Andrew Reynolds, Hans-Jörg Schurr
*
* This file is part of the cvc5 project.
*
* Copyright (c) 2009-2024 by the authors listed in the file AUTHORS
* in the top-level source directory and their institutional affiliations.
* All rights reserved. See the file COPYING in the top-level source
* directory for licensing information.
* ****************************************************************************
*
* proof rewrite rule class
*/
#include "cvc5_private.h"
#ifndef CVC5__REWRITER__REWRITE_PROOF_RULE__H
#define CVC5__REWRITER__REWRITE_PROOF_RULE__H
#include
#include
#include
#include "expr/nary_match_trie.h"
#include "expr/node.h"
#include "rewriter/rewrites.h"
namespace cvc5::internal {
namespace rewriter {
/**
* The definition of a (conditional) rewrite rule. An instance of this
* class is generated for each DSL rule provided in the rewrite files. The
* interface of this class is used by the proof reconstruction algorithm.
*/
class RewriteProofRule
{
public:
RewriteProofRule();
/**
* Initialize this rule.
* @param id The identifier of this rule
* @param userFvs The (user-provided) free variable list of the rule. This
* is used only to track the original names of the arguments to the rule.
* @param fvs The internal free variable list of the rule. Notice these
* variables are normalized such that *all* proof rules use the same
* variables, per type. In detail, the n^th argument left-to-right of a given
* type T is the same for all rules. This is to facilitate parallel matching.
* @param cond The conditions of the rule, normalized to fvs.
* @param conc The conclusion of the rule, which is an equality of the form
* (= t s), where t is specified as rewriting to s. This equality is
* normalized to fvs.
* @param context The term context for the conclusion of the rule. This is
* non-null for all rules that should be applied to fixed-point. The context
* is a lambda term that specifies the next position of the term to rewrite.
*/
void init(ProofRewriteRule id,
const std::vector& userFvs,
const std::vector& fvs,
const std::vector& cond,
Node conc,
Node context);
/** get id */
ProofRewriteRule getId() const;
/** get name */
const char* getName() const;
/** Get user variable list */
const std::vector& getUserVarList() const;
/** Get variable list */
const std::vector& getVarList() const;
/** The context that the rule is applied in */
Node getContext() const { return d_context; }
/** Does this rule have conditions? */
bool hasConditions() const;
/** Get (declared) conditions */
const std::vector& getConditions() const;
/**
* Get the conditions of the rule under the substitution { vs -> ss }.
*/
bool getObligations(const std::vector& vs,
const std::vector& ss,
std::vector& vcs) const;
/**
* Check match, return true if h matches the head of this rule; notifies
* the match notify object ntm.
*
* Note this method is not run as the main matching algorithm for rewrite
* proof reconstruction, which considers all rules in parallel. This method
* can be used for debugging matches of h against the head of this rule.
*/
void getMatches(Node h, expr::NotifyMatch* ntm) const;
/**
* Get (uninstantiated) conclusion of the rule.
* @param includeContext If we should include the context of this rule (if
* the RARE rule is given a "context" as described in the constructor).
* @return The (uninstantiated) conclusion of the rule.
*/
Node getConclusion(bool includeContext = false) const;
/**
* Get conclusion of the rule for the substituted terms ss for the variables
* v = getVarList() of this rule.
*
* @param ss The terms to substitute in this rule. Each ss[i] is the same sort
* as v[i] if v[i] is not a list variable, or is an SEXPR if v[i] is a list
* variable,
* @return the substituted conclusion of the rule.
*/
Node getConclusionFor(const std::vector& ss) const;
/**
* Get conclusion of the rule for the substituted terms ss.
* Additionally computes the "witness term" for each variable in the rule
* which gives the corresponding term.
* In particular, for each v[i] where v = getVarList(),
* witnessTerms[i] is either:
* (UNDEFINED_KIND, {t}), specifying that v -> t,
* (k, {t1...tn}), specifying that v -> ( t1 ... tn).
* Note that we don't construct ( t1 ... tn) since it may be illegal to
* do so if e.g. k=or, and n=1 due to restrictions on the arity of Kinds.
*
* @param ss The terms to substitute in this rule. Each ss[i] is the same sort
* as v[i] if v[i] is not a list variable, or is an SEXPR if v[i] is a list
* variable,
* @param witnessTerms The computed witness terms for each variable of this
* rule.
* @return the substituted conclusion of the rule.
*/
Node getConclusionFor(
const std::vector& ss,
std::vector>>& witnessTerms) const;
/**
* Is variable explicit? An explicit variable is one that does not occur
* in a condition and thus its value must be specified in a proof
* in languages that allow for implicit/unspecified hole arguments,
* e.g. LFSC.
*/
bool isExplicitVar(Node v) const;
/**
* Get list context. This returns the parent kind of the list variable v.
* For example, for
* (define-rule bool-or-true ((xs Bool :list) (ys Bool :list))
* (or xs true ys) true)
* The variable xs has list context `OR`.
*
* If v is in an ambiguous context, an exception will have been thrown
* in the constructor of this class.
*
* This method returns UNDEFINED_KIND if there is no list context for v,
* e.g. if v is not a list variable.
*/
Kind getListContext(Node v) const;
/** Was this rule marked as being applied to fixed point? */
bool isFixedPoint() const;
/** Is this rule in flat form? */
bool isFlatForm() const;
private:
/** The id of the rule */
ProofRewriteRule d_id;
/** The conditions of the rule */
std::vector d_cond;
/** The obligation generator formulas of the rule */
std::vector d_obGen;
/** The conclusion of the rule (an equality) */
Node d_conc;
/** Is the rule applied in some fixed point context? */
Node d_context;
/** Whether the rule is in flat form */
bool d_isFlatForm;
/** the ordered list of free variables, provided by the user */
std::vector d_userFvs;
/** the ordered list of free variables */
std::vector d_fvs;
/** number of free variables */
size_t d_numFv;
/**
* The free variables that do not occur in the conditions. These cannot be
* "holes" in a proof.
*/
std::unordered_set d_noOccVars;
/** The context for list variables (see expr::getListVarContext). */
std::map d_listVarCtx;
/** The match trie (for fixed point matching) */
expr::NaryMatchTrie d_mt;
};
} // namespace rewriter
} // namespace cvc5::internal
#endif /* CVC5__REWRITER__REWRITE_PROOF_RULE__H */