src/HOL/Tools/Nitpick/nitpick_model.ML
changeset 61331 2007ea8615a2
parent 61324 d4ec7594f558
child 61333 24b5e7579fdd
equal deleted inserted replaced
61330:20af2ad9261e 61331:2007ea8615a2
    21 
    21 
    22   structure NameTable : TABLE
    22   structure NameTable : TABLE
    23 
    23 
    24   val irrelevant : string
    24   val irrelevant : string
    25   val unknown : string
    25   val unknown : string
    26   val unrep : unit -> string
       
    27   val register_term_postprocessor :
    26   val register_term_postprocessor :
    28     typ -> term_postprocessor -> morphism -> Context.generic -> Context.generic
    27     typ -> term_postprocessor -> morphism -> Context.generic -> Context.generic
    29   val register_term_postprocessor_global :
    28   val register_term_postprocessor_global :
    30     typ -> term_postprocessor -> theory -> theory
    29     typ -> term_postprocessor -> theory -> theory
    31   val unregister_term_postprocessor :
    30   val unregister_term_postprocessor :
    71 
    70 
    72 fun xsym s s' () = if print_mode_active Symbol.xsymbolsN then s else s'
    71 fun xsym s s' () = if print_mode_active Symbol.xsymbolsN then s else s'
    73 
    72 
    74 val irrelevant = "_"
    73 val irrelevant = "_"
    75 val unknown = "?"
    74 val unknown = "?"
    76 val unrep = xsym "\<dots>" "..."
    75 val unrep_mixfix = xsym "\<dots>" "..."
    77 val maybe_mixfix = xsym "_\<^sup>?" "_?"
    76 val maybe_mixfix = xsym "_\<^sup>?" "_?"
    78 val base_mixfix = xsym "_\<^bsub>base\<^esub>" "_.base"
    77 val base_mixfix = xsym "_\<^bsub>base\<^esub>" "_.base"
    79 val step_mixfix = xsym "_\<^bsub>step\<^esub>" "_.step"
    78 val step_mixfix = xsym "_\<^bsub>step\<^esub>" "_.step"
    80 val abs_mixfix = xsym "\<guillemotleft>_\<guillemotright>" "\"_\""
    79 val abs_mixfix = xsym "\<guillemotleft>_\<guillemotright>" "\"_\""
    81 val arg_var_prefix = "x"
    80 val arg_var_prefix = "x"
    89 
    88 
    90 fun add_wacky_syntax ctxt =
    89 fun add_wacky_syntax ctxt =
    91   let
    90   let
    92     val name_of = fst o dest_Const
    91     val name_of = fst o dest_Const
    93     val thy = Proof_Context.theory_of ctxt
    92     val thy = Proof_Context.theory_of ctxt
    94     val (maybe_t, thy) =
    93     val (unrep_s, thy) = thy
    95       Sign.declare_const_global ((@{binding nitpick_maybe}, @{typ "'a => 'a"}),
    94       |> Sign.declare_const_global ((@{binding nitpick_unrep}, @{typ 'a}),
    96                           Mixfix (maybe_mixfix (), [1000], 1000)) thy
    95         Mixfix (unrep_mixfix (), [], 1000))
    97     val (abs_t, thy) =
    96       |>> name_of
    98       Sign.declare_const_global ((@{binding nitpick_abs}, @{typ "'a => 'b"}),
    97     val (maybe_s, thy) = thy
    99                           Mixfix (abs_mixfix (), [40], 40)) thy
    98       |> Sign.declare_const_global ((@{binding nitpick_maybe}, @{typ "'a => 'a"}),
   100     val (base_t, thy) =
    99         Mixfix (maybe_mixfix (), [1000], 1000))
   101       Sign.declare_const_global ((@{binding nitpick_base}, @{typ "'a => 'a"}),
   100       |>> name_of
   102                           Mixfix (base_mixfix (), [1000], 1000)) thy
   101     val (abs_s, thy) = thy
   103     val (step_t, thy) =
   102       |> Sign.declare_const_global ((@{binding nitpick_abs}, @{typ "'a => 'b"}),
   104       Sign.declare_const_global ((@{binding nitpick_step}, @{typ "'a => 'a"}),
   103         Mixfix (abs_mixfix (), [40], 40))
   105                           Mixfix (step_mixfix (), [1000], 1000)) thy
   104       |>> name_of
       
   105     val (base_s, thy) = thy
       
   106       |> Sign.declare_const_global ((@{binding nitpick_base}, @{typ "'a => 'a"}),
       
   107         Mixfix (base_mixfix (), [1000], 1000))
       
   108       |>> name_of
       
   109     val (step_s, thy) = thy
       
   110       |> Sign.declare_const_global ((@{binding nitpick_step}, @{typ "'a => 'a"}),
       
   111         Mixfix (step_mixfix (), [1000], 1000))
       
   112       |>> name_of
   106   in
   113   in
   107     (apply2 (apply2 name_of) ((maybe_t, abs_t), (base_t, step_t)),
   114     (((unrep_s, maybe_s, abs_s), (base_s, step_s)),
   108      Proof_Context.transfer thy ctxt)
   115      Proof_Context.transfer thy ctxt)
   109   end
   116   end
   110 
   117 
   111 (** Term reconstruction **)
   118 (** Term reconstruction **)
   112 
   119 
   360             t
   367             t
   361         | t => t
   368         | t => t
   362       end
   369       end
   363   in index_seq 0 card |> map nth_value_of_type |> sort nice_term_ord end
   370   in index_seq 0 card |> map nth_value_of_type |> sort nice_term_ord end
   364 and reconstruct_term maybe_opt unfold pool
   371 and reconstruct_term maybe_opt unfold pool
   365         (wacky_names as ((maybe_name, abs_name), _))
   372         (wacky_names as ((unrep_name, maybe_name, abs_name), _))
   366         (scope as {hol_ctxt as {thy, ctxt, ...}, binarize, card_assigns, bits,
   373         (scope as {hol_ctxt as {thy, ctxt, ...}, binarize, card_assigns, bits,
   367                    data_types, ofs, ...})
   374                    data_types, ofs, ...})
   368         atomss sel_names rel_table bounds =
   375         atomss sel_names rel_table bounds =
   369   let
   376   let
   370     val for_auto = (maybe_name = "")
   377     val for_auto = (maybe_name = "")
   399         val set_T = HOLogic.mk_setT T
   406         val set_T = HOLogic.mk_setT T
   400         val empty_const = Const (@{const_abbrev Set.empty}, set_T)
   407         val empty_const = Const (@{const_abbrev Set.empty}, set_T)
   401         val insert_const = Const (@{const_name insert}, T --> set_T --> set_T)
   408         val insert_const = Const (@{const_name insert}, T --> set_T --> set_T)
   402         fun aux [] =
   409         fun aux [] =
   403             if maybe_opt andalso not (is_complete_type data_types false T) then
   410             if maybe_opt andalso not (is_complete_type data_types false T) then
   404               insert_const $ Const (unrep (), T) $ empty_const
   411               insert_const $ Const (unrep_name, T) $ empty_const
   405             else
   412             else
   406               empty_const
   413               empty_const
   407           | aux ((t1, t2) :: zs) =
   414           | aux ((t1, t2) :: zs) =
   408             aux zs
   415             aux zs
   409             |> t2 <> @{const False}
   416             |> t2 <> @{const False}
   428             (case t2 of
   435             (case t2 of
   429                Const (@{const_name None}, _) => aux' tps
   436                Const (@{const_name None}, _) => aux' tps
   430              | _ => update_const $ aux' tps $ t1 $ t2)
   437              | _ => update_const $ aux' tps $ t1 $ t2)
   431         fun aux tps =
   438         fun aux tps =
   432           if maybe_opt andalso not (is_complete_type data_types false T1) then
   439           if maybe_opt andalso not (is_complete_type data_types false T1) then
   433             update_const $ aux' tps $ Const (unrep (), T1)
   440             update_const $ aux' tps $ Const (unrep_name, T1)
   434             $ (Const (@{const_name Some}, T2' --> T2) $ Const (unknown, T2'))
   441             $ (Const (@{const_name Some}, T2' --> T2) $ Const (unknown, T2'))
   435           else
   442           else
   436             aux' tps
   443             aux' tps
   437       in aux end
   444       in aux end
   438     fun polish_funs Ts t =
   445     fun polish_funs Ts t =
   977             | _ => []) @
   984             | _ => []) @
   978            [Pretty.str "=",
   985            [Pretty.str "=",
   979             Pretty.enum "," "{" "}"
   986             Pretty.enum "," "{" "}"
   980                 (map (pretty_term_auto_global ctxt) (all_values card typ) @
   987                 (map (pretty_term_auto_global ctxt) (all_values card typ) @
   981                  (if fun_from_pair complete false then []
   988                  (if fun_from_pair complete false then []
   982                   else [Pretty.str (unrep ())]))]))
   989                   else [Pretty.str (unrep_mixfix ())]))]))
   983     fun integer_data_type T =
   990     fun integer_data_type T =
   984       [{typ = T, card = card_of_type card_assigns T, co = false,
   991       [{typ = T, card = card_of_type card_assigns T, co = false,
   985         self_rec = true, complete = (false, false), concrete = (true, true),
   992         self_rec = true, complete = (false, false), concrete = (true, true),
   986         deep = true, constrs = []}]
   993         deep = true, constrs = []}]
   987       handle TYPE ("Nitpick_HOL.card_of_type", _, _) => []
   994       handle TYPE ("Nitpick_HOL.card_of_type", _, _) => []