feat(frontends/lean): apply eta-reduction in postprocessing step

Perhaps, we should add an option to disable this new feature.

Remark: this commit makes commit 46d418a redundant.
I'm keeping 46d418a because we may retract this commit in the future.
This commit is contained in:
Leonardo de Moura 2015-06-10 16:26:32 -07:00
parent f64784378a
commit 8b7dc4e03a
33 changed files with 77 additions and 103 deletions

View file

@ -72,16 +72,20 @@ namespace category
ua !equiv_equiv_iso
definition is_univalent_hset (A B : Precategory_hset) : is_equiv (iso_of_eq : A = B → A ≅ B) :=
have H : is_equiv (@iso_of_equiv A B ∘ @equiv_of_eq A B ∘ subtype_eq_inv _ _ ∘
@ap _ _ (to_fun (trunctype.sigma_char 0)) A B), from
@is_equiv_compose _ _ _ _ _
assert H₁ : is_equiv (@iso_of_equiv A B ∘ @equiv_of_eq A B ∘ subtype_eq_inv _ _ ∘
@ap _ _ (to_fun (trunctype.sigma_char 0)) A B), from
@is_equiv_compose _ _ _ _ _
(@is_equiv_compose _ _ _ _ _
(@is_equiv_compose _ _ _ _ _
_
(@is_equiv_subtype_eq_inv _ _ _ _ _))
!univalence)
!is_equiv_iso_of_equiv,
(iso_of_eq_eq_compose A B)⁻¹ ▸ H
(@is_equiv_compose _ _ _ _ _
_
(@is_equiv_subtype_eq_inv _ _ _ _ _))
!univalence)
!is_equiv_iso_of_equiv,
assert H₂ : _, from (iso_of_eq_eq_compose A B)⁻¹,
begin
rewrite H₂ at H₁,
assumption
end
end set
definition category_hset [instance] : category hset :=

View file

@ -213,7 +213,7 @@ namespace circle
{ exact idp},
{ intros n p,
apply transport (λ(y : base = base), transport circle.code y _ = _), apply power_con,
rewrite [▸*,con_tr, transport_code_loop, ↑[circle.encode,circle.code] at p, p]},
rewrite [▸*,con_tr, transport_code_loop, ↑[circle.encode,circle.code] at p], krewrite p},
{ intros n p,
apply transport (λ(y : base = base), transport circle.code y _ = _),
{ exact !power_con_inv ⬝ ap (power loop) !neg_succ⁻¹},

View file

@ -15,6 +15,7 @@ Author: Leonardo de Moura
#include "library/locals.h"
#include "library/explicit.h"
#include "library/aliases.h"
#include "library/normalize.h"
#include "library/placeholder.h"
#include "library/abbreviation.h"
#include "library/unfold_macros.h"
@ -450,6 +451,6 @@ char const * close_binder_string(binder_info const & bi, bool unicode) {
}
expr postprocess(environment const & env, expr const & e) {
return expand_abbreviations(env, unfold_untrusted_macros(env, e));
return eta_reduce(expand_abbreviations(env, unfold_untrusted_macros(env, e)));
}
}

View file

@ -220,6 +220,10 @@ expr beta_reduce(expr t) {
return eta_beta_reduce_fn<false, true>()(t);
}
expr eta_reduce(expr t) {
return eta_beta_reduce_fn<true, false>()(t);
}
expr beta_eta_reduce(expr t) {
return eta_beta_reduce_fn<true, true>()(t);
}

View file

@ -62,6 +62,7 @@ optional<unsigned> has_constructor_hint(environment const & env, name const & d)
expr try_eta(expr const & e);
expr beta_reduce(expr t);
expr eta_reduce(expr t);
expr beta_eta_reduce(expr t);
void initialize_normalize();

View file

@ -37,4 +37,4 @@ rinv : func ∘ finv = function.id
550.lean:43:2: error: failed to add declaration 'bijection.inv.linv' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (f : …),
bijection.rec_on f (λ (func finv : …) (linv : …) (rinv : …), ?M_1)
bijection.rec_on f ?M_1

View file

@ -9,5 +9,4 @@ H : ∃ (n : ), P n
571.lean:7:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (P : …) (H : …),
?M_1
?M_1

View file

@ -11,5 +11,4 @@ P : f a⁻¹ * f a = 1
583.lean:27:8: error: failed to add declaration 'group_hom.hom_map_inv' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (B : Type) (s1 : …) (s2 : …) (f : …) (Hom : …) (a : A),
assert P : …, from …,
?M_1
?M_1 …

View file

@ -1,9 +1,9 @@
definition category.id [reducible] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a
λ (ob : Type) (C : precategory ob) (a : ob), ID a
ID
definition function.id [reducible] : Π {A : Type}, A → A
λ (A : Type) (a : A), a
-----------
definition category.id [reducible] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a
λ (ob : Type) (C : precategory ob) (a : ob), ID a
ID
definition function.id [reducible] : Π {A : Type}, A → A
λ (A : Type) (a : A), a

View file

@ -3,5 +3,4 @@ C : Precategory
⊢ C = Precategory.mk (carrier C) C
abbrev_paren.hlean:5:54: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (C : Precategory),
?M_1
?M_1

View file

@ -10,5 +10,4 @@ a b : Prop
⊢ a ∧ b
apply_fail.lean:4:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b : Prop),
?M_1
?M_1

View file

@ -9,8 +9,7 @@ H : b ∧ a
⊢ a ∧ b
assert_fail.lean:4:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b : Prop) (H : …),
?M_1
?M_1
assert_fail.lean:9:2: error:invalid tactic, there are no goals to be solved
proof state:
no goals
@ -20,5 +19,4 @@ Ha : a
⊢ a
assert_fail.lean:10:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a : Prop) (Ha : a),
?M_1
?M_1

View file

@ -22,5 +22,4 @@ Hbc : b = c
⊢ a = c
beginend_bug.lean:9:0: error: failed to add declaration 'foo' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (a b c : A) (Hab : …) (Hbc : …),
?M_1
?M_1

View file

@ -30,5 +30,4 @@ s : square t b l r
⊢ unit
cases_failure.hlean:13:0: error: failed to add declaration 'foo' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (x y z : A) (t : …) (b : …) (l : …) (r : …) (s : …),
?M_1
?M_1

View file

@ -6,5 +6,4 @@ a b : A
⊢ list A
check_expr.lean:8:0: error: failed to add declaration 'foo' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (l : …),
?M_1
?M_1

View file

@ -19,8 +19,7 @@ a b : Prop
⊢ a → b → a ∧ b
constr_tac_errors.lean:13:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b : Prop),
?M_1
?M_1
constr_tac_errors.lean:18:2: error:invalid 'constructor' tactic, goal is an inductive datatype, but it does not have 2 constructor(s)
proof state:
a b : Prop,
@ -32,8 +31,7 @@ a b : Prop
⊢ a → b → a ∧ b
constr_tac_errors.lean:19:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b : Prop),
?M_1
?M_1
constr_tac_errors.lean:31:2: error:invalid 'constructor' tactic, too many arguments have been provided
proof state:
a b : Prop,
@ -45,8 +43,7 @@ a b : Prop
⊢ a → b → unit
constr_tac_errors.lean:32:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b : Prop),
?M_1
?M_1
constr_tac_errors.lean:39:2: error:invalid 'constructor' tactic, goal is not an inductive datatype
proof state:

View file

@ -1,9 +1,9 @@
crash.lean:8:12: error: type mismatch at application
have H' : ¬ P, from H,
have H' : ¬P, from H,
?M_1
term
H
has type
P
but is expected to have type
¬ P
¬P

View file

@ -7,5 +7,4 @@ p1 p2 : A × B
⊢ nat
ctx.lean:3:0: error: failed to add declaration 'foo' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A B : Type) (a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 : nat) (b1 b2 b3 : bool) (h : …) (p1 p2 : …),
?M_1
?M_1

View file

@ -20,5 +20,4 @@ a b : Prop
⊢ a → b → a ∧ b
exact_partial.lean:5:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b : Prop),
?M_1
?M_1

View file

@ -17,5 +17,4 @@ h₂ : b = c
⊢ a = c
exact_partial2.lean:4:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b c : nat) (h₁ : …) (h₂ : …),
?M_1
?M_1

View file

@ -13,61 +13,49 @@ A : Type,
h : decidable_eq A,
P : finset A → Prop,
H1 : P (@empty A),
H2 : ∀ ⦃s : finset A⦄ {a : A}, not (@mem A a s) → P s → P (@insert A (λ (a b : A), h a b) a s),
H2 : ∀ ⦃s : finset A⦄ {a : A}, not (@mem A a s) → P s → P (@insert A h a s),
s : finset A,
u : nodup_list A,
l : list A,
a : A,
l' : list A,
IH :
∀ (x : @nodup A l'),
P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (λ (l : list A), @nodup A l) l' x)),
IH : ∀ (x : @nodup A l'), P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (@nodup A) l' x)),
nodup_al' : @nodup A (@cons A a l'),
anl' : not (@list.mem A a l'),
H3 : @eq (list A) (@list.insert A (λ (a b : A), h a b) a l') (@cons A a l'),
nodup_l' : @nodup A l',
P_l' :
P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (λ (l : list A), @nodup A l) l' nodup_l')),
P_l' : P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (@nodup A) l' nodup_l')),
H4 :
P
(@insert A (λ (a b : A), h a b) a
(@quot.mk (nodup_list A) (nodup_list_setoid A)
(@subtype.tag (list A) (λ (l : list A), @nodup A l) l' nodup_l')))
⊢ P
(@quot.mk (nodup_list A) (nodup_list_setoid A)
(@subtype.tag (list A) (λ (l : list A), @nodup A l) (@cons A a l') nodup_al'))
(@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (@nodup A) l' nodup_l')))
⊢ P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (@nodup A) (@cons A a l') nodup_al'))
finset_induction_bug.lean:30:45: error: don't know how to synthesize placeholder
A : Type,
h : decidable_eq A,
P : finset A → Prop,
H1 : P (@empty A),
H2 : ∀ ⦃s : finset A⦄ {a : A}, not (@mem A a s) → P s → P (@insert A (λ (a b : A), h a b) a s),
H2 : ∀ ⦃s : finset A⦄ {a : A}, not (@mem A a s) → P s → P (@insert A h a s),
s : finset A,
u : nodup_list A,
l : list A,
a : A,
l' : list A,
IH :
∀ (x : @nodup A l'),
P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (λ (l : list A), @nodup A l) l' x)),
IH : ∀ (x : @nodup A l'), P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (@nodup A) l' x)),
nodup_al' : @nodup A (@cons A a l'),
anl' : not (@list.mem A a l'),
H3 : @eq (list A) (@list.insert A (λ (a b : A), h a b) a l') (@cons A a l'),
nodup_l' : @nodup A l',
P_l' :
P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (λ (l : list A), @nodup A l) l' nodup_l')),
P_l' : P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (@nodup A) l' nodup_l')),
H4 :
P
(@insert A (λ (a b : A), h a b) a
(@quot.mk (nodup_list A) (nodup_list_setoid A)
(@subtype.tag (list A) (λ (l : list A), @nodup A l) l' nodup_l')))
⊢ P
(@quot.mk (nodup_list A) (nodup_list_setoid A)
(@subtype.tag (list A) (λ (l : list A), @nodup A l) (@cons A a l') nodup_al'))
(@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (@nodup A) l' nodup_l')))
⊢ P (@quot.mk (nodup_list A) (nodup_list_setoid A) (@subtype.tag (list A) (@nodup A) (@cons A a l') nodup_al'))
finset_induction_bug.lean:16:5: error: failed to add declaration 'finset.induction₂' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (h : …) (P : …) (H1 : …) (H2 : …) (s : …),
@quot.induction_on … … s
@quot.induction_on … … P s
(λ (u : …),
@subtype.destruct … … … u
(λ (l : …),
@ -77,6 +65,5 @@ remark: set 'formatter.hide_full_terms' to false to see the complete term
assert H3 : …, from …,
assert nodup_l' : …, from …,
assert P_l' : …, from …,
assert H4 : …, from …,
?M_1)))
?M_1 …)))
finset_induction_bug.lean:30:49: error: invalid end of module, expecting 'end'

View file

@ -20,5 +20,4 @@ b : B
⊢ @heq A a B b → @heq B b A a
gen_bug.lean:12:0: error: failed to add declaration 'tst' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A B : Type) (a : A) (b : B),
?M_1
?M_1

View file

@ -17,5 +17,4 @@ v : vector n
⊢ v = v
gen_fail.lean:7:0: error: failed to add declaration 'tst' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (n : ) (v : …),
?M_1
?M_1

View file

@ -6,5 +6,4 @@ Hbc : eq b c
⊢ eq b c
goals1.lean:9:0: error: failed to add declaration 'foo' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (a b c : A) (Hab : …) (Hbc : …),
?M_1
?M_1

View file

@ -6,5 +6,4 @@ a : A
⊢ P (vone a)
inv_del.lean:15:2: error: failed to add declaration 'vec.eone' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (P : …) (H : …) (v : …),
?M_1
?M_1

View file

@ -1,2 +1,2 @@
em : ∀ (a : Prop), a ¬a
strong_indefinite_description : Π {A : Type} (P : A → Prop), nonempty A → { (x : A)| (∃ (y : A), P y) → P x}
strong_indefinite_description : Π {A : Type} (P : A → Prop), nonempty A → { (x : A)| Exists P → P x}

View file

@ -11,8 +11,7 @@ H : f a = a
⊢ g a = a
quasireducible.lean:11:3: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a : nat) (H : …),
?M_1
?M_1
quasireducible.lean:16:11: error:invalid 'rewrite' tactic, rewrite step failed using pattern
f a
no subterm in the goal matched the pattern
@ -26,5 +25,4 @@ H : f a = a
⊢ g a = a
quasireducible.lean:16:3: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a : nat) (H : …),
?M_1
?M_1

View file

@ -11,8 +11,7 @@ v : vector A n
⊢ v = v
revert_fail.lean:6:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (A : Type) (n : nat) (v : …),
?M_1
?M_1
revert_fail.lean:11:2: error:invalid tactic, there are no goals to be solved
proof state:
no goals
@ -21,8 +20,7 @@ n : nat
⊢ n = n
revert_fail.lean:12:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (n : nat),
?M_1
?M_1
revert_fail.lean:16:2: error:invalid 'revert' tactic, unknown hypothesis 'm'
proof state:
n : nat
@ -32,5 +30,4 @@ n : nat
⊢ n = n
revert_fail.lean:17:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (n : nat),
?M_1
?M_1

View file

@ -13,8 +13,7 @@ Hb : b = 0
⊢ a + b = 0
rewrite_fail.lean:6:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b : ) (Ha : …) (Hb : …),
?M_1
?M_1
rewrite_fail.lean:11:2: error:invalid tactic, there are no goals to be solved
proof state:
no goals
@ -23,5 +22,4 @@ a :
⊢ a = a
rewrite_fail.lean:12:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a : ),
?M_1
?M_1

View file

@ -12,10 +12,16 @@ if [ $# -ne 2 ]; then
else
INTERACTIVE=$2
fi
NUM_ERRORS=0
for f in *.lean; do
echo "-- testing $f"
"$LEAN" -t config.lean "$f" &> "$f.produced.out.1"
if [ ${f: -6} == ".hlean" ]; then
CONFIG="config.hlean"
else
CONFIG="config.lean"
fi
"$LEAN" -t $CONFIG "$f" &> "$f.produced.out.1"
sed "/warning: imported file uses 'sorry'/d" "$f.produced.out.1" > "$f.produced.out"
rm -f -- "$f.produced.out.1"
if test -f "$f.expected.out"; then

View file

@ -17,8 +17,7 @@ H₂ : b = c
⊢ a = c
unsolved_proof_qed.lean:2:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b c : nat) (H₁ : …) (H₂ : …),
?M_1
?M_1
unsolved_proof_qed.lean:5:33: error: don't know how to synthesize placeholder
a b c : nat,
H₁ : a = b,
@ -39,5 +38,4 @@ H₂ : b = c
unsolved_proof_qed.lean:5:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b c : nat) (H₁ : …) (H₂ : …),
have aux : …, from ?M_1,
… ?M_1

View file

@ -9,5 +9,4 @@ h : a ∧ b
⊢ a
user_rec_crash.lean:4:0: error: failed to add declaration 'example' to environment, value has metavariables
remark: set 'formatter.hide_full_terms' to false to see the complete term
λ (a b : Prop) (h : …),
?M_1
?M_1

View file

@ -1,4 +1,4 @@
succ (nat.rec 2 (λ (b₁ r : ), succ r) 0)
succ (nat.rec 2 (λ (b₁ : ), succ) 0)
3
succ (nat.rec a (λ (b₁ r : ), succ r) 0)
succ (nat.rec a (λ (b₁ : ), succ) 0)
succ a