fix(library/simplifier): must use metavar_env in is_ceq, otherwise it may ceqs that contain metavariables
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
4dc3aa46c3
commit
dd6aae378f
4 changed files with 14 additions and 9 deletions
|
@ -8,6 +8,7 @@ Author: Leonardo de Moura
|
||||||
#include "kernel/kernel.h"
|
#include "kernel/kernel.h"
|
||||||
#include "kernel/free_vars.h"
|
#include "kernel/free_vars.h"
|
||||||
#include "kernel/for_each_fn.h"
|
#include "kernel/for_each_fn.h"
|
||||||
|
#include "kernel/type_checker.h"
|
||||||
#include "library/expr_pair.h"
|
#include "library/expr_pair.h"
|
||||||
#include "library/ite.h"
|
#include "library/ite.h"
|
||||||
#include "library/kernel_bindings.h"
|
#include "library/kernel_bindings.h"
|
||||||
|
@ -16,7 +17,7 @@ Author: Leonardo de Moura
|
||||||
namespace lean {
|
namespace lean {
|
||||||
static name g_Hc("Hc"); // auxiliary name for if-then-else
|
static name g_Hc("Hc"); // auxiliary name for if-then-else
|
||||||
|
|
||||||
bool is_ceq(ro_environment const & env, expr e);
|
bool is_ceq(ro_environment const & env, optional<ro_metavar_env> const & menv, expr e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Auxiliary functional object for creating "conditional equations"
|
\brief Auxiliary functional object for creating "conditional equations"
|
||||||
|
@ -122,7 +123,7 @@ public:
|
||||||
to_ceqs_fn(ro_environment const & env, optional<ro_metavar_env> const & menv):m_env(env), m_menv(menv), m_idx(0) {}
|
to_ceqs_fn(ro_environment const & env, optional<ro_metavar_env> const & menv):m_env(env), m_menv(menv), m_idx(0) {}
|
||||||
|
|
||||||
list<expr_pair> operator()(expr const & e, expr const & H) {
|
list<expr_pair> operator()(expr const & e, expr const & H) {
|
||||||
return filter(apply(e, H), [&](expr_pair const & p) { return is_ceq(m_env, p.first); });
|
return filter(apply(e, H), [&](expr_pair const & p) { return is_ceq(m_env, m_menv, p.first); });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ list<expr_pair> to_ceqs(ro_environment const & env, optional<ro_metavar_env> con
|
||||||
return to_ceqs_fn(env, menv)(e, H);
|
return to_ceqs_fn(env, menv)(e, H);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_ceq(ro_environment const & env, expr e) {
|
bool is_ceq(ro_environment const & env, optional<ro_metavar_env> const & menv, expr e) {
|
||||||
buffer<bool> found_args;
|
buffer<bool> found_args;
|
||||||
// Define a procedure for marking arguments found.
|
// Define a procedure for marking arguments found.
|
||||||
auto visitor_fn = [&](expr const & e, unsigned offset) {
|
auto visitor_fn = [&](expr const & e, unsigned offset) {
|
||||||
|
@ -147,7 +148,7 @@ bool is_ceq(ro_environment const & env, expr e) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
type_checker tc(env);
|
||||||
context ctx;
|
context ctx;
|
||||||
while (is_pi(e)) {
|
while (is_pi(e)) {
|
||||||
if (!found_args.empty()) {
|
if (!found_args.empty()) {
|
||||||
|
@ -158,7 +159,7 @@ bool is_ceq(ro_environment const & env, expr e) {
|
||||||
}
|
}
|
||||||
// If a variable is a proposition, than if doesn't need to occurr in the lhs.
|
// If a variable is a proposition, than if doesn't need to occurr in the lhs.
|
||||||
// So, we mark it as true.
|
// So, we mark it as true.
|
||||||
found_args.push_back(env->is_proposition(abst_domain(e), ctx));
|
found_args.push_back(tc.is_proposition(abst_domain(e), ctx, menv));
|
||||||
ctx = extend(ctx, abst_name(e), abst_domain(e));
|
ctx = extend(ctx, abst_name(e), abst_domain(e));
|
||||||
e = abst_body(e);
|
e = abst_body(e);
|
||||||
}
|
}
|
||||||
|
@ -255,7 +256,10 @@ static int to_ceqs(lua_State * L) {
|
||||||
|
|
||||||
static int is_ceq(lua_State * L) {
|
static int is_ceq(lua_State * L) {
|
||||||
ro_shared_environment env(L, 1);
|
ro_shared_environment env(L, 1);
|
||||||
lua_pushboolean(L, is_ceq(env, to_expr(L, 2)));
|
optional<ro_metavar_env> menv;
|
||||||
|
if (!lua_isnil(L, 2))
|
||||||
|
menv = to_metavar_env(L, 2);
|
||||||
|
lua_pushboolean(L, is_ceq(env, menv, to_expr(L, 3)));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ list<expr_pair> to_ceqs(ro_environment const & env, optional<ro_metavar_env> con
|
||||||
Moreover, for <tt>(forall x : A, ceq)</tt>, the variable x must occur in the \c ceq left-hand-size
|
Moreover, for <tt>(forall x : A, ceq)</tt>, the variable x must occur in the \c ceq left-hand-size
|
||||||
when \c A is not a proposition.
|
when \c A is not a proposition.
|
||||||
*/
|
*/
|
||||||
bool is_ceq(ro_environment const & env, expr e);
|
bool is_ceq(ro_environment const & env, optional<ro_metavar_env> const & menv, expr e);
|
||||||
/**
|
/**
|
||||||
\brief Return true iff the lhs is identical to the rhs modulo a
|
\brief Return true iff the lhs is identical to the rhs modulo a
|
||||||
permutation of the conditional equation arguments.
|
permutation of the conditional equation arguments.
|
||||||
|
|
|
@ -7,6 +7,7 @@ Author: Leonardo de Moura
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "util/sstream.h"
|
#include "util/sstream.h"
|
||||||
#include "kernel/kernel.h"
|
#include "kernel/kernel.h"
|
||||||
|
#include "kernel/type_checker.h"
|
||||||
#include "library/equality.h"
|
#include "library/equality.h"
|
||||||
#include "library/simplifier/congr.h"
|
#include "library/simplifier/congr.h"
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ void congr_theorem_info::display(std::ostream & out) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
congr_theorem_info check_congr_theorem(ro_environment const & env, expr const & e) {
|
congr_theorem_info check_congr_theorem(ro_environment const & env, expr const & e) {
|
||||||
expr t = env->infer_type(e);
|
expr t = type_checker(env).infer_type(e);
|
||||||
expr b = t;
|
expr b = t;
|
||||||
unsigned num = 0;
|
unsigned num = 0;
|
||||||
while (is_pi(b)) {
|
while (is_pi(b)) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ function show_ceqs(ceqs)
|
||||||
for i = 1, #ceqs do
|
for i = 1, #ceqs do
|
||||||
print(ceqs[i][1], ceqs[i][2], is_permutation_ceq(ceqs[i][1]))
|
print(ceqs[i][1], ceqs[i][2], is_permutation_ceq(ceqs[i][1]))
|
||||||
env:type_check(ceqs[i][2])
|
env:type_check(ceqs[i][2])
|
||||||
assert(is_ceq(env, ceqs[i][1]))
|
assert(is_ceq(env, nil, ceqs[i][1]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue