src/HOL/Tools/choice_specification.ML
changeset 35807 e4d1b5cbd429
parent 35625 9c818cab0dd0
child 35845 e5980f0ad025
equal deleted inserted replaced
35806:a814cccce0b8 35807:e4d1b5cbd429
     4 Package for defining constants by specification.
     4 Package for defining constants by specification.
     5 *)
     5 *)
     6 
     6 
     7 signature CHOICE_SPECIFICATION =
     7 signature CHOICE_SPECIFICATION =
     8 sig
     8 sig
       
     9   val close_form : term -> term
     9   val add_specification: string option -> (bstring * xstring * bool) list ->
    10   val add_specification: string option -> (bstring * xstring * bool) list ->
    10     theory * thm -> theory * thm
    11     theory * thm -> theory * thm
    11 end
    12 end
    12 
    13 
    13 structure Choice_Specification: CHOICE_SPECIFICATION =
    14 structure Choice_Specification: CHOICE_SPECIFICATION =
    14 struct
    15 struct
    15 
    16 
    16 (* actual code *)
    17 (* actual code *)
       
    18 
       
    19 fun close_form t =
       
    20     fold_rev (fn (s, T) => fn t => HOLogic.mk_all (s, T, t))
       
    21              (map dest_Free (OldTerm.term_frees t)) t
    17 
    22 
    18 local
    23 local
    19     fun mk_definitional [] arg = arg
    24     fun mk_definitional [] arg = arg
    20       | mk_definitional ((thname,cname,covld)::cos) (thy,thm) =
    25       | mk_definitional ((thname,cname,covld)::cos) (thy,thm) =
    21         case HOLogic.dest_Trueprop (concl_of thm) of
    26         case HOLogic.dest_Trueprop (concl_of thm) of
   118         fun proc_single prop =
   123         fun proc_single prop =
   119             let
   124             let
   120                 val frees = OldTerm.term_frees prop
   125                 val frees = OldTerm.term_frees prop
   121                 val _ = forall (fn v => Sign.of_sort thy (type_of v,HOLogic.typeS)) frees
   126                 val _ = forall (fn v => Sign.of_sort thy (type_of v,HOLogic.typeS)) frees
   122                   orelse error "Specificaton: Only free variables of sort 'type' allowed"
   127                   orelse error "Specificaton: Only free variables of sort 'type' allowed"
   123                 val prop_closed = fold_rev (fn (vname, T) => fn prop =>
   128                 val prop_closed = close_form prop
   124                   HOLogic.mk_all (vname, T, prop)) (map dest_Free frees) prop
       
   125             in
   129             in
   126                 (prop_closed,frees)
   130                 (prop_closed,frees)
   127             end
   131             end
   128 
   132 
   129         val props'' = map proc_single props'
   133         val props'' = map proc_single props'
   188                                   PureThy.store_thm (Binding.name name, thm) thy)
   192                                   PureThy.store_thm (Binding.name name, thm) thy)
   189                     in
   193                     in
   190                         args |> apsnd (remove_alls frees)
   194                         args |> apsnd (remove_alls frees)
   191                              |> apsnd undo_imps
   195                              |> apsnd undo_imps
   192                              |> apsnd Drule.export_without_context
   196                              |> apsnd Drule.export_without_context
   193                              |> Thm.theory_attributes (map (Attrib.attribute thy) atts)
   197                              |> Thm.theory_attributes (map (Attrib.attribute thy)
       
   198                                                            (Attrib.internal (K Nitpick_Choice_Specs.add) :: atts))
   194                              |> add_final
   199                              |> add_final
   195                              |> Library.swap
   200                              |> Library.swap
   196                     end
   201                     end
   197 
   202 
   198                 fun process_all [proc_arg] args =
   203                 fun process_all [proc_arg] args =