src/HOL/Tools/Lifting/lifting_setup.ML
author huffman
Wed, 18 Apr 2012 12:15:20 +0200
changeset 47535 0f94b02fda1c
parent 47534 06cc372a80ed
child 47545 a2850a16e30f
permissions -rw-r--r--
lifting_setup generates transfer rule for rep of typedefs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     1
(*  Title:      HOL/Tools/Lifting/lifting_setup.ML
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     2
    Author:     Ondrej Kuncar
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     3
47352
e0bff2ae939f fix typos
huffman
parents: 47334
diff changeset
     4
Setting up the lifting infrastructure.
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     5
*)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     6
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     7
signature LIFTING_SETUP =
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     8
sig
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     9
  exception SETUP_LIFTING_INFR of string
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    10
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    11
  val setup_lifting_infr: thm -> local_theory -> local_theory
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    12
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    13
  val setup_by_quotient: thm -> thm option -> local_theory -> local_theory
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    14
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    15
  val setup_by_typedef_thm: thm -> local_theory -> local_theory
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    16
end;
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    17
47334
4708384e759d fix typo in ML structure name
huffman
parents: 47308
diff changeset
    18
structure Lifting_Setup: LIFTING_SETUP =
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    19
struct
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    20
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    21
infix 0 MRSL
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    22
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    23
fun ants MRSL thm = fold (fn rl => fn thm => rl RS thm) ants thm
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    24
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    25
exception SETUP_LIFTING_INFR of string
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    26
47361
87c0eaf04bad support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents: 47352
diff changeset
    27
fun define_cr_rel rep_fun lthy =
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    28
  let
47361
87c0eaf04bad support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents: 47352
diff changeset
    29
    val (qty, rty) = (dest_funT o fastype_of) rep_fun
87c0eaf04bad support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents: 47352
diff changeset
    30
    val rep_fun_graph = (HOLogic.eq_const rty) $ Bound 1 $ (rep_fun $ Bound 0)
87c0eaf04bad support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents: 47352
diff changeset
    31
    val def_term = Abs ("x", rty, Abs ("y", qty, rep_fun_graph));
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    32
    val qty_name = (fst o dest_Type) qty
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    33
    val cr_rel_name = Binding.prefix_name "cr_" (Binding.qualified_name qty_name)  
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    34
    val (fixed_def_term, lthy') = yield_singleton (Variable.importT_terms) def_term lthy
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    35
    val ((_, (_ , def_thm)), lthy'') =
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    36
      Local_Theory.define ((cr_rel_name, NoSyn), ((Thm.def_binding cr_rel_name, []), fixed_def_term)) lthy'
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    37
  in
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    38
    (def_thm, lthy'')
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    39
  end
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    40
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    41
fun define_abs_type quot_thm lthy =
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    42
  if Lifting_Def.can_generate_code_cert quot_thm then
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    43
    let
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    44
      val abs_type_thm = quot_thm RS @{thm Quotient_abs_rep}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    45
      val add_abstype_attribute = 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    46
          Thm.declaration_attribute (fn thm => Context.mapping (Code.add_abstype thm) I)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    47
        val add_abstype_attrib = Attrib.internal (K add_abstype_attribute);
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    48
    in
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    49
      lthy
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    50
        |> (snd oo Local_Theory.note) ((Binding.empty, [add_abstype_attrib]), [abs_type_thm])
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    51
    end
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    52
  else
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    53
    lthy
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    54
47379
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    55
fun quot_thm_sanity_check ctxt quot_thm =
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    56
  let
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    57
    val ((_, [quot_thm_fixed]), ctxt') = Variable.importT [quot_thm] ctxt 
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    58
    val (rty, qty) = Lifting_Term.quot_thm_rty_qty quot_thm_fixed
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    59
    val rty_tfreesT = Term.add_tfree_namesT rty []
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    60
    val qty_tfreesT = Term.add_tfree_namesT qty []
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    61
    val extra_rty_tfrees =
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    62
      (case subtract (op =) qty_tfreesT rty_tfreesT of
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    63
        [] => []
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    64
      | extras => [Pretty.block ([Pretty.str "Extra variables in the raw type:",
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    65
                                 Pretty.brk 1] @ 
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    66
                                 ((Pretty.commas o map (Pretty.str o quote)) extras) @
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    67
                                 [Pretty.str "."])])
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    68
    val not_type_constr = 
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    69
      (case qty of
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    70
         Type _ => []
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    71
         | _ => [Pretty.block [Pretty.str "The quotient type ",
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    72
                                Pretty.quote (Syntax.pretty_typ ctxt' qty),
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    73
                                Pretty.brk 1,
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    74
                                Pretty.str "is not a type constructor."]])
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    75
    val errs = extra_rty_tfrees @ not_type_constr
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    76
  in
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    77
    if null errs then () else error (cat_lines (["Sanity check of the quotient theorem failed:",""] 
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    78
                                                @ (map Pretty.string_of errs)))
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    79
  end
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    80
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    81
fun setup_lifting_infr quot_thm lthy =
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    82
  let
47379
075d22b3a32f detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents: 47361
diff changeset
    83
    val _ = quot_thm_sanity_check lthy quot_thm
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    84
    val (_, qtyp) = Lifting_Term.quot_thm_rty_qty quot_thm
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    85
    val qty_full_name = (fst o dest_Type) qtyp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    86
    val quotients = { quot_thm = quot_thm }
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    87
    fun quot_info phi = Lifting_Info.transform_quotients phi quotients
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    88
  in
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    89
    lthy
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    90
      |> Local_Theory.declaration {syntax = false, pervasive = true}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    91
        (fn phi => Lifting_Info.update_quotients qty_full_name (quot_info phi))
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    92
      |> define_abs_type quot_thm
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    93
  end
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    94
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    95
fun setup_by_quotient quot_thm maybe_reflp_thm lthy =
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    96
  let
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    97
    val transfer_attr = Attrib.internal (K Transfer.transfer_add)
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    98
    val lthy' = case maybe_reflp_thm of
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
    99
      SOME reflp_thm => lthy
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   100
        |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   101
          [[quot_thm, reflp_thm] MRSL @{thm Quotient_bi_total}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   102
        |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   103
          [[quot_thm, reflp_thm] MRSL @{thm Quotient_id_abs_transfer}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   104
      | NONE => lthy
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   105
  in
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   106
    lthy'
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   107
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   108
        [quot_thm RS @{thm Quotient_right_unique}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   109
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   110
        [quot_thm RS @{thm Quotient_right_total}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   111
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   112
        [quot_thm RS @{thm Quotient_rel_eq_transfer}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   113
      |> setup_lifting_infr quot_thm
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   114
  end
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   115
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   116
fun setup_by_typedef_thm typedef_thm lthy =
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   117
  let
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   118
    val transfer_attr = Attrib.internal (K Transfer.transfer_add)
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   119
    val (_ $ rep_fun $ _ $ typedef_set) = (HOLogic.dest_Trueprop o prop_of) typedef_thm
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   120
    val (T_def, lthy') = define_cr_rel rep_fun lthy
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   121
    
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   122
    val quot_thm = (case typedef_set of
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   123
      Const ("Orderings.top_class.top", _) => 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   124
        [typedef_thm, T_def] MRSL @{thm UNIV_typedef_to_Quotient}
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   125
      | Const (@{const_name "Collect"}, _) $ Abs (_, _, _) => 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   126
        [typedef_thm, T_def] MRSL @{thm open_typedef_to_Quotient}
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   127
      | _ => 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   128
        [typedef_thm, T_def] MRSL @{thm typedef_to_Quotient})
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   129
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   130
    val lthy'' = (case typedef_set of
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   131
      Const ("Orderings.top_class.top", _) => (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   132
        [[typedef_thm,T_def] MRSL @{thm copy_type_bi_total}]) lthy'
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   133
      | _ => lthy')
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   134
  in
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   135
    lthy''
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   136
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   137
        [[typedef_thm, T_def] MRSL @{thm typedef_bi_unique}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   138
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
47534
06cc372a80ed use context block to organize typedef lifting theorems
huffman
parents: 47521
diff changeset
   139
        [[typedef_thm, T_def] MRSL @{thm typedef_right_total}])
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   140
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
47535
0f94b02fda1c lifting_setup generates transfer rule for rep of typedefs
huffman
parents: 47534
diff changeset
   141
        [[typedef_thm, T_def] MRSL @{thm typedef_rep_transfer}])
0f94b02fda1c lifting_setup generates transfer rule for rep of typedefs
huffman
parents: 47534
diff changeset
   142
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   143
        [[typedef_thm, T_def] MRSL @{thm typedef_transfer_All}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   144
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   145
        [[typedef_thm, T_def] MRSL @{thm typedef_transfer_Ex}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   146
      |> (snd oo Local_Theory.note) ((Binding.empty, [transfer_attr]), 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   147
        [[typedef_thm, T_def] MRSL @{thm typedef_transfer_bforall}])
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   148
      |> setup_lifting_infr quot_thm
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   149
  end
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   150
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   151
fun setup_lifting_cmd xthm lthy =
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   152
  let 
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   153
    val input_thm = singleton (Attrib.eval_thms lthy) xthm
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   154
    val input_term = (HOLogic.dest_Trueprop o prop_of) input_thm
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   155
  in
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   156
    case input_term of
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   157
      (Const (@{const_name Quotient}, _) $ _ $ _ $ _ $ _) => setup_lifting_infr input_thm lthy
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   158
      | (Const (@{const_name type_definition}, _) $ _ $ _ $ _) => setup_by_typedef_thm input_thm lthy
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   159
      | _ => error "Unsupported type of a theorem. Only Quotient or type_definition are supported."
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   160
  end
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   161
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   162
val _ = 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   163
  Outer_Syntax.local_theory @{command_spec "setup_lifting"}
47352
e0bff2ae939f fix typos
huffman
parents: 47334
diff changeset
   164
    "Setup lifting infrastructure" 
47521
69f95ac85c3d tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents: 47379
diff changeset
   165
      (Parse_Spec.xthm >> (fn xthm => setup_lifting_cmd xthm))
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   166
end;