Add simplification to add_lift

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-09-17 03:14:02 -07:00
parent 99e8d2feae
commit a26c7d47f2
2 changed files with 22 additions and 3 deletions

View file

@ -119,9 +119,16 @@ expr instantiate_metavars(expr const & e, metavar_env const & env) {
} }
meta_ctx add_lift(meta_ctx const & ctx, unsigned s, unsigned n) { meta_ctx add_lift(meta_ctx const & ctx, unsigned s, unsigned n) {
if (n == 0) if (n == 0) {
return ctx; return ctx;
else } else if (ctx) {
meta_entry e = head(ctx);
// Simplification rule
// lift:(s1+n1):n2 lift:s1:n1 ---> lift:s1:n1+n2
if (e.is_lift() && s == e.s() + e.n()) {
return add_lift(tail(ctx), e.s(), e.n() + n);
}
}
return cons(mk_lift(s, n), ctx); return cons(mk_lift(s, n), ctx);
} }

View file

@ -432,6 +432,17 @@ static void tst20() {
std::cout << norm(F, ctx) << "\n"; std::cout << norm(F, ctx) << "\n";
} }
static void tst21() {
metavar_env menv;
expr m1 = menv.mk_metavar();
lean_assert(add_lift(add_lift(m1, 0, 1), 1, 1) ==
add_lift(m1, 0, 2));
lean_assert(add_lift(add_lift(m1, 1, 2), 3, 4) ==
add_lift(m1, 1, 6));
lean_assert(add_lift(add_lift(m1, 1, 3), 3, 4) !=
add_lift(m1, 1, 7));
}
int main() { int main() {
tst1(); tst1();
tst2(); tst2();
@ -453,5 +464,6 @@ int main() {
tst18(); tst18();
tst19(); tst19();
tst20(); tst20();
tst21();
return has_violations() ? 1 : 0; return has_violations() ? 1 : 0;
} }