Quot/Nominal/Rsp.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Tue, 23 Feb 2010 16:12:30 +0100
changeset 1227 ec2e0116779e
child 1230 a41c3a105104
permissions -rw-r--r--
rsp infrastructure.
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 {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    17
fun const_rsp const lthy =
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
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    26
ML {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
fun remove_alls trm =
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    28
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
  val vars = strip_all_vars trm
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    30
  val fs = rev (map Free vars)
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
in
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    32
  ((map fst vars), subst_bounds (fs, (strip_all_body trm)))
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    33
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    34
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    36
ML {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
fun get_rsp_goal thy trm =
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
  val goalstate = Goal.init (cterm_of thy trm);
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
  val tac = REPEAT o rtac @{thm fun_rel_id};
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
in
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    42
  case (SINGLE (tac 1) goalstate) of
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    43
    NONE => error "rsp_goal failed"
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    44
  | SOME th => remove_alls (term_of (cprem_of th 1))
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    46
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    47
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
ML {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
fun prove_const_rsp bind const tac ctxt =
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
  val rsp_goal = const_rsp const ctxt
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
  val thy = ProofContext.theory_of ctxt
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    53
  val (fixed, user_goal) = get_rsp_goal thy rsp_goal
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    54
  val user_thm = Goal.prove ctxt fixed [] user_goal tac
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    55
  fun tac _ = (REPEAT o rtac @{thm fun_rel_id} THEN' rtac user_thm THEN_ALL_NEW atac) 1
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    56
  val rsp_thm = Goal.prove ctxt [] [] rsp_goal tac
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    57
in
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    58
   ctxt
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    59
|> snd o Local_Theory.note 
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    60
  ((Binding.empty, [Attrib.internal (fn _ => Quotient_Info.rsp_rules_add)]), [rsp_thm])
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    61
|> snd o Local_Theory.note ((bind, []), [user_thm])
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    62
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    63
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    64
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    65
ML {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    66
fun fv_rsp_tac induct fv_simps =
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    67
  eresolve_tac induct THEN_ALL_NEW
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    68
  asm_full_simp_tac (HOL_ss addsimps (@{thm alpha_gen} :: fv_simps))
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    71
ML {*
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
fun constr_rsp_tac inj rsp equivps =
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
let
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
  val reflps = map (fn x => @{thm equivp_reflp} OF [x]) equivps
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
in
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    76
  REPEAT o rtac @{thm fun_rel_id} THEN'
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    77
  simp_tac (HOL_ss addsimps inj) THEN'
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
  (TRY o REPEAT_ALL_NEW (CHANGED o rtac conjI)) THEN_ALL_NEW
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    79
  (asm_simp_tac HOL_ss THEN_ALL_NEW (
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    80
   rtac @{thm exI[of _ "0 :: perm"]} THEN'
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
   asm_full_simp_tac (HOL_ss addsimps (rsp @ reflps @
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    82
     @{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
    83
  ))
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84
end
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    85
*}
ec2e0116779e rsp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    86
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
end