Nominal/nominal_dt_quot.ML
author Christian Urban <urbanc@in.tum.de>
Mon, 06 Dec 2010 17:11:34 +0000
changeset 2595 07f775729e90
parent 2574 50da1be9a7e5
child 2598 b136721eedb2
permissions -rw-r--r--
moved code from nominal_dt_supp to nominal_dt_quot
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(*  Title:      nominal_dt_alpha.ML
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
    Author:     Christian Urban
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
    Author:     Cezary Kaliszyk
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
2595
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
     5
  Performing quotient constructions, lifting theorems and
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
     6
  deriving support propoerties for the quotient types.
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
*)
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
signature NOMINAL_DT_QUOT =
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
sig
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    11
  val define_qtypes: (string list * binding * mixfix) list -> typ list -> term list -> 
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
    thm list -> local_theory -> Quotient_Info.quotdata_info list * local_theory
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    14
  val define_qconsts: typ list -> (string  * term * mixfix) list -> local_theory -> 
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
    Quotient_Info.qconsts_info list * local_theory
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
    16
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
    17
  val define_qperms: typ list -> string list -> (string * sort) list -> 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
    18
    (string * term * mixfix) list -> thm list -> local_theory -> local_theory
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    19
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
    20
  val define_qsizes: typ list -> string list -> (string * sort) list -> 
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
    21
    (string * term * mixfix) list -> local_theory -> local_theory
2426
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
    22
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2433
diff changeset
    23
  val lift_thms: typ list -> thm list -> thm list -> Proof.context -> thm list * Proof.context
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: 2434
diff changeset
    24
2595
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    25
  val prove_supports: Proof.context -> thm list -> term list -> thm list  
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    26
  val prove_fsupp: Proof.context -> typ list -> thm -> thm list -> thm list
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    27
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    28
  val fs_instance: typ list -> string list -> (string * sort) list -> thm list ->  
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    29
    local_theory -> local_theory
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    30
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    31
  val prove_fv_supp: typ list -> term list -> term list -> term list -> term list -> thm list -> 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    32
    thm list -> thm list -> thm list -> thm -> bclause list list -> Proof.context -> thm list 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    33
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    34
  val prove_bns_finite: typ list -> term list -> thm -> thm list -> Proof.context -> thm list
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    35
 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    36
  val prove_perm_bn_alpha_thms: typ list -> term list -> term list -> thm -> thm list -> thm list ->
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    37
    thm list -> Proof.context -> thm list
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
    38
  
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
end
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
structure Nominal_Dt_Quot: NOMINAL_DT_QUOT =
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
struct
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
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: 2434
diff changeset
    44
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
(* defines the quotient types *)
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    46
fun define_qtypes qtys_descr alpha_tys alpha_trms alpha_equivp_thms lthy =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    47
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    48
    val qty_args1 = map2 (fn ty => fn trm => (ty, trm, false)) alpha_tys alpha_trms
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    49
    val qty_args2 = (qtys_descr ~~ qty_args1) ~~ alpha_equivp_thms
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    50
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    51
    fold_map Quotient_Type.add_quotient_type qty_args2 lthy
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    52
  end 
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
2338
e1764a73c292 slight cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2337
diff changeset
    54
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
(* defines quotient constants *)
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    56
fun define_qconsts qtys consts_specs lthy =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    57
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    58
    val (qconst_infos, lthy') = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    59
      fold_map (Quotient_Def.lift_raw_const qtys) consts_specs lthy
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    60
    val phi = ProofContext.export_morphism lthy' lthy
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    61
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    62
    (map (Quotient_Info.transform_qconsts phi) qconst_infos, lthy')
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    63
  end
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    66
(* defines the quotient permutations and proves pt-class *)
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
    67
fun define_qperms qtys qfull_ty_names tvs perm_specs raw_perm_laws lthy =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    68
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    69
    val lthy1 = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    70
      lthy
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    71
      |> Local_Theory.exit_global
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    72
      |> Class.instantiation (qfull_ty_names, tvs, @{sort pt}) 
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2396
diff changeset
    73
  
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    74
    val (qs, lthy2) = define_qconsts qtys perm_specs lthy1
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
    75
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    76
    val ((_, raw_perm_laws'), lthy3) = Variable.importT raw_perm_laws lthy2
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2396
diff changeset
    77
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    78
    val lifted_perm_laws = 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    79
      map (Quotient_Tacs.lifted lthy3 qtys []) raw_perm_laws'
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    80
      |> Variable.exportT lthy3 lthy2
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2396
diff changeset
    81
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    82
    fun tac _ =
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    83
      Class.intro_classes_tac [] THEN
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    84
        (ALLGOALS (resolve_tac lifted_perm_laws))
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
    lthy2
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    87
    |> Class.prove_instantiation_exit tac 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    88
    |> Named_Target.theory_init
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    89
  end
2346
4c5881455923 more on the paper
Christian Urban <urbanc@in.tum.de>
parents: 2338
diff changeset
    90
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    92
(* defines the size functions and proves size-class *)
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
    93
fun define_qsizes qtys qfull_ty_names tvs size_specs lthy =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    94
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    95
    val tac = K (Class.intro_classes_tac [])
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    96
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    97
    lthy
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    98
    |> Local_Theory.exit_global
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
    99
    |> Class.instantiation (qfull_ty_names, tvs, @{sort size})
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   100
    |> snd o (define_qconsts qtys size_specs)
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   101
    |> Class.prove_instantiation_exit tac
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   102
    |> Named_Target.theory_init
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   103
  end
2400
c6d30d5f5ba1 defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   104
2426
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   105
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: 2434
diff changeset
   106
(* lifts a theorem and cleans all "_raw" parts
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   107
   from variable names *)
2426
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   108
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   109
local
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   110
  val any = Scan.one (Symbol.not_eof)
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   111
  val raw = Scan.this_string "_raw"
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   112
  val exclude =
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   113
    Scan.repeat (Scan.unless raw any) --| raw >> implode
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   114
  val parser = Scan.repeat (exclude || any)
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   115
in
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   116
  fun unraw_str s =
2574
50da1be9a7e5 current isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2476
diff changeset
   117
    s |> raw_explode
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   118
      |> Scan.finite Symbol.stopper parser >> implode 
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   119
      |> fst
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2430
diff changeset
   120
end
2426
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   121
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   122
fun unraw_vars_thm thm =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   123
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   124
    fun unraw_var_str ((s, i), T) = ((unraw_str s, i), T)
2426
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   125
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   126
    val vars = Term.add_vars (prop_of thm) []
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   127
    val vars' = map (Var o unraw_var_str) vars
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
    Thm.certify_instantiate ([], (vars ~~ vars')) thm
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   130
  end
2426
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   131
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   132
fun unraw_bounds_thm th =
2476
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   133
  let
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   134
    val trm = Thm.prop_of th
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   135
    val trm' = Term.map_abs_vars unraw_str trm
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   136
  in
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   137
    Thm.rename_boundvars trm trm' th
8f8652a8107f tuned (to conform with indentation policy of Markus)
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   138
  end
2426
deb5be0115a7 moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents: 2401
diff changeset
   139
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2433
diff changeset
   140
fun lift_thms qtys simps thms ctxt =
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2433
diff changeset
   141
  (map (Quotient_Tacs.lifted ctxt qtys simps
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2433
diff changeset
   142
        #> unraw_bounds_thm
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2433
diff changeset
   143
        #> unraw_vars_thm
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2433
diff changeset
   144
        #> Drule.zero_var_indexes) thms, ctxt)
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2433
diff changeset
   145
2595
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   146
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   147
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   148
fun mk_supports_goal ctxt qtrm =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   149
  let  
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   150
    val vs = fresh_args ctxt qtrm
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   151
    val rhs = list_comb (qtrm, vs)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   152
    val lhs = fold (curry HOLogic.mk_prod) vs @{term "()"}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   153
      |> mk_supp
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   154
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   155
    mk_supports lhs rhs
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   156
    |> HOLogic.mk_Trueprop
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   157
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   158
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   159
fun supports_tac ctxt perm_simps =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   160
  let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   161
    val ss1 = HOL_basic_ss addsimps @{thms supports_def fresh_def[symmetric]}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   162
    val ss2 = HOL_ss addsimps @{thms swap_fresh_fresh fresh_Pair}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   163
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   164
    EVERY' [ simp_tac ss1,
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   165
             Nominal_Permeq.eqvt_strict_tac ctxt perm_simps [],
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   166
             simp_tac ss2 ]
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   167
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   168
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   169
fun prove_supports_single ctxt perm_simps qtrm =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   170
  let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   171
    val goal = mk_supports_goal ctxt qtrm 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   172
    val ctxt' = Variable.auto_fixes goal ctxt
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   173
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   174
    Goal.prove ctxt' [] [] goal
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   175
      (K (HEADGOAL (supports_tac ctxt perm_simps)))
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   176
    |> singleton (ProofContext.export ctxt' ctxt)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   177
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   178
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   179
fun prove_supports ctxt perm_simps qtrms =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   180
  map (prove_supports_single ctxt perm_simps) qtrms
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   181
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   182
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   183
(* finite supp lemmas for qtypes *)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   184
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   185
fun prove_fsupp ctxt qtys qinduct qsupports_thms =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   186
  let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   187
    val (vs, ctxt') = Variable.variant_fixes (replicate (length qtys) "x") ctxt
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   188
    val goals = vs ~~ qtys
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   189
      |> map Free
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   190
      |> map (mk_finite o mk_supp)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   191
      |> foldr1 (HOLogic.mk_conj)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   192
      |> HOLogic.mk_Trueprop
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   193
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   194
    val tac = 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   195
      EVERY' [ rtac @{thm supports_finite},
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   196
               resolve_tac qsupports_thms,
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   197
               asm_simp_tac (HOL_ss addsimps @{thms finite_supp supp_Pair finite_Un}) ]
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   198
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   199
    Goal.prove ctxt' [] [] goals
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   200
      (K (HEADGOAL (rtac qinduct THEN_ALL_NEW tac)))
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   201
    |> singleton (ProofContext.export ctxt' ctxt)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   202
    |> Datatype_Aux.split_conj_thm
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   203
    |> map zero_var_indexes
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   204
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   205
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   206
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   207
(* finite supp instances *)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   208
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   209
fun fs_instance qtys qfull_ty_names tvs qfsupp_thms lthy =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   210
  let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   211
    val lthy1 = 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   212
      lthy
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   213
      |> Local_Theory.exit_global
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   214
      |> Class.instantiation (qfull_ty_names, tvs, @{sort fs}) 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   215
  
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   216
    fun tac _ =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   217
      Class.intro_classes_tac [] THEN
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   218
        (ALLGOALS (resolve_tac qfsupp_thms))
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   219
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   220
    lthy1
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   221
    |> Class.prove_instantiation_exit tac 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   222
    |> Named_Target.theory_init
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   223
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   224
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   225
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   226
(* proves that fv and fv_bn equals supp *)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   227
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   228
fun gen_mk_goals fv supp =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   229
  let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   230
    val arg_ty = 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   231
      fastype_of fv
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   232
      |> domain_type
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   233
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   234
    (arg_ty, fn x => HOLogic.mk_eq (fv $ x, supp x))
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   235
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   236
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   237
fun mk_fvs_goals fv = gen_mk_goals fv mk_supp
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   238
fun mk_fv_bns_goals fv_bn alpha_bn = gen_mk_goals fv_bn (mk_supp_rel alpha_bn)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   239
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   240
fun add_ss thms =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   241
  HOL_basic_ss addsimps thms
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   242
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   243
fun symmetric thms = 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   244
  map (fn thm => thm RS @{thm sym}) thms
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   245
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   246
val supp_Abs_set = @{thms supp_Abs(1)[symmetric]}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   247
val supp_Abs_res = @{thms supp_Abs(2)[symmetric]}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   248
val supp_Abs_lst = @{thms supp_Abs(3)[symmetric]}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   249
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   250
fun mk_supp_abs ctxt (BC (Set, _, _)) = EqSubst.eqsubst_tac ctxt [1] supp_Abs_set 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   251
  | mk_supp_abs ctxt (BC (Res, _, _)) = EqSubst.eqsubst_tac ctxt [1] supp_Abs_res
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   252
  | mk_supp_abs ctxt (BC (Lst, _, _)) = EqSubst.eqsubst_tac ctxt [1] supp_Abs_lst
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   253
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   254
fun mk_supp_abs_tac ctxt [] = []
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   255
  | mk_supp_abs_tac ctxt (BC (_, [], _)::xs) = mk_supp_abs_tac ctxt xs
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   256
  | mk_supp_abs_tac ctxt (bc::xs) = (DETERM o mk_supp_abs ctxt bc)::mk_supp_abs_tac ctxt xs
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   257
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   258
fun mk_bn_supp_abs_tac trm =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   259
  trm
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   260
  |> fastype_of
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   261
  |> body_type
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   262
  |> (fn ty => case ty of
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   263
        @{typ "atom set"}  => simp_tac (add_ss supp_Abs_set)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   264
      | @{typ "atom list"} => simp_tac (add_ss supp_Abs_lst)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   265
      | _ => raise TERM ("mk_bn_supp_abs_tac", [trm]))
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   266
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   267
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   268
val thms1 = @{thms supp_Pair supp_eqvt[symmetric] Un_assoc conj_assoc}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   269
val thms2 = @{thms de_Morgan_conj Collect_disj_eq finite_Un}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   270
val thms3 = @{thms alphas prod_alpha_def prod_fv.simps prod_rel_def permute_prod_def 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   271
  prod.recs prod.cases prod.inject not_True_eq_False empty_def[symmetric] finite.emptyI}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   272
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   273
fun prove_fv_supp qtys qtrms fvs fv_bns alpha_bns fv_simps eq_iffs perm_simps 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   274
  fv_bn_eqvts qinduct bclausess ctxt =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   275
  let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   276
    val goals1 = map mk_fvs_goals fvs
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   277
    val goals2 = map2 mk_fv_bns_goals fv_bns alpha_bns   
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   278
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   279
    fun tac ctxt =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   280
      SUBGOAL (fn (goal, i) =>
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   281
        let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   282
          val (fv_fun, arg) = 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   283
            goal |> Envir.eta_contract
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   284
                 |> Logic.strip_assums_concl
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   285
                 |> HOLogic.dest_Trueprop
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   286
                 |> fst o HOLogic.dest_eq
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   287
                 |> dest_comb
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   288
          val supp_abs_tac = 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   289
            case (AList.lookup (op=) (qtrms ~~ bclausess) (head_of arg)) of
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   290
              SOME bclauses => EVERY' (mk_supp_abs_tac ctxt bclauses)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   291
            | NONE => mk_bn_supp_abs_tac fv_fun
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   292
        in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   293
          EVERY' [ TRY o asm_full_simp_tac (add_ss (@{thm supp_Pair[symmetric]}::fv_simps)),
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   294
                   TRY o supp_abs_tac,
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   295
                   TRY o simp_tac (add_ss @{thms supp_def supp_rel_def}),
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   296
                   TRY o Nominal_Permeq.eqvt_tac ctxt (perm_simps @ fv_bn_eqvts) [], 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   297
                   TRY o simp_tac (add_ss (@{thms Abs_eq_iff} @ eq_iffs)),
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   298
                   TRY o asm_full_simp_tac (add_ss thms3),
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   299
                   TRY o simp_tac (add_ss thms2),
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   300
                   TRY o asm_full_simp_tac (add_ss (thms1 @ (symmetric fv_bn_eqvts)))] i
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   301
        end)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   302
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   303
    induct_prove qtys (goals1 @ goals2) qinduct tac ctxt
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   304
    |> map atomize
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   305
    |> map (simplify (HOL_basic_ss addsimps @{thms fun_eq_iff[symmetric]}))
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   306
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   307
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   308
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   309
fun prove_bns_finite qtys qbns qinduct qbn_simps ctxt =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   310
  let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   311
    fun mk_goal qbn = 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   312
      let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   313
        val arg_ty = domain_type (fastype_of qbn)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   314
        val finite = @{term "finite :: atom set => bool"}
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   315
      in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   316
        (arg_ty, fn x => finite $ (to_set (qbn $ x)))
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   317
      end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   318
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   319
    val props = map mk_goal qbns
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   320
    val ss_tac = asm_full_simp_tac (HOL_basic_ss addsimps (qbn_simps @ 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   321
      @{thms set.simps set_append finite_insert finite.emptyI finite_Un}))
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   322
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   323
    induct_prove qtys props qinduct (K ss_tac) ctxt
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   324
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   325
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   326
fun prove_perm_bn_alpha_thms qtys qperm_bns alpha_bns qinduct qperm_bn_simps qeq_iffs qalpha_refls ctxt =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   327
  let 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   328
    val ([p], ctxt') = Variable.variant_fixes ["p"] ctxt
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   329
    val p = Free (p, @{typ perm})
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   330
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   331
    fun mk_goal qperm_bn alpha_bn =
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   332
      let
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   333
        val arg_ty = domain_type (fastype_of alpha_bn)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   334
      in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   335
        (arg_ty, fn x => (mk_id (Abs ("", arg_ty, alpha_bn $ Bound 0 $ (qperm_bn $ p $ Bound 0)))) $ x)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   336
      end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   337
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   338
    val props = map2 mk_goal qperm_bns alpha_bns
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   339
    val ss = @{thm id_def}::qperm_bn_simps @ qeq_iffs @ qalpha_refls
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   340
    val ss_tac = asm_full_simp_tac (HOL_ss addsimps ss)
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   341
  in
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   342
    induct_prove qtys props qinduct (K ss_tac) ctxt'
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   343
    |> ProofContext.export ctxt' ctxt
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   344
    |> map (simplify (HOL_basic_ss addsimps @{thms id_def})) 
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   345
  end
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   346
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   347
07f775729e90 moved code from nominal_dt_supp to nominal_dt_quot
Christian Urban <urbanc@in.tum.de>
parents: 2574
diff changeset
   348
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
end (* structure *)
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350