Nominal/Nominal2.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 09 Jul 2015 09:12:44 +0100
changeset 3240 f80fa0d18d81
parent 3239 67370521c09c
child 3243 c4f31f1564b7
permissions -rw-r--r--
updated examples
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2454
9ffee4eb1ae1 renamed NewParser to Nominal2
Christian Urban <urbanc@in.tum.de>
parents: 2451
diff changeset
     1
theory Nominal2
2435
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
     2
imports 
2943
09834ba7ce59 exported various FCB-lemmas to a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
     3
  Nominal2_Base Nominal2_Abs Nominal2_FCB
3134
301b74fcd614 updated to new Isabelle (declared keywords)
Christian Urban <urbanc@in.tum.de>
parents: 3091
diff changeset
     4
keywords
301b74fcd614 updated to new Isabelle (declared keywords)
Christian Urban <urbanc@in.tum.de>
parents: 3091
diff changeset
     5
  "nominal_datatype" :: thy_decl and
3236
e2da10806a34 changed nominal_primrec to nominal_function and termination to nominal_termination
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3235
diff changeset
     6
  "nominal_function" "nominal_inductive" "nominal_termination" :: thy_goal and
3134
301b74fcd614 updated to new Isabelle (declared keywords)
Christian Urban <urbanc@in.tum.de>
parents: 3091
diff changeset
     7
  "avoids" "binds"
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
begin
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
3201
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    10
ML_file "nominal_dt_data.ML"
2885
1264f2a21ea9 some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
    11
ML {* open Nominal_Dt_Data *}
1264f2a21ea9 some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
    12
3201
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    13
ML_file "nominal_dt_rawfuns.ML"
2435
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    14
ML {* open Nominal_Dt_RawFuns *}
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    15
3201
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    16
ML_file "nominal_dt_alpha.ML"
2435
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    17
ML {* open Nominal_Dt_Alpha *}
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    18
3201
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    19
ML_file "nominal_dt_quot.ML"
2435
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    20
ML {* open Nominal_Dt_Quot *}
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    21
2631
e73bd379e839 removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
parents: 2630
diff changeset
    22
(*****************************************)
e73bd379e839 removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
parents: 2630
diff changeset
    23
(* setup for induction principles method *)
3201
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    24
ML_file "nominal_induct.ML"
2631
e73bd379e839 removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
parents: 2630
diff changeset
    25
method_setup nominal_induct =
e73bd379e839 removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
parents: 2630
diff changeset
    26
  {* NominalInduct.nominal_induct_method *}
e73bd379e839 removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
parents: 2630
diff changeset
    27
  {* nominal induction *}
2609
666ffc8a92a9 freshness theorem in strong exhausts; (temporarily includes a cheat_tac to make all tests go through)
Christian Urban <urbanc@in.tum.de>
parents: 2608
diff changeset
    28
2639
a8fc346deda3 exported the code into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2634
diff changeset
    29
(****************************************************)
a8fc346deda3 exported the code into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2634
diff changeset
    30
(* inductive definition involving nominal datatypes *)
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
    31
ML_file "nominal_inductive.ML"
2639
a8fc346deda3 exported the code into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2634
diff changeset
    32
a8fc346deda3 exported the code into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2634
diff changeset
    33
2665
16b5a67ee279 exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents: 2650
diff changeset
    34
(***************************************)
16b5a67ee279 exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents: 2650
diff changeset
    35
(* forked code of the function package *)
16b5a67ee279 exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents: 2650
diff changeset
    36
(* for defining nominal functions      *)
3201
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    37
ML_file "nominal_function_common.ML"
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    38
ML_file "nominal_function_core.ML"
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    39
ML_file "nominal_mutual.ML"
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    40
ML_file "nominal_function.ML"
3e6f4320669f removed "use" - replaced by "ML_file"
Christian Urban <urbanc@in.tum.de>
parents: 3190
diff changeset
    41
ML_file "nominal_termination.ML"
2665
16b5a67ee279 exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents: 2650
diff changeset
    42
2603
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
    43
ML {*
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
    44
val eqvt_attr = Attrib.internal (K Nominal_ThmDecls.eqvt_add)
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
    45
val simp_attr = Attrib.internal (K Simplifier.simp_add)
2787
1a6593bc494d added eq_iff and distinct lemmas of nominal datatypes to the simplifier
Christian Urban <urbanc@in.tum.de>
parents: 2781
diff changeset
    46
val induct_attr = Attrib.internal (K Induct.induct_simp_add)
2603
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
    47
*}
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2146
diff changeset
    48
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
section{* Interface for nominal_datatype *}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
fun get_cnstrs dts =
3065
51ef8a3cb6ef updated to lates changes in the datatype package
Christian Urban <urbanc@in.tum.de>
parents: 3063
diff changeset
    53
  map snd dts
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
fun get_typed_cnstrs dts =
3065
51ef8a3cb6ef updated to lates changes in the datatype package
Christian Urban <urbanc@in.tum.de>
parents: 3063
diff changeset
    56
  flat (map (fn ((bn, _, _), constrs) => 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
   (map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
fun get_cnstr_strs dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
fun get_bn_fun_strs bn_funs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
2106
409ecb7284dd properly exported defined bn-functions
Christian Urban <urbanc@in.tum.de>
parents: 2105
diff changeset
    66
1944
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    67
text {* Infrastructure for adding "_raw" to types and terms *}
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    68
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
fun add_raw s = s ^ "_raw"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
fun add_raws ss = map add_raw ss
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
fun raw_bind bn = Binding.suffix_name "_raw" bn
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
fun replace_str ss s = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  case (AList.lookup (op=) ss s) of 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
     SOME s' => s'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
   | NONE => s
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  | replace_typ ty_ss T = T  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
fun raw_dts ty_ss dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
let
2640
75d353e8e60e made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
parents: 2639
diff changeset
    84
  fun raw_dts_aux1 (bind, tys, _) =
75d353e8e60e made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
parents: 2639
diff changeset
    85
    (raw_bind bind, map (replace_typ ty_ss) tys, NoSyn)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
3065
51ef8a3cb6ef updated to lates changes in the datatype package
Christian Urban <urbanc@in.tum.de>
parents: 3063
diff changeset
    87
  fun raw_dts_aux2 ((bind, ty_args, _), constrs) =
51ef8a3cb6ef updated to lates changes in the datatype package
Christian Urban <urbanc@in.tum.de>
parents: 3063
diff changeset
    88
    ((raw_bind bind, ty_args, NoSyn), map raw_dts_aux1 constrs)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  map raw_dts_aux2 dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  | replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  | replace_aterm trm_ss trm = trm
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
fun replace_term trm_ss ty_ss trm =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
ML {*
3061
cfc795473656 updated to Isabelle 6 Dec (thanks to Odrej Kuncar)
Christian Urban <urbanc@in.tum.de>
parents: 3045
diff changeset
   102
fun rawify_dts dts dts_env = raw_dts dts_env dts
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
let
2640
75d353e8e60e made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
parents: 2639
diff changeset
   108
  val bn_funs' = map (fn (bn, ty, _) => 
75d353e8e60e made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
parents: 2639
diff changeset
   109
    (raw_bind bn, SOME (replace_typ dts_env ty), NoSyn)) bn_funs
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  val bn_eqs' = map (fn (attr, trm) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
    (attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  (bn_funs', bn_eqs') 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
ML {* 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  fun rawify_bnds bnds = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
    map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2146
diff changeset
   124
  fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
in
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   126
  (map o map o map) rawify_bclause bclauses
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
ML {*
2885
1264f2a21ea9 some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   132
(* definition of the raw datatype *)
1264f2a21ea9 some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   133
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   134
fun define_raw_dts dts cnstr_names cnstr_tys bn_funs bn_eqs bclauses lthy =
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   136
  val thy = Local_Theory.exit_global lthy
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  val thy_name = Context.theory_name thy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
3065
51ef8a3cb6ef updated to lates changes in the datatype package
Christian Urban <urbanc@in.tum.de>
parents: 3063
diff changeset
   139
  val dt_names = map (fn ((s, _, _), _) => Binding.name_of s) dts
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  val dt_full_names = map (Long_Name.qualify thy_name) dt_names 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  val dt_full_names' = add_raws dt_full_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  val dts_env = dt_full_names ~~ dt_full_names'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
2633
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   144
  val cnstr_full_names = map (Long_Name.qualify thy_name) cnstr_names
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   145
  val cnstr_full_names' = map (fn (x, y) => Long_Name.qualify thy_name 
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   146
    (Long_Name.qualify (add_raw x) (add_raw y))) cnstr_tys
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   147
  val cnstrs_env = cnstr_full_names ~~ cnstr_full_names'
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  val bn_fun_strs = get_bn_fun_strs bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  val bn_fun_strs' = add_raws bn_fun_strs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
  val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   152
  val bn_fun_full_env = map (apply2 (Long_Name.qualify thy_name)) 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
    (bn_fun_strs ~~ bn_fun_strs')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
  
3061
cfc795473656 updated to Isabelle 6 Dec (thanks to Odrej Kuncar)
Christian Urban <urbanc@in.tum.de>
parents: 3045
diff changeset
   155
  val raw_dts = rawify_dts dts dts_env
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
  val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs 
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   157
  val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env bclauses 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   159
  val (raw_full_dt_names', thy1) = 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   160
    Old_Datatype.add_datatype Old_Datatype_Aux.default_config raw_dts thy
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   161
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   162
  val lthy1 = Named_Target.theory_init thy1
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   163
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   164
  val dtinfos = map (Old_Datatype_Data.the_info (Proof_Context.theory_of lthy1)) raw_full_dt_names' 
3062
b4b71c167e06 updated to Isabelle 13 Dec
Christian Urban <urbanc@in.tum.de>
parents: 3061
diff changeset
   165
  val {descr, ...} = hd dtinfos
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   166
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   167
  val raw_tys = Old_Datatype_Aux.get_rec_types descr
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   168
  val raw_ty_args = hd raw_tys
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   169
    |> snd o dest_Type
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   170
    |> map dest_TFree 
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   171
3062
b4b71c167e06 updated to Isabelle 13 Dec
Christian Urban <urbanc@in.tum.de>
parents: 3061
diff changeset
   172
  val raw_cns_info = all_dtyp_constrs_types descr
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   173
  val raw_all_cns = (map o map) (fn (c, _, _, _) => c) raw_cns_info
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   174
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   175
  val raw_inject_thms = flat (map #inject dtinfos)
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   176
  val raw_distinct_thms = flat (map #distinct dtinfos)
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   177
  val raw_induct_thm = #induct (hd dtinfos)
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   178
  val raw_induct_thms = #inducts (hd dtinfos)
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   179
  val raw_exhaust_thms = map #exhaust dtinfos
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   180
  val raw_size_trms = map HOLogic.size_const raw_tys
3233
9ae285ce814e updated changes from upstream (AFP)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3231
diff changeset
   181
  val raw_size_thms = these (Option.map ((fn ths => drop (length ths div 2) ths) o fst o snd)
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   182
    (BNF_LFP_Size.size_of lthy1 (hd raw_full_dt_names')))
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   183
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   184
  val raw_result = RawDtInfo 
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   185
    {raw_dt_names = raw_full_dt_names',
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   186
     raw_dts = raw_dts,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   187
     raw_tys = raw_tys,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   188
     raw_ty_args = raw_ty_args,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   189
     raw_cns_info = raw_cns_info,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   190
     raw_all_cns = raw_all_cns,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   191
     raw_inject_thms = raw_inject_thms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   192
     raw_distinct_thms = raw_distinct_thms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   193
     raw_induct_thm = raw_induct_thm,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   194
     raw_induct_thms = raw_induct_thms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   195
     raw_exhaust_thms = raw_exhaust_thms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   196
     raw_size_trms = raw_size_trms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   197
     raw_size_thms = raw_size_thms}
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   198
in
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   199
  (raw_bclauses, raw_bn_funs, raw_bn_eqs, raw_result, lthy1)
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   200
end
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   201
*}
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   202
2125
60ee289a8c63 made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
parents: 2122
diff changeset
   203
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
ML {*
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   205
fun nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses lthy =
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
let
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   207
  val cnstr_names = get_cnstr_strs dts
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   208
  val cnstr_tys = get_typed_cnstrs dts
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   210
  val _ = trace_msg (K "Defining raw datatypes...")
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   211
  val (raw_bclauses, raw_bn_funs, raw_bn_eqs, raw_dt_info, lthy0) =
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   212
    define_raw_dts dts cnstr_names cnstr_tys bn_funs bn_eqs bclauses lthy   
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   213
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   214
  val RawDtInfo 
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   215
    {raw_dt_names,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   216
     raw_tys,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   217
     raw_ty_args,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   218
     raw_all_cns,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   219
     raw_inject_thms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   220
     raw_distinct_thms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   221
     raw_induct_thm,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   222
     raw_induct_thms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   223
     raw_exhaust_thms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   224
     raw_size_trms,
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   225
     raw_size_thms, ...} = raw_dt_info
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   226
  
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   227
  val _ = trace_msg (K "Defining raw permutations...")
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   228
  val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2a) = define_raw_perms raw_dt_info lthy0
2144
e900526e95c4 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2143
diff changeset
   229
 
e900526e95c4 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2143
diff changeset
   230
  (* noting the raw permutations as eqvt theorems *)
2959
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   231
  val lthy3 = snd (Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_perm_simps) lthy2a)
2011
12ce87b55f97 tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2008
diff changeset
   232
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   233
  val _ = trace_msg (K "Defining raw fv- and bn-functions...")
2922
a27215ab674e some experiments
Christian Urban <urbanc@in.tum.de>
parents: 2888
diff changeset
   234
  val (raw_bns, raw_bn_defs, raw_bn_info, raw_bn_inducts, lthy3a) =
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   235
    define_raw_bns raw_dt_info raw_bn_funs raw_bn_eqs lthy3
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   236
    
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   237
  (* defining the permute_bn functions *)
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   238
  val (raw_perm_bns, raw_perm_bn_simps, lthy3b) = 
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   239
    define_raw_bn_perms raw_dt_info raw_bn_info lthy3a
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   240
    
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   241
  val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3c) = 
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   242
    define_raw_fvs raw_dt_info raw_bn_info raw_bclauses lthy3b
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   243
    
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   244
  val _ = trace_msg (K "Defining alpha relations...")
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   245
  val (alpha_result, lthy4) =
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   246
    define_raw_alpha raw_dt_info raw_bn_info raw_bclauses raw_fvs lthy3c
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   247
    
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   248
  val _ = trace_msg (K "Proving distinct theorems...")
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   249
  val alpha_distincts = raw_prove_alpha_distincts lthy4 alpha_result raw_dt_info
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   250
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   251
  val _ = trace_msg (K "Proving eq-iff theorems...")
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   252
  val alpha_eq_iff = raw_prove_alpha_eq_iff lthy4 alpha_result raw_dt_info
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   253
    
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   254
  val _ = trace_msg (K "Proving equivariance of bns, fvs, size and alpha...")
2406
428d9cb9a243 can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
parents: 2405
diff changeset
   255
  val raw_bn_eqvt = 
2922
a27215ab674e some experiments
Christian Urban <urbanc@in.tum.de>
parents: 2888
diff changeset
   256
    raw_prove_eqvt raw_bns raw_bn_inducts (raw_bn_defs @ raw_perm_simps) lthy4
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   257
    
2406
428d9cb9a243 can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
parents: 2405
diff changeset
   258
  (* noting the raw_bn_eqvt lemmas in a temprorary theory *)
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   259
  val lthy_tmp = snd (Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_bn_eqvt) lthy4)
2305
93ab397f5980 smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   260
2406
428d9cb9a243 can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
parents: 2405
diff changeset
   261
  val raw_fv_eqvt = 
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   262
    raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_simps) 
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   263
      (Local_Theory.restore lthy_tmp)
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   264
    
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   265
  val raw_size_eqvt =
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   266
    let
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   267
      val RawDtInfo {raw_size_trms, raw_size_thms, raw_induct_thms, ...} = raw_dt_info
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   268
    in
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   269
      raw_prove_eqvt raw_size_trms raw_induct_thms (raw_size_thms @ raw_perm_simps) 
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   270
        (Local_Theory.restore lthy_tmp)
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   271
        |> map (rewrite_rule (Local_Theory.restore lthy_tmp)
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   272
            @{thms permute_nat_def[THEN eq_reflection]})
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   273
        |> map (fn thm => thm RS @{thm sym})
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   274
    end 
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   275
     
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   276
  val lthy5 = snd (Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_fv_eqvt) lthy_tmp)
2306
86c977b4a9bb equivariance done
Christian Urban <urbanc@in.tum.de>
parents: 2305
diff changeset
   277
2868
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2858
diff changeset
   278
  val alpha_eqvt =
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   279
    let
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   280
      val AlphaResult {alpha_trms, alpha_bn_trms, alpha_raw_induct, alpha_intros, ...} = alpha_result
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   281
    in
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3201
diff changeset
   282
      Nominal_Eqvt.raw_equivariance lthy5 (alpha_trms @ alpha_bn_trms) alpha_raw_induct alpha_intros
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   283
    end
2868
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2858
diff changeset
   284
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2858
diff changeset
   285
  val alpha_eqvt_norm = map (Nominal_ThmDecls.eqvt_transform lthy5) alpha_eqvt
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   286
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   287
  val _ = trace_msg (K "Proving equivalence of alpha...")
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   288
  val alpha_refl_thms = raw_prove_refl lthy5 alpha_result raw_induct_thm  
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   289
  val alpha_sym_thms = raw_prove_sym lthy5 alpha_result alpha_eqvt_norm
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   290
  val alpha_trans_thms =
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   291
    raw_prove_trans lthy5 alpha_result (raw_distinct_thms @ raw_inject_thms) alpha_eqvt_norm
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   292
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   293
  val (alpha_equivp_thms, alpha_bn_equivp_thms) = 
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   294
    raw_prove_equivp lthy5 alpha_result alpha_refl_thms alpha_sym_thms alpha_trans_thms
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2321
diff changeset
   295
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   296
  val _ = trace_msg (K "Proving alpha implies bn...")
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   297
  val alpha_bn_imp_thms = raw_prove_bn_imp lthy5 alpha_result
2922
a27215ab674e some experiments
Christian Urban <urbanc@in.tum.de>
parents: 2888
diff changeset
   298
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   299
  val _ = trace_msg (K "Proving respectfulness...")
2438
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   300
  val raw_funs_rsp_aux = 
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   301
    raw_fv_bn_rsp_aux lthy5 alpha_result raw_fvs raw_bns raw_fv_bns (raw_bn_defs @ raw_fv_defs) 
3164
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   302
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   303
  val raw_funs_rsp = map (Drule.eta_contraction_rule o mk_funs_rsp lthy5) raw_funs_rsp_aux
3164
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   304
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   305
  fun match_const cnst th =
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   306
    (fst o dest_Const o snd o dest_comb o HOLogic.dest_Trueprop o Thm.prop_of) th =
3164
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   307
    fst (dest_Const cnst);
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   308
  fun find_matching_rsp cnst =
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   309
    hd (filter (fn th => match_const cnst th) raw_funs_rsp);
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   310
  val raw_fv_rsp = map find_matching_rsp raw_fvs;
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   311
  val raw_bn_rsp = map find_matching_rsp raw_bns;
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   312
  val raw_fv_bn_rsp = map find_matching_rsp raw_fv_bns;
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   313
2438
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   314
  val raw_size_rsp = 
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   315
    raw_size_rsp_aux lthy5 alpha_result (raw_size_thms @ raw_size_eqvt)
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   316
      |> map (mk_funs_rsp lthy5)
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   317
2438
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   318
  val raw_constrs_rsp = 
3161
aa1ba91ed1ff Pass proper rsp theorems for constructors and for size
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3157
diff changeset
   319
    raw_constrs_rsp lthy5 alpha_result raw_all_cns (alpha_bn_imp_thms @ raw_funs_rsp_aux) 
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   320
    
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   321
  val alpha_permute_rsp = map (mk_alpha_permute_rsp lthy5) alpha_eqvt
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   322
2438
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   323
  val alpha_bn_rsp = 
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   324
    raw_alpha_bn_rsp alpha_result alpha_bn_equivp_thms alpha_bn_imp_thms
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   325
2966
fa37c2a33812 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   326
  val raw_perm_bn_rsp = raw_perm_bn_rsp lthy5 alpha_result raw_perm_bns raw_perm_bn_simps
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   327
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   328
  val _ = trace_msg (K "Defining the quotient types...")
3065
51ef8a3cb6ef updated to lates changes in the datatype package
Christian Urban <urbanc@in.tum.de>
parents: 3063
diff changeset
   329
  val qty_descr = map (fn ((bind, vs, mx), _) => (map fst vs, bind, mx)) dts
3164
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   330
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   331
  val (qty_infos, lthy7) =
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   332
    let
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   333
      val AlphaResult {alpha_trms, alpha_tys, ...} = alpha_result
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   334
    in
3164
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   335
      define_qtypes qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy5
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   336
    end
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   337
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   338
  val qtys = map #qtyp qty_infos
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   339
  val qty_full_names = map (fst o dest_Type) qtys
3161
aa1ba91ed1ff Pass proper rsp theorems for constructors and for size
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3157
diff changeset
   340
  val qty_names = map Long_Name.base_name qty_full_names
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   341
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   342
  val _ = trace_msg (K "Defining the quotient constants...")
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   343
  val qconstrs_descrs =
3161
aa1ba91ed1ff Pass proper rsp theorems for constructors and for size
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3157
diff changeset
   344
    (map2 o map2) (fn (b, _, mx) => fn (t, th) => (Variable.check_name b, t, mx, th))
aa1ba91ed1ff Pass proper rsp theorems for constructors and for size
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3157
diff changeset
   345
      (get_cnstrs dts) (map (op ~~) (raw_all_cns ~~ raw_constrs_rsp))
2338
e1764a73c292 slight cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2337
diff changeset
   346
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   347
  val qbns_descr =
3164
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   348
    map2 (fn (b, _, mx) => fn (t, th) => (Variable.check_name b, t, mx, th)) bn_funs (raw_bns ~~ raw_bn_rsp)
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   349
3164
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   350
  val qfvs_descr =
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   351
    map2 (fn n => fn (t, th) => ("fv_" ^ n, t, NoSyn, th)) qty_names (raw_fvs ~~ raw_fv_rsp)
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   352
3164
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   353
  val qfv_bns_descr =
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   354
    map2 (fn (b, _, _) => fn (t, th) => ("fv_" ^ Variable.check_name b, t, NoSyn, th))
25c61cc06ae2 Find remaining rsp theorems and provide them with the quotient definitions
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3163
diff changeset
   355
      bn_funs (raw_fv_bns ~~ raw_fv_bn_rsp)
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   356
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   357
  val qalpha_bns_descr = 
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   358
    let
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   359
      val AlphaResult {alpha_bn_trms, ...} = alpha_result 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   360
    in
3163
a29b35442d1c Declare rsp for permute, permute_bn, alpha_bn together with their definitions instead of TrueI
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3161
diff changeset
   361
      map2 (fn (b, _, _) => fn (t, th) => ("alpha_" ^ Variable.check_name b, t, NoSyn, th)) 
a29b35442d1c Declare rsp for permute, permute_bn, alpha_bn together with their definitions instead of TrueI
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3161
diff changeset
   362
        bn_funs (alpha_bn_trms ~~ alpha_bn_rsp)
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   363
    end
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   364
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   365
  val qperm_descr =
3163
a29b35442d1c Declare rsp for permute, permute_bn, alpha_bn together with their definitions instead of TrueI
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3161
diff changeset
   366
    map2 (fn n => fn (t, th) => ("permute_" ^ n, Type.legacy_freeze t, NoSyn, th))
a29b35442d1c Declare rsp for permute, permute_bn, alpha_bn together with their definitions instead of TrueI
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3161
diff changeset
   367
      qty_names (raw_perm_funs ~~ (take (length raw_perm_funs) alpha_permute_rsp))
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   368
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   369
  val qsize_descr =
3161
aa1ba91ed1ff Pass proper rsp theorems for constructors and for size
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3157
diff changeset
   370
    map2 (fn n => fn (t, th) => ("size_" ^ n, t, NoSyn, th)) qty_names
aa1ba91ed1ff Pass proper rsp theorems for constructors and for size
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3157
diff changeset
   371
      (raw_size_trms ~~ (take (length raw_size_trms) raw_size_rsp))
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   372
2562
e8ec504dddf2 lifted permute_bn constants
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   373
  val qperm_bn_descr = 
3163
a29b35442d1c Declare rsp for permute, permute_bn, alpha_bn together with their definitions instead of TrueI
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3161
diff changeset
   374
    map2 (fn (b, _, _) => fn (t, th) => ("permute_" ^ Variable.check_name b, t, NoSyn, th))
a29b35442d1c Declare rsp for permute, permute_bn, alpha_bn together with their definitions instead of TrueI
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3161
diff changeset
   375
      bn_funs (raw_perm_bns ~~ raw_perm_bn_rsp)
3157
de89c95c5377 updated to latest changes (10 April) to quotient package (lift_raw_const only takes dummy theorem TrueI....in the future this will not work anymore)
Christian Urban <urbanc@in.tum.de>
parents: 3135
diff changeset
   376
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   377
  val ((((((qconstrs_infos, qbns_info), qfvs_info), qfv_bns_info), qalpha_bns_info), qperm_bns_info), 
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   378
    lthy8) = 
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   379
      lthy7
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   380
      |> fold_map (define_qconsts qtys) qconstrs_descrs 
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   381
      ||>> define_qconsts qtys qbns_descr 
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   382
      ||>> define_qconsts qtys qfvs_descr
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   383
      ||>> define_qconsts qtys qfv_bns_descr
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   384
      ||>> define_qconsts qtys qalpha_bns_descr
2562
e8ec504dddf2 lifted permute_bn constants
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   385
      ||>> define_qconsts qtys qperm_bn_descr
2338
e1764a73c292 slight cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2337
diff changeset
   386
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   387
  val lthy9 = 
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   388
    define_qperms qtys qty_full_names raw_ty_args qperm_descr raw_perm_laws lthy8 
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   389
  
2401
7645e18e8b19 modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
parents: 2400
diff changeset
   390
  val lthy9a = 
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   391
    define_qsizes qtys qty_full_names raw_ty_args qsize_descr lthy9
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   392
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   393
  val qtrms = (map o map) #qconst qconstrs_infos
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   394
  val qbns = map #qconst qbns_info
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   395
  val qfvs = map #qconst qfvs_info
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   396
  val qfv_bns = map #qconst qfv_bns_info
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   397
  val qalpha_bns = map #qconst qalpha_bns_info
2593
25dcb2b1329e ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
parents: 2571
diff changeset
   398
  val qperm_bns = map #qconst qperm_bns_info
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   399
2649
a8ebcb368a15 a modified function package where, as a test, True has been injected into the compatibility condictions
Christian Urban <urbanc@in.tum.de>
parents: 2647
diff changeset
   400
  val _ = trace_msg (K "Lifting of theorems...")  
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   401
  val eq_iff_simps = @{thms alphas permute_prod.simps prod_fv.simps prod_alpha_def rel_prod_sel
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3228
diff changeset
   402
    prod.case} 
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   403
2959
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   404
  val ([ qdistincts, qeq_iffs, qfv_defs, qbn_defs, qperm_simps, qfv_qbn_eqvts, 
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   405
         qbn_inducts, qsize_eqvt, [qinduct], qexhausts, qsize_simps, qperm_bn_simps, 
2966
fa37c2a33812 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   406
         qalpha_refl_thms, qalpha_sym_thms, qalpha_trans_thms ], lthyB) = 
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   407
    lthy9a    
2959
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   408
    |>>> lift_thms qtys [] alpha_distincts  
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   409
    ||>>> lift_thms qtys eq_iff_simps alpha_eq_iff       
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   410
    ||>>> lift_thms qtys [] raw_fv_defs
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   411
    ||>>> lift_thms qtys [] raw_bn_defs
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   412
    ||>>> lift_thms qtys [] raw_perm_simps
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   413
    ||>>> lift_thms qtys [] (raw_fv_eqvt @ raw_bn_eqvt)
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   414
    ||>>> lift_thms qtys [] raw_bn_inducts
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   415
    ||>>> lift_thms qtys [] raw_size_eqvt
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   416
    ||>>> lift_thms qtys [] [raw_induct_thm]
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   417
    ||>>> lift_thms qtys [] raw_exhaust_thms
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   418
    ||>>> lift_thms qtys [] raw_size_thms
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   419
    ||>>> lift_thms qtys [] raw_perm_bn_simps
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   420
    ||>>> lift_thms qtys [] alpha_refl_thms
2966
fa37c2a33812 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   421
    ||>>> lift_thms qtys [] alpha_sym_thms
fa37c2a33812 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   422
    ||>>> lift_thms qtys [] alpha_trans_thms
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   423
2922
a27215ab674e some experiments
Christian Urban <urbanc@in.tum.de>
parents: 2888
diff changeset
   424
  val qinducts = Project_Rule.projections lthyB qinduct
2474
6e37bfb62474 generated inducts rule by Project_Rule.projections
Christian Urban <urbanc@in.tum.de>
parents: 2471
diff changeset
   425
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   426
  val _ = trace_msg (K "Proving supp lemmas and fs-instances...")
2959
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2957
diff changeset
   427
  val qsupports_thms = prove_supports lthyB qperm_simps (flat qtrms)
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   428
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   429
  (* finite supp lemmas *)
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   430
  val qfsupp_thms = prove_fsupp lthyB qtys qinduct qsupports_thms
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   431
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   432
  (* fs instances *)
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2950
diff changeset
   433
  val lthyC = fs_instance qtys qty_full_names raw_ty_args qfsupp_thms lthyB
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   434
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   435
  val _ = trace_msg (K "Proving equality between fv and supp...")
2475
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2474
diff changeset
   436
  val qfv_supp_thms = 
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   437
    prove_fv_supp qtys (flat qtrms) qfvs qfv_bns qalpha_bns qfv_defs qeq_iffs 
2481
3a5ebb2fcdbf made supp proofs more robust by not using the standard induction; renamed some example files
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   438
      qperm_simps qfv_qbn_eqvts qinduct (flat raw_bclauses) lthyC
3063
32abaea424bd generated the correct thm-list for showing that qfv are equal to support
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
   439
    |> map Drule.eta_contraction_rule
2475
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2474
diff changeset
   440
2492
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   441
  (* postprocessing of eq and fv theorems *)
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   442
  val qeq_iffs' = qeq_iffs
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   443
    |> map (simplify (put_simpset HOL_basic_ss lthyC addsimps qfv_supp_thms))
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   444
    |> map (simplify (put_simpset HOL_basic_ss lthyC
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   445
        addsimps @{thms prod_fv_supp prod_alpha_eq Abs_eq_iff[symmetric]}))
2492
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   446
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3201
diff changeset
   447
  (* filters the theorems that are of the form "qfv = supp" *)
3228
040519ec99e9 fixed bug with support and freshness lemmas not being simplified properly
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3227
diff changeset
   448
  val qfv_names = map (fst o dest_Const) qfvs
040519ec99e9 fixed bug with support and freshness lemmas not being simplified properly
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3227
diff changeset
   449
  fun is_qfv_thm (@{term Trueprop} $ (Const (@{const_name HOL.eq}, _) $ Const (lhs, _) $ _)) = 
040519ec99e9 fixed bug with support and freshness lemmas not being simplified properly
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3227
diff changeset
   450
    member (op=) qfv_names lhs
3063
32abaea424bd generated the correct thm-list for showing that qfv are equal to support
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
   451
  | is_qfv_thm _ = false
32abaea424bd generated the correct thm-list for showing that qfv are equal to support
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
   452
2492
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   453
  val qsupp_constrs = qfv_defs
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   454
    |> map (simplify (put_simpset HOL_basic_ss lthyC
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   455
        addsimps (filter (is_qfv_thm o Thm.prop_of) qfv_supp_thms)))
2492
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   456
2493
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   457
  val transform_thm = @{lemma "x = y \<Longrightarrow> a \<notin> x \<longleftrightarrow> a \<notin> y" by simp}
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   458
  val transform_thms = 
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   459
    [ @{lemma "a \<notin> (S \<union> T) \<longleftrightarrow> a \<notin> S \<and> a \<notin> T" by simp}, 
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   460
      @{lemma "a \<notin> (S - T) \<longleftrightarrow> a \<notin> S \<or> a \<in> T" by simp}, 
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   461
      @{lemma "(lhs = (a \<notin> {})) \<longleftrightarrow> lhs" by simp}, 
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   462
      @{thm fresh_def[symmetric]}]
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   463
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   464
  val qfresh_constrs = qsupp_constrs
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   465
    |> map (fn thm => thm RS transform_thm) 
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   466
    |> map (simplify (put_simpset HOL_basic_ss lthyC addsimps transform_thms))
2493
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   467
2593
25dcb2b1329e ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
parents: 2571
diff changeset
   468
  (* proving that the qbn result is finite *)
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   469
  val qbn_finite_thms = prove_bns_finite qtys qbns qinduct qbn_defs lthyC
2593
25dcb2b1329e ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
parents: 2571
diff changeset
   470
25dcb2b1329e ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
parents: 2571
diff changeset
   471
  (* proving that perm_bns preserve alpha *)
2594
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   472
  val qperm_bn_alpha_thms = 
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   473
    prove_perm_bn_alpha_thms qtys qperm_bns qalpha_bns qinduct qperm_bn_simps qeq_iffs' 
2594
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   474
      qalpha_refl_thms lthyC
2493
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   475
2598
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   476
  (* proving the relationship of bn and permute_bn *)
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   477
  val qpermute_bn_thms = 
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   478
    prove_permute_bn_thms qtys qbns qperm_bns qinduct qperm_bn_simps qbn_defs qfv_qbn_eqvts lthyC
2598
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   479
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   480
  val _ = trace_msg (K "Proving strong exhaust lemmas...")
2619
25fb0dbe9f13 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2618
diff changeset
   481
  val qstrong_exhaust_thms = prove_strong_exhausts lthyC qexhausts bclauses qbn_finite_thms qeq_iffs'
2616
dd7490fdd998 all examples for strong exhausts work; recursive binders need to be treated differently; still unclean version with lots of diagnostic code
Christian Urban <urbanc@in.tum.de>
parents: 2613
diff changeset
   482
    qfv_qbn_eqvts qpermute_bn_thms qperm_bn_alpha_thms
dd7490fdd998 all examples for strong exhausts work; recursive binders need to be treated differently; still unclean version with lots of diagnostic code
Christian Urban <urbanc@in.tum.de>
parents: 2613
diff changeset
   483
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   484
  val _ = trace_msg (K "Proving strong induct lemmas...")
2633
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   485
  val qstrong_induct_thms =  prove_strong_induct lthyC qinduct qstrong_exhaust_thms qsize_simps bclauses
2628
16ffbc8442ca generated goals for strong induction theorems.
Christian Urban <urbanc@in.tum.de>
parents: 2626
diff changeset
   486
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   487
  (* noting the theorems *)  
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   488
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   489
  (* generating the prefix for the theorem names *)
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   490
  val thms_name = 
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   491
    the_default (Binding.name (space_implode "_" qty_names)) opt_thms_name 
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   492
  fun thms_suffix s = Binding.qualified true s thms_name 
2633
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   493
  val case_names_attr = Attrib.internal (K (Rule_Cases.case_names cnstr_names))
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   494
2885
1264f2a21ea9 some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   495
  val infos = mk_infos qty_full_names qeq_iffs' qdistincts qstrong_exhaust_thms qstrong_induct_thms
1264f2a21ea9 some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   496
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   497
  val (_, lthy9') = lthyC
3045
d0ad264f8c4f updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 2973
diff changeset
   498
     |> Local_Theory.declaration {syntax = false, pervasive = false} (K (fold register_info infos))
2787
1a6593bc494d added eq_iff and distinct lemmas of nominal datatypes to the simplifier
Christian Urban <urbanc@in.tum.de>
parents: 2781
diff changeset
   499
     |> Local_Theory.note ((thms_suffix "distinct", [induct_attr, simp_attr]), qdistincts) 
1a6593bc494d added eq_iff and distinct lemmas of nominal datatypes to the simplifier
Christian Urban <urbanc@in.tum.de>
parents: 2781
diff changeset
   500
     ||>> Local_Theory.note ((thms_suffix "eq_iff", [induct_attr, simp_attr]), qeq_iffs')
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   501
     ||>> Local_Theory.note ((thms_suffix "fv_defs", []), qfv_defs) 
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   502
     ||>> Local_Theory.note ((thms_suffix "bn_defs", []), qbn_defs) 
2922
a27215ab674e some experiments
Christian Urban <urbanc@in.tum.de>
parents: 2888
diff changeset
   503
     ||>> Local_Theory.note ((thms_suffix "bn_inducts", []), qbn_inducts) 
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   504
     ||>> Local_Theory.note ((thms_suffix "perm_simps", [eqvt_attr, simp_attr]), qperm_simps) 
2922
a27215ab674e some experiments
Christian Urban <urbanc@in.tum.de>
parents: 2888
diff changeset
   505
     ||>> Local_Theory.note ((thms_suffix "fv_bn_eqvt", [eqvt_attr]), qfv_qbn_eqvts) 
2858
de6b601c8d3d added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
parents: 2822
diff changeset
   506
     ||>> Local_Theory.note ((thms_suffix "size", [simp_attr]), qsize_simps)
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   507
     ||>> Local_Theory.note ((thms_suffix "size_eqvt", []), qsize_eqvt)
2633
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   508
     ||>> Local_Theory.note ((thms_suffix "induct", [case_names_attr]), [qinduct]) 
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   509
     ||>> Local_Theory.note ((thms_suffix "inducts", [case_names_attr]), qinducts)
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   510
     ||>> Local_Theory.note ((thms_suffix "exhaust", [case_names_attr]), qexhausts)
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   511
     ||>> Local_Theory.note ((thms_suffix "strong_exhaust", [case_names_attr]), qstrong_exhaust_thms)
d1d09177ec89 added proper case names for all induct and exhaust theorems
Christian Urban <urbanc@in.tum.de>
parents: 2631
diff changeset
   512
     ||>> Local_Theory.note ((thms_suffix "strong_induct", [case_names_attr]), qstrong_induct_thms)
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   513
     ||>> Local_Theory.note ((thms_suffix "supports", []), qsupports_thms)
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   514
     ||>> Local_Theory.note ((thms_suffix "fsupp", []), qfsupp_thms)
2492
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   515
     ||>> Local_Theory.note ((thms_suffix "supp", []), qsupp_constrs)
3181
ca162f0a7957 added to the simplifier nominal_datatype.fresh lemmas
Christian Urban <urbanc@in.tum.de>
parents: 3164
diff changeset
   516
     ||>> Local_Theory.note ((thms_suffix "fresh", [simp_attr]), qfresh_constrs)
2563
7c8bfc35663a lifted permute_bn simp rules
Christian Urban <urbanc@in.tum.de>
parents: 2562
diff changeset
   517
     ||>> Local_Theory.note ((thms_suffix "perm_bn_simps", []), qperm_bn_simps)
2571
f0252365936c proved that bn functions return a finite set
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   518
     ||>> Local_Theory.note ((thms_suffix "bn_finite", []), qbn_finite_thms)
2593
25dcb2b1329e ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
parents: 2571
diff changeset
   519
     ||>> Local_Theory.note ((thms_suffix "perm_bn_alpha", []), qperm_bn_alpha_thms)
2598
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   520
     ||>> Local_Theory.note ((thms_suffix "permute_bn", []), qpermute_bn_thms)
2966
fa37c2a33812 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   521
     ||>> Local_Theory.note ((thms_suffix "alpha_refl", []), qalpha_refl_thms)
fa37c2a33812 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   522
     ||>> Local_Theory.note ((thms_suffix "alpha_sym", []), qalpha_sym_thms)
fa37c2a33812 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   523
     ||>> Local_Theory.note ((thms_suffix "alpha_trans", []), qalpha_trans_thms)
fa37c2a33812 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   524
     
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
in
2601
89c55d36980f moved definition of raw bn-functions into nominal_dt_rawfuns
Christian Urban <urbanc@in.tum.de>
parents: 2600
diff changeset
   526
  lthy9'
2647
5e95387bef45 removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
parents: 2643
diff changeset
   527
end 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
2475
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2474
diff changeset
   530
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
section {* Preparing and parsing of the specification *}
3091
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   532
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   533
ML {*
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   534
(* adds the default sort @{sort fs} to nominal specifications *)
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   535
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   536
fun augment_sort thy S = Sign.inter_sort thy (@{sort fs}, S)
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   537
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   538
fun augment_sort_typ thy =
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   539
  map_type_tfree (fn (s, S) => TFree (s, augment_sort thy S))
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   540
*}
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   541
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
ML {* 
3091
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   543
(* generates the parsed datatypes and declares the constructors *)
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   544
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   545
fun prepare_dts dt_strs thy = 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
let
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   547
  fun prep_spec ((tname, tvs, mx), constrs) =
3091
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   548
    ((tname, tvs, mx), constrs |> map (fn (c, atys, mx', _) => (c, map snd atys, mx')))
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   549
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   550
  val (dts, spec_ctxt) = 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   551
    Old_Datatype.read_specs (map prep_spec dt_strs) thy
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   552
 
3091
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   553
  fun augment ((tname, tvs, mx), constrs) =
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   554
    ((tname, map (apsnd (augment_sort thy)) tvs, mx), 
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   555
      constrs |> map (fn (c, tys, mx') => (c, map (augment_sort_typ thy) tys, mx')))
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   556
  
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   557
  val dts' = map augment dts
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   558
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   559
  fun mk_constr_trms ((tname, tvs, _), constrs) =
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   560
    let
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   561
      val ty = Type (Sign.full_name thy tname, map TFree tvs)
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   562
    in
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   563
      map (fn (c, tys, mx) => (c, (tys ---> ty), mx)) constrs
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   564
    end
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   565
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   566
  val constr_trms = flat (map mk_constr_trms dts')
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   567
  
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   568
  (* FIXME: local version *)
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   569
  (* val (_, spec_ctxt') = Proof_Context.add_fixes constr_trms spec_ctxt *)
3091
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   570
3231
188826f1ccdb updated to massive changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   571
  val thy' = Sign.add_consts constr_trms (Proof_Context.theory_of spec_ctxt)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
in
3091
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   573
  (dts', thy')
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
ML {*
3091
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   578
(* parsing the binding function specifications and *)
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   579
(* declaring the function constants                *)
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   580
fun prepare_bn_funs bn_fun_strs bn_eq_strs thy =
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   582
  val lthy = Named_Target.theory_init thy
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   583
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   584
  val ((bn_funs, bn_eqs), lthy') = 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   585
    Specification.read_spec bn_fun_strs bn_eq_strs lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   586
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   587
  fun prep_bn_fun ((bn, T), mx) = (bn, T, mx) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   588
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   589
  val bn_funs' = map prep_bn_fun bn_funs
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   590
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   591
in
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   592
  (Local_Theory.exit_global lthy')
3231
188826f1ccdb updated to massive changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   593
  |> Sign.add_consts bn_funs'
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   594
  |> pair (bn_funs', bn_eqs) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   595
end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   596
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   597
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   598
text {* associates every SOME with the index in the list; drops NONEs *}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   599
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   600
fun indexify xs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   601
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   602
  fun mapp _ [] = []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
    | mapp i (NONE :: xs) = mapp (i + 1) xs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
    | mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
in 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
  mapp 0 xs 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   607
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
fun index_lookup xs x =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   610
  case AList.lookup (op=) xs x of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   611
    SOME x => x
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   612
  | NONE => error ("Cannot find " ^ x ^ " as argument annotation.");
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   613
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   614
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   615
ML {*
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   616
fun prepare_bclauses dt_strs thy = 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
  val annos_bclauses =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
    get_cnstrs dt_strs
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   620
    |> (map o map) (fn (_, antys, _, bns) => (map fst antys, bns))
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
  fun prep_binder env bn_str =
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   623
    case (Syntax.read_term_global thy bn_str) of
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
      Free (x, _) => (NONE, index_lookup env x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
    | Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
    | _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   627
 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
  fun prep_body env bn_str = index_lookup env bn_str
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   629
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   630
  fun prep_bclause env (mode, binders, bodies) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   632
    val binders' = map (prep_binder env) binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
    val bodies' = map (prep_body env) bodies
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
  in  
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   635
    BC (mode, binders', bodies')
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   638
  fun prep_bclauses (annos, bclause_strs) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
    val env = indexify annos (* for every label, associate the index *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
    map (prep_bclause env) bclause_strs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
in
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   645
  ((map o map) prep_bclauses annos_bclauses, thy)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   648
1943
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   649
text {* 
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   650
  adds an empty binding clause for every argument
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   651
  that is not already part of a binding clause
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   652
*}
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   653
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
fun included i bcs = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   656
let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   657
  fun incl (BC (_, bns, bds)) = 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   658
    member (op =) (map snd bns) i orelse member (op =) bds i
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
  exists incl bcs 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   661
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
ML {* 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
fun complete dt_strs bclauses = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   666
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
  val args = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   668
    get_cnstrs dt_strs
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   669
    |> (map o map) (fn (_, antys, _, _) => length antys)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   671
  fun complt n bcs = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   672
  let
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2146
diff changeset
   673
    fun add bcs i = (if included i bcs then [] else [BC (Lst, [], [i])]) 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   675
    bcs @ (flat (map_range (add bcs) n))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   677
in
2616
dd7490fdd998 all examples for strong exhausts work; recursive binders need to be treated differently; still unclean version with lots of diagnostic code
Christian Urban <urbanc@in.tum.de>
parents: 2613
diff changeset
   678
  (map2 o map2) complt args bclauses
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   679
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   681
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682
ML {*
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   683
fun nominal_datatype2_cmd (opt_thms_name, dt_strs, bn_fun_strs, bn_eq_strs) lthy = 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   684
let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   685
  (* this theory is used just for parsing *)
3045
d0ad264f8c4f updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 2973
diff changeset
   686
  val thy = Proof_Context.theory_of lthy  
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   687
3091
578e0265b235 the default sort for type-variables in nominal specifications is fs; it is automatically addded
Christian Urban <urbanc@in.tum.de>
parents: 3076
diff changeset
   688
  val (((dts, (bn_funs, bn_eqs)), bclauses), _) = 
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   689
    thy
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   690
    |> prepare_dts dt_strs 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   691
    ||>> prepare_bn_funs bn_fun_strs bn_eq_strs 
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   692
    ||>> prepare_bclauses dt_strs
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   693
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   694
  val bclauses' = complete dt_strs bclauses
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   695
in
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   696
  nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses' lthy 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   697
end
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   698
*}
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   699
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   700
ML {* 
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   701
(* nominal datatype parser *)
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   702
local
3076
2b1b8404fe0d partially localised the parsing process using functions fron Datatype
Christian Urban <urbanc@in.tum.de>
parents: 3065
diff changeset
   703
  fun triple1 ((x, y), z) = (x, y, z)
3065
51ef8a3cb6ef updated to lates changes in the datatype package
Christian Urban <urbanc@in.tum.de>
parents: 3063
diff changeset
   704
  fun triple2 ((x, y), z) = (y, x, z)
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   705
  fun tuple2 (((x, y), z), u) = (x, y, u, z)
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   706
  fun tuple3 ((x, y), (z, u)) = (x, y, z, u)
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   707
in
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   708
3234
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   709
val opt_name = Scan.option (Parse.binding --| Args.colon)
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   710
3234
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   711
val anno_typ = Scan.option (Parse.name --| @{keyword "::"}) -- Parse.typ
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   712
3134
301b74fcd614 updated to new Isabelle (declared keywords)
Christian Urban <urbanc@in.tum.de>
parents: 3091
diff changeset
   713
val bind_mode = @{keyword "binds"} |--
3234
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   714
  Scan.optional (Args.parens 
2634
3ce1089cdbf3 changed res keyword to set+ for restrictions; comment by a referee
Christian Urban <urbanc@in.tum.de>
parents: 2633
diff changeset
   715
    (Args.$$$ "list" >> K Lst || (Args.$$$ "set" -- Args.$$$ "+") >> K Res || Args.$$$ "set" >> K Set)) Lst
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   716
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   717
val bind_clauses = 
3234
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   718
  Parse.enum "," (bind_mode -- Scan.repeat1 Parse.term -- (@{keyword "in"} |-- Scan.repeat1 Parse.name) >> triple1)
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   719
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   720
val cnstr_parser =
3234
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   721
  Parse.binding -- Scan.repeat anno_typ -- bind_clauses -- Parse.opt_mixfix >> tuple2
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   722
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   723
(* datatype parser *)
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   724
val dt_parser =
3234
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   725
  (Parse.type_args_constrained -- Parse.binding -- Parse.opt_mixfix >> triple2) -- 
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   726
    (@{keyword "="} |-- Parse.enum1 "|" cnstr_parser)
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   727
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   728
(* binding function parser *)
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   729
val bnfun_parser = 
3234
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   730
  Scan.optional (@{keyword "binder"} |-- Parse.fixes -- Parse_Spec.where_alt_specs) ([], [])
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   731
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   732
(* main parser *)
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   733
val main_parser =
3234
08c3ef07cef7 changes from upstream
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   734
  opt_name -- Parse.and_list1 dt_parser -- bnfun_parser >> tuple3
2424
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   735
621ebd8b13c4 changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents: 2411
diff changeset
   736
end
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   737
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   738
(* Command Keyword *)
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3236
diff changeset
   739
val _ = Outer_Syntax.local_theory @{command_keyword nominal_datatype}
3135
92b9b8d2888d updated to new Isabelle (20 March)
Christian Urban <urbanc@in.tum.de>
parents: 3134
diff changeset
   740
  "declaration of nominal datatypes" 
92b9b8d2888d updated to new Isabelle (20 March)
Christian Urban <urbanc@in.tum.de>
parents: 3134
diff changeset
   741
    (main_parser >> nominal_datatype2_cmd)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   742
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   743
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   744
end