CookBook/FirstSteps.thy
changeset 21 2356e5c70d98
parent 20 5ae6a1bb91c9
child 25 e2f9f94b26d4
equal deleted inserted replaced
20:5ae6a1bb91c9 21:2356e5c70d98
   166   function is called. Operationally speaking,  @{text "@{theory}"} is 
   166   function is called. Operationally speaking,  @{text "@{theory}"} is 
   167   \emph{not} replaced with code that will look up the current theory in 
   167   \emph{not} replaced with code that will look up the current theory in 
   168   some data structure and return it. Instead, it is literally
   168   some data structure and return it. Instead, it is literally
   169   replaced with the value representing the theory name.
   169   replaced with the value representing the theory name.
   170 
   170 
   171   In a similar way you can use antiquotations to refer to theorems:
   171   In a similar way you can use antiquotations to refer to theorems or simpsets:
   172 *}
   172 *}
   173 
   173 
   174 ML {* @{thm allI} *}
   174 ML {* @{thm allI} *}
       
   175 ML {* @{simpset} *}
   175 
   176 
   176 text {*
   177 text {*
   177   In the course of this introduction, we will learn more about 
   178   In the course of this introduction, we will learn more about 
   178   these antiquotations: they greatly simplify Isabelle programming since one
   179   these antiquotations: they greatly simplify Isabelle programming since one
   179   can directly access all kinds of logical elements from ML.
   180   can directly access all kinds of logical elements from ML.
   410    assumes assm\<^isub>1: "\<And>(x::nat). P x \<Longrightarrow> Q x" 
   411    assumes assm\<^isub>1: "\<And>(x::nat). P x \<Longrightarrow> Q x" 
   411    and     assm\<^isub>2: "P t"
   412    and     assm\<^isub>2: "P t"
   412    shows "Q t" (*<*)oops(*>*) 
   413    shows "Q t" (*<*)oops(*>*) 
   413 
   414 
   414 text {*
   415 text {*
   415   on the ML level:\footnote{Note that @{text "|>"} is just reverse
   416   on the ML level:\footnote{Note that @{text "|>"} is reverse
   416   application. This combinator, and several variants are defined in
   417   application. This combinator, and several variants are defined in
   417   @{ML_file "Pure/General/basics.ML"}.}
   418   @{ML_file "Pure/General/basics.ML"}.}
   418 
   419 
   419 *}
   420 *}
   420 
   421 
   437   |> implies_intr assm1
   438   |> implies_intr assm1
   438 end
   439 end
   439 *}
   440 *}
   440 
   441 
   441 text {*
   442 text {*
       
   443 
       
   444   This code-snippet constructs the following proof:
       
   445 
       
   446   \[
       
   447   \infer[(@{text "\<Longrightarrow>"}$-$intro)]{\vdash @{prop "(\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> P t \<Longrightarrow> Q t"}}
       
   448     {\infer[(@{text "\<Longrightarrow>"}$-$intro)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "P t \<Longrightarrow> Q t"}}
       
   449        {\infer[(@{text "\<Longrightarrow>"}$-$elim)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"}, @{prop "P t"} \vdash @{prop "Q t"}}
       
   450           {\infer[(@{text "\<And>"}$-$elim)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "P t \<Longrightarrow> Q t"}}
       
   451                  {\infer[(assume)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "\<And>x. P x \<Longrightarrow> Q x"}}{}}
       
   452                  &
       
   453            \infer[(assume)]{@{prop "P t"} \vdash @{prop "P t"}}{}
       
   454           }
       
   455        }
       
   456     }
       
   457   \]
       
   458 
   442 
   459 
   443   \begin{readmore}
   460   \begin{readmore}
   444   For how the functions @{text "assume"}, @{text "forall_elim"} etc work
   461   For how the functions @{text "assume"}, @{text "forall_elim"} etc work
   445   see \isccite{sec:thms}. The basic functions for theorems are defined in
   462   see \isccite{sec:thms}. The basic functions for theorems are defined in
   446   @{ML_file "Pure/thm.ML"}. 
   463   @{ML_file "Pure/thm.ML"}. 
   466   Since the goal @{term C} can potentially be an implication, there is a
   483   Since the goal @{term C} can potentially be an implication, there is a
   467   @{text "#"} wrapped around it, which prevents that premises are 
   484   @{text "#"} wrapped around it, which prevents that premises are 
   468   misinterpreted as open subgoals. The protection @{text "# :: prop \<Rightarrow>
   485   misinterpreted as open subgoals. The protection @{text "# :: prop \<Rightarrow>
   469   prop"} is just the identity function and used as a syntactic marker. 
   486   prop"} is just the identity function and used as a syntactic marker. 
   470   
   487   
       
   488   (FIXME: maybe show how this is printed on the screen) 
       
   489 
   471   \begin{readmore}
   490   \begin{readmore}
   472   For more on goals see \isccite{sec:tactical-goals}. 
   491   For more on goals see \isccite{sec:tactical-goals}. 
   473   \end{readmore}
   492   \end{readmore}
   474 
   493 
   475   Tactics are functions that map a goal state to a (lazy)
   494   Tactics are functions that map a goal state to a (lazy)
   500 apply assumption
   519 apply assumption
   501 done
   520 done
   502 
   521 
   503 
   522 
   504 text {*
   523 text {*
   505   
   524   To start the proof, the function  @{ML "Goal.prove"}~@{text "ctxt xs As C tac"} sets 
   506   To start the proof, the function  @{ML "Goal.prove"}~@{text "ctxt params assms goal tac"}
   525   up a goal state for proving the goal @{text C} under the assumptions @{text As} 
   507   sets up a goal state for proving @{text goal} under the assumptions @{text assms} with
   526   (empty in the proof at hand) 
   508   the variables @{text params} that will be generalised once the
   527   with the variables @{text xs} that will be generalised once the
   509   goal is proved; @{text "tac"} is a function that returns a tactic having some funny 
   528   goal is proved. The @{text "tac"} is the tactic which proves the goal and which 
   510   input parameters (FIXME by possibly having an explanation in the implementation-manual). 
   529   can make use of the local assumptions.
   511 
       
   512 *}
   530 *}
   513 
   531 
   514 
   532 
   515 
   533 
   516 ML {*
   534 ML {*
   525     THEN resolve_tac [disjI1] 1
   543     THEN resolve_tac [disjI1] 1
   526     THEN assume_tac 1)
   544     THEN assume_tac 1)
   527 end
   545 end
   528 *}
   546 *}
   529 
   547 
       
   548 text {*
       
   549 
       
   550   \begin{readmore}
       
   551   To learn more about the function @{ML Goal.prove} see \isccite{sec:results}.
       
   552   \end{readmore}
       
   553 
       
   554 *}
       
   555 
       
   556 
   530 text {* An alternative way to transcribe this proof is as follows *}
   557 text {* An alternative way to transcribe this proof is as follows *}
   531 
   558 
   532 ML {*
   559 ML {*
   533 let
   560 let
   534   val ctxt = @{context}
   561   val ctxt = @{context}
   541     THEN' resolve_tac [disjI1] 
   568     THEN' resolve_tac [disjI1] 
   542     THEN' assume_tac) 1)
   569     THEN' assume_tac) 1)
   543 end
   570 end
   544 *}
   571 *}
   545 
   572 
       
   573 text {* (FIXME: are there any advantages/disadvantages about this way?) *}
       
   574 
   546 section {* Storing Theorems *}
   575 section {* Storing Theorems *}
   547 
   576 
   548 section {* Theorem Attributes *}
   577 section {* Theorem Attributes *}
   549 
   578 
   550 text {* Was changing theorems. *}
       
   551 
   579 
   552 end
   580 end