Nominal/NewParser.thy
author Christian Urban <urbanc@in.tum.de>
Sat, 01 May 2010 09:15:46 +0100
changeset 2007 7ee9a2fefc77
parent 2006 2ceec1b4b015
parent 2001 7c8242a02f39
child 2008 1bddffddc03f
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory NewParser
1971
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
     2
imports "../Nominal-General/Nominal2_Base" 
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
        "../Nominal-General/Nominal2_Eqvt" 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
        "../Nominal-General/Nominal2_Supp" 
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
     5
        "Perm" "NewFv" "NewAlpha" "Tacs" "Equivp" "Lift"
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
begin
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
section{* Interface for nominal_datatype *}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
ML {* 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
(* nominal datatype parser *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
local
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  structure P = OuterParse;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  structure S = Scan
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  fun triple1 ((x, y), z) = (x, y, z)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  fun triple2 (x, (y, z)) = (x, y, z)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  fun tuple ((x, y, z), u) = (x, y, z, u)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  fun tswap (((x, y), z), u) = (x, y, u, z)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
val _ = OuterKeyword.keyword "bind"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
val _ = OuterKeyword.keyword "bind_set"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
val _ = OuterKeyword.keyword "bind_res"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
1943
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
    27
val anno_typ = S.option (P.name --| P.$$$ "::") -- P.typ
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
val bind_mode = P.$$$ "bind" || P.$$$ "bind_set" || P.$$$ "bind_res"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
val bind_clauses = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  P.enum "," (bind_mode -- S.repeat1 P.term -- (P.$$$ "in" |-- S.repeat1 P.name) >> triple1)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
val cnstr_parser =
1943
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
    35
  P.binding -- S.repeat anno_typ -- bind_clauses -- P.opt_mixfix >> tswap
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
(* datatype parser *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
val dt_parser =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  (P.type_args -- P.binding -- P.opt_mixfix >> triple1) -- 
1943
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
    40
    (P.$$$ "=" |-- P.enum1 "|" cnstr_parser) >> tuple
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
(* binding function parser *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
val bnfun_parser = 
1944
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    44
  S.optional (P.$$$ "binder" |-- P.fixes -- SpecParse.where_alt_specs) ([], [])
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
(* main parser *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
val main_parser =
1944
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    48
  P.and_list1 dt_parser -- bnfun_parser >> triple2
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
fun get_cnstrs dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  map (fn (_, _, _, constrs) => constrs) dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
fun get_typed_cnstrs dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  flat (map (fn (_, bn, _, constrs) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
   (map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
fun get_cnstr_strs dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
fun get_bn_fun_strs bn_funs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
ML {* 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
fun add_primrec_wrapper funs eqs lthy = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  if null funs then (([], []), lthy)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  else 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
   let 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
     val eqs' = map (fn (_, eq) => (Attrib.empty_binding, eq)) eqs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
     val funs' = map (fn (bn, ty, mx) => (bn, SOME ty, mx)) funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
   in 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
     Primrec.add_primrec funs' eqs' lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
   end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
fun add_datatype_wrapper dt_names dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  val conf = Datatype.default_config
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  Local_Theory.theory_result (Datatype.add_datatype conf dt_names dts)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
1944
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    89
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    90
text {* Infrastructure for adding "_raw" to types and terms *}
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
    91
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
fun add_raw s = s ^ "_raw"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
fun add_raws ss = map add_raw ss
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
fun raw_bind bn = Binding.suffix_name "_raw" bn
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
fun replace_str ss s = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  case (AList.lookup (op=) ss s) of 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
     SOME s' => s'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
   | NONE => s
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
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
   103
  | replace_typ ty_ss T = T  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
fun raw_dts ty_ss dts =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  fun raw_dts_aux1 (bind, tys, mx) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
    (raw_bind bind, map (replace_typ ty_ss) tys, mx)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  fun raw_dts_aux2 (ty_args, bind, mx, constrs) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
    (ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  map raw_dts_aux2 dts
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
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  | replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  | replace_aterm trm_ss trm = trm
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
fun replace_term trm_ss ty_ss trm =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
fun rawify_dts dt_names dts dts_env =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  val raw_dts = raw_dts dts_env dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  val raw_dt_names = add_raws dt_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  (raw_dt_names, raw_dts)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  val bn_funs' = map (fn (bn, ty, mx) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
    (raw_bind bn, replace_typ dts_env ty, mx)) bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  val bn_eqs' = map (fn (attr, trm) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
    (attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  (bn_funs', bn_eqs') 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
ML {* 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  fun rawify_bnds bnds = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
    map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  fun rawify_bclause (BEmy n) = BEmy n
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
    | rawify_bclause (BLst (bnds, bdys)) = BLst (rawify_bnds bnds, bdys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
    | rawify_bclause (BSet (bnds, bdys)) = BSet (rawify_bnds bnds, bdys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
    | rawify_bclause (BRes (bnds, bdys)) = BRes (rawify_bnds bnds, bdys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
  map (map (map rawify_bclause)) bclauses
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
1942
d3b89f6c086a added a comment about a function where I am not sure who wrote it.
Christian Urban <urbanc@in.tum.de>
parents: 1941
diff changeset
   162
text {* What does the prep_bn code do? Cezary's Function? *}
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
fun strip_bn_fun t =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  case t of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
    Const (@{const_name sup}, _) $ l $ r => strip_bn_fun l @ strip_bn_fun r
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
  | Const (@{const_name append}, _) $ l $ r => strip_bn_fun l @ strip_bn_fun r
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  | Const (@{const_name insert}, _) $ (Const (@{const_name atom}, _) $ Bound i) $ y =>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
      (i, NONE) :: strip_bn_fun y
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
  | Const (@{const_name Cons}, _) $ (Const (@{const_name atom}, _) $ Bound i) $ y =>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
      (i, NONE) :: strip_bn_fun y
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  | Const (@{const_name bot}, _) => []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
  | Const (@{const_name Nil}, _) => []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
  | (f as Free _) $ Bound i => [(i, SOME f)]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  | _ => error ("Unsupported binding function: " ^ (PolyML.makestring t))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
fun find [] _ = error ("cannot find element")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  | find ((x, z)::xs) y = if (Long_Name.base_name x) = y then z else find xs y
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
fun prep_bn dt_names dts eqs = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  fun aux eq = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
    val (lhs, rhs) = eq
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
      |> strip_qnt_body "all" 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
      |> HOLogic.dest_Trueprop
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
      |> HOLogic.dest_eq
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
    val (bn_fun, [cnstr]) = strip_comb lhs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
    val (_, ty) = dest_Free bn_fun
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
    val (ty_name, _) = dest_Type (domain_type ty)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
    val dt_index = find_index (fn x => x = ty_name) dt_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
    val (cnstr_head, cnstr_args) = strip_comb cnstr
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
    val rhs_elements = strip_bn_fun rhs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
    val included = map (apfst (fn i => length (cnstr_args) - i - 1)) rhs_elements
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
    (dt_index, (bn_fun, (cnstr_head, included)))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  fun order dts i ts = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
    val dt = nth dts i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
    val cts = map (fn (x, _, _) => Binding.name_of x) ((fn (_, _, _, x) => x) dt)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
    val ts' = map (fn (x, y) => (fst (dest_Const x), y)) ts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
    map (find ts') cts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  val unordered = AList.group (op=) (map aux eqs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  val unordered' = map (fn (x, y) =>  (x, AList.group (op=) y)) unordered
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
  val ordered = map (fn (x, y) => (x, map (fn (v, z) => (v, order dts x z)) y)) unordered' 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  ordered
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
fun raw_nominal_decls dts bn_funs bn_eqs binds lthy =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
  val thy = ProofContext.theory_of lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
  val thy_name = Context.theory_name thy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
  val dt_full_names = map (Long_Name.qualify thy_name) dt_names 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
  val dt_full_names' = add_raws dt_full_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  val dts_env = dt_full_names ~~ dt_full_names'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  val cnstrs = get_cnstr_strs dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
  val cnstrs_ty = get_typed_cnstrs dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
  val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
  val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
    (Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
  val bn_fun_strs = get_bn_fun_strs bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
  val bn_fun_strs' = add_raws bn_fun_strs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
  val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
  val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name)) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
    (bn_fun_strs ~~ bn_fun_strs')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
  val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
  val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
  val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env binds 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
  val raw_bns = prep_bn dt_full_names' raw_dts (map snd raw_bn_eqs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
  lthy 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
  |> add_datatype_wrapper raw_dt_names raw_dts 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  ||>> add_primrec_wrapper raw_bn_funs raw_bn_eqs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  ||>> pair raw_bclauses
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  ||>> pair raw_bns
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
fun nominal_datatype2 dts bn_funs bn_eqs bclauses lthy =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
let
1945
93e5a31ba230 added definition of raw-permutations to the new-parser
Christian Urban <urbanc@in.tum.de>
parents: 1944
diff changeset
   264
  val ((((raw_dt_names, (raw_bn_funs_loc, raw_bn_eqs_loc)), raw_bclauses), raw_bns), lthy1) =
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
    raw_nominal_decls dts bn_funs bn_eqs bclauses lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
1945
93e5a31ba230 added definition of raw-permutations to the new-parser
Christian Urban <urbanc@in.tum.de>
parents: 1944
diff changeset
   267
  val dtinfo = Datatype.the_info (ProofContext.theory_of lthy1) (hd raw_dt_names);
93e5a31ba230 added definition of raw-permutations to the new-parser
Christian Urban <urbanc@in.tum.de>
parents: 1944
diff changeset
   268
  val {descr, sorts, ...} = dtinfo;
2000
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   269
  fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i);
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   270
  val raw_tys = map (fn (i, _) => nth_dtyp i) descr;
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
   271
  val all_typs = map (fn i => typ_of_dtyp descr sorts (DtRec i)) (map fst descr)
1945
93e5a31ba230 added definition of raw-permutations to the new-parser
Christian Urban <urbanc@in.tum.de>
parents: 1944
diff changeset
   272
1999
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   273
  val all_full_tnames = map (fn (_, (n, _, _)) => n) descr;
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   274
  val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy1)) all_full_tnames;
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   275
  val inject = flat (map #inject dtinfos);
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   276
  val distincts = flat (map #distinct dtinfos);
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   277
  val rel_dtinfos = List.take (dtinfos, (length dts));
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   278
  val rel_distinct = map #distinct rel_dtinfos;
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   279
  val induct = #induct dtinfo;
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   280
  val exhausts = map #exhaust dtinfos;
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   281
1945
93e5a31ba230 added definition of raw-permutations to the new-parser
Christian Urban <urbanc@in.tum.de>
parents: 1944
diff changeset
   282
  val ((raw_perm_def, raw_perm_simps, perms), lthy2) =
93e5a31ba230 added definition of raw-permutations to the new-parser
Christian Urban <urbanc@in.tum.de>
parents: 1944
diff changeset
   283
    Local_Theory.theory_result (define_raw_perms dtinfo (length dts)) lthy1;
1960
47e2e91705f3 Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1945
diff changeset
   284
47e2e91705f3 Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1945
diff changeset
   285
  val morphism_2_0 = ProofContext.export_morphism lthy2 lthy
47e2e91705f3 Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1945
diff changeset
   286
  fun export_fun f (t, l) = (f t, map (map (apsnd (Option.map f))) l);
47e2e91705f3 Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1945
diff changeset
   287
  val raw_bns_exp = map (apsnd (map (export_fun (Morphism.term morphism_2_0)))) raw_bns;
47e2e91705f3 Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1945
diff changeset
   288
  val bn_funs_decls = flat (map (fn (ith, l) => map (fn (bn, data) => (bn, ith, data)) l) raw_bns_exp);
2000
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   289
  val raw_bn_eqs = ProofContext.export lthy2 lthy raw_bn_eqs_loc
1960
47e2e91705f3 Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1945
diff changeset
   290
  val thy = Local_Theory.exit_global lthy2;
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
   291
  val thy_name = Context.theory_name thy
1960
47e2e91705f3 Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1945
diff changeset
   292
  val lthy3 = Theory_Target.init NONE thy;
2000
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   293
  val raw_bn_funs = map (fn (f, _, _) => f) bn_funs_decls;
1960
47e2e91705f3 Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1945
diff changeset
   294
1999
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   295
  val ((fv, fvbn), fv_def, lthy3a) = define_raw_fv dtinfo bn_funs_decls raw_bclauses lthy3;
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   296
  val (((alpha_ts, alpha_intros), (alpha_cases, alpha_induct)), lthy4) =
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   297
    define_raw_alpha dtinfo bn_funs_decls raw_bclauses fv lthy3a;
4df3441aa0b4 more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1996
diff changeset
   298
  val (alpha_ts_nobn, alpha_ts_bn) = chop (length fv) alpha_ts
2000
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   299
  val dts_names = map (fn (i, (s, _, _)) => (s, i)) (#descr dtinfo);
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   300
  val bn_tys = map (domain_type o fastype_of) raw_bn_funs;
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   301
  val bn_nos = map (dtyp_no_of_typ dts_names) bn_tys;
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   302
  val bns = raw_bn_funs ~~ bn_nos;
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   303
  val rel_dists = flat (map (distinct_rel lthy4 alpha_cases)
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   304
    (rel_distinct ~~ alpha_ts_nobn));
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   305
  val rel_dists_bn = flat (map (distinct_rel lthy4 alpha_cases)
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   306
    ((map (fn i => nth rel_distinct i) bn_nos) ~~ alpha_ts_bn))
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   307
  val alpha_eq_iff = build_rel_inj alpha_intros (inject @ distincts) alpha_cases lthy4
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
   308
  val _ = warning "Proving equivariance";
2000
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   309
  val (bv_eqvt, lthy5) = prove_eqvt raw_tys induct (raw_bn_eqs @ raw_perm_def) (map fst bns) lthy4
f18b8e8a4909 Merged nominal_datatype into NewParser until eqvts
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1999
diff changeset
   310
  val (fv_eqvt, lthy6) = prove_eqvt raw_tys induct (fv_def @ raw_perm_def) (fv @ fvbn) lthy5
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
   311
  fun alpha_eqvt_tac' _ = Skip_Proof.cheat_tac thy
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
   312
  val alpha_eqvt = build_alpha_eqvts alpha_ts alpha_eqvt_tac' lthy6;
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
   313
  val _ = warning "Proving equivalence";
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
   314
  val fv_alpha_all = combine_fv_alpha_bns (fv, fvbn) (alpha_ts_nobn, alpha_ts_bn) bn_nos;
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
   315
  val reflps = build_alpha_refl fv_alpha_all alpha_ts induct alpha_eq_iff lthy6;
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
   316
  val alpha_equivp =
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
   317
    build_equivps alpha_ts reflps alpha_induct
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
   318
      inject alpha_eq_iff distincts alpha_cases alpha_eqvt lthy6;
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
   319
  val qty_binds = map (fn (_, b, _, _) => b) dts;
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
   320
  val qty_names = map Name.of_binding qty_binds;
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
   321
  val qty_full_names = map (Long_Name.qualify thy_name) qty_names
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
   322
  val (qtys, lthy7) = define_quotient_types qty_binds all_typs alpha_ts_nobn alpha_equivp lthy6;
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
   323
  val const_names = map Name.of_binding (flat (map (fn (_, _, _, t) => map (fn (b, _, _) => b) t) dts));
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
   324
  val raw_consts =
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
   325
    flat (map (fn (i, (_, _, l)) =>
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
   326
      map (fn (cname, dts) =>
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
   327
        Const (cname, map (typ_of_dtyp descr sorts) dts --->
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
   328
          typ_of_dtyp descr sorts (DtRec i))) l) descr);
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
   329
  val (consts, const_defs, lthy8) = quotient_lift_consts_export qtys (const_names ~~ raw_consts) lthy7;
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
   330
  val _ = warning "Proving respects";
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
   331
  val bns_rsp_pre' = build_fvbv_rsps alpha_ts alpha_induct raw_bn_eqs (map fst bns) lthy8;
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
   332
  val (bns_rsp_pre, lthy9) = fold_map (
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
   333
    fn (bn_t, _) => prove_const_rsp qtys Binding.empty [bn_t] (fn _ =>
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
   334
       resolve_tac bns_rsp_pre' 1)) bns lthy8;
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
   335
  val bns_rsp = flat (map snd bns_rsp_pre);
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
   336
  (*val _ = map tracing (map PolyML.makestring fv_alpha_all);*)
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
   337
  fun fv_rsp_tac _ = Skip_Proof.cheat_tac thy
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
   338
  val fv_rsps = prove_fv_rsp fv_alpha_all alpha_ts fv_rsp_tac lthy9;
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
   339
  val (fv_rsp_pre, lthy10) = fold_map
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
   340
    (fn fv => fn ctxt => prove_const_rsp qtys Binding.empty [fv]
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
   341
    (fn _ => asm_simp_tac (HOL_ss addsimps fv_rsps) 1) ctxt) (fv @ fvbn) lthy9;
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
   342
  val fv_rsp = flat (map snd fv_rsp_pre);
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
   343
  val (perms_rsp, lthy11) = prove_const_rsp qtys Binding.empty perms
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
   344
    (fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10;
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
   345
  val (alpha_bn_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst]
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
   346
        (fn _ => Skip_Proof.cheat_tac thy)) alpha_ts_bn lthy11
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
   347
  fun const_rsp_tac _ =
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
   348
    let val alpha_alphabn = prove_alpha_alphabn alpha_ts alpha_induct alpha_eq_iff alpha_ts_bn lthy11a
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
   349
      in constr_rsp_tac alpha_eq_iff (fv_rsp @ bns_rsp @ reflps @ alpha_alphabn) 1 end
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
   350
  val (const_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst]
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
   351
    const_rsp_tac) raw_consts lthy11a
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
   352
    val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) (fv @ fvbn)
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
   353
  val (qfv_ts, qfv_defs, lthy12a) = quotient_lift_consts_export qtys (qfv_names ~~ (fv @ fvbn)) lthy12;
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
   354
  val (qfv_ts_nobn, qfv_ts_bn) = chop (length perms) qfv_ts;
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
   355
  val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs
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
   356
  val (qbn_ts, qbn_defs, lthy12b) = quotient_lift_consts_export qtys (qbn_names ~~ raw_bn_funs) lthy12a;
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
   357
  val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_ts_bn
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
   358
  val (qalpha_ts_bn, qalphabn_defs, lthy12c) = quotient_lift_consts_export qtys (qalpha_bn_names ~~ alpha_ts_bn) lthy12b;
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
   359
  val _ = warning "Lifting permutations";
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
   360
  val thy = Local_Theory.exit_global lthy12c;
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
   361
  val perm_names = map (fn x => "permute_" ^ x) qty_names
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
   362
  val thy' = define_lifted_perms qtys qty_full_names (perm_names ~~ perms) raw_perm_simps thy;
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
   363
  val lthy13 = Theory_Target.init NONE thy';
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
   364
  val q_name = space_implode "_" qty_names;
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
   365
  fun suffix_bind s = Binding.qualify true q_name (Binding.name s);
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
   366
  val _ = warning "Lifting induction";
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
   367
  val constr_names = map (Long_Name.base_name o fst o dest_Const) consts;
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
   368
  val q_induct = Rule_Cases.name constr_names (lift_thm qtys lthy13 induct);
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
   369
  fun note_suffix s th ctxt =
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
   370
    snd (Local_Theory.note ((suffix_bind s, []), th) ctxt);
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
   371
  fun note_simp_suffix s th ctxt =
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
   372
    snd (Local_Theory.note ((suffix_bind s, [Attrib.internal (K Simplifier.simp_add)]), th) ctxt);
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
   373
  val (_, lthy14) = Local_Theory.note ((suffix_bind "induct",
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
   374
    [Attrib.internal (K (Rule_Cases.case_names constr_names))]), [Rule_Cases.name constr_names q_induct]) lthy13;
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
   375
  val q_inducts = Project_Rule.projects lthy13 (1 upto (length fv)) q_induct
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
   376
  val (_, lthy14a) = Local_Theory.note ((suffix_bind "inducts", []), q_inducts) lthy14;
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
   377
  val q_perm = map (lift_thm qtys lthy14) raw_perm_def;
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
   378
  val lthy15 = note_simp_suffix "perm" q_perm lthy14a;
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
   379
  val q_fv = map (lift_thm qtys lthy15) fv_def;
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
   380
  val lthy16 = note_simp_suffix "fv" q_fv lthy15;
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
   381
  val q_bn = map (lift_thm qtys lthy16) raw_bn_eqs;
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
   382
  val lthy17 = note_simp_suffix "bn" q_bn lthy16;
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
   383
  val _ = warning "Lifting eq-iff";
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
   384
  (*val _ = map tracing (map PolyML.makestring alpha_eq_iff);*)
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
   385
  val eq_iff_unfolded0 = map (Local_Defs.unfold lthy17 @{thms alphas3}) alpha_eq_iff
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
   386
  val eq_iff_unfolded1 = map (Local_Defs.unfold lthy17 @{thms alphas2}) eq_iff_unfolded0
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
   387
  val eq_iff_unfolded2 = map (Local_Defs.unfold lthy17 @{thms alphas} ) eq_iff_unfolded1
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
   388
  val q_eq_iff_pre0 = map (lift_thm qtys lthy17) eq_iff_unfolded2;
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
   389
  val q_eq_iff_pre1 = map (Local_Defs.fold lthy17 @{thms alphas3}) q_eq_iff_pre0
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
   390
  val q_eq_iff_pre2 = map (Local_Defs.fold lthy17 @{thms alphas2}) q_eq_iff_pre1
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
   391
  val q_eq_iff = map (Local_Defs.fold lthy17 @{thms alphas}) q_eq_iff_pre2
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
   392
  val (_, lthy18) = Local_Theory.note ((suffix_bind "eq_iff", []), q_eq_iff) lthy17;
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
   393
  val q_dis = map (lift_thm qtys lthy18) rel_dists;
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
   394
  val lthy19 = note_simp_suffix "distinct" q_dis lthy18;
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
   395
  val q_eqvt = map (lift_thm qtys lthy19) (bv_eqvt @ fv_eqvt);
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
   396
  val (_, lthy20) = Local_Theory.note ((Binding.empty,
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
   397
    [Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)]), q_eqvt) lthy19;
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
   398
  val _ = warning "Supports";
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
   399
  val supports = map (prove_supports lthy20 q_perm) consts;
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
   400
  val fin_supp = HOLogic.conj_elims (prove_fs lthy20 q_induct supports qtys);
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
   401
  val thy3 = Local_Theory.exit_global lthy20;
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
   402
  val _ = warning "Instantiating FS";
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
   403
  val lthy21 = Theory_Target.instantiation (qty_full_names, [], @{sort fs}) thy3;
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
   404
  fun tac _ = Class.intro_classes_tac [] THEN (ALLGOALS (resolve_tac fin_supp))
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
   405
  val lthy22 = Class.prove_instantiation_instance tac lthy21
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
   406
  val fv_alpha_all = combine_fv_alpha_bns (qfv_ts_nobn, qfv_ts_bn) (alpha_ts_nobn, qalpha_ts_bn) bn_nos;
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
   407
  val (names, supp_eq_t) = supp_eq fv_alpha_all;
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
   408
  val _ = warning "Support Equations";
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
   409
  val q_supp = HOLogic.conj_elims (Goal.prove lthy22 names [] supp_eq_t (fn _ => supp_eq_tac q_induct q_fv q_perm q_eq_iff lthy22 1)) handle _ => [];
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
   410
  val lthy23 = note_suffix "supp" q_supp lthy22;
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
in
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
   412
  (0, lthy23)
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
section {* Preparing and parsing of the specification *}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
ML {* 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
(* parsing the datatypes and declaring *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
(* constructors in the local theory    *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
fun prepare_dts dt_strs lthy = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
  val thy = ProofContext.theory_of lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
  fun mk_type full_tname tvrs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
    Type (full_tname, map (fn a => TVar ((a, 0), [])) tvrs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
  fun prep_cnstr full_tname tvs (cname, anno_tys, mx, _) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
    val tys = map (Syntax.read_typ lthy o snd) anno_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
    val ty = mk_type full_tname tvs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
    ((cname, tys ---> ty, mx), (cname, tys, mx))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
  fun prep_dt (tvs, tname, mx, cnstrs) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
    val full_tname = Sign.full_name thy tname
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
    val (cnstrs', cnstrs'') = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
      split_list (map (prep_cnstr full_tname tvs) cnstrs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
    (cnstrs', (tvs, tname, mx, cnstrs''))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
  end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
  val (cnstrs, dts) = split_list (map prep_dt dt_strs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
  lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
  |> Local_Theory.theory (Sign.add_consts_i (flat cnstrs))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
  |> pair dts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
(* parsing the binding function specification and *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
(* declaring the functions in the local theory    *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
fun prepare_bn_funs bn_fun_strs bn_eq_strs lthy =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
  val ((bn_funs, bn_eqs), _) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
    Specification.read_spec bn_fun_strs bn_eq_strs lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
  fun prep_bn_fun ((bn, T), mx) = (bn, T, mx) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
  val bn_funs' = map prep_bn_fun bn_funs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
  lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
  |> Local_Theory.theory (Sign.add_consts_i bn_funs')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   467
  |> pair (bn_funs', bn_eqs) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
end 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
text {* associates every SOME with the index in the list; drops NONEs *}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
fun indexify xs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
  fun mapp _ [] = []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
    | mapp i (NONE :: xs) = mapp (i + 1) xs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
    | mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
in 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
  mapp 0 xs 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
fun index_lookup xs x =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
  case AList.lookup (op=) xs x of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
    SOME x => x
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
  | NONE => error ("Cannot find " ^ x ^ " as argument annotation.");
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
fun prepare_bclauses dt_strs lthy = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
  val annos_bclauses =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
    get_cnstrs dt_strs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
    |> map (map (fn (_, antys, _, bns) => (map fst antys, bns)))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
  fun prep_binder env bn_str =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
    case (Syntax.read_term lthy bn_str) of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
      Free (x, _) => (NONE, index_lookup env x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
    | Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
    | _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   500
 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   501
  fun prep_body env bn_str = index_lookup env bn_str
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
  fun prep_mode "bind"     = BLst 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   504
    | prep_mode "bind_set" = BSet 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
    | prep_mode "bind_res" = BRes 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
  fun prep_bclause env (mode, binders, bodies) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
    val binders' = map (prep_binder env) binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
    val bodies' = map (prep_body env) bodies
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
  in  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
    prep_mode mode (binders', bodies')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
  fun prep_bclauses (annos, bclause_strs) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   516
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
    val env = indexify annos (* for every label, associate the index *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   518
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
    map (prep_bclause env) bclause_strs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
  map (map prep_bclauses) annos_bclauses
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
1943
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   526
text {* 
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   527
  adds an empty binding clause for every argument
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   528
  that is not already part of a binding clause
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   529
*}
48add8d4d7e5 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 1942
diff changeset
   530
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
fun included i bcs = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   534
  fun incl (BEmy j) = i = j
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
    | incl (BLst (bns, bds)) = (i mem (map snd bns)) orelse (i mem bds) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   536
    | incl (BSet (bns, bds)) = (i mem (map snd bns)) orelse (i mem bds) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   537
    | incl (BRes (bns, bds)) = (i mem (map snd bns)) orelse (i mem bds) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   538
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   539
  exists incl bcs 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   540
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   541
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
ML {* 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
fun complete dt_strs bclauses = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
  val args = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
    get_cnstrs dt_strs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
    |> map (map (fn (_, antys, _, _) => length antys))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   549
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   550
  fun complt n bcs = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   551
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   552
    fun add bcs i = (if included i bcs then [] else [BEmy i]) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   553
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   554
    bcs @ (flat (map_range (add bcs) n))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   555
  end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   556
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
  map2 (map2 complt) args bclauses
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   558
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   560
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   561
ML {*
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   562
fun nominal_datatype2_cmd (dt_strs, bn_fun_strs, bn_eq_strs) lthy = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   564
  fun prep_typ (tvs, tname, mx, _) = (tname, length tvs, mx)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   565
  val lthy0 = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   566
    Local_Theory.theory (Sign.add_types (map prep_typ dt_strs)) lthy
1944
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
   567
  val (dts, lthy1) = prepare_dts dt_strs lthy0
Christian Urban <urbanc@in.tum.de>
parents: 1943
diff changeset
   568
  val ((bn_funs, bn_eqs), lthy2) = prepare_bn_funs bn_fun_strs bn_eq_strs lthy1
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   569
  val bclauses = prepare_bclauses dt_strs lthy2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   570
  val bclauses' = complete dt_strs bclauses 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
  nominal_datatype2 dts bn_funs bn_eqs bclauses' lthy |> snd
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   573
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
(* Command Keyword *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   578
val _ = OuterSyntax.local_theory "nominal_datatype" "test" OuterKeyword.thy_decl
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
  (main_parser >> nominal_datatype2_cmd)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
*}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
1971
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   582
atom_decl name
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   583
1971
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   584
nominal_datatype lam =
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   585
  Var name
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   586
| App lam lam
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   587
| Lam x::name t::lam  bind_set x in t
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   588
| Let p::pt t::lam bind_set "bn p" in t
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   589
and pt =
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   590
  P1 name
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   591
| P2 pt pt
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   592
binder
1981
9f9c4965b608 Include support of unknown datatypes in new fv
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1971
diff changeset
   593
 bn::"pt \<Rightarrow> atom set"
1971
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   594
where
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   595
  "bn (P1 x) = {atom x}"
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   596
| "bn (P2 p1 p2) = bn p1 \<union> bn p2"
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   597
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
   598
thm lam_pt.bn
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
   599
thm lam_pt.fv[simplified lam_pt.supp(1-2)]
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
   600
thm lam_pt.eq_iff
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
   601
thm lam_pt.induct
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
   602
thm lam_pt.perm
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
nominal_datatype exp =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
  EVar name
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
| EUnit
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   607
| EPair q1::exp q2::exp
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
| ELetRec l::lrbs e::exp     bind "b_lrbs l" in e l
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   610
and fnclause =
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   611
  K x::name p::pat f::exp    bind_res "b_pat p" in f
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   612
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   613
and fnclauses =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   614
  S fnclause
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   615
| ORs fnclause fnclauses
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
and lrb =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
  Clause fnclauses
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
and lrbs =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
  Single lrb
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
| More lrb lrbs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   623
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
and pat =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
  PVar name
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
| PUnit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   627
| PPair pat pat
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   629
binder
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   630
  b_lrbs      :: "lrbs \<Rightarrow> atom list" and
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
  b_pat       :: "pat \<Rightarrow> atom set" and
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   632
  b_fnclauses :: "fnclauses \<Rightarrow> atom list" and
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   633
  b_fnclause  :: "fnclause \<Rightarrow> atom list" and
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   634
  b_lrb       :: "lrb \<Rightarrow> atom list"
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   635
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
  "b_lrbs (Single l) = b_lrb l"
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   638
| "b_lrbs (More l ls) = append (b_lrb l) (b_lrbs ls)"
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
| "b_pat (PVar x) = {atom x}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
| "b_pat (PUnit) = {}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
| "b_pat (PPair p1 p2) = b_pat p1 \<union> b_pat p2"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
| "b_fnclauses (S fc) = (b_fnclause fc)"
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   643
| "b_fnclauses (ORs fc fcs) = append (b_fnclause fc) (b_fnclauses fcs)"
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
| "b_lrb (Clause fcs) = (b_fnclauses fcs)"
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   645
| "b_fnclause (K x pat exp) = [atom x]"
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
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
   647
thm exp_fnclause_fnclauses_lrb_lrbs_pat.bn
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
   648
thm exp_fnclause_fnclauses_lrb_lrbs_pat.fv
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
   649
thm exp_fnclause_fnclauses_lrb_lrbs_pat.eq_iff
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
   650
thm exp_fnclause_fnclauses_lrb_lrbs_pat.induct
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
   651
thm exp_fnclause_fnclauses_lrb_lrbs_pat.perm
1945
93e5a31ba230 added definition of raw-permutations to the new-parser
Christian Urban <urbanc@in.tum.de>
parents: 1944
diff changeset
   652
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   653
nominal_datatype ty =
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
   654
  Vr "name"
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
   655
| Fn "ty" "ty"
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
   656
and tys =
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
   657
  Al xs::"name fset" t::"ty" bind_res xs in t
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
   658
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
   659
thm ty_tys.fv[simplified ty_tys.supp]
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
   660
thm ty_tys.eq_iff
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
   661
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
   662
(* some further tests *)
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
   663
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
   664
nominal_datatype ty =
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
   665
  Vr "name"
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
   666
| Fn "ty" "ty"
1988
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   667
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   668
nominal_datatype tys =
4444d52201dc Fixing the definitions in the Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1981
diff changeset
   669
  All xs::"name fset" ty::"ty_raw" bind_res xs in ty
1964
209ee65b2395 added some further problemetic tests
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   670
1971
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   671
nominal_datatype lam2 =
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   672
  Var2 "name"
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   673
| App2 "lam2" "lam2 list"
8daf6ff5e11a simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1970
diff changeset
   674
| Lam2 x::"name" t::"lam2" bind x in t
1964
209ee65b2395 added some further problemetic tests
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   675
209ee65b2395 added some further problemetic tests
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   676
1941
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   677
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   678
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   679
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   681
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682