quotient_info.ML
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Tue, 03 Nov 2009 16:17:19 +0100
changeset 267 3764566c1151
parent 264 d0581fbc096c
child 268 4d58c02289ca
permissions -rw-r--r--
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
signature QUOTIENT_INFO =
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
sig
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
  type maps_info = {mapfun: string, relfun: string}
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
  val maps_lookup: theory -> string -> maps_info option
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
  val maps_update_thy: string -> maps_info -> theory -> theory    
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
  val maps_update: string -> maps_info -> Proof.context -> Proof.context     
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  type quotient_info = {qtyp: typ, rtyp: typ, rel: term, equiv_thm: thm}
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  val print_quotdata: Proof.context -> unit
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  val quotdata_lookup_thy: theory -> quotient_info list
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  val quotdata_lookup: Proof.context -> quotient_info list
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  val quotdata_update_thy: (typ * typ * term * thm) -> theory -> theory
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  val quotdata_update: (typ * typ * term * thm) -> Proof.context -> Proof.context
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
end;
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
structure Quotient_Info: QUOTIENT_INFO =
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
struct
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
(* data containers *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
(*******************)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
(* info about map- and rel-functions *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
type maps_info = {mapfun: string, relfun: string}
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
structure MapsData = TheoryDataFun
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  (type T = maps_info Symtab.table
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
   val empty = Symtab.empty
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
   val copy = I
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
   val extend = I
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
   fun merge _ = Symtab.merge (K true))
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
val maps_lookup = Symtab.lookup o MapsData.get
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
fun maps_update_thy k minfo = MapsData.map (Symtab.update (k, minfo))
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
fun maps_update k minfo = ProofContext.theory (maps_update_thy k minfo)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
fun maps_attribute_aux s minfo = Thm.declaration_attribute 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  (fn thm => Context.mapping (maps_update_thy s minfo) (maps_update s minfo))
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
(* attribute to be used in declare statements *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
fun maps_attribute (ctxt, (tystr, (mapstr, relstr))) = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
let  
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  val thy = ProofContext.theory_of ctxt
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  val tyname = Sign.intern_type thy tystr
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  val mapname = Sign.intern_const thy mapstr
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  val relname = Sign.intern_const thy relstr
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
in
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  maps_attribute_aux tyname {mapfun = mapname, relfun = relname}
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
end
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
val maps_attr_parser = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
      Args.context -- Scan.lift
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
       ((Args.name --| OuterParse.$$$ "=") -- 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
         (OuterParse.$$$ "(" |-- Args.name --| OuterParse.$$$ "," -- 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
           Args.name --| OuterParse.$$$ ")"))
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
val _ = Context.>> (Context.map_theory
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
         (Attrib.setup @{binding "map"} (maps_attr_parser >> maps_attribute) 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
           "declaration of map information"))
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
(* info about the quotient types *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
type quotient_info = {qtyp: typ, rtyp: typ, rel: term, equiv_thm: thm}
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
structure QuotData = TheoryDataFun
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  (type T = quotient_info list
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
   val empty = []
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
   val copy = I
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
   val extend = I
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
   fun merge _ = (op @)) (* FIXME: is this the correct merging function for the list? *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
val quotdata_lookup_thy = QuotData.get
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
val quotdata_lookup = QuotData.get o ProofContext.theory_of
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
fun quotdata_update_thy (qty, rty, rel, equiv_thm) thy = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
      QuotData.map (fn ls => {qtyp = qty, rtyp = rty, rel = rel, equiv_thm = equiv_thm}::ls) thy
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
fun quotdata_update (qty, rty, rel, equiv_thm) ctxt = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
      ProofContext.theory (quotdata_update_thy (qty, rty, rel, equiv_thm)) ctxt
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
fun print_quotdata ctxt =
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
let
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  fun prt_quot {qtyp, rtyp, rel, equiv_thm} = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
      Pretty.block (Library.separate (Pretty.brk 2)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
          [Pretty.str ("quotient type:"), 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
           Syntax.pretty_typ ctxt qtyp,
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
           Pretty.str ("raw type:"), 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
           Syntax.pretty_typ ctxt rtyp,
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
           Pretty.str ("relation:"), 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
           Syntax.pretty_term ctxt rel,
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
           Pretty.str ("equiv. thm:"), 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
           Syntax.pretty_term ctxt (prop_of equiv_thm)])
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
in
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  QuotData.get (ProofContext.theory_of ctxt)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  |> map prt_quot
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  |> Pretty.big_list "quotients:" 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  |> Pretty.writeln
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
end
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
val _ = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  OuterSyntax.improper_command "print_quotients" "print out all quotients" 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
    OuterKeyword.diag (Scan.succeed (Toplevel.keep (print_quotdata o Toplevel.context_of)))
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
end; (* structure *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
open Quotient_Info