为了在 Lean 中定义倾斜堆并证明一些结果,我定义了一种树类型以及一个融合操作:
inductive tree : Type
| lf : tree
| nd : tree -> nat -> tree -> tree
def fusion : tree -> tree -> tree
| lf t2 := t2
| t1 lf := t1
| (nd l1 x1 r1) (nd l2 x2 r2) :=
if x1 <= x2
then nd (fusion r1 (nd l2 x2 r2)) x1 l1
else nd (fusion (nd l1 x1 l1) r2) x2 l2
然后,即使是非常简单的结果,例如
theorem fusion_lf : ∀ (t : tree), fusion lf t = t := sorry
我被困住了。我真的不知道开始写这个证明。如果我这样开始:
begin
intro t,
induction t with g x d,
refl,
end
我可以refl
用于 where t
is的情况lf
,但如果它是 a 则不能nd
。
我有点迷茫,因为在阿格达,这真的很容易。如果我定义这个:
data tree : Set where
lf : tree
nd : tree -> ℕ -> tree -> tree
fusion : tree -> tree -> tree
fusion lf t2 = t2
fusion t1 lf = t1
fusion (nd l1 x1 r1) (nd l2 x2 r2) with x1 ≤? x2
... | yes _ = nd (fusion r1 (nd l2 x2 r2)) x1 l1
... | no _ = nd (fusion (nd l1 x1 r1) r2) x2 l2
那么前面的结果直接用 a 得到refl
:
fusion_lf : ∀ t -> fusion lf t ≡ t
fusion_lf t = refl
我错过了什么?