Quot/quotient_info.ML
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Wed, 09 Dec 2009 15:57:47 +0100
changeset 663 0dd10a900cae
parent 643 cd4226736c37
child 669 2ee3bc9899c0
permissions -rw-r--r--
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
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
549
f178958d3d81 not yet quite functional treatment of constants
Christian Urban <urbanc@in.tum.de>
parents: 506
diff changeset
     3
  exception NotFound
f178958d3d81 not yet quite functional treatment of constants
Christian Urban <urbanc@in.tum.de>
parents: 506
diff changeset
     4
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
  type maps_info = {mapfun: string, relfun: string}
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
  val maps_lookup: theory -> string -> maps_info option
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  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
     8
  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
     9
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  type quotient_info = {qtyp: typ, rtyp: typ, rel: term, equiv_thm: thm}
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
    11
  val print_quotinfo: Proof.context -> unit
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    12
  val quotdata_lookup_thy: theory -> string -> quotient_info option
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    13
  val quotdata_lookup: Proof.context -> string -> quotient_info option
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    14
  val quotdata_update_thy: string -> (typ * typ * term * thm) -> theory -> theory
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    15
  val quotdata_update: string -> (typ * typ * term * thm) -> Proof.context -> Proof.context
460
3f8c7183ddac added facilities to get all stored quotient data (equiv thms etc)
Christian Urban <urbanc@in.tum.de>
parents: 450
diff changeset
    16
  val quotdata_dest: theory -> quotient_info list
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
    17
496
8f1bf5266ebc Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 460
diff changeset
    18
  type qconsts_info = {qconst: term, rconst: term, def: thm}
318
746b17e1d6d8 fixed the storage of qconst definitions
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
    19
  val qconsts_transfer: morphism -> qconsts_info -> qconsts_info
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
    20
  val qconsts_lookup: theory -> term -> qconsts_info
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
    21
  val qconsts_update_thy: string -> qconsts_info -> theory -> theory
497
b663bc007d00 Added qoutient_consts dest for getting all the constant definitions in the cleaning step.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 496
diff changeset
    22
  val qconsts_update_gen: string -> qconsts_info -> Context.generic -> Context.generic
b663bc007d00 Added qoutient_consts dest for getting all the constant definitions in the cleaning step.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 496
diff changeset
    23
  val qconsts_dest: theory -> qconsts_info list
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
    24
  val print_qconstinfo: Proof.context -> unit
450
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
    25
582
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
    26
  val equiv_rules_get: Proof.context -> thm list
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
    27
  val equiv_rules_add: attribute
450
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
    28
  val rsp_rules_get: Proof.context -> thm list  
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
    29
  val prs_rules_get: Proof.context -> thm list  
614
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
    30
  val id_simps_get: Proof.context -> thm list
503
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
    31
  val quotient_rules_get: Proof.context -> thm list
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
    32
  val quotient_rules_add: attribute
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
end;
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
structure Quotient_Info: QUOTIENT_INFO =
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
struct
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
549
f178958d3d81 not yet quite functional treatment of constants
Christian Urban <urbanc@in.tum.de>
parents: 506
diff changeset
    38
exception NotFound
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
    39
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
(* data containers *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
(*******************)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
(* info about map- and rel-functions *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
type maps_info = {mapfun: string, relfun: string}
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
306
e7279efbe3dd updated to new Theory_Data and to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
    46
structure MapsData = Theory_Data
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  (type T = maps_info Symtab.table
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
   val empty = Symtab.empty
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
   val extend = I
306
e7279efbe3dd updated to new Theory_Data and to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
    50
   val merge = Symtab.merge (K true))
264
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_lookup = Symtab.lookup o MapsData.get
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
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
    55
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
    56
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
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
    58
  (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
    59
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
(* attribute to be used in declare statements *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
fun maps_attribute (ctxt, (tystr, (mapstr, relstr))) = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
let  
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  val thy = ProofContext.theory_of ctxt
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  val tyname = Sign.intern_type thy tystr
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  val mapname = Sign.intern_const thy mapstr
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  val relname = Sign.intern_const thy relstr
613
018aabbffd08 removed a fixme: map_info is now checked
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    67
018aabbffd08 removed a fixme: map_info is now checked
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    68
  fun check s = (Const (s, dummyT) |> Syntax.check_term ctxt)
018aabbffd08 removed a fixme: map_info is now checked
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    69
        handle _ => error ("Constant " ^ s ^ " not declared.")
018aabbffd08 removed a fixme: map_info is now checked
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    70
  val _ =  map check [mapname, relname]
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
in
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  maps_attribute_aux tyname {mapfun = mapname, relfun = relname}
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
end
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
val maps_attr_parser = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
      Args.context -- Scan.lift
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
       ((Args.name --| OuterParse.$$$ "=") -- 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
         (OuterParse.$$$ "(" |-- Args.name --| OuterParse.$$$ "," -- 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
           Args.name --| OuterParse.$$$ ")"))
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
val _ = Context.>> (Context.map_theory
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
         (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
    83
           "declaration of map information"))
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
329
5d06e1dba69a slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 324
diff changeset
    86
(* info about quotient types *)
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
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
    88
306
e7279efbe3dd updated to new Theory_Data and to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
    89
structure QuotData = Theory_Data
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    90
  (type T = quotient_info Symtab.table
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    91
   val empty = Symtab.empty
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
   val extend = I
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    93
   val merge = Symtab.merge (K true)) 
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
320
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
    95
fun quotdata_lookup_thy thy str = 
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
    96
    Symtab.lookup (QuotData.get thy) (Sign.intern_type thy str)
7d3d86beacd6 started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
    97
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    98
val quotdata_lookup = quotdata_lookup_thy o ProofContext.theory_of
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
314
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 311
diff changeset
   100
fun quotdata_update_thy qty_name (qty, rty, rel, equiv_thm) =
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
   101
      QuotData.map (Symtab.update (qty_name, {qtyp = qty, rtyp = rty, rel = rel, equiv_thm = equiv_thm}))
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
   103
fun quotdata_update qty_name (qty, rty, rel, equiv_thm) = 
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
   104
      ProofContext.theory (quotdata_update_thy qty_name (qty, rty, rel, equiv_thm))
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
460
3f8c7183ddac added facilities to get all stored quotient data (equiv thms etc)
Christian Urban <urbanc@in.tum.de>
parents: 450
diff changeset
   106
fun quotdata_dest thy =
3f8c7183ddac added facilities to get all stored quotient data (equiv thms etc)
Christian Urban <urbanc@in.tum.de>
parents: 450
diff changeset
   107
    map snd (Symtab.dest (QuotData.get thy))
3f8c7183ddac added facilities to get all stored quotient data (equiv thms etc)
Christian Urban <urbanc@in.tum.de>
parents: 450
diff changeset
   108
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   109
fun print_quotinfo ctxt =
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
let
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  fun prt_quot {qtyp, rtyp, rel, equiv_thm} = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
      Pretty.block (Library.separate (Pretty.brk 2)
324
Christian Urban <urbanc@in.tum.de>
parents: 322
diff changeset
   113
          [Pretty.str "quotient type:", 
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
           Syntax.pretty_typ ctxt qtyp,
324
Christian Urban <urbanc@in.tum.de>
parents: 322
diff changeset
   115
           Pretty.str "raw type:", 
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
           Syntax.pretty_typ ctxt rtyp,
324
Christian Urban <urbanc@in.tum.de>
parents: 322
diff changeset
   117
           Pretty.str "relation:", 
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
           Syntax.pretty_term ctxt rel,
324
Christian Urban <urbanc@in.tum.de>
parents: 322
diff changeset
   119
           Pretty.str "equiv. thm:", 
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
           Syntax.pretty_term ctxt (prop_of equiv_thm)])
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
in
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  QuotData.get (ProofContext.theory_of ctxt)
311
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
   123
  |> Symtab.dest
77fc6f3c0343 changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
   124
  |> map (prt_quot o snd)
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  |> Pretty.big_list "quotients:" 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  |> Pretty.writeln
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
end
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
val _ = 
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  OuterSyntax.improper_command "print_quotients" "print out all quotients" 
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   131
    OuterKeyword.diag (Scan.succeed (Toplevel.keep (print_quotinfo o Toplevel.context_of)))
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
268
4d58c02289ca simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   133
450
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
   134
(* info about quotient constants *)
496
8f1bf5266ebc Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 460
diff changeset
   135
type qconsts_info = {qconst: term, rconst: term, def: thm}
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   136
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   137
structure QConstsData = Theory_Data
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   138
  (type T = qconsts_info Symtab.table
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   139
   val empty = Symtab.empty
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   140
   val extend = I
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   141
   val merge = Symtab.merge (K true))
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   142
496
8f1bf5266ebc Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 460
diff changeset
   143
fun qconsts_transfer phi {qconst, rconst, def} =
318
746b17e1d6d8 fixed the storage of qconst definitions
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   144
    {qconst = Morphism.term phi qconst,
496
8f1bf5266ebc Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 460
diff changeset
   145
     rconst = Morphism.term phi rconst,
8f1bf5266ebc Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 460
diff changeset
   146
     def = Morphism.thm phi def}
318
746b17e1d6d8 fixed the storage of qconst definitions
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   147
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   148
fun qconsts_update_thy id qcinfo = QConstsData.map (Symtab.update (id, qcinfo))
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   149
fun qconsts_update_gen id qcinfo = Context.mapping (qconsts_update_thy id qcinfo) I
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   150
497
b663bc007d00 Added qoutient_consts dest for getting all the constant definitions in the cleaning step.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 496
diff changeset
   151
fun qconsts_dest thy =
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   152
  map snd (Symtab.dest (QConstsData.get thy))
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   153
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   154
fun qconsts_lookup thy t =
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   155
  let
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   156
    val smt = Symtab.dest (QConstsData.get thy);
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   157
    val (name, qty) = dest_Const t
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   158
    fun matches (_, x) =
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   159
      let
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   160
        val (name', qty') = dest_Const (#qconst x);
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   161
      in
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   162
        name = name' andalso Sign.typ_instance thy (qty, qty')
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   163
      end
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   164
  in
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   165
    case (find_first matches smt) of
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   166
      SOME (_, x) => x
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   167
    | _ => raise NotFound
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 643
diff changeset
   168
  end
497
b663bc007d00 Added qoutient_consts dest for getting all the constant definitions in the cleaning step.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 496
diff changeset
   169
496
8f1bf5266ebc Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 460
diff changeset
   170
(* We don't print the definition *)
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   171
fun print_qconstinfo ctxt =
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   172
let
496
8f1bf5266ebc Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 460
diff changeset
   173
  fun prt_qconst {qconst, rconst, def} =
318
746b17e1d6d8 fixed the storage of qconst definitions
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   174
      Pretty.block (separate (Pretty.brk 1)
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   175
          [Syntax.pretty_term ctxt qconst,
318
746b17e1d6d8 fixed the storage of qconst definitions
Christian Urban <urbanc@in.tum.de>
parents: 314
diff changeset
   176
           Pretty.str ":=",
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   177
           Syntax.pretty_term ctxt rconst])
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   178
in
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   179
  QConstsData.get (ProofContext.theory_of ctxt)
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   180
  |> Symtab.dest
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   181
  |> map (prt_qconst o snd)
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   182
  |> Pretty.big_list "quotient constants:" 
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   183
  |> Pretty.writeln
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   184
end
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   185
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   186
val _ = 
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   187
  OuterSyntax.improper_command "print_quotconsts" "print out all quotient constants" 
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   188
    OuterKeyword.diag (Scan.succeed (Toplevel.keep (print_qconstinfo o Toplevel.context_of)))
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 306
diff changeset
   189
614
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   190
(* FIXME/TODO: check the various lemmas conform *)
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   191
(* with the required shape                      *)
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   192
582
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   193
(* equivalence relation theorems *)
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   194
structure EquivRules = Named_Thms
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   195
  (val name = "quot_equiv"
582
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   196
   val description = "Equivalence relation theorems.")
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   197
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   198
val equiv_rules_get = EquivRules.get
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   199
val equiv_rules_add = EquivRules.add
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   200
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   201
(* respectfulness theorems *)
450
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
   202
structure RspRules = Named_Thms
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   203
  (val name = "quot_respect"
450
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
   204
   val description = "Respectfulness theorems.")
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
   205
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
   206
val rsp_rules_get = RspRules.get
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
   207
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   208
(* preservation theorems *)
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   209
structure PrsRules = Named_Thms
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   210
  (val name = "quot_preserve"
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   211
   val description = "Respectfulness theorems.")
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   212
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   213
val prs_rules_get = PrsRules.get
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   214
614
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   215
(* respectfulness theorems *)
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   216
structure IdSimps = Named_Thms
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   217
  (val name = "id_simps"
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   218
   val description = "Identity simp rules for maps.")
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   219
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   220
val id_simps_get = IdSimps.get
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   221
582
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   222
(* quotient theorems *)
503
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
   223
structure QuotientRules = Named_Thms
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 614
diff changeset
   224
  (val name = "quot_thm"
503
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
   225
   val description = "Quotient theorems.")
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
   226
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
   227
val quotient_rules_get = QuotientRules.get
582
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   228
val quotient_rules_add = QuotientRules.add
503
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
   229
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
   230
(* setup of the theorem lists *)
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
   231
val _ = Context.>> (Context.map_theory 
582
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   232
    (EquivRules.setup #>
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 549
diff changeset
   233
     RspRules.setup #>
643
cd4226736c37 properly set up the prs_rules
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
   234
     PrsRules.setup #>
614
51a4208162ed added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents: 613
diff changeset
   235
     IdSimps.setup #>
503
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 460
diff changeset
   236
     QuotientRules.setup))
450
2dc708ddb93a introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
parents: 406
diff changeset
   237
264
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
end; (* structure *)
d0581fbc096c split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
314
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 311
diff changeset
   240
open Quotient_Info