src/HOL/Tools/Quotient/quotient_typ.ML
author wenzelm
Thu, 27 Oct 2011 20:26:38 +0200
changeset 45279 89a17197cb98
parent 45278 7c6c8e950636
child 45280 9fd6fce8a230
permissions -rw-r--r--
simplified/standardized signatures;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37744
3daaf23b9ab4 tuned titles
haftmann
parents: 37530
diff changeset
     1
(*  Title:      HOL/Tools/Quotient/quotient_typ.ML
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     2
    Author:     Cezary Kaliszyk and Christian Urban
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
35806
a814cccce0b8 rollback of local typedef until problem with type-variables can be sorted out; fixed header
Christian Urban <urbanc@in.tum.de>
parents: 35790
diff changeset
     4
Definition of a quotient type.
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     5
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
signature QUOTIENT_TYPE =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     8
sig
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
     9
  val add_quotient_type: ((string list * binding * mixfix) * (typ * term * bool)) * thm
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 45278
diff changeset
    10
    -> Proof.context -> Quotient_Info.quotients * local_theory
35415
1810b1ade437 export add_quotient_type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35351
diff changeset
    11
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
    12
  val quotient_type: ((string list * binding * mixfix) * (typ * term * bool)) list
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
    -> Proof.context -> Proof.state
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    14
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
    15
  val quotient_type_cmd: ((((string list * binding) * mixfix) * string) * (bool * string)) list
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
    -> Proof.context -> Proof.state
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    17
end;
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    18
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    19
structure Quotient_Type: QUOTIENT_TYPE =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    20
struct
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    21
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
    22
(* wrappers for define, note, Attrib.internal and theorem_i *)  (* FIXME !? *)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    23
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    24
fun define (name, mx, rhs) lthy =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    25
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    26
    val ((rhs, (_ , thm)), lthy') =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    27
      Local_Theory.define ((name, mx), (Attrib.empty_binding, rhs)) lthy
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    28
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    29
    ((rhs, thm), lthy')
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    30
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    32
fun note (name, thm, attrs) lthy =
37530
70d03844b2f9 export of proper information in the ML-interface of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37493
diff changeset
    33
  Local_Theory.note ((name, attrs), [thm]) lthy |> snd
70d03844b2f9 export of proper information in the ML-interface of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37493
diff changeset
    34
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    36
fun intern_attr at = Attrib.internal (K at)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
fun theorem after_qed goals ctxt =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    39
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    40
    val goals' = map (rpair []) goals
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    41
    fun after_qed' thms = after_qed (the_single thms)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    42
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    43
    Proof.theorem NONE after_qed' [goals'] ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    44
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    46
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    47
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
(*** definition of quotient types ***)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
44204
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    50
val mem_def1 = @{lemma "y : Collect S ==> S y" by simp}
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    51
val mem_def2 = @{lemma "S y ==> y : Collect S" by simp}
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    53
(* constructs the term lambda (c::rty => bool). EX (x::rty). c = rel x *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    54
fun typedef_term rel rty lthy =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    55
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    56
    val [x, c] =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    57
      [("x", rty), ("c", HOLogic.mk_setT rty)]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    58
      |> Variable.variant_frees lthy [rel]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    59
      |> map Free
44204
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    60
    fun mk_collect T =
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    61
      Const (@{const_name Collect}, (T --> @{typ bool}) --> HOLogic.mk_setT T)
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    62
    val collect_in = mk_collect rty
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    63
    val collect_out = mk_collect (HOLogic.mk_setT rty)
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    64
  in
44204
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    65
    collect_out $ (lambda c (HOLogic.exists_const rty $
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    66
        lambda x (HOLogic.mk_conj (rel $ x $ x,
3cdc4176638c Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43547
diff changeset
    67
        HOLogic.mk_eq (c, collect_in $ (rel $ x))))))
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    68
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    71
(* makes the new type definitions and proves non-emptyness *)
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
    72
fun typedef_make (vs, qty_name, mx, rel, rty) equiv_thm lthy =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    73
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    74
    val typedef_tac =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    75
      EVERY1 (map rtac [@{thm part_equivp_typedef}, equiv_thm])
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    76
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    77
  (* FIXME: purely local typedef causes at the moment
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    78
     problems with type variables
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    79
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    80
    Typedef.add_typedef false NONE (qty_name, vs, mx)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    81
      (typedef_term rel rty lthy) NONE typedef_tac lthy
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    82
  *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    83
  (* FIXME should really use local typedef here *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    84
    Local_Theory.background_theory_result
35806
a814cccce0b8 rollback of local typedef until problem with type-variables can be sorted out; fixed header
Christian Urban <urbanc@in.tum.de>
parents: 35790
diff changeset
    85
     (Typedef.add_typedef_global false NONE
35842
7c170d39a808 typedef etc.: no constraints;
wenzelm
parents: 35806
diff changeset
    86
       (qty_name, map (rpair dummyS) vs, mx)
35806
a814cccce0b8 rollback of local typedef until problem with type-variables can be sorted out; fixed header
Christian Urban <urbanc@in.tum.de>
parents: 35790
diff changeset
    87
         (typedef_term rel rty lthy)
a814cccce0b8 rollback of local typedef until problem with type-variables can be sorted out; fixed header
Christian Urban <urbanc@in.tum.de>
parents: 35790
diff changeset
    88
           NONE typedef_tac) lthy
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    89
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    90
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    92
(* tactic to prove the quot_type theorem for the new type *)
35994
9cc3df9a606e Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents: 35842
diff changeset
    93
fun typedef_quot_type_tac equiv_thm ((_, typedef_info): Typedef.info) =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    94
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    95
    val rep_thm = #Rep typedef_info RS mem_def1
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    96
    val rep_inv = #Rep_inverse typedef_info
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    97
    val abs_inv = #Abs_inverse typedef_info
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    98
    val rep_inj = #Rep_inject typedef_info
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
    99
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   100
    (rtac @{thm quot_type.intro} THEN' RANGE [
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   101
      rtac equiv_thm,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   102
      rtac rep_thm,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   103
      rtac rep_inv,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   104
      rtac abs_inv THEN' rtac mem_def2 THEN' atac,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   105
      rtac rep_inj]) 1
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   106
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   107
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   108
(* proves the quot_type theorem for the new type *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   109
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   110
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   111
    val quot_type_const = Const (@{const_name "quot_type"}, dummyT)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   112
    val goal =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   113
      HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   114
      |> Syntax.check_term lthy
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   115
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   116
    Goal.prove lthy [] [] goal
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   117
      (K (typedef_quot_type_tac equiv_thm typedef_info))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   118
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   119
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   120
(* main function for constructing a quotient type *)
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   121
fun add_quotient_type (((vs, qty_name, mx), (rty, rel, partial)), equiv_thm) lthy =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   122
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   123
    val part_equiv =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   124
      if partial
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   125
      then equiv_thm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   126
      else equiv_thm RS @{thm equivp_implies_part_equivp}
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   127
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   128
    (* generates the typedef *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   129
    val ((qty_full_name, typedef_info), lthy1) =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   130
      typedef_make (vs, qty_name, mx, rel, rty) part_equiv lthy
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   132
    (* abs and rep functions from the typedef *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   133
    val Abs_ty = #abs_type (#1 typedef_info)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   134
    val Rep_ty = #rep_type (#1 typedef_info)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   135
    val Abs_name = #Abs_name (#1 typedef_info)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   136
    val Rep_name = #Rep_name (#1 typedef_info)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   137
    val Abs_const = Const (Abs_name, Rep_ty --> Abs_ty)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   138
    val Rep_const = Const (Rep_name, Abs_ty --> Rep_ty)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   140
    (* more useful abs and rep definitions *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   141
    val abs_const = Const (@{const_name "quot_type.abs"}, dummyT )
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   142
    val rep_const = Const (@{const_name "quot_type.rep"}, dummyT )
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   143
    val abs_trm = Syntax.check_term lthy1 (abs_const $ rel $ Abs_const)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   144
    val rep_trm = Syntax.check_term lthy1 (rep_const $ Rep_const)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   145
    val abs_name = Binding.prefix_name "abs_" qty_name
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   146
    val rep_name = Binding.prefix_name "rep_" qty_name
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   147
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   148
    val ((_, abs_def), lthy2) = define (abs_name, NoSyn, abs_trm) lthy1
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   149
    val ((_, rep_def), lthy3) = define (rep_name, NoSyn, rep_trm) lthy2
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   150
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   151
    (* quot_type theorem *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   152
    val quot_thm = typedef_quot_type_thm (rel, Abs_const, Rep_const, part_equiv, typedef_info) lthy3
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   153
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   154
    (* quotient theorem *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   155
    val quotient_thm_name = Binding.prefix_name "Quotient_" qty_name
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   156
    val quotient_thm =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   157
      (quot_thm RS @{thm quot_type.Quotient})
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   158
      |> fold_rule [abs_def, rep_def]
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   159
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   160
    (* name equivalence theorem *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   161
    val equiv_thm_name = Binding.suffix_name "_equivp" qty_name
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   162
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 45278
diff changeset
   163
    (* storing the quotients *)
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 45278
diff changeset
   164
    val quotients = {qtyp = Abs_ty, rtyp = rty, equiv_rel = rel, equiv_thm = equiv_thm}
37530
70d03844b2f9 export of proper information in the ML-interface of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37493
diff changeset
   165
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 45278
diff changeset
   166
    fun qinfo phi = Quotient_Info.transform_quotients phi quotients
37530
70d03844b2f9 export of proper information in the ML-interface of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37493
diff changeset
   167
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   168
    val lthy4 = lthy3
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   169
      |> Local_Theory.declaration true
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 45278
diff changeset
   170
        (fn phi => Quotient_Info.update_quotients qty_full_name (qinfo phi))
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   171
      |> note
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   172
        (equiv_thm_name, equiv_thm,
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   173
          if partial then [] else [intern_attr Quotient_Info.equiv_rules_add])
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   174
      |> note (quotient_thm_name, quotient_thm, [intern_attr Quotient_Info.quotient_rules_add])
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   175
  in
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 45278
diff changeset
   176
    (quotients, lthy4)
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   177
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   179
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   180
(* sanity checks for the quotient type specifications *)
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   181
fun sanity_check ((vs, qty_name, _), (rty, rel, _)) =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   182
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   183
    val rty_tfreesT = map fst (Term.add_tfreesT rty [])
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   184
    val rel_tfrees = map fst (Term.add_tfrees rel [])
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   185
    val rel_frees = map fst (Term.add_frees rel [])
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   186
    val rel_vars = Term.add_vars rel []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   187
    val rel_tvars = Term.add_tvars rel []
43547
f3a8476285c6 clarified Binding.pretty/print: no quotes, only markup -- Binding.str_of is rendered obsolete;
wenzelm
parents: 42361
diff changeset
   188
    val qty_str = Binding.print qty_name ^ ": "
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   189
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   190
    val illegal_rel_vars =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   191
      if null rel_vars andalso null rel_tvars then []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   192
      else [qty_str ^ "illegal schematic variable(s) in the relation."]
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   193
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   194
    val dup_vs =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   195
      (case duplicates (op =) vs of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   196
        [] => []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   197
      | dups => [qty_str ^ "duplicate type variable(s) on the lhs: " ^ commas_quote dups])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   198
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   199
    val extra_rty_tfrees =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   200
      (case subtract (op =) vs rty_tfreesT of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   201
        [] => []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   202
      | extras => [qty_str ^ "extra type variable(s) on the lhs: " ^ commas_quote extras])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   203
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   204
    val extra_rel_tfrees =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   205
      (case subtract (op =) vs rel_tfrees of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   206
        [] => []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   207
      | extras => [qty_str ^ "extra type variable(s) in the relation: " ^ commas_quote extras])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   208
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   209
    val illegal_rel_frees =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   210
      (case rel_frees of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   211
        [] => []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   212
      | xs => [qty_str ^ "illegal variable(s) in the relation: " ^ commas_quote xs])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   213
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   214
    val errs = illegal_rel_vars @ dup_vs @ extra_rty_tfrees @ extra_rel_tfrees @ illegal_rel_frees
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   215
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   216
    if null errs then () else error (cat_lines errs)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   217
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   219
(* check for existence of map functions *)
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   220
fun map_check ctxt (_, (rty, _, _)) =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   221
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   222
    val thy = Proof_Context.theory_of ctxt
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   223
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   224
    fun map_check_aux rty warns =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   225
      case rty of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   226
        Type (_, []) => warns
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 45278
diff changeset
   227
      | Type (s, _) => if is_some (Quotient_Info.lookup_quotmaps thy s) then warns else s :: warns
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   228
      | _ => warns
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   229
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   230
    val warns = map_check_aux rty []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   231
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   232
    if null warns then ()
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   233
    else warning ("No map function defined for " ^ commas warns ^
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   234
      ". This will cause problems later on.")
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   235
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   236
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   237
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   238
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   239
(*** interface and syntax setup ***)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   240
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   241
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   242
(* the ML-interface takes a list of 5-tuples consisting of:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   243
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   244
 - the name of the quotient type
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   245
 - its free type variables (first argument)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   246
 - its mixfix annotation
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   247
 - the type to be quotient
37530
70d03844b2f9 export of proper information in the ML-interface of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37493
diff changeset
   248
 - the partial flag (a boolean)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   249
 - the relation according to which the type is quotient
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   250
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   251
 it opens a proof-state in which one has to show that the
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   252
 relations are equivalence relations
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   253
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   254
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   255
fun quotient_type quot_list lthy =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   256
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   257
    (* sanity check *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   258
    val _ = List.app sanity_check quot_list
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   259
    val _ = List.app (map_check lthy) quot_list
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   260
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   261
    fun mk_goal (rty, rel, partial) =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   262
      let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   263
        val equivp_ty = ([rty, rty] ---> @{typ bool}) --> @{typ bool}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   264
        val const =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   265
          if partial then @{const_name part_equivp} else @{const_name equivp}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   266
      in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   267
        HOLogic.mk_Trueprop (Const (const, equivp_ty) $ rel)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   268
      end
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   269
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   270
    val goals = map (mk_goal o snd) quot_list
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   271
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   272
    fun after_qed thms lthy =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   273
      fold_map add_quotient_type (quot_list ~~ thms) lthy |> snd
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   274
  in
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   275
    theorem after_qed goals lthy
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   276
  end
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   277
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   278
fun quotient_type_cmd specs lthy =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   279
  let
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   280
    fun parse_spec ((((vs, qty_name), mx), rty_str), (partial, rel_str)) lthy =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   281
      let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   282
        val rty = Syntax.read_typ lthy rty_str
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   283
        val lthy1 = Variable.declare_typ rty lthy
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   284
        val rel =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   285
          Syntax.parse_term lthy1 rel_str
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   286
          |> Type.constraint (rty --> rty --> @{typ bool})
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   287
          |> Syntax.check_term lthy1
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   288
        val lthy2 = Variable.declare_term rel lthy1
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   289
      in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   290
        (((vs, qty_name, mx), (rty, rel, partial)), lthy2)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   291
      end
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   292
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   293
    val (spec', lthy') = fold_map parse_spec specs lthy
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   294
  in
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   295
    quotient_type spec' lthy'
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   296
  end
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   297
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   298
val partial = Scan.optional (Parse.reserved "partial" -- Parse.$$$ ":" >> K true) false
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   299
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   300
val quotspec_parser =
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   301
  Parse.and_list1
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   302
    ((Parse.type_args -- Parse.binding) --
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   303
      Parse.opt_mixfix -- (Parse.$$$ "=" |-- Parse.typ) --
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36960
diff changeset
   304
        (Parse.$$$ "/" |-- (partial -- Parse.term)))
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   305
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36323
diff changeset
   306
val _ = Keyword.keyword "/"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   307
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   308
val _ =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   309
  Outer_Syntax.local_theory_to_proof "quotient_type"
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   310
    "quotient type definitions (require equivalence proofs)"
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 39288
diff changeset
   311
       Keyword.thy_goal (quotspec_parser >> quotient_type_cmd)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   312
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   313
end; (* structure *)