ProgTutorial/General.thy
changeset 349 9e374cd891e1
parent 348 2f2018927f2a
child 350 364fffa80794
equal deleted inserted replaced
348:2f2018927f2a 349:9e374cd891e1
   855 
   855 
   856   or with the @{text "@{thm \<dots>}"}-antiquotation on the ML-level. As can be seen
   856   or with the @{text "@{thm \<dots>}"}-antiquotation on the ML-level. As can be seen
   857   the theorem does not have any meta-variables that would be present if we proved
   857   the theorem does not have any meta-variables that would be present if we proved
   858   this theorem on the user-level. We will see later on that usually we have to 
   858   this theorem on the user-level. We will see later on that usually we have to 
   859   construct meta-variables in theorems explicitly.
   859   construct meta-variables in theorems explicitly.
       
   860 
       
   861   \footnote{\bf FIXME say something about @{ML_ind add_thms_dynamic in PureThy}}
   860 *}
   862 *}
   861 
   863 
   862 text {*
   864 text {*
   863   There is a multitude of functions that manage or manipulate theorems. For example 
   865   There is a multitude of functions that manage or manipulate theorems. For example 
   864   we can test theorems for alpha equality. Suppose you proved the following three 
   866   we can test theorems for alpha equality. Suppose you proved the following three 
   961 
   963 
   962   In this code the function @{ML atomize in ObjectLogic} produces 
   964   In this code the function @{ML atomize in ObjectLogic} produces 
   963   a meta-equation between the given theorem and the theorem transformed
   965   a meta-equation between the given theorem and the theorem transformed
   964   into the object logic. The result is the theorem with object logic 
   966   into the object logic. The result is the theorem with object logic 
   965   connectives. However, in order to completely transform a theorem
   967   connectives. However, in order to completely transform a theorem
   966   such as @{thm [source] list.induct}
   968   such as @{thm [source] list.induct}, which is of the form 
   967 
   969 
   968   @{thm [display] list.induct}
   970   @{thm [display] list.induct}
   969 
   971 
   970   we have to first abstract over the variables @{text "?P"} and 
   972   we have to first abstract over the meta variables @{text "?P"} and 
   971   @{text "?list"}. For this we can use the function 
   973   @{text "?list"}. For this we can use the function 
   972   @{ML_ind forall_intr_vars in Drule}. 
   974   @{ML_ind forall_intr_vars in Drule}. 
   973 *}
   975 *}
   974 
   976 
   975 ML{*fun atomize_thm thm =
   977 ML{*fun atomize_thm thm =
   979 in
   981 in
   980   MetaSimplifier.rewrite_rule [thm''] thm'
   982   MetaSimplifier.rewrite_rule [thm''] thm'
   981 end*}
   983 end*}
   982 
   984 
   983 text {*
   985 text {*
   984   For @{thm [source] list.induct} it produces:
   986   For the theorem @{thm [source] list.induct}, this function produces:
   985 
   987 
   986   @{ML_response_fake [display, gray]
   988   @{ML_response_fake [display, gray]
   987   "atomize_thm @{thm list.induct}"
   989   "atomize_thm @{thm list.induct}"
   988   "\<forall>P list. P [] \<longrightarrow> (\<forall>a list. P list \<longrightarrow> P (a # list)) \<longrightarrow> P list"}
   990   "\<forall>P list. P [] \<longrightarrow> (\<forall>a list. P list \<longrightarrow> P (a # list)) \<longrightarrow> P list"}
   989 
   991 
   990   Theorems can also be produced from terms by giving an explicit proof. 
   992   Theorems can also be produced from terms by giving an explicit proof. 
   991   One way to achive this is by using the function @{ML_ind prove in Goal}. 
   993   One way to achive this is by using the function @{ML_ind prove in Goal}. 
   992   For example
   994   For example below we prove the term @{term "P \<Longrightarrow> P"}.
   993   
   995   
   994   @{ML_response_fake [display,gray]
   996   @{ML_response_fake [display,gray]
   995   "let
   997   "let
   996   val trm = @{term \"P \<Longrightarrow> P::bool\"}
   998   val trm = @{term \"P \<Longrightarrow> P::bool\"}
   997   val tac = K (atac 1)
   999   val tac = K (atac 1)
  1000 end"
  1002 end"
  1001   "?P \<Longrightarrow> ?P"}
  1003   "?P \<Longrightarrow> ?P"}
  1002 
  1004 
  1003   This function takes as second argument a list of strings. This list specifies
  1005   This function takes as second argument a list of strings. This list specifies
  1004   which variables should be turned into meta-variables once the term is proved.
  1006   which variables should be turned into meta-variables once the term is proved.
  1005   The proof is given in form of a tactic. We explain tactics in 
  1007   The proof is given in form of a tactic as last argument. We explain tactics in 
  1006   Chapter~\ref{chp:tactical}. 
  1008   Chapter~\ref{chp:tactical}. In the code above the tactic proved the theorem 
       
  1009   by assumption.
  1007 
  1010 
  1008   Theorems also contain auxiliary data, such their names and kind, but also 
  1011   Theorems also contain auxiliary data, such their names and kind, but also 
  1009   names for cases etc. This data is stored in a string-string list and can
  1012   names for cases etc. This data is stored in a string-string list and can
  1010   be retrieved with the function @{ML_ind get_tags in Thm}. Assume the
  1013   be retrieved with the function @{ML_ind get_tags in Thm}. Assume the
  1011   following lemma. 
  1014   following lemma. 
  1018 
  1021 
  1019   @{ML_response_fake [display,gray]
  1022   @{ML_response_fake [display,gray]
  1020   "Thm.get_tags @{thm foo_data}"
  1023   "Thm.get_tags @{thm foo_data}"
  1021   "[(\"name\", \"General.foo_data\"), (\"kind\", \"lemma\")]"}
  1024   "[(\"name\", \"General.foo_data\"), (\"kind\", \"lemma\")]"}
  1022 
  1025 
  1023   We can extend the data associated with this lemma by attaching case names.  
  1026   When we store lemmas in the theorem database, we can explicitly extend the data 
       
  1027   associated with this lemma by attaching case names.  
  1024 *}
  1028 *}
  1025 
  1029 
  1026 local_setup %gray {*
  1030 local_setup %gray {*
  1027   LocalTheory.note Thm.lemmaK
  1031   LocalTheory.note Thm.lemmaK
  1028     ((@{binding "foo_data'"}, []), 
  1032     ((@{binding "foo_data'"}, []), 
  1029       [(RuleCases.name ["foo_case1", "foo_case2"] 
  1033       [(RuleCases.name ["foo_case1", "foo_case2"] 
  1030         @{thm foo_data})]) #> snd *}
  1034         @{thm foo_data})]) #> snd *}
  1031 
  1035 
  1032 text {*
  1036 text {*
  1033   The date of the theorem @{thm [source] foo_data'} is as follows:
  1037   The data of the theorem @{thm [source] foo_data'} is then as follows:
  1034 
  1038 
  1035   @{ML_response_fake [display,gray]
  1039   @{ML_response_fake [display,gray]
  1036   "Thm.get_tags @{thm foo_data'}"
  1040   "Thm.get_tags @{thm foo_data'}"
  1037   "[(\"name\", \"General.foo_data'\"), (\"kind\", \"lemma\"), 
  1041   "[(\"name\", \"General.foo_data'\"), (\"kind\", \"lemma\"), 
  1038  (\"case_names\", \"foo_case1;foo_case2\")]"}
  1042  (\"case_names\", \"foo_case1;foo_case2\")]"}
       
  1043 
       
  1044   You notice the difference when using the proof methods @{ML_text cases} 
       
  1045   or @{ML_text induct}. In the proof below
  1039 *}
  1046 *}
  1040 
  1047 
  1041 lemma
  1048 lemma
  1042   "Q \<Longrightarrow> Q \<Longrightarrow> Q"
  1049   "Q \<Longrightarrow> Q \<Longrightarrow> Q"
  1043 proof (induct rule: foo_data')
  1050 proof (cases rule: foo_data')
       
  1051 print_cases
  1044 (*<*)oops(*>*)
  1052 (*<*)oops(*>*)
  1045 
  1053 
  1046 text {*
  1054 text {*
       
  1055   we can proceed by analysing the cases @{ML_text "foo_case1"} and 
       
  1056   @{ML_text "foo_case2"}. While if the theorem has no names, then
       
  1057   the cases have standard names @{ML_text 1}, @{ML_text 2} and so 
       
  1058   on. This can be seen in the proof below.
       
  1059 *}
       
  1060 
       
  1061 lemma
       
  1062   "Q \<Longrightarrow> Q \<Longrightarrow> Q"
       
  1063 proof (cases rule: foo_data)
       
  1064 print_cases
       
  1065 (*<*)oops(*>*)
       
  1066 
       
  1067 text {*
  1047   TBD below
  1068   TBD below
       
  1069 
       
  1070   One great feature of Isabelle is its document preparation system where
       
  1071   proved theorems can be quoted in the text directly from the formalisation. 
  1048 
  1072 
  1049   (FIXME: example for how to add theorem styles)
  1073   (FIXME: example for how to add theorem styles)
  1050 *}
  1074 *}
  1051 
  1075 
  1052 ML {*
  1076 ML {*
  1066 
  1090 
  1067 ML {*
  1091 ML {*
  1068 strip_assums_all ([], @{term "\<And>x y. A x y"})
  1092 strip_assums_all ([], @{term "\<And>x y. A x y"})
  1069 *}
  1093 *}
  1070 
  1094 
       
  1095 (*
  1071 setup %gray {*
  1096 setup %gray {*
  1072   TermStyle.add_style "no_all_prem1" (style_parm_premise 1) #>
  1097   TermStyle.add_style "no_all_prem1" (style_parm_premise 1) #>
  1073   TermStyle.add_style "no_all_prem2" (style_parm_premise 2)
  1098   TermStyle.add_style "no_all_prem2" (style_parm_premise 2)
  1074 *}
  1099 *}
  1075 
  1100 *)
  1076 lemma 
  1101 lemma 
  1077   shows "A \<Longrightarrow> B"
  1102   shows "A \<Longrightarrow> B"
  1078   and   "C \<Longrightarrow> D"
  1103   and   "C \<Longrightarrow> D"
  1079 oops
  1104 oops
  1080 
  1105 
  1373 *}
  1398 *}
  1374 
  1399 
  1375 section {* Contexts (TBD) *}
  1400 section {* Contexts (TBD) *}
  1376 
  1401 
  1377 section {* Local Theories (TBD) *}
  1402 section {* Local Theories (TBD) *}
  1378 
       
  1379 section {* Storing Theorems\label{sec:storing} (TBD) *}
       
  1380 
       
  1381 text {* @{ML_ind  add_thms_dynamic in PureThy} *}
       
  1382 
       
  1383 local_setup %gray {* 
       
  1384   LocalTheory.note Thm.theoremK 
       
  1385     ((@{binding "allI_alt"}, []), [@{thm allI}]) #> snd *}
       
  1386 
  1403 
  1387 
  1404 
  1388 (*
  1405 (*
  1389 setup {*
  1406 setup {*
  1390  Sign.add_consts_i [(Binding"bar", @{typ "nat"},NoSyn)] 
  1407  Sign.add_consts_i [(Binding"bar", @{typ "nat"},NoSyn)] 
  1736 
  1753 
  1737 
  1754 
  1738 
  1755 
  1739 section {* Managing Name Spaces (TBD) *}
  1756 section {* Managing Name Spaces (TBD) *}
  1740 
  1757 
       
  1758 section {* Summary *}
       
  1759 
       
  1760 text {*
       
  1761   \begin{conventions}
       
  1762   \begin{itemize}
       
  1763   \item Start with a proper context and then pass it around 
       
  1764   through all your functions.
       
  1765   \end{itemize}
       
  1766   \end{conventions}
       
  1767 *}
  1741 
  1768 
  1742 end
  1769 end