src/HOL/Tools/Quotient/quotient_typ.ML
changeset 45282 eaec1651709a
parent 45280 9fd6fce8a230
child 45283 9e8616978d99
equal deleted inserted replaced
45281:29e88714ffe4 45282:eaec1651709a
    16     -> Proof.context -> Proof.state
    16     -> Proof.context -> Proof.state
    17 end;
    17 end;
    18 
    18 
    19 structure Quotient_Type: QUOTIENT_TYPE =
    19 structure Quotient_Type: QUOTIENT_TYPE =
    20 struct
    20 struct
    21 
       
    22 (* wrappers for define, note, Attrib.internal and theorem_i *)  (* FIXME !? *)
       
    23 
       
    24 fun define (name, mx, rhs) lthy =
       
    25   let
       
    26     val ((rhs, (_ , thm)), lthy') =
       
    27       Local_Theory.define ((name, mx), (Attrib.empty_binding, rhs)) lthy
       
    28   in
       
    29     ((rhs, thm), lthy')
       
    30   end
       
    31 
       
    32 fun note (name, thm, attrs) lthy =
       
    33   Local_Theory.note ((name, attrs), [thm]) lthy |> snd
       
    34 
       
    35 
       
    36 fun intern_attr at = Attrib.internal (K at)
       
    37 
       
    38 fun theorem after_qed goals ctxt =
       
    39   let
       
    40     val goals' = map (rpair []) goals
       
    41     fun after_qed' thms = after_qed (the_single thms)
       
    42   in
       
    43     Proof.theorem NONE after_qed' [goals'] ctxt
       
    44   end
       
    45 
       
    46 
    21 
    47 
    22 
    48 (*** definition of quotient types ***)
    23 (*** definition of quotient types ***)
    49 
    24 
    50 val mem_def1 = @{lemma "y : Collect S ==> S y" by simp}
    25 val mem_def1 = @{lemma "y : Collect S ==> S y" by simp}
   143     val abs_trm = Syntax.check_term lthy1 (abs_const $ rel $ Abs_const)
   118     val abs_trm = Syntax.check_term lthy1 (abs_const $ rel $ Abs_const)
   144     val rep_trm = Syntax.check_term lthy1 (rep_const $ Rep_const)
   119     val rep_trm = Syntax.check_term lthy1 (rep_const $ Rep_const)
   145     val abs_name = Binding.prefix_name "abs_" qty_name
   120     val abs_name = Binding.prefix_name "abs_" qty_name
   146     val rep_name = Binding.prefix_name "rep_" qty_name
   121     val rep_name = Binding.prefix_name "rep_" qty_name
   147 
   122 
   148     val ((_, abs_def), lthy2) = define (abs_name, NoSyn, abs_trm) lthy1
   123     val ((_, (_, abs_def)), lthy2) = lthy1
   149     val ((_, rep_def), lthy3) = define (rep_name, NoSyn, rep_trm) lthy2
   124       |> Local_Theory.define ((abs_name, NoSyn), (Attrib.empty_binding, abs_trm))
       
   125     val ((_, (_, rep_def)), lthy3) = lthy2
       
   126       |> Local_Theory.define ((rep_name, NoSyn), (Attrib.empty_binding, rep_trm))
   150 
   127 
   151     (* quot_type theorem *)
   128     (* quot_type theorem *)
   152     val quot_thm = typedef_quot_type_thm (rel, Abs_const, Rep_const, part_equiv, typedef_info) lthy3
   129     val quot_thm = typedef_quot_type_thm (rel, Abs_const, Rep_const, part_equiv, typedef_info) lthy3
   153 
   130 
   154     (* quotient theorem *)
   131     (* quotient theorem *)
   166     fun qinfo phi = Quotient_Info.transform_quotients phi quotients
   143     fun qinfo phi = Quotient_Info.transform_quotients phi quotients
   167 
   144 
   168     val lthy4 = lthy3
   145     val lthy4 = lthy3
   169       |> Local_Theory.declaration true
   146       |> Local_Theory.declaration true
   170         (fn phi => Quotient_Info.update_quotients qty_full_name (qinfo phi))
   147         (fn phi => Quotient_Info.update_quotients qty_full_name (qinfo phi))
   171       |> note
   148       |> (snd oo Local_Theory.note)
   172         (equiv_thm_name, equiv_thm,
   149         ((equiv_thm_name,
   173           if partial then [] else [intern_attr Quotient_Info.equiv_rules_add])
   150           if partial then [] else [Attrib.internal (K Quotient_Info.equiv_rules_add)]),
   174       |> note (quotient_thm_name, quotient_thm, [intern_attr Quotient_Info.quotient_rules_add])
   151           [equiv_thm])
       
   152       |> (snd oo Local_Theory.note)
       
   153         ((quotient_thm_name, [Attrib.internal (K Quotient_Info.quotient_rules_add)]),
       
   154           [quotient_thm])
   175   in
   155   in
   176     (quotients, lthy4)
   156     (quotients, lthy4)
   177   end
   157   end
   178 
   158 
   179 
   159 
   265         HOLogic.mk_Trueprop (Const (const, equivp_ty) $ rel)
   245         HOLogic.mk_Trueprop (Const (const, equivp_ty) $ rel)
   266       end
   246       end
   267 
   247 
   268     val goals = map (mk_goal o snd) quot_list
   248     val goals = map (mk_goal o snd) quot_list
   269 
   249 
   270     fun after_qed thms lthy =
   250     fun after_qed [thms] = fold (snd oo add_quotient_type) (quot_list ~~ thms)
   271       fold_map add_quotient_type (quot_list ~~ thms) lthy |> snd
   251   in
   272   in
   252     Proof.theorem NONE after_qed [map (rpair []) goals] lthy
   273     theorem after_qed goals lthy
       
   274   end
   253   end
   275 
   254 
   276 fun quotient_type_cmd specs lthy =
   255 fun quotient_type_cmd specs lthy =
   277   let
   256   let
   278     fun parse_spec ((((vs, qty_name), mx), rty_str), (partial, rel_str)) lthy =
   257     fun parse_spec ((((vs, qty_name), mx), rty_str), (partial, rel_str)) lthy =