Quot/quotient_def.ML
author Christian Urban <urbanc@in.tum.de>
Wed, 23 Dec 2009 13:45:42 +0100
changeset 781 f3a24012e9d8
parent 776 d1064fa29424
child 789 8237786171f1
permissions -rw-r--r--
renamed QUOT_TYPE to Quot_Type
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
signature QUOTIENT_DEF =
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 768
diff changeset
     3
sig 
709
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
     4
  val quotient_def: mixfix -> Attrib.binding -> term -> term ->
775
Christian Urban <urbanc@in.tum.de>
parents: 774
diff changeset
     5
    local_theory -> (term * thm) * local_theory
705
f51c6069cd17 New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 670
diff changeset
     6
  val quotdef_cmd: (Attrib.binding * string) * (mixfix * string) ->
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
    local_theory -> local_theory
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
end;
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
structure Quotient_Def: QUOTIENT_DEF =
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
struct
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
762
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
    13
open Quotient_Info;
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 768
diff changeset
    14
open Quotient_Term;
762
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
    15
279
b2fd070c8833 slightly tuned
Christian Urban <urbanc@in.tum.de>
parents: 277
diff changeset
    16
(* wrapper for define *)
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
fun define name mx attr rhs lthy =
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
let
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  val ((rhs, (_ , thm)), lthy') =
331
345c422b1cb5 updated to Isabelle 22nd November
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
    20
     Local_Theory.define ((name, mx), (attr, rhs)) lthy
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
in
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  ((rhs, thm), lthy')
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
end
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
709
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    26
(* interface and syntax setup *)
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    27
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    28
(* the ML-interface takes a 4-tuple consisting of *)
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    29
(*                                                *)
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    30
(* - the mixfix annotation                        *)
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    31
(* - name and attributes of the meta eq           *)
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    32
(* - the new constant including its type          *)
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    33
(* - the rhs of the definition                    *)
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 719
diff changeset
    34
709
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    35
fun quotient_def mx attr lhs rhs lthy =
293
653460d3e849 tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents: 290
diff changeset
    36
let
705
f51c6069cd17 New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 670
diff changeset
    37
  val Free (lhs_str, lhs_ty) = lhs;
f51c6069cd17 New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 670
diff changeset
    38
  val qconst_bname = Binding.name lhs_str;
776
d1064fa29424 renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents: 775
diff changeset
    39
  val absrep_trm = absrep_fun_chk absF lthy (fastype_of rhs, lhs_ty) $ rhs
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 598
diff changeset
    40
  val prop = Logic.mk_equals (lhs, absrep_trm)
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 598
diff changeset
    41
  val (_, prop') = LocalDefs.cert_def lthy prop
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 598
diff changeset
    42
  val (_, newrhs) = Primitive_Defs.abs_def prop'
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
    43
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 598
diff changeset
    44
  val ((trm, thm), lthy') = define qconst_bname mx attr newrhs lthy
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
    45
496
8f1bf5266ebc Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 389
diff changeset
    46
  fun qcinfo phi = qconsts_transfer phi {qconst = trm, rconst = rhs, def = thm}
319
0ae9d9e66cb7 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
    47
  val lthy'' = Local_Theory.declaration true
705
f51c6069cd17 New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 670
diff changeset
    48
                 (fn phi => qconsts_update_gen lhs_str (qcinfo phi)) lthy'
293
653460d3e849 tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents: 290
diff changeset
    49
in
310
fec6301a1989 added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
    50
  ((trm, thm), lthy'')
293
653460d3e849 tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents: 290
diff changeset
    51
end
653460d3e849 tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents: 290
diff changeset
    52
709
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    53
fun quotdef_cmd ((attr, lhsstr), (mx, rhsstr)) lthy =
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
let
663
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 598
diff changeset
    55
  val lhs = Syntax.read_term lthy lhsstr
0dd10a900cae Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 598
diff changeset
    56
  val rhs = Syntax.read_term lthy rhsstr
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
in
709
596467882518 Updated comments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 705
diff changeset
    58
  quotient_def mx attr lhs rhs lthy |> snd
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
end
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
705
f51c6069cd17 New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 670
diff changeset
    61
val _ = OuterKeyword.keyword "as";
f51c6069cd17 New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 670
diff changeset
    62
279
b2fd070c8833 slightly tuned
Christian Urban <urbanc@in.tum.de>
parents: 277
diff changeset
    63
val quotdef_parser =
705
f51c6069cd17 New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 670
diff changeset
    64
  (SpecParse.opt_thm_name ":" --
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 719
diff changeset
    65
     OuterParse.term) --
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 719
diff changeset
    66
      (OuterParse.opt_mixfix' --| OuterParse.$$$ "as" --
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 719
diff changeset
    67
         OuterParse.term)
279
b2fd070c8833 slightly tuned
Christian Urban <urbanc@in.tum.de>
parents: 277
diff changeset
    68
767
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    69
val _ = OuterSyntax.local_theory "quotient_definition" 
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    70
	  "definition for constants over the quotient type"
37285ec4387d on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    71
             OuterKeyword.thy_decl (quotdef_parser >> quotdef_cmd)
277
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
end; (* structure *)
37636f2b1c19 separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
321
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    75
f46dc0ca08c3 simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    76
762
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
    77