src/HOL/Tools/function_package/fundef_common.ML
author wenzelm
Sun, 15 Apr 2007 23:25:50 +0200
changeset 22709 9ab51bac6287
parent 22623 5fcee5b319a2
child 22733 0b14bb35be90
permissions -rw-r--r--
removed obsolete TypeInfer.logicT -- use dummyT;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     1
(*  Title:      HOL/Tools/function_package/fundef_common.ML
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     2
    ID:         $Id$
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     3
    Author:     Alexander Krauss, TU Muenchen
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     4
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     5
A package for general recursive function definitions. 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     6
Common type definitions and other infrastructure.
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     7
*)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     8
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
     9
structure FundefCommon =
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    10
struct
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    11
22498
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
    12
(* Profiling *)
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    13
val profile = ref false;
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    14
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    15
fun PROFILE msg = if !profile then timeap_msg msg else I
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    16
22498
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
    17
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
    18
val acc_const_name = "Accessible_Part.acc"
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    19
fun mk_acc domT R =
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
    20
    Const (acc_const_name, (fastype_of R) --> domT --> HOLogic.boolT) $ R 
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    21
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    22
val function_name = suffix "C"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    23
val graph_name = suffix "_graph"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    24
val rel_name = suffix "_rel"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    25
val dom_name = suffix "_dom"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    26
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    27
type depgraph = int IntGraph.T
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    28
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    29
datatype ctx_tree 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    30
  = Leaf of term
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    31
  | Cong of (term * thm * depgraph * ((string * typ) list * thm list * ctx_tree) list)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    32
  | RCall of (term * ctx_tree)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    33
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    34
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    35
19583
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
    36
datatype fundef_result =
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
    37
  FundefResult of
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    38
     {
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    39
      f: term,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    40
      G: term,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    41
      R: term,
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    42
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    43
      psimps : thm list, 
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
    44
      trsimps : thm list option, 
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
    45
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    46
      subset_pinducts : thm list, 
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    47
      simple_pinducts : thm list, 
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    48
      cases : thm,
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    49
      termination : thm,
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
    50
      domintros : thm list option
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    51
     }
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    52
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    53
datatype fundef_context_data =
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    54
  FundefCtxData of
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    55
     {
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
    56
      add_simps : string -> Attrib.src list -> thm list -> local_theory -> thm list * local_theory,
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    57
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    58
      f : term,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    59
      R : term,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    60
      
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    61
      psimps: thm list,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    62
      pinducts: thm list,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    63
      termination: thm
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    64
     }
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    65
22623
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    66
fun morph_fundef_data phi (FundefCtxData {add_simps, f, R, psimps, pinducts, termination}) =
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    67
    let
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    68
      val term = Morphism.term phi
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    69
      val thm = Morphism.thm phi
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    70
      val fact = Morphism.fact phi
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    71
    in
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    72
      FundefCtxData { add_simps=add_simps (*FIXME ???*), 
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    73
                      f = term f, R = term R, psimps = fact psimps, 
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    74
                      pinducts = fact pinducts, termination = thm termination }
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    75
    end
5fcee5b319a2 proper handling of morphisms
krauss
parents: 22498
diff changeset
    76
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    77
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    78
structure FundefData = GenericDataFun
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    79
(struct
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    80
  val name = "HOL/function_def/data";
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    81
  type T = string * fundef_context_data Symtab.table
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    82
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    83
  val empty = ("", Symtab.empty);
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    84
  val copy = I;
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    85
  val extend = I;
19617
7cb4b67d4b97 avoid raw equality on type thm;
wenzelm
parents: 19612
diff changeset
    86
  fun merge _ ((l1,tab1),(l2,tab2)) = (l1, Symtab.merge (K true) (tab1, tab2))
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    87
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    88
  fun print _ _ = ();
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    89
end);
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    90
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    91
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    92
structure FundefCongs = GenericDataFun
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    93
(struct
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    94
    val name = "HOL/function_def/congs"
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    95
    type T = thm list
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    96
    val empty = []
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    97
    val extend = I
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    98
    fun merge _ = Drule.merge_rules
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    99
    fun print  _ _ = ()
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   100
end);
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   101
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   102
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   103
fun add_fundef_data name fundef_data =
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   104
    FundefData.map (fn (last,tab) => (name, Symtab.update_new (name, fundef_data) tab))
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   105
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   106
fun get_fundef_data name thy = Symtab.lookup (snd (FundefData.get thy)) name
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   107
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   108
fun set_last_fundef name = FundefData.map (apfst (K name))
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   109
fun get_last_fundef thy = fst (FundefData.get thy)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   110
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   111
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   112
val map_fundef_congs = FundefCongs.map 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   113
val get_fundef_congs = FundefCongs.get
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   114
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   115
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   116
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   117
structure TerminationRule = ProofDataFun
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   118
(struct
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   119
    val name = "HOL/function_def/termination"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   120
    type T = thm option
21357
8ebff00544e5 value restriction
haftmann
parents: 21319
diff changeset
   121
    fun init _ = NONE
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   122
    fun print  _ _ = ()
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   123
end);
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   124
21835
84fd5de0691c whitespace correction
haftmann
parents: 21357
diff changeset
   125
val get_termination_rule = TerminationRule.get
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   126
val set_termination_rule = TerminationRule.map o K o SOME
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   127
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   128
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   129
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   130
(* Configuration management *)
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   131
datatype fundef_opt 
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   132
  = Sequential
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   133
  | Default of string
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   134
  | Preprocessor of string
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   135
  | Target of xstring
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   136
  | DomIntros
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   137
  | Tailrec
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   138
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   139
datatype fundef_config
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   140
  = FundefConfig of
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   141
   {
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   142
    sequential: bool,
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   143
    default: string,
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   144
    preprocessor: string option,
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   145
    target: xstring option,
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   146
    domintros: bool,
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   147
    tailrec: bool
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   148
   }
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   149
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   150
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   151
val default_config = FundefConfig { sequential=false, default="%x. arbitrary", preprocessor=NONE,
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   152
                                    target=NONE, domintros=false, tailrec=false }
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   153
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   154
val fun_config = FundefConfig { sequential=true, default="%x. arbitrary", preprocessor=NONE, 
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   155
                                target=NONE, domintros=false, tailrec=false }
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   156
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   157
fun apply_opt Sequential (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec}) = 
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   158
    FundefConfig {sequential=true, default=default, preprocessor=preprocessor, target=target, domintros=domintros, tailrec=tailrec }
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   159
  | apply_opt (Default d) (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec}) = 
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   160
    FundefConfig {sequential=sequential, default=d, preprocessor=preprocessor, target=target, domintros=domintros, tailrec=tailrec }
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   161
  | apply_opt (Preprocessor p) (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec}) = 
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   162
    FundefConfig {sequential=sequential, default=default, preprocessor=SOME p, target=target, domintros=domintros, tailrec=tailrec }
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   163
  | apply_opt (Target t) (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec }) =
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   164
    FundefConfig {sequential=sequential, default=default, preprocessor=preprocessor, target=SOME t, domintros=domintros, tailrec=tailrec }
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   165
  | apply_opt DomIntros (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec }) =
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   166
    FundefConfig {sequential=sequential, default=default, preprocessor=preprocessor, target=target, domintros=true,tailrec=tailrec }
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   167
  | apply_opt Tailrec (FundefConfig {sequential, default, preprocessor, target, domintros,tailrec }) =
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   168
    FundefConfig {sequential=sequential, default=default, preprocessor=preprocessor, target=target, domintros=domintros,tailrec=true } 
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   169
22498
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   170
fun target_of (FundefConfig {target, ...}) = target
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   171
22498
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   172
local 
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   173
  structure P = OuterParse and K = OuterKeyword 
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   174
22498
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   175
  val opt_sequential = Scan.optional ((P.$$$ "(" |-- P.$$$ "sequential" --| P.$$$ ")") >> K true) false
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   176
                       
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   177
  val option_parser = (P.$$$ "sequential" >> K Sequential)
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   178
                   || ((P.reserved "default" |-- P.term) >> Default)
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   179
                   || (P.reserved "domintros" >> K DomIntros)
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   180
                   || (P.reserved "tailrec" >> K Tailrec)
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   181
                   || ((P.$$$ "in" |-- P.xname) >> Target)
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   182
22498
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   183
  fun config_parser def = (Scan.optional (P.$$$ "(" |-- P.!!! (P.list1 (P.group "option" option_parser)) --| P.$$$ ")") [])
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   184
                          >> (fn opts => fold apply_opt opts def)
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21835
diff changeset
   185
22498
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   186
  fun pipe_list1 s = P.enum1 "|" s
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   187
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   188
  val otherwise = P.$$$ "(" |-- P.$$$ "otherwise" --| P.$$$ ")"
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   189
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   190
  fun pipe_error t = P.!!! (Scan.fail_with (K (cat_lines ["Equations must be separated by " ^ quote "|", quote t])))
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   191
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   192
  val statement_ow = SpecParse.opt_thm_name ":" -- (P.prop -- Scan.optional (otherwise >> K true) false)
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   193
                     --| Scan.ahead ((P.term :-- pipe_error) || Scan.succeed ("",""))
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   194
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   195
  val statements_ow = pipe_list1 statement_ow
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   196
in
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   197
  fun fundef_parser default_cfg = config_parser default_cfg -- P.fixes --| P.$$$ "where" -- statements_ow
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   198
end
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   199
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   200
end
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   201
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   202
(* Common Abbreviations *)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   203
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   204
structure FundefAbbrev =
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   205
struct
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   206
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   207
fun implies_elim_swp x y = implies_elim y x
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   208
22498
62cdd4b3e96b made function syntax strict, requiring | to separate equations; cleanup
krauss
parents: 22279
diff changeset
   209
(* HOL abbreviations *)
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   210
val boolT = HOLogic.boolT
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   211
val mk_prod = HOLogic.mk_prod
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   212
val mk_eq = HOLogic.mk_eq
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   213
val eq_const = HOLogic.eq_const
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   214
val Trueprop = HOLogic.mk_Trueprop
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   215
val mk_relT = HOLogic.mk_setT o HOLogic.mk_prodT
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   216
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   217
fun free_to_var (Free (v,T)) = Var ((v,0),T)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   218
  | free_to_var _ = raise Match
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   219
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   220
fun var_to_free (Var ((v,_),T)) = Free (v,T)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   221
  | var_to_free _ = raise Match
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   222
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   223
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   224
end