Nominal/nominal_dt_supp.ML
author Christian Urban <urbanc@in.tum.de>
Sun, 29 Aug 2010 12:14:40 +0800
changeset 2452 39f8d405d7a2
parent 2451 d2e929f51fa9
child 2475 486d4647bb37
permissions -rw-r--r--
updated todos
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(*  Title:      nominal_dt_alpha.ML
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
    Author:     Christian Urban
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
    Author:     Cezary Kaliszyk
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
  Deriving support propoerties for the quotient types.
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
*)
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
signature NOMINAL_DT_SUPP =
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
sig
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  val prove_supports: Proof.context -> thm list -> term list -> thm list  
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    11
  val prove_fsupp: Proof.context -> typ list -> thm -> thm list -> thm list
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    12
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    13
  val fs_instance: typ list -> string list -> (string * sort) list -> thm list ->  
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    14
    local_theory -> local_theory
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
end
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
structure Nominal_Dt_Supp: NOMINAL_DT_SUPP =
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
struct
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    21
(* supports lemmas for constructors *)
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
fun mk_supports_goal ctxt qtrm =
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
let  
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  val vs = fresh_args ctxt qtrm
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  val rhs = list_comb (qtrm, vs)
2449
6b51117b8955 fiexed problem with constructors that have no arguments
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    27
  val lhs = fold (curry HOLogic.mk_prod) vs @{term "()"}
6b51117b8955 fiexed problem with constructors that have no arguments
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    28
    |> mk_supp
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
in
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  mk_supports lhs rhs
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  |> HOLogic.mk_Trueprop
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
end
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
fun supports_tac ctxt perm_simps =
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
let
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  val ss1 = HOL_basic_ss addsimps @{thms supports_def fresh_def[symmetric]}
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  val ss2 = HOL_ss addsimps @{thms swap_fresh_fresh fresh_Pair}
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
in
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  EVERY' [ simp_tac ss1,
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
           Nominal_Permeq.eqvt_strict_tac ctxt perm_simps [],
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
           simp_tac ss2 ]
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
end
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
fun prove_supports_single ctxt perm_simps qtrm =
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
let
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  val goal = mk_supports_goal ctxt qtrm 
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  val ctxt' = Variable.auto_fixes goal ctxt
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
in
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  Goal.prove ctxt' [] [] goal
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
   (K (HEADGOAL (supports_tac ctxt perm_simps)))
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  |> singleton (ProofContext.export ctxt' ctxt)
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
end
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
fun prove_supports ctxt perm_simps qtrms =
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  map (prove_supports_single ctxt perm_simps) qtrms
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    58
(* finite supp lemmas for qtypes *)
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    60
fun prove_fsupp ctxt qtys qinduct qsupports_thms =
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    61
let
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    62
  val (vs, ctxt') = Variable.variant_fixes (replicate (length qtys) "x") ctxt
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    63
  val goals = vs ~~ qtys
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    64
    |> map Free
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    65
    |> map (mk_finite o mk_supp)
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    66
    |> foldr1 (HOLogic.mk_conj)
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    67
    |> HOLogic.mk_Trueprop
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    68
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    69
  val tac = 
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    70
    EVERY' [ rtac @{thm supports_finite},
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    71
             resolve_tac qsupports_thms,
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    72
             asm_simp_tac (HOL_ss addsimps @{thms finite_supp supp_Pair finite_Un}) ]
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    73
in
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    74
  Goal.prove ctxt' [] [] goals
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    75
    (K (HEADGOAL (rtac qinduct THEN_ALL_NEW tac)))
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    76
  |> singleton (ProofContext.export ctxt' ctxt)
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    77
  |> Datatype_Aux.split_conj_thm
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    78
  |> map zero_var_indexes
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2449
diff changeset
    79
end
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
2451
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    81
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    82
(* finite supp instances *)
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    83
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    84
fun fs_instance qtys qfull_ty_names tvs qfsupp_thms lthy =
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    85
let
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    86
  val lthy1 = 
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    87
    lthy
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    88
    |> Local_Theory.exit_global
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    89
    |> Class.instantiation (qfull_ty_names, tvs, @{sort fs}) 
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    90
  
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    91
  fun tac _ =
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    92
    Class.intro_classes_tac [] THEN
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    93
      (ALLGOALS (resolve_tac qfsupp_thms))
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    94
in
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    95
  lthy1
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    96
  |> Class.prove_instantiation_exit tac 
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    97
  |> Named_Target.theory_init
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    98
end
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    99
d2e929f51fa9 added fs-instance proofs
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   100
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
end (* structure *)
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102