我正试图从Programming and Proving in Isabelle解决练习4.7。 我遇到了一个我证明是错误的情况,因此我发现了一切,但我无法结案,因为我不知道如何参考我的证明义务。
theory ProgProveEx47
imports Main
begin
datatype alpha = a | b | c
inductive S :: "alpha list ⇒ bool" where
Nil: "S []" |
Grow: "S xs ⟹ S ([a]@xs@[b])" |
Append: "S xs ⟹ S ys ⟹ S (xs@ys)"
fun balanced :: "nat ⇒ alpha list ⇒ bool" where
"balanced 0 [] = True" |
"balanced (Suc n) (b#xs) = balanced n xs" |
"balanced n (a#xs) = balanced (Suc n) xs" |
"balanced _ _ = False"
lemma
fixes n xs
assumes b: "balanced n xs"
shows "S (replicate n a @ xs)"
proof -
from b show ?thesis
proof (induction xs)
case Nil
hence "S (replicate n a)"
proof (induction n)
case 0
show ?case using S.Nil by simp
case (Suc n)
value ?case
from `balanced (Suc n) []` have False by simp
(* thus "S (replicate (Suc n) a)" by simp *)
(* thus ?case by simp *)
then show "⋀n. (balanced n [] ⟹ S (replicate n a)) ⟹ balanced (Suc n) [] ⟹ S (replicate (Suc n) a)" by simp
最后一个show
之后的命题是从Isabelle / jedit中的证明状态复制而来的。但是,Isabelle报告错误(在最后show
):
Failed to refine any pending goal
Local statement fails to refine any pending goal
Failed attempt to solve goal by exported rule:
(balanced 0 []) ⟹
(balanced ?na3 [] ⟹ S (replicate ?na3 a)) ⟹
(balanced (Suc ?na3) []) ⟹
(balanced ?n [] ⟹ S (replicate ?n a)) ⟹
(balanced (Suc ?n) []) ⟹ S (replicate (Suc ?n) a)
现在注释掉的证明目标导致了同样的错误。如果我更换0
和Suc
的案例,则show
案例的最后0
出现错误,但Suc
案例不再出现错误。
有人可以解释为什么伊莎贝尔会在这里接受这些看似正确的目标吗?我怎样才能以Isabelle接受的方式陈述子目标?是否有一般参考当前的子目标?我认为考虑到我使用的构造,?case
应该做那个工作,但显然它没有。
我发现this Stack Overflow问题提到了相同的错误,但问题有所不同(定理存在一个等价,应该通过{{1}的隐式应用将其拆分为方向子目标在我的情况下,应用提供的解决方案会导致错误和无法实现的目标。
答案 0 :(得分:1)
您只是错过了内部入门证明中的next
。
lemma
fixes n xs
assumes b: "balanced n xs"
shows "S (replicate n a @ xs)"
proof -
from b show ?thesis
proof (induction xs)
case Nil
hence "S (replicate n a)"
proof (induction n)
case 0
show ?case using S.Nil by simp
next (* this next was missing *)
case (Suc n)
show ?case sorry
qed
show ?case sorry
next
case (Cons a xs)
then show ?case sorry
qed