Nominal/Perm.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 20 May 2010 21:23:53 +0100
changeset 2288 3b83960f9544
parent 2163 5dc48e1af733
child 2296 45a69c9cc4cc
permissions -rw-r--r--
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1159
3c6bee89d826 Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
theory Perm
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2163
diff changeset
     2
imports 
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2163
diff changeset
     3
  "../Nominal-General/Nominal2_Base"
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 2163
diff changeset
     4
  "../Nominal-General/Nominal2_Atoms"
1159
3c6bee89d826 Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     5
begin
3c6bee89d826 Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
2035
3622cae9b10e to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1971
diff changeset
     7
1910
57891245370d tuning of the code
Christian Urban <urbanc@in.tum.de>
parents: 1903
diff changeset
     8
(* permutations for quotient types *)
1899
8e0bfb14f6bf optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1896
diff changeset
     9
2144
e900526e95c4 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2143
diff changeset
    10
ML {* Class_Target.prove_instantiation_exit_result *}
e900526e95c4 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 2143
diff changeset
    11
1253
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    12
ML {*
1903
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    13
fun quotient_lift_consts_export qtys spec ctxt =
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    14
let
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    15
  val (result, ctxt') = fold_map (Quotient_Def.quotient_lift_const qtys) spec ctxt;
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    16
  val (ts_loc, defs_loc) = split_list result;
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    17
  val morphism = ProofContext.export_morphism ctxt' ctxt;
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    18
  val ts = map (Morphism.term morphism) ts_loc
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    19
  val defs = Morphism.fact morphism defs_loc
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    20
in
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    21
  (ts, defs, ctxt')
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    22
end
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    23
*}
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    24
950fd9b8f05e reordered code
Christian Urban <urbanc@in.tum.de>
parents: 1902
diff changeset
    25
ML {*
1683
f78c820f67c3 Automatically lift theorems and constants only using the new quotient types. Requires new Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1503
diff changeset
    26
fun define_lifted_perms qtys full_tnames name_term_pairs thms thy =
1253
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    27
let
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    28
  val lthy =
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    29
    Theory_Target.instantiation (full_tnames, [], @{sort pt}) thy;
1683
f78c820f67c3 Automatically lift theorems and constants only using the new quotient types. Requires new Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1503
diff changeset
    30
  val (_, _, lthy') = quotient_lift_consts_export qtys name_term_pairs lthy;
f78c820f67c3 Automatically lift theorems and constants only using the new quotient types. Requires new Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1503
diff changeset
    31
  val lifted_thms = map (Quotient_Tacs.lifted qtys lthy') thms;
1253
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    32
  fun tac _ =
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    33
    Class.intro_classes_tac [] THEN
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    34
    (ALLGOALS (resolve_tac lifted_thms))
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    35
  val lthy'' = Class.prove_instantiation_instance tac lthy'
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    36
in
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    37
  Local_Theory.exit_global lthy''
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    38
end
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    39
*}
cff8a67691d2 Define lifted perms.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1249
diff changeset
    40
1342
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    41
ML {*
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    42
fun neq_to_rel r neq =
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    43
let
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    44
  val neq = HOLogic.dest_Trueprop (prop_of neq)
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    45
  val eq = HOLogic.dest_not neq
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    46
  val (lhs, rhs) = HOLogic.dest_eq eq
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    47
  val rel = r $ lhs $ rhs
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    48
  val nrel = HOLogic.mk_not rel
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    49
in
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    50
  HOLogic.mk_Trueprop nrel
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    51
end
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    52
*}
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    53
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    54
ML {*
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    55
fun neq_to_rel_tac cases distinct =
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    56
  rtac notI THEN' eresolve_tac cases THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps distinct)
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    57
*}
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    58
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    59
ML {*
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    60
fun distinct_rel ctxt cases (dists, rel) =
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    61
let
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    62
  val ((_, thms), ctxt') = Variable.import false dists ctxt
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    63
  val terms = map (neq_to_rel rel) thms
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    64
  val nrels = map (fn t => Goal.prove ctxt' [] [] t (fn _ => neq_to_rel_tac cases dists 1)) terms
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    65
in
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    66
  Variable.export ctxt' ctxt nrels
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    67
end
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    68
*}
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    69
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    70
2b98012307f7 Lift distinct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
    71
1899
8e0bfb14f6bf optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1896
diff changeset
    72
(* Test *)
1910
57891245370d tuning of the code
Christian Urban <urbanc@in.tum.de>
parents: 1903
diff changeset
    73
(*
57891245370d tuning of the code
Christian Urban <urbanc@in.tum.de>
parents: 1903
diff changeset
    74
atom_decl name
1159
3c6bee89d826 Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
1896
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
    76
datatype trm =
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
    77
  Var "name"
1910
57891245370d tuning of the code
Christian Urban <urbanc@in.tum.de>
parents: 1903
diff changeset
    78
| App "trm" "(trm list) list"
1896
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
    79
| Lam "name" "trm"
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
    80
| Let "bp" "trm" "trm"
1170
a7b4160ef463 Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1164
diff changeset
    81
and bp =
a7b4160ef463 Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1164
diff changeset
    82
  BUnit
1896
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
    83
| BVar "name"
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
    84
| BPair "bp" "bp"
1159
3c6bee89d826 Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    85
1899
8e0bfb14f6bf optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1896
diff changeset
    86
setup {* fn thy =>
8e0bfb14f6bf optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1896
diff changeset
    87
let 
1910
57891245370d tuning of the code
Christian Urban <urbanc@in.tum.de>
parents: 1903
diff changeset
    88
  val info = Datatype.the_info thy "Perm.trm"
1899
8e0bfb14f6bf optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1896
diff changeset
    89
in
1910
57891245370d tuning of the code
Christian Urban <urbanc@in.tum.de>
parents: 1903
diff changeset
    90
  define_raw_perms info 2 thy |> snd
1899
8e0bfb14f6bf optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1896
diff changeset
    91
end
8e0bfb14f6bf optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1896
diff changeset
    92
*}
1170
a7b4160ef463 Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1164
diff changeset
    93
a7b4160ef463 Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1164
diff changeset
    94
print_theorems
a7b4160ef463 Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1164
diff changeset
    95
*)
a7b4160ef463 Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1164
diff changeset
    96
1159
3c6bee89d826 Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
end