src/Pure/Isar/proof_context.ML
changeset 14828 15d12761ba54
parent 14780 949a3f558a43
child 14876 477c414000f8
equal deleted inserted replaced
14827:d973e7f820cb 14828:15d12761ba54
    13   type context
    13   type context
    14   type exporter
    14   type exporter
    15   exception CONTEXT of string * context
    15   exception CONTEXT of string * context
    16   val theory_of: context -> theory
    16   val theory_of: context -> theory
    17   val sign_of: context -> Sign.sg
    17   val sign_of: context -> Sign.sg
    18   val syntax_of: context -> Syntax.syntax * string list * string list
    18   val is_fixed: context -> string -> bool
    19   val fixed_names_of: context -> string list
    19   val fixed_names_of: context -> string list
    20   val assumptions_of: context -> (cterm list * exporter) list
    20   val assumptions_of: context -> (cterm list * exporter) list
    21   val prems_of: context -> thm list
    21   val prems_of: context -> thm list
    22   val print_proof_data: theory -> unit
    22   val print_proof_data: theory -> unit
    23   val init: theory -> context
    23   val init: theory -> context
    24   val is_fixed: context -> string -> bool
    24   val pretty_term: context -> term -> Pretty.T
       
    25   val pretty_typ: context -> typ -> Pretty.T
       
    26   val pretty_sort: context -> sort -> Pretty.T
       
    27   val pp: context -> Pretty.pp
       
    28   val pretty_thm: context -> thm -> Pretty.T
       
    29   val pretty_thms: context -> thm list -> Pretty.T
       
    30   val pretty_fact: context -> string * thm list -> Pretty.T
       
    31   val string_of_term: context -> term -> string
    25   val default_type: context -> string -> typ option
    32   val default_type: context -> string -> typ option
    26   val used_types: context -> string list
    33   val used_types: context -> string list
    27   val read_typ: context -> string -> typ
    34   val read_typ: context -> string -> typ
    28   val read_typ_raw: context -> string -> typ
    35   val read_typ_raw: context -> string -> typ
    29   val cert_typ: context -> typ -> typ
    36   val cert_typ: context -> typ -> typ
   121   val bind_skolem: context -> string list -> term -> term
   128   val bind_skolem: context -> string list -> term -> term
   122   val get_case: context -> string -> string option list -> RuleCases.T
   129   val get_case: context -> string -> string option list -> RuleCases.T
   123   val add_cases: (string * RuleCases.T) list -> context -> context
   130   val add_cases: (string * RuleCases.T) list -> context -> context
   124   val apply_case: RuleCases.T -> context
   131   val apply_case: RuleCases.T -> context
   125     -> context * ((indexname * term option) list * (string * term list) list)
   132     -> context * ((indexname * term option) list * (string * term list) list)
   126   val pretty_term: context -> term -> Pretty.T
       
   127   val pretty_typ: context -> typ -> Pretty.T
       
   128   val pretty_sort: context -> sort -> Pretty.T
       
   129   val pretty_thm: context -> thm -> Pretty.T
       
   130   val pretty_thms: context -> thm list -> Pretty.T
       
   131   val pretty_fact: context -> string * thm list -> Pretty.T
       
   132   val string_of_term: context -> term -> string
       
   133   val verbose: bool ref
   133   val verbose: bool ref
   134   val setmp_verbose: ('a -> 'b) -> 'a -> 'b
   134   val setmp_verbose: ('a -> 'b) -> 'a -> 'b
   135   val print_syntax: context -> unit
   135   val print_syntax: context -> unit
   136   val print_binds: context -> unit
   136   val print_binds: context -> unit
   137   val print_lthms: context -> unit
   137   val print_lthms: context -> unit
   377 
   377 
   378 end;
   378 end;
   379 
   379 
   380 
   380 
   381 
   381 
       
   382 (** pretty printing **)
       
   383 
       
   384 fun pretty_term ctxt = Sign.pretty_term' (syn_of ctxt) (sign_of ctxt) o context_tr' ctxt;
       
   385 val pretty_typ = Sign.pretty_typ o sign_of;
       
   386 val pretty_sort = Sign.pretty_sort o sign_of;
       
   387 
       
   388 fun pp ctxt = Pretty.pp (pretty_term ctxt) (pretty_typ ctxt) (pretty_sort ctxt)
       
   389   (Sign.pretty_classrel (sign_of ctxt)) (Sign.pretty_arity (sign_of ctxt));
       
   390 
       
   391 val string_of_term = Pretty.string_of oo pretty_term;
       
   392 
       
   393 fun pretty_thm ctxt thm =
       
   394   if ! Display.show_hyps then
       
   395     Display.pretty_thm_aux (pretty_sort ctxt, pretty_term ctxt) false thm
       
   396   else pretty_term ctxt (Thm.prop_of thm);
       
   397 
       
   398 fun pretty_thms ctxt [th] = pretty_thm ctxt th
       
   399   | pretty_thms ctxt ths = Pretty.blk (0, Pretty.fbreaks (map (pretty_thm ctxt) ths));
       
   400 
       
   401 fun pretty_fact ctxt ("", ths) = pretty_thms ctxt ths
       
   402   | pretty_fact ctxt (a, [th]) =
       
   403       Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, pretty_thm ctxt th]
       
   404   | pretty_fact ctxt (a, ths) =
       
   405       Pretty.block (Pretty.fbreaks (Pretty.str (a ^ ":") :: map (pretty_thm ctxt) ths));
       
   406 
       
   407 
       
   408 
   382 (** default sorts and types **)
   409 (** default sorts and types **)
   383 
   410 
   384 fun def_sort (Context {defs = (_, sorts, _, _), ...}) xi = Vartab.lookup (sorts, xi);
   411 fun def_sort (Context {defs = (_, sorts, _, _), ...}) xi = Vartab.lookup (sorts, xi);
   385 
   412 
   386 fun def_type (Context {binds, defs = (types, _, _, _), ...}) pattern xi =
   413 fun def_type (Context {binds, defs = (types, _, _, _), ...}) pattern xi =
   472 *)
   499 *)
   473 
   500 
   474 
   501 
   475 (* read / certify wrt. signature *)     (*exception ERROR*) (*exception TERM*)
   502 (* read / certify wrt. signature *)     (*exception ERROR*) (*exception TERM*)
   476 
   503 
   477 fun read_def_termTs freeze syn sg (types, sorts, used) sTs =
   504 fun read_def_termTs freeze pp syn sg (types, sorts, used) sTs =
   478   Sign.read_def_terms' syn (sg, types, sorts) used freeze sTs;
   505   Sign.read_def_terms' pp syn (sg, types, sorts) used freeze sTs;
   479 
   506 
   480 fun read_def_termT freeze syn sg defs sT = apfst hd (read_def_termTs freeze syn sg defs [sT]);
   507 fun read_def_termT freeze pp syn sg defs sT =
   481 
   508   apfst hd (read_def_termTs freeze pp syn sg defs [sT]);
   482 fun read_term_sg freeze syn sg defs s =
   509 
   483   #1 (read_def_termT freeze syn sg defs (s, TypeInfer.logicT));
   510 fun read_term_sg freeze pp syn sg defs s =
   484 
   511   #1 (read_def_termT freeze pp syn sg defs (s, TypeInfer.logicT));
   485 fun read_prop_sg freeze syn sg defs s = #1 (read_def_termT freeze syn sg defs (s, propT));
   512 
   486 
   513 fun read_prop_sg freeze pp syn sg defs s =
   487 fun read_terms_sg freeze syn sg defs =
   514   #1 (read_def_termT freeze pp syn sg defs (s, propT));
   488   #1 o read_def_termTs freeze syn sg defs o map (rpair TypeInfer.logicT);
   515 
   489 
   516 fun read_terms_sg freeze pp syn sg defs =
   490 fun read_props_sg freeze syn sg defs = #1 o read_def_termTs freeze syn sg defs o map (rpair propT);
   517   #1 o read_def_termTs freeze pp syn sg defs o map (rpair TypeInfer.logicT);
   491 
   518 
   492 
   519 fun read_props_sg freeze pp syn sg defs =
   493 fun cert_term_sg sg t = Thm.term_of (Thm.cterm_of sg t);
   520   #1 o read_def_termTs freeze pp syn sg defs o map (rpair propT);
   494 
   521 
   495 fun cert_prop_sg sg tm =
   522 
   496   let
   523 fun cert_term_sg pp sg t = #1 (Sign.certify_term pp sg t);
   497     val ctm = Thm.cterm_of sg tm;
   524 
   498     val {t, T, ...} = Thm.rep_cterm ctm;
   525 fun cert_prop_sg pp sg tm =
       
   526   let val (t, T, _) = Sign.certify_term pp sg tm
   499   in if T = propT then t else raise TERM ("Term not of type prop", [t]) end;
   527   in if T = propT then t else raise TERM ("Term not of type prop", [t]) end;
   500 
   528 
   501 
   529 
   502 (* norm_term *)
   530 (* norm_term *)
   503 
   531 
   554   let
   582   let
   555     val types = append_env (def_type ctxt pattern) more_types;
   583     val types = append_env (def_type ctxt pattern) more_types;
   556     val sorts = append_env (def_sort ctxt) more_sorts;
   584     val sorts = append_env (def_sort ctxt) more_sorts;
   557     val used = used_types ctxt @ more_used;
   585     val used = used_types ctxt @ more_used;
   558   in
   586   in
   559     (transform_error (read (syn_of ctxt) (sign_of ctxt) (types, sorts, used)) s
   587     (transform_error (read (pp ctxt) (syn_of ctxt) (sign_of ctxt) (types, sorts, used)) s
   560       handle TERM (msg, _) => raise CONTEXT (msg, ctxt)
   588       handle TERM (msg, _) => raise CONTEXT (msg, ctxt)
   561         | ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt))
   589         | ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt))
   562     |> app (intern_skolem ctxt internal)
   590     |> app (intern_skolem ctxt internal)
   563     |> app (if pattern then I else norm_term ctxt schematic)
   591     |> app (if pattern then I else norm_term ctxt schematic)
   564     |> app (if pattern then prepare_dummies else if dummies then I else reject_dummies ctxt)
   592     |> app (if pattern then prepare_dummies else if dummies then I else reject_dummies ctxt)
   593 
   621 
   594 local
   622 local
   595 
   623 
   596 fun gen_cert cert pattern schematic ctxt t = t
   624 fun gen_cert cert pattern schematic ctxt t = t
   597   |> (if pattern then I else norm_term ctxt schematic)
   625   |> (if pattern then I else norm_term ctxt schematic)
   598   |> (fn t' => cert (sign_of ctxt) t' handle TERM (msg, _) => raise CONTEXT (msg, ctxt));
   626   |> (fn t' => cert (pp ctxt) (sign_of ctxt) t'
       
   627     handle TERM (msg, _) => raise CONTEXT (msg, ctxt));
   599 
   628 
   600 in
   629 in
   601 
   630 
   602 val cert_term = gen_cert cert_term_sg false false;
   631 val cert_term = gen_cert cert_term_sg false false;
   603 val cert_prop = gen_cert cert_prop_sg false false;
   632 val cert_prop = gen_cert cert_prop_sg false false;
   656 fun declare_term t ctxt = declare_occ (ctxt, t);
   685 fun declare_term t ctxt = declare_occ (ctxt, t);
   657 fun declare_terms ts ctxt = foldl declare_occ (ctxt, ts);
   686 fun declare_terms ts ctxt = foldl declare_occ (ctxt, ts);
   658 fun declare_terms_syntax ts ctxt = foldl declare_syn (ctxt, ts);
   687 fun declare_terms_syntax ts ctxt = foldl declare_syn (ctxt, ts);
   659 
   688 
   660 end;
   689 end;
   661 
       
   662 
       
   663 
       
   664 (** pretty printing **)
       
   665 
       
   666 fun pretty_term ctxt = Sign.pretty_term' (syn_of ctxt) (sign_of ctxt) o context_tr' ctxt;
       
   667 val pretty_typ = Sign.pretty_typ o sign_of;
       
   668 val pretty_sort = Sign.pretty_sort o sign_of;
       
   669 
       
   670 val string_of_term = Pretty.string_of oo pretty_term;
       
   671 
       
   672 fun pretty_thm ctxt thm =
       
   673   if ! Display.show_hyps then
       
   674     Display.pretty_thm_aux (pretty_sort ctxt, pretty_term ctxt) false thm
       
   675   else pretty_term ctxt (Thm.prop_of thm);
       
   676 
       
   677 fun pretty_thms ctxt [th] = pretty_thm ctxt th
       
   678   | pretty_thms ctxt ths = Pretty.blk (0, Pretty.fbreaks (map (pretty_thm ctxt) ths));
       
   679 
       
   680 fun pretty_fact ctxt ("", ths) = pretty_thms ctxt ths
       
   681   | pretty_fact ctxt (a, [th]) =
       
   682       Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, pretty_thm ctxt th]
       
   683   | pretty_fact ctxt (a, ths) =
       
   684       Pretty.block (Pretty.fbreaks (Pretty.str (a ^ ":") :: map (pretty_thm ctxt) ths));
       
   685 
   690 
   686 
   691 
   687 
   692 
   688 (** Hindley-Milner polymorphism **)
   693 (** Hindley-Milner polymorphism **)
   689 
   694