我如何引用 Isar 中的当前子目标?

How do I refer to the current subgoal in Isar?

我正在尝试解决 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中的证明状态复制过来的。然而,伊莎贝尔报错(在最后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)

现在被注释掉的证明目标导致了同样的错误。如果我将 0Suc 的大小写交换,错误出现在 0 的最后一个 show 中,但不再出现在 Suc 的情况中。

有人可以解释为什么伊莎贝尔会接受 none 这些看似正确的目标吗?我怎样才能以伊莎贝尔接受的方式陈述子目标?是否有一种通用的方式来引用当前的子目标?我认为考虑到我使用的结构,?case 应该可以完成这项工作,但显然它没有。

我发现 Stack Overflow 问题提到了同样的错误,但问题是不同的(定理有一个等价性应该通过隐式应用 rule) 并应用提供的解决方案在我的案例中会导致不正确且无法证明的目标。

你只是在内部归纳证明中遗漏了一个 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