Nominal/Lift.thy
author Christian Urban <urbanc@in.tum.de>
Sat, 20 Mar 2010 04:51:26 +0100
changeset 1558 a5ba76208983
parent 1553 4355eb3b7161
child 1656 c9d3dda79fe3
permissions -rw-r--r--
started cleaning up and introduced 3 versions of ~~gen
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 {*
1498
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
     6
fun rename_vars fnctn thm =
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
     7
let
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
     8
  val vars = Term.add_vars (prop_of thm) []
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
     9
  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
    10
in
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    11
  Thm.certify_instantiate ([], (vars ~~ nvars))  thm
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    12
end
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    13
*}
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    14
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    15
ML {*
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    16
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
    17
let
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    18
  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
    19
  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
    20
in
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    21
  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
    22
end
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    23
*}
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    24
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    25
(* Similar to Tools/IsaPlanner/rw_tools.ML *)
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    26
ML {*
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    27
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
    28
  | 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
    29
  | rename_term_bvars x = x;
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    30
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    31
fun rename_thm_bvars th =
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    32
let
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    33
  val t = Thm.prop_of th
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    34
in
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    35
  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
    36
end;
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    37
*}
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    38
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    39
ML {*
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    40
fun lift_thm ctxt thm =
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    41
let
1494
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    42
  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
    43
in
1498
2ff84b1f551f Rename bound variables + minor cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1497
diff changeset
    44
  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
    45
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
    46
*}
1274
d867021d8ac1 Preparing the generalized lifting procedure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    47
1494
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    48
ML {*
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    49
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
    50
let
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    51
  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
    52
  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
    53
  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
    54
  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
    55
  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
    56
in
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    57
  (ts, defs, ctxt')
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    58
end
923413256cbb Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1342
diff changeset
    59
*}
1342
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1316
diff changeset
    60
1497
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    61
ML {*
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    62
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
    63
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
    64
  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
    65
    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
    66
  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
    67
  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
    68
  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
    69
  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
    70
  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
    71
  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
    72
  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
    73
  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
    74
  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
    75
  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
    76
  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
    77
  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
    78
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
    79
  ((((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
    80
end;
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    81
*}
1c9931e5039a Move most of the exporting out of the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1494
diff changeset
    82
1280
1f057f8da8aa Progress with general lifting procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    83
end
1274
d867021d8ac1 Preparing the generalized lifting procedure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84