Isabelle 关于解析器组合子的一个定理的证明

Isabelle 关于解析器组合子的一个定理的证明,isabelle,Isabelle,我已经编写了一些简单的解析器组合器(没有回溯等)。以下是我的问题的重要定义 type_synonym ('a, 's) parser = "'s list ⇒ ('a * 's list) option" definition sequenceP :: "('a, 's) parser ⇒ ('b, 's) parser ⇒ ('b, 's) parser" (infixl ">>P" 60

我已经编写了一些简单的解析器组合器(没有回溯等)。以下是我的问题的重要定义

type_synonym ('a, 's) parser = "'s list ⇒ ('a * 's list) option"

definition sequenceP :: "('a, 's) parser
                       ⇒ ('b, 's) parser
                       ⇒ ('b, 's) parser" (infixl ">>P" 60) where
  "sequenceP p q ≡ λ i . 
    (case p i of
        None ⇒ None
      | Some v ⇒ q (snd v))"

definition consumerP :: "('a, 's) parser ⇒ bool" where
  "consumerP p ≡ (∀ i . (case p i of 
    None ⇒ True |
    Some v ⇒ length (snd v) ≤ length i))"
我想证明下面的引理

lemma consumerPI: "consumerP p ⟹ consumerP q ⟹ consumerP (p >>P q)"
apply (unfold sequenceP_def)
apply (simp (no_asm) add:consumerP_def)
apply clarsimp
apply (case_tac "case p i of None ⇒ None | Some v ⇒ q (snd v)")
apply simp
apply clarsimp
apply (case_tac "p i")
apply simp
apply clarsimp
apply (unfold consumerP_def)
我到达这种证明状态,在这种状态下我无法继续

goal (1 subgoal):
 1. ⋀i a b aa ba.
       ⟦∀i. case p i of None ⇒ True | Some v ⇒ length (snd v) ≤ length i;
        ∀i. case q i of None ⇒ True | Some v ⇒ length (snd v) ≤ length i; q ba = Some (a, b); p i = Some (aa, ba)⟧
       ⟹ length b ≤ length i
有谁能给我一个如何解决这个目标的建议吗?
提前谢谢

事实证明,如果你只是想证明引理,而没有进一步的洞察,那么

lemma consumerPI: "consumerP p ⟹ consumerP q ⟹ consumerP (p >>P q)"
by (smt consumerP_def le_trans option.case_eq_if sequenceP_def)
他做这项工作

如果你想有洞察力,你需要一个结构化的证明。首先确定一些关于
consumerP
的有用引理,然后编写一个Isar证明,详细说明必要的步骤

lemma consumerPI[intro!]:
  assumes "⋀ i x r . p i = Some (x,r) ⟹ length r ≤ length i"
  shows "consumerP p"
 unfolding consumerP_def by (auto split: option.split elim: assms)

lemma consumerPE[elim, consumes 1]:
  assumes "consumerP p"
  assumes "p i = Some (x,r)"
  shows "length r ≤ length i"
  using assms by (auto simp add: consumerP_def split: option.split_asm)

lemma consumerP_sequencePI: "consumerP p ⟹ consumerP q ⟹ consumerP (p >>P q)"
proof-
  assume "consumerP p"
  assume "consumerP q"
  show "consumerP (p >>P q)"
  proof(rule consumerPI)
    fix i x r
    assume "(p >>P q) i = Some (x, r)"
    then obtain x' r' where "p i = Some (x', r')" and "q r' = Some (x,r)"
      by (auto simp add: sequenceP_def split:option.split_asm)

    from `consumerP q` and `q r' = Some (x, r)`
    have "length r ≤ length r'" by (rule consumerPE)
    also
    from `consumerP p` and `p i = Some (x', r')`
    have "length r' ≤ length i" by (rule consumerPE)
    finally
    show "length r ≤ length i".
  qed
qed
事实上,对于这个定义,您可以很好地使用
inclusive
命令,免费获取intro和elim规则:

inductive consumerP where
  consumerPI: "(⋀ i x r . p i = Some (x,r) ⟹ length r ≤ length i) ⟹ consumerP p"

在上面的证明中,你可以用(rule consumerPE)替换
,用
替换成cases
,它是有效的。

结果表明,如果你只是想证明引理,而不需要进一步的洞察,那么

lemma consumerPI: "consumerP p ⟹ consumerP q ⟹ consumerP (p >>P q)"
by (smt consumerP_def le_trans option.case_eq_if sequenceP_def)
他做这项工作

如果你想有洞察力,你需要一个结构化的证明。首先确定一些关于
consumerP
的有用引理,然后编写一个Isar证明,详细说明必要的步骤

lemma consumerPI[intro!]:
  assumes "⋀ i x r . p i = Some (x,r) ⟹ length r ≤ length i"
  shows "consumerP p"
 unfolding consumerP_def by (auto split: option.split elim: assms)

lemma consumerPE[elim, consumes 1]:
  assumes "consumerP p"
  assumes "p i = Some (x,r)"
  shows "length r ≤ length i"
  using assms by (auto simp add: consumerP_def split: option.split_asm)

lemma consumerP_sequencePI: "consumerP p ⟹ consumerP q ⟹ consumerP (p >>P q)"
proof-
  assume "consumerP p"
  assume "consumerP q"
  show "consumerP (p >>P q)"
  proof(rule consumerPI)
    fix i x r
    assume "(p >>P q) i = Some (x, r)"
    then obtain x' r' where "p i = Some (x', r')" and "q r' = Some (x,r)"
      by (auto simp add: sequenceP_def split:option.split_asm)

    from `consumerP q` and `q r' = Some (x, r)`
    have "length r ≤ length r'" by (rule consumerPE)
    also
    from `consumerP p` and `p i = Some (x', r')`
    have "length r' ≤ length i" by (rule consumerPE)
    finally
    show "length r ≤ length i".
  qed
qed
事实上,对于这个定义,您可以很好地使用
inclusive
命令,免费获取intro和elim规则:

inductive consumerP where
  consumerPI: "(⋀ i x r . p i = Some (x,r) ⟹ length r ≤ length i) ⟹ consumerP p"

在上面的证明中,你可以用(rule consumerPE)
替换
,用
替换为cases
,它是有效的。

只是检查一下:你仔细阅读了目标了吗?你确信这确实是一个可证明的定理吗?另外,您是否尝试过运行
sledgehammer
如果这可以解决问题,我不会感到惊讶。只是检查一下:您是否仔细阅读了目标,并且您确信它确实是一个可证明的定理?另外,你试过运行
大锤吗
如果能解决这个问题,我不会感到惊讶。非常感谢。第一个证据看起来像是通过大锤获得的?你是怎么做到的,因为对我来说,sledgehammer超时了。没什么特别的,只是键入了
sledgehammer
,然后等待。如果你增加超时时间,你会得到它吗?是的,当设置超时时间为80秒时,我会得到一个结果。你能推荐一些超时时间吗?经验表明,如果sledgehammer没有找到证据,它在合理的时间内找不到证据?我只使用默认值,但我使用
sledgehammer
命令,而不是面板(其超时时间可能较短)。当然,这取决于你的机器。非常感谢。第一个证据看起来像是通过sledgehammer获得的?你是如何做到的,因为对于我来说sledgehammer超时了。没有什么特别的,只是键入
sledgehammer
并等待。如果你增加超时时间,你会得到吗?是的,当设置超时时间为80秒时,我会得到一个结果。你可以吗您建议一些超时,经验表明,如果sledgehammer没有找到证据,它在合理的时间内找不到证据?我只使用默认值,但我使用
sledgehammer
命令,而不是面板(可能有较短的超时时间)。当然,这取决于您的机器。