src/HOL/ex/Records.thy
changeset 38012 3ca193a6ae5a
parent 37826 4c0a5e35931a
child 42463 f270e3e18be5
equal deleted inserted replaced
37974:d9549f9da779 38012:3ca193a6ae5a
   247 lemma "r (| xpos := x, ypos := y, xpos := x' |) = r (| ypos := y, xpos := x' |)"
   247 lemma "r (| xpos := x, ypos := y, xpos := x' |) = r (| ypos := y, xpos := x' |)"
   248   by simp
   248   by simp
   249 
   249 
   250 text {* In some cases its convenient to automatically split
   250 text {* In some cases its convenient to automatically split
   251 (quantified) records. For this purpose there is the simproc @{ML [source]
   251 (quantified) records. For this purpose there is the simproc @{ML [source]
   252 "Record.record_split_simproc"} and the tactic @{ML [source]
   252 "Record.split_simproc"} and the tactic @{ML [source]
   253 "Record.record_split_simp_tac"}.  The simplification procedure
   253 "Record.split_simp_tac"}.  The simplification procedure
   254 only splits the records, whereas the tactic also simplifies the
   254 only splits the records, whereas the tactic also simplifies the
   255 resulting goal with the standard record simplification rules. A
   255 resulting goal with the standard record simplification rules. A
   256 (generalized) predicate on the record is passed as parameter that
   256 (generalized) predicate on the record is passed as parameter that
   257 decides whether or how `deep' to split the record. It can peek on the
   257 decides whether or how `deep' to split the record. It can peek on the
   258 subterm starting at the quantified occurrence of the record (including
   258 subterm starting at the quantified occurrence of the record (including
   259 the quantifier). The value @{ML "0"} indicates no split, a value
   259 the quantifier). The value @{ML "0"} indicates no split, a value
   260 greater @{ML "0"} splits up to the given bound of record extension and
   260 greater @{ML "0"} splits up to the given bound of record extension and
   261 finally the value @{ML "~1"} completely splits the record.
   261 finally the value @{ML "~1"} completely splits the record.
   262 @{ML [source] "Record.record_split_simp_tac"} additionally takes a list of
   262 @{ML [source] "Record.split_simp_tac"} additionally takes a list of
   263 equations for simplification and can also split fixed record variables.
   263 equations for simplification and can also split fixed record variables.
   264 
   264 
   265 *}
   265 *}
   266 
   266 
   267 lemma "(\<forall>r. P (xpos r)) \<longrightarrow> (\<forall>x. P x)"
   267 lemma "(\<forall>r. P (xpos r)) \<longrightarrow> (\<forall>x. P x)"
   268   apply (tactic {* simp_tac
   268   apply (tactic {* simp_tac
   269           (HOL_basic_ss addsimprocs [Record.record_split_simproc (K ~1)]) 1*})
   269           (HOL_basic_ss addsimprocs [Record.split_simproc (K ~1)]) 1*})
   270   apply simp
   270   apply simp
   271   done
   271   done
   272 
   272 
   273 lemma "(\<forall>r. P (xpos r)) \<longrightarrow> (\<forall>x. P x)"
   273 lemma "(\<forall>r. P (xpos r)) \<longrightarrow> (\<forall>x. P x)"
   274   apply (tactic {* Record.record_split_simp_tac [] (K ~1) 1*})
   274   apply (tactic {* Record.split_simp_tac [] (K ~1) 1*})
   275   apply simp
   275   apply simp
   276   done
   276   done
   277 
   277 
   278 lemma "(\<exists>r. P (xpos r)) \<longrightarrow> (\<exists>x. P x)"
   278 lemma "(\<exists>r. P (xpos r)) \<longrightarrow> (\<exists>x. P x)"
   279   apply (tactic {* simp_tac
   279   apply (tactic {* simp_tac
   280           (HOL_basic_ss addsimprocs [Record.record_split_simproc (K ~1)]) 1*})
   280           (HOL_basic_ss addsimprocs [Record.split_simproc (K ~1)]) 1*})
   281   apply simp
   281   apply simp
   282   done
   282   done
   283 
   283 
   284 lemma "(\<exists>r. P (xpos r)) \<longrightarrow> (\<exists>x. P x)"
   284 lemma "(\<exists>r. P (xpos r)) \<longrightarrow> (\<exists>x. P x)"
   285   apply (tactic {* Record.record_split_simp_tac [] (K ~1) 1*})
   285   apply (tactic {* Record.split_simp_tac [] (K ~1) 1*})
   286   apply simp
   286   apply simp
   287   done
   287   done
   288 
   288 
   289 lemma "\<And>r. P (xpos r) \<Longrightarrow> (\<exists>x. P x)"
   289 lemma "\<And>r. P (xpos r) \<Longrightarrow> (\<exists>x. P x)"
   290   apply (tactic {* simp_tac
   290   apply (tactic {* simp_tac
   291           (HOL_basic_ss addsimprocs [Record.record_split_simproc (K ~1)]) 1*})
   291           (HOL_basic_ss addsimprocs [Record.split_simproc (K ~1)]) 1*})
   292   apply auto
   292   apply auto
   293   done
   293   done
   294 
   294 
   295 lemma "\<And>r. P (xpos r) \<Longrightarrow> (\<exists>x. P x)"
   295 lemma "\<And>r. P (xpos r) \<Longrightarrow> (\<exists>x. P x)"
   296   apply (tactic {* Record.record_split_simp_tac [] (K ~1) 1*})
   296   apply (tactic {* Record.split_simp_tac [] (K ~1) 1*})
   297   apply auto
   297   apply auto
   298   done
   298   done
   299 
   299 
   300 lemma "P (xpos r) \<Longrightarrow> (\<exists>x. P x)"
   300 lemma "P (xpos r) \<Longrightarrow> (\<exists>x. P x)"
   301   apply (tactic {* Record.record_split_simp_tac [] (K ~1) 1*})
   301   apply (tactic {* Record.split_simp_tac [] (K ~1) 1*})
   302   apply auto
   302   apply auto
   303   done
   303   done
   304 
   304 
   305 lemma fixes r shows "P (xpos r) \<Longrightarrow> (\<exists>x. P x)"
   305 lemma fixes r shows "P (xpos r) \<Longrightarrow> (\<exists>x. P x)"
   306   apply (tactic {* Record.record_split_simp_tac [] (K ~1) 1*})
   306   apply (tactic {* Record.split_simp_tac [] (K ~1) 1*})
   307   apply auto
   307   apply auto
   308   done
   308   done
   309 
   309 
   310 
   310 
   311 lemma True
   311 lemma True
   314     fix P r
   314     fix P r
   315     assume pre: "P (xpos r)"
   315     assume pre: "P (xpos r)"
   316     have "\<exists>x. P x"
   316     have "\<exists>x. P x"
   317       using pre
   317       using pre
   318       apply -
   318       apply -
   319       apply (tactic {* Record.record_split_simp_tac [] (K ~1) 1*})
   319       apply (tactic {* Record.split_simp_tac [] (K ~1) 1*})
   320       apply auto 
   320       apply auto 
   321       done
   321       done
   322   }
   322   }
   323   show ?thesis ..
   323   show ?thesis ..
   324 qed
   324 qed
   325 
   325 
   326 text {* The effect of simproc @{ML [source]
   326 text {* The effect of simproc @{ML [source]
   327 "Record.record_ex_sel_eq_simproc"} is illustrated by the
   327 "Record.ex_sel_eq_simproc"} is illustrated by the
   328 following lemma.  
   328 following lemma.  
   329 *}
   329 *}
   330 
   330 
   331 lemma "\<exists>r. xpos r = x"
   331 lemma "\<exists>r. xpos r = x"
   332   apply (tactic {*simp_tac 
   332   apply (tactic {*simp_tac 
   333            (HOL_basic_ss addsimprocs [Record.record_ex_sel_eq_simproc]) 1*})
   333            (HOL_basic_ss addsimprocs [Record.ex_sel_eq_simproc]) 1*})
   334   done
   334   done
   335 
   335 
   336 
   336 
   337 subsection {* A more complex record expression *}
   337 subsection {* A more complex record expression *}
   338 
   338