Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
ajreynol committed Oct 18, 2024
1 parent d10ac5e commit 9533448
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ libcvc5_add_sources(
theory/arith/nl/coverings/variable_ordering.h
theory/arith/nl/equality_substitution.cpp
theory/arith/nl/equality_substitution.h
theory/arith/nl/ext/arith_nl_compare_proof_gen.cpp
theory/arith/nl/ext/arith_nl_compare_proof_gen.h
theory/arith/nl/ext/constraint.cpp
theory/arith/nl/ext/constraint.h
theory/arith/nl/ext/factoring_check.cpp
Expand Down
68 changes: 68 additions & 0 deletions src/theory/arith/nl/ext/arith_nl_compare_proof_gen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/******************************************************************************
* Top contributors (to current version):
* Andrew Reynolds
*
* 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.
* ****************************************************************************
*
* Utilities for monomials.
*/

#include "theory/arith/nl/ext/arith_nl_compare_proof_gen.h"

#include "theory/arith/arith_utilities.h"
#include "theory/arith/nl/ext/monomial_check.h"

namespace cvc5::internal {
namespace theory {
namespace arith {
namespace nl {

ArithNlCompareProofGenerator::ArithNlCompareProofGenerator(Env& env) : EnvObj(env), d_absConv(env) {}
ArithNlCompareProofGenerator::~ArithNlCompareProofGenerator() {}

std::shared_ptr<ProofNode> ArithNlCompareProofGenerator::getProofFor(Node fact)
{
Assert (fact.getKind()==Kind::IMPLIES);
std::vector<Node> exp;
if (fact[0].getKind()==Kind::AND)
{
exp.insert(exp.end(), fact[0].begin(), fact[0].end());
}
else
{
exp.emplace_back(fact[0]);
}
Node conc = fact[1];
CDProof cdp(d_env);
cdp.addStep(conc, ProofRule::MACRO_ARITH_NL_COMPARISON, exp, {conc});
cdp.addStep(fact, ProofRule::SCOPE, {conc}, exp);
return cdp.getProofFor(fact);
}

std::string ArithNlCompareProofGenerator::identify() const { return "ArithNlCompareProofGenerator"; }

Node ArithNlCompareProofGenerator::mkLit(NodeManager* nm, Kind k, Node a, Node b, bool isAbsolute)
{
if (isAbsolute)
{
a = nm->mkNode(Kind::ABS, a);
b = nm->mkNode(Kind::ABS, b);
}
if (k==Kind::EQUAL)
{
return mkEquality(a, b);
}
return nm->mkNode(k, a, b);
}

} // namespace nl
} // namespace arith
} // namespace theory
} // namespace cvc5::internal

50 changes: 50 additions & 0 deletions src/theory/arith/nl/ext/arith_nl_compare_proof_gen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/******************************************************************************
* Top contributors (to current version):
* Andrew Reynolds
*
* 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.
* ****************************************************************************
*
* Utilities for monomials.
*/

#ifndef CVC5__THEORY__ARITH__NL__EXT__ARITH_NL_COMPARE_PROOF_GEN_H
#define CVC5__THEORY__ARITH__NL__EXT__ARITH_NL_COMPARE_PROOF_GEN_H

#include "smt/env_obj.h"
#include "proof/proof_generator.h"
#include "proof/conv_proof_generator.h"

namespace cvc5::internal {
namespace theory {
namespace arith {
namespace nl {

class ArithNlCompareProofGenerator : protected EnvObj, public ProofGenerator
{
public:
ArithNlCompareProofGenerator(Env& env);
virtual ~ArithNlCompareProofGenerator();
/**
*/
std::shared_ptr<ProofNode> getProofFor(Node fact) override;
/** identify */
std::string identify() const override;
/** Make literal */
static Node mkLit(NodeManager* nm, Kind k, Node a, Node b, bool isAbsolute);
private:
/** Converter for absolute value literals */
TConvProofGenerator d_absConv;
};

} // namespace nl
} // namespace arith
} // namespace theory
} // namespace cvc5::internal

#endif /* CVC5__THEORY__ARITH__NL_MONOMIAL_H */
38 changes: 18 additions & 20 deletions src/theory/arith/nl/ext/monomial_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace arith {
namespace nl {

MonomialCheck::MonomialCheck(Env& env, ExtState* data)
: EnvObj(env), d_data(data)
: EnvObj(env), d_data(data), d_ancPfGen(env.isTheoryProofProducing() ? new ArithNlCompareProofGenerator(env) : nullptr)
{
d_order_points.push_back(d_data->d_neg_one);
d_order_points.push_back(d_data->d_zero);
Expand Down Expand Up @@ -304,7 +304,7 @@ int MonomialCheck::compareSign(
if (mvaoa.getConst<Rational>().sgn() != status)
{
Node zero = mkZero(oa.getType());
Node lemma = nm->mkAnd(exp).impNode(mkLit(oa, zero, status * 2));
Node lemma = nm->mkAnd(exp).impNode(mkLit(nm, oa, zero, status * 2));
CDProof* proof = nullptr;
if (d_data->isProofEnabled())
{
Expand Down Expand Up @@ -425,19 +425,18 @@ bool MonomialCheck::compareMonomial(
exp.push_back(v.eqNode(mkZero(v.getType())).negate());
}
}
Node conc = mkLit(oa, ob, status, true);
Node cob = ob;
if (ob==d_data->d_one)
{
cob = mkOne(oa.getType());
}
Node conc = mkLit(nm, oa, ob, status, true);
Node clem = nm->mkNode(
Kind::IMPLIES, nm->mkAnd(exp), conc);
Trace("nl-ext-comp-lemma") << "comparison lemma : " << clem << std::endl;
CDProof* proof = nullptr;
if (d_data->isProofEnabled())
{
proof = d_data->getProof();
proof->addStep(conc, ProofRule::MACRO_ARITH_NL_COMPARISON, exp, {conc});
proof->addStep(clem, ProofRule::SCOPE, {conc}, exp);
}
// use special proof generator
lem.emplace_back(
InferenceId::ARITH_NL_COMPARISON, clem, LemmaProperty::NONE, proof);
InferenceId::ARITH_NL_COMPARISON, clem, LemmaProperty::NONE, d_ancPfGen.get());
cmp_infers[status][oa][ob] = clem;
}
return true;
Expand Down Expand Up @@ -512,7 +511,7 @@ bool MonomialCheck::compareMonomial(
Trace("nl-ext-comp-debug") << "...take leading " << bv << std::endl;
// can multiply b by <=1
Node one = mkOne(bv.getType());
exp.push_back(mkLit(one, bv, bvo == ovo ? 0 : 2, true));
exp.push_back(mkLit(nm, one, bv, bvo == ovo ? 0 : 2, true));
return compareMonomial(oa,
a,
a_index,
Expand All @@ -537,7 +536,7 @@ bool MonomialCheck::compareMonomial(
Trace("nl-ext-comp-debug") << "...take leading " << av << std::endl;
// can multiply a by >=1
Node one = mkOne(av.getType());
exp.push_back(mkLit(av, one, avo == ovo ? 0 : 2, true));
exp.push_back(mkLit(nm, av, one, avo == ovo ? 0 : 2, true));
return compareMonomial(oa,
a,
a_index + 1,
Expand All @@ -563,7 +562,7 @@ bool MonomialCheck::compareMonomial(
Trace("nl-ext-comp-debug") << "...take leading " << av << std::endl;
// do avo>=1 instead
Node one = mkOne(av.getType());
exp.push_back(mkLit(av, one, avo == ovo ? 0 : 2, true));
exp.push_back(mkLit(nm, av, one, avo == ovo ? 0 : 2, true));
return compareMonomial(oa,
a,
a_index + 1,
Expand All @@ -582,7 +581,7 @@ bool MonomialCheck::compareMonomial(
b_exp_proc[bv] += min_exp;
Trace("nl-ext-comp-debug") << "...take leading " << min_exp << " from "
<< av << " and " << bv << std::endl;
exp.push_back(mkLit(av, bv, avo == bvo ? 0 : 2, true));
exp.push_back(mkLit(nm, av, bv, avo == bvo ? 0 : 2, true));
bool ret = compareMonomial(oa,
a,
a_index,
Expand All @@ -604,7 +603,7 @@ bool MonomialCheck::compareMonomial(
Trace("nl-ext-comp-debug") << "...take leading " << bv << std::endl;
// try multiply b <= 1
Node one = mkOne(bv.getType());
exp.push_back(mkLit(one, bv, bvo == ovo ? 0 : 2, true));
exp.push_back(mkLit(nm, one, bv, bvo == ovo ? 0 : 2, true));
return compareMonomial(oa,
a,
a_index,
Expand Down Expand Up @@ -726,9 +725,9 @@ void MonomialCheck::assignOrderIds(std::vector<Node>& vars,
order_index++;
}
}
Node MonomialCheck::mkLit(Node a, Node b, int status, bool isAbsolute) const

Node MonomialCheck::mkLit(NodeManager* nm, Node a, Node b, int status, bool isAbsolute)
{
NodeManager* nm = nodeManager();
Assert(a.getType().isRealOrInt() && b.getType().isRealOrInt());
if (status == 0)
{
Expand All @@ -742,15 +741,14 @@ Node MonomialCheck::mkLit(Node a, Node b, int status, bool isAbsolute) const
}
else if (status < 0)
{
return mkLit(b, a, -status);
return mkLit(nm, b, a, -status);
}
Assert(status == 1 || status == 2);
Kind greater_op = status == 1 ? Kind::GEQ : Kind::GT;
if (!isAbsolute)
{
return nm->mkNode(greater_op, a, b);
}
// return nm->mkNode( greater_op, mkAbs( a ), mkAbs( b ) );
Node zero = mkZero(a.getType());
Node a_is_nonnegative = nm->mkNode(Kind::GEQ, a, zero);
Node b_is_nonnegative = nm->mkNode(Kind::GEQ, b, zero);
Expand Down
7 changes: 5 additions & 2 deletions src/theory/arith/nl/ext/monomial_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "smt/env_obj.h"
#include "theory/arith/nl/ext/monomial.h"
#include "theory/theory_inference.h"
#include "theory/arith/nl/ext/arith_nl_compare_proof_gen.h"

namespace cvc5::internal {
namespace theory {
Expand Down Expand Up @@ -74,6 +75,8 @@ class MonomialCheck : protected EnvObj
*/
void checkMagnitude(unsigned c);

/** Make literal */
static Node mkLit(NodeManager* nm, Node a, Node b, int status, bool isAbsolute = false);
private:
/** In the following functions, status states a relationship
* between two arithmetic terms, where:
Expand Down Expand Up @@ -175,8 +178,6 @@ class MonomialCheck : protected EnvObj
NodeMultiset& d_order,
bool isConcrete,
bool isAbsolute);
/** Make literal */
Node mkLit(Node a, Node b, int status, bool isAbsolute = false) const;
/** register monomial */
void setMonomialFactor(Node a, Node b, const NodeMultiset& common);

Expand All @@ -191,6 +192,8 @@ class MonomialCheck : protected EnvObj
// list of monomials with factors whose model value is non-constant in model
// e.g. y*cos( x )
std::map<Node, bool> d_m_nconst_factor;
/** A proof generator for MACRO_ARITH_NL_COMPARISON steps */
std::shared_ptr<ArithNlCompareProofGenerator> d_ancPfGen;
};

} // namespace nl
Expand Down

0 comments on commit 9533448

Please sign in to comment.