Nominal/NewAlpha.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 20 May 2010 21:35:00 +0100
changeset 2289 bf748be70109
parent 2288 3b83960f9544
child 2294 72ad4e766acf
permissions -rw-r--r--
moved some mk_union and mk_diff into the library
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
theory NewAlpha
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
     2
imports "Abs" "Perm" "Nominal2_FSet"
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
     3
uses ("nominal_dt_rawperm.ML")
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
     4
     ("nominal_dt_rawfuns.ML")
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     5
begin
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
     7
use "nominal_dt_rawperm.ML"
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
     8
use "nominal_dt_rawfuns.ML"
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
     9
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    10
ML {*
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    11
open Nominal_Dt_RawPerm
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    12
open Nominal_Dt_RawFuns
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    13
*}
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    14
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    15
2073
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    16
ML {*
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    17
fun mk_binop2 ctxt s (l, r) =
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    18
  Syntax.check_term ctxt (Const (s, dummyT) $ l $ r)
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    19
*}
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    20
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    21
ML {*
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    22
fun mk_compound_fv' ctxt = foldr1 (mk_binop2 ctxt @{const_name prod_fv})
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    23
fun mk_compound_alpha' ctxt = foldr1 (mk_binop2 ctxt @{const_name prod_rel})
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    24
*}
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    25
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    26
ML {*
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
fun alpha_bm_lsts lthy dt_descr sorts dts args args2 alpha_frees fv_frees
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    28
  bn_alphabn alpha_const binds bodys =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
let
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    30
  fun bind_set args (NONE, no) = setify lthy (nth args no)
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
    | bind_set args (SOME f, no) = f $ (nth args no)
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    32
  fun bind_lst args (NONE, no) = listify lthy (nth args no)
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    33
    | bind_lst args (SOME f, no) = f $ (nth args no)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    34
  fun append (t1, t2) =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
    Const(@{const_name append}, @{typ "atom list \<Rightarrow> atom list \<Rightarrow> atom list"}) $ t1 $ t2;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    36
  fun binds_fn args nos =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
    if alpha_const = @{const_name alpha_lst}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
    then foldr1 append (map (bind_lst args) nos)
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    39
    else fold_union (map (bind_set args) nos);
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
  val lhs_binds = binds_fn args binds;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
  val rhs_binds = binds_fn args2 binds;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    42
  val lhs_bodys = foldr1 HOLogic.mk_prod (map (nth args) bodys);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    43
  val rhs_bodys = foldr1 HOLogic.mk_prod (map (nth args2) bodys);
2010
19fe16dd36c2 replaced make_pair with library function HOLogic.mk_prod
Christian Urban <urbanc@in.tum.de>
parents: 1996
diff changeset
    44
  val lhs = HOLogic.mk_prod (lhs_binds, lhs_bodys);
19fe16dd36c2 replaced make_pair with library function HOLogic.mk_prod
Christian Urban <urbanc@in.tum.de>
parents: 1996
diff changeset
    45
  val rhs = HOLogic.mk_prod (rhs_binds, rhs_bodys);
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    46
  val body_dts = map (nth dts) bodys;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    47
  fun fv_for_dt dt =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
    if Datatype_Aux.is_rec_type dt
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
    then nth fv_frees (Datatype_Aux.body_index dt)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
    else Const (@{const_name supp},
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
      Datatype_Aux.typ_of_dtyp dt_descr sorts dt --> @{typ "atom set"})
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
  val fvs = map fv_for_dt body_dts;
2087
c861b53d0cde Use mk_compound_fv' and mk_compound_rel'
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2074
diff changeset
    53
  val fv = mk_compound_fv' lthy fvs;
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    54
  fun alpha_for_dt dt =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    55
    if Datatype_Aux.is_rec_type dt
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    56
    then nth alpha_frees (Datatype_Aux.body_index dt)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    57
    else Const (@{const_name "op ="},
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    58
      Datatype_Aux.typ_of_dtyp dt_descr sorts dt -->
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    59
      Datatype_Aux.typ_of_dtyp dt_descr sorts dt --> @{typ bool})
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    60
  val alphas = map alpha_for_dt body_dts;
2087
c861b53d0cde Use mk_compound_fv' and mk_compound_rel'
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2074
diff changeset
    61
  val alpha = mk_compound_alpha' lthy alphas;
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    62
  val alpha_gen_pre = Const (alpha_const, dummyT) $ lhs $ alpha $ fv $ (Bound 0) $ rhs
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    63
  val alpha_gen_ex = HOLogic.exists_const @{typ perm} $ Abs ("p", @{typ perm}, alpha_gen_pre)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    64
  val t = Syntax.check_term lthy alpha_gen_ex
2133
16834a4ca1bb Proper fv/alpha for multiple compound binders
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2108
diff changeset
    65
  fun alpha_bn_bind (SOME bn, i) =
16834a4ca1bb Proper fv/alpha for multiple compound binders
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2108
diff changeset
    66
      if member (op =) bodys i then NONE
16834a4ca1bb Proper fv/alpha for multiple compound binders
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2108
diff changeset
    67
      else SOME ((the (AList.lookup (op=) bn_alphabn bn)) $ nth args i $ nth args2 i)
16834a4ca1bb Proper fv/alpha for multiple compound binders
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2108
diff changeset
    68
    | alpha_bn_bind (NONE, _) = NONE
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
in
2133
16834a4ca1bb Proper fv/alpha for multiple compound binders
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2108
diff changeset
    70
  t :: (map_filter alpha_bn_bind binds)
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    71
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
ML {*
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
fun alpha_bn_bm lthy dt_descr sorts dts args args2 alpha_frees fv_frees bn_alphabn args_in_bn bm =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    76
case bm of
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    77
  BC (_, [], [i]) =>
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
    let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    79
      val arg = nth args i;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    80
      val arg2 = nth args2 i;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
      val dt = nth dts i;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    82
    in
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    83
      case AList.lookup (op=) args_in_bn i of
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84
        NONE => if Datatype_Aux.is_rec_type dt
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    85
                then [(nth alpha_frees (Datatype_Aux.body_index dt)) $ arg $ arg2]
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    86
                else [HOLogic.mk_eq (arg, arg2)]
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    87
      | SOME (SOME (f : term)) => [(the (AList.lookup (op=) bn_alphabn f)) $ arg $ arg2]
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    88
      | SOME NONE => []
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    89
    end
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    90
| BC (Lst, x, y) => alpha_bm_lsts lthy dt_descr sorts dts args args2 alpha_frees
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
    fv_frees bn_alphabn @{const_name alpha_lst} x y
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    92
| BC (Set, x, y) => alpha_bm_lsts lthy dt_descr sorts dts args args2 alpha_frees
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
    fv_frees bn_alphabn @{const_name alpha_gen} x y
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
    94
| BC (Res, x, y) => alpha_bm_lsts lthy dt_descr sorts dts args args2 alpha_frees
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    95
    fv_frees bn_alphabn @{const_name alpha_res} x y
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    96
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    98
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
ML {*
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   100
fun alpha_bn lthy dt_descr sorts alpha_frees fv_frees bn_alphabn bclausess
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
  (alphabn, (_, ith_dtyp, args_in_bns)) =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   102
let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
  fun alpha_bn_constr (cname, dts) (args_in_bn, bclauses) =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   104
  let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   105
    val Ts = map (Datatype_Aux.typ_of_dtyp dt_descr sorts) dts;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   106
    val names = Datatype_Prop.make_tnames Ts;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   107
    val names2 = Name.variant_list names (Datatype_Prop.make_tnames Ts);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   108
    val args = map Free (names ~~ Ts);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   109
    val args2 = map Free (names2 ~~ Ts);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   110
    val c = Const (cname, Ts ---> (nth_dtyp dt_descr sorts ith_dtyp));
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   111
    val alpha_bn_bm = alpha_bn_bm lthy dt_descr sorts dts args args2 alpha_frees
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   112
      fv_frees bn_alphabn args_in_bn;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   113
    val rhs = HOLogic.mk_Trueprop
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   114
      (alphabn $ (list_comb (c, args)) $ (list_comb (c, args2)));
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   115
    val lhss = map HOLogic.mk_Trueprop (flat (map alpha_bn_bm bclauses))
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   116
  in
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   117
    Library.foldr Logic.mk_implies (lhss, rhs)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   118
  end;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   119
  val (_, (_, _, constrs)) = nth dt_descr ith_dtyp;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   120
in
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   121
  map2 alpha_bn_constr constrs (args_in_bns ~~ bclausess)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   122
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   123
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   124
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   125
ML {*
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   126
fun alpha_bns lthy dt_descr sorts alpha_frees fv_frees bn_funs bclausesss =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   127
let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   128
  fun mk_alphabn_free (bn, ith, _) =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   129
    let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   130
      val alphabn_name = "alpha_" ^ (Long_Name.base_name (fst (dest_Const bn)));
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
      val ty = nth_dtyp dt_descr sorts ith;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   132
      val alphabn_type = ty --> ty --> @{typ bool};
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   133
      val alphabn_free = Free(alphabn_name, alphabn_type);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   134
    in
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   135
      (alphabn_name, alphabn_free)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   136
    end;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   137
  val (alphabn_names, alphabn_frees) = split_list (map mk_alphabn_free bn_funs);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   138
  val bn_alphabn = (map (fn (bn, _, _) => bn) bn_funs) ~~ alphabn_frees
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
  val bclausessl = map (fn (_, i, _) => nth bclausesss i) bn_funs;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   140
  val eqs = map2 (alpha_bn lthy dt_descr sorts alpha_frees fv_frees bn_alphabn) bclausessl
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   141
    (alphabn_frees ~~ bn_funs);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   142
in
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   143
  (bn_alphabn, alphabn_names, eqs)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   144
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   145
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   146
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   147
ML {*
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   148
fun alpha_bm lthy dt_descr sorts dts args args2 alpha_frees fv_frees bn_alphabn bm =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   149
case bm of
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
   150
  BC (_, [], [i]) =>
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   151
    let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   152
      val arg = nth args i;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   153
      val arg2 = nth args2 i;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   154
      val dt = nth dts i;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   155
    in
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   156
      if Datatype_Aux.is_rec_type dt
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   157
      then [(nth alpha_frees (Datatype_Aux.body_index dt)) $ arg $ arg2]
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   158
      else [HOLogic.mk_eq (arg, arg2)]
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   159
    end
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
   160
| BC (Lst, x, y) => alpha_bm_lsts lthy dt_descr sorts dts args args2 alpha_frees
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   161
    fv_frees bn_alphabn @{const_name alpha_lst} x y
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
   162
| BC (Set, x, y) => alpha_bm_lsts lthy dt_descr sorts dts args args2 alpha_frees
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   163
    fv_frees bn_alphabn @{const_name alpha_gen} x y
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2133
diff changeset
   164
| BC (Res, x, y) => alpha_bm_lsts lthy dt_descr sorts dts args args2 alpha_frees
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   165
    fv_frees bn_alphabn @{const_name alpha_res} x y
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   166
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   167
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   168
ML {*
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   169
fun alpha lthy dt_descr sorts alpha_frees fv_frees bn_alphabn bclausess (alpha_free, ith_dtyp) =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   170
let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   171
  fun alpha_constr (cname, dts) bclauses =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   172
  let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   173
    val Ts = map (Datatype_Aux.typ_of_dtyp dt_descr sorts) dts;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   174
    val names = Datatype_Prop.make_tnames Ts;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   175
    val names2 = Name.variant_list names (Datatype_Prop.make_tnames Ts);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   176
    val args = map Free (names ~~ Ts);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   177
    val args2 = map Free (names2 ~~ Ts);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
    val c = Const (cname, Ts ---> (nth_dtyp dt_descr sorts ith_dtyp));
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   179
    val alpha_bm = alpha_bm lthy dt_descr sorts dts args args2 alpha_frees fv_frees bn_alphabn
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   180
    val rhs = HOLogic.mk_Trueprop
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   181
      (alpha_free $ (list_comb (c, args)) $ (list_comb (c, args2)));
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   182
    val lhss = map HOLogic.mk_Trueprop (flat (map alpha_bm bclauses))
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   183
  in
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   184
    Library.foldr Logic.mk_implies (lhss, rhs)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   185
  end;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   186
  val (_, (_, _, constrs)) = nth dt_descr ith_dtyp;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   187
in
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   188
  map2 alpha_constr constrs bclausess
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   189
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   190
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   191
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   192
ML {*
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   193
fun define_raw_alpha (dt_info : Datatype_Aux.info) bn_funs bclausesss fv_frees lthy =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   194
let
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   195
  val {descr as dt_descr, sorts, ...} = dt_info;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   196
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   197
  val alpha_names = prefix_dt_names dt_descr sorts "alpha_";
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   198
  val alpha_types = map (fn (i, _) =>
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   199
    nth_dtyp dt_descr sorts i --> nth_dtyp dt_descr sorts i --> @{typ bool}) dt_descr;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   200
  val alpha_frees = map Free (alpha_names ~~ alpha_types);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   201
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   202
  val (bn_alphabn, alpha_bn_names, alpha_bn_eqs) =
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   203
    alpha_bns lthy dt_descr sorts alpha_frees fv_frees bn_funs bclausesss
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   204
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   205
  val alpha_bns = map snd bn_alphabn;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   206
  val alpha_bn_types = map fastype_of alpha_bns;
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   207
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   208
  val alpha_nums = 0 upto (length alpha_frees - 1)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   209
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   210
  val alpha_eqs = map2 (alpha lthy dt_descr sorts alpha_frees fv_frees bn_alphabn) bclausesss
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   211
    (alpha_frees ~~ alpha_nums);
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   212
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   213
  val all_alpha_names = map2 (fn s => fn ty => ((Binding.name s, ty), NoSyn))
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   214
    (alpha_names @ alpha_bn_names) (alpha_types @ alpha_bn_types)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   215
  val all_alpha_eqs = map (pair Attrib.empty_binding) (flat alpha_eqs @ flat alpha_bn_eqs)
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   216
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   217
  val (alphas, lthy') = Inductive.add_inductive_i
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
     {quiet_mode = true, verbose = false, alt_name = Binding.empty,
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   219
      coind = false, no_elim = false, no_ind = false, skip_mono = true, fork_mono = false}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   220
     all_alpha_names [] all_alpha_eqs [] lthy
1996
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   221
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   222
  val alpha_ts_loc = #preds alphas;
2108
c5b7be27f105 Use raw_induct instead of induct
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2087
diff changeset
   223
  val alpha_induct_loc = #raw_induct alphas;
1996
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   224
  val alpha_intros_loc = #intrs alphas;
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   225
  val alpha_cases_loc = #elims alphas;
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   226
  val morphism = ProofContext.export_morphism lthy' lthy;
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   227
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   228
  val alpha_ts = map (Morphism.term morphism) alpha_ts_loc;
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   229
  val alpha_induct = Morphism.thm morphism alpha_induct_loc;
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   230
  val alpha_intros = Morphism.fact morphism alpha_intros_loc
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   231
  val alpha_cases = Morphism.fact morphism alpha_cases_loc
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   232
in
1996
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   233
  (((alpha_ts, alpha_intros), (alpha_cases, alpha_induct)), lthy')
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   234
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   235
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   236
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   237
end