0

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]

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

(1 st 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]"

(2nd trial)

value "rev_app [1,2]"

(3 rd trial)

fun ff :: "'a list ⇒ 'a list" 
where "rev(xs @ ys) = (rev ys) @ (rev xs)"
value "ff [1,2]"
thus ?aa by rev_app
show "rev_app [1; 2]"

end
Ho Yeung Lee
  • 453
  • 1
  • 3
  • 14
  • Can you make your question more precise? Do you want to know how to prove the `rev_app` lemma, or are you searching for an example where the `rev_app` lemma could be used? What precisely are your problems in the 3 attempts you showed? – Peter Zeller May 13 '15 at 13:09

1 Answers1

0

Firstly, you need the syntax for list enumeration (I just picked it up in the src/HOL/List.thy file):

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

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

Then, is one of the following what you're searching for ?

Proposition 1:

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

This lemma is proved by applying the definition rules of rev that are used by the method simp to rewrite the left-hand term and prove that the two sides of the equality are equal. This is the solution I prefer because you can see the example is satisfied even without evaluating it with Isabelle.

Proposition 2:

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

Here and in Proposition 3, we just uses the command value to evaluate rev.

Proposition 3:

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

This lemma is not used by the previous propositions:

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

Notes:

  • As a general principle, you shouldn't import the "Datatype" package alone, but import "Main" instead.
  • In your 1st attempt you're mixing the "apply" (apply ...) and the "structured proof" (thus ...) styles
  • "thus ?aa" makes no sense if "?aa" is "[1,2]" as the argument of "thus" should be a subgoal, ie. a proposition with a boolean value.
  • To evaluate, the command "value" uses ML execution or if this fails, normalisation by evaluation.
  • In example1, you can use a custom proof and thus lemmas (for example: by (simp add:rev_app)
Mathieu
  • 726
  • 3
  • 11
  • No, not i am searching for. rev is the default function, if there is a new lemma not exist in default libraries, for example, a custom lemma, how can i use this custom lemma on list? – Ho Yeung Lee May 16 '15 at 00:07
  • When you import only Datatype, and create your own list type, you don't have the syntax for list enumeration. Furthermore, you can't even use the syntax for natural numbers ! I'll modify my answer to take this into account. – Mathieu May 17 '15 at 21:39
  • how do you know the rev in value is using the rev in above lemma, and not the default rev? i remove syntax and translation, rev has error, it seems your code is really use the above lemma, but why the name is not rev_app, does it mean that i have to use the rev in the content of lemma rev_app – Ho Yeung Lee May 27 '15 at 02:43
  • I modified my answer to be clearer. I didn't import `List.thy` in my theory (even though I didn't mentioned it), then `rev` can only be the one you defined. If List was imported however, the last defined and not hidden would be used. On the other hand, `rev_app` is only the name of the lemma, and is not a function like in Coq. You could instantiate it with rev_app[where xs="a" and ys="b"] but in that case, "a" and "b" should be defined somewhere. – Mathieu May 27 '15 at 14:44
  • i feel syntax and translation are so expert, if i do not have list to prove and have math or logic to be proved, what would syntax and translation be? – Ho Yeung Lee May 30 '15 at 21:59
  • Syntax and translation are in fact quite simple and natural once you know how it works ;-), and it is well explained in the manuals (Isar reference I think). But it is not necessary at all to use it as it is only syntax, but it is so natural for list... For example: `rev [a, b]` can be written `rev (a#b#[])` or even `rev (Cons a (Cons b Nil))` – Mathieu Jun 01 '15 at 18:00