See Section "Other goodies" at https://github.com/leanprover/lean/wiki/Refactoring-structures This commit also improves the support for projections in the unifier/matcher. Now, we consider the extra case-split for projections. Given a projection `proj`, and the constraint `proj s =?= proj t`, we need to try first `s =?= t` and if it fails, then try to reduce. This is needed in the standard library because we now have constraints such as: ``` @has_le.le ?A ?s ?a ?b =?= @has_le.le nat nat.has_add x y ``` If we reduce the right hand side, we get the unsolvable constraint ``` @has_le.le ?A ?s ?a ?b =?= nat.le x y ``` Before this change, the constraint was `@le ?A ?s ?a ?b =?= @le nat nat.has_add x y`, and we already perform a case-split in this case. Moreover, projections were eagerly reduced whenever possible. The extra case-split generates a performance problem in several tests. For example `fib 8 = 34` was timing out. I worked around this issue by performing the case-split only when the constraint contains meta-variables. There are also minor issues. Example. `<` is notation for `has_lt.lt`, but `>` is for `gt`.
30 lines
946 B
Text
30 lines
946 B
Text
universe variables u
|
||
|
||
inductive Vec (α : Type u) : nat → Type (max 1 u)
|
||
| nil : Vec 0
|
||
| cons : ∀ {n}, α → Vec n → Vec (nat.succ n)
|
||
|
||
lemma split {α : Type u} {n : nat} (v : Vec α n) : (v == (Vec.nil α) ∧ n = 0) ∨ ∃ m h (t : Vec α m), v == Vec.cons h t ∧ n = nat.succ m :=
|
||
Vec.cases_on v
|
||
(or.inl ⟨heq.refl _, rfl⟩)
|
||
(λ n h t, or.inr ⟨n, h, t, heq.refl _, rfl⟩)
|
||
|
||
constant f {α : Type u} {n : nat} : Vec α n → nat
|
||
axiom fax1 (α : Type u) : f (Vec.nil α) = 0
|
||
axiom fax2 {α : Type u} {n : nat} (v : Vec α (nat.succ n)) : f v = 1
|
||
|
||
example {α : Type u} {n : nat} (v : Vec α n) : f v ≠ 2 :=
|
||
begin
|
||
destruct v,
|
||
{intros, intro, note h := fax1 α, cc},
|
||
intros n1 h t, intros, intro, note h := fax2 (Vec.cons h t), cc
|
||
end
|
||
|
||
open nat
|
||
example : ∀ n, 0 < n → succ (pred n) = n :=
|
||
begin
|
||
intro n,
|
||
destruct n,
|
||
{dsimp, intros, note h := lt_irrefl 0, cc},
|
||
{intros, subst n, dsimp, reflexivity}
|
||
end
|