Nominal/nominal_dt_alpha.ML
author Christian Urban <urbanc@in.tum.de>
Mon, 24 May 2010 21:11:33 +0100
changeset 2298 aead2aad845c
parent 2297 9ca7b249760e
child 2299 09bbed4f21d6
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(*  Title:      nominal_dt_alpha.ML
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
    Author:     Cezary Kaliszyk
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
    Author:     Christian Urban
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
  Definitions of the alpha relations.
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
*)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
signature NOMINAL_DT_ALPHA =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
sig
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  val define_raw_alpha: Datatype_Aux.descr -> (string * sort) list -> bn_info ->
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
    bclause list list list -> term list -> Proof.context -> 
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
    12
    term list * term list * thm list * thm list * thm * local_theory
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
structure Nominal_Dt_Alpha: NOMINAL_DT_ALPHA =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
struct
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
(* construct the compound terms for prod_fv and prod_alpha *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
fun mk_prod_fv (t1, t2) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  val ty1 = fastype_of t1
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  val ty2 = fastype_of t2 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  val resT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2) --> @{typ "atom set"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  Const (@{const_name "prod_fv"}, [ty1, ty2] ---> resT) $ t1 $ t2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
fun mk_prod_alpha (t1, t2) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  val ty1 = fastype_of t1
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  val ty2 = fastype_of t2 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  val prodT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  val resT = [prodT, prodT] ---> @{typ "bool"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  Const (@{const_name "prod_alpha"}, [ty1, ty2] ---> resT) $ t1 $ t2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
(* generates the compound binder terms *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
fun mk_binders lthy bmode args bodies = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
let  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  fun bind_set lthy args (NONE, i) = setify lthy (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
    | bind_set _ args (SOME bn, i) = bn $ (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  fun bind_lst lthy args (NONE, i) = listify lthy (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
    | bind_lst _ args (SOME bn, i) = bn $ (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  val (combine_fn, bind_fn) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
    case bmode of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
      Lst => (mk_append, bind_lst) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
    | Set => (mk_union,  bind_set)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
    | Res => (mk_union,  bind_set)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  foldl1 combine_fn (map (bind_fn lthy args) bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
(* produces the term for an alpha with abstraction *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
fun mk_alpha_term bmode fv alpha args args' binders binders' =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  val (alpha_name, binder_ty) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
    case bmode of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
      Lst => (@{const_name "alpha_lst"}, @{typ "atom list"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    | Set => (@{const_name "alpha_gen"}, @{typ "atom set"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    | Res => (@{const_name "alpha_res"}, @{typ "atom set"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  val ty = fastype_of args
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  val pair_ty = HOLogic.mk_prodT (binder_ty, ty)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  val alpha_ty = [ty, ty] ---> @{typ "bool"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  val fv_ty = ty --> @{typ "atom set"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  val pair_lhs = HOLogic.mk_prod (binders, args)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  val pair_rhs = HOLogic.mk_prod (binders', args')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  HOLogic.exists_const @{typ perm} $ Abs ("p", @{typ perm},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
    Const (alpha_name, [pair_ty, alpha_ty, fv_ty, @{typ "perm"}, pair_ty] ---> @{typ bool}) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
      $ pair_lhs $ alpha $ fv $ (Bound 0) $ pair_rhs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
(* for non-recursive binders we have to produce alpha_bn premises *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
fun mk_alpha_bn_prem alpha_bn_map args args' bodies binder = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  case binder of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    (NONE, _) => []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  | (SOME bn, i) =>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
     if member (op=) bodies i then [] 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
     else [the (AList.lookup (op=) alpha_bn_map bn) $ (nth args i) $ (nth args' i)]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
(* generat the premises for an alpha rule; mk_frees is used
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
   if no binders are present *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
fun mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  fun mk_frees i =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
      val arg = nth args i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
      val arg' = nth args' i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
      val ty = fastype_of arg
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
      if nth is_rec i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
      then fst (the (AList.lookup (op=) alpha_map ty)) $ arg $ arg'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
      else HOLogic.mk_eq (arg, arg')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
    end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  fun mk_alpha_fv i = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
      val ty = fastype_of (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
      case AList.lookup (op=) alpha_map ty of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
        NONE => (HOLogic.eq_const ty, supp_const ty) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
      | SOME (alpha, fv) => (alpha, fv) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
    end  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  case bclause of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
    BC (_, [], bodies) => map (HOLogic.mk_Trueprop o mk_frees) bodies 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  | BC (bmode, binders, bodies) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
      val (alphas, fvs) = split_list (map mk_alpha_fv bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
      val comp_fv = foldl1 mk_prod_fv fvs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
      val comp_alpha = foldl1 mk_prod_alpha alphas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
      val comp_args = foldl1 HOLogic.mk_prod (map (nth args) bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
      val comp_args' = foldl1 HOLogic.mk_prod (map (nth args') bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
      val comp_binders = mk_binders lthy bmode args binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
      val comp_binders' = mk_binders lthy bmode args' binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
      val alpha_prem = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
        mk_alpha_term bmode comp_fv comp_alpha comp_args comp_args' comp_binders comp_binders'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
      val alpha_bn_prems = flat (map (mk_alpha_bn_prem alpha_bn_map args args' bodies) binders)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
      map HOLogic.mk_Trueprop (alpha_prem::alpha_bn_prems)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
    end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
(* produces the introduction rule for an alpha rule *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
fun mk_alpha_intros lthy alpha_map alpha_bn_map (constr, ty, arg_tys, is_rec) bclauses = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  val arg_names = Datatype_Prop.make_tnames arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  val arg_names' = Name.variant_list arg_names arg_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  val args = map Free (arg_names ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  val args' = map Free (arg_names' ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  val alpha = fst (the (AList.lookup (op=) alpha_map ty))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  val concl = HOLogic.mk_Trueprop (alpha $ list_comb (constr, args) $ list_comb (constr, args'))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  val prems = map (mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args')) bclauses
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  Library.foldr Logic.mk_implies (flat prems, concl)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
(* produces the premise of an alpha-bn rule; we only need to
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
   treat the case special where the binding clause is empty;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
   - if the body is not included in the bn_info, then we either
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
     produce an equation or an alpha-premise
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
   - if the body is included in the bn_info, then we create
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
     either a recursive call to alpha-bn, or no premise  *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
fun mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args') bclause =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  fun mk_alpha_bn_prem alpha_map alpha_bn_map bn_args (args, args') i = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
    val arg = nth args i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
    val arg' = nth args' i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
    val ty = fastype_of arg
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
    case AList.lookup (op=) bn_args i of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
      NONE => (case (AList.lookup (op=) alpha_map ty) of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
                 NONE =>  [HOLogic.mk_eq (arg, arg')]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
               | SOME (alpha, _) => [alpha $ arg $ arg'])
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
    | SOME (NONE) => []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
    | SOME (SOME bn) => [the (AList.lookup (op=) alpha_bn_map bn) $ arg $ arg']
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  end  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
  case bclause of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
    BC (_, [], bodies) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
      map HOLogic.mk_Trueprop 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
        (flat (map (mk_alpha_bn_prem alpha_map alpha_bn_map bn_args (args, args')) bodies))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
  | _ => mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
fun mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map (bn_args, (constr, _, arg_tys, is_rec)) bclauses =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  val arg_names = Datatype_Prop.make_tnames arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
  val arg_names' = Name.variant_list arg_names arg_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
  val args = map Free (arg_names ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  val args' = map Free (arg_names' ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
  val alpha_bn = the (AList.lookup (op=) alpha_bn_map bn_trm)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
  val concl = HOLogic.mk_Trueprop (alpha_bn $ list_comb (constr, args) $ list_comb (constr, args'))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
  val prems = map (mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args')) bclauses
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  Library.foldr Logic.mk_implies (flat prems, concl)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
fun mk_alpha_bn_intros lthy alpha_map alpha_bn_map constrs_info bclausesss (bn_trm, bn_n, bn_argss) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  val nth_constrs_info = nth constrs_info bn_n
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  val nth_bclausess = nth bclausesss bn_n
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
  map2 (mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map) (bn_argss ~~ nth_constrs_info) nth_bclausess
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
fun define_raw_alpha descr sorts bn_info bclausesss fvs lthy =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  val alpha_names = prefix_dt_names descr sorts "alpha_"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
  val alpha_arg_tys = all_dtyps descr sorts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
  val alpha_tys = map (fn ty => [ty, ty] ---> @{typ bool}) alpha_arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
  val alpha_frees = map Free (alpha_names ~~ alpha_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
  val alpha_map = alpha_arg_tys ~~ (alpha_frees ~~ fvs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
  val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  val alpha_bn_names = map (prefix "alpha_") bn_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  val alpha_bn_arg_tys = map (fn i => nth_dtyp descr sorts i) bn_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
  val alpha_bn_tys = map (fn ty => [ty, ty] ---> @{typ "bool"}) alpha_bn_arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  val alpha_bn_frees = map Free (alpha_bn_names ~~ alpha_bn_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
  val alpha_bn_map = bns ~~ alpha_bn_frees
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
  val constrs_info = all_dtyp_constrs_types descr sorts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
  val alpha_intros = map2 (map2 (mk_alpha_intros lthy alpha_map alpha_bn_map)) constrs_info bclausesss 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
  val alpha_bn_intros = map (mk_alpha_bn_intros lthy alpha_map alpha_bn_map constrs_info bclausesss) bn_info
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  val all_alpha_names = map2 (fn s => fn ty => ((Binding.name s, ty), NoSyn))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
    (alpha_names @ alpha_bn_names) (alpha_tys @ alpha_bn_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
  val all_alpha_intros = map (pair Attrib.empty_binding) (flat alpha_intros @ flat alpha_bn_intros)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
  val (alphas, lthy') = Inductive.add_inductive_i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
     {quiet_mode = true, verbose = false, alt_name = Binding.empty,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
      coind = false, no_elim = false, no_ind = false, skip_mono = true, fork_mono = false}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
     all_alpha_names [] all_alpha_intros [] lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   222
  val all_alpha_trms_loc = #preds alphas;
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  val alpha_induct_loc = #raw_induct alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
  val alpha_intros_loc = #intrs alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
  val alpha_cases_loc = #elims alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
  val phi = ProofContext.export_morphism lthy' lthy;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   228
  val all_alpha_trms = map (Morphism.term phi) all_alpha_trms_loc;
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
  val alpha_induct = Morphism.thm phi alpha_induct_loc;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  val alpha_intros = map (Morphism.thm phi) alpha_intros_loc
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  val alpha_cases = map (Morphism.thm phi) alpha_cases_loc
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   232
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   233
  val (alpha_trms, alpha_bn_trms) = chop (length fvs) all_alpha_trms
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
in
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   235
  (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy')
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
end (* structure *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239