Nominal/Lift.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Fri, 26 Mar 2010 16:20:39 +0100
changeset 1656 c9d3dda79fe3
parent 1553 4355eb3b7161
child 1681 b8a07a3c1692
permissions -rw-r--r--
Removed remaining cheats + some cleaning.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1274
d867021d8ac1 Preparing the generalized lifting procedure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
theory Lift
1494
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
     2
imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" "Abs" "Perm" "Fv" "Rsp"
1274
d867021d8ac1 Preparing the generalized lifting procedure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
begin
d867021d8ac1 Preparing the generalized lifting procedure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
1316
0577afdb1732 Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1309
diff changeset
     5
ML {*
1656
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
     6
fun define_quotient_type args tac ctxt =
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
     7
let
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
     8
  val mthd = Method.SIMPLE_METHOD tac
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
     9
  val mthdt = Method.Basic (fn _ => mthd)
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
    10
  val bymt = Proof.global_terminal_proof (mthdt, NONE)
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
    11
in
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
    12
  bymt (Quotient_Type.quotient_type args ctxt)
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
    13
end
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
    14
*}
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
    15
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
    16
(* Renames schematic variables in a theorem *)
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
    17
ML {*
1498
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    18
fun rename_vars fnctn thm =
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    19
let
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    20
  val vars = Term.add_vars (prop_of thm) []
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    21
  val nvars = map (Var o ((apfst o apfst) fnctn)) vars
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    22
in
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    23
  Thm.certify_instantiate ([], (vars ~~ nvars))  thm
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    24
end
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    25
*}
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    26
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    27
ML {*
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    28
fun un_raws name =
1494
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    29
let
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    30
  fun un_raw name = unprefix "_raw" name handle Fail _ => name
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    31
  fun add_under names = hd names :: (map (prefix "_") (tl names))
1498
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    32
in
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    33
  implode (map un_raw (add_under (space_explode "_" name)))
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    34
end
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    35
*}
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    36
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    37
(* Similar to Tools/IsaPlanner/rw_tools.ML *)
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    38
ML {*
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    39
fun rename_term_bvars (Abs(s, ty, t)) = (Abs(un_raws s, ty, rename_term_bvars t))
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    40
  | rename_term_bvars (a $ b) = (rename_term_bvars a) $ (rename_term_bvars b)
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    41
  | rename_term_bvars x = x;
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    42
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    43
fun rename_thm_bvars th =
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    44
let
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    45
  val t = Thm.prop_of th
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    46
in
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    47
  Thm.rename_boundvars t (rename_term_bvars t) th
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    48
end;
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    49
*}
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    50
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    51
ML {*
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    52
fun lift_thm ctxt thm =
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    53
let
1494
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    54
  val un_raw_names = rename_vars un_raws
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    55
in
1498
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    56
  rename_thm_bvars (un_raw_names (snd (Quotient_Tacs.lifted_attrib (Context.Proof ctxt, thm))))
1494
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    57
end
1276
3365fce80f0f To call quotient it is enough to export the alpha frees to proper constants and their respective equivp theorems.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1274
diff changeset
    58
*}
1274
d867021d8ac1 Preparing the generalized lifting procedure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    59
1494
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    60
ML {*
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    61
fun quotient_lift_consts_export spec ctxt =
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    62
let
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    63
  val (result, ctxt') = fold_map Quotient_Def.quotient_lift_const spec ctxt;
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    64
  val (ts_loc, defs_loc) = split_list result;
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    65
  val morphism = ProofContext.export_morphism ctxt' ctxt;
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    66
  val ts = map (Morphism.term morphism) ts_loc
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    67
  val defs = Morphism.fact morphism defs_loc
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    68
in
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    69
  (ts, defs, ctxt')
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    70
end
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    71
*}
1342
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1316
diff changeset
    72
1497
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    73
ML {*
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    74
fun define_fv_alpha_export dt binds bns ctxt =
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    75
let
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    76
  val ((((fv_ts_loc, fv_def_loc), ord_fv_ts_loc), alpha), ctxt') =
1497
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    77
    define_fv_alpha dt binds bns ctxt;
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    78
  val alpha_ts_loc = #preds alpha
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    79
  val alpha_induct_loc = #induct alpha
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    80
  val alpha_intros_loc = #intrs alpha;
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    81
  val alpha_cases_loc = #elims alpha
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    82
  val morphism = ProofContext.export_morphism ctxt' ctxt;
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    83
  val fv_ts = map (Morphism.term morphism) fv_ts_loc;
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    84
  val ord_fv_ts = map (Morphism.term morphism) ord_fv_ts_loc;
1497
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    85
  val fv_def = Morphism.fact morphism fv_def_loc;
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    86
  val alpha_ts = map (Morphism.term morphism) alpha_ts_loc;
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    87
  val alpha_induct = Morphism.thm morphism alpha_induct_loc;
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    88
  val alpha_intros = Morphism.fact morphism alpha_intros_loc
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    89
  val alpha_cases = Morphism.fact morphism alpha_cases_loc
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    90
in
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    91
  ((((fv_ts, ord_fv_ts), fv_def), ((alpha_ts, alpha_intros), (alpha_cases, alpha_induct))), ctxt')
1497
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    92
end;
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    93
*}
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    94
1280
1f057f8da8aa Progress with general lifting procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    95
end
1274
d867021d8ac1 Preparing the generalized lifting procedure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    96