# HG changeset patch # User huffman # Date 1319039125 -7200 # Node ID 2825ce94fd4d1d345d554c9064266c65f6170c25 # Parent 5e4a1270c000343bf676dd5f2d9a48171fc9c679# Parent e3c13fa443efe8e3b9f9ef790ca8fe53e8660c32 merged diff -r 5e4a1270c000 -r 2825ce94fd4d Admin/isatest/isatest-stats --- a/Admin/isatest/isatest-stats Tue Oct 18 15:19:06 2011 +0200 +++ b/Admin/isatest/isatest-stats Wed Oct 19 17:45:25 2011 +0200 @@ -8,161 +8,177 @@ PLATFORMS="at-poly at-poly-test afp at64-poly cygwin-poly-e mac-poly-M2 mac-poly-M4 mac-poly64-M2 mac-poly64-M4 mac-poly-M8 mac-poly64-M8 at64-poly-5.1-para at-mac-poly-5.1-para at-sml-dev" -ISABELLE_SESSIONS="\ - HOL-Auth \ - HOL-Bali \ - HOL-Boogie-Examples \ - HOL-Decision_Procs \ - HOL-Hahn_Banach \ - HOL-Hoare \ - HOL-Hoare_Parallel \ - HOL-IMPP \ - HOL-IOA \ - HOL-Imperative_HOL \ - HOL-Import \ - HOL-Induct \ - HOL-Isar_Examples \ - HOL-Lattice \ - HOL-Library-Codegenerator_Test \ - HOL-Matrix \ - HOL-Metis_Examples \ - HOL-MicroJava \ - HOL-Mirabelle \ - HOL-Mutabelle \ - HOL-NanoJava \ - HOL-Nitpick_Examples \ +ISABELLE_SESSIONS=" + HOL + HOL-Main + HOL-Plain + HOL-Base + HOL-Library + HOL-Algebra + HOL-Auth + HOL-Bali + HOL-Boogie + HOL-Boogie-Examples + HOL-Decision_Procs + HOL-Hahn_Banach + HOL-Hoare + HOL-Hoare_Parallel + HOL-IMP + HOL-IMPP + HOL-IOA + HOL-Imperative_HOL + HOL-Import + HOL-Induct + HOL-Isar_Examples + HOL-Lattice + HOL-Library-Codegenerator_Test + HOL-Matrix + HOL-Metis_Examples + HOL-MicroJava + HOL-Mirabelle + HOL-Multivariate_Analysis + HOL-Mutabelle + HOL-NSA + HOL-NanoJava + HOL-Nitpick_Examples + HOL-Nominal HOL-Nominal-Examples - HOL-Number_Theory \ - HOL-Old_Number_Theory \ - HOL-Predicate_Compile_Examples \ + HOL-Number_Theory + HOL-Old_Number_Theory + HOL-Predicate_Compile_Examples HOL-Probability - HOL-Prolog \ - HOL-Proofs-Extraction \ - HOL-Proofs-Lambda \ - HOL-Proofs-ex \ - HOL-Quotient_Examples \ - HOL-SET_Protocol \ - HOL-SPARK-Examples \ - HOL-SPARK-Manual \ - HOL-Statespace \ - HOL-TPTP \ - HOL-UNITY \ - HOL-Unix \ - HOL-Word-Examples \ - HOL-Word-SMT_Examples \ + HOL-Prolog + HOL-Proofs + HOL-Proofs-Extraction + HOL-Proofs-Lambda + HOL-Proofs-ex + HOL-Quotient_Examples + HOL-SET_Protocol + HOL-SPARK + HOL-SPARK-Examples + HOL-SPARK-Manual + HOL-Statespace + HOL-TPTP + HOL-UNITY + HOL-Unix + HOL-Word + HOL-Word-Examples + HOL-Word-SMT_Examples HOL-ZF - HOL-ex \ - HOLCF-FOCUS \ - HOLCF-IMP \ - HOLCF-Library \ - HOLCF-Tutorial \ - HOLCF-ex \ - IOA-ABP \ - IOA-NTP \ - IOA-Storage \ - IOA-ex \ - TLA-Buffer \ - TLA-Inc \ + HOL-ex + HOL4 + HOLCF + HOLCF-FOCUS + HOLCF-IMP + HOLCF-Library + HOLCF-Tutorial + HOLCF-ex + IOA + IOA-ABP + IOA-NTP + IOA-Storage + IOA-ex + TLA + TLA-Buffer + TLA-Inc TLA-Memory" -AFP_SESSIONS="\ - ArrowImpossibilityGS \ - Coinductive \ - CoreC++ \ - HOL-AVL-Trees \ - HOL-Abstract-Hoare-Logics \ - HOL-Abstract-Rewriting \ - HOL-BinarySearchTree \ - HOL-Binomial-Heaps \ - HOL-Binomial-Queues \ - HOL-BytecodeLogicJmlTypes \ - HOL-Category \ - HOL-Category2 \ - HOL-Cauchy \ - HOL-ClockSynchInst \ - HOL-CofGroups \ - HOL-Collections \ - HOL-Compiling-Exceptions-Correctly \ - HOL-Completeness \ - HOL-DPT-SAT-Solver \ - HOL-DataRefinementIBP \ - HOL-Depth-First-Search \ - HOL-DiskPaxos \ - HOL-Example-Submission \ - HOL-FFT \ - HOL-FOL-Fitting \ - HOL-FeatherweightJava \ - HOL-FileRefinement \ - HOL-FinFun \ - HOL-Finger-Trees \ - HOL-Flyspeck-Tame \ - HOL-Free-Boolean-Algebra \ - HOL-Free-Groups \ - HOL-FunWithFunctions \ - HOL-FunWithTilings \ - HOL-Functional-Automata \ - HOL-Gauss-Jordan-Elim-Fun \ - HOL-GenClock \ - HOL-General-Triangle \ - HOL-GraphMarkingIBP \ - HOL-HotelKeyCards \ - HOL-Huffman \ - HOL-Integration \ - HOL-JiveDataStoreModel \ - HOL-KBPs \ - HOL-Lazy-Lists-II \ - HOL-LightweightJava \ - HOL-List-Index \ - HOL-Locally-Nameless-Sigma \ - HOL-Marriage \ - HOL-Matrix \ - HOL-Max-Card-Matching \ - HOL-MiniML \ - HOL-MuchAdoAboutTwo \ - HOL-Multivariate_Analysis \ - HOL-Myhill-Nerode \ - HOL-Nominal \ - HOL-Nominal-Lam-ml-Normalization \ - HOL-Nominal-SequentInvertibility \ - HOL-Ordinal \ - HOL-Ordinals_and_Cardinals \ - HOL-POPLmark-deBruijn \ - HOL-Perfect-Number-Thm \ - HOL-Polynomials \ - HOL-Presburger-Automata \ - HOL-Program-Conflict-Analysis \ - HOL-Ramsey-Infinite \ - HOL-Recursion-Theory-I \ - HOL-Regular-Sets \ - HOL-Robbins-Conjecture \ - HOL-SATSolverVerification \ - HOL-SIFPL \ - HOL-SenSocialChoice \ - HOL-Statecharts \ - HOL-Topology \ - HOL-Transitive-Closure \ - HOL-Tree-Automata \ - HOL-Verified-Prover \ - HOL-Word \ - HOL-Word-RIPEMD-160-SPARK \ - HOLCF \ - HOLCF-Shivers-CFA \ - HOLCF-Stream-Fusion \ - HOLCF-WorkerWrapper \ - HRB-Slicing \ - HRB-Slicing-InformationFlowSlicing \ - Jinja \ - Jinja \ - LatticeProperties \ - LatticeProperties-MonoBoolTranAlgebra \ - LatticeProperties-PseudoHoops \ - Lower_Semicontinuous \ - NormByEval \ - Simpl \ - Simpl-BDD \ - Slicing \ - Slicing \ - Slicing-InformationFlowSlicing \ +AFP_SESSIONS=" + ArrowImpossibilityGS + Coinductive + CoreC++ + HOL-AVL-Trees + HOL-Abstract-Hoare-Logics + HOL-Abstract-Rewriting + HOL-BinarySearchTree + HOL-Binomial-Heaps + HOL-Binomial-Queues + HOL-BytecodeLogicJmlTypes + HOL-Category + HOL-Category2 + HOL-Cauchy + HOL-ClockSynchInst + HOL-CofGroups + HOL-Collections + HOL-Compiling-Exceptions-Correctly + HOL-Completeness + HOL-DPT-SAT-Solver + HOL-DataRefinementIBP + HOL-Depth-First-Search + HOL-DiskPaxos + HOL-Example-Submission + HOL-FFT + HOL-FOL-Fitting + HOL-FeatherweightJava + HOL-FileRefinement + HOL-FinFun + HOL-Finger-Trees + HOL-Flyspeck-Tame + HOL-Free-Boolean-Algebra + HOL-Free-Groups + HOL-FunWithFunctions + HOL-FunWithTilings + HOL-Functional-Automata + HOL-Gauss-Jordan-Elim-Fun + HOL-GenClock + HOL-General-Triangle + HOL-GraphMarkingIBP + HOL-HotelKeyCards + HOL-Huffman + HOL-Integration + HOL-JiveDataStoreModel + HOL-KBPs + HOL-Lazy-Lists-II + HOL-LightweightJava + HOL-List-Index + HOL-Locally-Nameless-Sigma + HOL-Marriage + HOL-Matrix + HOL-Max-Card-Matching + HOL-MiniML + HOL-MuchAdoAboutTwo + HOL-Multivariate_Analysis + HOL-Myhill-Nerode + HOL-Nominal + HOL-Nominal-Lam-ml-Normalization + HOL-Nominal-SequentInvertibility + HOL-Ordinal + HOL-Ordinals_and_Cardinals + HOL-POPLmark-deBruijn + HOL-Perfect-Number-Thm + HOL-Polynomials + HOL-Presburger-Automata + HOL-Program-Conflict-Analysis + HOL-Ramsey-Infinite + HOL-Recursion-Theory-I + HOL-Regular-Sets + HOL-Robbins-Conjecture + HOL-SATSolverVerification + HOL-SIFPL + HOL-SenSocialChoice + HOL-Statecharts + HOL-Topology + HOL-Transitive-Closure + HOL-Tree-Automata + HOL-Verified-Prover + HOL-Word + HOL-Word-RIPEMD-160-SPARK + HOLCF + HOLCF-Shivers-CFA + HOLCF-Stream-Fusion + HOLCF-WorkerWrapper + HRB-Slicing + HRB-Slicing-InformationFlowSlicing + Jinja + LatticeProperties + LatticeProperties-MonoBoolTranAlgebra + LatticeProperties-PseudoHoops + Lower_Semicontinuous + NormByEval + Simpl + Simpl-BDD + Slicing + Slicing-InformationFlowSlicing VolpanoSmith" diff -r 5e4a1270c000 -r 2825ce94fd4d Admin/mira.py --- a/Admin/mira.py Tue Oct 18 15:19:06 2011 +0200 +++ b/Admin/mira.py Wed Oct 19 17:45:25 2011 +0200 @@ -18,7 +18,6 @@ from mira import schedule, misc from mira.environment import scheduler - # build and evaluation tools default_usedir_options = "$ISABELLE_USEDIR_OPTIONS -d pdf -g true -i true -t true" @@ -67,6 +66,12 @@ writer.close() +def isabelle_getenv(isabelle_home, var): + + _, out = env.run_process('%s/bin/isabelle' % isabelle_home, 'getenv', var) + return out.split('=', 1)[1].strip() + + def extract_isabelle_run_timing(logdata): def to_secs(h, m, s): @@ -99,6 +104,18 @@ return summary +def extract_image_size(isabelle_home): + + isabelle_output = isabelle_getenv(isabelle_home, 'ISABELLE_OUTPUT') + return dict((p, path.getsize(path.join(isabelle_output, p))) for p in os.listdir(isabelle_output) if p != "log") + +def extract_report_data(isabelle_home, logdata): + + return { + 'timing': extract_isabelle_run_timing(logdata), + 'image_size': extract_image_size(isabelle_home) } + + @tool def import_isatest_log(env, conf, logfile): @@ -159,8 +176,9 @@ (return_code, log) = isabelle_usedir(env, isabelle_home, '-b', base, img) result = path.join(isabelle_home, 'heaps') + return (return_code == 0, extract_isabelle_run_summary(log), - {'timing': extract_isabelle_run_timing(log)}, {'log': log}, result) + extract_report_data(isabelle_home, log), {'log': log}, result) def isabelle_make(subdir, env, case, paths, dep_paths, playground, usedir_options=default_usedir_options, @@ -175,8 +193,9 @@ (return_code, log) = env.run_process('%s/bin/isabelle' % isabelle_home, 'make', '-k', target) result = path.join(isabelle_home, 'heaps') if keep_results else None + return (return_code == 0, extract_isabelle_run_summary(log), - {'timing': extract_isabelle_run_timing(log)}, {'log': log}, result) + extract_report_data(isabelle_home, log), {'log': log}, result) def isabelle_makeall(env, case, paths, dep_paths, playground, usedir_options=default_usedir_options, @@ -204,7 +223,7 @@ (return_code, log) = env.run_process('%s/bin/isabelle' % isabelle_home, 'makeall', '-k', *(make_options + (target,))) return (return_code == 0, extract_isabelle_run_summary(log), - {'timing': extract_isabelle_run_timing(log)}, {'log': log}, None) + extract_report_data(isabelle_home, log), {'log': log}, None) def make_pure(env, case, paths, dep_paths, playground, more_settings=''): diff -r 5e4a1270c000 -r 2825ce94fd4d NEWS --- a/NEWS Tue Oct 18 15:19:06 2011 +0200 +++ b/NEWS Wed Oct 19 17:45:25 2011 +0200 @@ -9,6 +9,9 @@ * Obsolete command 'types' has been discontinued. Use 'type_synonym' instead. INCOMPATIBILITY. +* Ancient code generator for SML and its commands 'code_module', + 'code_library', 'consts_code', 'types_code' have been discontinued. + Use commands of the generic code generator instead. INCOMPATIBILITY. *** HOL *** @@ -25,6 +28,7 @@ zadd_commute ~> add_commute zadd_assoc ~> add_assoc zadd_left_commute ~> add_left_commute + zadd_ac ~> add_ac zmult_ac ~> mult_ac zadd_0 ~> add_0_left zadd_0_right ~> add_0_right diff -r 5e4a1270c000 -r 2825ce94fd4d doc-src/IsarRef/Thy/HOL_Specific.thy --- a/doc-src/IsarRef/Thy/HOL_Specific.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/doc-src/IsarRef/Thy/HOL_Specific.thy Wed Oct 19 17:45:25 2011 +0200 @@ -1724,17 +1724,12 @@ A more efficient way of executing specifications is to translate them into a functional programming language such as ML. - Isabelle provides two generic frameworks to support code generation + Isabelle provides a generic framework to support code generation from executable specifications. Isabelle/HOL instantiates these - mechanisms in a way that is amenable to end-user applications. -*} - - -subsection {* The new code generator (F. Haftmann) *} - -text {* This framework generates code from functional programs - (including overloading using type classes) to SML \cite{SML}, OCaml - \cite{OCaml}, Haskell \cite{haskell-revised-report} and Scala + mechanisms in a way that is amenable to end-user applications. Code + can be generated for functional programs (including overloading + using type classes) targeting SML \cite{SML}, OCaml \cite{OCaml}, + Haskell \cite{haskell-revised-report} and Scala \cite{scala-overview-tech-report}. Conceptually, code generation is split up in three steps: \emph{selection} of code theorems, \emph{translation} into an abstract executable view and @@ -1956,242 +1951,6 @@ *} -subsection {* The old code generator (S. Berghofer) *} - -text {* This framework generates code from both functional and - relational programs to SML, as explained below. - - \begin{matharray}{rcl} - @{command_def "code_module"} & : & @{text "theory \ theory"} \\ - @{command_def "code_library"} & : & @{text "theory \ theory"} \\ - @{command_def "consts_code"} & : & @{text "theory \ theory"} \\ - @{command_def "types_code"} & : & @{text "theory \ theory"} \\ - @{attribute_def code} & : & @{text attribute} \\ - \end{matharray} - - @{rail " - ( @@{command code_module} | @@{command code_library} ) modespec? @{syntax name}? \\ - ( @'file' name ) ? ( @'imports' ( @{syntax name} + ) ) ? \\ - @'contains' ( ( @{syntax name} '=' @{syntax term} ) + | @{syntax term} + ) - ; - - modespec: '(' ( @{syntax name} * ) ')' - ; - - @@{command (HOL) consts_code} (codespec +) - ; - - codespec: const template attachment ? - ; - - @@{command (HOL) types_code} (tycodespec +) - ; - - tycodespec: @{syntax name} template attachment ? - ; - - const: @{syntax term} - ; - - template: '(' @{syntax string} ')' - ; - - attachment: 'attach' modespec? '{' @{syntax text} '}' - ; - - @@{attribute code} name? - "} -*} - - -subsubsection {* Invoking the code generator *} - -text {* The code generator is invoked via the @{command code_module} - and @{command code_library} commands, which correspond to - \emph{incremental} and \emph{modular} code generation, respectively. - - \begin{description} - - \item [Modular] For each theory, an ML structure is generated, - containing the code generated from the constants defined in this - theory. - - \item [Incremental] All the generated code is emitted into the same - structure. This structure may import code from previously generated - structures, which can be specified via @{keyword "imports"}. - Moreover, the generated structure may also be referred to in later - invocations of the code generator. - - \end{description} - - After the @{command code_module} and @{command code_library} - keywords, the user may specify an optional list of ``modes'' in - parentheses. These can be used to instruct the code generator to - emit additional code for special purposes, e.g.\ functions for - converting elements of generated datatypes to Isabelle terms, or - test data generators. The list of modes is followed by a module - name. The module name is optional for modular code generation, but - must be specified for incremental code generation. - - The code can either be written to a file, in which case a file name - has to be specified after the @{keyword "file"} keyword, or be loaded - directly into Isabelle's ML environment. In the latter case, the - @{command ML} theory command can be used to inspect the results - interactively, for example. - - The terms from which to generate code can be specified after the - @{keyword "contains"} keyword, either as a list of bindings, or just - as a list of terms. In the latter case, the code generator just - produces code for all constants and types occuring in the term, but - does not bind the compiled terms to ML identifiers. - - Here is an example: -*} - -code_module Test -contains test = "foldl op + (0 :: int) [1, 2, 3, 4, 5]" - -text {* \noindent This binds the result of compiling the given term to - the ML identifier @{ML Test.test}. *} - -ML {* @{assert} (Test.test = 15) *} - - -subsubsection {* Configuring the code generator *} - -text {* When generating code for a complex term, the code generator - recursively calls itself for all subterms. When it arrives at a - constant, the default strategy of the code generator is to look up - its definition and try to generate code for it. Constants which - have no definitions that are immediately executable, may be - associated with a piece of ML code manually using the @{command_ref - consts_code} command. It takes a list whose elements consist of a - constant (given in usual term syntax -- an explicit type constraint - accounts for overloading), and a mixfix template describing the ML - code. The latter is very much the same as the mixfix templates used - when declaring new constants. The most notable difference is that - terms may be included in the ML template using antiquotation - brackets @{verbatim "{"}@{verbatim "*"}~@{text "..."}~@{verbatim - "*"}@{verbatim "}"}. - - A similar mechanism is available for types: @{command_ref - types_code} associates type constructors with specific ML code. - - For example, the following declarations copied from @{file - "~~/src/HOL/Product_Type.thy"} describe how the product type of - Isabelle/HOL should be compiled to ML. *} - -typedecl ('a, 'b) prod -consts Pair :: "'a \ 'b \ ('a, 'b) prod" - -types_code prod ("(_ */ _)") -consts_code Pair ("(_,/ _)") - -text {* Sometimes, the code associated with a constant or type may - need to refer to auxiliary functions, which have to be emitted when - the constant is used. Code for such auxiliary functions can be - declared using @{keyword "attach"}. For example, the @{const wfrec} - function can be implemented as follows: -*} - -consts_code wfrec ("\wfrec?") (* FIXME !? *) -attach {* fun wfrec f x = f (wfrec f) x *} - -text {* If the code containing a call to @{const wfrec} resides in an - ML structure different from the one containing the function - definition attached to @{const wfrec}, the name of the ML structure - (followed by a ``@{text "."}'') is inserted in place of ``@{text - "\"}'' in the above template. The ``@{text "?"}'' means that - the code generator should ignore the first argument of @{const - wfrec}, i.e.\ the termination relation, which is usually not - executable. - - \medskip Another possibility of configuring the code generator is to - register theorems to be used for code generation. Theorems can be - registered via the @{attribute code} attribute. It takes an optional - name as an argument, which indicates the format of the - theorem. Currently supported formats are equations (this is the - default when no name is specified) and horn clauses (this is - indicated by the name \texttt{ind}). The left-hand sides of - equations may only contain constructors and distinct variables, - whereas horn clauses must have the same format as introduction rules - of inductive definitions. - - The following example specifies three equations from which to - generate code for @{term "op <"} on natural numbers (see also - @{"file" "~~/src/HOL/Nat.thy"}). *} - -lemma [code]: "(Suc m < Suc n) = (m < n)" - and [code]: "((n::nat) < 0) = False" - and [code]: "(0 < Suc n) = True" by simp_all - - -subsubsection {* Specific HOL code generators *} - -text {* The basic code generator framework offered by Isabelle/Pure - has already been extended with additional code generators for - specific HOL constructs. These include datatypes, recursive - functions and inductive relations. The code generator for inductive - relations can handle expressions of the form @{text "(t\<^sub>1, \, t\<^sub>n) \ - r"}, where @{text "r"} is an inductively defined relation. If at - least one of the @{text "t\<^sub>i"} is a dummy pattern ``@{text "_"}'', - the above expression evaluates to a sequence of possible answers. If - all of the @{text "t\<^sub>i"} are proper terms, the expression evaluates - to a boolean value. - - The following example demonstrates this for beta-reduction on lambda - terms (see also @{"file" "~~/src/HOL/Proofs/Lambda/Lambda.thy"}). -*} - -datatype dB = - Var nat - | App dB dB (infixl "\" 200) - | Abs dB - -primrec lift :: "dB \ nat \ dB" -where - "lift (Var i) k = (if i < k then Var i else Var (i + 1))" - | "lift (s \ t) k = lift s k \ lift t k" - | "lift (Abs s) k = Abs (lift s (k + 1))" - -primrec subst :: "dB \ dB \ nat \ dB" ("_[_'/_]" [300, 0, 0] 300) -where - "(Var i)[s/k] = - (if k < i then Var (i - 1) else if i = k then s else Var i)" - | "(t \ u)[s/k] = t[s/k] \ u[s/k]" - | "(Abs t)[s/k] = Abs (t[lift s 0 / k+1])" - -inductive beta :: "dB \ dB \ bool" (infixl "\\<^sub>\" 50) -where - beta: "Abs s \ t \\<^sub>\ s[t/0]" - | appL: "s \\<^sub>\ t \ s \ u \\<^sub>\ t \ u" - | appR: "s \\<^sub>\ t \ u \ s \\<^sub>\ u \ t" - | abs: "s \\<^sub>\ t \ Abs s \\<^sub>\ Abs t" - -code_module Test -contains - test1 = "Abs (Var 0) \ Var 0 \\<^sub>\ Var 0" - test2 = "Abs (Abs (Var 0 \ Var 0) \ (Abs (Var 0) \ Var 0)) \\<^sub>\ _" - -text {* - In the above example, @{ML Test.test1} evaluates to a boolean, - whereas @{ML Test.test2} is a lazy sequence whose elements can be - inspected separately. -*} - -ML {* @{assert} Test.test1 *} -ML {* val results = DSeq.list_of Test.test2 *} -ML {* @{assert} (length results = 2) *} - -text {* - \medskip The theory underlying the HOL code generator is described - more detailed in \cite{Berghofer-Nipkow:2002}. More examples that - illustrate the usage of the code generator can be found e.g.\ in - @{"file" "~~/src/HOL/MicroJava/J/JListExample.thy"} and @{"file" - "~~/src/HOL/MicroJava/JVM/JVMListExample.thy"}. -*} - - section {* Definition by specification \label{sec:hol-specification} *} text {* diff -r 5e4a1270c000 -r 2825ce94fd4d doc-src/IsarRef/Thy/document/HOL_Specific.tex --- a/doc-src/IsarRef/Thy/document/HOL_Specific.tex Tue Oct 18 15:19:06 2011 +0200 +++ b/doc-src/IsarRef/Thy/document/HOL_Specific.tex Wed Oct 19 17:45:25 2011 +0200 @@ -2523,20 +2523,12 @@ A more efficient way of executing specifications is to translate them into a functional programming language such as ML. - Isabelle provides two generic frameworks to support code generation + Isabelle provides a generic framework to support code generation from executable specifications. Isabelle/HOL instantiates these - mechanisms in a way that is amenable to end-user applications.% -\end{isamarkuptext}% -\isamarkuptrue% -% -\isamarkupsubsection{The new code generator (F. Haftmann)% -} -\isamarkuptrue% -% -\begin{isamarkuptext}% -This framework generates code from functional programs - (including overloading using type classes) to SML \cite{SML}, OCaml - \cite{OCaml}, Haskell \cite{haskell-revised-report} and Scala + mechanisms in a way that is amenable to end-user applications. Code + can be generated for functional programs (including overloading + using type classes) targeting SML \cite{SML}, OCaml \cite{OCaml}, + Haskell \cite{haskell-revised-report} and Scala \cite{scala-overview-tech-report}. Conceptually, code generation is split up in three steps: \emph{selection} of code theorems, \emph{translation} into an abstract executable view and @@ -2989,388 +2981,6 @@ \end{isamarkuptext}% \isamarkuptrue% % -\isamarkupsubsection{The old code generator (S. Berghofer)% -} -\isamarkuptrue% -% -\begin{isamarkuptext}% -This framework generates code from both functional and - relational programs to SML, as explained below. - - \begin{matharray}{rcl} - \indexdef{}{command}{code\_module}\hypertarget{command.code-module}{\hyperlink{command.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\ - \indexdef{}{command}{code\_library}\hypertarget{command.code-library}{\hyperlink{command.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\ - \indexdef{}{command}{consts\_code}\hypertarget{command.consts-code}{\hyperlink{command.consts-code}{\mbox{\isa{\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\ - \indexdef{}{command}{types\_code}\hypertarget{command.types-code}{\hyperlink{command.types-code}{\mbox{\isa{\isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}}}}} & : & \isa{{\isaliteral{22}{\isachardoublequote}}theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ theory{\isaliteral{22}{\isachardoublequote}}} \\ - \indexdef{}{attribute}{code}\hypertarget{attribute.code}{\hyperlink{attribute.code}{\mbox{\isa{code}}}} & : & \isa{attribute} \\ - \end{matharray} - - \begin{railoutput} -\rail@begin{11}{} -\rail@bar -\rail@term{\hyperlink{command.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}}}[] -\rail@nextbar{1} -\rail@term{\hyperlink{command.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}}}[] -\rail@endbar -\rail@bar -\rail@nextbar{1} -\rail@nont{\isa{modespec}}[] -\rail@endbar -\rail@bar -\rail@nextbar{1} -\rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[] -\rail@endbar -\rail@cr{3} -\rail@bar -\rail@nextbar{4} -\rail@term{\isa{\isakeyword{file}}}[] -\rail@nont{\isa{name}}[] -\rail@endbar -\rail@bar -\rail@nextbar{4} -\rail@term{\isa{\isakeyword{imports}}}[] -\rail@plus -\rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[] -\rail@nextplus{5} -\rail@endplus -\rail@endbar -\rail@cr{7} -\rail@term{\isa{\isakeyword{contains}}}[] -\rail@bar -\rail@plus -\rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[] -\rail@term{\isa{{\isaliteral{3D}{\isacharequal}}}}[] -\rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[] -\rail@nextplus{8} -\rail@endplus -\rail@nextbar{9} -\rail@plus -\rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[] -\rail@nextplus{10} -\rail@endplus -\rail@endbar -\rail@end -\rail@begin{2}{\isa{modespec}} -\rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[] -\rail@plus -\rail@nextplus{1} -\rail@cnont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[] -\rail@endplus -\rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[] -\rail@end -\rail@begin{2}{} -\rail@term{\hyperlink{command.HOL.consts-code}{\mbox{\isa{\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}}}}}[] -\rail@plus -\rail@nont{\isa{codespec}}[] -\rail@nextplus{1} -\rail@endplus -\rail@end -\rail@begin{2}{\isa{codespec}} -\rail@nont{\isa{const}}[] -\rail@nont{\isa{template}}[] -\rail@bar -\rail@nextbar{1} -\rail@nont{\isa{attachment}}[] -\rail@endbar -\rail@end -\rail@begin{2}{} -\rail@term{\hyperlink{command.HOL.types-code}{\mbox{\isa{\isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}}}}}[] -\rail@plus -\rail@nont{\isa{tycodespec}}[] -\rail@nextplus{1} -\rail@endplus -\rail@end -\rail@begin{2}{\isa{tycodespec}} -\rail@nont{\hyperlink{syntax.name}{\mbox{\isa{name}}}}[] -\rail@nont{\isa{template}}[] -\rail@bar -\rail@nextbar{1} -\rail@nont{\isa{attachment}}[] -\rail@endbar -\rail@end -\rail@begin{1}{\isa{const}} -\rail@nont{\hyperlink{syntax.term}{\mbox{\isa{term}}}}[] -\rail@end -\rail@begin{1}{\isa{template}} -\rail@term{\isa{{\isaliteral{28}{\isacharparenleft}}}}[] -\rail@nont{\hyperlink{syntax.string}{\mbox{\isa{string}}}}[] -\rail@term{\isa{{\isaliteral{29}{\isacharparenright}}}}[] -\rail@end -\rail@begin{2}{\isa{attachment}} -\rail@term{\isa{attach}}[] -\rail@bar -\rail@nextbar{1} -\rail@nont{\isa{modespec}}[] -\rail@endbar -\rail@term{\isa{{\isaliteral{7B}{\isacharbraceleft}}}}[] -\rail@nont{\hyperlink{syntax.text}{\mbox{\isa{text}}}}[] -\rail@term{\isa{{\isaliteral{7D}{\isacharbraceright}}}}[] -\rail@end -\rail@begin{2}{} -\rail@term{\hyperlink{attribute.code}{\mbox{\isa{code}}}}[] -\rail@bar -\rail@nextbar{1} -\rail@nont{\isa{name}}[] -\rail@endbar -\rail@end -\end{railoutput}% -\end{isamarkuptext}% -\isamarkuptrue% -% -\isamarkupsubsubsection{Invoking the code generator% -} -\isamarkuptrue% -% -\begin{isamarkuptext}% -The code generator is invoked via the \hyperlink{command.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}} - and \hyperlink{command.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}} commands, which correspond to - \emph{incremental} and \emph{modular} code generation, respectively. - - \begin{description} - - \item [Modular] For each theory, an ML structure is generated, - containing the code generated from the constants defined in this - theory. - - \item [Incremental] All the generated code is emitted into the same - structure. This structure may import code from previously generated - structures, which can be specified via \hyperlink{keyword.imports}{\mbox{\isa{\isakeyword{imports}}}}. - Moreover, the generated structure may also be referred to in later - invocations of the code generator. - - \end{description} - - After the \hyperlink{command.code-module}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}}}} and \hyperlink{command.code-library}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}library}}}} - keywords, the user may specify an optional list of ``modes'' in - parentheses. These can be used to instruct the code generator to - emit additional code for special purposes, e.g.\ functions for - converting elements of generated datatypes to Isabelle terms, or - test data generators. The list of modes is followed by a module - name. The module name is optional for modular code generation, but - must be specified for incremental code generation. - - The code can either be written to a file, in which case a file name - has to be specified after the \hyperlink{keyword.file}{\mbox{\isa{\isakeyword{file}}}} keyword, or be loaded - directly into Isabelle's ML environment. In the latter case, the - \hyperlink{command.ML}{\mbox{\isa{\isacommand{ML}}}} theory command can be used to inspect the results - interactively, for example. - - The terms from which to generate code can be specified after the - \hyperlink{keyword.contains}{\mbox{\isa{\isakeyword{contains}}}} keyword, either as a list of bindings, or just - as a list of terms. In the latter case, the code generator just - produces code for all constants and types occuring in the term, but - does not bind the compiled terms to ML identifiers. - - Here is an example:% -\end{isamarkuptext}% -\isamarkuptrue% -\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}\isamarkupfalse% -\ Test\isanewline -\isakeyword{contains}\ test\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{22}{\isachardoublequoteopen}}foldl\ op\ {\isaliteral{2B}{\isacharplus}}\ {\isaliteral{28}{\isacharparenleft}}{\isadigit{0}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ int{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{2}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{3}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{4}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{5}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{22}{\isachardoublequoteclose}}% -\begin{isamarkuptext}% -\noindent This binds the result of compiling the given term to - the ML identifier \verb|Test.test|.% -\end{isamarkuptext}% -\isamarkuptrue% -% -\isadelimML -% -\endisadelimML -% -\isatagML -\isacommand{ML}\isamarkupfalse% -\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ % -\isaantiq -assert{}% -\endisaantiq -\ {\isaliteral{28}{\isacharparenleft}}Test{\isaliteral{2E}{\isachardot}}test\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{1}}{\isadigit{5}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}% -\endisatagML -{\isafoldML}% -% -\isadelimML -% -\endisadelimML -% -\isamarkupsubsubsection{Configuring the code generator% -} -\isamarkuptrue% -% -\begin{isamarkuptext}% -When generating code for a complex term, the code generator - recursively calls itself for all subterms. When it arrives at a - constant, the default strategy of the code generator is to look up - its definition and try to generate code for it. Constants which - have no definitions that are immediately executable, may be - associated with a piece of ML code manually using the \indexref{}{command}{consts\_code}\hyperlink{command.consts-code}{\mbox{\isa{\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}}}} command. It takes a list whose elements consist of a - constant (given in usual term syntax -- an explicit type constraint - accounts for overloading), and a mixfix template describing the ML - code. The latter is very much the same as the mixfix templates used - when declaring new constants. The most notable difference is that - terms may be included in the ML template using antiquotation - brackets \verb|{|\verb|*|~\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2E}{\isachardot}}{\isaliteral{2E}{\isachardot}}{\isaliteral{2E}{\isachardot}}{\isaliteral{22}{\isachardoublequote}}}~\verb|*|\verb|}|. - - A similar mechanism is available for types: \indexref{}{command}{types\_code}\hyperlink{command.types-code}{\mbox{\isa{\isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}}}} associates type constructors with specific ML code. - - For example, the following declarations copied from \verb|~~/src/HOL/Product_Type.thy| describe how the product type of - Isabelle/HOL should be compiled to ML.% -\end{isamarkuptext}% -\isamarkuptrue% -\isacommand{typedecl}\isamarkupfalse% -\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{27}{\isacharprime}}a{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{27}{\isacharprime}}b{\isaliteral{29}{\isacharparenright}}\ prod\isanewline -\isacommand{consts}\isamarkupfalse% -\ Pair\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}b\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{27}{\isacharprime}}a{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{27}{\isacharprime}}b{\isaliteral{29}{\isacharparenright}}\ prod{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\isanewline -\isacommand{types{\isaliteral{5F}{\isacharunderscore}}code}\isamarkupfalse% -\ prod\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5F}{\isacharunderscore}}\ {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{2F}{\isacharslash}}\ {\isaliteral{5F}{\isacharunderscore}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}{\isaliteral{29}{\isacharparenright}}\isanewline -\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}\isamarkupfalse% -\ Pair\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{2C}{\isacharcomma}}{\isaliteral{2F}{\isacharslash}}\ {\isaliteral{5F}{\isacharunderscore}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}{\isaliteral{29}{\isacharparenright}}% -\begin{isamarkuptext}% -Sometimes, the code associated with a constant or type may - need to refer to auxiliary functions, which have to be emitted when - the constant is used. Code for such auxiliary functions can be - declared using \hyperlink{keyword.attach}{\mbox{\isa{\isakeyword{attach}}}}. For example, the \isa{wfrec} - function can be implemented as follows:% -\end{isamarkuptext}% -\isamarkuptrue% -\isacommand{consts{\isaliteral{5F}{\isacharunderscore}}code}\isamarkupfalse% -\ wfrec\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C6D6F64756C653E}{\isasymmodule}}wfrec{\isaliteral{3F}{\isacharquery}}{\isaliteral{22}{\isachardoublequoteclose}}{\isaliteral{29}{\isacharparenright}}\ \ \isanewline -\isakeyword{attach}\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ fun\ wfrec\ f\ x\ {\isaliteral{3D}{\isacharequal}}\ f\ {\isaliteral{28}{\isacharparenleft}}wfrec\ f{\isaliteral{29}{\isacharparenright}}\ x\ {\isaliteral{2A7D}{\isacharverbatimclose}}% -\begin{isamarkuptext}% -If the code containing a call to \isa{wfrec} resides in an - ML structure different from the one containing the function - definition attached to \isa{wfrec}, the name of the ML structure - (followed by a ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2E}{\isachardot}}{\isaliteral{22}{\isachardoublequote}}}'') is inserted in place of ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5C3C6D6F64756C653E}{\isasymmodule}}{\isaliteral{22}{\isachardoublequote}}}'' in the above template. The ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3F}{\isacharquery}}{\isaliteral{22}{\isachardoublequote}}}'' means that - the code generator should ignore the first argument of \isa{wfrec}, i.e.\ the termination relation, which is usually not - executable. - - \medskip Another possibility of configuring the code generator is to - register theorems to be used for code generation. Theorems can be - registered via the \hyperlink{attribute.code}{\mbox{\isa{code}}} attribute. It takes an optional - name as an argument, which indicates the format of the - theorem. Currently supported formats are equations (this is the - default when no name is specified) and horn clauses (this is - indicated by the name \texttt{ind}). The left-hand sides of - equations may only contain constructors and distinct variables, - whereas horn clauses must have the same format as introduction rules - of inductive definitions. - - The following example specifies three equations from which to - generate code for \isa{{\isaliteral{22}{\isachardoublequote}}op\ {\isaliteral{3C}{\isacharless}}{\isaliteral{22}{\isachardoublequote}}} on natural numbers (see also - \verb|~~/src/HOL/Nat.thy|).% -\end{isamarkuptext}% -\isamarkuptrue% -\isacommand{lemma}\isamarkupfalse% -\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}Suc\ m\ {\isaliteral{3C}{\isacharless}}\ Suc\ n{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}m\ {\isaliteral{3C}{\isacharless}}\ n{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ \isakeyword{and}\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{28}{\isacharparenleft}}n{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}nat{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3C}{\isacharless}}\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ False{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ \isakeyword{and}\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isadigit{0}}\ {\isaliteral{3C}{\isacharless}}\ Suc\ n{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ True{\isaliteral{22}{\isachardoublequoteclose}}% -\isadelimproof -\ % -\endisadelimproof -% -\isatagproof -\isacommand{by}\isamarkupfalse% -\ simp{\isaliteral{5F}{\isacharunderscore}}all% -\endisatagproof -{\isafoldproof}% -% -\isadelimproof -% -\endisadelimproof -% -\isamarkupsubsubsection{Specific HOL code generators% -} -\isamarkuptrue% -% -\begin{isamarkuptext}% -The basic code generator framework offered by Isabelle/Pure - has already been extended with additional code generators for - specific HOL constructs. These include datatypes, recursive - functions and inductive relations. The code generator for inductive - relations can handle expressions of the form \isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{28}{\isacharparenleft}}t\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ t\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C696E3E}{\isasymin}}\ r{\isaliteral{22}{\isachardoublequote}}}, where \isa{{\isaliteral{22}{\isachardoublequote}}r{\isaliteral{22}{\isachardoublequote}}} is an inductively defined relation. If at - least one of the \isa{{\isaliteral{22}{\isachardoublequote}}t\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} is a dummy pattern ``\isa{{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{22}{\isachardoublequote}}}'', - the above expression evaluates to a sequence of possible answers. If - all of the \isa{{\isaliteral{22}{\isachardoublequote}}t\isaliteral{5C3C5E7375623E}{}\isactrlsub i{\isaliteral{22}{\isachardoublequote}}} are proper terms, the expression evaluates - to a boolean value. - - The following example demonstrates this for beta-reduction on lambda - terms (see also \verb|~~/src/HOL/Proofs/Lambda/Lambda.thy|).% -\end{isamarkuptext}% -\isamarkuptrue% -\isacommand{datatype}\isamarkupfalse% -\ dB\ {\isaliteral{3D}{\isacharequal}}\isanewline -\ \ \ \ Var\ nat\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ App\ dB\ dB\ \ {\isaliteral{28}{\isacharparenleft}}\isakeyword{infixl}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C6465677265653E}{\isasymdegree}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isadigit{2}}{\isadigit{0}}{\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ Abs\ dB\isanewline -\isanewline -\isacommand{primrec}\isamarkupfalse% -\ lift\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ nat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ dB{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\isakeyword{where}\isanewline -\ \ \ \ {\isaliteral{22}{\isachardoublequoteopen}}lift\ {\isaliteral{28}{\isacharparenleft}}Var\ i{\isaliteral{29}{\isacharparenright}}\ k\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}if\ i\ {\isaliteral{3C}{\isacharless}}\ k\ then\ Var\ i\ else\ Var\ {\isaliteral{28}{\isacharparenleft}}i\ {\isaliteral{2B}{\isacharplus}}\ {\isadigit{1}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}lift\ {\isaliteral{28}{\isacharparenleft}}s\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ t{\isaliteral{29}{\isacharparenright}}\ k\ {\isaliteral{3D}{\isacharequal}}\ lift\ s\ k\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ lift\ t\ k{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}lift\ {\isaliteral{28}{\isacharparenleft}}Abs\ s{\isaliteral{29}{\isacharparenright}}\ k\ {\isaliteral{3D}{\isacharequal}}\ Abs\ {\isaliteral{28}{\isacharparenleft}}lift\ s\ {\isaliteral{28}{\isacharparenleft}}k\ {\isaliteral{2B}{\isacharplus}}\ {\isadigit{1}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\isanewline -\isacommand{primrec}\isamarkupfalse% -\ subst\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ nat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ dB{\isaliteral{22}{\isachardoublequoteclose}}\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{27}{\isacharprime}}{\isaliteral{2F}{\isacharslash}}{\isaliteral{5F}{\isacharunderscore}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isadigit{3}}{\isadigit{0}}{\isadigit{0}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{0}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{0}}{\isaliteral{5D}{\isacharbrackright}}\ {\isadigit{3}}{\isadigit{0}}{\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\isanewline -\isakeyword{where}\isanewline -\ \ \ \ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}Var\ i{\isaliteral{29}{\isacharparenright}}{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline -\ \ \ \ \ \ {\isaliteral{28}{\isacharparenleft}}if\ k\ {\isaliteral{3C}{\isacharless}}\ i\ then\ Var\ {\isaliteral{28}{\isacharparenleft}}i\ {\isaliteral{2D}{\isacharminus}}\ {\isadigit{1}}{\isaliteral{29}{\isacharparenright}}\ else\ if\ i\ {\isaliteral{3D}{\isacharequal}}\ k\ then\ s\ else\ Var\ i{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}t\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ u{\isaliteral{29}{\isacharparenright}}{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ t{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ u{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}Abs\ t{\isaliteral{29}{\isacharparenright}}{\isaliteral{5B}{\isacharbrackleft}}s{\isaliteral{2F}{\isacharslash}}k{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ Abs\ {\isaliteral{28}{\isacharparenleft}}t{\isaliteral{5B}{\isacharbrackleft}}lift\ s\ {\isadigit{0}}\ {\isaliteral{2F}{\isacharslash}}\ k{\isaliteral{2B}{\isacharplus}}{\isadigit{1}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\isanewline -\isacommand{inductive}\isamarkupfalse% -\ beta\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ dB\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ bool{\isaliteral{22}{\isachardoublequoteclose}}\ \ {\isaliteral{28}{\isacharparenleft}}\isakeyword{infixl}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isadigit{5}}{\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\isanewline -\isakeyword{where}\isanewline -\ \ \ \ beta{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}Abs\ s\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ t\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ s{\isaliteral{5B}{\isacharbrackleft}}t{\isaliteral{2F}{\isacharslash}}{\isadigit{0}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ appL{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ t\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ s\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ u\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ t\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ u{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ appR{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ t\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ u\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ u\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ t{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ {\isaliteral{7C}{\isacharbar}}\ abs{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ t\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ Abs\ s\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ Abs\ t{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\isanewline -\isacommand{code{\isaliteral{5F}{\isacharunderscore}}module}\isamarkupfalse% -\ Test\isanewline -\isakeyword{contains}\isanewline -\ \ test{\isadigit{1}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{22}{\isachardoublequoteopen}}Abs\ {\isaliteral{28}{\isacharparenleft}}Var\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ Var\ {\isadigit{0}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ Var\ {\isadigit{0}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline -\ \ test{\isadigit{2}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{22}{\isachardoublequoteopen}}Abs\ {\isaliteral{28}{\isacharparenleft}}Abs\ {\isaliteral{28}{\isacharparenleft}}Var\ {\isadigit{0}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ Var\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ {\isaliteral{28}{\isacharparenleft}}Abs\ {\isaliteral{28}{\isacharparenleft}}Var\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6465677265653E}{\isasymdegree}}\ Var\ {\isadigit{0}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5F}{\isacharunderscore}}{\isaliteral{22}{\isachardoublequoteclose}}% -\begin{isamarkuptext}% -In the above example, \verb|Test.test1| evaluates to a boolean, - whereas \verb|Test.test2| is a lazy sequence whose elements can be - inspected separately.% -\end{isamarkuptext}% -\isamarkuptrue% -% -\isadelimML -% -\endisadelimML -% -\isatagML -\isacommand{ML}\isamarkupfalse% -\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ % -\isaantiq -assert{}% -\endisaantiq -\ Test{\isaliteral{2E}{\isachardot}}test{\isadigit{1}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline -\isacommand{ML}\isamarkupfalse% -\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ val\ results\ {\isaliteral{3D}{\isacharequal}}\ DSeq{\isaliteral{2E}{\isachardot}}list{\isaliteral{5F}{\isacharunderscore}}of\ Test{\isaliteral{2E}{\isachardot}}test{\isadigit{2}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline -\isacommand{ML}\isamarkupfalse% -\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ % -\isaantiq -assert{}% -\endisaantiq -\ {\isaliteral{28}{\isacharparenleft}}length\ results\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{2}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}% -\endisatagML -{\isafoldML}% -% -\isadelimML -% -\endisadelimML -% -\begin{isamarkuptext}% -\medskip The theory underlying the HOL code generator is described - more detailed in \cite{Berghofer-Nipkow:2002}. More examples that - illustrate the usage of the code generator can be found e.g.\ in - \verb|~~/src/HOL/MicroJava/J/JListExample.thy| and \verb|~~/src/HOL/MicroJava/JVM/JVMListExample.thy|.% -\end{isamarkuptext}% -\isamarkuptrue% -% \isamarkupsection{Definition by specification \label{sec:hol-specification}% } \isamarkuptrue% diff -r 5e4a1270c000 -r 2825ce94fd4d doc-src/Sledgehammer/sledgehammer.tex --- a/doc-src/Sledgehammer/sledgehammer.tex Tue Oct 18 15:19:06 2011 +0200 +++ b/doc-src/Sledgehammer/sledgehammer.tex Wed Oct 19 17:45:25 2011 +0200 @@ -523,12 +523,12 @@ that can be guessed from the number of facts in the original proof and the time it took to find it or replay it). -In addition, some provers (notably CVC3, Satallax, and Yices) do not provide -proofs or sometimes produce incomplete proofs. The minimizer is then invoked to -find out which facts are actually needed from the (large) set of facts that was -initinally given to the prover. Finally, if a prover returns a proof with lots -of facts, the minimizer is invoked automatically since Metis would be unlikely -to re-find the proof. +In addition, some provers (e.g., Yices) do not provide proofs or sometimes +produce incomplete proofs. The minimizer is then invoked to find out which facts +are actually needed from the (large) set of facts that was initinally given to +the prover. Finally, if a prover returns a proof with lots of facts, the +minimizer is invoked automatically since Metis would be unlikely to re-find the +proof. \point{A strange error occurred---what should I do?} @@ -737,7 +737,8 @@ \item[$\bullet$] \textbf{\textit{satallax}:} Satallax is an automatic higher-order prover developed by Chad Brown et al.\ \cite{satallax}, with -support for the TPTP many-typed higher-order syntax (THF0). +support for the TPTP many-typed higher-order syntax (THF0). Sledgehammer +requires version 2.2 or above. \item[$\bullet$] \textbf{\textit{spass}:} SPASS is a first-order resolution prover developed by Christoph Weidenbach et al.\ \cite{weidenbach-et-al-2009}. diff -r 5e4a1270c000 -r 2825ce94fd4d etc/isar-keywords.el --- a/etc/isar-keywords.el Tue Oct 18 15:19:06 2011 +0200 +++ b/etc/isar-keywords.el Wed Oct 19 17:45:25 2011 +0200 @@ -51,8 +51,6 @@ "code_deps" "code_include" "code_instance" - "code_library" - "code_module" "code_modulename" "code_monad" "code_pred" @@ -64,7 +62,6 @@ "coinductive_set" "commit" "consts" - "consts_code" "context" "corollary" "cpodef" @@ -264,7 +261,6 @@ "typed_print_translation" "typedecl" "typedef" - "types_code" "ultimately" "undo" "undos_proof" @@ -292,7 +288,6 @@ "checking" "congs" "constrains" - "contains" "datatypes" "defines" "file" @@ -456,8 +451,6 @@ "code_datatype" "code_include" "code_instance" - "code_library" - "code_module" "code_modulename" "code_monad" "code_reflect" @@ -466,7 +459,6 @@ "coinductive" "coinductive_set" "consts" - "consts_code" "context" "datatype" "declaration" @@ -538,7 +530,6 @@ "type_synonym" "typed_print_translation" "typedecl" - "types_code" "use")) (defconst isar-keywords-theory-script diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Finite_Set.thy --- a/src/HOL/Finite_Set.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Finite_Set.thy Wed Oct 19 17:45:25 2011 +0200 @@ -1859,7 +1859,7 @@ by (simp add: card_Suc_Diff1 [symmetric]) lemma card_Diff_singleton_if: - "finite A ==> card (A-{x}) = (if x : A then card A - 1 else card A)" + "finite A ==> card (A - {x}) = (if x : A then card A - 1 else card A)" by (simp add: card_Diff_singleton) lemma card_Diff_insert[simp]: diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Fun.thy --- a/src/HOL/Fun.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Fun.thy Wed Oct 19 17:45:25 2011 +0200 @@ -812,28 +812,6 @@ subsubsection {* Code generator *} -types_code - "fun" ("(_ ->/ _)") -attach (term_of) {* -fun term_of_fun_type _ aT _ bT _ = Free ("", aT --> bT); -*} -attach (test) {* -fun gen_fun_type aF aT bG bT i = - let - val tab = Unsynchronized.ref []; - fun mk_upd (x, (_, y)) t = Const ("Fun.fun_upd", - (aT --> bT) --> aT --> bT --> aT --> bT) $ t $ aF x $ y () - in - (fn x => - case AList.lookup op = (!tab) x of - NONE => - let val p as (y, _) = bG i - in (tab := (x, p) :: !tab; y) end - | SOME (y, _) => y, - fn () => Basics.fold mk_upd (!tab) (Const ("HOL.undefined", aT --> bT))) - end; -*} - code_const "op \" (SML infixl 5 "o") (Haskell infixr 9 ".") diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/HOL.thy --- a/src/HOL/HOL.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/HOL.thy Wed Oct 19 17:45:25 2011 +0200 @@ -28,7 +28,6 @@ "~~/src/Tools/induct.ML" ("~~/src/Tools/induction.ML") ("~~/src/Tools/induct_tacs.ML") - ("Tools/recfun_codegen.ML") ("Tools/cnf_funcs.ML") "~~/src/Tools/subtyping.ML" "~~/src/Tools/case_product.ML" @@ -1715,66 +1714,6 @@ subsection {* Code generator setup *} -subsubsection {* SML code generator setup *} - -use "Tools/recfun_codegen.ML" - -setup {* - Codegen.setup - #> RecfunCodegen.setup - #> Codegen.map_unfold (K HOL_basic_ss) -*} - -types_code - "bool" ("bool") -attach (term_of) {* -fun term_of_bool b = if b then HOLogic.true_const else HOLogic.false_const; -*} -attach (test) {* -fun gen_bool i = - let val b = one_of [false, true] - in (b, fn () => term_of_bool b) end; -*} - "prop" ("bool") -attach (term_of) {* -fun term_of_prop b = - HOLogic.mk_Trueprop (if b then HOLogic.true_const else HOLogic.false_const); -*} - -consts_code - "Trueprop" ("(_)") - "True" ("true") - "False" ("false") - "Not" ("Bool.not") - HOL.disj ("(_ orelse/ _)") - HOL.conj ("(_ andalso/ _)") - "If" ("(if _/ then _/ else _)") - -setup {* -let - -fun eq_codegen thy mode defs dep thyname b t gr = - (case strip_comb t of - (Const (@{const_name HOL.eq}, Type (_, [Type ("fun", _), _])), _) => NONE - | (Const (@{const_name HOL.eq}, _), [t, u]) => - let - val (pt, gr') = Codegen.invoke_codegen thy mode defs dep thyname false t gr; - val (pu, gr'') = Codegen.invoke_codegen thy mode defs dep thyname false u gr'; - val (_, gr''') = - Codegen.invoke_tycodegen thy mode defs dep thyname false HOLogic.boolT gr''; - in - SOME (Codegen.parens - (Pretty.block [pt, Codegen.str " =", Pretty.brk 1, pu]), gr''') - end - | (t as Const (@{const_name HOL.eq}, _), ts) => SOME (Codegen.invoke_codegen - thy mode defs dep thyname b (Codegen.eta_expand t ts 2) gr) - | _ => NONE); - -in - Codegen.add_codegen "eq_codegen" eq_codegen -end -*} - subsubsection {* Generic code generator preprocessor setup *} setup {* @@ -1979,10 +1918,6 @@ Scan.succeed (gen_eval_method (Code_Runtime.dynamic_holds_conv o Proof_Context.theory_of)) *} "solve goal by evaluation" -method_setup evaluation = {* - Scan.succeed (gen_eval_method Codegen.evaluation_conv) -*} "solve goal by evaluation" - method_setup normalization = {* Scan.succeed (fn ctxt => SIMPLE_METHOD' (CHANGED_PROP o (CONVERSION (Nbe.dynamic_conv (Proof_Context.theory_of ctxt)) diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Abs_Int0_const.thy --- a/src/HOL/IMP/Abs_Int0_const.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Abs_Int0_const.thy Wed Oct 19 17:45:25 2011 +0200 @@ -88,7 +88,7 @@ text{* While: *} definition "test4_const = - ''x'' ::= N 0; WHILE B True DO ''x'' ::= N 0" + ''x'' ::= N 0; WHILE Bc True DO ''x'' ::= N 0" text{* While, test is ignored: *} definition "test5_const = diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Abs_Int1.thy --- a/src/HOL/IMP/Abs_Int1.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Abs_Int1.thy Wed Oct 19 17:45:25 2011 +0200 @@ -101,7 +101,7 @@ fun bfilter :: "bexp \ bool \ 'a st up \ 'a st up" where -"bfilter (B bv) res S = (if bv=res then S else Bot)" | +"bfilter (Bc v) res S = (if v=res then S else Bot)" | "bfilter (Not b) res S = bfilter b (\ res) S" | "bfilter (And b1 b2) res S = (if res then bfilter b1 True (bfilter b2 True S) @@ -130,7 +130,7 @@ lemma bfilter_sound: "s <:up S \ bv = bval b s \ s <:up bfilter b bv S" proof(induction b arbitrary: S bv) - case B thus ?case by simp + case Bc thus ?case by simp next case (Not b) thus ?case by simp next diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Abs_Int_Den/Abs_Int_den0_const.thy --- a/src/HOL/IMP/Abs_Int_Den/Abs_Int_den0_const.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Abs_Int_Den/Abs_Int_den0_const.thy Wed Oct 19 17:45:25 2011 +0200 @@ -83,7 +83,7 @@ text{* While: *} definition "test4_const = - ''x'' ::= N 0; WHILE B True DO ''x'' ::= N 0" + ''x'' ::= N 0; WHILE Bc True DO ''x'' ::= N 0" text{* While, test is ignored: *} definition "test5_const = diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Abs_Int_Den/Abs_Int_den1.thy --- a/src/HOL/IMP/Abs_Int_Den/Abs_Int_den1.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Abs_Int_Den/Abs_Int_den1.thy Wed Oct 19 17:45:25 2011 +0200 @@ -131,7 +131,7 @@ fun bfilter :: "bexp \ bool \ 'a astate up \ 'a astate up" where -"bfilter (B bv) res S = (if bv=res then S else bot)" | +"bfilter (Bc v) res S = (if v=res then S else bot)" | "bfilter (Not b) res S = bfilter b (\ res) S" | "bfilter (And b1 b2) res S = (if res then bfilter b1 True (bfilter b2 True S) @@ -159,7 +159,7 @@ lemma bfilter_sound: "s <:: S \ bv = bval b s \ s <:: bfilter b bv S" proof(induction b arbitrary: S bv) - case B thus ?case by simp + case Bc thus ?case by simp next case (Not b) thus ?case by simp next diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/BExp.thy --- a/src/HOL/IMP/BExp.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/BExp.thy Wed Oct 19 17:45:25 2011 +0200 @@ -2,10 +2,10 @@ subsection "Boolean Expressions" -datatype bexp = B bool | Not bexp | And bexp bexp | Less aexp aexp +datatype bexp = Bc bool | Not bexp | And bexp bexp | Less aexp aexp fun bval :: "bexp \ state \ bool" where -"bval (B bv) _ = bv" | +"bval (Bc v) _ = v" | "bval (Not b) s = (\ bval b s)" | "bval (And b1 b2) s = (if bval b1 s then bval b2 s else False)" | "bval (Less a1 a2) s = (aval a1 s < aval a2 s)" @@ -19,7 +19,7 @@ text{* Optimized constructors: *} fun less :: "aexp \ aexp \ bexp" where -"less (N n1) (N n2) = B(n1 < n2)" | +"less (N n1) (N n2) = Bc(n1 < n2)" | "less a1 a2 = Less a1 a2" lemma [simp]: "bval (less a1 a2) s = (aval a1 s < aval a2 s)" @@ -28,10 +28,10 @@ done fun "and" :: "bexp \ bexp \ bexp" where -"and (B True) b = b" | -"and b (B True) = b" | -"and (B False) b = B False" | -"and b (B False) = B False" | +"and (Bc True) b = b" | +"and b (Bc True) = b" | +"and (Bc False) b = Bc False" | +"and b (Bc False) = Bc False" | "and b1 b2 = And b1 b2" lemma bval_and[simp]: "bval (and b1 b2) s = (bval b1 s \ bval b2 s)" @@ -40,8 +40,8 @@ done fun not :: "bexp \ bexp" where -"not (B True) = B False" | -"not (B False) = B True" | +"not (Bc True) = Bc False" | +"not (Bc False) = Bc True" | "not b = Not b" lemma bval_not[simp]: "bval (not b) s = (~bval b s)" @@ -55,7 +55,7 @@ "bsimp (Less a1 a2) = less (asimp a1) (asimp a2)" | "bsimp (And b1 b2) = and (bsimp b1) (bsimp b2)" | "bsimp (Not b) = not(bsimp b)" | -"bsimp (B bv) = B bv" +"bsimp (Bc v) = Bc v" value "bsimp (And (Less (N 0) (N 1)) b)" diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/C_like.thy --- a/src/HOL/IMP/C_like.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/C_like.thy Wed Oct 19 17:45:25 2011 +0200 @@ -11,10 +11,10 @@ "aval (!a) s = s(aval a s)" | "aval (Plus a\<^isub>1 a\<^isub>2) s = aval a\<^isub>1 s + aval a\<^isub>2 s" -datatype bexp = B bool | Not bexp | And bexp bexp | Less aexp aexp +datatype bexp = Bc bool | Not bexp | And bexp bexp | Less aexp aexp primrec bval :: "bexp \ state \ bool" where -"bval (B bv) _ = bv" | +"bval (Bc v) _ = v" | "bval (Not b) s = (\ bval b s)" | "bval (And b\<^isub>1 b\<^isub>2) s = (if bval b\<^isub>1 s then bval b\<^isub>2 s else False)" | "bval (Less a\<^isub>1 a\<^isub>2) s = (aval a\<^isub>1 s < aval a\<^isub>2 s)" diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Comp_Rev.thy --- a/src/HOL/IMP/Comp_Rev.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Comp_Rev.thy Wed Oct 19 17:45:25 2011 +0200 @@ -443,7 +443,7 @@ shows "i = isize(bcomp b c j) + (if c = bval b s then j else 0) \ s' = s \ stk' = stk" using assms proof (induction b arbitrary: c j i n s' stk') - case B thus ?case + case Bc thus ?case by (simp split: split_if_asm add: exec_n_simps) next case (Not b) diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Compiler.thy --- a/src/HOL/IMP/Compiler.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Compiler.thy Wed Oct 19 17:45:25 2011 +0200 @@ -204,7 +204,7 @@ by (induct a arbitrary: stk) fastforce+ fun bcomp :: "bexp \ bool \ int \ instr list" where -"bcomp (B bv) c n = (if bv=c then [JMP n] else [])" | +"bcomp (Bc v) c n = (if v=c then [JMP n] else [])" | "bcomp (Not b) c n = bcomp b (\c) n" | "bcomp (And b1 b2) c n = (let cb2 = bcomp b2 c n; diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Def_Ass_Exp.thy --- a/src/HOL/IMP/Def_Ass_Exp.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Def_Ass_Exp.thy Wed Oct 19 17:45:25 2011 +0200 @@ -18,7 +18,7 @@ fun bval :: "bexp \ state \ bool option" where -"bval (B bv) s = Some bv" | +"bval (Bc v) s = Some v" | "bval (Not b) s = (case bval b s of None \ None | Some bv \ Some(\ bv))" | "bval (And b\<^isub>1 b\<^isub>2) s = (case (bval b\<^isub>1 s, bval b\<^isub>2 s) of (Some bv\<^isub>1, Some bv\<^isub>2) \ Some(bv\<^isub>1 & bv\<^isub>2) | _ \ None)" | diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Fold.thy --- a/src/HOL/IMP/Fold.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Fold.thy Wed Oct 19 17:45:25 2011 +0200 @@ -233,35 +233,35 @@ "bsimp_const (Less a1 a2) t = less (simp_const a1 t) (simp_const a2 t)" | "bsimp_const (And b1 b2) t = and (bsimp_const b1 t) (bsimp_const b2 t)" | "bsimp_const (Not b) t = not(bsimp_const b t)" | -"bsimp_const (B bv) _ = B bv" +"bsimp_const (Bc bc) _ = Bc bc" theorem bvalsimp_const [simp]: assumes "approx t s" shows "bval (bsimp_const b t) s = bval b s" using assms by (induct b) auto -lemma not_B [simp]: "not (B v) = B (\v)" +lemma not_Bc [simp]: "not (Bc v) = Bc (\v)" by (cases v) auto -lemma not_B_eq [simp]: "(not b = B v) = (b = B (\v))" +lemma not_Bc_eq [simp]: "(not b = Bc v) = (b = Bc (\v))" by (cases b) auto -lemma and_B_eq: - "(and a b = B v) = (a = B False \ \v \ - b = B False \ \v \ - (\v1 v2. a = B v1 \ b = B v2 \ v = v1 \ v2))" +lemma and_Bc_eq: + "(and a b = Bc v) = + (a = Bc False \ \v \ b = Bc False \ \v \ + (\v1 v2. a = Bc v1 \ b = Bc v2 \ v = v1 \ v2))" by (rule and.induct) auto -lemma less_B_eq [simp]: - "(less a b = B v) = (\n1 n2. a = N n1 \ b = N n2 \ v = (n1 < n2))" +lemma less_Bc_eq [simp]: + "(less a b = Bc v) = (\n1 n2. a = N n1 \ b = N n2 \ v = (n1 < n2))" by (rule less.induct) auto -theorem bvalsimp_const_B: +theorem bvalsimp_const_Bc: assumes "approx t s" -shows "bsimp_const b t = B v \ bval b s = v" +shows "bsimp_const b t = Bc v \ bval b s = v" using assms by (induct b arbitrary: v) - (auto simp: approx_def and_B_eq aval_simp_const_N + (auto simp: approx_def and_Bc_eq aval_simp_const_N split: bexp.splits bool.splits) @@ -271,8 +271,8 @@ (case simp_const a t of N k \ t(x \ k) | _ \ t(x:=None))" | "bdefs (c1;c2) t = (bdefs c2 o bdefs c1) t" | "bdefs (IF b THEN c1 ELSE c2) t = (case bsimp_const b t of - B True \ bdefs c1 t - | B False \ bdefs c2 t + Bc True \ bdefs c1 t + | Bc False \ bdefs c2 t | _ \ merge (bdefs c1 t) (bdefs c2 t))" | "bdefs (WHILE b DO c) t = t |` (-lnames c)" @@ -282,11 +282,11 @@ "bfold (x ::= a) t = (x ::= (simp_const a t))" | "bfold (c1;c2) t = (bfold c1 t; bfold c2 (bdefs c1 t))" | "bfold (IF b THEN c1 ELSE c2) t = (case bsimp_const b t of - B True \ bfold c1 t - | B False \ bfold c2 t + Bc True \ bfold c1 t + | Bc False \ bfold c2 t | _ \ IF bsimp_const b t THEN bfold c1 t ELSE bfold c2 t)" | "bfold (WHILE b DO c) t = (case bsimp_const b t of - B False \ SKIP + Bc False \ SKIP | _ \ WHILE bsimp_const b (t |` (-lnames c)) DO bfold c (t |` (-lnames c)))" @@ -342,18 +342,18 @@ case (IfTrue b s c1 s') hence "approx (bdefs c1 t) s'" by simp thus ?case using `bval b s` `approx t s` - by (clarsimp simp: approx_merge bvalsimp_const_B + by (clarsimp simp: approx_merge bvalsimp_const_Bc split: bexp.splits bool.splits) next case (IfFalse b s c2 s') hence "approx (bdefs c2 t) s'" by simp thus ?case using `\bval b s` `approx t s` - by (clarsimp simp: approx_merge bvalsimp_const_B + by (clarsimp simp: approx_merge bvalsimp_const_Bc split: bexp.splits bool.splits) next case WhileFalse thus ?case - by (clarsimp simp: bvalsimp_const_B approx_def restrict_map_def + by (clarsimp simp: bvalsimp_const_Bc approx_def restrict_map_def split: bexp.splits bool.splits) next case (WhileTrue b s1 c s2 s3) @@ -385,7 +385,7 @@ IF Fold.bsimp_const b t THEN bfold c1 t ELSE bfold c2 t" by (auto intro: equiv_up_to_if_weak simp: bequiv_up_to_def) thus ?case using If - by (fastforce simp: bvalsimp_const_B split: bexp.splits bool.splits + by (fastforce simp: bvalsimp_const_Bc split: bexp.splits bool.splits intro: equiv_up_to_trans) next case (While b c) @@ -400,7 +400,7 @@ thus ?case by (auto split: bexp.splits bool.splits intro: equiv_up_to_while_False - simp: bvalsimp_const_B) + simp: bvalsimp_const_Bc) qed diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Poly_Types.thy --- a/src/HOL/IMP/Poly_Types.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Poly_Types.thy Wed Oct 19 17:45:25 2011 +0200 @@ -18,7 +18,7 @@ inductive btyping :: "tyenv \ bexp \ bool" (infix "\p" 50) where -"\ \p B bv" | +"\ \p Bc v" | "\ \p b \ \ \p Not b" | "\ \p b1 \ \ \p b2 \ \ \p And b1 b2" | "\ \p a1 : \ \ \ \p a2 : \ \ \ \p Less a1 a2" diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Sec_Type_Expr.thy --- a/src/HOL/IMP/Sec_Type_Expr.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Sec_Type_Expr.thy Wed Oct 19 17:45:25 2011 +0200 @@ -20,7 +20,7 @@ "sec_aexp (Plus a\<^isub>1 a\<^isub>2) = max (sec_aexp a\<^isub>1) (sec_aexp a\<^isub>2)" fun sec_bexp :: "bexp \ level" where -"sec_bexp (B bv) = 0" | +"sec_bexp (Bc v) = 0" | "sec_bexp (Not b) = sec_bexp b" | "sec_bexp (And b\<^isub>1 b\<^isub>2) = max (sec_bexp b\<^isub>1) (sec_bexp b\<^isub>2)" | "sec_bexp (Less a\<^isub>1 a\<^isub>2) = max (sec_aexp a\<^isub>1) (sec_aexp a\<^isub>2)" diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Sem_Equiv.thy --- a/src/HOL/IMP/Sem_Equiv.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Sem_Equiv.thy Wed Oct 19 17:45:25 2011 +0200 @@ -152,11 +152,11 @@ "(\s. P s \ \ bval b s) \ P \ WHILE b DO c \ SKIP" by (auto simp: equiv_up_to_def) -lemma while_never: "(c, s) \ u \ c \ WHILE (B True) DO c'" +lemma while_never: "(c, s) \ u \ c \ WHILE (Bc True) DO c'" by (induct rule: big_step_induct) auto lemma equiv_up_to_while_True [intro!,simp]: - "P \ WHILE B True DO c \ WHILE B True DO SKIP" + "P \ WHILE Bc True DO c \ WHILE Bc True DO SKIP" unfolding equiv_up_to_def by (blast dest: while_never) diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Types.thy --- a/src/HOL/IMP/Types.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Types.thy Wed Oct 19 17:45:25 2011 +0200 @@ -27,10 +27,10 @@ subsection "Boolean Expressions" -datatype bexp = B bool | Not bexp | And bexp bexp | Less aexp aexp +datatype bexp = Bc bool | Not bexp | And bexp bexp | Less aexp aexp inductive tbval :: "bexp \ state \ bool \ bool" where -"tbval (B bv) s bv" | +"tbval (Bc v) s v" | "tbval b s bv \ tbval (Not b) s (\ bv)" | "tbval b1 s bv1 \ tbval b2 s bv2 \ tbval (And b1 b2) s (bv1 & bv2)" | "taval a1 s (Iv i1) \ taval a2 s (Iv i2) \ tbval (Less a1 a2) s (i1 < i2)" | @@ -85,7 +85,7 @@ inductive btyping :: "tyenv \ bexp \ bool" (infix "\" 50) where -B_ty: "\ \ B bv" | +B_ty: "\ \ Bc v" | Not_ty: "\ \ b \ \ \ Not b" | And_ty: "\ \ b1 \ \ \ b2 \ \ \ And b1 b2" | Less_ty: "\ \ a1 : \ \ \ \ a2 : \ \ \ \ Less a1 a2" diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/IMP/Vars.thy --- a/src/HOL/IMP/Vars.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/IMP/Vars.thy Wed Oct 19 17:45:25 2011 +0200 @@ -41,7 +41,7 @@ begin fun vars_bexp :: "bexp \ name set" where -"vars_bexp (B bv) = {}" | +"vars_bexp (Bc v) = {}" | "vars_bexp (Not b) = vars_bexp b" | "vars_bexp (And b\<^isub>1 b\<^isub>2) = vars_bexp b\<^isub>1 \ vars_bexp b\<^isub>2" | "vars_bexp (Less a\<^isub>1 a\<^isub>2) = vars a\<^isub>1 \ vars a\<^isub>2" diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Int.thy --- a/src/HOL/Int.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Int.thy Wed Oct 19 17:45:25 2011 +0200 @@ -2383,47 +2383,6 @@ code_modulename Haskell Int Arith -types_code - "int" ("int") -attach (term_of) {* -val term_of_int = HOLogic.mk_number HOLogic.intT; -*} -attach (test) {* -fun gen_int i = - let val j = one_of [~1, 1] * random_range 0 i - in (j, fn () => term_of_int j) end; -*} - -setup {* -let - -fun strip_number_of (@{term "Int.number_of :: int => int"} $ t) = t - | strip_number_of t = t; - -fun numeral_codegen thy mode defs dep module b t gr = - let val i = HOLogic.dest_numeral (strip_number_of t) - in - SOME (Codegen.str (string_of_int i), - snd (Codegen.invoke_tycodegen thy mode defs dep module false HOLogic.intT gr)) - end handle TERM _ => NONE; - -in - -Codegen.add_codegen "numeral_codegen" numeral_codegen - -end -*} - -consts_code - "number_of :: int \ int" ("(_)") - "0 :: int" ("0") - "1 :: int" ("1") - "uminus :: int => int" ("~") - "op + :: int => int => int" ("(_ +/ _)") - "op * :: int => int => int" ("(_ */ _)") - "op \ :: int => int => bool" ("(_ <=/ _)") - "op < :: int => int => bool" ("(_ find_var u | x => x) - | find_var _ = NONE; - fun find_thm th = - let val th' = Conv.fconv_rule Object_Logic.atomize th - in Option.map (pair (th, th')) (find_var (prop_of th')) end - in - case get_first find_thm thms of - NONE => thms - | SOME ((th, th'), (Sucv, v)) => - let - val cert = cterm_of (Thm.theory_of_thm th); - val th'' = Object_Logic.rulify (Thm.implies_elim - (Conv.fconv_rule (Thm.beta_conversion true) - (Drule.instantiate' [] - [SOME (cert (lambda v (Abs ("x", HOLogic.natT, - abstract_over (Sucv, - HOLogic.dest_Trueprop (prop_of th')))))), - SOME (cert v)] @{thm Suc_clause})) - (Thm.forall_intr (cert v) th')) - in - remove_suc_clause thy (map (fn th''' => - if (op = o pairself prop_of) (th''', th) then th'' else th''') thms) - end - end; - -fun clause_suc_preproc thy ths = - let - val dest = fst o HOLogic.dest_mem o HOLogic.dest_Trueprop - in - if forall (can (dest o concl_of)) ths andalso - exists (fn th => exists (exists_Const (fn (c, _) => c = @{const_name Suc})) - (map_filter (try dest) (concl_of th :: prems_of th))) ths - then remove_suc_clause thy ths else ths - end; in Code_Preproc.add_functrans ("eqn_Suc", eqn_suc_preproc) - #> Codegen.add_preprocessor clause_suc_preproc end; *} @@ -225,19 +185,8 @@ (OCaml "Big'_int.big'_int") (Eval "int") -types_code - nat ("int") -attach (term_of) {* -val term_of_nat = HOLogic.mk_number HOLogic.natT; -*} -attach (test) {* -fun gen_nat i = - let val n = random_range 0 i - in (n, fn () => term_of_nat n) end; -*} - text {* - For Haskell ans Scala we define our own @{typ nat} type. The reason + For Haskell and Scala we define our own @{typ nat} type. The reason is that we have to distinguish type class instances for @{typ nat} and @{typ int}. *} @@ -379,13 +328,6 @@ (SML "_") (OCaml "_") -consts_code - int ("(_)") - nat ("\nat") -attach {* -fun nat i = if i < 0 then 0 else i; -*} - code_const nat (SML "IntInf.max/ (0,/ _)") (OCaml "Big'_int.max'_big'_int/ Big'_int.zero'_big'_int") @@ -461,15 +403,6 @@ (Scala infixl 4 "<") (Eval infixl 6 "<") -consts_code - "0::nat" ("0") - "1::nat" ("1") - Suc ("(_ +/ 1)") - "op + \ nat \ nat \ nat" ("(_ +/ _)") - "op * \ nat \ nat \ nat" ("(_ */ _)") - "op \ \ nat \ nat \ bool" ("(_ <=/ _)") - "op < \ nat \ nat \ bool" ("(_ Coset") - Set ("\Set") -attach {* - datatype 'a set = Set of 'a list | Coset of 'a list; -*} -- {* This assumes that there won't be a @{text Coset} without a @{text Set} *} - subsection {* Basic operations *} diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Library/Transitive_Closure_Table.thy --- a/src/HOL/Library/Transitive_Closure_Table.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Library/Transitive_Closure_Table.thy Wed Oct 19 17:45:25 2011 +0200 @@ -201,22 +201,6 @@ | "test B A" | "test B C" -subsubsection {* Invoking with the (legacy) SML code generator *} - -text {* this test can be removed once the SML code generator is deactivated *} - -code_module Test -contains -test1 = "test\<^sup>*\<^sup>* A C" -test2 = "test\<^sup>*\<^sup>* C A" -test3 = "test\<^sup>*\<^sup>* A _" -test4 = "test\<^sup>*\<^sup>* _ C" - -ML "Test.test1" -ML "Test.test2" -ML "DSeq.list_of Test.test3" -ML "DSeq.list_of Test.test4" - subsubsection {* Invoking with the predicate compiler and the generic code generator *} code_pred test . diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/List.thy --- a/src/HOL/List.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/List.thy Wed Oct 19 17:45:25 2011 +0200 @@ -5261,39 +5261,7 @@ code_reserved OCaml list -types_code - "list" ("_ list") -attach (term_of) {* -fun term_of_list f T = HOLogic.mk_list T o map f; -*} -attach (test) {* -fun gen_list' aG aT i j = frequency - [(i, fn () => - let - val (x, t) = aG j; - val (xs, ts) = gen_list' aG aT (i-1) j - in (x :: xs, fn () => HOLogic.cons_const aT $ t () $ ts ()) end), - (1, fn () => ([], fn () => HOLogic.nil_const aT))] () -and gen_list aG aT i = gen_list' aG aT i i; -*} - -consts_code Cons ("(_ ::/ _)") - -setup {* -let - fun list_codegen thy mode defs dep thyname b t gr = - let - val ts = HOLogic.dest_list t; - val (_, gr') = Codegen.invoke_tycodegen thy mode defs dep thyname false - (fastype_of t) gr; - val (ps, gr'') = fold_map - (Codegen.invoke_codegen thy mode defs dep thyname false) ts gr' - in SOME (Pretty.list "[" "]" ps, gr'') end handle TERM _ => NONE; -in - fold (List_Code.add_literal_list) ["SML", "OCaml", "Haskell", "Scala"] - #> Codegen.add_codegen "list_codegen" list_codegen -end -*} +setup {* fold (List_Code.add_literal_list) ["SML", "OCaml", "Haskell", "Scala"] *} subsubsection {* Use convenient predefined operations *} diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Mutabelle/lib/Tools/mutabelle --- a/src/HOL/Mutabelle/lib/Tools/mutabelle Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Mutabelle/lib/Tools/mutabelle Wed Oct 19 17:45:25 2011 +0200 @@ -89,10 +89,11 @@ val mtds = [ MutabelleExtra.quickcheck_mtd (Context.proof_map (Quickcheck.set_active_testers [\"random\"])) \"random\", MutabelleExtra.quickcheck_mtd (Context.proof_map (Quickcheck.set_active_testers [\"exhaustive\"])) \"exhaustive\", - MutabelleExtra.quickcheck_mtd (Context.proof_map (Quickcheck.set_active_testers [\"exhaustive\"]) #> Config.put Quickcheck.finite_types false) \"exhaustive_nft\", - MutabelleExtra.quickcheck_mtd (Context.proof_map (Quickcheck.set_active_testers [\"narrowing\"]) #> Config.put Quickcheck.finite_types false) \"narrowing\", + MutabelleExtra.quickcheck_mtd (Context.proof_map (Quickcheck.set_active_testers [\"exhaustive\"]) #> Config.put Quickcheck.finite_types false) \"exhaustive_no_finite_types\", + MutabelleExtra.quickcheck_mtd (Context.proof_map (Quickcheck.set_active_testers [\"narrowing\"]) #> Config.put Quickcheck.finite_types true) \"narrowing\", + MutabelleExtra.quickcheck_mtd (Context.proof_map (Quickcheck.set_active_testers [\"narrowing\"]) #> Config.put Quickcheck.finite_types false) \"narrowing_no_finite_types\", MutabelleExtra.quickcheck_mtd (Context.proof_map (Quickcheck.set_active_testers [\"narrowing\"]) #> Config.put Quickcheck.finite_types false - #> Context.proof_map (Quickcheck.map_test_params (apfst (K [@{typ nat}])))) \"narrowing_nat\" + #> Context.proof_map (Quickcheck.map_test_params (apfst (K [@{typ nat}])))) \"narrowing_nat\" (* MutabelleExtra.nitpick_mtd *) ] *} diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Mutabelle/mutabelle_extra.ML --- a/src/HOL/Mutabelle/mutabelle_extra.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Mutabelle/mutabelle_extra.ML Wed Oct 19 17:45:25 2011 +0200 @@ -321,7 +321,8 @@ in can (TimeLimit.timeLimit (seconds 2.0) (Quickcheck.test_terms - ((Config.put Quickcheck.finite_types true #> + ((Context.proof_map (Quickcheck.set_active_testers ["exhaustive"]) #> + Config.put Quickcheck.finite_types true #> Config.put Quickcheck.finite_type_size 1 #> Config.put Quickcheck.size 1 #> Config.put Quickcheck.iterations 1) ctxt) (false, false) [])) (map (rpair [] o Object_Logic.atomize_term thy) diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Product_Type.thy --- a/src/HOL/Product_Type.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Product_Type.thy Wed Oct 19 17:45:25 2011 +0200 @@ -9,7 +9,6 @@ imports Typedef Inductive Fun uses ("Tools/split_rule.ML") - ("Tools/inductive_codegen.ML") ("Tools/inductive_set.ML") begin @@ -312,95 +311,6 @@ code_const "HOL.equal \ 'a \ 'b \ 'a \ 'b \ bool" (Haskell infix 4 "==") -types_code - "prod" ("(_ */ _)") -attach (term_of) {* -fun term_of_prod aF aT bF bT (x, y) = HOLogic.pair_const aT bT $ aF x $ bF y; -*} -attach (test) {* -fun gen_prod aG aT bG bT i = - let - val (x, t) = aG i; - val (y, u) = bG i - in ((x, y), fn () => HOLogic.pair_const aT bT $ t () $ u ()) end; -*} - -consts_code - "Pair" ("(_,/ _)") - -setup {* -let - -fun strip_abs_split 0 t = ([], t) - | strip_abs_split i (Abs (s, T, t)) = - let - val s' = Codegen.new_name t s; - val v = Free (s', T) - in apfst (cons v) (strip_abs_split (i-1) (subst_bound (v, t))) end - | strip_abs_split i (u as Const (@{const_name prod_case}, _) $ t) = - (case strip_abs_split (i+1) t of - (v :: v' :: vs, u) => (HOLogic.mk_prod (v, v') :: vs, u) - | _ => ([], u)) - | strip_abs_split i t = - strip_abs_split i (Abs ("x", hd (binder_types (fastype_of t)), t $ Bound 0)); - -fun let_codegen thy mode defs dep thyname brack t gr = - (case strip_comb t of - (t1 as Const (@{const_name Let}, _), t2 :: t3 :: ts) => - let - fun dest_let (l as Const (@{const_name Let}, _) $ t $ u) = - (case strip_abs_split 1 u of - ([p], u') => apfst (cons (p, t)) (dest_let u') - | _ => ([], l)) - | dest_let t = ([], t); - fun mk_code (l, r) gr = - let - val (pl, gr1) = Codegen.invoke_codegen thy mode defs dep thyname false l gr; - val (pr, gr2) = Codegen.invoke_codegen thy mode defs dep thyname false r gr1; - in ((pl, pr), gr2) end - in case dest_let (t1 $ t2 $ t3) of - ([], _) => NONE - | (ps, u) => - let - val (qs, gr1) = fold_map mk_code ps gr; - val (pu, gr2) = Codegen.invoke_codegen thy mode defs dep thyname false u gr1; - val (pargs, gr3) = fold_map - (Codegen.invoke_codegen thy mode defs dep thyname true) ts gr2 - in - SOME (Codegen.mk_app brack - (Pretty.blk (0, [Codegen.str "let ", Pretty.blk (0, flat - (separate [Codegen.str ";", Pretty.brk 1] (map (fn (pl, pr) => - [Pretty.block [Codegen.str "val ", pl, Codegen.str " =", - Pretty.brk 1, pr]]) qs))), - Pretty.brk 1, Codegen.str "in ", pu, - Pretty.brk 1, Codegen.str "end"])) pargs, gr3) - end - end - | _ => NONE); - -fun split_codegen thy mode defs dep thyname brack t gr = (case strip_comb t of - (t1 as Const (@{const_name prod_case}, _), t2 :: ts) => - let - val ([p], u) = strip_abs_split 1 (t1 $ t2); - val (q, gr1) = Codegen.invoke_codegen thy mode defs dep thyname false p gr; - val (pu, gr2) = Codegen.invoke_codegen thy mode defs dep thyname false u gr1; - val (pargs, gr3) = fold_map - (Codegen.invoke_codegen thy mode defs dep thyname true) ts gr2 - in - SOME (Codegen.mk_app brack - (Pretty.block [Codegen.str "(fn ", q, Codegen.str " =>", - Pretty.brk 1, pu, Codegen.str ")"]) pargs, gr2) - end - | _ => NONE); - -in - - Codegen.add_codegen "let_codegen" let_codegen - #> Codegen.add_codegen "split_codegen" split_codegen - -end -*} - subsubsection {* Fundamental operations and properties *} @@ -1203,9 +1113,6 @@ subsection {* Inductively defined sets *} -use "Tools/inductive_codegen.ML" -setup Inductive_Codegen.setup - use "Tools/inductive_set.ML" setup Inductive_Set.setup diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Proofs/Extraction/Euclid.thy --- a/src/HOL/Proofs/Extraction/Euclid.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Proofs/Extraction/Euclid.thy Wed Oct 19 17:45:25 2011 +0200 @@ -268,15 +268,4 @@ lemma "iterate 4 Euclid 0 = [2, 3, 7, 71]" by eval -consts_code - default ("(error \"default\")") - -lemma "factor_exists 1007 = [53, 19]" by evaluation -lemma "factor_exists 567 = [7, 3, 3, 3, 3]" by evaluation -lemma "factor_exists 345 = [23, 5, 3]" by evaluation -lemma "factor_exists 999 = [37, 3, 3, 3]" by evaluation -lemma "factor_exists 876 = [73, 3, 2, 2]" by evaluation - -lemma "iterate 4 Euclid 0 = [2, 3, 7, 71]" by evaluation - end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Proofs/Extraction/Greatest_Common_Divisor.thy --- a/src/HOL/Proofs/Extraction/Greatest_Common_Divisor.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Proofs/Extraction/Greatest_Common_Divisor.thy Wed Oct 19 17:45:25 2011 +0200 @@ -87,10 +87,6 @@ end -consts_code - default ("(error \"default\")") - -lemma "greatest_common_divisor 7 12 = (4, 3, 2)" by evaluation lemma "greatest_common_divisor 7 12 = (4, 3, 2)" by eval end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Proofs/Extraction/Higman_Extraction.thy --- a/src/HOL/Proofs/Extraction/Higman_Extraction.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Proofs/Extraction/Higman_Extraction.thy Wed Oct 19 17:45:25 2011 +0200 @@ -107,58 +107,4 @@ end; *} -text {* The same story with the legacy SML code generator, -this can be removed once the code generator is removed. *} - -code_module Higman -contains - higman = higman_idx - -ML {* -local open Higman in - -val a = 16807.0; -val m = 2147483647.0; - -fun nextRand seed = - let val t = a*seed - in t - m * real (Real.floor(t/m)) end; - -fun mk_word seed l = - let - val r = nextRand seed; - val i = Real.round (r / m * 10.0); - in if i > 7 andalso l > 2 then (r, []) else - apsnd (cons (if i mod 2 = 0 then A else B)) (mk_word r (l+1)) - end; - -fun f s zero = mk_word s 0 - | f s (Suc n) = f (fst (mk_word s 0)) n; - -val g1 = snd o (f 20000.0); - -val g2 = snd o (f 50000.0); - -fun f1 zero = [A,A] - | f1 (Suc zero) = [B] - | f1 (Suc (Suc zero)) = [A,B] - | f1 _ = []; - -fun f2 zero = [A,A] - | f2 (Suc zero) = [B] - | f2 (Suc (Suc zero)) = [B,A] - | f2 _ = []; - -val (i1, j1) = higman g1; -val (v1, w1) = (g1 i1, g1 j1); -val (i2, j2) = higman g2; -val (v2, w2) = (g2 i2, g2 j2); -val (i3, j3) = higman f1; -val (v3, w3) = (f1 i3, f1 j3); -val (i4, j4) = higman f2; -val (v4, w4) = (f2 i4, f2 j4); - -end; -*} - end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Proofs/Extraction/Pigeonhole.thy --- a/src/HOL/Proofs/Extraction/Pigeonhole.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Proofs/Extraction/Pigeonhole.thy Wed Oct 19 17:45:25 2011 +0200 @@ -252,28 +252,5 @@ ML "timeit (@{code test} 500)" ML "timeit @{code test''}" -text {* the same story with the legacy SML code generator. -this can be removed once the code generator is removed. -*} - -consts_code - "default :: nat" ("{* 0::nat *}") - "default :: nat \ nat" ("{* (0::nat, 0::nat) *}") - -code_module PH -contains - test = test - test' = test' - test'' = test'' - -ML "timeit (PH.test 10)" -ML "timeit (PH.test' 10)" -ML "timeit (PH.test 20)" -ML "timeit (PH.test' 20)" -ML "timeit (PH.test 25)" -ML "timeit (PH.test' 25)" -ML "timeit (PH.test 500)" -ML "timeit PH.test''" - end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Proofs/Extraction/QuotRem.thy --- a/src/HOL/Proofs/Extraction/QuotRem.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Proofs/Extraction/QuotRem.thy Wed Oct 19 17:45:25 2011 +0200 @@ -40,7 +40,6 @@ @{thm [display] division_correctness [no_vars]} *} -lemma "division 9 2 = (0, 3)" by evaluation lemma "division 9 2 = (0, 3)" by eval end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Proofs/Lambda/WeakNorm.thy --- a/src/HOL/Proofs/Lambda/WeakNorm.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Proofs/Lambda/WeakNorm.thy Wed Oct 19 17:45:25 2011 +0200 @@ -437,81 +437,4 @@ val ct2' = cterm_of @{theory} (term_of_dB [] (#T (rep_cterm ct2)) dB2); *} - -text {* -The same story again for the (legacy) SML code generator. -This can be removed once the SML code generator is removed. -*} - -consts_code - "default" ("(error \"default\")") - "default :: 'a \ 'b::default" ("(fn '_ => error \"default\")") - -code_module Norm -contains - test = "type_NF" - -ML {* -fun nat_of_int 0 = Norm.zero - | nat_of_int n = Norm.Suc (nat_of_int (n-1)); - -fun int_of_nat Norm.zero = 0 - | int_of_nat (Norm.Suc n) = 1 + int_of_nat n; - -fun dBtype_of_typ (Type ("fun", [T, U])) = - Norm.Fun (dBtype_of_typ T, dBtype_of_typ U) - | dBtype_of_typ (TFree (s, _)) = (case raw_explode s of - ["'", a] => Norm.Atom (nat_of_int (ord a - 97)) - | _ => error "dBtype_of_typ: variable name") - | dBtype_of_typ _ = error "dBtype_of_typ: bad type"; - -fun dB_of_term (Bound i) = Norm.dB_Var (nat_of_int i) - | dB_of_term (t $ u) = Norm.App (dB_of_term t, dB_of_term u) - | dB_of_term (Abs (_, _, t)) = Norm.Abs (dB_of_term t) - | dB_of_term _ = error "dB_of_term: bad term"; - -fun term_of_dB Ts (Type ("fun", [T, U])) (Norm.Abs dBt) = - Abs ("x", T, term_of_dB (T :: Ts) U dBt) - | term_of_dB Ts _ dBt = term_of_dB' Ts dBt -and term_of_dB' Ts (Norm.dB_Var n) = Bound (int_of_nat n) - | term_of_dB' Ts (Norm.App (dBt, dBu)) = - let val t = term_of_dB' Ts dBt - in case fastype_of1 (Ts, t) of - Type ("fun", [T, U]) => t $ term_of_dB Ts T dBu - | _ => error "term_of_dB: function type expected" - end - | term_of_dB' _ _ = error "term_of_dB: term not in normal form"; - -fun typing_of_term Ts e (Bound i) = - Norm.Var (e, nat_of_int i, dBtype_of_typ (nth Ts i)) - | typing_of_term Ts e (t $ u) = (case fastype_of1 (Ts, t) of - Type ("fun", [T, U]) => Norm.rtypingT_App (e, dB_of_term t, - dBtype_of_typ T, dBtype_of_typ U, dB_of_term u, - typing_of_term Ts e t, typing_of_term Ts e u) - | _ => error "typing_of_term: function type expected") - | typing_of_term Ts e (Abs (s, T, t)) = - let val dBT = dBtype_of_typ T - in Norm.rtypingT_Abs (e, dBT, dB_of_term t, - dBtype_of_typ (fastype_of1 (T :: Ts, t)), - typing_of_term (T :: Ts) (Norm.shift e Norm.zero dBT) t) - end - | typing_of_term _ _ _ = error "typing_of_term: bad term"; - -fun dummyf _ = error "dummy"; -*} - -text {* -We now try out the extracted program @{text "type_NF"} on some example terms. -*} - -ML {* -val ct1 = @{cterm "%f. ((%f x. f (f (f x))) ((%f x. f (f (f (f x)))) f))"}; -val (dB1, _) = Norm.type_NF (typing_of_term [] dummyf (term_of ct1)); -val ct1' = cterm_of @{theory} (term_of_dB [] (#T (rep_cterm ct1)) dB1); - -val ct2 = @{cterm "%f x. (%x. f x x) ((%x. f x x) ((%x. f x x) ((%x. f x x) ((%x. f x x) ((%x. f x x) x)))))"}; -val (dB2, _) = Norm.type_NF (typing_of_term [] dummyf (term_of ct2)); -val ct2' = cterm_of @{theory} (term_of_dB [] (#T (rep_cterm ct2)) dB2); -*} - end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Quickcheck.thy --- a/src/HOL/Quickcheck.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Quickcheck.thy Wed Oct 19 17:45:25 2011 +0200 @@ -144,13 +144,6 @@ no_notation fcomp (infixl "\>" 60) no_notation scomp (infixl "\\" 60) -subsection {* Tester SML-inductive based on the SML code generator *} - -setup {* - Context.theory_map (Quickcheck.add_tester ("SML_inductive", - (Inductive_Codegen.active, Quickcheck_Common.generator_test_goal_terms Inductive_Codegen.test_term))); -*} - subsection {* The Random-Predicate Monad *} fun iter' :: diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Rat.thy --- a/src/HOL/Rat.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Rat.thy Wed Oct 19 17:45:25 2011 +0200 @@ -1197,46 +1197,7 @@ end -text {* Setup for SML code generator *} - -types_code - rat ("(int */ int)") -attach (term_of) {* -fun term_of_rat (p, q) = - let - val rT = Type ("Rat.rat", []) - in - if q = 1 orelse p = 0 then HOLogic.mk_number rT p - else @{term "op / \ rat \ rat \ rat"} $ - HOLogic.mk_number rT p $ HOLogic.mk_number rT q - end; -*} -attach (test) {* -fun gen_rat i = - let - val p = random_range 0 i; - val q = random_range 1 (i + 1); - val g = Integer.gcd p q; - val p' = p div g; - val q' = q div g; - val r = (if one_of [true, false] then p' else ~ p', - if p' = 0 then 1 else q') - in - (r, fn () => term_of_rat r) - end; -*} - -consts_code - Fract ("(_,/ _)") - -consts_code - quotient_of ("{*normalize*}") - -consts_code - "of_int :: int \ rat" ("\rat'_of'_int") -attach {* -fun rat_of_int i = (i, 1); -*} +subsection {* Setup for Nitpick *} declaration {* Nitpick_HOL.register_frac_type @{type_name rat} diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/RealDef.thy --- a/src/HOL/RealDef.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/RealDef.thy Wed Oct 19 17:45:25 2011 +0200 @@ -1756,43 +1756,7 @@ end -text {* Setup for SML code generator *} - -types_code - real ("(int */ int)") -attach (term_of) {* -fun term_of_real (p, q) = - let - val rT = HOLogic.realT - in - if q = 1 orelse p = 0 then HOLogic.mk_number rT p - else @{term "op / \ real \ real \ real"} $ - HOLogic.mk_number rT p $ HOLogic.mk_number rT q - end; -*} -attach (test) {* -fun gen_real i = - let - val p = random_range 0 i; - val q = random_range 1 (i + 1); - val g = Integer.gcd p q; - val p' = p div g; - val q' = q div g; - val r = (if one_of [true, false] then p' else ~ p', - if p' = 0 then 1 else q') - in - (r, fn () => term_of_real r) - end; -*} - -consts_code - Ratreal ("(_)") - -consts_code - "of_int :: int \ real" ("\real'_of'_int") -attach {* -fun real_of_int i = (i, 1); -*} +subsection {* Setup for Nitpick *} declaration {* Nitpick_HOL.register_frac_type @{type_name real} diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/String.thy --- a/src/HOL/String.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/String.thy Wed Oct 19 17:45:25 2011 +0200 @@ -213,31 +213,6 @@ (Haskell infix 4 "==") (Scala infixl 5 "==") -types_code - "char" ("string") -attach (term_of) {* -val term_of_char = HOLogic.mk_char o ord; -*} -attach (test) {* -fun gen_char i = - let val j = random_range (ord "a") (Int.min (ord "a" + i, ord "z")) - in (chr j, fn () => HOLogic.mk_char j) end; -*} - -setup {* -let - -fun char_codegen thy mode defs dep thyname b t gr = - let - val i = HOLogic.dest_char t; - val (_, gr') = Codegen.invoke_tycodegen thy mode defs dep thyname false - (fastype_of t) gr; - in SOME (Codegen.str (ML_Syntax.print_string (chr i)), gr') - end handle TERM _ => NONE; - -in Codegen.add_codegen "char_codegen" char_codegen end -*} - hide_type (open) literal end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Tools/ATP/atp_proof.ML --- a/src/HOL/Tools/ATP/atp_proof.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Tools/ATP/atp_proof.ML Wed Oct 19 17:45:25 2011 +0200 @@ -324,6 +324,8 @@ (* We ignore TFF and THF types for now. *) AQuant (q, map (rpair NONE o ho_term_head) ts, phi))) x +val dummy_phi = AAtom (ATerm ("", [])) + fun skip_formula ss = let fun skip _ [] = [] @@ -335,7 +337,7 @@ | skip n ("]" :: ss) = skip (n - 1) ss | skip n (")" :: ss) = skip (n - 1) ss | skip n (_ :: ss) = skip n ss - in (AAtom (ATerm ("", [])), skip 0 ss) end + in (dummy_phi, skip 0 ss) end val parse_tstp_extra_arguments = Scan.optional ($$ "," |-- parse_annotation @@ -456,17 +458,21 @@ NONE | NONE => NONE -(* Syntax: [0:] - || -> . *) -fun parse_spass_line spass_names x = - (scan_general_id --| $$ "[" --| $$ "0" --| $$ ":" --| Symbol.scan_id - -- parse_spass_annotations --| $$ "]" -- parse_horn_clause --| $$ "." - >> (fn ((num, deps), u) => - Inference ((num, resolve_spass_num spass_names num), u, - map (swap o `(resolve_spass_num spass_names)) deps))) x +(* Syntax: [0:] || -> . *) +fun parse_spass_line spass_names = + scan_general_id --| $$ "[" --| $$ "0" --| $$ ":" --| Symbol.scan_id + -- parse_spass_annotations --| $$ "]" -- parse_horn_clause --| $$ "." + >> (fn ((num, deps), u) => + Inference ((num, resolve_spass_num spass_names num), u, + map (swap o `(resolve_spass_num spass_names)) deps)) + +(* Syntax: *) +fun parse_satallax_line x = + (scan_general_id --| Scan.option ($$ " ") + >> (fn s => Inference ((s, SOME [s]), dummy_phi, []))) x fun parse_line problem spass_names = - parse_tstp_line problem || parse_spass_line spass_names + parse_tstp_line problem || parse_spass_line spass_names || parse_satallax_line fun parse_proof problem spass_names tstp = tstp |> strip_spaces_except_between_idents |> raw_explode diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Tools/ATP/atp_systems.ML --- a/src/HOL/Tools/ATP/atp_systems.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Tools/ATP/atp_systems.ML Wed Oct 19 17:45:25 2011 +0200 @@ -101,6 +101,24 @@ (NoPerl, "env: perl"), (NoLibwwwPerl, "Can't locate HTTP")] +fun known_szs_failures wrap = + [(Unprovable, wrap "CounterSatisfiable"), + (Unprovable, wrap "Satisfiable"), + (GaveUp, wrap "GaveUp"), + (GaveUp, wrap "Unknown"), + (GaveUp, wrap "Incomplete"), + (ProofMissing, wrap "Theorem"), + (ProofMissing, wrap "Unsatisfiable"), + (TimedOut, wrap "Timeout"), + (Inappropriate, wrap "Inappropriate"), + (OutOfResources, wrap "ResourceOut"), + (OutOfResources, wrap "MemoryOut"), + (Interrupted, wrap "Forced"), + (Interrupted, wrap "User")] + +val known_szs_status_failures = known_szs_failures (prefix "SZS status ") +val known_says_failures = known_szs_failures (prefix " says ") + (* named ATPs *) val eN = "e" @@ -208,14 +226,10 @@ " -tAutoDev --silent --cpu-limit=" ^ string_of_int (to_secs 2 timeout), proof_delims = tstp_proof_delims, known_failures = - [(Unprovable, "SZS status: CounterSatisfiable"), - (Unprovable, "SZS status CounterSatisfiable"), - (ProofMissing, "SZS status Theorem"), - (TimedOut, "Failure: Resource limit exceeded (time)"), + known_szs_status_failures @ + [(TimedOut, "Failure: Resource limit exceeded (time)"), (TimedOut, "time limit exceeded"), - (OutOfResources, "# Cannot determine problem status"), - (OutOfResources, "SZS status: ResourceOut"), - (OutOfResources, "SZS status ResourceOut")], + (OutOfResources, "# Cannot determine problem status")], conj_sym_kind = Hypothesis, prem_kind = Conjecture, best_slices = fn ctxt => @@ -244,7 +258,7 @@ "--proofoutput --timeout " ^ string_of_int (to_secs 1 timeout) |> sos = sosN ? prefix "--sos ", proof_delims = tstp_proof_delims, - known_failures = [], + known_failures = known_szs_status_failures, conj_sym_kind = Axiom, prem_kind = Hypothesis, best_slices = fn ctxt => @@ -266,9 +280,10 @@ required_execs = [], arguments = fn _ => fn _ => fn _ => fn timeout => fn _ => - "-t " ^ string_of_int (to_secs 1 timeout), - proof_delims = tstp_proof_delims, - known_failures = [(ProofMissing, "SZS status Theorem")], + "-p hocore -t " ^ string_of_int (to_secs 1 timeout), + proof_delims = + [("% Higher-Order Unsat Core BEGIN", "% Higher-Order Unsat Core END")], + known_failures = known_szs_status_failures, conj_sym_kind = Axiom, prem_kind = Hypothesis, best_slices = @@ -336,10 +351,9 @@ ("% SZS output start Refutation", "% SZS output end Refutation"), ("% SZS output start Proof", "% SZS output end Proof")], known_failures = + known_szs_status_failures @ [(GaveUp, "UNPROVABLE"), (GaveUp, "CANNOT PROVE"), - (GaveUp, "SZS status GaveUp"), - (TimedOut, "SZS status Timeout"), (Unprovable, "Satisfiability detected"), (Unprovable, "Termination reason: Satisfiable"), (VampireTooOld, "not a valid option"), @@ -372,13 +386,7 @@ arguments = fn _ => fn _ => fn _ => fn timeout => fn _ => "MBQI=true -tptp -t:" ^ string_of_int (to_secs 1 timeout), proof_delims = [], - known_failures = - [(GaveUp, "SZS status Satisfiable"), - (GaveUp, "SZS status CounterSatisfiable"), - (GaveUp, "SZS status GaveUp"), - (GaveUp, "SZS status Unknown"), - (ProofMissing, "SZS status Unsatisfiable"), - (ProofMissing, "SZS status Theorem")], + known_failures = known_szs_status_failures, conj_sym_kind = Hypothesis, prem_kind = Hypothesis, best_slices = @@ -398,7 +406,7 @@ required_execs = [], arguments = K (K (K (K (K "")))), proof_delims = [], - known_failures = [(GaveUp, "SZS status Unknown")], + known_failures = known_szs_status_failures, conj_sym_kind = Hypothesis, prem_kind = Hypothesis, best_slices = K [(1.0, (false, (200, format, type_enc, "")))]} @@ -455,15 +463,7 @@ "-t " ^ string_of_int (Int.min (max_remote_secs, to_secs 1 timeout)) ^ " -s " ^ the_system system_name system_versions, proof_delims = union (op =) tstp_proof_delims proof_delims, - known_failures = known_failures @ known_perl_failures @ - [(Unprovable, "says Satisfiable"), - (Unprovable, "says CounterSatisfiable"), - (GaveUp, "says Unknown"), - (GaveUp, "says GaveUp"), - (ProofMissing, "says Theorem"), - (ProofMissing, "says Unsatisfiable"), - (TimedOut, "says Timeout"), - (Inappropriate, "says Inappropriate")], + known_failures = known_failures @ known_perl_failures @ known_says_failures, conj_sym_kind = conj_sym_kind, prem_kind = prem_kind, best_slices = fn ctxt => diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Tools/ATP/atp_translate.ML --- a/src/HOL/Tools/ATP/atp_translate.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Tools/ATP/atp_translate.ML Wed Oct 19 17:45:25 2011 +0200 @@ -946,10 +946,8 @@ | _ => IConst (name, T, []) else IConst (proxy_base |>> prefix const_prefix, T, T_args) - | NONE => if s = tptp_choice then - tweak_ho_quant tptp_choice T args - else - IConst (name, T, T_args)) + | NONE => if s = tptp_choice then tweak_ho_quant tptp_choice T args + else IConst (name, T, T_args)) | intro _ _ (IAbs (bound, tm)) = IAbs (bound, intro false [] tm) | intro _ _ tm = tm in intro true [] end @@ -1049,8 +1047,12 @@ | @{const Not} $ t1 => do_formula bs (Option.map not pos) t1 #>> mk_anot | Const (@{const_name All}, _) $ Abs (s, T, t') => do_quant bs AForall pos s T t' + | (t0 as Const (@{const_name All}, _)) $ t1 => + do_formula bs pos (t0 $ eta_expand (map (snd o snd) bs) t1 1) | Const (@{const_name Ex}, _) $ Abs (s, T, t') => do_quant bs AExists pos s T t' + | (t0 as Const (@{const_name Ex}, _)) $ t1 => + do_formula bs pos (t0 $ eta_expand (map (snd o snd) bs) t1 1) | @{const HOL.conj} $ t1 $ t2 => do_conn bs AAnd pos t1 pos t2 | @{const HOL.disj} $ t1 $ t2 => do_conn bs AOr pos t1 pos t2 | @{const HOL.implies} $ t1 $ t2 => @@ -1163,20 +1165,22 @@ | freeze t = t in t |> exists_subterm is_Var t ? freeze end -fun presimp_prop ctxt presimp_consts t = - let - val thy = Proof_Context.theory_of ctxt - val t = t |> Envir.beta_eta_contract - |> transform_elim_prop - |> Object_Logic.atomize_term thy - val need_trueprop = (fastype_of t = @{typ bool}) - in - t |> need_trueprop ? HOLogic.mk_Trueprop - |> Raw_Simplifier.rewrite_term thy (Meson.unfold_set_const_simps ctxt) [] - |> extensionalize_term ctxt - |> presimplify_term ctxt presimp_consts - |> perhaps (try (HOLogic.dest_Trueprop)) - end +fun presimp_prop ctxt presimp_consts role t = + (let + val thy = Proof_Context.theory_of ctxt + val t = t |> Envir.beta_eta_contract + |> transform_elim_prop + |> Object_Logic.atomize_term thy + val need_trueprop = (fastype_of t = @{typ bool}) + in + t |> need_trueprop ? HOLogic.mk_Trueprop + |> Raw_Simplifier.rewrite_term thy (Meson.unfold_set_const_simps ctxt) [] + |> extensionalize_term ctxt + |> presimplify_term ctxt presimp_consts + |> HOLogic.dest_Trueprop + end + handle TERM _ => if role = Conjecture then @{term False} else @{term True}) + |> pair role (* making fact and conjecture formulas *) fun make_formula ctxt format type_enc eq_as_iff name loc kind t = @@ -1197,7 +1201,8 @@ | formula => SOME formula fun s_not_trueprop (@{const Trueprop} $ t) = @{const Trueprop} $ s_not t - | s_not_trueprop t = s_not t + | s_not_trueprop t = + if fastype_of t = @{typ bool} then s_not t else @{prop False} (* too meta *) fun make_conjecture ctxt format type_enc = map (fn ((name, loc), (kind, t)) => @@ -1652,14 +1657,14 @@ val facts = facts |> map (apsnd (pair Axiom)) val conjs = map (pair prem_kind) hyp_ts @ [(Conjecture, s_not_trueprop concl_t)] + |> map (apsnd freeze_term) |> map2 (pair o rpair Local o string_of_int) (0 upto length hyp_ts) val ((conjs, facts), lambdas) = if preproc then conjs @ facts - |> map (apsnd (apsnd (presimp_prop ctxt presimp_consts))) + |> map (apsnd (uncurry (presimp_prop ctxt presimp_consts))) |> preprocess_abstractions_in_terms trans_lambdas |>> chop (length conjs) - |>> apfst (map (apsnd (apsnd freeze_term))) else ((conjs, facts), []) val conjs = conjs |> make_conjecture ctxt format type_enc diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Tools/Datatype/datatype_codegen.ML --- a/src/HOL/Tools/Datatype/datatype_codegen.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Tools/Datatype/datatype_codegen.ML Wed Oct 19 17:45:25 2011 +0200 @@ -147,294 +147,8 @@ end; -(** SML code generator **) - -(* datatype definition *) - -fun add_dt_defs thy mode defs dep module descr sorts gr = - let - val descr' = filter (can (map Datatype_Aux.dest_DtTFree o #2 o snd)) descr; - val rtnames = map (#1 o snd) (filter (fn (_, (_, _, cs)) => - exists (exists Datatype_Aux.is_rec_type o snd) cs) descr'); - - val (_, (tname, _, _)) :: _ = descr'; - val node_id = tname ^ " (type)"; - val module' = Codegen.if_library mode (Codegen.thyname_of_type thy tname) module; - - fun mk_dtdef prfx [] gr = ([], gr) - | mk_dtdef prfx ((_, (tname, dts, cs))::xs) gr = - let - val tvs = map Datatype_Aux.dest_DtTFree dts; - val cs' = map (apsnd (map (Datatype_Aux.typ_of_dtyp descr sorts))) cs; - val ((_, type_id), gr') = Codegen.mk_type_id module' tname gr; - val (ps, gr'') = gr' |> - fold_map (fn (cname, cargs) => - fold_map (Codegen.invoke_tycodegen thy mode defs node_id module' false) - cargs ##>> - Codegen.mk_const_id module' cname) cs'; - val (rest, gr''') = mk_dtdef "and " xs gr'' - in - (Pretty.block (Codegen.str prfx :: - (if null tvs then [] else - [Codegen.mk_tuple (map Codegen.str tvs), Codegen.str " "]) @ - [Codegen.str (type_id ^ " ="), Pretty.brk 1] @ - flat (separate [Pretty.brk 1, Codegen.str "| "] - (map (fn (ps', (_, cname)) => [Pretty.block - (Codegen.str cname :: - (if null ps' then [] else - flat ([Codegen.str " of", Pretty.brk 1] :: - separate [Codegen.str " *", Pretty.brk 1] - (map single ps'))))]) ps))) :: rest, gr''') - end; - - fun mk_constr_term cname Ts T ps = - flat (separate [Codegen.str " $", Pretty.brk 1] - ([Codegen.str ("Const (\"" ^ cname ^ "\","), Pretty.brk 1, - Codegen.mk_type false (Ts ---> T), Codegen.str ")"] :: ps)); - - fun mk_term_of_def gr prfx [] = [] - | mk_term_of_def gr prfx ((_, (tname, dts, cs)) :: xs) = - let - val cs' = map (apsnd (map (Datatype_Aux.typ_of_dtyp descr sorts))) cs; - val dts' = map (Datatype_Aux.typ_of_dtyp descr sorts) dts; - val T = Type (tname, dts'); - val rest = mk_term_of_def gr "and " xs; - val (eqs, _) = fold_map (fn (cname, Ts) => fn prfx => - let val args = map (fn i => - Codegen.str ("x" ^ string_of_int i)) (1 upto length Ts) - in (Pretty.blk (4, - [Codegen.str prfx, Codegen.mk_term_of gr module' false T, Pretty.brk 1, - if null Ts then Codegen.str (snd (Codegen.get_const_id gr cname)) - else Codegen.parens (Pretty.block - [Codegen.str (snd (Codegen.get_const_id gr cname)), - Pretty.brk 1, Codegen.mk_tuple args]), - Codegen.str " =", Pretty.brk 1] @ - mk_constr_term cname Ts T - (map2 (fn x => fn U => [Pretty.block [Codegen.mk_term_of gr module' false U, - Pretty.brk 1, x]]) args Ts)), " | ") - end) cs' prfx - in eqs @ rest end; - - fun mk_gen_of_def gr prfx [] = [] - | mk_gen_of_def gr prfx ((i, (tname, dts, cs)) :: xs) = - let - val tvs = map Datatype_Aux.dest_DtTFree dts; - val Us = map (Datatype_Aux.typ_of_dtyp descr sorts) dts; - val T = Type (tname, Us); - val (cs1, cs2) = - List.partition (exists Datatype_Aux.is_rec_type o snd) cs; - val SOME (cname, _) = Datatype_Aux.find_shortest_path descr i; - - fun mk_delay p = Pretty.block - [Codegen.str "fn () =>", Pretty.brk 1, p]; - - fun mk_force p = Pretty.block [p, Pretty.brk 1, Codegen.str "()"]; - - fun mk_constr s b (cname, dts) = - let - val gs = map (fn dt => Codegen.mk_app false - (Codegen.mk_gen gr module' false rtnames s - (Datatype_Aux.typ_of_dtyp descr sorts dt)) - [Codegen.str (if b andalso Datatype_Aux.is_rec_type dt then "0" - else "j")]) dts; - val Ts = map (Datatype_Aux.typ_of_dtyp descr sorts) dts; - val xs = map Codegen.str - (Datatype_Prop.indexify_names (replicate (length dts) "x")); - val ts = map Codegen.str - (Datatype_Prop.indexify_names (replicate (length dts) "t")); - val (_, id) = Codegen.get_const_id gr cname; - in - Codegen.mk_let - (map2 (fn p => fn q => Codegen.mk_tuple [p, q]) xs ts ~~ gs) - (Codegen.mk_tuple - [case xs of - _ :: _ :: _ => Pretty.block - [Codegen.str id, Pretty.brk 1, Codegen.mk_tuple xs] - | _ => Codegen.mk_app false (Codegen.str id) xs, - mk_delay (Pretty.block (mk_constr_term cname Ts T - (map (single o mk_force) ts)))]) - end; - - fun mk_choice [c] = mk_constr "(i-1)" false c - | mk_choice cs = Pretty.block [Codegen.str "one_of", - Pretty.brk 1, Pretty.blk (1, Codegen.str "[" :: - flat (separate [Codegen.str ",", Pretty.fbrk] - (map (single o mk_delay o mk_constr "(i-1)" false) cs)) @ - [Codegen.str "]"]), Pretty.brk 1, Codegen.str "()"]; - - val gs = maps (fn s => - let val s' = Codegen.strip_tname s - in [Codegen.str (s' ^ "G"), Codegen.str (s' ^ "T")] end) tvs; - val gen_name = "gen_" ^ snd (Codegen.get_type_id gr tname) - - in - Pretty.blk (4, separate (Pretty.brk 1) - (Codegen.str (prfx ^ gen_name ^ - (if null cs1 then "" else "'")) :: gs @ - (if null cs1 then [] else [Codegen.str "i"]) @ - [Codegen.str "j"]) @ - [Codegen.str " =", Pretty.brk 1] @ - (if not (null cs1) andalso not (null cs2) - then [Codegen.str "frequency", Pretty.brk 1, - Pretty.blk (1, [Codegen.str "[", - Codegen.mk_tuple [Codegen.str "i", mk_delay (mk_choice cs1)], - Codegen.str ",", Pretty.fbrk, - Codegen.mk_tuple [Codegen.str "1", mk_delay (mk_choice cs2)], - Codegen.str "]"]), Pretty.brk 1, Codegen.str "()"] - else if null cs2 then - [Pretty.block [Codegen.str "(case", Pretty.brk 1, - Codegen.str "i", Pretty.brk 1, Codegen.str "of", - Pretty.brk 1, Codegen.str "0 =>", Pretty.brk 1, - mk_constr "0" true (cname, the (AList.lookup (op =) cs cname)), - Pretty.brk 1, Codegen.str "| _ =>", Pretty.brk 1, - mk_choice cs1, Codegen.str ")"]] - else [mk_choice cs2])) :: - (if null cs1 then [] - else [Pretty.blk (4, separate (Pretty.brk 1) - (Codegen.str ("and " ^ gen_name) :: gs @ [Codegen.str "i"]) @ - [Codegen.str " =", Pretty.brk 1] @ - separate (Pretty.brk 1) (Codegen.str (gen_name ^ "'") :: gs @ - [Codegen.str "i", Codegen.str "i"]))]) @ - mk_gen_of_def gr "and " xs - end - - in - (module', (Codegen.add_edge_acyclic (node_id, dep) gr - handle Graph.CYCLES _ => gr) handle Graph.UNDEF _ => - let - val gr1 = Codegen.add_edge (node_id, dep) - (Codegen.new_node (node_id, (NONE, "", "")) gr); - val (dtdef, gr2) = mk_dtdef "datatype " descr' gr1 ; - in - Codegen.map_node node_id (K (NONE, module', - Codegen.string_of (Pretty.blk (0, separate Pretty.fbrk dtdef @ - [Codegen.str ";"])) ^ "\n\n" ^ - (if member (op =) mode "term_of" then - Codegen.string_of (Pretty.blk (0, separate Pretty.fbrk - (mk_term_of_def gr2 "fun " descr') @ [Codegen.str ";"])) ^ "\n\n" - else "") ^ - (if member (op =) mode "test" then - Codegen.string_of (Pretty.blk (0, separate Pretty.fbrk - (mk_gen_of_def gr2 "fun " descr') @ [Codegen.str ";"])) ^ "\n\n" - else ""))) gr2 - end) - end; - - -(* case expressions *) - -fun pretty_case thy mode defs dep module brack constrs (c as Const (_, T)) ts gr = - let val i = length constrs - in if length ts <= i then - Codegen.invoke_codegen thy mode defs dep module brack (Codegen.eta_expand c ts (i+1)) gr - else - let - val ts1 = take i ts; - val t :: ts2 = drop i ts; - val names = List.foldr Misc_Legacy.add_term_names - (map (fst o fst o dest_Var) (List.foldr Misc_Legacy.add_term_vars [] ts1)) ts1; - val (Ts, dT) = split_last (take (i+1) (binder_types T)); - - fun pcase [] [] [] gr = ([], gr) - | pcase ((cname, cargs)::cs) (t::ts) (U::Us) gr = - let - val j = length cargs; - val xs = Name.variant_list names (replicate j "x"); - val Us' = take j (binder_types U); - val frees = map2 (curry Free) xs Us'; - val (cp, gr0) = Codegen.invoke_codegen thy mode defs dep module false - (list_comb (Const (cname, Us' ---> dT), frees)) gr; - val t' = Envir.beta_norm (list_comb (t, frees)); - val (p, gr1) = Codegen.invoke_codegen thy mode defs dep module false t' gr0; - val (ps, gr2) = pcase cs ts Us gr1; - in - ([Pretty.block [cp, Codegen.str " =>", Pretty.brk 1, p]] :: ps, gr2) - end; - - val (ps1, gr1) = pcase constrs ts1 Ts gr ; - val ps = flat (separate [Pretty.brk 1, Codegen.str "| "] ps1); - val (p, gr2) = Codegen.invoke_codegen thy mode defs dep module false t gr1; - val (ps2, gr3) = fold_map (Codegen.invoke_codegen thy mode defs dep module true) ts2 gr2; - in ((if not (null ts2) andalso brack then Codegen.parens else I) - (Pretty.block (separate (Pretty.brk 1) - (Pretty.block ([Codegen.str "(case ", p, Codegen.str " of", - Pretty.brk 1] @ ps @ [Codegen.str ")"]) :: ps2))), gr3) - end - end; - - -(* constructors *) - -fun pretty_constr thy mode defs dep module brack args (c as Const (s, T)) ts gr = - let val i = length args - in if i > 1 andalso length ts < i then - Codegen.invoke_codegen thy mode defs dep module brack (Codegen.eta_expand c ts i) gr - else - let - val id = Codegen.mk_qual_id module (Codegen.get_const_id gr s); - val (ps, gr') = fold_map - (Codegen.invoke_codegen thy mode defs dep module (i = 1)) ts gr; - in - (case args of - _ :: _ :: _ => (if brack then Codegen.parens else I) - (Pretty.block [Codegen.str id, Pretty.brk 1, Codegen.mk_tuple ps]) - | _ => (Codegen.mk_app brack (Codegen.str id) ps), gr') - end - end; - - -(* code generators for terms and types *) - -fun datatype_codegen thy mode defs dep module brack t gr = - (case strip_comb t of - (c as Const (s, T), ts) => - (case Datatype_Data.info_of_case thy s of - SOME {index, descr, ...} => - if is_some (Codegen.get_assoc_code thy (s, T)) then NONE - else - SOME (pretty_case thy mode defs dep module brack - (#3 (the (AList.lookup op = descr index))) c ts gr) - | NONE => - (case (Datatype_Data.info_of_constr thy (s, T), body_type T) of - (SOME {index, descr, ...}, U as Type (tyname, _)) => - if is_some (Codegen.get_assoc_code thy (s, T)) then NONE - else - let - val SOME (tyname', _, constrs) = AList.lookup op = descr index; - val SOME args = AList.lookup op = constrs s; - in - if tyname <> tyname' then NONE - else - SOME - (pretty_constr thy mode defs - dep module brack args c ts - (snd (Codegen.invoke_tycodegen thy mode defs dep module false U gr))) - end - | _ => NONE)) - | _ => NONE); - -fun datatype_tycodegen thy mode defs dep module brack (Type (s, Ts)) gr = - (case Datatype_Data.get_info thy s of - NONE => NONE - | SOME {descr, sorts, ...} => - if is_some (Codegen.get_assoc_type thy s) then NONE else - let - val (ps, gr') = fold_map - (Codegen.invoke_tycodegen thy mode defs dep module false) Ts gr; - val (module', gr'') = add_dt_defs thy mode defs dep module descr sorts gr' ; - val (tyid, gr''') = Codegen.mk_type_id module' s gr'' - in SOME (Pretty.block ((if null Ts then [] else - [Codegen.mk_tuple ps, Codegen.str " "]) @ - [Codegen.str (Codegen.mk_qual_id module tyid)]), gr''') - end) - | datatype_tycodegen _ _ _ _ _ _ _ _ = NONE; - - (** theory setup **) -val setup = - Datatype_Data.interpretation add_all_code - #> Codegen.add_codegen "datatype" datatype_codegen - #> Codegen.add_tycodegen "datatype" datatype_tycodegen; +val setup = Datatype_Data.interpretation add_all_code; end; diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Tools/Qelim/cooper.ML --- a/src/HOL/Tools/Qelim/cooper.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Tools/Qelim/cooper.ML Wed Oct 19 17:45:25 2011 +0200 @@ -74,7 +74,8 @@ val false_tm = @{cterm "False"}; val zdvd1_eq = @{thm "zdvd1_eq"}; val presburger_ss = @{simpset} addsimps [zdvd1_eq]; -val lin_ss = presburger_ss addsimps (@{thm dvd_eq_mod_eq_0} :: zdvd1_eq :: @{thms zadd_ac}); +val lin_ss = + presburger_ss addsimps (@{thm dvd_eq_mod_eq_0} :: zdvd1_eq :: @{thms add_ac [where 'a=int]}); val iT = HOLogic.intT val bT = HOLogic.boolT; diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Tools/inductive_codegen.ML --- a/src/HOL/Tools/inductive_codegen.ML Tue Oct 18 15:19:06 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,929 +0,0 @@ -(* Title: HOL/Tools/inductive_codegen.ML - Author: Stefan Berghofer, TU Muenchen - -Code generator for inductive predicates. -*) - -signature INDUCTIVE_CODEGEN = -sig - val add: string option -> int option -> attribute - val poke_test_fn: (int * int * int -> term list option) -> unit - val test_term: Proof.context -> (term * term list) list -> int list -> - term list option * Quickcheck.report option - val active : bool Config.T - val setup: theory -> theory -end; - -structure Inductive_Codegen : INDUCTIVE_CODEGEN = -struct - -(**** theory data ****) - -fun merge_rules tabs = - Symtab.join (fn _ => AList.merge (Thm.eq_thm_prop) (K true)) tabs; - -structure CodegenData = Theory_Data -( - type T = - {intros : (thm * (string * int)) list Symtab.table, - graph : unit Graph.T, - eqns : (thm * string) list Symtab.table}; - val empty = - {intros = Symtab.empty, graph = Graph.empty, eqns = Symtab.empty}; - val extend = I; - fun merge - ({intros = intros1, graph = graph1, eqns = eqns1}, - {intros = intros2, graph = graph2, eqns = eqns2}) : T = - {intros = merge_rules (intros1, intros2), - graph = Graph.merge (K true) (graph1, graph2), - eqns = merge_rules (eqns1, eqns2)}; -); - - -fun warn thy thm = - warning ("Inductive_Codegen: Not a proper clause:\n" ^ - Display.string_of_thm_global thy thm); - -fun add_node x g = Graph.new_node (x, ()) g handle Graph.DUP _ => g; - -fun add optmod optnparms = Thm.declaration_attribute (fn thm => Context.mapping (fn thy => - let - val {intros, graph, eqns} = CodegenData.get thy; - fun thyname_of s = (case optmod of - NONE => Codegen.thyname_of_const thy s | SOME s => s); - in - (case Option.map strip_comb (try HOLogic.dest_Trueprop (concl_of thm)) of - SOME (Const (@{const_name HOL.eq}, _), [t, _]) => - (case head_of t of - Const (s, _) => - CodegenData.put {intros = intros, graph = graph, - eqns = eqns |> Symtab.map_default (s, []) - (AList.update Thm.eq_thm_prop (thm, thyname_of s))} thy - | _ => (warn thy thm; thy)) - | SOME (Const (s, _), _) => - let - val cs = fold Term.add_const_names (Thm.prems_of thm) []; - val rules = Symtab.lookup_list intros s; - val nparms = - (case optnparms of - SOME k => k - | NONE => - (case rules of - [] => - (case try (Inductive.the_inductive (Proof_Context.init_global thy)) s of - SOME (_, {raw_induct, ...}) => - length (Inductive.params_of raw_induct) - | NONE => 0) - | xs => snd (snd (List.last xs)))) - in CodegenData.put - {intros = intros |> - Symtab.update (s, (AList.update Thm.eq_thm_prop - (thm, (thyname_of s, nparms)) rules)), - graph = fold_rev (Graph.add_edge o pair s) cs (fold add_node (s :: cs) graph), - eqns = eqns} thy - end - | _ => (warn thy thm; thy)) - end) I); - -fun get_clauses thy s = - let val {intros, graph, ...} = CodegenData.get thy in - (case Symtab.lookup intros s of - NONE => - (case try (Inductive.the_inductive (Proof_Context.init_global thy)) s of - NONE => NONE - | SOME ({names, ...}, {intrs, raw_induct, ...}) => - SOME (names, Codegen.thyname_of_const thy s, - length (Inductive.params_of raw_induct), - Codegen.preprocess thy intrs)) - | SOME _ => - let - val SOME names = find_first - (fn xs => member (op =) xs s) (Graph.strong_conn graph); - val intrs as (_, (thyname, nparms)) :: _ = - maps (the o Symtab.lookup intros) names; - in SOME (names, thyname, nparms, Codegen.preprocess thy (map fst (rev intrs))) end) - end; - - -(**** check if a term contains only constructor functions ****) - -fun is_constrt thy = - let - val cnstrs = flat (maps - (map (fn (_, (_, _, cs)) => map (apsnd length) cs) o #descr o snd) - (Symtab.dest (Datatype_Data.get_all thy))); - fun check t = - (case strip_comb t of - (Var _, []) => true - | (Const (s, _), ts) => - (case AList.lookup (op =) cnstrs s of - NONE => false - | SOME i => length ts = i andalso forall check ts) - | _ => false); - in check end; - - -(**** check if a type is an equality type (i.e. doesn't contain fun) ****) - -fun is_eqT (Type (s, Ts)) = s <> "fun" andalso forall is_eqT Ts - | is_eqT _ = true; - - -(**** mode inference ****) - -fun string_of_mode (iss, is) = space_implode " -> " (map - (fn NONE => "X" - | SOME js => enclose "[" "]" (commas (map string_of_int js))) - (iss @ [SOME is])); - -fun print_modes modes = Codegen.message ("Inferred modes:\n" ^ - cat_lines (map (fn (s, ms) => s ^ ": " ^ commas (map - (fn (m, rnd) => string_of_mode m ^ - (if rnd then " (random)" else "")) ms)) modes)); - -val term_vs = map (fst o fst o dest_Var) o Misc_Legacy.term_vars; -val terms_vs = distinct (op =) o maps term_vs; - -(** collect all Vars in a term (with duplicates!) **) -fun term_vTs tm = - fold_aterms (fn Var ((x, _), T) => cons (x, T) | _ => I) tm []; - -fun get_args _ _ [] = ([], []) - | get_args is i (x::xs) = (if member (op =) is i then apfst else apsnd) (cons x) - (get_args is (i+1) xs); - -fun merge xs [] = xs - | merge [] ys = ys - | merge (x::xs) (y::ys) = if length x >= length y then x::merge xs (y::ys) - else y::merge (x::xs) ys; - -fun subsets i j = if i <= j then - let val is = subsets (i+1) j - in merge (map (fn ks => i::ks) is) is end - else [[]]; - -fun cprod ([], ys) = [] - | cprod (x :: xs, ys) = map (pair x) ys @ cprod (xs, ys); - -fun cprods xss = List.foldr (map op :: o cprod) [[]] xss; - -datatype mode = Mode of ((int list option list * int list) * bool) * int list * mode option list; - -fun needs_random (Mode ((_, b), _, ms)) = - b orelse exists (fn NONE => false | SOME m => needs_random m) ms; - -fun modes_of modes t = - let - val ks = 1 upto length (binder_types (fastype_of t)); - val default = [Mode ((([], ks), false), ks, [])]; - fun mk_modes name args = Option.map - (maps (fn (m as ((iss, is), _)) => - let - val (args1, args2) = - if length args < length iss then - error ("Too few arguments for inductive predicate " ^ name) - else chop (length iss) args; - val k = length args2; - val prfx = 1 upto k - in - if not (is_prefix op = prfx is) then [] else - let val is' = map (fn i => i - k) (List.drop (is, k)) - in map (fn x => Mode (m, is', x)) (cprods (map - (fn (NONE, _) => [NONE] - | (SOME js, arg) => map SOME (filter - (fn Mode (_, js', _) => js=js') (modes_of modes arg))) - (iss ~~ args1))) - end - end)) (AList.lookup op = modes name) - - in - (case strip_comb t of - (Const (@{const_name HOL.eq}, Type (_, [T, _])), _) => - [Mode ((([], [1]), false), [1], []), Mode ((([], [2]), false), [2], [])] @ - (if is_eqT T then [Mode ((([], [1, 2]), false), [1, 2], [])] else []) - | (Const (name, _), args) => the_default default (mk_modes name args) - | (Var ((name, _), _), args) => the (mk_modes name args) - | (Free (name, _), args) => the (mk_modes name args) - | _ => default) - end; - -datatype indprem = Prem of term list * term * bool | Sidecond of term; - -fun missing_vars vs ts = subtract (fn (x, ((y, _), _)) => x = y) vs - (fold Term.add_vars ts []); - -fun monomorphic_vars vs = null (fold (Term.add_tvarsT o snd) vs []); - -fun mode_ord p = int_ord (pairself (fn (Mode ((_, rnd), _, _), vs) => - length vs + (if null vs then 0 else 1) + (if rnd then 1 else 0)) p); - -fun select_mode_prem thy modes vs ps = - sort (mode_ord o pairself (hd o snd)) - (filter_out (null o snd) (ps ~~ map - (fn Prem (us, t, is_set) => sort mode_ord - (map_filter (fn m as Mode (_, is, _) => - let - val (in_ts, out_ts) = get_args is 1 us; - val (out_ts', in_ts') = List.partition (is_constrt thy) out_ts; - val vTs = maps term_vTs out_ts'; - val dupTs = map snd (duplicates (op =) vTs) @ - map_filter (AList.lookup (op =) vTs) vs; - val missing_vs = missing_vars vs (t :: in_ts @ in_ts') - in - if forall (is_eqT o fastype_of) in_ts' andalso forall is_eqT dupTs - andalso monomorphic_vars missing_vs - then SOME (m, missing_vs) - else NONE - end) - (if is_set then [Mode ((([], []), false), [], [])] - else modes_of modes t handle Option => - error ("Bad predicate: " ^ Syntax.string_of_term_global thy t))) - | Sidecond t => - let val missing_vs = missing_vars vs [t] - in - if monomorphic_vars missing_vs - then [(Mode ((([], []), false), [], []), missing_vs)] - else [] - end) - ps)); - -fun use_random codegen_mode = member (op =) codegen_mode "random_ind"; - -fun check_mode_clause thy codegen_mode arg_vs modes ((iss, is), rnd) (ts, ps) = - let - val modes' = modes @ map_filter - (fn (_, NONE) => NONE | (v, SOME js) => SOME (v, [(([], js), false)])) - (arg_vs ~~ iss); - fun check_mode_prems vs rnd [] = SOME (vs, rnd) - | check_mode_prems vs rnd ps = - (case select_mode_prem thy modes' vs ps of - (x, (m, []) :: _) :: _ => - check_mode_prems - (case x of Prem (us, _, _) => union (op =) vs (terms_vs us) | _ => vs) - (rnd orelse needs_random m) - (filter_out (equal x) ps) - | (_, (_, vs') :: _) :: _ => - if use_random codegen_mode then - check_mode_prems (union (op =) vs (map (fst o fst) vs')) true ps - else NONE - | _ => NONE); - val (in_ts, in_ts') = List.partition (is_constrt thy) (fst (get_args is 1 ts)); - val in_vs = terms_vs in_ts; - in - if forall is_eqT (map snd (duplicates (op =) (maps term_vTs in_ts))) andalso - forall (is_eqT o fastype_of) in_ts' - then - (case check_mode_prems (union (op =) arg_vs in_vs) rnd ps of - NONE => NONE - | SOME (vs, rnd') => - let val missing_vs = missing_vars vs ts - in - if null missing_vs orelse - use_random codegen_mode andalso monomorphic_vars missing_vs - then SOME (rnd' orelse not (null missing_vs)) - else NONE - end) - else NONE - end; - -fun check_modes_pred thy codegen_mode arg_vs preds modes (p, ms) = - let val SOME rs = AList.lookup (op =) preds p in - (p, map_filter (fn m as (m', _) => - let val xs = map (check_mode_clause thy codegen_mode arg_vs modes m) rs in - (case find_index is_none xs of - ~1 => SOME (m', exists (fn SOME b => b) xs) - | i => (Codegen.message ("Clause " ^ string_of_int (i+1) ^ " of " ^ - p ^ " violates mode " ^ string_of_mode m'); NONE)) - end) ms) - end; - -fun fixp f (x : (string * ((int list option list * int list) * bool) list) list) = - let val y = f x - in if x = y then x else fixp f y end; - -fun infer_modes thy codegen_mode extra_modes arities arg_vs preds = fixp (fn modes => - map (check_modes_pred thy codegen_mode arg_vs preds (modes @ extra_modes)) modes) - (map (fn (s, (ks, k)) => (s, map (rpair false) (cprod (cprods (map - (fn NONE => [NONE] - | SOME k' => map SOME (subsets 1 k')) ks), - subsets 1 k)))) arities); - - -(**** code generation ****) - -fun mk_eq (x::xs) = - let - fun mk_eqs _ [] = [] - | mk_eqs a (b :: cs) = Codegen.str (a ^ " = " ^ b) :: mk_eqs b cs; - in mk_eqs x xs end; - -fun mk_tuple xs = - Pretty.block (Codegen.str "(" :: - flat (separate [Codegen.str ",", Pretty.brk 1] (map single xs)) @ - [Codegen.str ")"]); - -fun mk_v s (names, vs) = - (case AList.lookup (op =) vs s of - NONE => (s, (names, (s, [s])::vs)) - | SOME xs => - let val s' = singleton (Name.variant_list names) s - in (s', (s'::names, AList.update (op =) (s, s'::xs) vs)) end); - -fun distinct_v (Var ((s, 0), T)) nvs = - let val (s', nvs') = mk_v s nvs - in (Var ((s', 0), T), nvs') end - | distinct_v (t $ u) nvs = - let - val (t', nvs') = distinct_v t nvs; - val (u', nvs'') = distinct_v u nvs'; - in (t' $ u', nvs'') end - | distinct_v t nvs = (t, nvs); - -fun is_exhaustive (Var _) = true - | is_exhaustive (Const (@{const_name Pair}, _) $ t $ u) = - is_exhaustive t andalso is_exhaustive u - | is_exhaustive _ = false; - -fun compile_match nvs eq_ps out_ps success_p can_fail = - let val eqs = flat (separate [Codegen.str " andalso", Pretty.brk 1] - (map single (maps (mk_eq o snd) nvs @ eq_ps))); - in - Pretty.block - ([Codegen.str "(fn ", mk_tuple out_ps, Codegen.str " =>", Pretty.brk 1] @ - (Pretty.block ((if null eqs then [] else Codegen.str "if " :: - [Pretty.block eqs, Pretty.brk 1, Codegen.str "then "]) @ - (success_p :: - (if null eqs then [] else [Pretty.brk 1, Codegen.str "else DSeq.empty"]))) :: - (if can_fail then - [Pretty.brk 1, Codegen.str "| _ => DSeq.empty)"] - else [Codegen.str ")"]))) - end; - -fun modename module s (iss, is) gr = - let val (id, gr') = if s = @{const_name HOL.eq} then (("", "equal"), gr) - else Codegen.mk_const_id module s gr - in (space_implode "__" - (Codegen.mk_qual_id module id :: - map (space_implode "_" o map string_of_int) (map_filter I iss @ [is])), gr') - end; - -fun mk_funcomp brack s k p = (if brack then Codegen.parens else I) - (Pretty.block [Pretty.block ((if k = 0 then [] else [Codegen.str "("]) @ - separate (Pretty.brk 1) (Codegen.str s :: replicate k (Codegen.str "|> ???")) @ - (if k = 0 then [] else [Codegen.str ")"])), Pretty.brk 1, p]); - -fun compile_expr thy codegen_mode defs dep module brack modes (NONE, t) gr = - apfst single (Codegen.invoke_codegen thy codegen_mode defs dep module brack t gr) - | compile_expr _ _ _ _ _ _ _ (SOME _, Var ((name, _), _)) gr = - ([Codegen.str name], gr) - | compile_expr thy codegen_mode - defs dep module brack modes (SOME (Mode ((mode, _), _, ms)), t) gr = - (case strip_comb t of - (Const (name, _), args) => - if name = @{const_name HOL.eq} orelse AList.defined op = modes name then - let - val (args1, args2) = chop (length ms) args; - val ((ps, mode_id), gr') = - gr |> fold_map - (compile_expr thy codegen_mode defs dep module true modes) (ms ~~ args1) - ||>> modename module name mode; - val (ps', gr'') = - (case mode of - ([], []) => ([Codegen.str "()"], gr') - | _ => fold_map - (Codegen.invoke_codegen thy codegen_mode defs dep module true) args2 gr'); - in - ((if brack andalso not (null ps andalso null ps') then - single o Codegen.parens o Pretty.block else I) - (flat (separate [Pretty.brk 1] - ([Codegen.str mode_id] :: ps @ map single ps'))), gr') - end - else - apfst (single o mk_funcomp brack "??" (length (binder_types (fastype_of t)))) - (Codegen.invoke_codegen thy codegen_mode defs dep module true t gr) - | _ => - apfst (single o mk_funcomp brack "??" (length (binder_types (fastype_of t)))) - (Codegen.invoke_codegen thy codegen_mode defs dep module true t gr)); - -fun compile_clause thy codegen_mode defs dep module all_vs arg_vs modes (iss, is) (ts, ps) inp gr = - let - val modes' = modes @ map_filter - (fn (_, NONE) => NONE | (v, SOME js) => SOME (v, [(([], js), false)])) - (arg_vs ~~ iss); - - fun check_constrt t (names, eqs) = - if is_constrt thy t then (t, (names, eqs)) - else - let val s = singleton (Name.variant_list names) "x"; - in (Var ((s, 0), fastype_of t), (s::names, (s, t)::eqs)) end; - - fun compile_eq (s, t) gr = - apfst (Pretty.block o cons (Codegen.str (s ^ " = ")) o single) - (Codegen.invoke_codegen thy codegen_mode defs dep module false t gr); - - val (in_ts, out_ts) = get_args is 1 ts; - val (in_ts', (all_vs', eqs)) = fold_map check_constrt in_ts (all_vs, []); - - fun compile_prems out_ts' vs names [] gr = - let - val (out_ps, gr2) = - fold_map (Codegen.invoke_codegen thy codegen_mode defs dep module false) - out_ts gr; - val (eq_ps, gr3) = fold_map compile_eq eqs gr2; - val (out_ts'', (names', eqs')) = fold_map check_constrt out_ts' (names, []); - val (out_ts''', nvs) = - fold_map distinct_v out_ts'' (names', map (fn x => (x, [x])) vs); - val (out_ps', gr4) = - fold_map (Codegen.invoke_codegen thy codegen_mode defs dep module false) - out_ts''' gr3; - val (eq_ps', gr5) = fold_map compile_eq eqs' gr4; - val vs' = distinct (op =) (flat (vs :: map term_vs out_ts')); - val missing_vs = missing_vars vs' out_ts; - val final_p = Pretty.block - [Codegen.str "DSeq.single", Pretty.brk 1, mk_tuple out_ps] - in - if null missing_vs then - (compile_match (snd nvs) (eq_ps @ eq_ps') out_ps' - final_p (exists (not o is_exhaustive) out_ts'''), gr5) - else - let - val (pat_p, gr6) = - Codegen.invoke_codegen thy codegen_mode defs dep module true - (HOLogic.mk_tuple (map Var missing_vs)) gr5; - val gen_p = - Codegen.mk_gen gr6 module true [] "" - (HOLogic.mk_tupleT (map snd missing_vs)); - in - (compile_match (snd nvs) eq_ps' out_ps' - (Pretty.block [Codegen.str "DSeq.generator ", gen_p, - Codegen.str " :->", Pretty.brk 1, - compile_match [] eq_ps [pat_p] final_p false]) - (exists (not o is_exhaustive) out_ts'''), - gr6) - end - end - | compile_prems out_ts vs names ps gr = - let - val vs' = distinct (op =) (flat (vs :: map term_vs out_ts)); - val (out_ts', (names', eqs)) = fold_map check_constrt out_ts (names, []); - val (out_ts'', nvs) = - fold_map distinct_v out_ts' (names', map (fn x => (x, [x])) vs); - val (out_ps, gr0) = - fold_map (Codegen.invoke_codegen thy codegen_mode defs dep module false) - out_ts'' gr; - val (eq_ps, gr1) = fold_map compile_eq eqs gr0; - in - (case hd (select_mode_prem thy modes' vs' ps) of - (p as Prem (us, t, is_set), (mode as Mode (_, js, _), []) :: _) => - let - val ps' = filter_out (equal p) ps; - val (in_ts, out_ts''') = get_args js 1 us; - val (in_ps, gr2) = - fold_map (Codegen.invoke_codegen thy codegen_mode defs dep module true) - in_ts gr1; - val (ps, gr3) = - if not is_set then - apfst (fn ps => ps @ - (if null in_ps then [] else [Pretty.brk 1]) @ - separate (Pretty.brk 1) in_ps) - (compile_expr thy codegen_mode defs dep module false modes - (SOME mode, t) gr2) - else - apfst (fn p => - Pretty.breaks [Codegen.str "DSeq.of_list", Codegen.str "(case", p, - Codegen.str "of", Codegen.str "Set", Codegen.str "xs", Codegen.str "=>", - Codegen.str "xs)"]) - (*this is a very strong assumption about the generated code!*) - (Codegen.invoke_codegen thy codegen_mode defs dep module true t gr2); - val (rest, gr4) = compile_prems out_ts''' vs' (fst nvs) ps' gr3; - in - (compile_match (snd nvs) eq_ps out_ps - (Pretty.block (ps @ - [Codegen.str " :->", Pretty.brk 1, rest])) - (exists (not o is_exhaustive) out_ts''), gr4) - end - | (p as Sidecond t, [(_, [])]) => - let - val ps' = filter_out (equal p) ps; - val (side_p, gr2) = - Codegen.invoke_codegen thy codegen_mode defs dep module true t gr1; - val (rest, gr3) = compile_prems [] vs' (fst nvs) ps' gr2; - in - (compile_match (snd nvs) eq_ps out_ps - (Pretty.block [Codegen.str "?? ", side_p, - Codegen.str " :->", Pretty.brk 1, rest]) - (exists (not o is_exhaustive) out_ts''), gr3) - end - | (_, (_, missing_vs) :: _) => - let - val T = HOLogic.mk_tupleT (map snd missing_vs); - val (_, gr2) = - Codegen.invoke_tycodegen thy codegen_mode defs dep module false T gr1; - val gen_p = Codegen.mk_gen gr2 module true [] "" T; - val (rest, gr3) = compile_prems - [HOLogic.mk_tuple (map Var missing_vs)] vs' (fst nvs) ps gr2; - in - (compile_match (snd nvs) eq_ps out_ps - (Pretty.block [Codegen.str "DSeq.generator", Pretty.brk 1, - gen_p, Codegen.str " :->", Pretty.brk 1, rest]) - (exists (not o is_exhaustive) out_ts''), gr3) - end) - end; - - val (prem_p, gr') = compile_prems in_ts' arg_vs all_vs' ps gr ; - in - (Pretty.block [Codegen.str "DSeq.single", Pretty.brk 1, inp, - Codegen.str " :->", Pretty.brk 1, prem_p], gr') - end; - -fun compile_pred thy codegen_mode defs dep module prfx all_vs arg_vs modes s cls mode gr = - let - val xs = map Codegen.str (Name.variant_list arg_vs - (map (fn i => "x" ^ string_of_int i) (snd mode))); - val ((cl_ps, mode_id), gr') = gr |> - fold_map (fn cl => compile_clause thy codegen_mode defs - dep module all_vs arg_vs modes mode cl (mk_tuple xs)) cls ||>> - modename module s mode - in - (Pretty.block - ([Pretty.block (separate (Pretty.brk 1) - (Codegen.str (prfx ^ mode_id) :: - map Codegen.str arg_vs @ - (case mode of ([], []) => [Codegen.str "()"] | _ => xs)) @ - [Codegen.str " ="]), - Pretty.brk 1] @ - flat (separate [Codegen.str " ++", Pretty.brk 1] (map single cl_ps))), (gr', "and ")) - end; - -fun compile_preds thy codegen_mode defs dep module all_vs arg_vs modes preds gr = - let val (prs, (gr', _)) = fold_map (fn (s, cls) => - fold_map (fn (mode, _) => fn (gr', prfx') => compile_pred thy codegen_mode defs - dep module prfx' all_vs arg_vs modes s cls mode gr') - (((the o AList.lookup (op =) modes) s))) preds (gr, "fun ") - in - (space_implode "\n\n" (map Codegen.string_of (flat prs)) ^ ";\n\n", gr') - end; - -(**** processing of introduction rules ****) - -exception Modes of - (string * ((int list option list * int list) * bool) list) list * - (string * (int option list * int)) list; - -fun lookup_modes gr dep = apfst flat (apsnd flat (ListPair.unzip - (map ((fn (SOME (Modes x), _, _) => x | _ => ([], [])) o Codegen.get_node gr) - (Graph.all_preds (fst gr) [dep])))); - -fun print_arities arities = Codegen.message ("Arities:\n" ^ - cat_lines (map (fn (s, (ks, k)) => s ^ ": " ^ - space_implode " -> " (map - (fn NONE => "X" | SOME k' => string_of_int k') - (ks @ [SOME k]))) arities)); - -fun prep_intrs intrs = - map (Codegen.rename_term o Thm.prop_of o Drule.export_without_context) intrs; - -fun constrain cs [] = [] - | constrain cs ((s, xs) :: ys) = - (s, - (case AList.lookup (op =) cs (s : string) of - NONE => xs - | SOME xs' => inter (op = o apfst fst) xs' xs)) :: constrain cs ys; - -fun mk_extra_defs thy codegen_mode defs gr dep names module ts = - fold (fn name => fn gr => - if member (op =) names name then gr - else - (case get_clauses thy name of - NONE => gr - | SOME (names, thyname, nparms, intrs) => - mk_ind_def thy codegen_mode defs gr dep names - (Codegen.if_library codegen_mode thyname module) - [] (prep_intrs intrs) nparms)) - (fold Term.add_const_names ts []) gr - -and mk_ind_def thy codegen_mode defs gr dep names module modecs intrs nparms = - Codegen.add_edge_acyclic (hd names, dep) gr handle - Graph.CYCLES (xs :: _) => - error ("Inductive_Codegen: illegal cyclic dependencies:\n" ^ commas xs) - | Graph.UNDEF _ => - let - val _ $ u = Logic.strip_imp_concl (hd intrs); - val args = List.take (snd (strip_comb u), nparms); - val arg_vs = maps term_vs args; - - fun get_nparms s = if member (op =) names s then SOME nparms else - Option.map #3 (get_clauses thy s); - - fun dest_prem (_ $ (Const (@{const_name Set.member}, _) $ t $ u)) = - Prem ([t], Envir.beta_eta_contract u, true) - | dest_prem (_ $ ((eq as Const (@{const_name HOL.eq}, _)) $ t $ u)) = - Prem ([t, u], eq, false) - | dest_prem (_ $ t) = - (case strip_comb t of - (v as Var _, ts) => - if member (op =) args v then Prem (ts, v, false) else Sidecond t - | (c as Const (s, _), ts) => - (case get_nparms s of - NONE => Sidecond t - | SOME k => - let val (ts1, ts2) = chop k ts - in Prem (ts2, list_comb (c, ts1), false) end) - | _ => Sidecond t); - - fun add_clause intr (clauses, arities) = - let - val _ $ t = Logic.strip_imp_concl intr; - val (Const (name, T), ts) = strip_comb t; - val (ts1, ts2) = chop nparms ts; - val prems = map dest_prem (Logic.strip_imp_prems intr); - val (Ts, Us) = chop nparms (binder_types T) - in - (AList.update op = (name, these (AList.lookup op = clauses name) @ - [(ts2, prems)]) clauses, - AList.update op = (name, (map (fn U => - (case strip_type U of - (Rs as _ :: _, @{typ bool}) => SOME (length Rs) - | _ => NONE)) Ts, - length Us)) arities) - end; - - val gr' = mk_extra_defs thy codegen_mode defs - (Codegen.add_edge (hd names, dep) - (Codegen.new_node (hd names, (NONE, "", "")) gr)) (hd names) names module intrs; - val (extra_modes, extra_arities) = lookup_modes gr' (hd names); - val (clauses, arities) = fold add_clause intrs ([], []); - val modes = constrain modecs - (infer_modes thy codegen_mode extra_modes arities arg_vs clauses); - val _ = print_arities arities; - val _ = print_modes modes; - val (s, gr'') = - compile_preds thy codegen_mode defs (hd names) module (terms_vs intrs) - arg_vs (modes @ extra_modes) clauses gr'; - in - (Codegen.map_node (hd names) - (K (SOME (Modes (modes, arities)), module, s)) gr'') - end; - -fun find_mode gr dep s u modes is = - (case find_first (fn Mode (_, js, _) => is = js) (modes_of modes u handle Option => []) of - NONE => - Codegen.codegen_error gr dep - ("No such mode for " ^ s ^ ": " ^ string_of_mode ([], is)) - | mode => mode); - -fun mk_ind_call thy codegen_mode defs dep module is_query s T ts names thyname k intrs gr = - let - val (ts1, ts2) = chop k ts; - val u = list_comb (Const (s, T), ts1); - - fun mk_mode (Const (@{const_name dummy_pattern}, _)) ((ts, mode), i) = - ((ts, mode), i + 1) - | mk_mode t ((ts, mode), i) = ((ts @ [t], mode @ [i]), i + 1); - - val module' = Codegen.if_library codegen_mode thyname module; - val gr1 = - mk_extra_defs thy codegen_mode defs - (mk_ind_def thy codegen_mode defs gr dep names module' - [] (prep_intrs intrs) k) dep names module' [u]; - val (modes, _) = lookup_modes gr1 dep; - val (ts', is) = - if is_query then fst (fold mk_mode ts2 (([], []), 1)) - else (ts2, 1 upto length (binder_types T) - k); - val mode = find_mode gr1 dep s u modes is; - val _ = if is_query orelse not (needs_random (the mode)) then () - else warning ("Illegal use of random data generators in " ^ s); - val (in_ps, gr2) = - fold_map (Codegen.invoke_codegen thy codegen_mode defs dep module true) - ts' gr1; - val (ps, gr3) = - compile_expr thy codegen_mode defs dep module false modes (mode, u) gr2; - in - (Pretty.block (ps @ (if null in_ps then [] else [Pretty.brk 1]) @ - separate (Pretty.brk 1) in_ps), gr3) - end; - -fun clause_of_eqn eqn = - let - val (t, u) = HOLogic.dest_eq (HOLogic.dest_Trueprop (concl_of eqn)); - val (Const (s, T), ts) = strip_comb t; - val (Ts, U) = strip_type T - in - Codegen.rename_term (Logic.list_implies (prems_of eqn, HOLogic.mk_Trueprop - (list_comb (Const (s ^ "_aux", Ts @ [U] ---> HOLogic.boolT), ts @ [u])))) - end; - -fun mk_fun thy codegen_mode defs name eqns dep module module' gr = - (case try (Codegen.get_node gr) name of - NONE => - let - val clauses = map clause_of_eqn eqns; - val pname = name ^ "_aux"; - val arity = - length (snd (strip_comb (fst (HOLogic.dest_eq - (HOLogic.dest_Trueprop (concl_of (hd eqns))))))); - val mode = 1 upto arity; - val ((fun_id, mode_id), gr') = gr |> - Codegen.mk_const_id module' name ||>> - modename module' pname ([], mode); - val vars = map (fn i => Codegen.str ("x" ^ string_of_int i)) mode; - val s = Codegen.string_of (Pretty.block - [Codegen.mk_app false (Codegen.str ("fun " ^ snd fun_id)) vars, Codegen.str " =", - Pretty.brk 1, Codegen.str "DSeq.hd", Pretty.brk 1, - Codegen.parens (Pretty.block (separate (Pretty.brk 1) (Codegen.str mode_id :: - vars)))]) ^ ";\n\n"; - val gr'' = mk_ind_def thy codegen_mode defs (Codegen.add_edge (name, dep) - (Codegen.new_node (name, (NONE, module', s)) gr')) name [pname] module' - [(pname, [([], mode)])] clauses 0; - val (modes, _) = lookup_modes gr'' dep; - val _ = find_mode gr'' dep pname (head_of (HOLogic.dest_Trueprop - (Logic.strip_imp_concl (hd clauses)))) modes mode - in (Codegen.mk_qual_id module fun_id, gr'') end - | SOME _ => - (Codegen.mk_qual_id module (Codegen.get_const_id gr name), - Codegen.add_edge (name, dep) gr)); - -(* convert n-tuple to nested pairs *) - -fun conv_ntuple fs ts p = - let - val k = length fs; - val xs = map_range (fn i => Codegen.str ("x" ^ string_of_int i)) (k + 1); - val xs' = map (fn Bound i => nth xs (k - i)) ts; - fun conv xs js = - if member (op =) fs js then - let - val (p, xs') = conv xs (1::js); - val (q, xs'') = conv xs' (2::js) - in (mk_tuple [p, q], xs'') end - else (hd xs, tl xs) - in - if k > 0 then - Pretty.block - [Codegen.str "DSeq.map (fn", Pretty.brk 1, - mk_tuple xs', Codegen.str " =>", Pretty.brk 1, fst (conv xs []), - Codegen.str ")", Pretty.brk 1, Codegen.parens p] - else p - end; - -fun inductive_codegen thy codegen_mode defs dep module brack t gr = - (case strip_comb t of - (Const (@{const_name Collect}, _), [u]) => - let val (r, Ts, fs) = HOLogic.strip_psplits u in - (case strip_comb r of - (Const (s, T), ts) => - (case (get_clauses thy s, Codegen.get_assoc_code thy (s, T)) of - (SOME (names, thyname, k, intrs), NONE) => - let - val (ts1, ts2) = chop k ts; - val ts2' = map - (fn Bound i => Term.dummy_pattern (nth Ts (length Ts - i - 1)) | t => t) ts2; - val (ots, its) = List.partition is_Bound ts2; - val closed = forall (not o Term.is_open); - in - if null (duplicates op = ots) andalso - closed ts1 andalso closed its - then - let - val (call_p, gr') = - mk_ind_call thy codegen_mode defs dep module true - s T (ts1 @ ts2') names thyname k intrs gr; - in - SOME ((if brack then Codegen.parens else I) (Pretty.block - [Codegen.str "Set", Pretty.brk 1, Codegen.str "(DSeq.list_of", Pretty.brk 1, - Codegen.str "(", conv_ntuple fs ots call_p, Codegen.str "))"]), - (*this is a very strong assumption about the generated code!*) - gr') - end - else NONE - end - | _ => NONE) - | _ => NONE) - end - | (Const (s, T), ts) => - (case Symtab.lookup (#eqns (CodegenData.get thy)) s of - NONE => - (case (get_clauses thy s, Codegen.get_assoc_code thy (s, T)) of - (SOME (names, thyname, k, intrs), NONE) => - if length ts < k then NONE else - SOME - (let - val (call_p, gr') = mk_ind_call thy codegen_mode defs dep module false - s T (map Term.no_dummy_patterns ts) names thyname k intrs gr - in - (mk_funcomp brack "?!" - (length (binder_types T) - length ts) (Codegen.parens call_p), gr') - end - handle TERM _ => - mk_ind_call thy codegen_mode defs dep module true - s T ts names thyname k intrs gr) - | _ => NONE) - | SOME eqns => - let - val (_, thyname) :: _ = eqns; - val (id, gr') = - mk_fun thy codegen_mode defs s (Codegen.preprocess thy (map fst (rev eqns))) - dep module (Codegen.if_library codegen_mode thyname module) gr; - val (ps, gr'') = - fold_map (Codegen.invoke_codegen thy codegen_mode defs dep module true) - ts gr'; - in SOME (Codegen.mk_app brack (Codegen.str id) ps, gr'') end) - | _ => NONE); - -val setup = - Codegen.add_codegen "inductive" inductive_codegen #> - Attrib.setup @{binding code_ind} - (Scan.lift (Scan.option (Args.$$$ "target" |-- Args.colon |-- Args.name) -- - Scan.option (Args.$$$ "params" |-- Args.colon |-- Parse.nat) >> uncurry add)) - "introduction rules for executable predicates"; - - -(**** Quickcheck involving inductive predicates ****) - -structure Result = Proof_Data -( - type T = int * int * int -> term list option; - fun init _ = (fn _ => NONE); -); - -val get_test_fn = Result.get; -fun poke_test_fn f = Context.>> (Context.map_proof (Result.put f)); - - -fun strip_imp p = - let val (q, r) = HOLogic.dest_imp p - in strip_imp r |>> cons q end - handle TERM _ => ([], p); - -fun deepen bound f i = - if i > bound then NONE - else - (case f i of - NONE => deepen bound f (i + 1) - | SOME x => SOME x); - -val active = Attrib.setup_config_bool @{binding quickcheck_SML_inductive_active} (K false); - -val depth_bound = Attrib.setup_config_int @{binding quickcheck_ind_depth} (K 10); -val depth_start = Attrib.setup_config_int @{binding quickcheck_ind_depth_start} (K 1); -val random_values = Attrib.setup_config_int @{binding quickcheck_ind_random} (K 5); -val size_offset = Attrib.setup_config_int @{binding quickcheck_ind_size_offset} (K 0); - -fun test_term ctxt [(t, [])] = - let - val t' = fold_rev absfree (Term.add_frees t []) t; - val thy = Proof_Context.theory_of ctxt; - val (xs, p) = strip_abs t'; - val args' = map_index (fn (i, (_, T)) => ("arg" ^ string_of_int i, T)) xs; - val args = map Free args'; - val (ps, q) = strip_imp p; - val Ts = map snd xs; - val T = Ts ---> HOLogic.boolT; - val rl = Logic.list_implies - (map (HOLogic.mk_Trueprop o curry subst_bounds (rev args)) ps @ - [HOLogic.mk_Trueprop (HOLogic.mk_not (subst_bounds (rev args, q)))], - HOLogic.mk_Trueprop (list_comb (Free ("quickcheckp", T), args))); - val (_, thy') = Inductive.add_inductive_global - {quiet_mode=true, verbose=false, alt_name=Binding.empty, coind=false, - no_elim=true, no_ind=false, skip_mono=false, fork_mono=false} - [((@{binding quickcheckp}, T), NoSyn)] [] - [(Attrib.empty_binding, rl)] [] (Theory.copy thy); - val pred = HOLogic.mk_Trueprop (list_comb - (Const (Sign.intern_const thy' "quickcheckp", T), - map Term.dummy_pattern Ts)); - val (code, gr) = - Codegen.generate_code_i thy' ["term_of", "test", "random_ind"] [] "Generated" - [("testf", pred)]; - val s = "structure Test_Term =\nstruct\n\n" ^ - cat_lines (map snd code) ^ - "\nopen Generated;\n\n" ^ Codegen.string_of - (Pretty.block [Codegen.str "val () = Inductive_Codegen.poke_test_fn", - Pretty.brk 1, Codegen.str "(fn p =>", Pretty.brk 1, - Codegen.str "case Seq.pull (testf p) of", Pretty.brk 1, - Codegen.str "SOME ", - mk_tuple [mk_tuple (map (Codegen.str o fst) args'), Codegen.str "_"], - Codegen.str " =>", Pretty.brk 1, Codegen.str "SOME ", - Pretty.enum "," "[" "]" - (map (fn (s, T) => Pretty.block - [Codegen.mk_term_of gr "Generated" false T, Pretty.brk 1, Codegen.str s]) args'), - Pretty.brk 1, - Codegen.str "| NONE => NONE);"]) ^ - "\n\nend;\n"; - val test_fn = - ctxt - |> Context.proof_map - (ML_Context.exec (fn () => ML_Context.eval_text false Position.none s)) - |> get_test_fn; - val values = Config.get ctxt random_values; - val bound = Config.get ctxt depth_bound; - val start = Config.get ctxt depth_start; - val offset = Config.get ctxt size_offset; - fun test [k] = (deepen bound (fn i => - (Output.urgent_message ("Search depth: " ^ string_of_int i); - test_fn (i, values, k+offset))) start, NONE); - in test end - | test_term ctxt [_] = error "Option eval is not supported by tester SML_inductive" - | test_term ctxt _ = - error "Compilation of multiple instances is not supported by tester SML_inductive"; - -end; diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Tools/inductive_set.ML --- a/src/HOL/Tools/inductive_set.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/Tools/inductive_set.ML Wed Oct 19 17:45:25 2011 +0200 @@ -401,7 +401,7 @@ else thm in map preproc end; -fun code_ind_att optmod = to_pred_att [] #> Inductive_Codegen.add optmod NONE; +fun code_ind_att optmod = to_pred_att []; (**** definition of inductive sets ****) @@ -551,10 +551,6 @@ "convert rule to set notation" #> Attrib.setup @{binding to_pred} (Attrib.thms >> to_pred_att) "convert rule to predicate notation" #> - Attrib.setup @{binding code_ind_set} - (Scan.lift (Scan.option (Args.$$$ "target" |-- Args.colon |-- Args.name) >> code_ind_att)) - "introduction rules for executable predicates" #> - Codegen.add_preprocessor codegen_preproc #> Attrib.setup @{binding mono_set} (Attrib.add_del mono_add_att mono_del_att) "declaration of monotonicity rule for set operators" #> Simplifier.map_simpset_global (fn ss => ss addsimprocs [collect_mem_simproc]); diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/Tools/recfun_codegen.ML --- a/src/HOL/Tools/recfun_codegen.ML Tue Oct 18 15:19:06 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,164 +0,0 @@ -(* Title: HOL/Tools/recfun_codegen.ML - Author: Stefan Berghofer, TU Muenchen - -Code generator for recursive functions. -*) - -signature RECFUN_CODEGEN = -sig - val setup: theory -> theory -end; - -structure RecfunCodegen : RECFUN_CODEGEN = -struct - -val const_of = dest_Const o head_of o fst o Logic.dest_equals; - -structure ModuleData = Theory_Data -( - type T = string Symtab.table; - val empty = Symtab.empty; - val extend = I; - fun merge data = Symtab.merge (K true) data; -); - -fun add_thm_target module_name thm thy = - let - val (thm', _) = Code.mk_eqn thy (thm, true) - in - thy - |> ModuleData.map (Symtab.update (fst (Code.const_typ_eqn thy thm'), module_name)) - end; - -fun avoid_value thy [thm] = - let val (_, T) = Code.const_typ_eqn thy thm - in - if null (Term.add_tvarsT T []) orelse null (binder_types T) - then [thm] - else [Code.expand_eta thy 1 thm] - end - | avoid_value thy thms = thms; - -fun get_equations thy defs (raw_c, T) = if raw_c = @{const_name HOL.eq} then ([], "") else - let - val c = AxClass.unoverload_const thy (raw_c, T); - val raw_thms = Code.get_cert thy (Code_Preproc.preprocess_functrans thy) c - |> Code.bare_thms_of_cert thy - |> map (AxClass.overload thy) - |> filter (Codegen.is_instance T o snd o const_of o prop_of); - val module_name = case Symtab.lookup (ModuleData.get thy) c - of SOME module_name => module_name - | NONE => - case Codegen.get_defn thy defs c T - of SOME ((_, (thyname, _)), _) => thyname - | NONE => Codegen.thyname_of_const thy c; - in if null raw_thms then ([], "") else - raw_thms - |> Codegen.preprocess thy - |> avoid_value thy - |> rpair module_name - end; - -fun mk_suffix thy defs (s, T) = - (case Codegen.get_defn thy defs s T of - SOME (_, SOME i) => " def" ^ string_of_int i - | _ => ""); - -exception EQN of string * typ * string; - -fun cycle g x xs = - if member (op =) xs x then xs - else fold (cycle g) (flat (Graph.all_paths (fst g) (x, x))) (x :: xs); - -fun add_rec_funs thy mode defs dep module eqs gr = - let - fun dest_eq t = (fst (const_of t) ^ mk_suffix thy defs (const_of t), - Logic.dest_equals (Codegen.rename_term t)); - val eqs' = map dest_eq eqs; - val (dname, _) :: _ = eqs'; - val (s, T) = const_of (hd eqs); - - fun mk_fundef module fname first [] gr = ([], gr) - | mk_fundef module fname first ((fname' : string, (lhs, rhs)) :: xs) gr = - let - val (pl, gr1) = Codegen.invoke_codegen thy mode defs dname module false lhs gr; - val (pr, gr2) = Codegen.invoke_codegen thy mode defs dname module false rhs gr1; - val (rest, gr3) = mk_fundef module fname' false xs gr2 ; - val (ty, gr4) = Codegen.invoke_tycodegen thy mode defs dname module false T gr3; - val num_args = (length o snd o strip_comb) lhs; - val prfx = if fname = fname' then " |" - else if not first then "and" - else if num_args = 0 then "val" - else "fun"; - val pl' = Pretty.breaks (Codegen.str prfx - :: (if num_args = 0 then [pl, Codegen.str ":", ty] else [pl])); - in - (Pretty.blk (4, pl' - @ [Codegen.str " =", Pretty.brk 1, pr]) :: rest, gr4) - end; - - fun put_code module fundef = Codegen.map_node dname - (K (SOME (EQN ("", dummyT, dname)), module, Codegen.string_of (Pretty.blk (0, - separate Pretty.fbrk fundef @ [Codegen.str ";"])) ^ "\n\n")); - - in - (case try (Codegen.get_node gr) dname of - NONE => - let - val gr1 = Codegen.add_edge (dname, dep) - (Codegen.new_node (dname, (SOME (EQN (s, T, "")), module, "")) gr); - val (fundef, gr2) = mk_fundef module "" true eqs' gr1 ; - val xs = cycle gr2 dname []; - val cs = map (fn x => - case Codegen.get_node gr2 x of - (SOME (EQN (s, T, _)), _, _) => (s, T) - | _ => error ("RecfunCodegen: illegal cyclic dependencies:\n" ^ - implode (separate ", " xs))) xs - in - (case xs of - [_] => (module, put_code module fundef gr2) - | _ => - if not (member (op =) xs dep) then - let - val thmss as (_, thyname) :: _ = map (get_equations thy defs) cs; - val module' = Codegen.if_library mode thyname module; - val eqs'' = map (dest_eq o prop_of) (maps fst thmss); - val (fundef', gr3) = mk_fundef module' "" true eqs'' - (Codegen.add_edge (dname, dep) - (List.foldr (uncurry Codegen.new_node) (Codegen.del_nodes xs gr2) - (map (fn k => - (k, (SOME (EQN ("", dummyT, dname)), module', ""))) xs))) - in (module', put_code module' fundef' gr3) end - else (module, gr2)) - end - | SOME (SOME (EQN (_, _, s)), module', _) => - (module', if s = "" then - if dname = dep then gr else Codegen.add_edge (dname, dep) gr - else if s = dep then gr else Codegen.add_edge (s, dep) gr)) - end; - -fun recfun_codegen thy mode defs dep module brack t gr = - (case strip_comb t of - (Const (p as (s, T)), ts) => - (case (get_equations thy defs p, Codegen.get_assoc_code thy (s, T)) of - (([], _), _) => NONE - | (_, SOME _) => NONE - | ((eqns, thyname), NONE) => - let - val module' = Codegen.if_library mode thyname module; - val (ps, gr') = fold_map - (Codegen.invoke_codegen thy mode defs dep module true) ts gr; - val suffix = mk_suffix thy defs p; - val (module'', gr'') = - add_rec_funs thy mode defs dep module' (map prop_of eqns) gr'; - val (fname, gr''') = Codegen.mk_const_id module'' (s ^ suffix) gr'' - in - SOME (Codegen.mk_app brack (Codegen.str (Codegen.mk_qual_id module fname)) ps, gr''') - end) - | _ => NONE); - -val setup = - Codegen.add_codegen "recfun" recfun_codegen - #> Code.set_code_target_attr add_thm_target; - -end; diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/ex/CodegenSML_Test.thy --- a/src/HOL/ex/CodegenSML_Test.thy Tue Oct 18 15:19:06 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -(* Title: HOL/ex/CodegenSML_Test.thy - Author: Tobias Nipkow, TU Muenchen - -Test file for Stefan Berghofer's SML code generator. -*) - -theory CodegenSML_Test -imports Executable_Set -begin - -lemma "True : {False, True} & False ~: {True}" -by evaluation - -lemma -"eq_set ({1::nat,2,3,2} \ {3,1,2,1}) {2,2,3,1} & - eq_set ({1::nat,2,3,2} \ {4,1,5,1}) {4,4,5,1,2,3}" -by evaluation - -lemma -"eq_set ({1::nat,2,3,2} \ {3,1,2,1}) {2,2,3,1} & - eq_set ({1::nat,2,3,2} \ {4,1,5,2}) {2,1,2}" -by evaluation - -lemma -"eq_set ({1::nat,2,3,2} - {3,1,2,1}) {} & - eq_set ({1::nat,2,3,2} - {4,1,5,2}) {3}" -by evaluation - -lemma -"eq_set (Union{{1::nat,2,3,2}, {3,1,2,1}}) {2,2,3,1} & - eq_set (Union{{1::nat,2,3,2}, {4,1,5,1}}) {4,4,5,1,2,3}" -by evaluation - -lemma -"eq_set (Inter{{1::nat,2,3,2}, {3,1,2,1}}) {2,2,3,1} & - eq_set (Inter{{1::nat,2,3,2}, {4,1,5,2}}) {2,1,2}" -by evaluation - -lemma "eq_set ((%x. x+2) ` {1::nat,2,3,2}) {4,5,3,3}" -by evaluation - -lemma -"(ALL x:{1::nat,2,3,2}. EX y : {4,5,2}. x < y) & - (EX x:{1::nat,2,3,2}. ALL y : {4,5,6}. x < y)" -by evaluation - -lemma -"eq_set {x : {4::nat,7,10}. 2 dvd x } {4,10}" -by evaluation - -lemma -"fold (op +) (5::int) {3,7,9} = 24 & - fold_image (op *) id (2::int) {3,4,5} = 120" -by evaluation - -end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/ex/Efficient_Nat_examples.thy --- a/src/HOL/ex/Efficient_Nat_examples.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/ex/Efficient_Nat_examples.thy Wed Oct 19 17:45:25 2011 +0200 @@ -32,9 +32,6 @@ lemma "harmonic 200 \ 5" by eval -lemma "harmonic 200 \ 5" - by evaluation - lemma "harmonic 20 \ 3" by normalization @@ -42,27 +39,18 @@ by eval lemma "naive_prime 89" - by evaluation - -lemma "naive_prime 89" by normalization lemma "\ naive_prime 87" by eval lemma "\ naive_prime 87" - by evaluation - -lemma "\ naive_prime 87" by normalization lemma "fac 10 > 3000000" by eval lemma "fac 10 > 3000000" - by evaluation - -lemma "fac 10 > 3000000" by normalization end diff -r 5e4a1270c000 -r 2825ce94fd4d src/HOL/ex/Eval_Examples.thy --- a/src/HOL/ex/Eval_Examples.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/HOL/ex/Eval_Examples.thy Wed Oct 19 17:45:25 2011 +0200 @@ -14,14 +14,6 @@ lemma "[()] = [()]" by eval lemma "fst ([] :: nat list, Suc 0) = []" by eval -text {* SML evaluation oracle *} - -lemma "True \ False" by evaluation -lemma "Suc 0 \ Suc 1" by evaluation -lemma "[] = ([] :: int list)" by evaluation -lemma "[()] = [()]" by evaluation -lemma "fst ([] :: nat list, Suc 0) = []" by evaluation - text {* normalization *} lemma "True \ False" by normalization diff -r 5e4a1270c000 -r 2825ce94fd4d src/Tools/Code/code_preproc.ML --- a/src/Tools/Code/code_preproc.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/Tools/Code/code_preproc.ML Wed Oct 19 17:45:25 2011 +0200 @@ -515,11 +515,9 @@ fun mk_attribute f = Thm.declaration_attribute (fn thm => Context.mapping (f thm) I); fun add_del_attribute_parser add del = Attrib.add_del (mk_attribute add) (mk_attribute del); - fun both f g thm = f thm #> g thm; in - Attrib.setup @{binding code_unfold} (add_del_attribute_parser - (both Codegen.add_unfold add_unfold) (both Codegen.del_unfold del_unfold)) - "preprocessing equations for code generators" + Attrib.setup @{binding code_unfold} (add_del_attribute_parser add_unfold del_unfold) + "preprocessing equations for code generator" #> Attrib.setup @{binding code_inline} (add_del_attribute_parser add_unfold del_unfold) "preprocessing equations for code generator" #> Attrib.setup @{binding code_post} (add_del_attribute_parser add_post del_post) diff -r 5e4a1270c000 -r 2825ce94fd4d src/Tools/Code/code_thingol.ML --- a/src/Tools/Code/code_thingol.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/Tools/Code/code_thingol.ML Wed Oct 19 17:45:25 2011 +0200 @@ -268,15 +268,17 @@ (* policies *) local + fun thyname_of_type thy = #theory_name o Name_Space.the_entry (Sign.type_space thy); fun thyname_of_class thy = #theory_name o Name_Space.the_entry (Sign.class_space thy); + fun thyname_of_const' thy = #theory_name o Name_Space.the_entry (Sign.const_space thy); fun thyname_of_instance thy inst = case AxClass.thynames_of_arity thy inst of [] => error ("No such instance: " ^ quote (snd inst ^ " :: " ^ fst inst)) | thyname :: _ => thyname; fun thyname_of_const thy c = case AxClass.class_of_param thy c of SOME class => thyname_of_class thy class | NONE => (case Code.get_type_of_constr_or_abstr thy c - of SOME (tyco, _) => Codegen.thyname_of_type thy tyco - | NONE => Codegen.thyname_of_const thy c); + of SOME (tyco, _) => thyname_of_type thy tyco + | NONE => thyname_of_const' thy c); fun purify_base "==>" = "follows" | purify_base "==" = "meta_eq" | purify_base s = Name.desymbolize false s; @@ -293,7 +295,7 @@ (fn thy => thyname_of_class thy o fst); (*order fits nicely with composed projections*) fun namify_tyco thy "fun" = "Pure.fun" - | namify_tyco thy tyco = namify thy Long_Name.base_name Codegen.thyname_of_type tyco; + | namify_tyco thy tyco = namify thy Long_Name.base_name thyname_of_type tyco; fun namify_instance thy = namify thy (fn (class, tyco) => Long_Name.base_name class ^ "_" ^ Long_Name.base_name tyco) thyname_of_instance; fun namify_const thy = namify thy Long_Name.base_name thyname_of_const; diff -r 5e4a1270c000 -r 2825ce94fd4d src/Tools/Code_Generator.thy --- a/src/Tools/Code_Generator.thy Tue Oct 18 15:19:06 2011 +0200 +++ b/src/Tools/Code_Generator.thy Wed Oct 19 17:45:25 2011 +0200 @@ -8,7 +8,6 @@ imports Pure uses "~~/src/Tools/misc_legacy.ML" - "~~/src/Tools/codegen.ML" "~~/src/Tools/cache_io.ML" "~~/src/Tools/try.ML" "~~/src/Tools/solve_direct.ML" diff -r 5e4a1270c000 -r 2825ce94fd4d src/Tools/codegen.ML --- a/src/Tools/codegen.ML Tue Oct 18 15:19:06 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1049 +0,0 @@ -(* Title: Tools/codegen.ML - Author: Stefan Berghofer, TU Muenchen - -Old code generator. -*) - -signature CODEGEN = -sig - val quiet_mode : bool Unsynchronized.ref - val message : string -> unit - val margin : int Unsynchronized.ref - val string_of : Pretty.T -> string - val str : string -> Pretty.T - - datatype 'a mixfix = - Arg - | Ignore - | Module - | Pretty of Pretty.T - | Quote of 'a; - - type deftab - type node - type codegr - type 'a codegen - - val add_codegen: string -> term codegen -> theory -> theory - val add_tycodegen: string -> typ codegen -> theory -> theory - val add_preprocessor: (theory -> thm list -> thm list) -> theory -> theory - val preprocess: theory -> thm list -> thm list - val preprocess_term: theory -> term -> term - val print_codegens: theory -> unit - val generate_code: theory -> string list -> string list -> string -> (string * string) list -> - (string * string) list * codegr - val generate_code_i: theory -> string list -> string list -> string -> (string * term) list -> - (string * string) list * codegr - val assoc_const: string * (term mixfix list * - (string * string) list) -> theory -> theory - val assoc_const_i: (string * typ) * (term mixfix list * - (string * string) list) -> theory -> theory - val assoc_type: xstring * (typ mixfix list * - (string * string) list) -> theory -> theory - val get_assoc_code: theory -> string * typ -> - (term mixfix list * (string * string) list) option - val get_assoc_type: theory -> string -> - (typ mixfix list * (string * string) list) option - val codegen_error: codegr -> string -> string -> 'a - val invoke_codegen: theory -> string list -> deftab -> string -> string -> bool -> - term -> codegr -> Pretty.T * codegr - val invoke_tycodegen: theory -> string list -> deftab -> string -> string -> bool -> - typ -> codegr -> Pretty.T * codegr - val mk_id: string -> string - val mk_qual_id: string -> string * string -> string - val mk_const_id: string -> string -> codegr -> (string * string) * codegr - val get_const_id: codegr -> string -> string * string - val mk_type_id: string -> string -> codegr -> (string * string) * codegr - val get_type_id: codegr -> string -> string * string - val thyname_of_type: theory -> string -> string - val thyname_of_const: theory -> string -> string - val rename_terms: term list -> term list - val rename_term: term -> term - val new_names: term -> string list -> string list - val new_name: term -> string -> string - val if_library: string list -> 'a -> 'a -> 'a - val get_defn: theory -> deftab -> string -> typ -> - ((typ * (string * thm)) * int option) option - val is_instance: typ -> typ -> bool - val parens: Pretty.T -> Pretty.T - val mk_app: bool -> Pretty.T -> Pretty.T list -> Pretty.T - val mk_tuple: Pretty.T list -> Pretty.T - val mk_let: (Pretty.T * Pretty.T) list -> Pretty.T -> Pretty.T - val eta_expand: term -> term list -> int -> term - val strip_tname: string -> string - val mk_type: bool -> typ -> Pretty.T - val mk_term_of: codegr -> string -> bool -> typ -> Pretty.T - val mk_gen: codegr -> string -> bool -> string list -> string -> typ -> Pretty.T - val poke_test_fn: (int -> term list option) -> unit - val poke_eval_fn: (unit -> term) -> unit - val test_term: Proof.context -> term -> int -> term list option - val eval_term: Proof.context -> term -> term - val evaluation_conv: Proof.context -> conv - val parse_mixfix: (string -> 'a) -> string -> 'a mixfix list - val quotes_of: 'a mixfix list -> 'a list - val num_args_of: 'a mixfix list -> int - val replace_quotes: 'b list -> 'a mixfix list -> 'b mixfix list - val mk_deftab: theory -> deftab - val map_unfold: (simpset -> simpset) -> theory -> theory - val add_unfold: thm -> theory -> theory - val del_unfold: thm -> theory -> theory - - val get_node: codegr -> string -> node - val add_edge: string * string -> codegr -> codegr - val add_edge_acyclic: string * string -> codegr -> codegr - val del_nodes: string list -> codegr -> codegr - val map_node: string -> (node -> node) -> codegr -> codegr - val new_node: string * node -> codegr -> codegr - - val setup: theory -> theory -end; - -structure Codegen : CODEGEN = -struct - -val quiet_mode = Unsynchronized.ref true; -fun message s = if !quiet_mode then () else writeln s; - -val margin = Unsynchronized.ref 80; - -fun string_of p = Print_Mode.setmp [] (Pretty.string_of_margin (!margin)) p; - -val str = Print_Mode.setmp [] Pretty.str; - -(**** Mixfix syntax ****) - -datatype 'a mixfix = - Arg - | Ignore - | Module - | Pretty of Pretty.T - | Quote of 'a; - -fun is_arg Arg = true - | is_arg Ignore = true - | is_arg _ = false; - -fun quotes_of [] = [] - | quotes_of (Quote q :: ms) = q :: quotes_of ms - | quotes_of (_ :: ms) = quotes_of ms; - -fun args_of [] xs = ([], xs) - | args_of (Arg :: ms) (x :: xs) = apfst (cons x) (args_of ms xs) - | args_of (Ignore :: ms) (_ :: xs) = args_of ms xs - | args_of (_ :: ms) xs = args_of ms xs; - -fun num_args_of x = length (filter is_arg x); - - -(**** theory data ****) - -(* preprocessed definition table *) - -type deftab = - (typ * (* type of constant *) - (string * (* name of theory containing definition of constant *) - thm)) (* definition theorem *) - list Symtab.table; - -(* code dependency graph *) - -type nametab = (string * string) Symtab.table * unit Symtab.table; - -fun merge_nametabs ((tab, used) : nametab, (tab', used')) = - (Symtab.merge op = (tab, tab'), Symtab.merge op = (used, used')); - -type node = - (exn option * (* slot for arbitrary data *) - string * (* name of structure containing piece of code *) - string); (* piece of code *) - -type codegr = - node Graph.T * - (nametab * (* table for assigned constant names *) - nametab); (* table for assigned type names *) - -val emptygr : codegr = (Graph.empty, - ((Symtab.empty, Symtab.empty), (Symtab.empty, Symtab.empty))); - -(* type of code generators *) - -type 'a codegen = - theory -> (* theory in which generate_code was called *) - string list -> (* mode *) - deftab -> (* definition table (for efficiency) *) - string -> (* node name of caller (for recording dependencies) *) - string -> (* module name of caller (for modular code generation) *) - bool -> (* whether to parenthesize generated expression *) - 'a -> (* item to generate code from *) - codegr -> (* code dependency graph *) - (Pretty.T * codegr) option; - - -(* theory data *) - -structure CodegenData = Theory_Data -( - type T = - {codegens : (string * term codegen) list, - tycodegens : (string * typ codegen) list, - consts : ((string * typ) * (term mixfix list * (string * string) list)) list, - types : (string * (typ mixfix list * (string * string) list)) list, - preprocs: (stamp * (theory -> thm list -> thm list)) list, - modules: codegr Symtab.table}; - - val empty = - {codegens = [], tycodegens = [], consts = [], types = [], - preprocs = [], modules = Symtab.empty}; - val extend = I; - - fun merge - ({codegens = codegens1, tycodegens = tycodegens1, - consts = consts1, types = types1, - preprocs = preprocs1, modules = modules1} : T, - {codegens = codegens2, tycodegens = tycodegens2, - consts = consts2, types = types2, - preprocs = preprocs2, modules = modules2}) : T = - {codegens = AList.merge (op =) (K true) (codegens1, codegens2), - tycodegens = AList.merge (op =) (K true) (tycodegens1, tycodegens2), - consts = AList.merge (op =) (K true) (consts1, consts2), - types = AList.merge (op =) (K true) (types1, types2), - preprocs = AList.merge (op =) (K true) (preprocs1, preprocs2), - modules = Symtab.merge (K true) (modules1, modules2)}; -); - -fun print_codegens thy = - let val {codegens, tycodegens, ...} = CodegenData.get thy in - Pretty.writeln (Pretty.chunks - [Pretty.strs ("term code generators:" :: map fst codegens), - Pretty.strs ("type code generators:" :: map fst tycodegens)]) - end; - - - -(**** access modules ****) - -fun get_modules thy = #modules (CodegenData.get thy); - -fun map_modules f thy = - let val {codegens, tycodegens, consts, types, preprocs, modules} = - CodegenData.get thy; - in CodegenData.put {codegens = codegens, tycodegens = tycodegens, - consts = consts, types = types, preprocs = preprocs, - modules = f modules} thy - end; - - -(**** add new code generators to theory ****) - -fun add_codegen name f thy = - let val {codegens, tycodegens, consts, types, preprocs, modules} = - CodegenData.get thy - in (case AList.lookup (op =) codegens name of - NONE => CodegenData.put {codegens = (name, f) :: codegens, - tycodegens = tycodegens, consts = consts, types = types, - preprocs = preprocs, modules = modules} thy - | SOME _ => error ("Code generator " ^ name ^ " already declared")) - end; - -fun add_tycodegen name f thy = - let val {codegens, tycodegens, consts, types, preprocs, modules} = - CodegenData.get thy - in (case AList.lookup (op =) tycodegens name of - NONE => CodegenData.put {tycodegens = (name, f) :: tycodegens, - codegens = codegens, consts = consts, types = types, - preprocs = preprocs, modules = modules} thy - | SOME _ => error ("Code generator " ^ name ^ " already declared")) - end; - - -(**** preprocessors ****) - -fun add_preprocessor p thy = - let val {codegens, tycodegens, consts, types, preprocs, modules} = - CodegenData.get thy - in CodegenData.put {tycodegens = tycodegens, - codegens = codegens, consts = consts, types = types, - preprocs = (stamp (), p) :: preprocs, - modules = modules} thy - end; - -fun preprocess thy = - let val {preprocs, ...} = CodegenData.get thy - in fold (fn (_, f) => f thy) preprocs end; - -fun preprocess_term thy t = - let - val x = Free (singleton (Name.variant_list (Misc_Legacy.add_term_names (t, []))) "x", fastype_of t); - (* fake definition *) - val eq = Skip_Proof.make_thm thy (Logic.mk_equals (x, t)); - fun err () = error "preprocess_term: bad preprocessor" - in case map prop_of (preprocess thy [eq]) of - [Const ("==", _) $ x' $ t'] => if x = x' then t' else err () - | _ => err () - end; - -structure UnfoldData = Theory_Data -( - type T = simpset; - val empty = empty_ss; - val extend = I; - val merge = merge_ss; -); - -val map_unfold = UnfoldData.map; -val add_unfold = map_unfold o Simplifier.add_simp; -val del_unfold = map_unfold o Simplifier.del_simp; - -fun unfold_preprocessor thy = - let val ss = Simplifier.global_context thy (UnfoldData.get thy) - in map (Thm.transfer thy #> Simplifier.full_simplify ss) end; - - -(**** associate constants with target language code ****) - -fun gen_assoc_const prep_const (raw_const, syn) thy = - let - val {codegens, tycodegens, consts, types, preprocs, modules} = - CodegenData.get thy; - val (cname, T) = prep_const thy raw_const; - in - if num_args_of (fst syn) > length (binder_types T) then - error ("More arguments than in corresponding type of " ^ cname) - else case AList.lookup (op =) consts (cname, T) of - NONE => CodegenData.put {codegens = codegens, - tycodegens = tycodegens, - consts = ((cname, T), syn) :: consts, - types = types, preprocs = preprocs, - modules = modules} thy - | SOME _ => error ("Constant " ^ cname ^ " already associated with code") - end; - -val assoc_const_i = gen_assoc_const (K I); -val assoc_const = gen_assoc_const Code.read_bare_const; - - -(**** associate types with target language types ****) - -fun assoc_type (s, syn) thy = - let - val {codegens, tycodegens, consts, types, preprocs, modules} = - CodegenData.get thy; - val tc = Sign.intern_type thy s; - in - case Symtab.lookup (snd (#types (Type.rep_tsig (Sign.tsig_of thy)))) tc of - SOME (Type.LogicalType i) => - if num_args_of (fst syn) > i then - error ("More arguments than corresponding type constructor " ^ s) - else - (case AList.lookup (op =) types tc of - NONE => CodegenData.put {codegens = codegens, - tycodegens = tycodegens, consts = consts, - types = (tc, syn) :: types, - preprocs = preprocs, modules = modules} thy - | SOME _ => error ("Type " ^ tc ^ " already associated with code")) - | _ => error ("Not a type constructor: " ^ s) - end; - -fun get_assoc_type thy = AList.lookup (op =) ((#types o CodegenData.get) thy); - - -(**** make valid ML identifiers ****) - -fun is_ascii_letdig x = Symbol.is_ascii_letter x orelse - Symbol.is_ascii_digit x orelse Symbol.is_ascii_quasi x; - -fun dest_sym s = - (case split_last (snd (take_prefix (fn c => c = "\\") (raw_explode s))) of - ("<" :: "^" :: xs, ">") => (true, implode xs) - | ("<" :: xs, ">") => (false, implode xs) - | _ => raise Fail "dest_sym"); - -fun mk_id s = if s = "" then "" else - let - fun check_str [] = [] - | check_str xs = (case take_prefix is_ascii_letdig xs of - ([], " " :: zs) => check_str zs - | ([], z :: zs) => - if size z = 1 then string_of_int (ord z) :: check_str zs - else (case dest_sym z of - (true, "isub") => check_str zs - | (true, "isup") => "" :: check_str zs - | (ctrl, s') => (if ctrl then "ctrl_" ^ s' else s') :: check_str zs) - | (ys, zs) => implode ys :: check_str zs); - val s' = space_implode "_" (maps (check_str o Symbol.explode) (Long_Name.explode s)) - in - if Symbol.is_ascii_letter (hd (raw_explode s')) then s' else "id_" ^ s' - end; - -fun mk_long_id (p as (tab, used)) module s = - let - fun find_name [] = raise Fail "mk_long_id" - | find_name (ys :: yss) = - let - val s' = Long_Name.implode ys - val s'' = Long_Name.append module s' - in case Symtab.lookup used s'' of - NONE => ((module, s'), - (Symtab.update_new (s, (module, s')) tab, - Symtab.update_new (s'', ()) used)) - | SOME _ => find_name yss - end - in case Symtab.lookup tab s of - NONE => find_name (Library.suffixes1 (Long_Name.explode s)) - | SOME name => (name, p) - end; - -(* module: module name for caller *) -(* module': module name for callee *) -(* if caller and callee reside in different modules, use qualified access *) - -fun mk_qual_id module (module', s) = - if module = module' orelse module' = "" then s else module' ^ "." ^ s; - -fun mk_const_id module cname (gr, (tab1, tab2)) = - let - val ((module, s), tab1') = mk_long_id tab1 module cname - val s' = mk_id s; - val s'' = if ML_Syntax.is_reserved s' then s' ^ "_const" else s' - in (((module, s'')), (gr, (tab1', tab2))) end; - -fun get_const_id (gr, (tab1, tab2)) cname = - case Symtab.lookup (fst tab1) cname of - NONE => error ("get_const_id: no such constant: " ^ quote cname) - | SOME (module, s) => - let - val s' = mk_id s; - val s'' = if ML_Syntax.is_reserved s' then s' ^ "_const" else s' - in (module, s'') end; - -fun mk_type_id module tyname (gr, (tab1, tab2)) = - let - val ((module, s), tab2') = mk_long_id tab2 module tyname - val s' = mk_id s; - val s'' = if ML_Syntax.is_reserved s' then s' ^ "_type" else s' - in ((module, s''), (gr, (tab1, tab2'))) end; - -fun get_type_id (gr, (tab1, tab2)) tyname = - case Symtab.lookup (fst tab2) tyname of - NONE => error ("get_type_id: no such type: " ^ quote tyname) - | SOME (module, s) => - let - val s' = mk_id s; - val s'' = if ML_Syntax.is_reserved s' then s' ^ "_type" else s' - in (module, s'') end; - -fun get_type_id' f tab tyname = apsnd f (get_type_id tab tyname); - -fun get_node (gr, x) k = Graph.get_node gr k; -fun add_edge e (gr, x) = (Graph.add_edge e gr, x); -fun add_edge_acyclic e (gr, x) = (Graph.add_edge_acyclic e gr, x); -fun del_nodes ks (gr, x) = (Graph.del_nodes ks gr, x); -fun map_node k f (gr, x) = (Graph.map_node k f gr, x); -fun new_node p (gr, x) = (Graph.new_node p gr, x); - -fun thyname_of_type thy = #theory_name o Name_Space.the_entry (Sign.type_space thy); -fun thyname_of_const thy = #theory_name o Name_Space.the_entry (Sign.const_space thy); - -fun rename_terms ts = - let - val names = List.foldr Misc_Legacy.add_term_names - (map (fst o fst) (rev (fold Term.add_vars ts []))) ts; - val reserved = filter ML_Syntax.is_reserved names; - val (illegal, alt_names) = split_list (map_filter (fn s => - let val s' = mk_id s in if s = s' then NONE else SOME (s, s') end) names) - val ps = (reserved @ illegal) ~~ - Name.variant_list names (map (suffix "'") reserved @ alt_names); - - fun rename_id s = AList.lookup (op =) ps s |> the_default s; - - fun rename (Var ((a, i), T)) = Var ((rename_id a, i), T) - | rename (Free (a, T)) = Free (rename_id a, T) - | rename (Abs (s, T, t)) = Abs (s, T, rename t) - | rename (t $ u) = rename t $ rename u - | rename t = t; - in - map rename ts - end; - -val rename_term = hd o rename_terms o single; - - -(**** retrieve definition of constant ****) - -fun is_instance T1 T2 = - Type.raw_instance (T1, if null (Misc_Legacy.typ_tfrees T2) then T2 else Logic.varifyT_global T2); - -fun get_assoc_code thy (s, T) = Option.map snd (find_first (fn ((s', T'), _) => - s = s' andalso is_instance T T') (#consts (CodegenData.get thy))); - -fun get_aux_code mode xs = map_filter (fn (m, code) => - if m = "" orelse member (op =) mode m then SOME code else NONE) xs; - -fun dest_prim_def t = - let - val (lhs, rhs) = Logic.dest_equals t; - val (c, args) = strip_comb lhs; - val (s, T) = dest_Const c - in if forall is_Var args then SOME (s, (T, (args, rhs))) else NONE - end handle TERM _ => NONE; - -fun mk_deftab thy = - let - val axmss = - map (fn thy' => (Context.theory_name thy', Theory.axiom_table thy')) - (Theory.nodes_of thy); - fun add_def thyname (name, t) = - (case dest_prim_def t of - NONE => I - | SOME (s, (T, _)) => Symtab.map_default (s, []) - (cons (T, (thyname, Thm.axiom thy name)))); - in - fold (fn (thyname, axms) => Symtab.fold (add_def thyname) axms) axmss Symtab.empty - end; - -fun prep_prim_def thy thm = - let - val prop = case preprocess thy [thm] - of [thm'] => Thm.prop_of thm' - | _ => error "mk_deftab: bad preprocessor" - in ((Option.map o apsnd o apsnd) - (fn (args, rhs) => split_last (rename_terms (args @ [rhs]))) o dest_prim_def) prop - end; - -fun get_defn thy defs s T = (case Symtab.lookup defs s of - NONE => NONE - | SOME ds => - let val i = find_index (is_instance T o fst) ds - in if i >= 0 then - SOME (nth ds i, if length ds = 1 then NONE else SOME i) - else NONE - end); - - -(**** invoke suitable code generator for term / type ****) - -fun codegen_error (gr, _) dep s = - error (s ^ "\nrequired by:\n" ^ commas (Graph.all_succs gr [dep])); - -fun invoke_codegen thy mode defs dep module brack t gr = (case get_first - (fn (_, f) => f thy mode defs dep module brack t gr) (#codegens (CodegenData.get thy)) of - NONE => codegen_error gr dep ("Unable to generate code for term:\n" ^ - Syntax.string_of_term_global thy t) - | SOME x => x); - -fun invoke_tycodegen thy mode defs dep module brack T gr = (case get_first - (fn (_, f) => f thy mode defs dep module brack T gr ) (#tycodegens (CodegenData.get thy)) of - NONE => codegen_error gr dep ("Unable to generate code for type:\n" ^ - Syntax.string_of_typ_global thy T) - | SOME x => x); - - -(**** code generator for mixfix expressions ****) - -fun parens p = Pretty.block [str "(", p, str ")"]; - -fun pretty_fn [] p = [p] - | pretty_fn (x::xs) p = str ("fn " ^ x ^ " =>") :: - Pretty.brk 1 :: pretty_fn xs p; - -fun pretty_mixfix _ _ [] [] _ = [] - | pretty_mixfix module module' (Arg :: ms) (p :: ps) qs = - p :: pretty_mixfix module module' ms ps qs - | pretty_mixfix module module' (Ignore :: ms) ps qs = - pretty_mixfix module module' ms ps qs - | pretty_mixfix module module' (Module :: ms) ps qs = - (if module <> module' - then cons (str (module' ^ ".")) else I) - (pretty_mixfix module module' ms ps qs) - | pretty_mixfix module module' (Pretty p :: ms) ps qs = - p :: pretty_mixfix module module' ms ps qs - | pretty_mixfix module module' (Quote _ :: ms) ps (q :: qs) = - q :: pretty_mixfix module module' ms ps qs; - -fun replace_quotes [] [] = [] - | replace_quotes xs (Arg :: ms) = - Arg :: replace_quotes xs ms - | replace_quotes xs (Ignore :: ms) = - Ignore :: replace_quotes xs ms - | replace_quotes xs (Module :: ms) = - Module :: replace_quotes xs ms - | replace_quotes xs (Pretty p :: ms) = - Pretty p :: replace_quotes xs ms - | replace_quotes (x::xs) (Quote _ :: ms) = - Quote x :: replace_quotes xs ms; - - -(**** default code generators ****) - -fun eta_expand t ts i = - let - val k = length ts; - val Ts = drop k (binder_types (fastype_of t)); - val j = i - k - in - List.foldr (fn (T, t) => Abs ("x", T, t)) - (list_comb (t, ts @ map Bound (j-1 downto 0))) (take j Ts) - end; - -fun mk_app _ p [] = p - | mk_app brack p ps = if brack then - Pretty.block (str "(" :: - separate (Pretty.brk 1) (p :: ps) @ [str ")"]) - else Pretty.block (separate (Pretty.brk 1) (p :: ps)); - -fun new_names t xs = Name.variant_list - (union (op =) (map (fst o fst o dest_Var) (Misc_Legacy.term_vars t)) - (Misc_Legacy.add_term_names (t, ML_Syntax.reserved_names))) (map mk_id xs); - -fun new_name t x = hd (new_names t [x]); - -fun if_library mode x y = if member (op =) mode "library" then x else y; - -fun default_codegen thy mode defs dep module brack t gr = - let - val (u, ts) = strip_comb t; - fun codegens brack = fold_map (invoke_codegen thy mode defs dep module brack) - in (case u of - Var ((s, i), T) => - let - val (ps, gr') = codegens true ts gr; - val (_, gr'') = invoke_tycodegen thy mode defs dep module false T gr' - in SOME (mk_app brack (str (s ^ - (if i=0 then "" else string_of_int i))) ps, gr'') - end - - | Free (s, T) => - let - val (ps, gr') = codegens true ts gr; - val (_, gr'') = invoke_tycodegen thy mode defs dep module false T gr' - in SOME (mk_app brack (str s) ps, gr'') end - - | Const (s, T) => - (case get_assoc_code thy (s, T) of - SOME (ms, aux) => - let val i = num_args_of ms - in if length ts < i then - default_codegen thy mode defs dep module brack (eta_expand u ts i) gr - else - let - val (ts1, ts2) = args_of ms ts; - val (ps1, gr1) = codegens false ts1 gr; - val (ps2, gr2) = codegens true ts2 gr1; - val (ps3, gr3) = codegens false (quotes_of ms) gr2; - val (_, gr4) = invoke_tycodegen thy mode defs dep module false - (funpow (length ts) (hd o tl o snd o dest_Type) T) gr3; - val (module', suffix) = (case get_defn thy defs s T of - NONE => (if_library mode (thyname_of_const thy s) module, "") - | SOME ((U, (module', _)), NONE) => - (if_library mode module' module, "") - | SOME ((U, (module', _)), SOME i) => - (if_library mode module' module, " def" ^ string_of_int i)); - val node_id = s ^ suffix; - fun p module' = mk_app brack (Pretty.block - (pretty_mixfix module module' ms ps1 ps3)) ps2 - in SOME (case try (get_node gr4) node_id of - NONE => (case get_aux_code mode aux of - [] => (p module, gr4) - | xs => (p module', add_edge (node_id, dep) (new_node - (node_id, (NONE, module', cat_lines xs ^ "\n")) gr4))) - | SOME (_, module'', _) => - (p module'', add_edge (node_id, dep) gr4)) - end - end - | NONE => (case get_defn thy defs s T of - NONE => NONE - | SOME ((U, (thyname, thm)), k) => (case prep_prim_def thy thm - of SOME (_, (_, (args, rhs))) => let - val module' = if_library mode thyname module; - val suffix = (case k of NONE => "" | SOME i => " def" ^ string_of_int i); - val node_id = s ^ suffix; - val ((ps, def_id), gr') = gr |> codegens true ts - ||>> mk_const_id module' (s ^ suffix); - val p = mk_app brack (str (mk_qual_id module def_id)) ps - in SOME (case try (get_node gr') node_id of - NONE => - let - val _ = message ("expanding definition of " ^ s); - val Ts = binder_types U; - val (args', rhs') = - if not (null args) orelse null Ts then (args, rhs) else - let val v = Free (new_name rhs "x", hd Ts) - in ([v], betapply (rhs, v)) end; - val (p', gr1) = invoke_codegen thy mode defs node_id module' false - rhs' (add_edge (node_id, dep) - (new_node (node_id, (NONE, "", "")) gr')); - val (xs, gr2) = codegens false args' gr1; - val (_, gr3) = invoke_tycodegen thy mode defs dep module false T gr2; - val (ty, gr4) = invoke_tycodegen thy mode defs node_id module' false U gr3; - in (p, map_node node_id (K (NONE, module', string_of - (Pretty.block (separate (Pretty.brk 1) - (if null args' then - [str ("val " ^ snd def_id ^ " :"), ty] - else str ("fun " ^ snd def_id) :: xs) @ - [str " =", Pretty.brk 1, p', str ";"])) ^ "\n\n")) gr4) - end - | SOME _ => (p, add_edge (node_id, dep) gr')) - end - | NONE => NONE))) - - | Abs _ => - let - val (bs, Ts) = ListPair.unzip (strip_abs_vars u); - val t = strip_abs_body u - val bs' = new_names t bs; - val (ps, gr1) = codegens true ts gr; - val (p, gr2) = invoke_codegen thy mode defs dep module false - (subst_bounds (map Free (rev (bs' ~~ Ts)), t)) gr1; - in - SOME (mk_app brack (Pretty.block (str "(" :: pretty_fn bs' p @ - [str ")"])) ps, gr2) - end - - | _ => NONE) - end; - -fun default_tycodegen thy mode defs dep module brack (TVar ((s, i), _)) gr = - SOME (str (s ^ (if i = 0 then "" else string_of_int i)), gr) - | default_tycodegen thy mode defs dep module brack (TFree (s, _)) gr = - SOME (str s, gr) - | default_tycodegen thy mode defs dep module brack (Type (s, Ts)) gr = - (case AList.lookup (op =) ((#types o CodegenData.get) thy) s of - NONE => NONE - | SOME (ms, aux) => - let - val (ps, gr') = fold_map - (invoke_tycodegen thy mode defs dep module false) - (fst (args_of ms Ts)) gr; - val (qs, gr'') = fold_map - (invoke_tycodegen thy mode defs dep module false) - (quotes_of ms) gr'; - val module' = if_library mode (thyname_of_type thy s) module; - val node_id = s ^ " (type)"; - fun p module' = Pretty.block (pretty_mixfix module module' ms ps qs) - in SOME (case try (get_node gr'') node_id of - NONE => (case get_aux_code mode aux of - [] => (p module', gr'') - | xs => (p module', snd (mk_type_id module' s - (add_edge (node_id, dep) (new_node (node_id, - (NONE, module', cat_lines xs ^ "\n")) gr''))))) - | SOME (_, module'', _) => - (p module'', add_edge (node_id, dep) gr'')) - end); - -fun mk_tuple [p] = p - | mk_tuple ps = Pretty.block (str "(" :: - flat (separate [str ",", Pretty.brk 1] (map single ps)) @ [str ")"]); - -fun mk_let bindings body = - Pretty.blk (0, [str "let", Pretty.brk 1, - Pretty.blk (0, separate Pretty.fbrk (map (fn (pat, rhs) => - Pretty.block [str "val ", pat, str " =", Pretty.brk 1, - rhs, str ";"]) bindings)), - Pretty.brk 1, str "in", Pretty.brk 1, body, - Pretty.brk 1, str "end"]); - -fun mk_struct name s = "structure " ^ name ^ " =\nstruct\n\n" ^ s ^ "end;\n"; - -fun add_to_module name s = AList.map_entry (op =) (name : string) (suffix s); - -fun output_code gr module xs = - let - val code = map_filter (fn s => - let val c as (_, module', _) = Graph.get_node gr s - in if module = "" orelse module = module' then SOME (s, c) else NONE end) - (rev (Graph.all_preds gr xs)); - fun string_of_cycle (a :: b :: cs) = - let val SOME (x, y) = get_first (fn (x, (_, a', _)) => - if a = a' then Option.map (pair x) - (find_first ((fn (_, b', _) => b' = b) o Graph.get_node gr) - (Graph.immediate_succs gr x)) - else NONE) code - in x ^ " called by " ^ y ^ "\n" ^ string_of_cycle (b :: cs) end - | string_of_cycle _ = "" - in - if module = "" then - let - val modules = distinct (op =) (map (#2 o snd) code); - val mod_gr = fold_rev Graph.add_edge_acyclic - (maps (fn (s, (_, module, _)) => map (pair module) - (filter_out (fn s => s = module) (map (#2 o Graph.get_node gr) - (Graph.immediate_succs gr s)))) code) - (fold_rev (Graph.new_node o rpair ()) modules Graph.empty); - val modules' = - rev (Graph.all_preds mod_gr (map (#2 o Graph.get_node gr) xs)) - in - List.foldl (fn ((_, (_, module, s)), ms) => add_to_module module s ms) - (map (rpair "") modules') code - end handle Graph.CYCLES (cs :: _) => - error ("Cyclic dependency of modules:\n" ^ commas cs ^ - "\n" ^ string_of_cycle cs) - else [(module, implode (map (#3 o snd) code))] - end; - -fun gen_generate_code prep_term thy mode modules module xs = - let - val _ = (module <> "" orelse - member (op =) mode "library" andalso forall (fn (s, _) => s = "") xs) - orelse error "missing module name"; - val graphs = get_modules thy; - val defs = mk_deftab thy; - val gr = new_node ("", (NONE, module, "")) - (List.foldl (fn ((gr, (tab1, tab2)), (gr', (tab1', tab2'))) => - (Graph.merge (fn ((_, module, _), (_, module', _)) => - module = module') (gr, gr'), - (merge_nametabs (tab1, tab1'), merge_nametabs (tab2, tab2')))) emptygr - (map (fn s => case Symtab.lookup graphs s of - NONE => error ("Undefined code module: " ^ s) - | SOME gr => gr) modules)) - handle Graph.DUP k => error ("Duplicate code for " ^ k); - fun expand (t as Abs _) = t - | expand t = (case fastype_of t of - Type ("fun", [T, U]) => Abs ("x", T, t $ Bound 0) | _ => t); - val (ps, gr') = fold_map (fn (s, t) => fn gr => apfst (pair s) - (invoke_codegen thy mode defs "" module false t gr)) - (map (apsnd (expand o preprocess_term thy o prep_term thy)) xs) gr; - val code = map_filter - (fn ("", _) => NONE - | (s', p) => SOME (string_of (Pretty.block - [str ("val " ^ s' ^ " ="), Pretty.brk 1, p, str ";"]))) ps; - val code' = space_implode "\n\n" code ^ "\n\n"; - val code'' = - map_filter (fn (name, s) => - if member (op =) mode "library" andalso name = module andalso null code - then NONE - else SOME (name, mk_struct name s)) - ((if null code then I - else add_to_module module code') - (output_code (fst gr') (if_library mode "" module) [""])) - in - (code'', del_nodes [""] gr') - end; - -val generate_code_i = gen_generate_code Sign.cert_term; -val generate_code = - gen_generate_code (Syntax.read_term o Proof_Context.allow_dummies o Proof_Context.init_global); - - -(**** Reflection ****) - -val strip_tname = implode o tl o raw_explode; - -fun pretty_list xs = Pretty.block (str "[" :: - flat (separate [str ",", Pretty.brk 1] (map single xs)) @ - [str "]"]); - -fun mk_type p (TVar ((s, i), _)) = str - (strip_tname s ^ (if i = 0 then "" else string_of_int i) ^ "T") - | mk_type p (TFree (s, _)) = str (strip_tname s ^ "T") - | mk_type p (Type (s, Ts)) = (if p then parens else I) (Pretty.block - [str "Type", Pretty.brk 1, str ("(\"" ^ s ^ "\","), - Pretty.brk 1, pretty_list (map (mk_type false) Ts), str ")"]); - -fun mk_term_of gr module p (TVar ((s, i), _)) = str - (strip_tname s ^ (if i = 0 then "" else string_of_int i) ^ "F") - | mk_term_of gr module p (TFree (s, _)) = str (strip_tname s ^ "F") - | mk_term_of gr module p (Type (s, Ts)) = (if p then parens else I) - (Pretty.block (separate (Pretty.brk 1) - (str (mk_qual_id module - (get_type_id' (fn s' => "term_of_" ^ s') gr s)) :: - maps (fn T => - [mk_term_of gr module true T, mk_type true T]) Ts))); - - -(**** Implicit results ****) - -structure Result = Proof_Data -( - type T = (int -> term list option) * (unit -> term); - fun init _ = (fn _ => NONE, fn () => Bound 0); -); - -val get_test_fn = #1 o Result.get; -val get_eval_fn = #2 o Result.get; - -fun poke_test_fn f = Context.>> (Context.map_proof (Result.map (fn (_, g) => (f, g)))); -fun poke_eval_fn g = Context.>> (Context.map_proof (Result.map (fn (f, _) => (f, g)))); - - -(**** Test data generators ****) - -fun mk_gen gr module p xs a (TVar ((s, i), _)) = str - (strip_tname s ^ (if i = 0 then "" else string_of_int i) ^ "G") - | mk_gen gr module p xs a (TFree (s, _)) = str (strip_tname s ^ "G") - | mk_gen gr module p xs a (Type (tyc as (s, Ts))) = (if p then parens else I) - (Pretty.block (separate (Pretty.brk 1) - (str (mk_qual_id module (get_type_id' (fn s' => "gen_" ^ s') gr s) ^ - (if member (op =) xs s then "'" else "")) :: - (case tyc of - ("fun", [T, U]) => - [mk_term_of gr module true T, mk_type true T, - mk_gen gr module true xs a U, mk_type true U] - | _ => maps (fn T => - [mk_gen gr module true xs a T, mk_type true T]) Ts) @ - (if member (op =) xs s then [str a] else [])))); - -fun test_term ctxt t = - let - val thy = Proof_Context.theory_of ctxt; - val (code, gr) = generate_code_i thy ["term_of", "test"] [] "Generated" [("testf", t)]; - val Ts = map snd (fst (strip_abs t)); - val args = map_index (fn (i, T) => ("arg" ^ string_of_int i, T)) Ts; - val s = "structure Test_Term =\nstruct\n\n" ^ - cat_lines (map snd code) ^ - "\nopen Generated;\n\n" ^ string_of - (Pretty.block [str "val () = Codegen.poke_test_fn", - Pretty.brk 1, str ("(fn i =>"), Pretty.brk 1, - mk_let (map (fn (s, T) => - (mk_tuple [str s, str (s ^ "_t")], - Pretty.block [mk_gen gr "Generated" false [] "" T, Pretty.brk 1, - str "i"])) args) - (Pretty.block [str "if ", - mk_app false (str "testf") (map (str o fst) args), - Pretty.brk 1, str "then NONE", - Pretty.brk 1, str "else ", - Pretty.block [str "SOME ", - Pretty.enum "," "[" "]" (map (fn (s, _) => str (s ^ "_t ()")) args)]]), - str ");"]) ^ - "\n\nend;\n"; - in - ctxt - |> Context.proof_map (ML_Context.exec (fn () => ML_Context.eval_text false Position.none s)) - |> get_test_fn - end; - - -(**** Evaluator for terms ****) - -fun eval_term ctxt t = - let - val _ = - legacy_feature - "Old evaluation mechanism -- use evaluator \"code\" or method \"eval\" instead"; - val thy = Proof_Context.theory_of ctxt; - val _ = (null (Term.add_tvars t []) andalso null (Term.add_tfrees t [])) orelse - error "Term to be evaluated contains type variables"; - val _ = (null (Term.add_vars t []) andalso null (Term.add_frees t [])) orelse - error "Term to be evaluated contains variables"; - val (code, gr) = - generate_code_i thy ["term_of"] [] "Generated" - [("result", Abs ("x", TFree ("'a", []), t))]; - val s = "structure Eval_Term =\nstruct\n\n" ^ - cat_lines (map snd code) ^ - "\nopen Generated;\n\n" ^ string_of - (Pretty.block [str "val () = Codegen.poke_eval_fn (fn () =>", - Pretty.brk 1, - mk_app false (mk_term_of gr "Generated" false (fastype_of t)) - [str "(result ())"], - str ");"]) ^ - "\n\nend;\n"; - val eval_fn = - ctxt - |> Context.proof_map (ML_Context.exec (fn () => ML_Context.eval_text false Position.none s)) - |> get_eval_fn; - in eval_fn () end; - -val (_, evaluation_oracle) = Context.>>> (Context.map_theory_result - (Thm.add_oracle (Binding.name "evaluation", fn (ctxt, ct) => - let - val thy = Proof_Context.theory_of ctxt; - val t = Thm.term_of ct; - in - if Theory.subthy (Thm.theory_of_cterm ct, thy) then - Thm.cterm_of thy (Logic.mk_equals (t, eval_term ctxt t)) - else raise CTERM ("evaluation_oracle: bad theory", [ct]) - end))); - -fun evaluation_conv ctxt ct = evaluation_oracle (ctxt, ct); - - -(**** Interface ****) - -fun parse_mixfix rd s = - (case Scan.finite Symbol.stopper (Scan.repeat - ( $$ "_" >> K Arg - || $$ "?" >> K Ignore - || $$ "\" >> K Module - || $$ "/" |-- Scan.repeat ($$ " ") >> (Pretty o Pretty.brk o length) - || $$ "{" |-- $$ "*" |-- Scan.repeat1 - ( $$ "'" |-- Scan.one Symbol.is_regular - || Scan.unless ($$ "*" -- $$ "}") (Scan.one Symbol.is_regular)) --| - $$ "*" --| $$ "}" >> (Quote o rd o implode) - || Scan.repeat1 - ( $$ "'" |-- Scan.one Symbol.is_regular - || Scan.unless ($$ "_" || $$ "?" || $$ "\" || $$ "/" || $$ "{" |-- $$ "*") - (Scan.one Symbol.is_regular)) >> (Pretty o str o implode))) - (Symbol.explode s) of - (p, []) => p - | _ => error ("Malformed annotation: " ^ quote s)); - - -val _ = List.app Keyword.keyword ["attach", "file", "contains"]; - -fun strip_whitespace s = implode (fst (take_suffix (fn c => c = "\n" orelse c = " ") - (snd (take_prefix (fn c => c = "\n" orelse c = " ") (raw_explode s))))) ^ "\n"; - -val parse_attach = Scan.repeat (Parse.$$$ "attach" |-- - Scan.optional (Parse.$$$ "(" |-- Parse.xname --| Parse.$$$ ")") "" -- - (Parse.verbatim >> strip_whitespace)); - -val _ = - Outer_Syntax.command "types_code" - "associate types with target language types" Keyword.thy_decl - (Scan.repeat1 (Parse.xname --| Parse.$$$ "(" -- Parse.string --| Parse.$$$ ")" -- parse_attach) >> - (fn xs => Toplevel.theory (fn thy => fold (assoc_type o - (fn ((name, mfx), aux) => (name, (parse_mixfix - (Syntax.read_typ_global thy) mfx, aux)))) xs thy))); - -val _ = - Outer_Syntax.command "consts_code" - "associate constants with target language code" Keyword.thy_decl - (Scan.repeat1 - (Parse.term --| - Parse.$$$ "(" -- Parse.string --| Parse.$$$ ")" -- parse_attach) >> - (fn xs => Toplevel.theory (fn thy => fold (assoc_const o - (fn ((const, mfx), aux) => - (const, (parse_mixfix (Syntax.read_term_global thy) mfx, aux)))) xs thy))); - -fun parse_code lib = - Scan.optional (Parse.$$$ "(" |-- Parse.enum "," Parse.xname --| Parse.$$$ ")") [] -- - (if lib then Scan.optional Parse.name "" else Parse.name) -- - Scan.option (Parse.$$$ "file" |-- Parse.name) -- - (if lib then Scan.succeed [] - else Scan.optional (Parse.$$$ "imports" |-- Scan.repeat1 Parse.name) []) --| - Parse.$$$ "contains" -- - ( Scan.repeat1 (Parse.name --| Parse.$$$ "=" -- Parse.term) - || Scan.repeat1 (Parse.term >> pair "")) >> - (fn ((((mode, module), opt_fname), modules), xs) => Toplevel.theory (fn thy => - let - val _ = legacy_feature "Old code generation command -- use 'export_code' instead"; - val mode' = (if lib then insert (op =) "library" else I) (remove (op =) "library" mode); - val (code, gr) = generate_code thy mode' modules module xs; - val thy' = thy |> Context.theory_map (ML_Context.exec (fn () => - (case opt_fname of - NONE => ML_Context.eval_text false Position.none (cat_lines (map snd code)) - | SOME fname => - if lib then app (fn (name, s) => File.write - (Path.append (Path.explode fname) (Path.basic (name ^ ".ML"))) s) - (("ROOT", implode (map (fn (name, _) => - "use \"" ^ name ^ ".ML\";\n") code)) :: code) - else File.write (Path.explode fname) (snd (hd code))))); - in - if lib then thy' - else map_modules (Symtab.update (module, gr)) thy' - end)); - -val setup = add_codegen "default" default_codegen - #> add_tycodegen "default" default_tycodegen - #> add_preprocessor unfold_preprocessor; - -val _ = - Outer_Syntax.command "code_library" - "generate code for terms (one structure for each theory)" Keyword.thy_decl - (parse_code true); - -val _ = - Outer_Syntax.command "code_module" - "generate code for terms (single structure, incremental)" Keyword.thy_decl - (parse_code false); - -end; diff -r 5e4a1270c000 -r 2825ce94fd4d src/Tools/misc_legacy.ML --- a/src/Tools/misc_legacy.ML Tue Oct 18 15:19:06 2011 +0200 +++ b/src/Tools/misc_legacy.ML Wed Oct 19 17:45:25 2011 +0200 @@ -5,7 +5,6 @@ signature MISC_LEGACY = sig - val it_term_types: (typ * 'a -> 'a) -> term * 'a -> 'a val add_term_names: term * string list -> string list val add_typ_tvars: typ * (indexname * sort) list -> (indexname * sort) list val add_typ_tfree_names: typ * string list -> string list