Nominal/Nominal2.thy
author Christian Urban <urbanc@in.tum.de>
Tue, 28 Dec 2010 19:51:25 +0000
changeset 2630 8268b277d240
parent 2629 ffb5a181844b
child 2631 e73bd379e839
permissions -rw-r--r--
automated all strong induction lemmas
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 
2568
8193bbaa07fe merged Nominal-General directory into Nominal; renamed Abs.thy to Nominal2_Abs.thy
Christian Urban <urbanc@in.tum.de>
parents: 2566
diff changeset
     3
  Nominal2_Base Nominal2_Eqvt Nominal2_Abs
2598
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
     4
uses ("nominal_dt_rawfuns.ML")
2435
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
     5
     ("nominal_dt_alpha.ML")
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
     6
     ("nominal_dt_quot.ML")
2629
ffb5a181844b proper application of induction_schema and strong_exhaust rules; needs local fix in induction_schema.ML
Christian Urban <urbanc@in.tum.de>
parents: 2628
diff changeset
     7
     ("induction_schema.ML")
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
begin
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
2629
ffb5a181844b proper application of induction_schema and strong_exhaust rules; needs local fix in induction_schema.ML
Christian Urban <urbanc@in.tum.de>
parents: 2628
diff changeset
    10
use "induction_schema.ML"
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
    11
2435
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    12
use "nominal_dt_rawfuns.ML"
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    13
ML {* open Nominal_Dt_RawFuns *}
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    14
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    15
use "nominal_dt_alpha.ML"
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    16
ML {* open Nominal_Dt_Alpha *}
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    17
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    18
use "nominal_dt_quot.ML"
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    19
ML {* open Nominal_Dt_Quot *}
3772bb3bd7ce cleaning of unused files and code
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    20
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
    21
2603
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
    22
ML {*
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
    23
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
    24
val rsp_attr = Attrib.internal (K Quotient_Info.rsp_rules_add)
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
    25
val simp_attr = Attrib.internal (K Simplifier.simp_add)
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
    26
*}
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
    27
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
section{* Interface for nominal_datatype *}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
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
    30
ML {* print_depth 50 *}
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
fun get_cnstrs dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  map (fn (_, _, _, constrs) => constrs) dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
fun get_typed_cnstrs dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  flat (map (fn (_, bn, _, constrs) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
   (map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
fun get_cnstr_strs dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
fun get_bn_fun_strs bn_funs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
2106
409ecb7284dd properly exported defined bn-functions
Christian Urban <urbanc@in.tum.de>
parents: 2105
diff changeset
    47
1944
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    48
text {* Infrastructure for adding "_raw" to types and terms *}
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    49
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
fun add_raw s = s ^ "_raw"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
fun add_raws ss = map add_raw ss
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
fun raw_bind bn = Binding.suffix_name "_raw" bn
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
fun replace_str ss s = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  case (AList.lookup (op=) ss s) of 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
     SOME s' => s'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
   | NONE => s
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
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
    61
  | replace_typ ty_ss T = T  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
fun raw_dts ty_ss dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  fun raw_dts_aux1 (bind, tys, mx) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    (raw_bind bind, map (replace_typ ty_ss) tys, mx)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  fun raw_dts_aux2 (ty_args, bind, mx, constrs) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    (ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  map raw_dts_aux2 dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  | replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  | replace_aterm trm_ss trm = trm
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
fun replace_term trm_ss ty_ss trm =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
fun rawify_dts dt_names dts dts_env =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  val raw_dts = raw_dts dts_env dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  val raw_dt_names = add_raws dt_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  (raw_dt_names, raw_dts)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  val bn_funs' = map (fn (bn, ty, mx) => 
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
    96
    (raw_bind bn, SOME (replace_typ dts_env ty), mx)) bn_funs
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  val bn_eqs' = map (fn (attr, trm) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
    (attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  (bn_funs', bn_eqs') 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
end 
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_bclauses dts_env cnstrs_env bn_fun_env bclauses =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  fun rawify_bnds bnds = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
    map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
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
   111
  fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
in
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   113
  (map o map o map) rawify_bclause bclauses
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
*}
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 {*
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   119
fun define_raw_dts dts bn_funs bn_eqs bclauses lthy =
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   121
  val thy = Local_Theory.exit_global lthy
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  val thy_name = Context.theory_name thy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
  val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  val dt_full_names = map (Long_Name.qualify thy_name) dt_names 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  val dt_full_names' = add_raws dt_full_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  val dts_env = dt_full_names ~~ dt_full_names'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  val cnstrs = get_cnstr_strs dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  val cnstrs_ty = get_typed_cnstrs dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
    (Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
  val bn_fun_strs = get_bn_fun_strs bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  val bn_fun_strs' = add_raws bn_fun_strs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name)) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
    (bn_fun_strs ~~ bn_fun_strs')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  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
   144
  val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env bclauses 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   146
  val (raw_dt_full_names, thy1) = 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   147
    Datatype.add_datatype Datatype.default_config raw_dt_names raw_dts thy
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   148
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   149
  val lthy1 = Named_Target.theory_init thy1
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   150
in
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents: 2336
diff changeset
   151
  (raw_dt_full_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy1)
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   152
end
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   153
*}
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   154
2046
73c50e913db6 tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2037
diff changeset
   155
ML {*
73c50e913db6 tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2037
diff changeset
   156
(* for testing porposes - to exit the procedure early *)
73c50e913db6 tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2037
diff changeset
   157
exception TEST of Proof.context
73c50e913db6 tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2037
diff changeset
   158
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   159
val (STEPS, STEPS_setup) = Attrib.config_int "STEPS" (K 100);
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
   160
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
   161
fun get_STEPS ctxt = Config.get ctxt STEPS
2046
73c50e913db6 tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2037
diff changeset
   162
*}
2008
1bddffddc03f attempted to remove dependency on (old) Fv and (old) Parser; lifting still uses Fv.thy; the examples do not work at the moment (with equivp proofs failing)
Christian Urban <urbanc@in.tum.de>
parents: 2007
diff changeset
   163
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
   164
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
   165
setup STEPS_setup
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
   166
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
ML {*
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   168
fun nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses lthy =
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
let
2294
72ad4e766acf properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents: 2293
diff changeset
   170
  (* definition of the raw datatypes *)
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   171
  val _ = warning "Definition of raw datatypes";
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents: 2336
diff changeset
   172
  val (raw_dt_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy0) =
2308
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2306
diff changeset
   173
    if get_STEPS lthy > 0 
2410
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2409
diff changeset
   174
    then define_raw_dts dts bn_funs bn_eqs bclauses lthy
2046
73c50e913db6 tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2037
diff changeset
   175
    else raise TEST lthy
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2302
diff changeset
   177
  val dtinfo = Datatype.the_info (ProofContext.theory_of lthy0) (hd raw_dt_names)
2143
871d8a5e0c67 somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents: 2142
diff changeset
   178
  val {descr, sorts, ...} = dtinfo
2407
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2406
diff changeset
   179
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   180
  val raw_tys = all_dtyps descr sorts
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   181
  val raw_full_ty_names = map (fst o dest_Type) raw_tys
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   182
  val tvs = hd raw_tys
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   183
    |> snd o dest_Type
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   184
    |> map dest_TFree  
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   185
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   186
  val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) raw_full_ty_names  
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   187
 
2407
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2406
diff changeset
   188
  val raw_cns_info = all_dtyp_constrs_types descr sorts
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   189
  val raw_constrs = (map o map) (fn (c, _, _, _) => c) raw_cns_info
2407
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2406
diff changeset
   190
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   191
  val raw_inject_thms = flat (map #inject dtinfos)
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   192
  val raw_distinct_thms = flat (map #distinct dtinfos)
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   193
  val raw_induct_thm = #induct dtinfo
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   194
  val raw_induct_thms = #inducts dtinfo
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   195
  val raw_exhaust_thms = map #exhaust dtinfos
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   196
  val raw_size_trms = map HOLogic.size_const raw_tys
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   197
  val raw_size_thms = Size.size_thms (ProofContext.theory_of lthy0) (hd raw_dt_names)
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   198
    |> `(fn thms => (length thms) div 2)
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   199
    |> uncurry drop
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   200
  
2409
83990a42a068 more tuning of the code
Christian Urban <urbanc@in.tum.de>
parents: 2407
diff changeset
   201
  (* definitions of raw permutations by primitive recursion *)
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   202
  val _ = warning "Definition of raw permutations";
2401
7645e18e8b19 modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
parents: 2400
diff changeset
   203
  val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2a) =
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   204
    if get_STEPS lthy0 > 0 
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   205
    then define_raw_perms raw_full_ty_names raw_tys tvs (flat raw_constrs) raw_induct_thm lthy0
2308
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2306
diff changeset
   206
    else raise TEST lthy0
2144
e900526e95c4 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2143
diff changeset
   207
 
e900526e95c4 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2143
diff changeset
   208
  (* noting the raw permutations as eqvt theorems *)
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   209
  val (_, lthy3) = 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
   210
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   211
  (* definition of raw fv and bn functions *)
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   212
  val _ = warning "Definition of raw fv- and bn-functions";
2405
29ebbe56f450 also able to lift the bn_defs
Christian Urban <urbanc@in.tum.de>
parents: 2404
diff changeset
   213
  val (raw_bns, raw_bn_defs, raw_bn_info, raw_bn_induct, lthy3a) =
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   214
    if get_STEPS lthy3 > 1
2410
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2409
diff changeset
   215
    then define_raw_bns raw_full_ty_names raw_dts raw_bn_funs raw_bn_eqs 
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2409
diff changeset
   216
      (raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3
2046
73c50e913db6 tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2037
diff changeset
   217
    else raise TEST lthy3
2292
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   218
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   219
  (* defining the permute_bn functions *)
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   220
  val (raw_perm_bns, raw_perm_bn_simps, lthy3b) = 
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   221
    if get_STEPS lthy3a > 2
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   222
    then define_raw_bn_perms raw_tys raw_bn_info raw_cns_info 
2410
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2409
diff changeset
   223
      (raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3a
2308
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2306
diff changeset
   224
    else raise TEST lthy3a
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2306
diff changeset
   225
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   226
  val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3c) = 
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   227
    if get_STEPS lthy3b > 3 
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   228
    then define_raw_fvs raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses 
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   229
      (raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3b
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   230
    else raise TEST lthy3b
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   231
2011
12ce87b55f97 tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents: 2008
diff changeset
   232
  (* definition of raw alphas *)
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   233
  val _ = warning "Definition of alphas";
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   234
  val (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy4) =
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   235
    if get_STEPS lthy3c > 4 
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   236
    then define_raw_alpha raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses raw_fvs lthy3c
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   237
    else raise TEST lthy3c
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   238
  val alpha_tys = map (domain_type o fastype_of) alpha_trms  
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   239
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   240
  (* definition of alpha-distinct lemmas *)
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   241
  val _ = warning "Distinct theorems";
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   242
  val alpha_distincts = 
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   243
    mk_alpha_distincts lthy4 alpha_cases raw_distinct_thms alpha_trms raw_tys
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   244
2361
d73d4d151cce more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2346
diff changeset
   245
  (* definition of alpha_eq_iff  lemmas *)
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   246
  val _ = warning "Eq-iff theorems";
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
   247
  val alpha_eq_iff = 
2295
8aff3f3ce47f started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents: 2294
diff changeset
   248
    if get_STEPS lthy > 5
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   249
    then mk_alpha_eq_iff lthy4 alpha_intros raw_distinct_thms raw_inject_thms alpha_cases
2295
8aff3f3ce47f started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents: 2294
diff changeset
   250
    else raise TEST lthy4
2022
8ffede2c8ce9 Introduce eq_iff_simp to match the one from Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2020
diff changeset
   251
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   252
  (* proving equivariance lemmas for bns, fvs, size and alpha *)
2001
7c8242a02f39 NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2000
diff changeset
   253
  val _ = warning "Proving equivariance";
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
   254
  val raw_bn_eqvt = 
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   255
    if get_STEPS lthy > 6
2405
29ebbe56f450 also able to lift the bn_defs
Christian Urban <urbanc@in.tum.de>
parents: 2404
diff changeset
   256
    then raw_prove_eqvt raw_bns raw_bn_induct (raw_bn_defs @ raw_perm_simps) lthy4
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   257
    else raise TEST lthy4
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   258
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
   259
  (* 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
   260
  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
   261
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
   262
  val raw_fv_eqvt = 
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   263
    if get_STEPS lthy > 7
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   264
    then 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
   265
      (Local_Theory.restore lthy_tmp)
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   266
    else raise TEST lthy4
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   267
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2388
diff changeset
   268
  val raw_size_eqvt = 
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   269
    if get_STEPS lthy > 8
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   270
    then raw_prove_eqvt raw_size_trms raw_induct_thms (raw_size_thms @ raw_perm_simps) 
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   271
      (Local_Theory.restore lthy_tmp)
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2388
diff changeset
   272
      |> map (rewrite_rule @{thms permute_nat_def[THEN eq_reflection]})
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2388
diff changeset
   273
      |> map (fn thm => thm RS @{thm sym})
2305
93ab397f5980 smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   274
    else raise TEST lthy4
93ab397f5980 smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents: 2304
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
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   278
  val (alpha_eqvt, lthy6) =
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   279
    if get_STEPS lthy > 9
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   280
    then Nominal_Eqvt.equivariance true (alpha_trms @ alpha_bn_trms) alpha_induct alpha_intros lthy5
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   281
    else raise TEST lthy4
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   282
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   283
  (* proving alpha equivalence *)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   284
  val _ = warning "Proving equivalence"
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   285
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   286
  val alpha_refl_thms = 
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   287
    if get_STEPS lthy > 10
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   288
    then raw_prove_refl alpha_trms alpha_bn_trms alpha_intros raw_induct_thm lthy6 
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   289
    else raise TEST lthy6
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   290
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   291
  val alpha_sym_thms = 
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   292
    if get_STEPS lthy > 11
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   293
    then raw_prove_sym (alpha_trms @ alpha_bn_trms) alpha_intros alpha_induct lthy6 
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   294
    else raise TEST lthy6
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   295
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   296
  val alpha_trans_thms = 
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   297
    if get_STEPS lthy > 12
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   298
    then raw_prove_trans (alpha_trms @ alpha_bn_trms) (raw_distinct_thms @ raw_inject_thms) 
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   299
           alpha_intros alpha_induct alpha_cases lthy6
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   300
    else raise TEST lthy6
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2309
diff changeset
   301
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   302
  val (alpha_equivp_thms, alpha_bn_equivp_thms) = 
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   303
    if get_STEPS lthy > 13
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   304
    then raw_prove_equivp alpha_trms alpha_bn_trms alpha_refl_thms alpha_sym_thms 
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   305
       alpha_trans_thms lthy6
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   306
    else raise TEST lthy6
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2321
diff changeset
   307
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   308
  (* proving alpha implies alpha_bn *)
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   309
  val _ = warning "Proving alpha implies bn"
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   310
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   311
  val alpha_bn_imp_thms = 
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   312
    if get_STEPS lthy > 14
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   313
    then raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct lthy6 
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   314
    else raise TEST lthy6
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2321
diff changeset
   315
  
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2396
diff changeset
   316
  (* respectfulness proofs *)
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
   317
  val raw_funs_rsp_aux = 
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
    if get_STEPS lthy > 15
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   319
    then raw_fv_bn_rsp_aux alpha_trms alpha_bn_trms raw_fvs 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   320
      raw_bns raw_fv_bns alpha_induct (raw_bn_defs @ raw_fv_defs) lthy6
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   321
    else raise TEST lthy6 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   322
  
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 raw_funs_rsp = 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   324
    if get_STEPS lthy > 16
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   325
    then map mk_funs_rsp raw_funs_rsp_aux
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   326
    else raise TEST lthy6 
2388
ebf253d80670 equivariance for size
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   327
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
   328
  val raw_size_rsp = 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   329
    if get_STEPS lthy > 17
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   330
    then
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   331
      raw_size_rsp_aux (alpha_trms @ alpha_bn_trms) alpha_induct 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   332
      (raw_size_thms @ raw_size_eqvt) lthy6
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   333
      |> map mk_funs_rsp
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   334
    else raise TEST lthy6 
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   335
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
   336
  val raw_constrs_rsp = 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   337
    if get_STEPS lthy > 18
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   338
    then raw_constrs_rsp (flat raw_constrs) alpha_trms alpha_intros
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
   339
      (alpha_bn_imp_thms @ raw_funs_rsp_aux) lthy6 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   340
    else raise TEST lthy6 
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2396
diff changeset
   341
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
   342
  val alpha_permute_rsp = 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   343
    if get_STEPS lthy > 19
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   344
    then map mk_alpha_permute_rsp alpha_eqvt
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   345
    else raise TEST lthy6 
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   346
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
   347
  val alpha_bn_rsp = 
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2436
diff changeset
   348
    if get_STEPS lthy > 20
2440
0a36825b16c1 "isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
parents: 2438
diff changeset
   349
    then raw_alpha_bn_rsp alpha_bn_trms alpha_bn_equivp_thms alpha_bn_imp_thms
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
   350
    else raise TEST lthy6 
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   351
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   352
  val raw_perm_bn_rsp =
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   353
    if get_STEPS lthy > 21
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   354
    then raw_perm_bn_rsp (alpha_trms @ alpha_bn_trms) raw_perm_bns alpha_induct 
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   355
      alpha_intros raw_perm_bn_simps lthy6
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   356
    else raise TEST lthy6
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   357
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   358
  (* noting the quot_respects lemmas *)
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   359
  val (_, lthy6a) = 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   360
    if get_STEPS lthy > 22
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   361
    then Local_Theory.note ((Binding.empty, [rsp_attr]),
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   362
      raw_constrs_rsp @ raw_funs_rsp @ raw_size_rsp @ alpha_permute_rsp @ 
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   363
      alpha_bn_rsp @ raw_perm_bn_rsp) lthy6
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   364
    else raise TEST lthy6
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   365
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   366
  (* defining the quotient type *)
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   367
  val _ = warning "Declaring the quotient types"
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   368
  val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   369
     
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   370
  val (qty_infos, lthy7) = 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   371
    if get_STEPS lthy > 23
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   372
    then define_qtypes qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6a
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   373
    else raise TEST lthy6a
2336
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   374
f2d545b77b31 added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents: 2324
diff changeset
   375
  val qtys = map #qtyp qty_infos
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   376
  val qty_full_names = map (fst o dest_Type) qtys
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   377
  val qty_names = map Long_Name.base_name qty_full_names             
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   378
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   379
  (* defining of quotient term-constructors, binding functions, free vars functions *)
2378
2f13fe48c877 updated to new Isabelle; made FSet more "quiet"
Christian Urban <urbanc@in.tum.de>
parents: 2361
diff changeset
   380
  val _ = warning "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
   381
  val qconstrs_descrs =
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
   382
    (map2 o map2) (fn (b, _, mx) => fn t => (Name.of_binding b, t, mx)) (get_cnstrs dts) raw_constrs
2338
e1764a73c292 slight cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2337
diff changeset
   383
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   384
  val qbns_descr =
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   385
    map2 (fn (b, _, mx) => fn t => (Name.of_binding b, t, mx)) bn_funs raw_bns
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   386
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   387
  val qfvs_descr = 
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   388
    map2 (fn n => fn t => ("fv_" ^ n, t, NoSyn)) qty_names raw_fvs
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   389
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   390
  val qfv_bns_descr = 
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   391
    map2 (fn (b, _, _) => fn t => ("fv_" ^ Name.of_binding b, t, NoSyn)) bn_funs raw_fv_bns
2339
1e0b3992189c more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
   392
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   393
  val qalpha_bns_descr = 
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   394
    map2 (fn (b, _, _) => fn t => ("alpha_" ^ Name.of_binding b, t, NoSyn)) bn_funs  alpha_bn_trms
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   395
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   396
  val qperm_descr =
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   397
    map2 (fn n => fn t => ("permute_" ^ n, Type.legacy_freeze t, NoSyn)) qty_names raw_perm_funs
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   398
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   399
  val qsize_descr =
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   400
    map2 (fn n => fn t => ("size_" ^ n, t, NoSyn)) qty_names raw_size_trms
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   401
2562
e8ec504dddf2 lifted permute_bn constants
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   402
  val qperm_bn_descr = 
e8ec504dddf2 lifted permute_bn constants
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   403
    map2 (fn (b, _, _) => fn t => ("permute_" ^ Name.of_binding b, t, NoSyn)) bn_funs raw_perm_bns
e8ec504dddf2 lifted permute_bn constants
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   404
     
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   405
  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
   406
    lthy8) = 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   407
    if get_STEPS lthy > 24
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   408
    then 
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   409
      lthy7
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   410
      |> fold_map (define_qconsts qtys) qconstrs_descrs 
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   411
      ||>> define_qconsts qtys qbns_descr 
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   412
      ||>> define_qconsts qtys qfvs_descr
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   413
      ||>> define_qconsts qtys qfv_bns_descr
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   414
      ||>> define_qconsts qtys qalpha_bns_descr
2562
e8ec504dddf2 lifted permute_bn constants
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   415
      ||>> define_qconsts qtys qperm_bn_descr
2338
e1764a73c292 slight cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2337
diff changeset
   416
    else raise TEST lthy7
e1764a73c292 slight cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2337
diff changeset
   417
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   418
  (* definition of the quotient permfunctions and pt-class *)
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   419
  val lthy9 = 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   420
    if get_STEPS lthy > 25
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   421
    then define_qperms qtys qty_full_names tvs qperm_descr raw_perm_laws lthy8 
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   422
    else raise TEST lthy8
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   423
  
2401
7645e18e8b19 modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
parents: 2400
diff changeset
   424
  val lthy9a = 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   425
    if get_STEPS lthy > 26
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   426
    then define_qsizes qtys qty_full_names tvs qsize_descr lthy9
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   427
    else raise TEST lthy9
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   428
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   429
  val qtrms = (map o map) #qconst qconstrs_infos
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   430
  val qbns = map #qconst qbns_info
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   431
  val qfvs = map #qconst qfvs_info
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2339
diff changeset
   432
  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
   433
  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
   434
  val qperm_bns = map #qconst qperm_bns_info
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   435
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   436
  (* lifting of the theorems *)
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   437
  val _ = warning "Lifting of Theorems"
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   438
  
2559
add799cf0817 adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
parents: 2500
diff changeset
   439
  val eq_iff_simps = @{thms alphas permute_prod.simps prod_fv.simps prod_alpha_def prod_rel_def
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   440
    prod.cases} 
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   441
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   442
  val ((((((qdistincts, qeq_iffs), qfv_defs), qbn_defs), qperm_simps), qfv_qbn_eqvts), lthyA) = 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   443
    if get_STEPS lthy > 27
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   444
    then 
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   445
      lthy9a    
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   446
      |> lift_thms qtys [] alpha_distincts  
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   447
      ||>> lift_thms qtys eq_iff_simps alpha_eq_iff       
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   448
      ||>> lift_thms qtys [] raw_fv_defs
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   449
      ||>> lift_thms qtys [] raw_bn_defs
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   450
      ||>> lift_thms qtys [] raw_perm_simps
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   451
      ||>> lift_thms qtys [] (raw_fv_eqvt @ raw_bn_eqvt)
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   452
    else raise TEST lthy9a
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   453
2594
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   454
  val ((((((qsize_eqvt, [qinduct]), qexhausts), qsize_simps), qperm_bn_simps), qalpha_refl_thms), lthyB) = 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   455
    if get_STEPS lthy > 28
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   456
    then
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   457
      lthyA 
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   458
      |> lift_thms qtys [] raw_size_eqvt
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   459
      ||>> lift_thms qtys [] [raw_induct_thm]
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   460
      ||>> lift_thms qtys [] raw_exhaust_thms
2487
fbdaaa20396b lifted size_thms and exported them as <name>.size
Christian Urban <urbanc@in.tum.de>
parents: 2483
diff changeset
   461
      ||>> lift_thms qtys [] raw_size_thms
2563
7c8bfc35663a lifted permute_bn simp rules
Christian Urban <urbanc@in.tum.de>
parents: 2562
diff changeset
   462
      ||>> lift_thms qtys [] raw_perm_bn_simps
2594
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   463
      ||>> lift_thms qtys [] alpha_refl_thms
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   464
    else raise TEST lthyA
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2431
diff changeset
   465
2474
6e37bfb62474 generated inducts rule by Project_Rule.projections
Christian Urban <urbanc@in.tum.de>
parents: 2471
diff changeset
   466
  val qinducts = Project_Rule.projections lthyA qinduct
6e37bfb62474 generated inducts rule by Project_Rule.projections
Christian Urban <urbanc@in.tum.de>
parents: 2471
diff changeset
   467
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   468
  (* supports lemmas *) 
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
   469
  val _ = warning "Proving Supports Lemmas and fs-Instances"
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   470
  val qsupports_thms =
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   471
    if get_STEPS lthy > 29
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   472
    then prove_supports lthyB qperm_simps (flat qtrms)
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   473
    else raise TEST lthyB
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   474
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   475
  (* finite supp lemmas *)
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   476
  val qfsupp_thms =
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   477
    if get_STEPS lthy > 30
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   478
    then prove_fsupp lthyB qtys qinduct qsupports_thms
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   479
    else raise TEST lthyB
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   480
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   481
  (* fs instances *)
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   482
  val lthyC =
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   483
    if get_STEPS lthy > 31
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   484
    then fs_instance qtys qty_full_names tvs qfsupp_thms lthyB
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   485
    else raise TEST lthyB
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   486
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
   487
  (* fv - supp equality *)
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
   488
  val _ = warning "Proving Equality between fv and supp"
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
   489
  val qfv_supp_thms = 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   490
    if get_STEPS lthy > 32
2600
ca6b4bc7a871 kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
parents: 2598
diff changeset
   491
    then 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
   492
      qperm_simps qfv_qbn_eqvts qinduct (flat raw_bclauses) lthyC
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
   493
    else []
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
   494
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
   495
  (* 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
   496
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   497
  val qeq_iffs' = qeq_iffs
2493
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   498
    |> map (simplify (HOL_basic_ss addsimps qfv_supp_thms))
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   499
    |> map (simplify (HOL_basic_ss 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
   500
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   501
  val qsupp_constrs = qfv_defs
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   502
    |> map (simplify (HOL_basic_ss addsimps (take (length qfvs) qfv_supp_thms)))
5ac9a74d22fd post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
parents: 2487
diff changeset
   503
2493
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   504
  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
   505
  val transform_thms = 
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   506
    [ @{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
   507
      @{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
   508
      @{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
   509
      @{thm fresh_def[symmetric]}]
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   510
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   511
  val qfresh_constrs = qsupp_constrs
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   512
    |> map (fn thm => thm RS transform_thm) 
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   513
    |> map (simplify (HOL_basic_ss addsimps transform_thms))
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   514
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
   515
  (* proving that the qbn result is finite *)
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
   516
  val qbn_finite_thms =
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
   517
    if get_STEPS lthy > 33
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
   518
    then prove_bns_finite qtys qbns qinduct qbn_defs lthyC
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
    else []
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
   520
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
   521
  (* proving that perm_bns preserve alpha *)
2594
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   522
  val qperm_bn_alpha_thms = 
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   523
    if get_STEPS lthy > 33
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   524
    then prove_perm_bn_alpha_thms qtys qperm_bns qalpha_bns qinduct qperm_bn_simps qeq_iffs' 
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   525
      qalpha_refl_thms lthyC
515e5496171c automated alpha_perm_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   526
    else []
2493
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   527
2598
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   528
  (* proving the relationship of bn and permute_bn *)
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   529
  val qpermute_bn_thms = 
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   530
    if get_STEPS lthy > 33
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   531
    then prove_permute_bn_thms qtys qbns qperm_bns qinduct qperm_bn_simps qbn_defs qfv_qbn_eqvts lthyC
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   532
    else []
b136721eedb2 automated permute_bn theorems
Christian Urban <urbanc@in.tum.de>
parents: 2595
diff changeset
   533
2628
16ffbc8442ca generated goals for strong induction theorems.
Christian Urban <urbanc@in.tum.de>
parents: 2626
diff changeset
   534
  (* proving the strong exhausts and induct lemmas *)
2619
25fb0dbe9f13 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2618
diff changeset
   535
  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
   536
    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
   537
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2629
diff changeset
   538
  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
   539
2603
90779aefbf1a first tests about exhaust
Christian Urban <urbanc@in.tum.de>
parents: 2602
diff changeset
   540
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   541
  (* noting the theorems *)  
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   542
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   543
  (* generating the prefix for the theorem names *)
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   544
  val thms_name = 
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   545
    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
   546
  fun thms_suffix s = Binding.qualified true s thms_name 
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   547
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   548
  val (_, lthy9') = lthyC
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   549
     |> Local_Theory.note ((thms_suffix "distinct", []), qdistincts) 
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
   550
     ||>> Local_Theory.note ((thms_suffix "eq_iff", []), qeq_iffs')
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   551
     ||>> 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
   552
     ||>> Local_Theory.note ((thms_suffix "bn_defs", []), qbn_defs) 
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   553
     ||>> Local_Theory.note ((thms_suffix "perm_simps", [eqvt_attr, simp_attr]), qperm_simps) 
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   554
     ||>> Local_Theory.note ((thms_suffix "fv_bn_eqvt", []), qfv_qbn_eqvts) 
2487
fbdaaa20396b lifted size_thms and exported them as <name>.size
Christian Urban <urbanc@in.tum.de>
parents: 2483
diff changeset
   555
     ||>> Local_Theory.note ((thms_suffix "size", []), qsize_simps)
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   556
     ||>> Local_Theory.note ((thms_suffix "size_eqvt", []), qsize_eqvt)
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   557
     ||>> Local_Theory.note ((thms_suffix "induct", []), [qinduct]) 
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
   558
     ||>> Local_Theory.note ((thms_suffix "inducts", []), qinducts)
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   559
     ||>> Local_Theory.note ((thms_suffix "exhaust", []), qexhausts)
2617
e44551d067e6 properly exported strong exhaust theorem; cleaned up some examples
Christian Urban <urbanc@in.tum.de>
parents: 2616
diff changeset
   560
     ||>> Local_Theory.note ((thms_suffix "strong_exhaust", []), qstrong_exhaust_thms)
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2629
diff changeset
   561
     ||>> Local_Theory.note ((thms_suffix "strong_induct", []), qstrong_induct_thms)
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2440
diff changeset
   562
     ||>> 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
   563
     ||>> 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
   564
     ||>> Local_Theory.note ((thms_suffix "supp", []), qsupp_constrs)
2493
2e174807c891 added postprocessed fresh-lemmas for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2492
diff changeset
   565
     ||>> Local_Theory.note ((thms_suffix "fresh", []), qfresh_constrs)
2500
3b6a70e73006 worked example Foo1 with induct_schema
Christian Urban <urbanc@in.tum.de>
parents: 2493
diff changeset
   566
     ||>> Local_Theory.note ((thms_suffix "raw_alpha", []), alpha_intros)
2563
7c8bfc35663a lifted permute_bn simp rules
Christian Urban <urbanc@in.tum.de>
parents: 2562
diff changeset
   567
     ||>> 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
   568
     ||>> 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
   569
     ||>> 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
   570
     ||>> Local_Theory.note ((thms_suffix "permute_bn", []), qpermute_bn_thms)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
in
2601
89c55d36980f moved definition of raw bn-functions into nominal_dt_rawfuns
Christian Urban <urbanc@in.tum.de>
parents: 2600
diff changeset
   572
  lthy9'
89c55d36980f moved definition of raw bn-functions into nominal_dt_rawfuns
Christian Urban <urbanc@in.tum.de>
parents: 2600
diff changeset
   573
end handle TEST ctxt => ctxt
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
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
   576
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
section {* Preparing and parsing of the specification *}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   578
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
ML {* 
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   580
(* generates the parsed datatypes and 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   581
   declares the constructors 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   582
*)
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   583
fun prepare_dts dt_strs thy = 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   584
let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   585
  fun inter_fs_sort thy (a, S) = 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   586
    (a, Type.inter_sort (Sign.tsig_of thy) (@{sort fs}, S)) 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   587
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   588
  fun mk_type tname sorts (cname, cargs, mx) =
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   589
  let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   590
    val full_tname = Sign.full_name thy tname
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   591
    val ty = Type (full_tname, map (TFree o inter_fs_sort thy) sorts)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   592
  in
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   593
    (cname, cargs ---> ty, mx)
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   594
  end
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   595
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   596
  fun prep_constr (cname, cargs, mx, _) (constrs, sorts) =
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   597
  let 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   598
    val (cargs', sorts') = 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   599
      fold_map (Datatype.read_typ thy) (map snd cargs) sorts
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   600
      |>> map (map_type_tfree (TFree o inter_fs_sort thy)) 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   601
  in 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   602
    (constrs @ [(cname, cargs', mx)], sorts') 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
  
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   605
  fun prep_dts (tvs, tname, mx, constrs) (constr_trms, dts, sorts) =
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   606
  let 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   607
    val (constrs', sorts') = 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   608
      fold prep_constr constrs ([], sorts)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   610
    val constr_trms' = 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   611
      map (mk_type tname (rev sorts')) constrs'
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   612
  in 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   613
    (constr_trms @ constr_trms', dts @ [(tvs, tname, mx, constrs')], sorts') 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   614
  end
2425
715ab84065a0 nominal_datatypes with type variables do not work
Christian Urban <urbanc@in.tum.de>
parents: 2424
diff changeset
   615
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   616
  val (constr_trms, dts, sorts) = fold prep_dts dt_strs ([], [], []);
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
in
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   618
  thy
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   619
  |> Sign.add_consts_i constr_trms
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
  |> pair dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   623
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
(* parsing the binding function specification and *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
(* declaring the functions in the local theory    *)
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   627
fun prepare_bn_funs bn_fun_strs bn_eq_strs thy =
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   629
  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
   630
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   631
  val ((bn_funs, bn_eqs), lthy') = 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   632
    Specification.read_spec bn_fun_strs bn_eq_strs lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
  fun prep_bn_fun ((bn, T), mx) = (bn, T, mx) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   635
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
  val bn_funs' = map prep_bn_fun bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
in
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   638
  (Local_Theory.exit_global lthy')
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   639
  |> Sign.add_consts_i bn_funs'
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
  |> pair (bn_funs', bn_eqs) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
text {* associates every SOME with the index in the list; drops NONEs *}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
fun indexify xs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   648
  fun mapp _ [] = []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
    | mapp i (NONE :: xs) = mapp (i + 1) xs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
    | mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   651
in 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   652
  mapp 0 xs 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   653
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
fun index_lookup xs x =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   656
  case AList.lookup (op=) xs x of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   657
    SOME x => x
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   658
  | NONE => error ("Cannot find " ^ x ^ " as argument annotation.");
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   661
ML {*
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   662
fun prepare_bclauses dt_strs thy = 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
  val annos_bclauses =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
    get_cnstrs dt_strs
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   666
    |> (map o map) (fn (_, antys, _, bns) => (map fst antys, bns))
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   668
  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
   669
    case (Syntax.read_term_global thy bn_str) of
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
      Free (x, _) => (NONE, index_lookup env x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   671
    | Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   672
    | _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   673
 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
  fun prep_body env bn_str = index_lookup env bn_str
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   675
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
  fun prep_bclause env (mode, binders, bodies) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   677
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   678
    val binders' = map (prep_binder env) binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   679
    val bodies' = map (prep_body env) bodies
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
  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
   681
    BC (mode, binders', bodies')
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   683
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   684
  fun prep_bclauses (annos, bclause_strs) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   685
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   686
    val env = indexify annos (* for every label, associate the index *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   687
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   688
    map (prep_bclause env) bclause_strs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   689
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   690
in
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   691
  ((map o map) prep_bclauses annos_bclauses, thy)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   692
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   693
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   694
1943
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   695
text {* 
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   696
  adds an empty binding clause for every argument
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   697
  that is not already part of a binding clause
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   698
*}
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   699
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   700
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   701
fun included i bcs = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   702
let
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   703
  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
   704
    member (op =) (map snd bns) i orelse member (op =) bds i
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   705
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   706
  exists incl bcs 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   707
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   708
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   709
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   710
ML {* 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   711
fun complete dt_strs bclauses = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   712
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   713
  val args = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   714
    get_cnstrs dt_strs
2612
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
   715
    |> (map o map) (fn (_, antys, _, _) => length antys)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   716
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   717
  fun complt n bcs = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   718
  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
   719
    fun add bcs i = (if included i bcs then [] else [BC (Lst, [], [i])]) 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   720
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   721
    bcs @ (flat (map_range (add bcs) n))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   722
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   723
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
   724
  (map2 o map2) complt args bclauses
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   725
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   726
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   727
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   728
ML {*
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   729
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
   730
let
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   731
  val pre_typs = 
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   732
    map (fn (tvs, tname, mx, _) => (tname, length tvs, mx)) dt_strs
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   733
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   734
  (* this theory is used just for parsing *)
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   735
  val thy = ProofContext.theory_of lthy  
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   736
  val tmp_thy = Theory.copy thy 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   737
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   738
  val (((dts, (bn_funs, bn_eqs)), bclauses), tmp_thy') = 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   739
    tmp_thy
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   740
    |> Sign.add_types pre_typs
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   741
    |> 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
   742
    ||>> prepare_bn_funs bn_fun_strs bn_eq_strs 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   743
    ||>> prepare_bclauses dt_strs 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   744
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   745
  val bclauses' = complete dt_strs bclauses
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   746
in
2601
89c55d36980f moved definition of raw bn-functions into nominal_dt_rawfuns
Christian Urban <urbanc@in.tum.de>
parents: 2600
diff changeset
   747
  timeit (fn () => nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses' lthy)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   748
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
   749
*}
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   750
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
   751
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
   752
(* 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
   753
local
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
   754
  structure P = Parse;
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
   755
  structure S = Scan
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
   756
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   757
  fun triple ((x, y), z) = (x, y, z)
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   758
  fun tuple1 ((x, y, z), u) = (x, y, z, u)
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   759
  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
   760
  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
   761
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
   762
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
   763
val _ = Keyword.keyword "bind"
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   764
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   765
val opt_name = Scan.option (P.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
   766
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
   767
val anno_typ = S.option (P.name --| P.$$$ "::") -- P.typ
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
   768
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
   769
val bind_mode = P.$$$ "bind" |--
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
   770
  S.optional (Args.parens 
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   771
    (Args.$$$ "list" >> K Lst || Args.$$$ "set" >> K Set || Args.$$$ "res" >> K Res)) 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
   772
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
   773
val bind_clauses = 
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   774
  P.enum "," (bind_mode -- S.repeat1 P.term -- (P.$$$ "in" |-- S.repeat1 P.name) >> triple)
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
   775
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
   776
val cnstr_parser =
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   777
  P.binding -- S.repeat anno_typ -- bind_clauses -- P.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
   778
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
   779
(* 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
   780
val dt_parser =
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   781
  (P.type_args -- P.binding -- P.opt_mixfix >> triple) -- 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   782
    (P.$$$ "=" |-- P.enum1 "|" cnstr_parser) >> tuple1
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
   783
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
   784
(* 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
   785
val bnfun_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
   786
  S.optional (P.$$$ "binder" |-- P.fixes -- Parse_Spec.where_alt_specs) ([], [])
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
   787
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
   788
(* 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
   789
val main_parser =
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   790
  opt_name -- P.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
   791
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
   792
end
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   793
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   794
(* Command Keyword *)
2168
ce0255ffaeb4 Renamings
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2146
diff changeset
   795
val _ = Outer_Syntax.local_theory "nominal_datatype" "test" Keyword.thy_decl
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   796
  (main_parser >> nominal_datatype2_cmd)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   797
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   798
2292
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   799
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   800
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   801
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   802
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   803