From 2cdf9f3124be175050a1b2c798f892d9c190db89 Mon Sep 17 00:00:00 2001 From: Burkhart Wolff Date: Wed, 23 Sep 2020 13:23:20 +0200 Subject: [PATCH] stiluebungen < 1150 --- .../TR_MyCommentedIsabelle.thy | 123 +++++++++--------- 1 file changed, 65 insertions(+), 58 deletions(-) diff --git a/examples/technical_report/TR_my_commented_isabelle/TR_MyCommentedIsabelle.thy b/examples/technical_report/TR_my_commented_isabelle/TR_MyCommentedIsabelle.thy index 3e984086..b305a8a2 100755 --- a/examples/technical_report/TR_my_commented_isabelle/TR_MyCommentedIsabelle.thy +++ b/examples/technical_report/TR_my_commented_isabelle/TR_MyCommentedIsabelle.thy @@ -889,6 +889,7 @@ text\ (binding * string option * mixfix) list -> string -> bool -> local_theory -> local_theory\ \ + text\ Note that the interface is mostly based on \<^ML_type>\local_theory\, which is a synonym to \<^ML_type>\Proof.context\. Need to lift this to a global system transition ? @@ -957,21 +958,19 @@ text\ More specialized variants of \<^ML_structure>\Tactical\ -text\The next layer in the architecture describes @{ML_type \tactic\}'s, i.e. basic operations on - theorems in a backward reasoning style (bottom up development of proof-trees). An initial goal-state - for some property @{term A} --- the \<^emph>\goal\ --- is constructed via the kernel - @{ML "Thm.trivial"}-operation into @{term "A \ A"}, and tactics either refine the premises - --- the \<^emph>\subgoals\ the of this meta-implication --- - producing more and more of them or eliminate them in subsequent goal-states. Subgoals of the form - @{term "B\<^sub>1 \ B\<^sub>2 \ A \ B\<^sub>3 \ B\<^sub>4 \ A"} can be eliminated via - the @{ML Tactic.assume_tac} - tactic, - and a subgoal @{term C\<^sub>m} can be refined via the theorem - @{term "E\<^sub>1 \ E\<^sub>2 \ E\<^sub>3 \ C\<^sub>m"} the @{ML Tactic.resolve_tac} - tactic to new subgoals - @{term "E\<^sub>1"},@{term "E\<^sub>2"}, @{term "E\<^sub>3"}. In case that a theorem used for resolution - has no premise @{term "E\<^sub>i"}, the subgoal @{term C\<^sub>m} is also eliminated ("closed"). +text\The next layer in the architecture describes \<^ML_type>\tactic\'s, i.e. basic operations on + theorems in a backward reasoning style (bottom up development of proof-trees). An initial + goal-state for some property \<^prop>\A\ --- the \<^emph>\goal\ --- is constructed via the kernel + \<^ML>\Thm.trivial\-operation into \<^prop>\A \ A\, and tactics either refine the premises --- the + \<^emph>\subgoals\ the of this meta-implication --- producing more and more of them or eliminate them + in subsequent goal-states. Subgoals of the form \<^prop>\B\<^sub>1 \ B\<^sub>2 \ A \ B\<^sub>3 \ B\<^sub>4 \ A\ can be + eliminated via the \<^ML>\Tactic.assume_tac\-tactic, and a subgoal \<^prop>\C\<^sub>m\ can be refined via the + theorem \<^prop>\E\<^sub>1 \ E\<^sub>2 \ E\<^sub>3 \ C\<^sub>m\ the \<^ML>\Tactic.resolve_tac\ - tactic to new subgoals + \<^prop>\E\<^sub>1\, \<^prop>\E\<^sub>2\, \<^prop>\E\<^sub>3\. In case that a theorem used for resolution has no premise \<^prop>\E\<^sub>i\, + the subgoal \<^prop>\C\<^sub>m\ is also eliminated ("closed"). - The following abstract of the most commonly used @{ML_type \tactic\}'s drawn from - @{file "~~/src/Pure/tactic.ML"} are summarized as follows: + The following abstract of the most commonly used \<^ML_type>\tactic\'s drawn from + \<^file>\~~/src/Pure/tactic.ML\ are summarized as follows: \<^item> \<^ML>\ assume_tac: Proof.context -> int -> tactic\ \<^item> \<^ML>\ compose_tac: Proof.context -> (bool * thm * int) -> int -> tactic\ @@ -993,17 +992,17 @@ text\Note that "applying a rule" is a fairly complex operation in the Exte \?x + ?y = ?y + ?x\. By the way, type variables were treated equally. \<^item> \<^emph>\lifting over assumptions\. If a subgoal is of the form: - \<^term>\B\<^sub>1 \ B\<^sub>2 \ A\ and we have a theorem \<^term>\D\<^sub>1 \ D\<^sub>2 \ A\, then before + \<^prop>\B\<^sub>1 \ B\<^sub>2 \ A\ and we have a theorem \<^prop>\D\<^sub>1 \ D\<^sub>2 \ A\, then before applying the theorem, the premisses were \<^emph>\lifted\ resulting in the logical refinement: - \<^term>\(B\<^sub>1 \ B\<^sub>2 \ D\<^sub>1) \ (B\<^sub>1 \ B\<^sub>2 \ D\<^sub>2) \ A\. Now, \<^ML>\resolve_tac\, for example, - will replace the subgoal \<^term>\B\<^sub>1 \ B\<^sub>2 \ A\ by the subgoals - \<^term>\B\<^sub>1 \ B\<^sub>2 \ D\<^sub>1\ and \<^term>\B\<^sub>1 \ B\<^sub>2 \ D\<^sub>2\. Of course, if the theorem wouldn't - have assumptions \<^term>\D\<^sub>1\ and \<^term>\D\<^sub>2\, the subgoal \<^term>\A\ would be replaced by + \<^prop>\(B\<^sub>1 \ B\<^sub>2 \ D\<^sub>1) \ (B\<^sub>1 \ B\<^sub>2 \ D\<^sub>2) \ A\. Now, \<^ML>\resolve_tac\, for example, + will replace the subgoal \<^prop>\B\<^sub>1 \ B\<^sub>2 \ A\ by the subgoals + \<^prop>\B\<^sub>1 \ B\<^sub>2 \ D\<^sub>1\ and \<^prop>\B\<^sub>1 \ B\<^sub>2 \ D\<^sub>2\. Of course, if the theorem wouldn't + have assumptions \<^prop>\D\<^sub>1\ and \<^prop>\D\<^sub>2\, the subgoal \<^prop>\A\ would be replaced by \<^bold>\nothing\, i.e. deleted. \<^item> \<^emph>\lifting over parameters\. If a subgoal is meta-quantified like in: - \<^term>\\ x y z. A x y z\, then a theorem like \<^term>\D\<^sub>1 \ D\<^sub>2 \ A\ is \<^emph>\lifted\ - to \<^term>\\ x y z. D\<^sub>1' \ D\<^sub>2' \ A'\, too. Since free variables occurring in \<^term>\D\<^sub>1\, - \<^term>\D\<^sub>2\ and \<^term>\A\ have been replaced by schematic variables (see phase one), + \<^prop>\\ x y z. A x y z\, then a theorem like \<^prop>\D\<^sub>1 \ D\<^sub>2 \ A\ is \<^emph>\lifted\ + to \<^prop>\\ x y z. D\<^sub>1' \ D\<^sub>2' \ A'\, too. Since free variables occurring in \<^prop>\D\<^sub>1\, + \<^prop>\D\<^sub>2\ and \<^prop>\A\ have been replaced by schematic variables (see phase one), they must be replaced by parameterized schematic variables, i. e. a kind of skolem function. For example, \?x + ?y = ?y + ?x\ would be lifted to \!! x y z. ?x x y z + ?y x y z = ?y x y z + ?x x y z\. This way, the lifted theorem @@ -1033,8 +1032,8 @@ text\The main mechanism in Isabelle as an LCF-style system is to produce \ operations: \<^item> \<^ML>\Goal.prove_internal : Proof.context -> cterm list -> cterm -> (thm list -> tactic) -> thm\ -\<^item> \<^ML>\Goal.prove_global : theory -> string list -> term list -> term -> - ({context: Proof.context, prems: thm list} -> tactic) -> thm\ +\<^item> \<^ML>\Goal.prove_global : theory -> string list -> term list -> term -> + ({context: Proof.context, prems: thm list} -> tactic) -> thm\ \<^item> ... and many more variants. \ @@ -1090,50 +1089,59 @@ thm "thm111" section\Toplevel --- aka. ''The Isar Engine''\ -text\The main structure of the Isar-engine is @{ ML_structure Toplevel} and provides and -internal @{ ML_type state} with the necessary infrastructure --- -i.e. the operations to pack and unpack theories and Proof.contexts --- on it: +text\The main structure of the Isar-engine is \<^ML_structure>\Toplevel\ and provides and +internal \<^ML_type>\state\ with the necessary infrastructure --- +i.e. the operations to pack and unpack theories and \<^ML_type>\Proof.context\'s --- on it: + +\<^item> \<^ML>\ Toplevel.theory_toplevel: theory -> Toplevel.state\ +\<^item> \<^ML>\ Toplevel.init_toplevel: unit -> Toplevel.state\ +\<^item> \<^ML>\ Toplevel.is_toplevel: Toplevel.state -> bool\ +\<^item> \<^ML>\ Toplevel.is_theory: Toplevel.state -> bool\ +\<^item> \<^ML>\ Toplevel.is_proof: Toplevel.state -> bool\ +\<^item> \<^ML>\ Toplevel.is_skipped_proof: Toplevel.state -> bool\ +\<^item> \<^ML>\ Toplevel.level: Toplevel.state -> int\ +\<^item> \<^ML>\ Toplevel.context_of: Toplevel.state -> Proof.context\ +\<^item> \<^ML>\ Toplevel.generic_theory_of: Toplevel.state -> generic_theory\ +\<^item> \<^ML>\ Toplevel.theory_of: Toplevel.state -> theory\ +\<^item> \<^ML>\ Toplevel.proof_of: Toplevel.state -> Proof.state\ +\<^item> \<^ML>\ Toplevel.presentation_context: Toplevel.state -> Proof.context\ +\<^item> ... \ -ML\ - Toplevel.theory_toplevel: theory -> Toplevel.state; - Toplevel.init_toplevel: unit -> Toplevel.state; - Toplevel.is_toplevel: Toplevel.state -> bool; - Toplevel.is_theory: Toplevel.state -> bool; - Toplevel.is_proof: Toplevel.state -> bool; - Toplevel.is_skipped_proof: Toplevel.state -> bool; - Toplevel.level: Toplevel.state -> int; - Toplevel.context_of: Toplevel.state -> Proof.context; - Toplevel.generic_theory_of: Toplevel.state -> generic_theory; - Toplevel.theory_of: Toplevel.state -> theory; - Toplevel.proof_of: Toplevel.state -> Proof.state; - Toplevel.presentation_context: Toplevel.state -> Proof.context; - (* ... *) \ text\ The extensibility of Isabelle as a system framework depends on a number of tables, into which various concepts commands, ML-antiquotations, text-antiquotations, cartouches, ... can be entered via a late-binding on the fly. - A paradigmatic example is the @{ML "Outer_Syntax.command"}-operation, which --- + A paradigmatic example is the \<^ML>\Outer_Syntax.command\-operation, which --- representing in itself a toplevel system transition --- allows to define a new command section and bind its syntax and semantics at a specific keyword. - Calling @{ML "Outer_Syntax.command"} - creates an implicit @{ML Theory.setup} with an entry for a call-back function, which happens + Calling \<^ML>\Outer_Syntax.command\ + creates an implicit \<^ML>\Theory.setup\ with an entry for a call-back function, which happens to be a parser that must have as side-effect a Toplevel-transition-transition. - Registers @{ML_type "Toplevel.transition -> Toplevel.transition"} parsers to the - Isar interpreter.\ + Registers \<^ML_type>\Toplevel.transition -> Toplevel.transition\ parsers to the + Isar interpreter. + + The global type of this key function for extending the Isar toplevel is, together + with a few query operations on the state of the toplevel: + \<^item> \<^ML>\Outer_Syntax.command : Outer_Syntax.command_keyword -> string -> + (Toplevel.transition -> Toplevel.transition) parser -> unit\, + \<^item> \<^ML>\Document.state : unit -> Document.state\, giving the state as a "collection of named + nodes, each consisting of an editable list of commands, associated with asynchronous + execution process, + \<^item> \<^ML>\Session.get_keywords : unit -> Keyword.keywords\, this looks to be really session global, + \<^item> \<^ML>\Thy_Header.get_keywords : theory -> Keyword.keywords\ + +\ -ML\ Outer_Syntax.command : Outer_Syntax.command_keyword -> string -> - (Toplevel.transition -> Toplevel.transition) parser -> unit;\ +subsubsection*[ex1137::example]\A paradigmatic example: \<^theory_text>\text\\ +text\ + @{ML [display]\ -text\A paradigmatic example: "text" is defined by: \ - -(* --- commented out since this code is not re-executable -val _ = Outer_Syntax.command ("text", @{here}) "formal comment (primary style)" - (Parse.opt_target -- Parse.document_source >> Thy_Output.document_command {markdown = true}); -*) - + (Parse.opt_target -- Parse.document_source >> Pure_Syn.document_command {markdown = true}) + \} +\ text\Here are a few queries relevant for the global config of the isar engine:\ ML\ Document.state();\ @@ -1142,7 +1150,6 @@ ML\ Thy_Header.get_keywords @{theory};(* this looks to be really theory gl - subsection*[transmgt::technical] \Transaction Management in the Isar-Engine : The Toplevel \ ML\Toplevel.exit: Toplevel.transition -> Toplevel.transition; @@ -1405,14 +1412,14 @@ text\A \<^verbatim>\.thy\ file consists of a \<^emph>\h information (so: practically excluding any form of text antiquotation (see above)). The context-definition contains an \<^emph>\import\ and a \<^emph>\keyword\ section; for example: - \begin{verbatim} + @{theory_text [display] \ theory Isa_DOF (* Isabelle Document Ontology Framework *) imports Main RegExpInterface (* Interface to functional regular automata for monitoring *) Assert keywords "+=" ":=" "accepts" "rejects" - \end{verbatim} + \} where \<^verbatim>\Isa_DOF\ is the abstract name of the text-file, \<^verbatim>\Main\ etc. refer to imported text files (recall that the import relation must be acyclic). \<^emph>\keyword\s are used to separate commands form each other;