Nominal/nominal_dt_alpha.ML
author Christian Urban <urbanc@in.tum.de>
Thu, 19 Apr 2018 13:58:22 +0100
branchNominal2-Isabelle2016-1
changeset 3246 66114fa3d2ee
parent 3245 017e33849f4d
permissions -rw-r--r--
updated to Isabelle 2016-1
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
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2594
diff changeset
    10
  val comb_binders: Proof.context -> bmode -> term list -> (term option * int) list -> term
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2594
diff changeset
    11
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
    12
  val define_raw_alpha: raw_dt_info -> bn_info list -> bclause list list list -> term list -> 
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
    13
    Proof.context -> alpha_result * local_theory
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    14
2480
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
    15
  val induct_prove: typ list -> (typ * (term -> term)) list -> thm -> 
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
    16
    (Proof.context -> int -> tactic) -> Proof.context -> thm list
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
    17
  
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
    18
  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
    19
    (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
    20
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
    21
  val raw_prove_alpha_distincts: Proof.context -> alpha_result -> raw_dt_info -> thm list
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
    22
  val raw_prove_alpha_eq_iff: Proof.context -> alpha_result -> raw_dt_info -> thm list
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
    23
  val raw_prove_refl: Proof.context -> alpha_result -> thm -> thm list
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
    24
  val raw_prove_sym: Proof.context -> alpha_result -> thm list -> thm list
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
    25
  val raw_prove_trans: Proof.context -> alpha_result -> thm list -> thm list -> thm list
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
    26
  val raw_prove_equivp: Proof.context -> alpha_result -> thm list -> thm list -> thm list -> 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
    27
    thm list * thm list
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
    28
  val raw_prove_bn_imp: Proof.context -> alpha_result -> thm list
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
    29
  val raw_fv_bn_rsp_aux: Proof.context -> alpha_result -> term list -> term list -> term list -> 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
    30
    thm list -> thm list
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
    31
  val raw_size_rsp_aux: Proof.context -> alpha_result -> thm list -> thm list
3161
aa1ba91ed1ff Pass proper rsp theorems for constructors and for size
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3124
diff changeset
    32
  val raw_constrs_rsp: Proof.context -> alpha_result -> term list list -> thm list -> thm list list
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
    33
  val raw_alpha_bn_rsp: alpha_result -> thm list -> thm list -> thm list
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
    34
  val raw_perm_bn_rsp: Proof.context -> alpha_result -> term list -> thm list -> thm list
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
    35
  
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
    36
  val mk_funs_rsp: Proof.context -> thm -> thm
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
    37
  val mk_alpha_permute_rsp: Proof.context -> thm -> thm 
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
end
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
structure Nominal_Dt_Alpha: NOMINAL_DT_ALPHA =
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
struct
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
2765
7ac5e5c86c7d introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
    43
open Nominal_Permeq
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
    44
open Nominal_Dt_Data
2765
7ac5e5c86c7d introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
parents: 2611
diff changeset
    45
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
    46
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
    47
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
    48
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
    49
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
    50
(** 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
    51
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
(* construct the compound terms for prod_fv and prod_alpha *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
fun mk_prod_fv (t1, t2) =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    54
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    55
    val ty1 = fastype_of t1
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    56
    val ty2 = fastype_of t2 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    57
    val resT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2) --> @{typ "atom set"}
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    58
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    59
    Const (@{const_name "prod_fv"}, [ty1, ty2] ---> resT) $ t1 $ t2
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    60
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
fun mk_prod_alpha (t1, t2) =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    63
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    64
    val ty1 = fastype_of t1
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    65
    val ty2 = fastype_of t2 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    66
    val prodT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    67
    val resT = [prodT, prodT] ---> @{typ "bool"}
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    68
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    69
    Const (@{const_name "prod_alpha"}, [ty1, ty2] ---> resT) $ t1 $ t2
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    70
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
(* generates the compound binder terms *)
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2594
diff changeset
    73
fun comb_binders lthy bmode args binders = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    74
  let  
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    75
    fun bind_set lthy args (NONE, i) = setify lthy (nth args i)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    76
      | bind_set _ args (SOME bn, i) = bn $ (nth args i)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    77
    fun bind_lst lthy args (NONE, i) = listify lthy (nth args i)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    78
      | bind_lst _ args (SOME bn, i) = bn $ (nth args i)
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    80
    val (combine_fn, bind_fn) =
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    81
      case bmode of
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    82
        Lst => (mk_append, bind_lst) 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    83
      | Set => (mk_union,  bind_set)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    84
      | Res => (mk_union,  bind_set)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    85
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    86
    binders
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    87
    |> map (bind_fn lthy args)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    88
    |> foldl1 combine_fn 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    89
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
(* produces the term for an alpha with abstraction *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
fun mk_alpha_term bmode fv alpha args args' binders binders' =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    93
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    94
    val (alpha_name, binder_ty) = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    95
      case bmode of
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    96
        Lst => (@{const_name "alpha_lst"}, @{typ "atom list"})
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    97
      | Set => (@{const_name "alpha_set"}, @{typ "atom set"})
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    98
      | Res => (@{const_name "alpha_res"}, @{typ "atom set"})
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    99
    val ty = fastype_of args
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   100
    val pair_ty = HOLogic.mk_prodT (binder_ty, ty)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   101
    val alpha_ty = [ty, ty] ---> @{typ "bool"}
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   102
    val fv_ty = ty --> @{typ "atom set"}
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   103
    val pair_lhs = HOLogic.mk_prod (binders, args)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   104
    val pair_rhs = HOLogic.mk_prod (binders', args')
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   105
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   106
    HOLogic.exists_const @{typ perm} $ Abs ("p", @{typ perm},
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   107
      Const (alpha_name, [pair_ty, alpha_ty, fv_ty, @{typ "perm"}, pair_ty] ---> @{typ bool}) 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   108
        $ pair_lhs $ alpha $ fv $ (Bound 0) $ pair_rhs)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   109
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
(* for non-recursive binders we have to produce alpha_bn premises *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
fun mk_alpha_bn_prem alpha_bn_map args args' bodies binder = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  case binder of
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
    (NONE, _) => []
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  | (SOME bn, i) =>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
     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
   117
     else [lookup alpha_bn_map bn $ nth args i $ nth args' i]
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
2438
abafea9b39bb corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
parents: 2435
diff changeset
   119
(* generate the premises for an alpha rule; mk_frees is used
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
   if no binders are present *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
fun mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   122
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   123
    fun mk_frees i =
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   124
      let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   125
        val arg = nth args i
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   126
        val arg' = nth args' i
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   127
        val ty = fastype_of arg
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   128
      in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   129
        if nth is_rec i
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   130
        then fst (lookup alpha_map ty) $ arg $ arg'
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   131
        else HOLogic.mk_eq (arg, arg')
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   132
      end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   134
    fun mk_alpha_fv i = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   135
      let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   136
        val ty = fastype_of (nth args i)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   137
      in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   138
        case AList.lookup (op=) alpha_map ty of
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   139
          NONE => (HOLogic.eq_const ty, supp_const ty) 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   140
        | SOME (alpha, fv) => (alpha, fv) 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   141
      end  
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   142
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   143
    case bclause of
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   144
      BC (_, [], bodies) => map (HOLogic.mk_Trueprop o mk_frees) bodies 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   145
    | BC (bmode, binders, bodies) => 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   146
        let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   147
          val (alphas, fvs) = split_list (map mk_alpha_fv bodies)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   148
          val comp_fv = foldl1 mk_prod_fv fvs
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   149
          val comp_alpha = foldl1 mk_prod_alpha alphas
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   150
          val comp_args = foldl1 HOLogic.mk_prod (map (nth args) bodies)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   151
          val comp_args' = foldl1 HOLogic.mk_prod (map (nth args') bodies)
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2594
diff changeset
   152
          val comp_binders = comb_binders lthy bmode args binders
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2594
diff changeset
   153
          val comp_binders' = comb_binders lthy bmode args' binders
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   154
          val alpha_prem = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   155
            mk_alpha_term bmode comp_fv comp_alpha comp_args comp_args' comp_binders comp_binders'
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   156
          val alpha_bn_prems = flat (map (mk_alpha_bn_prem alpha_bn_map args args' bodies) binders)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   157
        in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   158
          map HOLogic.mk_Trueprop (alpha_prem::alpha_bn_prems)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   159
        end
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   160
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
(* produces the introduction rule for an alpha rule *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
fun mk_alpha_intros lthy alpha_map alpha_bn_map (constr, ty, arg_tys, is_rec) bclauses = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   164
  let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   165
    val arg_names = Old_Datatype_Prop.make_tnames arg_tys
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   166
    val arg_names' = Name.variant_list arg_names arg_names
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   167
    val args = map Free (arg_names ~~ arg_tys)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   168
    val args' = map Free (arg_names' ~~ arg_tys)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   169
    val alpha = fst (lookup alpha_map ty)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   170
    val concl = HOLogic.mk_Trueprop (alpha $ list_comb (constr, args) $ list_comb (constr, args'))
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   171
    val prems = map (mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args')) bclauses
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   172
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   173
    Library.foldr Logic.mk_implies (flat prems, concl)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   174
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
(* produces the premise of an alpha-bn rule; we only need to
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
   treat the case special where the binding clause is empty;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
   - if the body is not included in the bn_info, then we either
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
     produce an equation or an alpha-premise
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
   - if the body is included in the bn_info, then we create
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
     either a recursive call to alpha-bn, or no premise  *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
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
   185
  let
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   186
    fun mk_alpha_bn_prem i = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   187
      let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   188
        val arg = nth args i
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   189
        val arg' = nth args' i
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   190
        val ty = fastype_of arg
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   191
      in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   192
        case AList.lookup (op=) bn_args i of
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   193
          NONE => (case (AList.lookup (op=) alpha_map ty) of
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   194
                     NONE =>  [HOLogic.mk_eq (arg, arg')]
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   195
                   | SOME (alpha, _) => [alpha $ arg $ arg'])
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   196
        | SOME (NONE) => []
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   197
        | SOME (SOME bn) => [lookup alpha_bn_map bn $ arg $ arg']
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   198
      end  
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  in
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   200
    case bclause of
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   201
      BC (_, [], bodies) => 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   202
        map HOLogic.mk_Trueprop (flat (map mk_alpha_bn_prem bodies))
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   203
    | _ => mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   204
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
fun mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map (bn_args, (constr, _, arg_tys, is_rec)) bclauses =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   207
  let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   208
    val arg_names = Old_Datatype_Prop.make_tnames arg_tys
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   209
    val arg_names' = Name.variant_list arg_names arg_names
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   210
    val args = map Free (arg_names ~~ arg_tys)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   211
    val args' = map Free (arg_names' ~~ arg_tys)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   212
    val alpha_bn = lookup alpha_bn_map bn_trm
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   213
    val concl = HOLogic.mk_Trueprop (alpha_bn $ list_comb (constr, args) $ list_comb (constr, args'))
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   214
    val prems = map (mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args')) bclauses
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   215
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   216
    Library.foldr Logic.mk_implies (flat prems, concl)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   217
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
fun mk_alpha_bn_intros lthy alpha_map alpha_bn_map constrs_info bclausesss (bn_trm, bn_n, bn_argss) = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   220
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   221
    val nth_constrs_info = nth constrs_info bn_n
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   222
    val nth_bclausess = nth bclausesss bn_n
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   223
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   224
    map2 (mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map) (bn_argss ~~ nth_constrs_info) nth_bclausess
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   225
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   227
fun define_raw_alpha raw_dt_info bn_info bclausesss fvs lthy =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   228
  let
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   229
    val RawDtInfo {raw_dt_names, raw_tys, raw_cns_info, ...} = raw_dt_info
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   230
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   231
    val alpha_names = map (prefix "alpha_" o Long_Name.base_name) raw_dt_names
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   232
    val alpha_tys = map (fn ty => [ty, ty] ---> @{typ bool}) raw_tys
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   233
    val alpha_frees = map Free (alpha_names ~~ alpha_tys)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   234
    val alpha_map = raw_tys ~~ (alpha_frees ~~ fvs)
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   236
    val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   237
    val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   238
    val alpha_bn_names = map (prefix "alpha_") bn_names
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   239
    val alpha_bn_arg_tys = map (nth raw_tys) bn_tys
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   240
    val alpha_bn_tys = map (fn ty => [ty, ty] ---> @{typ "bool"}) alpha_bn_arg_tys
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   241
    val alpha_bn_frees = map Free (alpha_bn_names ~~ alpha_bn_tys)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   242
    val alpha_bn_map = bns ~~ alpha_bn_frees
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   244
    val alpha_intros = map2 (map2 (mk_alpha_intros lthy alpha_map alpha_bn_map)) raw_cns_info bclausesss 
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   245
    val alpha_bn_intros = map (mk_alpha_bn_intros lthy alpha_map alpha_bn_map raw_cns_info bclausesss) bn_info
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   247
    val all_alpha_names = map (fn (a, ty) => ((Binding.name a, ty), NoSyn))
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   248
      (alpha_names @ alpha_bn_names ~~ alpha_tys @ alpha_bn_tys)
3245
017e33849f4d updated to Isabelle 2016-1
Christian Urban <urbanc@in.tum.de>
parents: 3244
diff changeset
   249
    val all_alpha_intros = map (pair Binding.empty_atts) (flat alpha_intros @ flat alpha_bn_intros)
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2407
diff changeset
   250
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   251
    val (alpha_info, lthy') = lthy
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   252
      |> Inductive.add_inductive_i
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   253
       {quiet_mode = true, verbose = false, alt_name = Binding.empty,
3200
995d47b09ab4 removed fork_mono flag
Christian Urban <urbanc@in.tum.de>
parents: 3161
diff changeset
   254
        coind = false, no_elim = false, no_ind = false, skip_mono = false}
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   255
         all_alpha_names [] all_alpha_intros []
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   257
    val all_alpha_trms_loc = #preds alpha_info;
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   258
    val alpha_raw_induct_loc = #raw_induct alpha_info;
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   259
    val alpha_intros_loc = #intrs alpha_info;
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   260
    val alpha_cases_loc = #elims alpha_info;
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   261
    val phi =
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   262
      Proof_Context.export_morphism lthy'
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   263
        (Proof_Context.transfer (Proof_Context.theory_of lthy') lthy);
2888
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   264
    
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   265
    val all_alpha_trms = all_alpha_trms_loc
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   266
      |> map (Morphism.term phi) 
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   267
      |> map Type.legacy_freeze 
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   268
    val alpha_raw_induct = Morphism.thm phi alpha_raw_induct_loc
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   269
    val alpha_intros = map (Morphism.thm phi) alpha_intros_loc
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   270
    val alpha_cases = map (Morphism.thm phi) alpha_cases_loc
2298
Christian Urban <urbanc@in.tum.de>
parents: 2297
diff changeset
   271
2888
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   272
    val (alpha_trms, alpha_bn_trms) = chop (length fvs) all_alpha_trms
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   273
    
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   274
    val alpha_tys = map (domain_type o fastype_of) alpha_trms
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   275
    val alpha_bn_tys = map (domain_type o fastype_of) alpha_bn_trms
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   276
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   277
    val alpha_names = map (fst o dest_Const) alpha_trms  
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   278
    val alpha_bn_names = map (fst o dest_Const) alpha_bn_trms
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   279
  in
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   280
    (AlphaResult
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   281
      {alpha_names = alpha_names,
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   282
       alpha_trms = alpha_trms,
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   283
       alpha_tys = alpha_tys,
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   284
       alpha_bn_names = alpha_bn_names, 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   285
       alpha_bn_trms = alpha_bn_trms,
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   286
       alpha_bn_tys = alpha_bn_tys, 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   287
       alpha_intros = alpha_intros,
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   288
       alpha_cases = alpha_cases,
3245
017e33849f4d updated to Isabelle 2016-1
Christian Urban <urbanc@in.tum.de>
parents: 3244
diff changeset
   289
       alpha_raw_induct = alpha_raw_induct}, Local_Theory.reset lthy')  (* FIXME disrupts context *)
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   290
  end
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   292
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   293
(** induction proofs **)
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   294
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   295
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   296
(* proof by structural induction over data types *)
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   297
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   298
fun induct_prove tys props induct_thm cases_tac ctxt =
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   299
  let
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   300
    val (arg_names, ctxt') =
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   301
      Variable.variant_fixes (replicate (length tys) "x") ctxt
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   302
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   303
    val args = map2 (curry Free) arg_names tys
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   304
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   305
    val true_trms = replicate (length tys) (K @{term True})
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   306
  
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   307
    fun apply_all x fs = map (fn f => f x) fs
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   308
    
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   309
    val goals = 
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   310
        group (props @ (tys ~~ true_trms))
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   311
        |> map snd 
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   312
        |> map2 apply_all args
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   313
        |> map fold_conj
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   314
        |> foldr1 HOLogic.mk_conj
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   315
        |> HOLogic.mk_Trueprop
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   316
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   317
    fun tac ctxt =
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   318
      HEADGOAL 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   319
        (DETERM o (resolve_tac ctxt [induct_thm]) 
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   320
         THEN_ALL_NEW 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   321
           (REPEAT_ALL_NEW (FIRST' [resolve_tac ctxt @{thms TrueI conjI}, cases_tac ctxt])))
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   322
  in
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   323
    Goal.prove ctxt' [] [] goals (fn {context, ...} => tac context)
3045
d0ad264f8c4f updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 3029
diff changeset
   324
    |> singleton (Proof_Context.export ctxt' ctxt)
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   325
    |> Old_Datatype_Aux.split_conj_thm
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   326
    |> map Old_Datatype_Aux.split_conj_thm
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   327
    |> flat
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   328
    |> filter_out (is_true o Thm.concl_of)
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   329
    |> map zero_var_indexes
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   330
  end
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   331
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   332
(* proof by rule induction over the alpha-definitions *)
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   333
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   334
fun alpha_prove alphas props alpha_induct_thm cases_tac ctxt =
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   335
  let
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   336
    val arg_tys = map (domain_type o fastype_of) alphas
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   337
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   338
    val ((arg_names1, arg_names2), ctxt') =
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   339
      ctxt
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   340
      |> Variable.variant_fixes (replicate (length alphas) "x") 
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   341
      ||>> Variable.variant_fixes (replicate (length alphas) "y")
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   342
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   343
    val args1 = map2 (curry Free) arg_names1 arg_tys
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   344
    val args2 = map2 (curry Free) arg_names2 arg_tys
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   345
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   346
    val true_trms = replicate (length alphas) (K @{term True})
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   347
  
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   348
    fun apply_all x fs = map (fn f => f x) fs
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   349
    
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   350
    val goals_rhs = 
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   351
        group (props @ (alphas ~~ true_trms))
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   352
        |> map snd 
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   353
        |> map2 apply_all (args1 ~~ args2)
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   354
        |> map fold_conj
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   355
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   356
    fun apply_trm_pair t (ar1, ar2) = t $ ar1 $ ar2
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   357
    val goals_lhs = map2 apply_trm_pair alphas (args1 ~~ args2)
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   358
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   359
    val goals =
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   360
      (map2 (curry HOLogic.mk_imp) goals_lhs goals_rhs)
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   361
      |> foldr1 HOLogic.mk_conj
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   362
      |> HOLogic.mk_Trueprop
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   363
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   364
    fun tac ctxt =
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   365
      HEADGOAL 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   366
        (DETERM o (resolve_tac ctxt [alpha_induct_thm]) 
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   367
         THEN_ALL_NEW FIRST' [resolve_tac ctxt @{thms TrueI}, cases_tac ctxt])
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   368
  in
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   369
    Goal.prove ctxt' [] [] goals (fn {context, ...} => tac context)
3045
d0ad264f8c4f updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 3029
diff changeset
   370
    |> singleton (Proof_Context.export ctxt' ctxt)
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   371
    |> Old_Datatype_Aux.split_conj_thm
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   372
    |> map (fn th => th RS mp) 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   373
    |> map Old_Datatype_Aux.split_conj_thm
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   374
    |> flat
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   375
    |> filter_out (is_true o Thm.concl_of)
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   376
    |> map zero_var_indexes
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   377
  end
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   378
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   379
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   380
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   381
(** produces the distinctness theorems **)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   382
2926
37c0d7953cba moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
parents: 2922
diff changeset
   383
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   384
(* transforms the distinctness theorems of the constructors 
2888
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   385
   into "not-alphas" of the constructors *)
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   386
fun mk_distinct_goal ty_trm_assoc neq =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   387
  let
2888
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   388
    val (Const (@{const_name "HOL.eq"}, ty_eq) $ lhs $ rhs) = 
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   389
      HOLogic.dest_not (HOLogic.dest_Trueprop neq)
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   390
    val ty_str = fst (dest_Type (domain_type ty_eq))
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   391
  in
2888
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   392
    Const (lookup ty_trm_assoc ty_str, ty_eq) $ lhs $ rhs
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   393
    |> HOLogic.mk_not
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   394
    |> HOLogic.mk_Trueprop
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   395
  end
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   396
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   397
fun distinct_tac ctxt cases_thms distinct_thms =
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   398
  resolve_tac ctxt [notI] THEN' eresolve_tac ctxt cases_thms 
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   399
  THEN_ALL_NEW asm_full_simp_tac (put_simpset HOL_ss ctxt addsimps distinct_thms)
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   400
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   401
fun raw_prove_alpha_distincts ctxt alpha_result raw_dt_info =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   402
  let
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   403
    val AlphaResult {alpha_names, alpha_cases, ...} = alpha_result
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   404
    val RawDtInfo {raw_dt_names, raw_distinct_thms, ...} = raw_dt_info
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   405
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   406
    val ty_trm_assoc = raw_dt_names ~~ alpha_names
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   407
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   408
    fun mk_alpha_distinct raw_distinct_trm =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   409
      let
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   410
        val goal = mk_distinct_goal ty_trm_assoc raw_distinct_trm
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   411
    in
2888
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   412
      Goal.prove ctxt [] [] goal 
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   413
        (K (distinct_tac ctxt alpha_cases raw_distinct_thms 1))
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   414
    end
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   415
  in
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   416
    map (mk_alpha_distinct o Thm.prop_of) raw_distinct_thms
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   417
  end
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   418
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   419
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   420
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   421
(** produces the alpha_eq_iff simplification rules **)
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   422
2475
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2469
diff changeset
   423
(* in case a theorem is of the form (Rel Const Const), it will be
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2469
diff changeset
   424
   rewritten to ((Rel Const = Const) = True) 
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2469
diff changeset
   425
*)
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   426
fun mk_simp_rule thm =
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   427
  case Thm.prop_of thm of
2475
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2469
diff changeset
   428
    @{term "Trueprop"} $ (_ $ Const _ $ Const _) => thm RS @{thm eqTrueI}
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   429
  | _ => thm
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   430
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   431
fun alpha_eq_iff_tac ctxt dist_inj intros elims =
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   432
  SOLVED' (asm_full_simp_tac (put_simpset HOL_ss ctxt addsimps intros)) ORELSE'
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   433
  (resolve_tac ctxt @{thms iffI} THEN' 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   434
    RANGE [eresolve_tac ctxt elims THEN_ALL_NEW asm_full_simp_tac (put_simpset HOL_ss ctxt addsimps dist_inj),
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   435
           asm_full_simp_tac (put_simpset HOL_ss ctxt addsimps intros)])
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   436
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   437
fun mk_alpha_eq_iff_goal thm =
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   438
  let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   439
    val prop = Thm.prop_of thm;
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   440
    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
   441
    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
   442
    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
   443
  in
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   444
    if hyps = [] then HOLogic.mk_Trueprop concl
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   445
    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
   446
  end;
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   447
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   448
fun raw_prove_alpha_eq_iff ctxt alpha_result raw_dt_info =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   449
  let
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   450
    val AlphaResult {alpha_intros, alpha_cases, ...} = alpha_result
2957
01ff621599bc code refactoring; introduced a record for raw_dt_info
Christian Urban <urbanc@in.tum.de>
parents: 2928
diff changeset
   451
    val RawDtInfo {raw_distinct_thms, raw_inject_thms, ...} = raw_dt_info
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   452
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   453
    val ((_, thms_imp), ctxt') = Variable.import false alpha_intros ctxt;
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   454
    val goals = map mk_alpha_eq_iff_goal thms_imp;
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   455
    val tac = alpha_eq_iff_tac ctxt (raw_distinct_thms @ raw_inject_thms) alpha_intros alpha_cases 1;
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   456
    val thms = map (fn goal => Goal.prove ctxt' [] [] goal (K tac)) goals;
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   457
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   458
    Variable.export ctxt' ctxt thms
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   459
    |> map mk_simp_rule
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   460
  end
2300
9fb315392493 added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents: 2299
diff changeset
   461
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   462
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   463
(** reflexivity proof for the alphas **)
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   464
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   465
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
   466
2480
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
   467
fun cases_tac intros ctxt =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   468
  let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   469
    val prod_simps = @{thms split_conv prod_alpha_def rel_prod_conv}
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   470
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   471
    val unbound_tac = REPEAT o (eresolve_tac ctxt @{thms conjE}) THEN' assume_tac ctxt  
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   472
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   473
    val bound_tac = 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   474
      EVERY' [ resolve_tac ctxt [exi_zero], 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   475
               resolve_tac ctxt @{thms alpha_refl}, 
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   476
               asm_full_simp_tac (put_simpset HOL_ss ctxt addsimps prod_simps) ]
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   477
  in
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   478
    resolve_tac ctxt intros THEN_ALL_NEW
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   479
      FIRST' [resolve_tac ctxt @{thms refl}, unbound_tac, bound_tac]
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   480
  end
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   481
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   482
fun raw_prove_refl ctxt alpha_result raw_dt_induct =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   483
  let
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   484
    val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_bn_tys, alpha_intros, ...} = 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   485
      alpha_result
2480
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
   486
    
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
   487
    val props = 
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
   488
      map (fn (ty, c) => (ty, fn x => c $ x $ x)) 
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   489
        ((alpha_tys ~~ alpha_trms) @ (alpha_bn_tys ~~ alpha_bn_trms))
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   490
  in
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   491
    induct_prove alpha_tys props raw_dt_induct (cases_tac alpha_intros) ctxt 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   492
  end
2316
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   493
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   494
08bbde090a17 also symmetry
Christian Urban <urbanc@in.tum.de>
parents: 2314
diff changeset
   495
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   496
(** symmetry proof for the alphas **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   497
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   498
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
   499
  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
   500
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   501
(* for premises that contain binders *)
2868
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2765
diff changeset
   502
fun prem_bound_tac pred_names alpha_eqvt ctxt = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   503
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   504
    fun trans_prem_tac pred_names ctxt = 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   505
      SUBPROOF (fn {prems, context = ctxt', ...} => 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   506
        let
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   507
          val prems' = map (transform_prem1 ctxt' pred_names) prems
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   508
        in
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   509
          resolve_tac ctxt' prems' 1
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   510
        end) ctxt
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   511
    val prod_simps = @{thms split_conv permute_prod.simps prod_alpha_def rel_prod_conv alphas}
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   512
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   513
    EVERY' 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   514
      [ eresolve_tac ctxt [exi_neg],
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   515
        resolve_tac ctxt @{thms alpha_sym_eqvt},
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   516
        asm_full_simp_tac (put_simpset HOL_ss ctxt addsimps prod_simps),
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   517
        eqvt_tac ctxt (eqvt_relaxed_config addpres alpha_eqvt) THEN'
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   518
        resolve_tac ctxt @{thms refl},
2868
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2765
diff changeset
   519
        trans_prem_tac pred_names ctxt] 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   520
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   521
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   522
fun raw_prove_sym ctxt alpha_result alpha_eqvt =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   523
  let
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   524
    val AlphaResult {alpha_names, alpha_trms, alpha_bn_names, alpha_bn_trms, 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   525
      alpha_intros, alpha_raw_induct, ...} = alpha_result
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   526
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   527
    val alpha_trms = alpha_trms @ alpha_bn_trms
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   528
    val alpha_names = alpha_names @ alpha_bn_names 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   529
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   530
    val props = map (fn t => fn (x, y) => t $ y $ x) alpha_trms
2868
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2765
diff changeset
   531
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   532
    fun tac ctxt = 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   533
      resolve_tac ctxt alpha_intros THEN_ALL_NEW 
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   534
      FIRST' [assume_tac ctxt,
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   535
        resolve_tac ctxt @{thms sym} THEN' assume_tac ctxt,
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   536
        prem_bound_tac alpha_names alpha_eqvt ctxt]
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   537
  in
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   538
    alpha_prove alpha_trms (alpha_trms ~~ props) alpha_raw_induct tac ctxt 
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   539
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   540
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   541
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   542
(** transitivity proof for alphas **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   543
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   544
(* 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
   545
fun ecases_tac cases = 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   546
  Subgoal.FOCUS (fn {context = ctxt, prems, ...} =>
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   547
    HEADGOAL (resolve_tac ctxt cases THEN' resolve_tac ctxt [List.last prems]))
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   548
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   549
fun aatac pred_names = 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   550
  SUBPROOF (fn {context = ctxt, prems, ...} =>
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   551
    HEADGOAL (resolve_tac ctxt (map (transform_prem1 ctxt pred_names) prems)))
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   552
  
2314
1a14c4171a51 premerge
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
   553
(* instantiates exI with the permutation p + q *)
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   554
val perm_inst_tac =
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   555
  Subgoal.FOCUS (fn {context = ctxt, params, ...} => 
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   556
    let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   557
      val (p, q) = apply2 snd (last2 params)
3123
998978623654 Update from Isabelle Wed Feb 15 23:19:30
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3045
diff changeset
   558
      val pq_inst = foldl1 (uncurry Thm.apply) [@{cterm "plus::perm => perm => perm"}, p, q]
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   559
      val exi_inst = Thm.instantiate' [SOME (@{ctyp "perm"})] [NONE, SOME pq_inst] @{thm exI}
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   560
    in
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   561
      HEADGOAL (resolve_tac ctxt [exi_inst])
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   562
    end)
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
   563
2868
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2765
diff changeset
   564
fun non_trivial_cases_tac pred_names intros alpha_eqvt ctxt = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   565
  let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   566
    val prod_simps = @{thms split_conv alphas permute_prod.simps prod_alpha_def rel_prod_conv}
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   567
  in
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   568
    resolve_tac ctxt intros
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   569
    THEN_ALL_NEW (asm_simp_tac (put_simpset HOL_basic_ss ctxt) THEN' 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   570
      TRY o EVERY'   (* if binders are present *)
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   571
        [ eresolve_tac ctxt @{thms exE},
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   572
          eresolve_tac ctxt @{thms exE},
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   573
          perm_inst_tac ctxt, 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   574
          resolve_tac ctxt @{thms alpha_trans_eqvt},
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   575
          assume_tac ctxt,
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   576
          aatac pred_names ctxt, 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   577
          eqvt_tac ctxt (eqvt_relaxed_config addpres alpha_eqvt) THEN'
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   578
          resolve_tac ctxt @{thms refl},
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   579
          asm_full_simp_tac (put_simpset HOL_ss ctxt addsimps prod_simps) ])
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   580
  end
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   581
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   582
fun prove_trans_tac alpha_result raw_dt_thms alpha_eqvt ctxt =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   583
  let
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   584
    val AlphaResult {alpha_names, alpha_bn_names, alpha_intros, alpha_cases, ...} = alpha_result
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   585
    val alpha_names = alpha_names @ alpha_bn_names 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   586
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   587
    fun all_cases ctxt = 
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   588
      asm_full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps raw_dt_thms) 
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   589
      THEN' TRY o non_trivial_cases_tac alpha_names alpha_intros alpha_eqvt ctxt
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   590
  in
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   591
    EVERY' [ resolve_tac ctxt @{thms allI},
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   592
      resolve_tac ctxt @{thms impI}, 
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   593
      ecases_tac alpha_cases ctxt THEN_ALL_NEW all_cases ctxt ]
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   594
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   595
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2387
diff changeset
   596
fun prep_trans_goal alpha_trm (arg1, arg2) =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   597
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   598
    val arg_ty = fastype_of arg1
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   599
    val mid = alpha_trm $ arg2 $ (Bound 0)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   600
    val rhs = alpha_trm $ arg1 $ (Bound 0) 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   601
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   602
    HOLogic.all_const arg_ty $ Abs ("z", arg_ty, HOLogic.mk_imp (mid, rhs))
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   603
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   604
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   605
fun raw_prove_trans ctxt alpha_result raw_dt_thms alpha_eqvt =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   606
  let
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   607
    val AlphaResult {alpha_names, alpha_trms, alpha_bn_names, alpha_bn_trms, 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   608
      alpha_raw_induct, ...} = alpha_result
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   609
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   610
    val alpha_trms = alpha_trms @ alpha_bn_trms
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   611
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   612
    val props = map prep_trans_goal alpha_trms
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   613
  in
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   614
    alpha_prove alpha_trms (alpha_trms ~~ props) alpha_raw_induct
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   615
      (prove_trans_tac alpha_result raw_dt_thms alpha_eqvt) ctxt
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   616
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2300
diff changeset
   617
2390
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   618
920366e646b0 further simplification with alpha_prove
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   619
(** proves the equivp predicate for all alphas **)
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   620
2592
98236fbd8aa6 updated to Isabelle 2nd December
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   621
val reflp_def' = 
98236fbd8aa6 updated to Isabelle 2nd December
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   622
  @{lemma "reflp R == !x. R x x" by (simp add: reflp_def refl_on_def)}
98236fbd8aa6 updated to Isabelle 2nd December
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   623
98236fbd8aa6 updated to Isabelle 2nd December
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   624
val symp_def' =
98236fbd8aa6 updated to Isabelle 2nd December
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   625
  @{lemma "symp R == !x y . R x y --> R y x" by (simp add: symp_def sym_def)}
98236fbd8aa6 updated to Isabelle 2nd December
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   626
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   627
val transp_def' =
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   628
  @{lemma "transp R == !x y. R x y --> (!z. R y z --> R x z)" 
2592
98236fbd8aa6 updated to Isabelle 2nd December
Christian Urban <urbanc@in.tum.de>
parents: 2561
diff changeset
   629
    by (rule eq_reflection, auto simp add: trans_def transp_def)}
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   630
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   631
fun raw_prove_equivp ctxt alpha_result refl symm trans = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   632
  let
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   633
    val AlphaResult {alpha_trms, alpha_bn_trms, ...} = alpha_result 
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   634
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   635
    val refl' = map (fold_rule ctxt [reflp_def'] o atomize ctxt) refl
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   636
    val symm' = map (fold_rule ctxt [symp_def'] o atomize ctxt) symm
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   637
    val trans' = map (fold_rule ctxt [transp_def'] o atomize ctxt) trans
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   638
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   639
    fun prep_goal t = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   640
      HOLogic.mk_Trueprop (Const (@{const_name "equivp"}, fastype_of t --> @{typ bool}) $ t) 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   641
  in    
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   642
    Goal.prove_common ctxt NONE [] [] (map prep_goal (alpha_trms @ alpha_bn_trms))
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   643
    (K (HEADGOAL (Goal.conjunction_tac THEN_ALL_NEW (resolve_tac ctxt @{thms equivpI} THEN' 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   644
       RANGE [resolve_tac ctxt refl', resolve_tac ctxt symm', resolve_tac ctxt trans']))))
2927
116f9ba4f59f combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
parents: 2926
diff changeset
   645
    |> chop (length alpha_trms)
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   646
  end
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   647
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   648
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   649
(* 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
   650
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   651
fun raw_prove_bn_imp_tac alpha_result ctxt = 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   652
  SUBPROOF (fn {prems, context = ctxt', ...} => 
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   653
    let
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   654
      val AlphaResult {alpha_names, alpha_intros, ...} = alpha_result 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   655
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   656
      val prems' = flat (map Old_Datatype_Aux.split_conj_thm prems)
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   657
      val prems'' = map (transform_prem1 ctxt' alpha_names) prems'
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   658
    in
2322
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   659
      HEADGOAL 
24de7e548094 proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents: 2320
diff changeset
   660
        (REPEAT_ALL_NEW 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   661
           (FIRST' [ resolve_tac ctxt' @{thms TrueI}, 
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   662
                     resolve_tac ctxt' @{thms conjI}, 
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   663
                     resolve_tac ctxt' prems', 
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   664
                     resolve_tac ctxt' prems'',
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   665
                     resolve_tac ctxt' alpha_intros ]))
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   666
    end) ctxt
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   667
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   668
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   669
fun raw_prove_bn_imp ctxt alpha_result =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   670
  let
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   671
    val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_raw_induct, ...} = alpha_result 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   672
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   673
    val arg_ty = domain_type o fastype_of 
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   674
    val ty_assoc = alpha_tys ~~ alpha_trms
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   675
    val props = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => t $ x $ y)) alpha_bn_trms
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   676
  in
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   677
    alpha_prove (alpha_trms @ alpha_bn_trms) props alpha_raw_induct 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   678
      (raw_prove_bn_imp_tac alpha_result) ctxt
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   679
  end
2320
d835a2771608 prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2316
diff changeset
   680
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   681
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
   682
(* respectfulness for fv_raw / bn_raw *)
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   683
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   684
fun raw_fv_bn_rsp_aux ctxt alpha_result fvs bns fv_bns simps =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   685
  let
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   686
    val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_raw_induct, ...} = alpha_result 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   687
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   688
    val arg_ty = domain_type o fastype_of 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   689
    val ty_assoc = alpha_tys ~~ alpha_trms
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   690
    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
   691
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   692
    val prop1 = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => mk_eq' t x y)) fvs
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   693
    val prop2 = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => mk_eq' t x y)) (bns @ fv_bns)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   694
    val prop3 = map2 (fn t1 => fn t2 => (t1, fn (x, y) => mk_eq' t2 x y)) alpha_bn_trms fv_bns
2888
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   695
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   696
    val simpset =
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   697
      put_simpset HOL_ss ctxt addsimps (simps @ @{thms alphas prod_fv.simps set_simps append.simps} 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   698
      @ @{thms Un_assoc Un_insert_left Un_empty_right Un_empty_left}) 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   699
  in
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   700
    alpha_prove (alpha_trms @ alpha_bn_trms) (prop1 @ prop2 @ prop3) alpha_raw_induct 
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   701
      (K (asm_full_simp_tac simpset)) ctxt
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   702
  end
2387
082d9fd28f89 helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2385
diff changeset
   703
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   704
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
(* respectfulness for size *)
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   706
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   707
fun raw_size_rsp_aux ctxt alpha_result simps =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   708
  let
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   709
    val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_bn_tys, alpha_raw_induct, ...} = 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   710
      alpha_result 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   711
    
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   712
    fun mk_prop ty (x, y) = HOLogic.mk_eq 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   713
      (HOLogic.size_const ty $ x, HOLogic.size_const ty $ y)
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   714
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   715
    val props = (alpha_trms @ alpha_bn_trms) ~~ (map mk_prop (alpha_tys @ alpha_bn_tys)) 
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   716
  
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   717
    val simpset =
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   718
      put_simpset HOL_ss ctxt addsimps (simps @ @{thms alphas prod_alpha_def rel_prod_conv 
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   719
      permute_prod_def prod.case prod.rec})
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   720
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   721
    val tac = (TRY o REPEAT o eresolve_tac ctxt @{thms exE}) THEN' asm_full_simp_tac simpset
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   722
  in
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   723
    alpha_prove (alpha_trms @ alpha_bn_trms) props alpha_raw_induct (K tac) ctxt
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   724
  end
2392
9294d7cec5e2 proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents: 2391
diff changeset
   725
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
   726
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   727
(* respectfulness for constructors *)
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   728
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   729
fun raw_constr_rsp_tac ctxt alpha_intros simps = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   730
  let
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   731
    val pre_simpset = put_simpset HOL_ss ctxt addsimps @{thms rel_fun_def}
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   732
    val post_simpset = put_simpset HOL_ss ctxt addsimps @{thms alphas prod_alpha_def rel_prod_conv 
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   733
      prod_fv.simps fresh_star_zero permute_zero prod.case} @ simps
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   734
  in
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   735
    asm_full_simp_tac pre_simpset
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   736
    THEN' REPEAT o (resolve_tac ctxt @{thms allI impI})
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   737
    THEN' resolve_tac ctxt alpha_intros
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   738
    THEN_ALL_NEW (TRY o (resolve_tac ctxt [exi_zero]) THEN' asm_full_simp_tac post_simpset)
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   739
  end
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   740
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   741
fun raw_constrs_rsp ctxt alpha_result constrs simps =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   742
  let
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   743
    val AlphaResult {alpha_trms, alpha_tys, alpha_intros, ...} = alpha_result 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   744
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   745
    fun lookup ty = 
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   746
      case AList.lookup (op=) (alpha_tys ~~ alpha_trms) ty of
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   747
        NONE => HOLogic.eq_const ty
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   748
      | SOME alpha => alpha 
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   749
  
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   750
    fun rel_fun_app (t1, t2) = 
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   751
      Const (@{const_name "rel_fun"}, dummyT) $ t1 $ t2
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   752
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   753
    fun prep_goal trm =
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   754
      trm
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   755
      |> strip_type o fastype_of
2888
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   756
      |> (fn (tys, ty) => tys @ [ty])
eda5aeb056a6 fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
parents: 2868
diff changeset
   757
      |> map lookup
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   758
      |> foldr1 rel_fun_app
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   759
      |> (fn t => t $ trm $ trm)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   760
      |> Syntax.check_term ctxt
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   761
      |> HOLogic.mk_Trueprop
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   762
  in
3161
aa1ba91ed1ff Pass proper rsp theorems for constructors and for size
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents: 3124
diff changeset
   763
    map (fn constrs =>
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   764
    Goal.prove_common ctxt NONE [] [] (map prep_goal constrs)
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   765
      (K (HEADGOAL 
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3200
diff changeset
   766
        (Goal.conjunction_tac THEN_ALL_NEW raw_constr_rsp_tac ctxt alpha_intros simps)))) constrs
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   767
  end
2395
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   768
79e493880801 rsp for constructors
Christian Urban <urbanc@in.tum.de>
parents: 2393
diff changeset
   769
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   770
(* rsp lemmas for alpha_bn relations *)
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   771
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   772
val rsp_equivp =
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   773
  @{lemma "[|equivp Q; !!x y. R x y ==> Q x y|] ==> (R ===> R ===> op =) Q Q"
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   774
    by (simp only: rel_fun_def equivp_def, metis)}
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   775
2440
0a36825b16c1 "isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
parents: 2438
diff changeset
   776
0a36825b16c1 "isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
parents: 2438
diff changeset
   777
(* we have to reorder the alpha_bn_imps theorems in order
0a36825b16c1 "isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
parents: 2438
diff changeset
   778
   to be in order with alpha_bn_trms *)
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   779
fun raw_alpha_bn_rsp alpha_result alpha_bn_equivp alpha_bn_imps =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   780
  let
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   781
    val AlphaResult {alpha_bn_trms, ...} = alpha_result 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   782
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   783
    fun mk_map thm =
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   784
      thm |> `Thm.prop_of
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   785
          |>> List.last  o snd o strip_comb
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   786
          |>> HOLogic.dest_Trueprop
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   787
          |>> head_of
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   788
          |>> fst o dest_Const
2440
0a36825b16c1 "isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
parents: 2438
diff changeset
   789
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   790
    val alpha_bn_imps' = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   791
      map (lookup (map mk_map alpha_bn_imps) o fst o dest_Const) alpha_bn_trms
2440
0a36825b16c1 "isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
parents: 2438
diff changeset
   792
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   793
    fun mk_thm thm1 thm2 = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   794
      (forall_intr_vars thm2) COMP (thm1 RS rsp_equivp)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   795
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   796
    map2 mk_thm alpha_bn_equivp alpha_bn_imps'
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   797
  end
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   798
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   799
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   800
(* rsp for permute_bn functions *)
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   801
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   802
val perm_bn_rsp = @{lemma "(!x y p. R x y --> R (f p x) (f p y)) ==> (op= ===> R ===> R) f f"
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   803
 by (simp add: rel_fun_def)}
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   804
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   805
fun raw_prove_perm_bn_tac alpha_result simps ctxt = 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   806
  SUBPROOF (fn {prems, context = ctxt', ...} => 
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   807
    let
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   808
      val AlphaResult {alpha_names, alpha_bn_names, alpha_intros, ...} = alpha_result 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3229
diff changeset
   809
      val prems' = flat (map Old_Datatype_Aux.split_conj_thm prems)
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   810
      val prems'' = map (transform_prem1 ctxt' (alpha_names @ alpha_bn_names)) prems'
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   811
    in
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   812
      HEADGOAL 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   813
        (simp_tac (put_simpset HOL_basic_ss ctxt' addsimps (simps @ prems'))
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   814
         THEN' TRY o REPEAT_ALL_NEW 
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   815
           (FIRST' [ resolve_tac ctxt' @{thms TrueI}, 
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   816
                     resolve_tac ctxt' @{thms conjI}, 
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   817
                     resolve_tac ctxt' @{thms refl},
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   818
                     resolve_tac ctxt' prems', 
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   819
                     resolve_tac ctxt' prems'',
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   820
                     resolve_tac ctxt' alpha_intros ]))
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   821
    end) ctxt
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   822
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   823
fun raw_perm_bn_rsp ctxt alpha_result perm_bns simps =
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   824
  let
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   825
    val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_bn_tys, alpha_raw_induct, ...} = 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   826
      alpha_result 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   827
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   828
    val perm_bn_ty = range_type o range_type o fastype_of
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   829
    val ty_assoc = (alpha_tys @ alpha_bn_tys) ~~ (alpha_trms @ alpha_bn_trms)
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   830
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   831
    val ([p], ctxt') = Variable.variant_fixes ["p"] ctxt
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   832
    val p = Free (p, @{typ perm})
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   833
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   834
    fun mk_prop t =
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   835
      let
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   836
        val alpha_trm = lookup ty_assoc (perm_bn_ty t)
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   837
      in
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   838
        (alpha_trm, fn (x, y) => alpha_trm $ (t $ p $ x) $ (t $ p $ y))
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   839
      end
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   840
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   841
    val goals = map mk_prop perm_bns    
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   842
  in
2928
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   843
    alpha_prove (alpha_trms @ alpha_bn_trms) goals alpha_raw_induct 
c537d43c09f1 more code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2927
diff changeset
   844
      (raw_prove_perm_bn_tac alpha_result simps) ctxt
3045
d0ad264f8c4f updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 3029
diff changeset
   845
     |> Proof_Context.export ctxt' ctxt
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   846
     |> map (atomize ctxt)
2561
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   847
     |> map single
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   848
     |> map (curry (op OF) perm_bn_rsp)
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   849
  end
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   850
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   851
7926f1cb45eb respectfulness for permute_bn functions
Christian Urban <urbanc@in.tum.de>
parents: 2560
diff changeset
   852
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   853
(* transformation of the natural rsp-lemmas into standard form *)
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   854
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   855
val fun_rsp = @{lemma
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   856
  "(!x y. R x y --> f x = f y) ==> (R ===> (op =)) f f" by (simp add: rel_fun_def)}
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   857
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   858
fun mk_funs_rsp ctxt thm = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   859
  thm
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   860
  |> atomize ctxt
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   861
  |> single
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   862
  |> 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
   863
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   864
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   865
val permute_rsp = @{lemma 
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   866
  "(!x y p. R x y --> R (permute p x) (permute p y)) 
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   867
     ==> ((op =) ===> R ===> R) permute permute"  by (simp add: rel_fun_def)}
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   868
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   869
fun mk_alpha_permute_rsp ctxt thm = 
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   870
  thm
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   871
  |> atomize ctxt
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   872
  |> single
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   873
  |> curry (op OF) permute_rsp
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2395
diff changeset
   874
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
   875
d9a0cf26a88c added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2392
diff changeset
   876
2404
66ae73fd66c0 added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   877
2297
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   878
end (* structure *)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   879