feat(frontends/lean/builtin_cmds): use type_context to implement #reduce command

This commit is contained in:
Leonardo de Moura 2018-01-09 16:40:41 -08:00
parent 0c5c1a27c6
commit 60be2bf2aa
5 changed files with 18 additions and 65 deletions

View file

@ -222,13 +222,12 @@ environment reduce_cmd(parser & p) {
expr e; level_param_names ls;
std::tie(e, ls) = parse_local_expr(p, "_reduce");
expr r;
type_context ctx(p.env(), p.get_options(), metavar_context(), local_context(), transparency_mode::All);
if (whnf) {
type_checker tc(p.env(), true, false);
r = tc.whnf(e);
r = ctx.whnf(e);
} else {
type_checker tc(p.env(), true, false);
bool eta = false;
r = normalize(tc, e, eta);
r = normalize(ctx, e, eta);
}
auto out = p.mk_message(p.cmd_pos(), p.pos(), INFORMATION);
out.set_caption("reduce result") << r;

View file

@ -112,7 +112,6 @@ class normalize_fn {
}
expr normalize(expr e) {
// TODO(Leo): smart_reduction doesn't seem to work with normalize
check_system("normalize");
if (!m_pred(e))
return e;

View file

@ -0,0 +1,5 @@
constant n : nat
#reduce n + (nat.succ n)
set_option type_context.smart_unfolding false
#reduce n + (nat.succ n)

View file

@ -0,0 +1,8 @@
nat.succ (nat.add n n)
nat.succ
((nat.rec ⟨λ (a : ), a, punit.star⟩
(λ (n : )
(ih : pprod () (nat.rec punit (λ (n : ) (ih : Type), pprod (pprod () ih) punit) n)),
⟨λ (a : ), nat.succ (ih.fst a), ⟨ih, punit.star⟩⟩)
n).fst
n)

View file

@ -1,62 +1,4 @@
succ
((⟨nat.rec
⟨(λ (a : ) (_F : nat.below (λ (a : ), ) a) (a_1 : ),
(λ (a a_1 : ) (_F : nat.below (λ (a : ), ) a_1),
nat.cases_on a_1 (λ (_F : nat.below (λ (a : ), ) 0), id_rhs a)
(λ (a_1 : ) (_F : nat.below (λ (a : ), ) (succ a_1)),
id_rhs (succ ((_F.fst).fst a)))
_F)
a_1
a
_F)
0
punit.star,
punit.star⟩
(λ (n : ) (ih : pprod ((λ (a : ), ) n) (nat.below (λ (a : ), ) n)),
⟨(λ (a : ) (_F : nat.below (λ (a : ), ) a) (a_1 : ),
(λ (a a_1 : ) (_F : nat.below (λ (a : ), ) a_1),
nat.cases_on a_1 (λ (_F : nat.below (λ (a : ), ) 0), id_rhs a)
(λ (a_1 : ) (_F : nat.below (λ (a : ), ) (succ a_1)),
id_rhs (succ ((_F.fst).fst a)))
_F)
a_1
a
_F)
(succ n)
⟨ih, punit.star⟩,
⟨ih, punit.star⟩⟩)
0,
punit.star⟩.fst).fst
2)
succ (nat.add 2 0)
3
succ
((⟨nat.rec
⟨(λ (a : ) (_F : nat.below (λ (a : ), ) a) (a_1 : ),
(λ (a a_1 : ) (_F : nat.below (λ (a : ), ) a_1),
nat.cases_on a_1 (λ (_F : nat.below (λ (a : ), ) 0), id_rhs a)
(λ (a_1 : ) (_F : nat.below (λ (a : ), ) (succ a_1)),
id_rhs (succ ((_F.fst).fst a)))
_F)
a_1
a
_F)
0
punit.star,
punit.star⟩
(λ (n : ) (ih : pprod ((λ (a : ), ) n) (nat.below (λ (a : ), ) n)),
⟨(λ (a : ) (_F : nat.below (λ (a : ), ) a) (a_1 : ),
(λ (a a_1 : ) (_F : nat.below (λ (a : ), ) a_1),
nat.cases_on a_1 (λ (_F : nat.below (λ (a : ), ) 0), id_rhs a)
(λ (a_1 : ) (_F : nat.below (λ (a : ), ) (succ a_1)),
id_rhs (succ ((_F.fst).fst a)))
_F)
a_1
a
_F)
(succ n)
⟨ih, punit.star⟩,
⟨ih, punit.star⟩⟩)
0,
punit.star⟩.fst).fst
a)
succ (nat.add a 0)
succ a