Nominal/Rsp.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Thu, 04 Mar 2010 18:57:23 +0100
changeset 1342 2b98012307f7
parent 1334 80441e27dfd6
child 1407 beeaa85c9897
permissions -rw-r--r--
Lift distinct.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
theory Rsp
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     2
imports Abs
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
begin
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     5
ML {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
fun define_quotient_type args tac ctxt =
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     8
  val mthd = Method.SIMPLE_METHOD tac
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     9
  val mthdt = Method.Basic (fn _ => mthd)
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
  val bymt = Proof.global_terminal_proof (mthdt, NONE)
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    11
in
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    12
  bymt (Quotient_Type.quotient_type args ctxt)
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    14
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    15
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
ML {*
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    17
fun const_rsp lthy const =
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    18
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    19
  val nty = fastype_of (Quotient_Term.quotient_lift_const ("", const) lthy)
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    20
  val rel = Quotient_Term.equiv_relation_chk lthy (fastype_of const, nty);
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    21
in
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    22
  HOLogic.mk_Trueprop (rel $ const $ const)
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    23
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    24
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    25
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    26
(* Replaces bounds by frees and meta implications by implications *)
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
ML {*
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    28
fun prepare_goal trm =
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    30
  val vars = strip_all_vars trm
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
  val fs = rev (map Free vars)
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    32
  val (fixes, no_alls) = ((map fst vars), subst_bounds (fs, (strip_all_body trm)))
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    33
  val prems = map HOLogic.dest_Trueprop (Logic.strip_imp_prems no_alls)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    34
  val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl no_alls)
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
in
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    36
  (fixes, fold (curry HOLogic.mk_imp) prems concl)
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
ML {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
fun get_rsp_goal thy trm =
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    42
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    43
  val goalstate = Goal.init (cterm_of thy trm);
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    44
  val tac = REPEAT o rtac @{thm fun_rel_id};
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
in
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    46
  case (SINGLE (tac 1) goalstate) of
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    47
    NONE => error "rsp_goal failed"
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    48
  | SOME th => prepare_goal (term_of (cprem_of th 1))
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
ML {*
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    53
fun repeat_mp thm = repeat_mp (mp OF [thm]) handle THM _ => thm
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    54
*}
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    55
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    56
ML {*
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    57
fun prove_const_rsp bind consts tac ctxt =
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    58
let
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    59
  val rsp_goals = map (const_rsp ctxt) consts
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    60
  val thy = ProofContext.theory_of ctxt
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    61
  val (fixed, user_goals) = split_list (map (get_rsp_goal thy) rsp_goals)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    62
  val fixed' = distinct (op =) (flat fixed)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    63
  val user_goal = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj user_goals)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    64
  val user_thm = Goal.prove ctxt fixed' [] user_goal tac
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    65
  val user_thms = map repeat_mp (HOLogic.conj_elims user_thm)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    66
  fun tac _ = (REPEAT o rtac @{thm fun_rel_id} THEN' resolve_tac user_thms THEN_ALL_NEW atac) 1
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    67
  val rsp_thms = map (fn gl => Goal.prove ctxt [] [] gl tac) rsp_goals
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    68
in
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
   ctxt
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
|> snd o Local_Theory.note 
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    71
  ((Binding.empty, [Attrib.internal (fn _ => Quotient_Info.rsp_rules_add)]), rsp_thms)
1278
8814494fe4da Change in signature of prove_const_rsp for general lifting.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1268
diff changeset
    72
|> Local_Theory.note ((bind, []), user_thms)
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    76
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    77
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
ML {*
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    79
fun fvbv_rsp_tac induct fvbv_simps =
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    80
  ((((rtac impI THEN' etac induct) ORELSE' rtac induct) THEN_ALL_NEW
1303
c28403308b34 More fixes for new alpha, the whole lift script should now work again.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1300
diff changeset
    81
  (TRY o rtac @{thm TrueI})) THEN_ALL_NEW
c28403308b34 More fixes for new alpha, the whole lift script should now work again.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1300
diff changeset
    82
  asm_full_simp_tac
c28403308b34 More fixes for new alpha, the whole lift script should now work again.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1300
diff changeset
    83
  (HOL_ss addsimps (@{thm alpha_gen} :: fvbv_simps))
c28403308b34 More fixes for new alpha, the whole lift script should now work again.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1300
diff changeset
    84
  THEN_ALL_NEW (REPEAT o eresolve_tac [conjE, exE] THEN'
c28403308b34 More fixes for new alpha, the whole lift script should now work again.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1300
diff changeset
    85
  asm_full_simp_tac
c28403308b34 More fixes for new alpha, the whole lift script should now work again.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1300
diff changeset
    86
  (HOL_ss addsimps (@{thm alpha_gen} :: fvbv_simps))))
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    87
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    88
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    89
ML {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    90
fun constr_rsp_tac inj rsp equivps =
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    92
  val reflps = map (fn x => @{thm equivp_reflp} OF [x]) equivps
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
in
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
    94
  REPEAT o rtac impI THEN'
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    95
  simp_tac (HOL_ss addsimps inj) THEN'
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    96
  (TRY o REPEAT_ALL_NEW (CHANGED o rtac conjI)) THEN_ALL_NEW
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
  (asm_simp_tac HOL_ss THEN_ALL_NEW (
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    98
   rtac @{thm exI[of _ "0 :: perm"]} THEN'
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
   asm_full_simp_tac (HOL_ss addsimps (rsp @ reflps @
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   100
     @{thms alpha_gen fresh_star_def fresh_zero_perm permute_zero ball_triv}))
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
  ))
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   102
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   104
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   105
(* Testing code
1278
8814494fe4da Change in signature of prove_const_rsp for general lifting.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1268
diff changeset
   106
local_setup {* snd o prove_const_rsp @{binding fv_rtrm2_rsp} [@{term rbv2}]
1230
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   107
  (fn _ => fv_rsp_tac @{thm alpha_rtrm2_alpha_rassign.inducts(2)} @{thms fv_rtrm2_fv_rassign.simps} 1) *}*)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   108
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   109
(*ML {*
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   110
  val rsp_goals = map (const_rsp @{context}) [@{term rbv2}]
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   111
  val (fixed, user_goals) = split_list (map (get_rsp_goal @{theory}) rsp_goals)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   112
  val fixed' = distinct (op =) (flat fixed)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   113
  val user_goal = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj user_goals)
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   114
*}
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   115
prove ug: {* user_goal *}
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   116
ML_prf {*
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   117
val induct = @{thm alpha_rtrm2_alpha_rassign.inducts(2)}
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   118
val fv_simps = @{thms rbv2.simps}
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   119
*} 
a41c3a105104 rsp for bv; the only issue is that it requires an appropriate induction principle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1227
diff changeset
   120
*)
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   121
1268
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   122
ML {*
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   123
fun build_eqvts bind funs perms simps induct ctxt =
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   124
let
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   125
  val pi = Free ("p", @{typ perm});
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   126
  val types = map (domain_type o fastype_of) funs;
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   127
  val indnames = Name.variant_list ["p"] (Datatype_Prop.make_tnames (map body_type types));
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   128
  val args = map Free (indnames ~~ types);
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   129
  val perm_at = @{term "permute :: perm \<Rightarrow> atom set \<Rightarrow> atom set"}
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   130
  fun eqvtc (fnctn, (arg, perm)) =
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   131
    HOLogic.mk_eq ((perm_at $ pi $ (fnctn $ arg)), (fnctn $ (perm $ pi $ arg)))
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   132
  val gl = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj (map eqvtc (funs ~~ (args ~~ perms))))
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   133
  fun tac _ = (Datatype_Aux.indtac induct indnames THEN_ALL_NEW
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   134
    (asm_full_simp_tac (HOL_ss addsimps
1314
6d851952799c Include the raw eqvt lemmas.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1308
diff changeset
   135
      (@{thm atom_eqvt} :: (Nominal_ThmDecls.get_eqvts_thms ctxt) @ (Nominal_ThmDecls.get_eqvts_raw_thms ctxt) @ simps)))) 1
1268
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   136
  val thm = Goal.prove ctxt ("p" :: indnames) [] gl tac
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   137
  val thms = HOLogic.conj_elims thm
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   138
in
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   139
  Local_Theory.note ((bind, [Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)]), thms) ctxt
1227
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   140
end
1268
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   141
*}
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   142
1300
22a084c9316b Fixed eqvt code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1278
diff changeset
   143
lemma exi: "\<exists>(pi :: perm). P pi \<Longrightarrow> (\<And>(p :: perm). P p \<Longrightarrow> Q (pi \<bullet> p)) \<Longrightarrow> \<exists>pi. Q pi"
22a084c9316b Fixed eqvt code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1278
diff changeset
   144
apply (erule exE)
22a084c9316b Fixed eqvt code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1278
diff changeset
   145
apply (rule_tac x="pi \<bullet> pia" in exI)
22a084c9316b Fixed eqvt code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1278
diff changeset
   146
by auto
1268
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   147
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   148
ML {*
1334
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1331
diff changeset
   149
fun ind_tac induct = (rtac impI THEN' etac induct) ORELSE' rtac induct
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1331
diff changeset
   150
*}
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1331
diff changeset
   151
ML {*
1331
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   152
  fun all_eqvts ctxt =
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   153
    Nominal_ThmDecls.get_eqvts_thms ctxt @ Nominal_ThmDecls.get_eqvts_raw_thms ctxt
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   154
  val split_conjs = REPEAT o etac conjE THEN' TRY o REPEAT_ALL_NEW (CHANGED o rtac conjI)
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   155
*}
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   156
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   157
ML {*
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   158
fun mk_minimal_ss ctxt =
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   159
  Simplifier.context ctxt empty_ss
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   160
    setsubgoaler asm_simp_tac
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   161
    setmksimps (mksimps [])
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   162
*}
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   163
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   164
ML {*
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   165
fun alpha_eqvt_tac induct simps ctxt =
1334
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1331
diff changeset
   166
  ind_tac induct THEN_ALL_NEW
1331
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   167
  simp_tac ((mk_minimal_ss ctxt) addsimps simps) THEN_ALL_NEW
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   168
  REPEAT o etac @{thm exi[of _ _ "p"]} THEN' split_conjs THEN_ALL_NEW
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   169
  asm_full_simp_tac (HOL_ss addsimps (all_eqvts ctxt @ simps)) THEN_ALL_NEW
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   170
  asm_full_simp_tac (HOL_ss addsimps 
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   171
    @{thms supp_eqvt[symmetric] inter_eqvt[symmetric] empty_eqvt alpha_gen}) THEN_ALL_NEW
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   172
  (split_conjs THEN_ALL_NEW TRY o resolve_tac
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   173
    @{thms fresh_star_permute_iff[of "- p", THEN iffD1] permute_eq_iff[of "- p", THEN iffD1]})
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   174
  THEN_ALL_NEW
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   175
  asm_full_simp_tac (HOL_ss addsimps (@{thms permute_minus_cancel permute_plus permute_eqvt[symmetric]} @ all_eqvts ctxt))
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   176
*}
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   177
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   178
ML {*
1268
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   179
fun build_alpha_eqvts funs perms simps induct ctxt =
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   180
let
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   181
  val pi = Free ("p", @{typ perm});
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   182
  val types = map (domain_type o fastype_of) funs;
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   183
  val indnames = Name.variant_list ["p"] (Datatype_Prop.make_tnames (map body_type types));
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   184
  val indnames2 = Name.variant_list ("p" :: indnames) (Datatype_Prop.make_tnames (map body_type types));
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   185
  val args = map Free (indnames ~~ types);
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   186
  val args2 = map Free (indnames2 ~~ types);
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   187
  fun eqvtc ((alpha, perm), (arg, arg2)) =
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   188
    HOLogic.mk_imp (alpha $ arg $ arg2,
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   189
      (alpha $ (perm $ pi $ arg) $ (perm $ pi $ arg2)))
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   190
  val gl = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj (map eqvtc ((funs ~~ perms) ~~ (args ~~ args2))))
1331
0f329449e304 Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1314
diff changeset
   191
  fun tac _ = alpha_eqvt_tac induct simps ctxt 1
1268
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   192
  val thm = Goal.prove ctxt ("p" :: indnames @ indnames2) [] gl tac
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   193
in
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   194
  map (fn x => mp OF [x]) (HOLogic.conj_elims thm)
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   195
end
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   196
*}
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   197
1308
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   198
ML {*
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   199
fun build_bv_eqvt perms simps inducts (t, n) =
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   200
  build_eqvts Binding.empty [t] [nth perms n] simps (nth inducts n)
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   201
*}
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   202
1268
d1999540d23a Move the eqvt code out of Terms and fixed induction for single-rule examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   203
end