Nominal/NewAlpha.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 24 Jun 2010 00:41:41 +0100
changeset 2334 0d10196364aa
parent 2303 c785fff02a8f
permissions -rw-r--r--
added comment about partial equivalence relations
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
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
     2
imports "Abs" "Perm"
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
begin
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
2073
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
     5
ML {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
     6
fun mk_prod_fv (t1, t2) =
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
     7
let
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
     8
  val ty1 = fastype_of t1
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
     9
  val ty2 = fastype_of t2 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    10
  val resT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2) --> @{typ "atom set"}
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    11
in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    12
  Const (@{const_name "prod_fv"}, [ty1, ty2] ---> resT) $ t1 $ t2
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    13
end
2073
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    14
*}
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    15
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 {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    17
fun mk_prod_alpha (t1, t2) =
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    18
let
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    19
  val ty1 = fastype_of t1
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    20
  val ty2 = fastype_of t2 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    21
  val prodT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    22
  val resT = [prodT, prodT] ---> @{typ "bool"}
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    23
in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    24
  Const (@{const_name "prod_alpha"}, [ty1, ty2] ---> resT) $ t1 $ t2
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    25
end
2073
2bfd5be8578a compound versions with prod_rel and prod_fun, not made default yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2010
diff changeset
    26
*}
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    28
ML {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    29
fun mk_binders lthy bmode args bodies = 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    30
let  
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    31
  fun bind_set lthy args (NONE, i) = setify lthy (nth args i)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    32
    | bind_set _ args (SOME bn, i) = bn $ (nth args i)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    33
  fun bind_lst lthy args (NONE, i) = listify lthy (nth args i)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    34
    | bind_lst _ args (SOME bn, i) = bn $ (nth args i)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    35
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    36
  val (connect_fn, bind_fn) =
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    37
    case bmode of
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    38
      Lst => (mk_append, bind_lst) 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    39
    | Set => (mk_union,  bind_set)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    40
    | Res => (mk_union,  bind_set)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    41
in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    42
  foldl1 connect_fn (map (bind_fn lthy args) bodies)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    43
end
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    44
*}
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    45
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    46
ML {* 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    47
fun mk_alpha_prem bmode fv alpha args args' binders binders' =
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
let
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    49
  val (alpha_name, binder_ty) = 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    50
    case bmode of
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    51
      Lst => (@{const_name "alpha_lst"}, @{typ "atom list"})
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    52
    | Set => (@{const_name "alpha_gen"}, @{typ "atom set"})
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    53
    | Res => (@{const_name "alpha_res"}, @{typ "atom set"})
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    54
  val ty = fastype_of args
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    55
  val pair_ty = HOLogic.mk_prodT (binder_ty, ty)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    56
  val alpha_ty = [ty, ty] ---> @{typ "bool"}
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    57
  val fv_ty = ty --> @{typ "atom set"}
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    58
in
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    59
  HOLogic.exists_const @{typ perm} $ Abs ("p", @{typ perm},
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    60
    Const (alpha_name, [pair_ty, alpha_ty, fv_ty, @{typ "perm"}, pair_ty] ---> @{typ bool}) 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    61
      $ HOLogic.mk_prod (binders, args) $ alpha $ fv $ (Bound 0) $ HOLogic.mk_prod (binders', args'))
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    62
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    63
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    64
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    65
ML {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    66
fun mk_alpha_bn_prem alpha_bn_map args args' bodies binder = 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    67
  case binder of
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    68
    (NONE, i) => []
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    69
  | (SOME bn, i) =>
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    70
     if member (op=) bodies i
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    71
     then [] 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    72
     else [the (AList.lookup (op=) alpha_bn_map bn) $ (nth args i) $ (nth args' i)]
1992
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
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
ML {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    76
fun mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause =
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    77
let
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    78
  fun mk_frees i =
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    79
    let
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    80
      val arg = nth args i
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    81
      val arg' = nth args' i
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    82
      val ty = fastype_of arg
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    83
    in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    84
      if nth is_rec i
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    85
      then fst (the (AList.lookup (op=) alpha_map ty)) $ arg $ arg'
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    86
      else HOLogic.mk_eq (arg, arg')
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    87
    end
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    88
  fun mk_alpha_fv i = 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    89
    let
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    90
      val ty = fastype_of (nth args i)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    91
    in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    92
      case AList.lookup (op=) alpha_map ty of
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    93
        NONE => (HOLogic.eq_const ty, supp_const ty) 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    94
      | SOME (alpha, fv) => (alpha, fv) 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    95
    end
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    96
  
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
in
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    98
  case bclause of
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
    99
    BC (_, [], bodies) => map (HOLogic.mk_Trueprop o mk_frees) bodies 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   100
  | BC (bmode, binders, bodies) => 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   101
    let
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   102
      val (alphas, fvs) = split_list (map mk_alpha_fv bodies)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   103
      val comp_fv = foldl1 mk_prod_fv fvs
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   104
      val comp_alpha = foldl1 mk_prod_alpha alphas
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   105
      val comp_args = foldl1 HOLogic.mk_prod (map (nth args) bodies)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   106
      val comp_args' = foldl1 HOLogic.mk_prod (map (nth args') bodies)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   107
      val comp_binders = mk_binders lthy bmode args binders
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   108
      val comp_binders' = mk_binders lthy bmode args' binders
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   109
      val alpha_prem = 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   110
        mk_alpha_prem bmode comp_fv comp_alpha comp_args comp_args' comp_binders comp_binders'
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   111
      val alpha_bn_prems = flat (map (mk_alpha_bn_prem alpha_bn_map args args' bodies) binders)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   112
    in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   113
      map HOLogic.mk_Trueprop (alpha_prem::alpha_bn_prems)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   114
    end
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   115
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   116
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   117
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   118
ML {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   119
fun mk_alpha_intros lthy alpha_map alpha_bn_map (constr, ty, arg_tys, is_rec) bclauses = 
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   120
let
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   121
  val arg_names = Datatype_Prop.make_tnames arg_tys
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   122
  val arg_names' = Name.variant_list arg_names arg_names
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   123
  val args = map Free (arg_names ~~ arg_tys)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   124
  val args' = map Free (arg_names' ~~ arg_tys)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   125
  val alpha = fst (the (AList.lookup (op=) alpha_map ty))
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   126
  val concl = HOLogic.mk_Trueprop (alpha $ list_comb (constr, args) $ list_comb (constr, args'))
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   127
  val prems = map (mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args')) bclauses
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   128
in
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   129
  Library.foldr Logic.mk_implies (flat prems, concl)
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   130
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   132
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   133
ML {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   134
fun mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args') bclause =
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   135
let
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   136
  fun mk_alpha_bn_prem alpha_map alpha_bn_map bn_args (args, args') i = 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   137
  let
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   138
    val arg = nth args i
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   139
    val arg' = nth args' i
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   140
    val ty = fastype_of arg
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   141
  in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   142
    case AList.lookup (op=) bn_args i of
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   143
      NONE => (case (AList.lookup (op=) alpha_map ty) of
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   144
                 NONE =>  [HOLogic.mk_eq (arg, arg')]
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   145
               | SOME (alpha, _) => [alpha $ arg $ arg'])
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   146
    | SOME (NONE) => []
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   147
    | SOME (SOME bn) => [the (AList.lookup (op=) alpha_bn_map bn) $ arg $ arg']
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   148
  end  
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   149
in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   150
  case bclause of
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   151
    BC (_, [], bodies) => 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   152
      map HOLogic.mk_Trueprop 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   153
        (flat (map (mk_alpha_bn_prem alpha_map alpha_bn_map bn_args (args, args')) bodies))
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   154
  | _ => mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   155
end
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   156
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   157
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   158
ML {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   159
fun mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map (bn_args, (constr, _, arg_tys, is_rec)) bclauses =
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   160
let
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   161
  val arg_names = Datatype_Prop.make_tnames arg_tys
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   162
  val arg_names' = Name.variant_list arg_names arg_names
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   163
  val args = map Free (arg_names ~~ arg_tys)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   164
  val args' = map Free (arg_names' ~~ arg_tys)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   165
  val alpha_bn = the (AList.lookup (op=) alpha_bn_map bn_trm)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   166
  val concl = HOLogic.mk_Trueprop (alpha_bn $ list_comb (constr, args) $ list_comb (constr, args'))
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   167
  val prems = map (mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args')) bclauses
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   168
in
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   169
  Library.foldr Logic.mk_implies (flat prems, concl)
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   170
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   171
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   172
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   173
ML {*
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   174
fun mk_alpha_bn_intros lthy alpha_map alpha_bn_map constrs_info bclausesss (bn_trm, bn_n, bn_argss) = 
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   175
let
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   176
  val nth_constrs_info = nth constrs_info bn_n
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   177
  val nth_bclausess = nth bclausesss bn_n
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   178
in
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   179
  map2 (mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map) (bn_argss ~~ nth_constrs_info) nth_bclausess
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   180
end
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   181
*}
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   182
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   183
ML {*
2297
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
   184
fun define_raw_alpha descr sorts bn_info bclausesss fvs lthy =
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   185
let
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   186
  val alpha_names = prefix_dt_names descr sorts "alpha_"
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   187
  val alpha_arg_tys = all_dtyps descr sorts
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   188
  val alpha_tys = map (fn ty => [ty, ty] ---> @{typ bool}) alpha_arg_tys
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   189
  val alpha_frees = map Free (alpha_names ~~ alpha_tys)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   190
  val alpha_map = alpha_arg_tys ~~ (alpha_frees ~~ fvs)
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   191
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   192
  val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   193
  val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   194
  val alpha_bn_names = map (prefix "alpha_") bn_names
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   195
  val alpha_bn_arg_tys = map (fn i => nth_dtyp descr sorts i) bn_tys
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   196
  val alpha_bn_tys = map (fn ty => [ty, ty] ---> @{typ "bool"}) alpha_bn_arg_tys
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   197
  val alpha_bn_frees = map Free (alpha_bn_names ~~ alpha_bn_tys)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   198
  val alpha_bn_map = bns ~~ alpha_bn_frees
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   199
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   200
  val constrs_info = all_dtyp_constrs_types descr sorts
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   201
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   202
  val alpha_intros = map2 (map2 (mk_alpha_intros lthy alpha_map alpha_bn_map)) constrs_info bclausesss 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   203
  val alpha_bn_intros = map (mk_alpha_bn_intros lthy alpha_map alpha_bn_map constrs_info bclausesss) bn_info
1992
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 all_alpha_names = map2 (fn s => fn ty => ((Binding.name s, ty), NoSyn))
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   206
    (alpha_names @ alpha_bn_names) (alpha_tys @ alpha_bn_tys)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   207
  val all_alpha_intros = map (pair Attrib.empty_binding) (flat alpha_intros @ flat alpha_bn_intros)
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   208
  
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   209
  val (alphas, lthy') = Inductive.add_inductive_i
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   210
     {quiet_mode = true, verbose = false, alt_name = Binding.empty,
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   211
      coind = false, no_elim = false, no_ind = false, skip_mono = true, fork_mono = false}
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   212
     all_alpha_names [] all_alpha_intros [] lthy
1996
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   213
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   214
  val alpha_trms_loc = #preds alphas;
2108
c5b7be27f105 Use raw_induct instead of induct
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2087
diff changeset
   215
  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
   216
  val alpha_intros_loc = #intrs alphas;
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   217
  val alpha_cases_loc = #elims alphas;
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   218
  val phi = ProofContext.export_morphism lthy' lthy;
1996
953f74f40727 Change signature of fv and alpha generation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1992
diff changeset
   219
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   220
  val alpha_trms = map (Morphism.term phi) alpha_trms_loc;
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   221
  val alpha_induct = Morphism.thm phi alpha_induct_loc;
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   222
  val alpha_intros = map (Morphism.thm phi) alpha_intros_loc
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   223
  val alpha_cases = map (Morphism.thm phi) alpha_cases_loc
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   224
in
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2295
diff changeset
   225
  (alpha_trms, alpha_intros, alpha_cases, alpha_induct, lthy')
1992
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   226
end
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   227
*}
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   228
e306247b5ce3 New Alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   229
end