Attic/Quot/quotient_typ.ML
author Christian Urban <urbanc@in.tum.de>
Sun, 14 Mar 2010 11:36:15 +0100
changeset 1437 45fb38a2e3f7
parent 1260 9df6144e281b
child 1438 61671de8a545
permissions -rw-r--r--
localised the typedef in Attic (requires new Isabelle)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 918
diff changeset
     1
(*  Title:      quotient_typ.thy
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 918
diff changeset
     2
    Author:     Cezary Kaliszyk and Christian Urban
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 918
diff changeset
     3
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 918
diff changeset
     4
    Definition of a quotient type.
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 918
diff changeset
     5
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 918
diff changeset
     6
*)
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 918
diff changeset
     7
762
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
     8
signature QUOTIENT_TYPE =
127
b054cf6bd179 the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
     9
sig
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
    10
  val quotient_type: ((string list * binding * mixfix) * (typ * term)) list
787
5cf83fa5b36c made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    11
    -> Proof.context -> Proof.state
789
Christian Urban <urbanc@in.tum.de>
parents: 788
diff changeset
    12
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
    13
  val quotient_type_cmd: ((((string list * binding) * mixfix) * string) * string) list
787
5cf83fa5b36c made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    14
    -> Proof.context -> Proof.state
127
b054cf6bd179 the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    15
end;
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
762
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
    17
structure Quotient_Type: QUOTIENT_TYPE =
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
struct
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
762
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
    20
open Quotient_Info;
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
    21
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 725
diff changeset
    22
(* wrappers for define, note, Attrib.internal and theorem_i *)
135
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    23
fun define (name, mx, rhs) lthy =
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    24
let
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    25
  val ((rhs, (_ , thm)), lthy') =
331
345c422b1cb5 updated to Isabelle 22nd November
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
    26
     Local_Theory.define ((name, mx), (Attrib.empty_binding, rhs)) lthy
135
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    27
in
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    28
  ((rhs, thm), lthy')
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    29
end
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    30
503
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 447
diff changeset
    31
fun note (name, thm, attrs) lthy =
135
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    32
let
503
d2c9a72e52e0 first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 447
diff changeset
    33
  val ((_,[thm']), lthy') = Local_Theory.note ((name, attrs), [thm]) lthy
135
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    34
in
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    35
  (thm', lthy')
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    36
end
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    37
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 725
diff changeset
    38
fun intern_attr at = Attrib.internal (K at)
582
a082e2d138ab added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
    39
203
7384115df9fd added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    40
fun theorem after_qed goals ctxt =
7384115df9fd added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    41
let
7384115df9fd added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    42
  val goals' = map (rpair []) goals
7384115df9fd added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    43
  fun after_qed' thms = after_qed (the_single thms)
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
    44
in
203
7384115df9fd added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    45
  Proof.theorem_i NONE after_qed' [goals'] ctxt
7384115df9fd added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    46
end
135
6f0d14ba096c started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 130
diff changeset
    47
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 128
diff changeset
    48
838
a32f4f866051 started to adhere to Wenzel-Standard
Christian Urban <urbanc@in.tum.de>
parents: 805
diff changeset
    49
a32f4f866051 started to adhere to Wenzel-Standard
Christian Urban <urbanc@in.tum.de>
parents: 805
diff changeset
    50
(*** definition of quotient types ***)
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 128
diff changeset
    51
780
a24e26f5488c explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    52
val mem_def1 = @{lemma "y : S ==> S y" by (simp add: mem_def)}
a24e26f5488c explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    53
val mem_def2 = @{lemma "S y ==> y : S" by (simp add: mem_def)}
a24e26f5488c explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
    54
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
    55
(* constructs the term lambda (c::rty => bool). EX (x::rty). c = rel x *)
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
fun typedef_term rel rty lthy =
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
let
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    58
  val [x, c] =
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    59
    [("x", rty), ("c", HOLogic.mk_setT rty)]
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    60
    |> Variable.variant_frees lthy [rel]
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    61
    |> map Free
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
in
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
    63
  lambda c (HOLogic.exists_const rty $
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
    64
     lambda x (HOLogic.mk_eq (c, (rel $ x))))
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
end
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
    67
788
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
    68
(* makes the new type definitions and proves non-emptyness *)
787
5cf83fa5b36c made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    69
fun typedef_make (vs, qty_name, mx, rel, rty) lthy =
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
let
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  val typedef_tac =
792
Christian Urban <urbanc@in.tum.de>
parents: 790
diff changeset
    72
     EVERY1 (map rtac [@{thm exI}, mem_def2, @{thm exI}, @{thm refl}])
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
in
1437
45fb38a2e3f7 localised the typedef in Attic (requires new Isabelle)
Christian Urban <urbanc@in.tum.de>
parents: 1260
diff changeset
    74
  Typedef.add_typedef false NONE
787
5cf83fa5b36c made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    75
       (qty_name, vs, mx)
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
    76
          (typedef_term rel rty lthy)
1437
45fb38a2e3f7 localised the typedef in Attic (requires new Isabelle)
Christian Urban <urbanc@in.tum.de>
parents: 1260
diff changeset
    77
             NONE typedef_tac lthy
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
end
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
    80
1124
4a4c714ff795 lowercase locale
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1110
diff changeset
    81
(* tactic to prove the quot_type theorem for the new type *)
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) =
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
let
885
fe7d27e197e5 tuned quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents: 866
diff changeset
    84
  val rep_thm = #Rep typedef_info RS mem_def1
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  val rep_inv = #Rep_inverse typedef_info
885
fe7d27e197e5 tuned quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents: 866
diff changeset
    86
  val abs_inv = mem_def2 RS #Abs_inverse typedef_info
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  val rep_inj = #Rep_inject typedef_info
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
in
1124
4a4c714ff795 lowercase locale
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1110
diff changeset
    89
  (rtac @{thm quot_type.intro} THEN' RANGE [
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    90
    rtac equiv_thm,
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    91
    rtac rep_thm,
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    92
    rtac rep_inv,
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    93
    EVERY' (map rtac [abs_inv, @{thm exI}, @{thm refl}]),
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
    94
    rtac rep_inj]) 1
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
end
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
    97
1124
4a4c714ff795 lowercase locale
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1110
diff changeset
    98
(* proves the quot_type theorem for the new type *)
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy =
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
let
1124
4a4c714ff795 lowercase locale
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1110
diff changeset
   101
  val quot_type_const = Const (@{const_name "quot_type"}, dummyT)
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   102
  val goal =
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   103
    HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep)
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   104
    |> Syntax.check_term lthy
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
in
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  Goal.prove lthy [] [] goal
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
    (K (typedef_quot_type_tac equiv_thm typedef_info))
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
end
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
885
fe7d27e197e5 tuned quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents: 866
diff changeset
   110
(* proves the quotient theorem for the new type *)
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
fun typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_type_thm) lthy =
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
let
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 503
diff changeset
   113
  val quotient_const = Const (@{const_name "Quotient"}, dummyT)
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   114
  val goal =
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   115
    HOLogic.mk_Trueprop (quotient_const $ rel $ abs $ rep)
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   116
    |> Syntax.check_term lthy
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  val typedef_quotient_thm_tac =
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   119
    EVERY1 [
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   120
      K (rewrite_goals_tac [abs_def, rep_def]),
1124
4a4c714ff795 lowercase locale
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1110
diff changeset
   121
      rtac @{thm quot_type.Quotient},
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   122
      rtac quot_type_thm]
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
in
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
  Goal.prove lthy [] [] goal
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
    (K typedef_quotient_thm_tac)
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
end
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
   128
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 725
diff changeset
   129
(* main function for constructing a quotient type *)
885
fe7d27e197e5 tuned quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents: 866
diff changeset
   130
fun mk_quotient_type (((vs, qty_name, mx), (rty, rel)), equiv_thm) lthy =
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
let
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 725
diff changeset
   132
  (* generates the typedef *)
787
5cf83fa5b36c made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   133
  val ((qty_full_name, typedef_info), lthy1) = typedef_make (vs, qty_name, mx, rel, rty) lthy
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 725
diff changeset
   135
  (* abs and rep functions from the typedef *)
782
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   136
  val Abs_ty = #abs_type typedef_info
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   137
  val Rep_ty = #rep_type typedef_info
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   138
  val Abs_name = #Abs_name typedef_info
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   139
  val Rep_name = #Rep_name typedef_info
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   140
  val Abs_const = Const (Abs_name, Rep_ty --> Abs_ty)
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   141
  val Rep_const = Const (Rep_name, Abs_ty --> Rep_ty)
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
792
Christian Urban <urbanc@in.tum.de>
parents: 790
diff changeset
   143
  (* more useful abs and rep definitions *)
1124
4a4c714ff795 lowercase locale
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1110
diff changeset
   144
  val abs_const = Const (@{const_name "quot_type.abs"}, dummyT )
4a4c714ff795 lowercase locale
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1110
diff changeset
   145
  val rep_const = Const (@{const_name "quot_type.rep"}, dummyT )
782
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   146
  val abs_trm = Syntax.check_term lthy1 (abs_const $ rel $ Abs_const)
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   147
  val rep_trm = Syntax.check_term lthy1 (rep_const $ Rep_const)
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   148
  val abs_name = Binding.prefix_name "abs_" qty_name
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   149
  val rep_name = Binding.prefix_name "rep_" qty_name
781
f3a24012e9d8 renamed QUOT_TYPE to Quot_Type
Christian Urban <urbanc@in.tum.de>
parents: 780
diff changeset
   150
782
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   151
  val ((abs, abs_def), lthy2) = define (abs_name, NoSyn, abs_trm) lthy1
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   152
  val ((rep, rep_def), lthy3) = define (rep_name, NoSyn, rep_trm) lthy2
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
885
fe7d27e197e5 tuned quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents: 866
diff changeset
   154
  (* quot_type theorem *)
782
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   155
  val quot_thm = typedef_quot_type_thm (rel, Abs_const, Rep_const, equiv_thm, typedef_info) lthy3
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   157
  (* quotient theorem *)
782
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   158
  val quotient_thm = typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_thm) lthy3
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 503
diff changeset
   159
  val quotient_thm_name = Binding.prefix_name "Quotient_" qty_name
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
782
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   161
  (* name equivalence theorem *)
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   162
  val equiv_thm_name = Binding.suffix_name "_equivp" qty_name
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   163
182
c7eff9882bd8 added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   164
  (* storing the quot-info *)
799
0755f8fd56b3 renamed transfer to transform (Markus)
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   165
  fun qinfo phi = transform_quotdata phi
1110
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   166
    {qtyp = Abs_ty, rtyp = rty, equiv_rel = rel, equiv_thm = equiv_thm}
786
d6407afb913c used Local_Theory.declaration for storing quotdata
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
   167
  val lthy4 = Local_Theory.declaration true
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   168
    (fn phi => quotdata_update_gen qty_full_name (qinfo phi)) lthy3
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
in
781
f3a24012e9d8 renamed QUOT_TYPE to Quot_Type
Christian Urban <urbanc@in.tum.de>
parents: 780
diff changeset
   170
  lthy4
780
a24e26f5488c explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
parents: 766
diff changeset
   171
  |> note (quotient_thm_name, quotient_thm, [intern_attr quotient_rules_add])
782
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 781
diff changeset
   172
  ||>> note (equiv_thm_name, equiv_thm, [intern_attr equiv_rules_add])
71
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
end
35be65791f1d exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
   175
805
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   176
(* sanity checks for the quotient type specifications *)
788
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   177
fun sanity_check ((vs, qty_name, _), (rty, rel)) =
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   178
let
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   179
  val rty_tfreesT = map fst (Term.add_tfreesT rty [])
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   180
  val rel_tfrees = map fst (Term.add_tfrees rel [])
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   181
  val rel_frees = map fst (Term.add_frees rel [])
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   182
  val rel_vars = Term.add_vars rel []
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   183
  val rel_tvars = Term.add_tvars rel []
885
fe7d27e197e5 tuned quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents: 866
diff changeset
   184
  val qty_str = Binding.str_of qty_name ^ ": "
788
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   185
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   186
  val illegal_rel_vars =
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   187
    if null rel_vars andalso null rel_tvars then []
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   188
    else [qty_str ^ "illegal schematic variable(s) in the relation."]
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   189
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   190
  val dup_vs =
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   191
    (case duplicates (op =) vs of
788
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   192
       [] => []
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   193
     | dups => [qty_str ^ "duplicate type variable(s) on the lhs: " ^ commas_quote dups])
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   194
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   195
  val extra_rty_tfrees =
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   196
    (case subtract (op =) vs rty_tfreesT of
788
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   197
       [] => []
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   198
     | extras => [qty_str ^ "extra type variable(s) on the lhs: " ^ commas_quote extras])
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   199
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   200
  val extra_rel_tfrees =
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   201
    (case subtract (op =) vs rel_tfrees of
788
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   202
       [] => []
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   203
     | extras => [qty_str ^ "extra type variable(s) in the relation: " ^ commas_quote extras])
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   204
788
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   205
  val illegal_rel_frees =
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   206
    (case rel_frees of
788
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   207
      [] => []
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   208
    | xs => [qty_str ^ "illegal variable(s) in the relation: " ^ commas_quote xs])
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   209
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   210
  val errs = illegal_rel_vars @ dup_vs @ extra_rty_tfrees @ extra_rel_tfrees @ illegal_rel_frees
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   211
in
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   212
  if null errs then () else error (cat_lines errs)
0b60d8416ec5 added sanity checks for quotient_type
Christian Urban <urbanc@in.tum.de>
parents: 787
diff changeset
   213
end
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 128
diff changeset
   214
805
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   215
(* check for existence of map functions *)
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   216
fun map_check ctxt (_, (rty, _)) =
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   217
let
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   218
  val thy = ProofContext.theory_of ctxt
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   219
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   220
  fun map_check_aux rty warns =
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   221
    case rty of
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   222
      Type (_, []) => warns
885
fe7d27e197e5 tuned quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents: 866
diff changeset
   223
    | Type (s, _) => if maps_defined thy s then warns else s::warns
805
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   224
    | _ => warns
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   225
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   226
  val warns = map_check_aux rty []
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   227
in
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   228
  if null warns then ()
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   229
  else warning ("No map function defined for " ^ commas warns ^
1101
5eb84b817855 More indentation cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   230
    ". This will cause problems later on.")
805
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   231
end
d193e2111811 added a warning to the quotient_type definition, if a map function is missing
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   232
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 789
diff changeset
   233
838
a32f4f866051 started to adhere to Wenzel-Standard
Christian Urban <urbanc@in.tum.de>
parents: 805
diff changeset
   234
a32f4f866051 started to adhere to Wenzel-Standard
Christian Urban <urbanc@in.tum.de>
parents: 805
diff changeset
   235
(*** interface and syntax setup ***)
a32f4f866051 started to adhere to Wenzel-Standard
Christian Urban <urbanc@in.tum.de>
parents: 805
diff changeset
   236
75
5fe163543bb8 started some strange functions
Christian Urban <urbanc@in.tum.de>
parents: 71
diff changeset
   237
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   238
(* the ML-interface takes a list of 5-tuples consisting of:
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   239
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   240
 - the name of the quotient type
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   241
 - its free type variables (first argument)
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   242
 - its mixfix annotation
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   243
 - the type to be quotient
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   244
 - the relation according to which the type is quotient
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   245
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   246
 it opens a proof-state in which one has to show that the
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 838
diff changeset
   247
 relations are equivalence relations
838
a32f4f866051 started to adhere to Wenzel-Standard
Christian Urban <urbanc@in.tum.de>
parents: 805
diff changeset
   248
*)
130
8e8ba210f0f7 moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents: 128
diff changeset
   249
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   250
fun quotient_type quot_list lthy =
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   251
let
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   252
  (* sanity check *)
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   253
  val _ = List.app sanity_check quot_list
838
a32f4f866051 started to adhere to Wenzel-Standard
Christian Urban <urbanc@in.tum.de>
parents: 805
diff changeset
   254
  val _ = List.app (map_check lthy) quot_list
800
71225f4a4635 some slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 799
diff changeset
   255
185
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   256
  fun mk_goal (rty, rel) =
127
b054cf6bd179 the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   257
  let
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 503
diff changeset
   258
    val equivp_ty = ([rty, rty] ---> @{typ bool}) --> @{typ bool}
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   259
  in
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 503
diff changeset
   260
    HOLogic.mk_Trueprop (Const (@{const_name equivp}, equivp_ty) $ rel)
127
b054cf6bd179 the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   261
  end
b054cf6bd179 the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   262
185
929bc55efff7 added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents: 182
diff changeset
   263
  val goals = map (mk_goal o snd) quot_list
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   264
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   265
  fun after_qed thms lthy =
885
fe7d27e197e5 tuned quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents: 866
diff changeset
   266
    fold_map mk_quotient_type (quot_list ~~ thms) lthy |> snd
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   267
in
203
7384115df9fd added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
   268
  theorem after_qed goals lthy
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   269
end
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   270
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   271
fun quotient_type_cmd specs lthy =
205
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   272
let
1110
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   273
  fun parse_spec ((((vs, qty_name), mx), rty_str), rel_str) lthy =
205
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   274
  let
1110
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   275
    (* new parsing with proper declaration *)
293
653460d3e849 tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents: 290
diff changeset
   276
    val rty = Syntax.read_typ lthy rty_str
1110
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   277
    val lthy1 = Variable.declare_typ rty lthy
1152
fbaebf08c1bd further tuning
Christian Urban <urbanc@in.tum.de>
parents: 1128
diff changeset
   278
    val rel = 
1162
6642df770bc4 indenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1155
diff changeset
   279
      Syntax.parse_term lthy1 rel_str
6642df770bc4 indenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1155
diff changeset
   280
      |> Syntax.type_constraint (rty --> rty --> @{typ bool}) 
6642df770bc4 indenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1155
diff changeset
   281
      |> Syntax.check_term lthy1 
1110
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   282
    val lthy2 = Variable.declare_term rel lthy1
205
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   283
  in
1110
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   284
    (((vs, qty_name, mx), (rty, rel)), lthy2)
205
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   285
  end
1110
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   286
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   287
  val (spec', lthy') = fold_map parse_spec specs lthy
205
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   288
in
1110
1e5dee9e6ae2 proper declaration of types and terms during parsing (removes the varifyT when storing data)
Christian Urban <urbanc@in.tum.de>
parents: 1101
diff changeset
   289
  quotient_type spec' lthy'
205
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   290
end
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   291
1152
fbaebf08c1bd further tuning
Christian Urban <urbanc@in.tum.de>
parents: 1128
diff changeset
   292
local
fbaebf08c1bd further tuning
Christian Urban <urbanc@in.tum.de>
parents: 1128
diff changeset
   293
  structure P = OuterParse;
fbaebf08c1bd further tuning
Christian Urban <urbanc@in.tum.de>
parents: 1128
diff changeset
   294
in
fbaebf08c1bd further tuning
Christian Urban <urbanc@in.tum.de>
parents: 1128
diff changeset
   295
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   296
val quotspec_parser =
1155
5650924c69ed 2-spaces rule (where it makes sense)
Christian Urban <urbanc@in.tum.de>
parents: 1152
diff changeset
   297
  P.and_list1 ((P.type_args -- P.binding) -- P.opt_infix -- 
5650924c69ed 2-spaces rule (where it makes sense)
Christian Urban <urbanc@in.tum.de>
parents: 1152
diff changeset
   298
    (P.$$$ "=" |-- P.typ) -- (P.$$$ "/" |-- P.term))
1152
fbaebf08c1bd further tuning
Christian Urban <urbanc@in.tum.de>
parents: 1128
diff changeset
   299
end
75
5fe163543bb8 started some strange functions
Christian Urban <urbanc@in.tum.de>
parents: 71
diff changeset
   300
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   301
val _ = OuterKeyword.keyword "/"
75
5fe163543bb8 started some strange functions
Christian Urban <urbanc@in.tum.de>
parents: 71
diff changeset
   302
1128
17ca92ab4660 Main renaming + fixes for new Isabelle in IntEx2.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1124
diff changeset
   303
val _ =
1166
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1162
diff changeset
   304
  OuterSyntax.local_theory_to_proof "quotient_type"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1162
diff changeset
   305
    "quotient type definitions (require equivalence proofs)"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1162
diff changeset
   306
       OuterKeyword.thy_goal (quotspec_parser >> quotient_type_cmd)
79
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   307
c0c41fefeb06 added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   308
end; (* structure *)