src/HOL/Tools/function_package/fundef_common.ML
author haftmann
Tue, 14 Nov 2006 09:06:08 +0100
changeset 21357 8ebff00544e5
parent 21319 cf814e36f788
child 21835 84fd5de0691c
permissions -rw-r--r--
value restriction
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
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    12
(* Theory Dependencies *)
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
    13
val acc_const_name = "FunDef.accP"
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    14
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    15
val domintros = ref true;
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    16
val profile = ref false;
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    17
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
    18
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
    19
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    20
fun mk_acc domT R =
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
    21
    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
    22
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    23
val function_name = suffix "C"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    24
val graph_name = suffix "_graph"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    25
val rel_name = suffix "_rel"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    26
val dom_name = suffix "_dom"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    27
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
    28
val dest_rel_name = unsuffix "_rel"
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    29
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    30
type depgraph = int IntGraph.T
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    31
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    32
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    33
datatype ctx_tree 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    34
  = Leaf of term
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    35
  | 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
    36
  | RCall of (term * ctx_tree)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    37
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
    38
type glrs = (term list * term list * term * term) list
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    39
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    40
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    41
datatype globals =
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    42
   Globals of { 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    43
         fvar: term, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    44
         domT: typ, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    45
         ranT: typ,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    46
         h: term, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    47
         y: term, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    48
         x: term, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    49
         z: term, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    50
         a:term, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    51
         P: term, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    52
         D: term, 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    53
         Pbool:term
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    54
}
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    55
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    56
19583
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
    57
datatype rec_call_info = 
19781
c62720b20e9a HOL/Tools/function_package: More cleanup
krauss
parents: 19770
diff changeset
    58
  RCInfo of
c62720b20e9a HOL/Tools/function_package: More cleanup
krauss
parents: 19770
diff changeset
    59
  {
19922
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
    60
   RIvs: (string * typ) list,  (* Call context: fixes and assumes *)
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
    61
   CCas: thm list,
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
    62
   rcarg: term,                 (* The recursive argument *)
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
    63
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
    64
   llRI: thm,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    65
   h_assum: term
19781
c62720b20e9a HOL/Tools/function_package: More cleanup
krauss
parents: 19770
diff changeset
    66
  } 
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    67
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    68
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    69
datatype clause_context =
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    70
  ClauseContext of
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    71
  {
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    72
    ctxt : Proof.context,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    73
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    74
    qs : term list,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    75
    gs : term list,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    76
    lhs: term,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    77
    rhs: term,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    78
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    79
    cqs: cterm list,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    80
    ags: thm list,     
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    81
    case_hyp : thm
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    82
  }
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    83
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    84
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    85
fun transfer_clause_ctx thy (ClauseContext { ctxt, qs, gs, lhs, rhs, cqs, ags, case_hyp }) =
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    86
    ClauseContext { ctxt = ProofContext.transfer thy ctxt,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    87
                    qs = qs, gs = gs, lhs = lhs, rhs = rhs, cqs = cqs, ags = ags, case_hyp = case_hyp }
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    88
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    89
19583
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
    90
datatype clause_info =
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
    91
  ClauseInfo of 
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    92
     {
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    93
      no: int,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    94
      qglr : ((string * typ) list * term list * term * term),
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    95
      cdata : clause_context,
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    96
19922
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
    97
      tree: ctx_tree,
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
    98
      lGI: thm,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
    99
      RCs: rec_call_info list
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   100
     }
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   101
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   102
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   103
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   104
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   105
type qgar = string * (string * typ) list * term list * term list * term
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   106
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   107
fun name_of_fqgar (f, _, _, _, _) = f
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   108
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   109
datatype mutual_part =
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   110
  MutualPart of 
21237
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   111
   {
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   112
    fvar : string * typ,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   113
    cargTs: typ list,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   114
    pthA: SumTools.sum_path,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   115
    pthR: SumTools.sum_path,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   116
    f_def: term,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   117
21237
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   118
    f: term option,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   119
    f_defthm : thm option
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   120
   }
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   121
   
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   122
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   123
datatype mutual_info =
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   124
  Mutual of 
21237
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   125
   { 
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   126
    defname: string,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   127
    fsum_var : string * typ,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   128
21237
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   129
    ST: typ,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   130
    RST: typ,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   131
    streeA: SumTools.sum_tree,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   132
    streeR: SumTools.sum_tree,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   133
21237
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   134
    parts: mutual_part list,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   135
    fqgars: qgar list,
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   136
    qglrs: ((string * typ) list * term list * term * term) list,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   137
21237
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   138
    fsum : term option
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   139
   }
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   140
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   141
19583
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
   142
datatype prep_result =
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
   143
  Prep of
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   144
     {
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   145
      globals: globals,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   146
      f: term,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   147
      G: term,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   148
      R: term,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   149
 
19922
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
   150
      goal: term,
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
   151
      goalI: thm,
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
   152
      values: thm list,
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
   153
      clauses: clause_info list,
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
   154
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
   155
      R_cases: thm,
984ae977f7aa Fixed name clash.
krauss
parents: 19781
diff changeset
   156
      ex1_iff: thm
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   157
     }
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   158
19583
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
   159
datatype fundef_result =
c5fa77b03442 function-package: Changed record usage to make sml/nj happy...
krauss
parents: 19564
diff changeset
   160
  FundefResult of
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   161
     {
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   162
      f: term,
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   163
      G : term,
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   164
      R : term,
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   165
      completeness : thm,
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   166
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   167
      psimps : thm list, 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   168
      subset_pinduct : thm, 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   169
      simple_pinduct : thm, 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   170
      total_intro : thm,
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   171
      dom_intros : thm list
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   172
     }
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   173
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   174
datatype fundef_mresult =
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   175
  FundefMResult of
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   176
     {
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   177
      f: term,
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   178
      G: term,
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   179
      R: term,
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   180
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   181
      psimps : thm list, 
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   182
      subset_pinducts : thm list, 
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   183
      simple_pinducts : thm list, 
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   184
      cases : thm,
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   185
      termination : thm,
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   186
      domintros : thm list
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   187
     }
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   188
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   189
datatype fundef_context_data =
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   190
  FundefCtxData of
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   191
     {
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   192
      fixes : ((string * typ) * mixfix) list,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   193
      spec : ((string * Attrib.src list) * term list) list list,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   194
      mutual: mutual_info,
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19617
diff changeset
   195
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   196
      f : term,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   197
      R : term,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   198
      
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   199
      psimps: thm list,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   200
      pinducts: thm list,
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   201
      termination: thm
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   202
     }
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   203
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   204
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents: 20289
diff changeset
   205
structure FundefData = GenericDataFun
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   206
(struct
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   207
  val name = "HOL/function_def/data";
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   208
  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
   209
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   210
  val empty = ("", Symtab.empty);
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   211
  val copy = I;
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   212
  val extend = I;
19617
7cb4b67d4b97 avoid raw equality on type thm;
wenzelm
parents: 19612
diff changeset
   213
  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
   214
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   215
  fun print _ _ = ();
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   216
end);
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   217
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   218
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   219
structure FundefCongs = GenericDataFun
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   220
(struct
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   221
    val name = "HOL/function_def/congs"
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   222
    type T = thm list
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   223
    val empty = []
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   224
    val extend = I
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   225
    fun merge _ = Drule.merge_rules
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   226
    fun print  _ _ = ()
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   227
end);
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   228
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   229
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   230
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
   231
    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
   232
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   233
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
   234
21255
617fdb08abe9 added profiling code, improved handling of proof terms, generation of domain
krauss
parents: 21237
diff changeset
   235
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
   236
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
   237
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   238
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   239
val map_fundef_congs = FundefCongs.map 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   240
val get_fundef_congs = FundefCongs.get
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   241
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   242
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   243
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   244
structure TerminationRule = ProofDataFun
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   245
(struct
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   246
    val name = "HOL/function_def/termination"
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   247
    type T = thm option
21357
8ebff00544e5 value restriction
haftmann
parents: 21319
diff changeset
   248
    fun init _ = NONE
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   249
    fun print  _ _ = ()
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   250
end);
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   251
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   252
val get_termination_rule = TerminationRule.get 
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   253
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
   254
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   255
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   256
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   257
(* Configuration management *)
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   258
datatype fundef_opt 
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   259
  = Sequential
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   260
  | Default of string
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   261
  | Preprocessor of string
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   262
  | Target of xstring
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   263
  | DomIntros
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   264
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   265
datatype fundef_config
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   266
  = FundefConfig of
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   267
   {
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   268
    sequential: bool,
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   269
    default: string,
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   270
    preprocessor: string option,
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   271
    target: xstring option,
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   272
    domintros: bool
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   273
   }
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   274
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   275
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   276
val default_config = FundefConfig { sequential=false, default="%x. arbitrary", preprocessor=NONE, target=NONE, domintros=false }
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   277
val fun_config = FundefConfig { sequential=true, default="%x. arbitrary", preprocessor=NONE, target=NONE, domintros=false }
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   278
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   279
fun apply_opt Sequential (FundefConfig {sequential, default, preprocessor, target, domintros}) = 
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   280
    FundefConfig {sequential=true, default=default, preprocessor=preprocessor, target=target, domintros=domintros }
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   281
  | apply_opt (Default d) (FundefConfig {sequential, default, preprocessor, target, domintros}) = 
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   282
    FundefConfig {sequential=sequential, default=d, preprocessor=preprocessor, target=target, domintros=domintros }
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   283
  | apply_opt (Preprocessor p) (FundefConfig {sequential, default, preprocessor, target, domintros}) = 
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   284
    FundefConfig {sequential=sequential, default=default, preprocessor=SOME p, target=target, domintros=domintros }
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   285
  | apply_opt (Target t) (FundefConfig {sequential, default, preprocessor, target, domintros }) =
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   286
    FundefConfig {sequential=sequential, default=default, preprocessor=preprocessor, target=SOME t, domintros=domintros }
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   287
  | apply_opt Domintros (FundefConfig {sequential, default, preprocessor, target, domintros }) =
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   288
    FundefConfig {sequential=sequential, default=default, preprocessor=preprocessor, target=target, domintros=true }
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   289
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   290
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   291
local structure P = OuterParse and K = OuterKeyword in
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   292
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   293
val opt_sequential = Scan.optional ((P.$$$ "(" |-- P.$$$ "sequential" --| P.$$$ ")") >> K true) false
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   294
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   295
val option_parser = (P.$$$ "sequential" >> K Sequential)
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   296
               || ((P.reserved "default" |-- P.term) >> Default)
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   297
               || (P.reserved "domintros" >> K DomIntros)
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   298
               || ((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
   299
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   300
fun config_parser def = (Scan.optional (P.$$$ "(" |-- P.list1 option_parser --| P.$$$ ")") [])
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   301
                          >> (fn opts => fold apply_opt opts def)
20654
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   302
end
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   303
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   304
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   305
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   306
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   307
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   308
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   309
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   310
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   311
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   312
d80502f0d701 1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents: 20523
diff changeset
   313
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 20874
diff changeset
   314
21319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   315
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   316
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   317
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   318
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   319
cf814e36f788 replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents: 21255
diff changeset
   320
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   321
end
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   322
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   323
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   324
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   325
(* Common Abbreviations *)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   326
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   327
structure FundefAbbrev =
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   328
struct
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   329
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   330
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
   331
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   332
(* Some HOL things frequently used *)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   333
val boolT = HOLogic.boolT
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   334
val mk_prod = HOLogic.mk_prod
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   335
val mk_mem = HOLogic.mk_mem
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   336
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
   337
val eq_const = HOLogic.eq_const
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   338
val Trueprop = HOLogic.mk_Trueprop
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   339
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   340
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
   341
fun mk_relmem (x,y) R = Trueprop (mk_mem (mk_prod (x, y), R))
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   342
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   343
fun mk_subset T A B = 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   344
    let val sT = HOLogic.mk_setT T
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   345
    in Const ("Orderings.less_eq", sT --> sT --> boolT) $ A $ B end
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   346
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   347
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   348
(* with explicit types: Needed with loose bounds *)
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   349
fun mk_relmemT xT yT (x,y) R = 
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   350
    let 
21237
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   351
  val pT = HOLogic.mk_prodT (xT, yT)
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   352
  val RT = HOLogic.mk_setT pT
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   353
    in
21237
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   354
  Const ("op :", [pT, RT] ---> boolT)
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   355
        $ (HOLogic.pair_const xT yT $ x $ y)
b803f9870e97 untabified
krauss
parents: 21051
diff changeset
   356
        $ R
19564
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   357
    end
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   358
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   359
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
   360
  | free_to_var _ = raise Match
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   361
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   362
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
   363
  | var_to_free _ = raise Match
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   364
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   365
d3e2f532459a First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff changeset
   366
end