我定义了一种树,以及fusion
如下操作:
open nat
inductive tree : Type
| lf : tree
| nd : tree -> nat -> tree -> tree
open tree
def fusion : tree -> tree -> tree
| lf t2 := t2
| (nd l1 x1 r1) lf := (nd l1 x1 r1)
| (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 r1) r2) x2 l2
然后,我有一个计数函数,它返回给定整数在树中出现的次数:
def occ : nat -> tree -> nat
| _ lf := 0
| y (nd g x d) := (occ y g) + (occ y d) + (if x = y then 1 else 0)
我想证明(occ x (fusion t1 t2)) = (occ x t1) + (occ x t2)
,但在证明过程中,我遇到了一个问题,因为我不知道如何处理给定的归纳假设。
到目前为止,我已经想到了这个:
theorem q5 : ∀ (x : ℕ) (t1 t2 : tree),
(occ x (fusion t1 t2)) = (occ x t1) + (occ x t2) :=
begin
intros x t1 t2,
induction t1 with g1 x1 d1 _ ih1,
simp [fusion, occ],
induction t2 with g2 x2 d2 _ ih2,
simp [fusion, occ],
by_cases x1 <= x2,
simp [fusion, h, occ],
rw ih1,
simp [occ, fusion, h],
simp [occ, fusion, h],
end
但我拼命地卡住了。ih 处理fusion d1 (nd g2 x2 d2))
我想要的东西fusion (nd g1 x1 d1) d2
。
我很乐意欢迎任何建议。