Nominal/nominal_dt_alpha.ML
author Christian Urban <urbanc@in.tum.de>
Sat, 14 Aug 2010 16:54:41 +0800
changeset 2397 c670a849af65
parent 2395 79e493880801
child 2399 107c06267f33
permissions -rw-r--r--
more experiments with lifting
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
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
    17
  val mk_alpha_eq_iff: Proof.context -> thm list -> thm list -> thm list -> 
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
    18
    thm list -> (thm list * thm list)
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
    19
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
    20
  val alpha_prove: term list -> (term * ((term * term) -> term)) list -> thm -> 
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
    21
    (Proof.context -> int -> tactic) -> Proof.context -> thm list
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
    22
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
    23
  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
    24
  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
    25
  val raw_prove_trans: term list -> thm list -> thm list -> thm -> thm list -> Proof.context -> thm list
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
    26
  val raw_prove_equivp: term list -> thm list -> thm list -> thm list -> Proof.context -> thm list
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
    27
  val raw_prove_bn_imp: term list -> term list -> thm list -> thm -> Proof.context -> thm list
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
    28
  val raw_fv_bn_rsp_aux: term list -> term list -> term list -> term list -> 
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
    29
    term list -> thm -> thm list -> Proof.context -> thm list
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
    30
  val raw_size_rsp_aux: term list -> thm -> thm list -> Proof.context -> thm list
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
    31
  val raw_constrs_rsp: term list -> term list -> thm list -> thm list -> Proof.context -> thm list
2393
d9a0cf26a88c added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2392
diff changeset
    32
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
    33
  val mk_funs_rsp: thm -> thm
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
    34
  val mk_alpha_permute_rsp: thm -> thm 
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
structure Nominal_Dt_Alpha: NOMINAL_DT_ALPHA =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
struct
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
    40
fun lookup xs x = the (AList.lookup (op=) xs x)
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
    41
fun group xs = AList.group (op=) xs
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
    42
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    43
(** 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
    44
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
(* construct the compound terms for prod_fv and prod_alpha *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
fun mk_prod_fv (t1, t2) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  val ty1 = fastype_of t1
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  val ty2 = fastype_of t2 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  val resT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2) --> @{typ "atom set"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  Const (@{const_name "prod_fv"}, [ty1, ty2] ---> resT) $ t1 $ t2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
fun mk_prod_alpha (t1, t2) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  val ty1 = fastype_of t1
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  val ty2 = fastype_of t2 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  val prodT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  val resT = [prodT, prodT] ---> @{typ "bool"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  Const (@{const_name "prod_alpha"}, [ty1, ty2] ---> resT) $ t1 $ t2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
(* generates the compound binder terms *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
fun mk_binders lthy bmode args bodies = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
let  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  fun bind_set lthy args (NONE, i) = setify lthy (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    | bind_set _ args (SOME bn, i) = bn $ (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  fun bind_lst lthy args (NONE, i) = listify lthy (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
    | bind_lst _ args (SOME bn, i) = bn $ (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  val (combine_fn, bind_fn) =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
    case bmode of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
      Lst => (mk_append, bind_lst) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    | Set => (mk_union,  bind_set)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
    | Res => (mk_union,  bind_set)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
in
2375
e163fd99de44 minor polishing
Christian Urban <urbanc@in.tum.de>
parents: 2322
diff changeset
    79
  bodies
e163fd99de44 minor polishing
Christian Urban <urbanc@in.tum.de>
parents: 2322
diff changeset
    80
  |> map (bind_fn lthy args)
e163fd99de44 minor polishing
Christian Urban <urbanc@in.tum.de>
parents: 2322
diff changeset
    81
  |> foldl1 combine_fn 
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
(* produces the term for an alpha with abstraction *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
fun mk_alpha_term bmode fv alpha args args' binders binders' =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  val (alpha_name, binder_ty) = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
    case bmode of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
      Lst => (@{const_name "alpha_lst"}, @{typ "atom list"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
    | Set => (@{const_name "alpha_gen"}, @{typ "atom set"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
    | Res => (@{const_name "alpha_res"}, @{typ "atom set"})
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  val ty = fastype_of args
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  val pair_ty = HOLogic.mk_prodT (binder_ty, ty)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  val alpha_ty = [ty, ty] ---> @{typ "bool"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  val fv_ty = ty --> @{typ "atom set"}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  val pair_lhs = HOLogic.mk_prod (binders, args)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  val pair_rhs = HOLogic.mk_prod (binders', args')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  HOLogic.exists_const @{typ perm} $ Abs ("p", @{typ perm},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
    Const (alpha_name, [pair_ty, alpha_ty, fv_ty, @{typ "perm"}, pair_ty] ---> @{typ bool}) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
      $ pair_lhs $ alpha $ fv $ (Bound 0) $ pair_rhs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
(* for non-recursive binders we have to produce alpha_bn premises *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
fun mk_alpha_bn_prem alpha_bn_map args args' bodies binder = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  case binder of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
    (NONE, _) => []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  | (SOME bn, i) =>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
     if member (op=) bodies i then [] 
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   110
     else [lookup alpha_bn_map bn $ nth args i $ nth args' i]
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
(* generat the premises for an alpha rule; mk_frees is used
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
   if no binders are present *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
fun mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  fun mk_frees i =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
      val arg = nth args i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
      val arg' = nth args' i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
      val ty = fastype_of arg
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
      if nth is_rec i
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   123
      then fst (lookup alpha_map ty) $ arg $ arg'
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
      else HOLogic.mk_eq (arg, arg')
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
    end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  fun mk_alpha_fv i = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
      val ty = fastype_of (nth args i)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
      case AList.lookup (op=) alpha_map ty of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
        NONE => (HOLogic.eq_const ty, supp_const ty) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
      | SOME (alpha, fv) => (alpha, fv) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
    end  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
  case bclause of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
    BC (_, [], bodies) => map (HOLogic.mk_Trueprop o mk_frees) bodies 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  | BC (bmode, binders, bodies) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
    let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
      val (alphas, fvs) = split_list (map mk_alpha_fv bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
      val comp_fv = foldl1 mk_prod_fv fvs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
      val comp_alpha = foldl1 mk_prod_alpha alphas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
      val comp_args = foldl1 HOLogic.mk_prod (map (nth args) bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
      val comp_args' = foldl1 HOLogic.mk_prod (map (nth args') bodies)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
      val comp_binders = mk_binders lthy bmode args binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
      val comp_binders' = mk_binders lthy bmode args' binders
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
      val alpha_prem = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
        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
   149
      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
   150
    in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
      map HOLogic.mk_Trueprop (alpha_prem::alpha_bn_prems)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
    end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
(* produces the introduction rule for an alpha rule *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
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
   157
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
  val arg_names = Datatype_Prop.make_tnames arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
  val arg_names' = Name.variant_list arg_names arg_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
  val args = map Free (arg_names ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
  val args' = map Free (arg_names' ~~ arg_tys)
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   162
  val alpha = fst (lookup alpha_map ty)
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
  val concl = HOLogic.mk_Trueprop (alpha $ list_comb (constr, args) $ list_comb (constr, args'))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
  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
   165
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  Library.foldr Logic.mk_implies (flat prems, concl)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
(* produces the premise of an alpha-bn rule; we only need to
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
   treat the case special where the binding clause is empty;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
   - if the body is not included in the bn_info, then we either
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
     produce an equation or an alpha-premise
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
   - if the body is included in the bn_info, then we create
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
     either a recursive call to alpha-bn, or no premise  *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
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
   178
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
  fun mk_alpha_bn_prem alpha_map alpha_bn_map bn_args (args, args') i = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
  let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
    val arg = nth args i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
    val arg' = nth args' i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
    val ty = fastype_of arg
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
    case AList.lookup (op=) bn_args i of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
      NONE => (case (AList.lookup (op=) alpha_map ty) of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
                 NONE =>  [HOLogic.mk_eq (arg, arg')]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
               | SOME (alpha, _) => [alpha $ arg $ arg'])
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
    | SOME (NONE) => []
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   190
    | SOME (SOME bn) => [lookup alpha_bn_map bn $ arg $ arg']
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
  end  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  case bclause of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
    BC (_, [], bodies) => 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
      map HOLogic.mk_Trueprop 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
        (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
   197
  | _ => mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
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
   201
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  val arg_names = Datatype_Prop.make_tnames arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  val arg_names' = Name.variant_list arg_names arg_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
  val args = map Free (arg_names ~~ arg_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  val args' = map Free (arg_names' ~~ arg_tys)
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   206
  val alpha_bn = lookup alpha_bn_map bn_trm
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
  val concl = HOLogic.mk_Trueprop (alpha_bn $ list_comb (constr, args) $ list_comb (constr, args'))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
  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
   209
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
  Library.foldr Logic.mk_implies (flat prems, concl)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
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
   214
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
  val nth_constrs_info = nth constrs_info bn_n
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  val nth_bclausess = nth bclausesss bn_n
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
in
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  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
   219
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
fun define_raw_alpha descr sorts bn_info bclausesss fvs lthy =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
let
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  val alpha_names = prefix_dt_names descr sorts "alpha_"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
  val alpha_arg_tys = all_dtyps descr sorts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
  val alpha_tys = map (fn ty => [ty, ty] ---> @{typ bool}) alpha_arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
  val alpha_frees = map Free (alpha_names ~~ alpha_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  val alpha_map = alpha_arg_tys ~~ (alpha_frees ~~ fvs)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
  val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  val alpha_bn_names = map (prefix "alpha_") bn_names
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  val alpha_bn_arg_tys = map (fn i => nth_dtyp descr sorts i) bn_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
  val alpha_bn_tys = map (fn ty => [ty, ty] ---> @{typ "bool"}) alpha_bn_arg_tys
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
  val alpha_bn_frees = map Free (alpha_bn_names ~~ alpha_bn_tys)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
  val alpha_bn_map = bns ~~ alpha_bn_frees
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  val constrs_info = all_dtyp_constrs_types descr sorts
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
  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
   240
  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
   241
2299
09bbed4f21d6 added slides
Christian Urban <urbanc@in.tum.de>
parents: 2298
diff changeset
   242
  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
   243
    (alpha_names @ alpha_bn_names ~~ alpha_tys @ alpha_bn_tys)
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
  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
   245
  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
  val (alphas, lthy') = Inductive.add_inductive_i
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
     {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
   248
      coind = false, no_elim = false, no_ind = false, skip_mono = false, fork_mono = false}
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
     all_alpha_names [] all_alpha_intros [] lthy
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   251
  val all_alpha_trms_loc = #preds alphas;
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
  val alpha_induct_loc = #raw_induct alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
  val alpha_intros_loc = #intrs alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
  val alpha_cases_loc = #elims alphas;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  val phi = ProofContext.export_morphism lthy' lthy;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   257
  val all_alpha_trms = map (Morphism.term phi) all_alpha_trms_loc;
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
  val alpha_induct = Morphism.thm phi alpha_induct_loc;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
  val alpha_intros = map (Morphism.thm phi) alpha_intros_loc
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
  val alpha_cases = map (Morphism.thm phi) alpha_cases_loc
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   261
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   262
  val (alpha_trms, alpha_bn_trms) = chop (length fvs) all_alpha_trms
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
in
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   264
  (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy')
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   267
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   268
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   269
(** produces the distinctness theorems **)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   270
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   271
(* transforms the distinctness theorems of the constructors 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   272
   to "not-alphas" of the constructors *)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   273
fun mk_alpha_distinct_goal alpha neq =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   274
let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   275
  val (lhs, rhs) = 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   276
    neq
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   277
    |> HOLogic.dest_Trueprop
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   278
    |> HOLogic.dest_not
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   279
    |> HOLogic.dest_eq
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   280
in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   281
  alpha $ lhs $ rhs
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   282
  |> HOLogic.mk_not
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   283
  |> HOLogic.mk_Trueprop
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   284
end
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   285
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   286
fun distinct_tac cases distinct_thms =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   287
  rtac notI THEN' eresolve_tac cases 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   288
  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
   289
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   290
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
   291
let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   292
  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
   293
  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
   294
  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
   295
in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   296
  Variable.export ctxt' ctxt nrels
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   297
end
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   298
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   299
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
   300
let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   301
  val alpha_distincts = 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   302
    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
   303
  val distinc_thms = map 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   304
  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
   305
  val alpha_bn_distincts =  
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   306
    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
   307
in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   308
  (flat alpha_distincts, flat alpha_bn_distincts)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   309
end
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   310
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   311
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   312
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   313
(** produces the alpha_eq_iff simplification rules **)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   314
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   315
(* 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
   316
   rewritten to ((C.. = C..) = True) *)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   317
fun mk_simp_rule thm =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   318
  case (prop_of thm) of
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   319
    @{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
   320
  | _ => thm
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   321
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   322
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
   323
  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
   324
  (rtac @{thm iffI} THEN' 
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   325
    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
   326
           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
   327
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   328
fun mk_alpha_eq_iff_goal thm =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   329
  let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   330
    val prop = prop_of thm;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   331
    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
   332
    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
   333
    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
   334
  in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   335
    if hyps = [] then HOLogic.mk_Trueprop concl
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   336
    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
   337
  end;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   338
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   339
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
   340
let
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   341
  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
   342
  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
   343
  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
   344
  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
   345
in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   346
  Variable.export ctxt' ctxt thms
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   347
  |> `(map mk_simp_rule)
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   348
end
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   349
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   350
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   351
(** proof by induction over the alpha-definitions **)
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   352
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   353
fun is_true @{term "Trueprop True"} = true
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   354
  | is_true _ = false 
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   355
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   356
fun alpha_prove alphas props alpha_induct_thm cases_tac ctxt =
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   357
let
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   358
  val arg_tys = map (domain_type o fastype_of) alphas
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   359
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   360
  val ((arg_names1, arg_names2), ctxt') =
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   361
    ctxt
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   362
    |> Variable.variant_fixes (replicate (length alphas) "x") 
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   363
    ||>> Variable.variant_fixes (replicate (length alphas) "y")
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   364
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   365
  val args1 = map2 (curry Free) arg_names1 arg_tys
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   366
  val args2 = map2 (curry Free) arg_names2 arg_tys
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   367
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   368
  val true_trms = replicate (length alphas) (K @{term True})
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   369
  
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   370
  fun apply_all x fs = map (fn f => f x) fs
2391
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   371
  val goals_rhs = 
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   372
    group (props @ (alphas ~~ true_trms))
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   373
    |> map snd 
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   374
    |> map2 apply_all (args1 ~~ args2)
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   375
    |> map fold_conj
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   376
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   377
  fun apply_trm_pair t (ar1, ar2) = t $ ar1 $ ar2
2391
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   378
  val goals_lhs = map2 apply_trm_pair alphas (args1 ~~ args2)
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   379
2391
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   380
  val goals =
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   381
    (map2 (curry HOLogic.mk_imp) goals_lhs goals_rhs)
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   382
    |> foldr1 HOLogic.mk_conj
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   383
    |> HOLogic.mk_Trueprop
2391
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   384
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   385
  fun tac ctxt =
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   386
   HEADGOAL 
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   387
     (DETERM o (rtac alpha_induct_thm) 
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   388
      THEN_ALL_NEW FIRST' [rtac @{thm TrueI}, cases_tac ctxt])
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   389
in
2391
Christian Urban <urbanc@in.tum.de>
parents: 2390
diff changeset
   390
  Goal.prove ctxt' [] [] goals (fn {context, ...} => tac context)
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   391
  |> singleton (ProofContext.export ctxt' ctxt)
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   392
  |> Datatype_Aux.split_conj_thm
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   393
  |> map (fn th => th RS mp) 
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   394
  |> map Datatype_Aux.split_conj_thm
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   395
  |> flat
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   396
  |> map zero_var_indexes
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   397
  |> filter_out (is_true o concl_of)
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   398
end
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   399
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   400
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   401
(** reflexivity proof for the alphas **)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   402
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   403
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
   404
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   405
fun cases_tac intros =
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   406
let
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   407
  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
   408
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   409
  val unbound_tac = REPEAT o (etac @{thm conjE}) THEN' atac  
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   410
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   411
  val bound_tac = 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   412
    EVERY' [ rtac exi_zero, 
2385
fe25a3ffeb14 cleaned up a bit Abs.thy
Christian Urban <urbanc@in.tum.de>
parents: 2375
diff changeset
   413
             resolve_tac @{thms alpha_refl}, 
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   414
             asm_full_simp_tac (HOL_ss addsimps prod_simps) ]
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   415
in
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   416
  REPEAT o FIRST' [rtac @{thm conjI}, 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   417
    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
   418
end
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   419
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   420
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
   421
let
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   422
  val arg_tys = 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   423
    alpha_trms
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   424
    |> map fastype_of
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   425
    |> map domain_type
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   426
  val arg_bn_tys = 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   427
    alpha_bns
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   428
    |> map fastype_of
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   429
    |> map domain_type
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   430
  val arg_names = Datatype_Prop.make_tnames arg_tys
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   431
  val arg_bn_names = map (lookup (arg_tys ~~ arg_names)) arg_bn_tys
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   432
  val args = map Free (arg_names ~~ arg_tys)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   433
  val arg_bns = map Free (arg_bn_names ~~ arg_bn_tys)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   434
  val goal = 
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   435
    group ((arg_bns ~~ alpha_bns) @ (args ~~ alpha_trms))
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   436
    |> map (fn (ar, cnsts) => map (fn c => c $ ar $ ar) cnsts) 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   437
    |> map (foldr1 HOLogic.mk_conj)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   438
    |> foldr1 HOLogic.mk_conj
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   439
    |> HOLogic.mk_Trueprop
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   440
in
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   441
  Goal.prove ctxt arg_names [] goal
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   442
    (fn {context, ...} => 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   443
       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
   444
  |> Datatype_Aux.split_conj_thm 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   445
  |> map Datatype_Aux.split_conj_thm 
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   446
  |> flat
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   447
end
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   448
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   449
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   450
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   451
(** symmetry proof for the alphas **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   452
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   453
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
   454
  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
   455
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   456
(* for premises that contain binders *)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   457
fun prem_bound_tac pred_names ctxt = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   458
let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   459
  fun trans_prem_tac pred_names ctxt = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   460
    SUBPROOF (fn {prems, context, ...} => 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   461
    let
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   462
      val prems' = map (transform_prem1 context pred_names) prems
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   463
    in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   464
      resolve_tac prems' 1
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   465
    end) ctxt
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   466
  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
   467
in
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   468
  EVERY' 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   469
    [ etac exi_neg,
2385
fe25a3ffeb14 cleaned up a bit Abs.thy
Christian Urban <urbanc@in.tum.de>
parents: 2375
diff changeset
   470
      resolve_tac @{thms alpha_sym_eqvt},
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   471
      asm_full_simp_tac (HOL_ss addsimps prod_simps),
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   472
      Nominal_Permeq.eqvt_tac ctxt [] [] THEN' rtac @{thm refl},
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   473
      trans_prem_tac pred_names ctxt ] 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   474
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   475
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   476
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
   477
let
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   478
  val props = map (fn t => fn (x, y) => t $ y $ x) alpha_trms
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   479
  
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   480
  fun tac ctxt = 
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   481
    let
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   482
      val alpha_names =  map (fst o dest_Const) alpha_trms   
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   483
    in
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   484
      resolve_tac alpha_intros THEN_ALL_NEW 
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   485
      FIRST' [atac, rtac @{thm sym} THEN' atac, prem_bound_tac alpha_names ctxt]
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   486
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   487
in
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   488
  alpha_prove alpha_trms (alpha_trms ~~ props) alpha_induct tac ctxt 
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   489
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   490
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   491
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   492
(** transitivity proof for alphas **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   493
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   494
(* 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
   495
fun ecases_tac cases = 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   496
  Subgoal.FOCUS (fn {prems, ...} =>
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   497
    HEADGOAL (resolve_tac cases THEN' rtac (List.last prems)))
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   498
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   499
fun aatac pred_names = 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   500
  SUBPROOF (fn {prems, context, ...} =>
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   501
    HEADGOAL (resolve_tac (map (transform_prem1 context pred_names) prems)))
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   502
  
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   503
(* instantiates exI with the permutation p + q *)
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   504
val perm_inst_tac =
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   505
  Subgoal.FOCUS (fn {params, ...} => 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   506
    let
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   507
      val (p, q) = pairself snd (last2 params)
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   508
      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
   509
      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
   510
    in
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   511
      HEADGOAL (rtac exi_inst)
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   512
    end)
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   513
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   514
fun non_trivial_cases_tac pred_names intros ctxt = 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   515
let
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   516
  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
   517
in
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   518
  resolve_tac intros
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   519
  THEN_ALL_NEW (asm_simp_tac HOL_basic_ss THEN' 
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   520
    TRY o EVERY'   (* if binders are present *)
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   521
      [ etac @{thm exE},
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   522
        etac @{thm exE},
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   523
        perm_inst_tac ctxt, 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   524
        resolve_tac @{thms alpha_trans_eqvt}, 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   525
        atac,
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   526
        aatac pred_names ctxt, 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   527
        Nominal_Permeq.eqvt_tac ctxt [] [] THEN' rtac @{thm refl},
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   528
        asm_full_simp_tac (HOL_ss addsimps prod_simps) ])
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   529
end
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   530
			  
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   531
fun prove_trans_tac pred_names raw_dt_thms intros cases ctxt =
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   532
let
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   533
  fun all_cases ctxt = 
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   534
    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
   535
    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
   536
in
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   537
  EVERY' [ rtac @{thm allI}, rtac @{thm impI}, 
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   538
           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
   539
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   540
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   541
fun prep_trans_goal alpha_trm (arg1, arg2) =
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   542
let
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   543
  val arg_ty = fastype_of arg1
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   544
  val mid = alpha_trm $ arg2 $ (Bound 0)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   545
  val rhs = alpha_trm $ arg1 $ (Bound 0) 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   546
in
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   547
  HOLogic.all_const arg_ty $ Abs ("z", arg_ty, HOLogic.mk_imp (mid, rhs))
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   548
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   549
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   550
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
   551
let
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   552
  val alpha_names =  map (fst o dest_Const) alpha_trms 
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   553
  val props = map prep_trans_goal alpha_trms
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   554
  val norm = @{lemma "A ==> (!x. B x --> C x) ==> (!!x. [|A; B x|] ==> C x)" by simp}  
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   555
in
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   556
  alpha_prove alpha_trms (alpha_trms ~~ props) alpha_induct
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   557
    (prove_trans_tac alpha_names raw_dt_thms alpha_intros alpha_cases) ctxt
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   558
end
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   559
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   560
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   561
(** proves the equivp predicate for all alphas **)
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   562
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   563
val transp_def' =
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   564
  @{lemma "transp R == !x y. R x y --> (!z. R y z --> R x z)" 
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   565
    by (rule eq_reflection, auto simp add: transp_def)}
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   566
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   567
fun raw_prove_equivp alphas refl symm trans ctxt = 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   568
let
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   569
  val refl' = map (fold_rule @{thms reflp_def} o atomize) refl
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   570
  val symm' = map (fold_rule @{thms symp_def} o atomize) symm
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   571
  val trans' = map (fold_rule [transp_def'] o atomize) trans
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   572
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   573
  fun prep_goal t = 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   574
    HOLogic.mk_Trueprop (Const (@{const_name "equivp"}, fastype_of t --> @{typ bool}) $ t) 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   575
in    
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   576
  Goal.prove_multi ctxt [] [] (map prep_goal alphas)
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   577
  (K (HEADGOAL (Goal.conjunction_tac THEN_ALL_NEW (rtac @{thm equivpI} THEN' 
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   578
     RANGE [resolve_tac refl', resolve_tac symm', resolve_tac trans']))))
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   579
end
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   580
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   581
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   582
(* proves that alpha_raw implies alpha_bn *)
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   583
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   584
fun raw_prove_bn_imp_tac pred_names alpha_intros ctxt = 
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   585
  SUBPROOF (fn {prems, context, ...} => 
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   586
    let
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   587
      val prems' = flat (map Datatype_Aux.split_conj_thm prems)
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   588
      val prems'' = map (transform_prem1 context pred_names) prems'
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   589
    in
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   590
      HEADGOAL 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   591
        (REPEAT_ALL_NEW 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   592
           (FIRST' [ rtac @{thm TrueI}, 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   593
                     rtac @{thm conjI}, 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   594
                     resolve_tac prems', 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   595
                     resolve_tac prems'',
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   596
                     resolve_tac alpha_intros ]))
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   597
    end) ctxt
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   598
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   599
fun raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct ctxt =
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   600
let
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   601
  val arg_ty = domain_type o fastype_of 
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   602
  val alpha_names =  map (fst o dest_Const) alpha_trms
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   603
  val ty_assoc = map (fn t => (arg_ty t, t)) alpha_trms
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   604
  val props = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => t $ x $ y)) alpha_bn_trms
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   605
in
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   606
  alpha_prove (alpha_trms @ alpha_bn_trms) props alpha_induct 
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   607
    (raw_prove_bn_imp_tac alpha_names alpha_intros) ctxt
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   608
end
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   609
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   610
2393
d9a0cf26a88c added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2392
diff changeset
   611
(* respectfulness for fv_raw / bn_raw *)
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   612
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   613
fun raw_fv_bn_rsp_aux alpha_trms alpha_bn_trms fvs bns fv_bns alpha_induct simps ctxt =
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   614
let
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   615
  val arg_ty = domain_type o fastype_of 
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   616
  val ty_assoc = map (fn t => (arg_ty t, t)) alpha_trms
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   617
  fun mk_eq' t x y = HOLogic.mk_eq (t $ x, t $ y)
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   618
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   619
  val prop1 = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => mk_eq' t x y)) fvs
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   620
  val prop2 = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => mk_eq' t x y)) (bns @ fv_bns)
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   621
  val prop3 = map2 (fn t1 => fn t2 => (t1, fn (x, y) => mk_eq' t2 x y)) alpha_bn_trms fv_bns
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   622
  
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   623
  val ss = HOL_ss addsimps (simps @ @{thms alphas prod_fv.simps set.simps append.simps} 
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   624
    @ @{thms Un_assoc Un_insert_left Un_empty_right Un_empty_left}) 
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   625
in
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   626
  alpha_prove (alpha_trms @ alpha_bn_trms) (prop1 @ prop2 @ prop3) alpha_induct 
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   627
    (K (asm_full_simp_tac ss)) ctxt
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   628
end
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   629
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   630
2393
d9a0cf26a88c added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2392
diff changeset
   631
(* respectfulness for size *)
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   632
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   633
fun raw_size_rsp_aux all_alpha_trms alpha_induct simps ctxt =
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   634
let
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   635
  val arg_tys = map (domain_type o fastype_of) all_alpha_trms
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   636
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   637
  fun mk_prop ty (x, y) = HOLogic.mk_eq 
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   638
    (HOLogic.size_const ty $ x, HOLogic.size_const ty $ y)
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   639
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   640
  val props = map2 (fn trm => fn ty => (trm, mk_prop ty)) all_alpha_trms arg_tys 
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   641
  
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   642
  val ss = HOL_ss addsimps (simps @ @{thms alphas prod_alpha_def prod_rel.simps 
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   643
    permute_prod_def prod.cases prod.recs})
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   644
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   645
  val tac = (TRY o REPEAT o etac @{thm exE}) THEN' asm_full_simp_tac ss
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   646
in
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   647
  alpha_prove all_alpha_trms props alpha_induct (K tac) ctxt
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   648
end
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   649
2393
d9a0cf26a88c added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2392
diff changeset
   650
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   651
(* respectfulness for constructors *)
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   652
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   653
fun raw_constr_rsp_tac alpha_intros simps = 
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   654
let
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   655
  val pre_ss = HOL_ss addsimps @{thms fun_rel_def}
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   656
  val post_ss = HOL_ss addsimps @{thms alphas prod_alpha_def prod_rel.simps 
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   657
    prod_fv.simps fresh_star_zero permute_zero prod.cases} @ simps
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   658
  (* funs_rsp alpha_bn_simps *)
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   659
in
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   660
  asm_full_simp_tac pre_ss
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   661
  THEN' REPEAT o (resolve_tac @{thms allI impI})
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   662
  THEN' resolve_tac alpha_intros
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   663
  THEN_ALL_NEW (TRY o (rtac exi_zero) THEN' asm_full_simp_tac post_ss)
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   664
end
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   665
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   666
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   667
fun raw_constrs_rsp constrs alpha_trms alpha_intros simps ctxt =
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   668
let
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   669
  val alpha_arg_tys = map (domain_type o fastype_of) alpha_trms
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   670
  
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   671
  fun lookup ty = 
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   672
    case AList.lookup (op=) (alpha_arg_tys ~~ alpha_trms) ty of
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   673
      NONE => HOLogic.eq_const ty
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   674
    | SOME alpha => alpha 
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   675
  
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   676
  fun fun_rel_app t1 t2 = 
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   677
    Const (@{const_name "fun_rel"}, dummyT) $ t1 $ t2
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   678
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   679
  fun prep_goal trm =
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   680
    trm
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   681
    |> strip_type o fastype_of
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   682
    |>> map lookup
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   683
    ||> lookup
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   684
    |> uncurry (fold_rev fun_rel_app)
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   685
    |> (fn t => t $ trm $ trm)
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   686
    |> Syntax.check_term ctxt
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   687
    |> HOLogic.mk_Trueprop
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   688
in
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   689
  Goal.prove_multi ctxt [] [] (map prep_goal constrs)
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   690
    (K (HEADGOAL 
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   691
      (Goal.conjunction_tac THEN_ALL_NEW raw_constr_rsp_tac alpha_intros simps)))
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   692
end
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   693
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   694
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   695
(* transformation of the natural rsp-lemmas into the standard form *)
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   696
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   697
val fun_rsp = @{lemma
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   698
  "(!x y. R x y --> f x = f y) ==> (R ===> (op =)) f f" by simp}
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   699
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   700
fun mk_funs_rsp thm = 
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   701
 thm
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   702
 |> atomize
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   703
 |> single
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   704
 |> curry (op OF) fun_rsp
2393
d9a0cf26a88c added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2392
diff changeset
   705
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   706
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   707
val permute_rsp = @{lemma 
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   708
  "(!x y p. R x y --> R (permute p x) (permute p y)) 
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   709
     ==> ((op =) ===> R ===> R) permute permute"  by simp}
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   710
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   711
fun mk_alpha_permute_rsp thm = 
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   712
 thm
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   713
 |> atomize
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   714
 |> single
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   715
 |> curry (op OF) permute_rsp
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   716
2393
d9a0cf26a88c added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2392
diff changeset
   717
d9a0cf26a88c added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2392
diff changeset
   718
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   719
end (* structure *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   720