doc-src/TutorialI/Rules/Basic.thy
changeset 10957 2a4a50e7ddf2
parent 10843 f2e4e383dbca
child 11080 22855d091249
equal deleted inserted replaced
10956:1db8b894ada0 10957:2a4a50e7ddf2
    34 apply (drule mp)
    34 apply (drule mp)
    35   apply assumption
    35   apply assumption
    36  apply assumption
    36  apply assumption
    37 done
    37 done
    38 
    38 
    39 text {*NEW
    39 text {*
    40 by eliminates uses of assumption and done
    40 by eliminates uses of assumption and done
    41 *}
    41 *}
    42 
    42 
    43 lemma imp_uncurry: "P \<longrightarrow> Q \<longrightarrow> R \<Longrightarrow> P \<and> Q \<longrightarrow> R"
    43 lemma imp_uncurry: "P \<longrightarrow> Q \<longrightarrow> R \<Longrightarrow> P \<and> Q \<longrightarrow> R"
    44 apply (rule impI)
    44 apply (rule impI)
    61 text {*
    61 text {*
    62 also provable by simp (re-orients)
    62 also provable by simp (re-orients)
    63 *};
    63 *};
    64 
    64 
    65 lemma "\<lbrakk> x = f x; P (f x) (f x) x \<rbrakk> \<Longrightarrow> P x x x"
    65 lemma "\<lbrakk> x = f x; P (f x) (f x) x \<rbrakk> \<Longrightarrow> P x x x"
    66 apply (erule ssubst)
    66 apply (erule ssubst) 
    67 back
    67   --{* @{subgoals[display,indent=0,margin=65]} *}
    68 back
    68 back --{* @{subgoals[display,indent=0,margin=65]} *}
    69 back
    69 back --{* @{subgoals[display,indent=0,margin=65]} *}
    70 back
    70 back --{* @{subgoals[display,indent=0,margin=65]} *}
    71 apply assumption
    71 back --{* @{subgoals[display,indent=0,margin=65]} *}
    72 done
    72 apply assumption
    73 
    73 done
    74 text {*
       
    75 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ \isadigit{1}\isanewline
       
    76 \isanewline
       
    77 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
    78 {\isasymlbrakk}x\ {\isacharequal}\ f\ x{\isacharsemicolon}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ x\ x\ x\isanewline
       
    79 \ \isadigit{1}{\isachardot}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}
       
    80 
       
    81 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ \isadigit{1}\isanewline
       
    82 \isanewline
       
    83 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
    84 {\isasymlbrakk}x\ {\isacharequal}\ f\ x{\isacharsemicolon}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ x\ x\ x\isanewline
       
    85 \ \isadigit{1}{\isachardot}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x\ {\isasymLongrightarrow}\ P\ x\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}
       
    86 
       
    87 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ \isadigit{1}\isanewline
       
    88 \isanewline
       
    89 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
    90 {\isasymlbrakk}x\ {\isacharequal}\ f\ x{\isacharsemicolon}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ x\ x\ x\isanewline
       
    91 \ \isadigit{1}{\isachardot}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ x\ {\isacharparenleft}f\ x{\isacharparenright}
       
    92 
       
    93 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ \isadigit{1}\isanewline
       
    94 \isanewline
       
    95 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
    96 {\isasymlbrakk}x\ {\isacharequal}\ f\ x{\isacharsemicolon}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ x\ x\ x\isanewline
       
    97 \ \isadigit{1}{\isachardot}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x\ {\isasymLongrightarrow}\ P\ x\ x\ {\isacharparenleft}f\ x{\isacharparenright}
       
    98 
       
    99 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ \isadigit{1}\isanewline
       
   100 \isanewline
       
   101 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
   102 {\isasymlbrakk}x\ {\isacharequal}\ f\ x{\isacharsemicolon}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ x\ x\ x\isanewline
       
   103 \ \isadigit{1}{\isachardot}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharparenleft}f\ x{\isacharparenright}\ x
       
   104 *};
       
   105 
    74 
   106 lemma "\<lbrakk> x = f x; P (f x) (f x) x \<rbrakk> \<Longrightarrow> P x x x"
    75 lemma "\<lbrakk> x = f x; P (f x) (f x) x \<rbrakk> \<Longrightarrow> P x x x"
   107 apply (erule ssubst, assumption)
    76 apply (erule ssubst, assumption)
   108 done
    77 done
   109 
    78 
   110 text{*
    79 text{*
   111 or better still NEW
    80 or better still 
   112 *}
    81 *}
   113 
    82 
   114 lemma "\<lbrakk> x = f x; P (f x) (f x) x \<rbrakk> \<Longrightarrow> P x x x"
    83 lemma "\<lbrakk> x = f x; P (f x) (f x) x \<rbrakk> \<Longrightarrow> P x x x"
   115 by (erule ssubst)
    84 by (erule ssubst)
   116 
    85 
   117 
    86 
   118 text{*NEW*}
       
   119 lemma "\<lbrakk> x = f x; P (f x) (f x) x \<rbrakk> \<Longrightarrow> P x x x"
    87 lemma "\<lbrakk> x = f x; P (f x) (f x) x \<rbrakk> \<Longrightarrow> P x x x"
   120 apply (erule_tac P="\<lambda>u. P u u x" in ssubst)
    88 apply (erule_tac P="\<lambda>u. P u u x" in ssubst)
   121 apply (assumption)
    89 apply (assumption)
   122 done
    90 done
   123 
    91 
   149 *};
   117 *};
   150 
   118 
   151 
   119 
   152 lemma "\<lbrakk>\<not>(P\<longrightarrow>Q); \<not>(R\<longrightarrow>Q)\<rbrakk> \<Longrightarrow> R"
   120 lemma "\<lbrakk>\<not>(P\<longrightarrow>Q); \<not>(R\<longrightarrow>Q)\<rbrakk> \<Longrightarrow> R"
   153 apply (erule_tac Q="R\<longrightarrow>Q" in contrapos_np)
   121 apply (erule_tac Q="R\<longrightarrow>Q" in contrapos_np)
   154 txt{*
   122 	--{* @{subgoals[display,indent=0,margin=65]} *}
   155 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{1}}\isanewline
   123 apply intro
   156 \isanewline
   124 	--{* @{subgoals[display,indent=0,margin=65]} *}
   157 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
   158 {\isasymlbrakk}{\isasymnot}\ {\isacharparenleft}P\ {\isasymlongrightarrow}\ Q{\isacharparenright}{\isacharsemicolon}\ {\isasymnot}\ {\isacharparenleft}R\ {\isasymlongrightarrow}\ Q{\isacharparenright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ R\isanewline
       
   159 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}{\isasymnot}\ {\isacharparenleft}P\ {\isasymlongrightarrow}\ Q{\isacharparenright}{\isacharsemicolon}\ {\isasymnot}\ R{\isasymrbrakk}\ {\isasymLongrightarrow}\ R\ {\isasymlongrightarrow}\ Q
       
   160 *}
       
   161 
       
   162 apply intro
       
   163 txt{*
       
   164 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{3}}\isanewline
       
   165 \isanewline
       
   166 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
   167 {\isasymlbrakk}{\isasymnot}\ {\isacharparenleft}P\ {\isasymlongrightarrow}\ Q{\isacharparenright}{\isacharsemicolon}\ {\isasymnot}\ {\isacharparenleft}R\ {\isasymlongrightarrow}\ Q{\isacharparenright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ R\isanewline
       
   168 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}{\isasymnot}\ {\isacharparenleft}P\ {\isasymlongrightarrow}\ Q{\isacharparenright}{\isacharsemicolon}\ {\isasymnot}\ R{\isacharsemicolon}\ R{\isasymrbrakk}\ {\isasymLongrightarrow}\ Q
       
   169 *}
       
   170 by (erule notE)
   125 by (erule notE)
   171 text{*NEW*}
       
   172 
       
   173 
       
   174 
   126 
   175 lemma "(P \<or> Q) \<and> R \<Longrightarrow> P \<or> Q \<and> R"
   127 lemma "(P \<or> Q) \<and> R \<Longrightarrow> P \<or> Q \<and> R"
   176 apply intro
   128 apply intro
   177 txt{*
   129 	--{* @{subgoals[display,indent=0,margin=65]} *}
   178 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{1}}\isanewline
       
   179 \isanewline
       
   180 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
   181 {\isacharparenleft}P\ {\isasymor}\ Q{\isacharparenright}\ {\isasymand}\ R\ {\isasymLongrightarrow}\ P\ {\isasymor}\ Q\ {\isasymand}\ R\isanewline
       
   182 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}{\isacharparenleft}P\ {\isasymor}\ Q{\isacharparenright}\ {\isasymand}\ R{\isacharsemicolon}\ {\isasymnot}\ {\isacharparenleft}Q\ {\isasymand}\ R{\isacharparenright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ P
       
   183 *}
       
   184 
   130 
   185 apply (elim conjE disjE)
   131 apply (elim conjE disjE)
   186  apply assumption
   132  apply assumption
   187 
   133 	--{* @{subgoals[display,indent=0,margin=65]} *}
   188 txt{*
       
   189 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{4}}\isanewline
       
   190 \isanewline
       
   191 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
   192 {\isacharparenleft}P\ {\isasymor}\ Q{\isacharparenright}\ {\isasymand}\ R\ {\isasymLongrightarrow}\ P\ {\isasymor}\ Q\ {\isasymand}\ R\isanewline
       
   193 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}{\isasymnot}\ {\isacharparenleft}Q\ {\isasymand}\ R{\isacharparenright}{\isacharsemicolon}\ R{\isacharsemicolon}\ Q{\isasymrbrakk}\ {\isasymLongrightarrow}\ P
       
   194 *}
       
   195 
   134 
   196 by (erule contrapos_np, rule conjI)
   135 by (erule contrapos_np, rule conjI)
   197 text{*NEW
   136 text{*
   198 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{6}}\isanewline
   137 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{6}}\isanewline
   199 \isanewline
   138 \isanewline
   200 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
   139 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
   201 {\isacharparenleft}P\ {\isasymor}\ Q{\isacharparenright}\ {\isasymand}\ R\ {\isasymLongrightarrow}\ P\ {\isasymor}\ Q\ {\isasymand}\ R\isanewline
   140 {\isacharparenleft}P\ {\isasymor}\ Q{\isacharparenright}\ {\isasymand}\ R\ {\isasymLongrightarrow}\ P\ {\isasymor}\ Q\ {\isasymand}\ R\isanewline
   202 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}R{\isacharsemicolon}\ Q{\isacharsemicolon}\ {\isasymnot}\ P{\isasymrbrakk}\ {\isasymLongrightarrow}\ Q\isanewline
   141 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}R{\isacharsemicolon}\ Q{\isacharsemicolon}\ {\isasymnot}\ P{\isasymrbrakk}\ {\isasymLongrightarrow}\ Q\isanewline
   207 text{*Quantifiers*}
   146 text{*Quantifiers*}
   208 
   147 
   209 lemma "\<forall>x. P x \<longrightarrow> P x"
   148 lemma "\<forall>x. P x \<longrightarrow> P x"
   210 apply (rule allI)
   149 apply (rule allI)
   211 by (rule impI)
   150 by (rule impI)
   212 text{*NEW*}
       
   213 
   151 
   214 lemma "(\<forall>x. P \<longrightarrow> Q x) \<Longrightarrow> P \<longrightarrow> (\<forall>x. Q x)"
   152 lemma "(\<forall>x. P \<longrightarrow> Q x) \<Longrightarrow> P \<longrightarrow> (\<forall>x. Q x)"
   215 apply (rule impI, rule allI)
   153 apply (rule impI, rule allI)
   216 apply (drule spec)
   154 apply (drule spec)
   217 by (drule mp)
   155 by (drule mp)
   218 text{*NEW*}
   156 
       
   157 text{*NEW: rename_tac*}
       
   158 lemma "x < y \<Longrightarrow> \<forall>x y. P x (f y)"
       
   159 apply intro
       
   160 	--{* @{subgoals[display,indent=0,margin=65]} *}
       
   161 apply (rename_tac v w)
       
   162 	--{* @{subgoals[display,indent=0,margin=65]} *}
       
   163 oops
       
   164 
   219 
   165 
   220 lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (h x); P a\<rbrakk> \<Longrightarrow> P(h (h a))"
   166 lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (h x); P a\<rbrakk> \<Longrightarrow> P(h (h a))"
   221 apply (frule spec)
   167 apply (frule spec)
       
   168 	--{* @{subgoals[display,indent=0,margin=65]} *}
   222 apply (drule mp, assumption)
   169 apply (drule mp, assumption)
   223 apply (drule spec)
   170 apply (drule spec)
       
   171 	--{* @{subgoals[display,indent=0,margin=65]} *}
   224 by (drule mp)
   172 by (drule mp)
   225 text{*NEW*}
   173 
   226 
       
   227 
       
   228 text
       
   229 {*
       
   230 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{1}}\isanewline
       
   231 \isanewline
       
   232 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
   233 {\isasymlbrakk}{\isasymforall}x{\isachardot}\ P\ x\ {\isasymlongrightarrow}\ P\ {\isacharparenleft}f\ x{\isacharparenright}{\isacharsemicolon}\ P\ a{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}f\ {\isacharparenleft}f\ a{\isacharparenright}{\isacharparenright}\isanewline
       
   234 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}{\isasymforall}x{\isachardot}\ P\ x\ {\isasymlongrightarrow}\ P\ {\isacharparenleft}f\ x{\isacharparenright}{\isacharsemicolon}\ P\ a{\isacharsemicolon}\ P\ {\isacharquery}x\ {\isasymlongrightarrow}\ P\ {\isacharparenleft}f\ {\isacharquery}x{\isacharparenright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}f\ {\isacharparenleft}f\ a{\isacharparenright}{\isacharparenright}
       
   235 *}
       
   236 
       
   237 text{*
       
   238 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{3}}\isanewline
       
   239 \isanewline
       
   240 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
       
   241 {\isasymlbrakk}{\isasymforall}x{\isachardot}\ P\ x\ {\isasymlongrightarrow}\ P\ {\isacharparenleft}f\ x{\isacharparenright}{\isacharsemicolon}\ P\ a{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}f\ {\isacharparenleft}f\ a{\isacharparenright}{\isacharparenright}\isanewline
       
   242 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}{\isasymforall}x{\isachardot}\ P\ x\ {\isasymlongrightarrow}\ P\ {\isacharparenleft}f\ x{\isacharparenright}{\isacharsemicolon}\ P\ a{\isacharsemicolon}\ P\ {\isacharparenleft}f\ a{\isacharparenright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}f\ {\isacharparenleft}f\ a{\isacharparenright}{\isacharparenright}
       
   243 *}
       
   244 
   174 
   245 lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (f x); P a\<rbrakk> \<Longrightarrow> P(f (f a))"
   175 lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (f x); P a\<rbrakk> \<Longrightarrow> P(f (f a))"
   246 by blast
   176 by blast
   247 
   177 
   248 text{*NEW
   178 text{*
   249 Hilbert-epsilon theorems*}
   179 Hilbert-epsilon theorems*}
   250 
   180 
   251 text{*
   181 text{*
   252 @{thm[display] some_equality[no_vars]}
   182 @{thm[display] some_equality[no_vars]}
   253 \rulename{some_equality}
   183 \rulename{some_equality}
   321 
   251 
   322 theorem axiom_of_choice: "(\<forall>x. \<exists> y. P x y) \<Longrightarrow> \<exists>f. \<forall>x. P x (f x)"
   252 theorem axiom_of_choice: "(\<forall>x. \<exists> y. P x y) \<Longrightarrow> \<exists>f. \<forall>x. P x (f x)"
   323 apply (rule exI [of _  "\<lambda>x. SOME y. P x y"])
   253 apply (rule exI [of _  "\<lambda>x. SOME y. P x y"])
   324 by (blast intro: someI);
   254 by (blast intro: someI);
   325 
   255 
   326 text{*end of NEW material*}
   256 text{*end of Epsilon section*}
       
   257 
   327 
   258 
   328 lemma "(\<exists>x. P x) \<or> (\<exists>x. Q x) \<Longrightarrow> \<exists>x. P x \<or> Q x"
   259 lemma "(\<exists>x. P x) \<or> (\<exists>x. Q x) \<Longrightarrow> \<exists>x. P x \<or> Q x"
   329 apply elim
   260 apply elim
   330  apply intro
   261  apply intro
   331  apply assumption
   262  apply assumption