Nominal/nominal_dt_alpha.ML
author Christian Urban <urbanc@in.tum.de>
Fri, 11 Jun 2010 03:02:42 +0200
changeset 2316 08bbde090a17
parent 2314 1a14c4171a51
child 2320 d835a2771608
permissions -rw-r--r--
also symmetry
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
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
     5
  Definitions and proofs for the alpha-relations.
2297
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
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    13
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    14
  val mk_alpha_distincts: Proof.context -> thm list -> thm list list -> 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    15
    term list -> term list -> bn_info -> thm list * thm list
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    16
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    17
  val mk_alpha_eq_iff: Proof.context -> thm list -> thm list -> thm list -> thm list -> thm list
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
    18
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
    19
  val raw_prove_refl: term list -> term list -> thm list -> thm -> Proof.context -> thm list
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
    20
  val raw_prove_sym: term list -> thm list -> thm -> Proof.context -> thm list
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
    21
  val raw_prove_trans: term list -> thm list -> thm list -> thm -> thm list -> Proof.context -> thm list
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
structure Nominal_Dt_Alpha: NOMINAL_DT_ALPHA =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
struct
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    27
(** definition of the inductive rules for alpha and alpha_bn **)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    28
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
(* construct the compound terms for prod_fv and prod_alpha *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
fun mk_prod_fv (t1, t2) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  val ty1 = fastype_of t1
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  val ty2 = fastype_of t2 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  val resT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2) --> @{typ "atom set"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  Const (@{const_name "prod_fv"}, [ty1, ty2] ---> resT) $ t1 $ t2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
fun mk_prod_alpha (t1, t2) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  val ty1 = fastype_of t1
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  val ty2 = fastype_of t2 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  val prodT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  val resT = [prodT, prodT] ---> @{typ "bool"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  Const (@{const_name "prod_alpha"}, [ty1, ty2] ---> resT) $ t1 $ t2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
(* generates the compound binder terms *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
fun mk_binders lthy bmode args bodies = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
let  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  fun bind_set lthy args (NONE, i) = setify lthy (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
    | bind_set _ args (SOME bn, i) = bn $ (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  fun bind_lst lthy args (NONE, i) = listify lthy (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    | bind_lst _ args (SOME bn, i) = bn $ (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  val (combine_fn, bind_fn) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
    case bmode of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
      Lst => (mk_append, bind_lst) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
    | Set => (mk_union,  bind_set)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
    | Res => (mk_union,  bind_set)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  foldl1 combine_fn (map (bind_fn lthy args) bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
(* produces the term for an alpha with abstraction *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
fun mk_alpha_term bmode fv alpha args args' binders binders' =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  val (alpha_name, binder_ty) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
    case bmode of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
      Lst => (@{const_name "alpha_lst"}, @{typ "atom list"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
    | Set => (@{const_name "alpha_gen"}, @{typ "atom set"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    | Res => (@{const_name "alpha_res"}, @{typ "atom set"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  val ty = fastype_of args
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  val pair_ty = HOLogic.mk_prodT (binder_ty, ty)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  val alpha_ty = [ty, ty] ---> @{typ "bool"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  val fv_ty = ty --> @{typ "atom set"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  val pair_lhs = HOLogic.mk_prod (binders, args)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  val pair_rhs = HOLogic.mk_prod (binders', args')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  HOLogic.exists_const @{typ perm} $ Abs ("p", @{typ perm},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
    Const (alpha_name, [pair_ty, alpha_ty, fv_ty, @{typ "perm"}, pair_ty] ---> @{typ bool}) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
      $ pair_lhs $ alpha $ fv $ (Bound 0) $ pair_rhs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
(* for non-recursive binders we have to produce alpha_bn premises *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
fun mk_alpha_bn_prem alpha_bn_map args args' bodies binder = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  case binder of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
    (NONE, _) => []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  | (SOME bn, i) =>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
     if member (op=) bodies i then [] 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
     else [the (AList.lookup (op=) alpha_bn_map bn) $ (nth args i) $ (nth args' i)]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
(* generat the premises for an alpha rule; mk_frees is used
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
   if no binders are present *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
fun mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  fun mk_frees i =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
      val arg = nth args i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
      val arg' = nth args' i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
      val ty = fastype_of arg
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
      if nth is_rec i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
      then fst (the (AList.lookup (op=) alpha_map ty)) $ arg $ arg'
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
      else HOLogic.mk_eq (arg, arg')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
    end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  fun mk_alpha_fv i = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
      val ty = fastype_of (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
      case AList.lookup (op=) alpha_map ty of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
        NONE => (HOLogic.eq_const ty, supp_const ty) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
      | SOME (alpha, fv) => (alpha, fv) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
    end  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  case bclause of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
    BC (_, [], bodies) => map (HOLogic.mk_Trueprop o mk_frees) bodies 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  | BC (bmode, binders, bodies) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
      val (alphas, fvs) = split_list (map mk_alpha_fv bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
      val comp_fv = foldl1 mk_prod_fv fvs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
      val comp_alpha = foldl1 mk_prod_alpha alphas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
      val comp_args = foldl1 HOLogic.mk_prod (map (nth args) bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
      val comp_args' = foldl1 HOLogic.mk_prod (map (nth args') bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
      val comp_binders = mk_binders lthy bmode args binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
      val comp_binders' = mk_binders lthy bmode args' binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
      val alpha_prem = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
        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
   131
      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
   132
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
      map HOLogic.mk_Trueprop (alpha_prem::alpha_bn_prems)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
    end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
(* produces the introduction rule for an alpha rule *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
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
   139
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  val arg_names = Datatype_Prop.make_tnames arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  val arg_names' = Name.variant_list arg_names arg_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  val args = map Free (arg_names ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  val args' = map Free (arg_names' ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  val alpha = fst (the (AList.lookup (op=) alpha_map ty))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
  val concl = HOLogic.mk_Trueprop (alpha $ list_comb (constr, args) $ list_comb (constr, args'))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  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
   147
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  Library.foldr Logic.mk_implies (flat prems, concl)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
(* produces the premise of an alpha-bn rule; we only need to
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
   treat the case special where the binding clause is empty;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
   - if the body is not included in the bn_info, then we either
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
     produce an equation or an alpha-premise
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
   - if the body is included in the bn_info, then we create
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
     either a recursive call to alpha-bn, or no premise  *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
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
   160
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
  fun mk_alpha_bn_prem alpha_map alpha_bn_map bn_args (args, args') i = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
    val arg = nth args i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
    val arg' = nth args' i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
    val ty = fastype_of arg
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
    case AList.lookup (op=) bn_args i of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
      NONE => (case (AList.lookup (op=) alpha_map ty) of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
                 NONE =>  [HOLogic.mk_eq (arg, arg')]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
               | SOME (alpha, _) => [alpha $ arg $ arg'])
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
    | SOME (NONE) => []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
    | SOME (SOME bn) => [the (AList.lookup (op=) alpha_bn_map bn) $ arg $ arg']
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  end  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
  case bclause of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
    BC (_, [], bodies) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
      map HOLogic.mk_Trueprop 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
        (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
   179
  | _ => mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
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
   183
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  val arg_names = Datatype_Prop.make_tnames arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  val arg_names' = Name.variant_list arg_names arg_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  val args = map Free (arg_names ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  val args' = map Free (arg_names' ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
  val alpha_bn = the (AList.lookup (op=) alpha_bn_map bn_trm)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
  val concl = HOLogic.mk_Trueprop (alpha_bn $ list_comb (constr, args) $ list_comb (constr, args'))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
  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
   191
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
  Library.foldr Logic.mk_implies (flat prems, concl)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
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
   196
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
  val nth_constrs_info = nth constrs_info bn_n
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
  val nth_bclausess = nth bclausesss bn_n
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  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
   201
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
fun define_raw_alpha descr sorts bn_info bclausesss fvs lthy =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  val alpha_names = prefix_dt_names descr sorts "alpha_"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
  val alpha_arg_tys = all_dtyps descr sorts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
  val alpha_tys = map (fn ty => [ty, ty] ---> @{typ bool}) alpha_arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
  val alpha_frees = map Free (alpha_names ~~ alpha_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
  val alpha_map = alpha_arg_tys ~~ (alpha_frees ~~ fvs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
  val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  val alpha_bn_names = map (prefix "alpha_") bn_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
  val alpha_bn_arg_tys = map (fn i => nth_dtyp descr sorts i) bn_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
  val alpha_bn_tys = map (fn ty => [ty, ty] ---> @{typ "bool"}) alpha_bn_arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  val alpha_bn_frees = map Free (alpha_bn_names ~~ alpha_bn_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
  val alpha_bn_map = bns ~~ alpha_bn_frees
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  val constrs_info = all_dtyp_constrs_types descr sorts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
  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
   222
  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
   223
2299
09bbed4f21d6 added slides
Christian Urban <urbanc@in.tum.de>
parents: 2298
diff changeset
   224
  val all_alpha_names = map (fn (a, ty) => ((Binding.name a, ty), NoSyn))
09bbed4f21d6 added slides
Christian Urban <urbanc@in.tum.de>
parents: 2298
diff changeset
   225
    (alpha_names @ alpha_bn_names ~~ alpha_tys @ alpha_bn_tys)
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
  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
   227
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
  val (alphas, lthy') = Inductive.add_inductive_i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
     {quiet_mode = true, verbose = false, alt_name = Binding.empty,
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   230
      coind = false, no_elim = false, no_ind = false, skip_mono = false, fork_mono = false}
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
     all_alpha_names [] all_alpha_intros [] lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   233
  val all_alpha_trms_loc = #preds alphas;
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
  val alpha_induct_loc = #raw_induct alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
  val alpha_intros_loc = #intrs alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
  val alpha_cases_loc = #elims alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  val phi = ProofContext.export_morphism lthy' lthy;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   239
  val all_alpha_trms = map (Morphism.term phi) all_alpha_trms_loc;
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
  val alpha_induct = Morphism.thm phi alpha_induct_loc;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
  val alpha_intros = map (Morphism.thm phi) alpha_intros_loc
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
  val alpha_cases = map (Morphism.thm phi) alpha_cases_loc
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   243
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   244
  val (alpha_trms, alpha_bn_trms) = chop (length fvs) all_alpha_trms
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
in
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   246
  (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy')
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   249
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   250
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   251
(** produces the distinctness theorems **)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   252
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   253
(* transforms the distinctness theorems of the constructors 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   254
   to "not-alphas" of the constructors *)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   255
fun mk_alpha_distinct_goal alpha neq =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   256
let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   257
  val (lhs, rhs) = 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   258
    neq
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   259
    |> HOLogic.dest_Trueprop
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   260
    |> HOLogic.dest_not
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   261
    |> HOLogic.dest_eq
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   262
in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   263
  alpha $ lhs $ rhs
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   264
  |> HOLogic.mk_not
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   265
  |> HOLogic.mk_Trueprop
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   266
end
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   267
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   268
fun distinct_tac cases distinct_thms =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   269
  rtac notI THEN' eresolve_tac cases 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   270
  THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps distinct_thms)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   271
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   272
fun mk_alpha_distinct ctxt cases_thms (distinct_thm, alpha) =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   273
let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   274
  val ((_, thms), ctxt') = Variable.import false distinct_thm ctxt
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   275
  val goals = map (mk_alpha_distinct_goal alpha o prop_of) thms
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   276
  val nrels = map (fn t => Goal.prove ctxt' [] [] t (K (distinct_tac cases_thms distinct_thm 1))) goals
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   277
in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   278
  Variable.export ctxt' ctxt nrels
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   279
end
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   280
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   281
fun mk_alpha_distincts ctxt alpha_cases constrs_distinct_thms alpha_trms alpha_bn_trms bn_infos =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   282
let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   283
  val alpha_distincts = 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   284
    map (mk_alpha_distinct ctxt alpha_cases) (constrs_distinct_thms ~~ alpha_trms)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   285
  val distinc_thms = map 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   286
  val alpha_bn_distincts_aux = map (fn (_, i, _) => nth constrs_distinct_thms i) bn_infos
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   287
  val alpha_bn_distincts =  
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   288
    map (mk_alpha_distinct ctxt alpha_cases) (alpha_bn_distincts_aux ~~ alpha_bn_trms)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   289
in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   290
  (flat alpha_distincts, flat alpha_bn_distincts)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   291
end
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   292
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   293
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   294
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   295
(** produces the alpha_eq_iff simplification rules **)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   296
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   297
(* in case a theorem is of the form (C.. = C..), it will be
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   298
   rewritten to ((C.. = C..) = True) *)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   299
fun mk_simp_rule thm =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   300
  case (prop_of thm) of
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   301
    @{term "Trueprop"} $ (Const (@{const_name "op ="}, _) $ _ $ _) => @{thm eqTrueI} OF [thm]
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   302
  | _ => thm
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   303
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   304
fun alpha_eq_iff_tac dist_inj intros elims =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   305
  SOLVED' (asm_full_simp_tac (HOL_ss addsimps intros)) ORELSE'
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   306
  (rtac @{thm iffI} THEN' 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   307
    RANGE [eresolve_tac elims THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps dist_inj),
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   308
           asm_full_simp_tac (HOL_ss addsimps intros)])
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   309
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   310
fun mk_alpha_eq_iff_goal thm =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   311
  let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   312
    val prop = prop_of thm;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   313
    val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop);
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   314
    val hyps = map HOLogic.dest_Trueprop (Logic.strip_imp_prems prop);
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   315
    fun list_conj l = foldr1 HOLogic.mk_conj l;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   316
  in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   317
    if hyps = [] then HOLogic.mk_Trueprop concl
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   318
    else HOLogic.mk_Trueprop (HOLogic.mk_eq (concl, list_conj hyps))
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   319
  end;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   320
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   321
fun mk_alpha_eq_iff ctxt alpha_intros distinct_thms inject_thms alpha_elims =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   322
let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   323
  val ((_, thms_imp), ctxt') = Variable.import false alpha_intros ctxt;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   324
  val goals = map mk_alpha_eq_iff_goal thms_imp;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   325
  val tac = alpha_eq_iff_tac (distinct_thms @ inject_thms) alpha_intros alpha_elims 1;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   326
  val thms = map (fn goal => Goal.prove ctxt' [] [] goal (K tac)) goals;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   327
in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   328
  Variable.export ctxt' ctxt thms
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   329
  |> map mk_simp_rule
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   330
end
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   331
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   332
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   333
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   334
(** reflexivity proof for the alphas **)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   335
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   336
val exi_zero = @{lemma "P (0::perm) ==> (? x. P x)" by auto}
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   337
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   338
fun cases_tac intros =
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   339
let
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   340
  val prod_simps = @{thms split_conv prod_alpha_def prod_rel.simps}
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   341
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   342
  val unbound_tac = REPEAT o (etac @{thm conjE}) THEN' atac  
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   343
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   344
  val bound_tac = 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   345
    EVERY' [ rtac exi_zero, 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   346
             resolve_tac @{thms alpha_gen_refl}, 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   347
             asm_full_simp_tac (HOL_ss addsimps prod_simps) ]
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   348
in
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   349
  REPEAT o FIRST' [rtac @{thm conjI}, 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   350
    resolve_tac intros THEN_ALL_NEW FIRST' [rtac @{thm refl}, unbound_tac, bound_tac]]
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   351
end
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   352
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   353
fun raw_prove_refl alpha_trms alpha_bns alpha_intros raw_dt_induct ctxt =
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   354
let
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   355
  val arg_tys = 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   356
    alpha_trms
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   357
    |> map fastype_of
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   358
    |> map domain_type
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   359
  val arg_bn_tys = 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   360
    alpha_bns
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   361
    |> map fastype_of
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   362
    |> map domain_type
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   363
  val arg_names = Datatype_Prop.make_tnames arg_tys
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   364
  val arg_bn_names = map (fn ty => the (AList.lookup (op=) (arg_tys ~~ arg_names) ty)) arg_bn_tys
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   365
  val args = map Free (arg_names ~~ arg_tys)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   366
  val arg_bns = map Free (arg_bn_names ~~ arg_bn_tys)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   367
  val goal = 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   368
    AList.group (op=) ((arg_bns ~~ alpha_bns) @ (args ~~ alpha_trms))
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   369
    |> map (fn (ar, cnsts) => map (fn c => c $ ar $ ar) cnsts) 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   370
    |> map (foldr1 HOLogic.mk_conj)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   371
    |> foldr1 HOLogic.mk_conj
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   372
    |> HOLogic.mk_Trueprop
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   373
in
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   374
  Goal.prove ctxt arg_names [] goal
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   375
    (fn {context, ...} => 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   376
       HEADGOAL (DETERM o (rtac raw_dt_induct) THEN_ALL_NEW cases_tac alpha_intros)) 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   377
  |> Datatype_Aux.split_conj_thm 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   378
  |> map Datatype_Aux.split_conj_thm 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   379
  |> flat
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   380
end
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   381
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   382
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   383
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   384
(** symmetry proof for the alphas **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   385
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   386
val exi_neg = @{lemma "(EX (p::perm). P p) ==> (!!q. P q ==> Q (- q)) ==> EX p. Q p"
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   387
  by (erule exE, rule_tac x="-p" in exI, auto)}
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   388
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   389
(* for premises that contain binders *)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   390
fun prem_bound_tac pred_names ctxt = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   391
let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   392
  fun trans_prem_tac pred_names ctxt = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   393
    SUBPROOF (fn {prems, context, ...} => 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   394
    let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   395
      val prems' = map (transform_prem1 context pred_names) prems
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   396
    in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   397
      resolve_tac prems' 1
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   398
    end) ctxt
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   399
  val prod_simps = @{thms split_conv permute_prod.simps prod_alpha_def prod_rel.simps alphas}
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   400
in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   401
  EVERY' 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   402
    [ etac exi_neg,
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   403
      resolve_tac @{thms alpha_gen_sym_eqvt},
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   404
      asm_full_simp_tac (HOL_ss addsimps prod_simps),
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   405
      Nominal_Permeq.eqvt_tac ctxt [] [] THEN' rtac @{thm refl},
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   406
      trans_prem_tac pred_names ctxt ] 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   407
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   408
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   409
fun prove_sym_tac pred_names intros induct ctxt =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   410
let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   411
  val prem_eq_tac = rtac @{thm sym} THEN' atac   
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   412
  val prem_unbound_tac = atac
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   413
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   414
  val prem_cases_tacs = FIRST' 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   415
    [prem_eq_tac, prem_unbound_tac, prem_bound_tac pred_names ctxt]
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   416
in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   417
  HEADGOAL (rtac induct THEN_ALL_NEW 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   418
    (resolve_tac intros THEN_ALL_NEW prem_cases_tacs))
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   419
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   420
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   421
fun prep_sym_goal alpha_trm (arg1, arg2) =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   422
let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   423
  val lhs = alpha_trm $ arg1 $ arg2
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   424
  val rhs = alpha_trm $ arg2 $ arg1
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   425
in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   426
  HOLogic.mk_imp (lhs, rhs)  
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   427
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   428
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   429
fun raw_prove_sym alpha_trms alpha_intros alpha_induct ctxt =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   430
let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   431
  val alpha_names =  map (fst o dest_Const) alpha_trms
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   432
  val arg_tys = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   433
    alpha_trms
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   434
    |> map fastype_of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   435
    |> map domain_type  
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   436
  val (arg_names1, (arg_names2, ctxt')) =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   437
    ctxt
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   438
    |> Variable.variant_fixes (replicate (length arg_tys) "x") 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   439
    ||> Variable.variant_fixes (replicate (length arg_tys) "y")   
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   440
  val args1 = map Free (arg_names1 ~~ arg_tys) 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   441
  val args2 = map Free (arg_names2 ~~ arg_tys)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   442
  val goal = HOLogic.mk_Trueprop 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   443
    (foldr1 HOLogic.mk_conj (map2 prep_sym_goal alpha_trms (args1 ~~ args2)))	      
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   444
in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   445
  Goal.prove ctxt' [] [] goal 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   446
    (fn {context,...} =>  prove_sym_tac alpha_names alpha_intros alpha_induct context)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   447
    |> singleton (ProofContext.export ctxt' ctxt)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   448
    |> Datatype_Aux.split_conj_thm 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   449
    |> map (fn th => zero_var_indexes (th RS mp))
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   450
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   451
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   452
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   453
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   454
(** transitivity proof for alphas **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   455
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   456
(* applies cases rules and resolves them with the last premise *)
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   457
fun ecases_tac cases = 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   458
  Subgoal.FOCUS (fn {prems, ...} =>
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   459
    HEADGOAL (resolve_tac cases THEN' rtac (List.last prems)))
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   460
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   461
fun aatac pred_names = 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   462
  SUBPROOF (fn {prems, context, ...} =>
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   463
    HEADGOAL (resolve_tac (map (transform_prem1 context pred_names) prems)))
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   464
  
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   465
(* instantiates exI with the permutation p + q *)
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   466
val perm_inst_tac =
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   467
  Subgoal.FOCUS (fn {params, ...} => 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   468
    let
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   469
      val (p, q) = pairself snd (last2 params)
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   470
      val pq_inst = foldl1 (uncurry Thm.capply) [@{cterm "plus::perm => perm => perm"}, p, q]
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   471
      val exi_inst = Drule.instantiate' [SOME (@{ctyp "perm"})] [NONE, SOME pq_inst] @{thm exI}
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   472
    in
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   473
      HEADGOAL (rtac exi_inst)
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   474
    end)
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   475
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   476
fun non_trivial_cases_tac pred_names intros ctxt = 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   477
let
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   478
  val prod_simps = @{thms split_conv alphas permute_prod.simps prod_alpha_def prod_rel.simps}
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   479
in
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   480
  resolve_tac intros
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   481
  THEN_ALL_NEW (asm_simp_tac HOL_basic_ss THEN' 
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   482
    TRY o EVERY'   (* if binders are present *)
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   483
      [ etac @{thm exE},
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   484
        etac @{thm exE},
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   485
        perm_inst_tac ctxt, 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   486
        resolve_tac @{thms alpha_trans_eqvt}, 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   487
        atac,
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   488
        aatac pred_names ctxt, 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   489
        Nominal_Permeq.eqvt_tac ctxt [] [] THEN' rtac @{thm refl},
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   490
        asm_full_simp_tac (HOL_ss addsimps prod_simps) ])
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   491
end
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   492
			  
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   493
fun prove_trans_tac pred_names raw_dt_thms intros induct cases ctxt =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   494
let
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   495
  fun all_cases ctxt = 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   496
    asm_full_simp_tac (HOL_basic_ss addsimps raw_dt_thms) 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   497
    THEN' TRY o non_trivial_cases_tac pred_names intros ctxt
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   498
in
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   499
  HEADGOAL (rtac induct THEN_ALL_NEW  
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   500
    EVERY' [ rtac @{thm allI}, rtac @{thm impI}, 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   501
             ecases_tac cases ctxt THEN_ALL_NEW all_cases ctxt ])
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   502
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   503
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   504
fun prep_trans_goal alpha_trm ((arg1, arg2), arg_ty) =
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   505
let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   506
  val lhs = alpha_trm $ arg1 $ arg2
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   507
  val mid = alpha_trm $ arg2 $ (Bound 0)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   508
  val rhs = alpha_trm $ arg1 $ (Bound 0) 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   509
in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   510
  HOLogic.mk_imp (lhs, 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   511
    HOLogic.all_const arg_ty $ Abs ("z", arg_ty, 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   512
      HOLogic.mk_imp (mid, rhs)))
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   513
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   514
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   515
val norm = @{lemma "A --> (!x. B x --> C x) ==> (!!x. [|A; B x|] ==> C x)" by simp}
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   516
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   517
fun raw_prove_trans alpha_trms raw_dt_thms alpha_intros alpha_induct alpha_cases ctxt =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   518
let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   519
  val alpha_names =  map (fst o dest_Const) alpha_trms
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   520
  val arg_tys = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   521
    alpha_trms
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   522
    |> map fastype_of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   523
    |> map domain_type  
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   524
  val (arg_names1, (arg_names2, ctxt')) =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   525
    ctxt
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   526
    |> Variable.variant_fixes (replicate (length arg_tys) "x") 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   527
    ||> Variable.variant_fixes (replicate (length arg_tys) "y")
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   528
  val args1 = map Free (arg_names1 ~~ arg_tys) 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   529
  val args2 = map Free (arg_names2 ~~ arg_tys)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   530
  val goal = HOLogic.mk_Trueprop 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   531
    (foldr1 HOLogic.mk_conj (map2 prep_trans_goal alpha_trms (args1 ~~ args2 ~~ arg_tys))) 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   532
in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   533
  Goal.prove ctxt' [] [] goal 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   534
    (fn {context,...} =>  
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   535
       prove_trans_tac alpha_names raw_dt_thms alpha_intros alpha_induct alpha_cases context)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   536
    |> singleton (ProofContext.export ctxt' ctxt)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   537
    |> Datatype_Aux.split_conj_thm 
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   538
    |> map (fn th => zero_var_indexes (th RS norm))
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   539
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   540
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   541
end (* structure *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542