how to make an example to test the rev_app immediately after lemma proved. an starting example for custom lemma

时间:2015-05-12 22:19:49

标签: isabelle

expect to use the subgoal to run the list which defined by let? aa = [1,2] and run rev_app on this aa and show the value as [2,1]

f.input :invoice_file_date, as: :datepicker, 
        :input_html => { :disabled => !current_admin_user.role?(:admin) } if f.object.invoice_file.present?

(1 st trial)

theory Scratch2
imports Datatype
begin
datatype 'a list  = Nil ("[]")
                  | Cons 'a "'a list" (infixr "#" 65)
(* This is the append function: *)
primrec app :: "'a list => 'a list => 'a list" (infixr "@" 65)
where
"[] @ ys = ys" |
"(x # xs) @ ys = x # (xs @ ys)"
primrec rev :: "'a list => 'a list" where
"rev [] = []" |
"rev (x # xs) = (rev xs) @ (x # [])"
primrec itrev :: "'a list => 'a list => 'a list" where
"itrev [] ys = ys" |
"itrev (x#xs) ys = itrev xs (x#ys)"
value "rev (True # False # [])"
lemma app_Nil2 [simp]: "xs @ [] = xs"
apply(induct_tac xs)
apply(auto)
done
lemma app_assoc [simp]: "(xs @ ys) @ zs = xs @ (ys @ zs)"
apply(induct_tac xs)
apply(auto)
done

(2nd trial)

lemma rev_app [simp]: "rev(xs @ ys) = (rev ys) @ (rev xs)"
apply(induct_tac xs)
thus ?aa by rev_app
show "rev_app [1; 2]"

(3 rd trial)

value "rev_app [1,2]"

1 个答案:

答案 0 :(得分:0)

首先,您需要list枚举的语法(我只是在src / HOL / List.thy文件中选择它):

syntax
  -- {* list Enumeration *}
  "_list" :: "args => 'a list"    ("[(_)]")

translations
  "[x, xs]" == "x#[xs]"
  "[x]" == "x#[]"

然后,您正在寻找以下其中一项?

命题1:

lemma example1: "rev [a, b] = [b, a]"
  by simp

这个引理通过应用rev的定义规则来证明,该方法simp用于重写左手术语并证明等式的两个边是相等的。这是我更喜欢的解决方案,因为即使没有使用Isabelle进行评估,您也可以看到示例得到满足。

命题2:

value "rev [a, b]" (* return "[b, a]" *)

在这里和命题3中,我们只使用命令value来评估rev

命题3:

value "rev [a, b] = [b, a]" (* returns "True" *)

以前的命题没有使用这个引理:

lemma rev_app [simp]: "rev(xs @ ys) = (rev ys) @ (rev xs)"
  apply (induct_tac xs)
  by simp_all

注意:

  • 作为一般原则,您不应该导入"数据类型"单独打包,但导入" Main"代替。
  • 在您的第一次尝试中,您将" apply" (申请......)和"结构化证明" (因此......)风格
  • "因此?aa"没有意义,如果"?aa"是" [1,2]"作为"因此"的论点应该是一个子目标,即。具有布尔值的命题。
  • 要评估,命令"值"使用ML执行或如果失败,则通过评估进行标准化。
  • 在example1中,您可以使用自定义证明,从而使用lemmas(例如:by(simp add:rev_app)