0

I have created a small proof with the intention of creating an example for using next on proof cases:

theory RedGreen 

imports Main 

begin 

datatype color = RED | GREEN 

fun green :: "color => color" 
where 
  "green RED   = GREEN" 
| "green GREEN = GREEN" 

lemma disj_not: "P \<or> Q \<Longrightarrow> \<not>P \<longrightarrow> Q" 
proof 
  assume disj: "P \<or> Q" 
  assume "\<not>P" 
  from this show "Q" using `P \<or> Q` by (simp) 
qed   

lemma redgreen: "x \<noteq> RED \<longrightarrow> x = GREEN" 
proof  
  assume notred: "x \<noteq> RED" 
  have "x = RED \<or> x = GREEN" by (simp only: color.nchotomy)  
  from this show "x = GREEN" using notred by (simp add:  disj_not) 
qed 

lemma "green x = GREEN" 
proof cases 
  assume "x = RED" 
  from this show "green x = GREEN" by (simp) 
next 
  assume "x \<noteq> RED" 
  from this have "x = GREEN" by (simp add: redgreen) 
  from this show "green x = GREEN" by (simp) 
qed 

Can this be streamlined without losing the details? Using some magical tricks would not be the thing I wish for. Improving the style of using Isar is welcome.

Gergely
  • 6,879
  • 6
  • 25
  • 35

1 Answers1

2

My experience is that such low-level (and ad-hoc) rules like your disj_not and redgreen are hardly ever useful. If they are really necessary this can most likely be attributed to some lack of automation (via appropriate simp, intro, elim, and dest rules). Gladly, in your example these "intermediate lemmas" are not necessary at all (and I do not think that they are of special educational value). Coming to your question of a streamlined version. I think one canonical way of doing so would be the following:

lemma "green x = GREEN"
proof (cases x)
  case RED
  then show "green x = GREEN" by simp
next
  case GREEN
  then show "green x = GREEN" by simp
qed

Where the automatically generated fact color.exhaust is used for a proof by cases on the variable x of type color.

chris
  • 4,988
  • 20
  • 36
  • 1
    Another stylistic suggestion I would make is that you can say `then show ?thesis by simp`, which avoids some of the duplication. `?thesis` is simply shorthand for the original statement you were trying to prove. – davidg Jul 01 '14 at 00:30
  • 1
    @davidg: you are of course right. For readability (if there are short goals) I sometimes explicitly write show statements. In a real development the above would be proved via `by (cases x) simp_all` anyway ;) – chris Jul 01 '14 at 08:46