All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cvc5-cvc5-1.2.0.src.theory.quantifiers.proof_checker.cpp Maven / Gradle / Ivy

The newest version!
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds, Hans-Jörg Schurr, Aina Niemetz
 *
 * 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.
 * ****************************************************************************
 *
 * Implementation of quantifiers proof checker.
 */

#include "theory/quantifiers/proof_checker.h"

#include "expr/node_algorithm.h"
#include "expr/skolem_manager.h"
#include "theory/builtin/proof_checker.h"
#include "theory/quantifiers/skolemize.h"

using namespace cvc5::internal::kind;

namespace cvc5::internal {
namespace theory {
namespace quantifiers {

QuantifiersProofRuleChecker::QuantifiersProofRuleChecker(NodeManager* nm)
    : ProofRuleChecker(nm)
{
}

void QuantifiersProofRuleChecker::registerTo(ProofChecker* pc)
{
  // add checkers
  pc->registerChecker(ProofRule::SKOLEM_INTRO, this);
  pc->registerChecker(ProofRule::SKOLEMIZE, this);
  pc->registerChecker(ProofRule::INSTANTIATE, this);
  pc->registerChecker(ProofRule::ALPHA_EQUIV, this);
}

Node QuantifiersProofRuleChecker::checkInternal(
    ProofRule id,
    const std::vector& children,
    const std::vector& args)
{
  if (id == ProofRule::SKOLEM_INTRO)
  {
    Assert(children.empty());
    Assert(args.size() == 1);
    Node t = SkolemManager::getUnpurifiedForm(args[0]);
    return args[0].eqNode(t);
  }
  else if (id == ProofRule::SKOLEMIZE)
  {
    Assert(children.size() == 1);
    Assert(args.empty());
    // must use negated FORALL
    if (children[0].getKind() != Kind::NOT
        || children[0][0].getKind() != Kind::FORALL)
    {
      return Node::null();
    }
    Node q = children[0][0];
    std::vector vars(q[0].begin(), q[0].end());
    std::vector skolems = Skolemize::getSkolemConstants(q);
    Node res = q[1].substitute(
        vars.begin(), vars.end(), skolems.begin(), skolems.end());
    res = res.notNode();
    return res;
  }
  else if (id == ProofRule::INSTANTIATE)
  {
    Assert(children.size() == 1);
    // note we may have more arguments than just the term vector
    if (children[0].getKind() != Kind::FORALL || args.empty())
    {
      return Node::null();
    }
    Node body = children[0][1];
    std::vector vars;
    std::vector subs;
    for (size_t i = 0, nc = children[0][0].getNumChildren(); i < nc; i++)
    {
      vars.push_back(children[0][0][i]);
      subs.push_back(args[0][i]);
    }
    Node inst =
        body.substitute(vars.begin(), vars.end(), subs.begin(), subs.end());
    return inst;
  }
  else if (id == ProofRule::ALPHA_EQUIV)
  {
    Assert(children.empty());
    Assert(args.size() == 3);
    // must be lists of the same length
    if (args[1].getKind() != Kind::SEXPR || args[2].getKind() != Kind::SEXPR
        || args[1].getNumChildren() != args[2].getNumChildren())
    {
      return Node::null();
    }
    // arguments must be lists of bound variables that are pairwise unique
    std::unordered_set allVars[2];
    std::vector vars;
    std::vector newVars;
    for (size_t i = 0, nargs = args[1].getNumChildren(); i < nargs; i++)
    {
      for (size_t j = 1; j <= 2; j++)
      {
        Node v = args[j][i];
        std::unordered_set& av = allVars[j - 1];
        if (v.getKind() != Kind::BOUND_VARIABLE || av.find(v) != av.end())
        {
          return Node::null();
        }
        av.insert(v);
      }
      vars.push_back(args[1][i]);
      newVars.push_back(args[2][i]);
    }
    Node renamedBody = args[0].substitute(
        vars.begin(), vars.end(), newVars.begin(), newVars.end());
    return args[0].eqNode(renamedBody);
  }

  // no rule
  return Node::null();
}

}  // namespace quantifiers
}  // namespace theory
}  // namespace cvc5::internal




© 2015 - 2024 Weber Informatics LLC | Privacy Policy