fix(frontends/lean/builtin_exprs): bug in new 'obtain' expression

This commit is contained in:
Leonardo de Moura 2015-05-06 10:01:24 -07:00
parent 26c662accd
commit 613281d622
2 changed files with 22 additions and 3 deletions

View file

@ -457,6 +457,7 @@ static expr parse_show(parser & p, unsigned, expr const *, pos_info const & pos)
static obtain_struct parse_obtain_decls (parser & p, buffer<expr> & ps) { static obtain_struct parse_obtain_decls (parser & p, buffer<expr> & ps) {
buffer<obtain_struct> children; buffer<obtain_struct> children;
parser::local_scope scope(p);
while (!p.curr_is_token(get_comma_tk()) && !p.curr_is_token(get_rbracket_tk())) { while (!p.curr_is_token(get_comma_tk()) && !p.curr_is_token(get_rbracket_tk())) {
if (p.curr_is_token(get_lbracket_tk())) { if (p.curr_is_token(get_lbracket_tk())) {
p.next(); p.next();
@ -464,11 +465,14 @@ static obtain_struct parse_obtain_decls (parser & p, buffer<expr> & ps) {
children.push_back(s); children.push_back(s);
p.check_token_next(get_rbracket_tk(), "invalid 'obtain' expression, ']' expected"); p.check_token_next(get_rbracket_tk(), "invalid 'obtain' expression, ']' expected");
} else { } else {
unsigned old_sz = ps.size();
unsigned rbp = 0; unsigned rbp = 0;
p.parse_simple_binders(ps, rbp); buffer<expr> new_ps;
for (unsigned i = old_sz; i < ps.size(); i++) p.parse_simple_binders(new_ps, rbp);
for (expr const & l : new_ps) {
ps.push_back(l);
p.add_local(l);
children.push_back(obtain_struct()); children.push_back(obtain_struct());
}
} }
} }
if (children.empty()) if (children.empty())

View file

@ -0,0 +1,15 @@
import data.set
open set function eq.ops
variables {X Y Z : Type}
lemma image_compose (f : Y → X) (g : X → Y) (a : set X) : (f ∘ g) '[a] = f '[g '[a]] :=
setext (take z,
iff.intro
(assume Hz : z ∈ (f ∘ g) '[a],
obtain x (Hx₁ : x ∈ a) (Hx₂ : f (g x) = z), from Hz,
have Hgx : g x ∈ g '[a], from in_image Hx₁ rfl,
show z ∈ f '[g '[a]], from in_image Hgx Hx₂)
(assume Hz : z ∈ f '[g '[a]],
obtain y [x (Hz₁ : x ∈ a) (Hz₂ : g x = y)] (Hy₂ : f y = z), from Hz,
show z ∈ (f ∘ g) '[a], from in_image Hz₁ (Hz₂⁻¹ ▸ Hy₂)))