src/Pure/Isar/proof_context.ML
changeset 7270 2b64729d9acb
parent 7200 c9b03d9d6647
child 7411 4dbff71ac480
equal deleted inserted replaced
7269:8aa45a40c87a 7270:2b64729d9acb
    48   val put_thmss: (string * thm list) list -> context -> context
    48   val put_thmss: (string * thm list) list -> context -> context
    49   val have_thmss: thm list -> string -> context attribute list
    49   val have_thmss: thm list -> string -> context attribute list
    50     -> (thm list * context attribute list) list -> context -> context * (string * thm list)
    50     -> (thm list * context attribute list) list -> context -> context * (string * thm list)
    51   val assumptions: context -> (cterm * ((int -> tactic) * (int -> tactic))) list
    51   val assumptions: context -> (cterm * ((int -> tactic) * (int -> tactic))) list
    52   val fixed_names: context -> string list
    52   val fixed_names: context -> string list
    53   val assume: ((int -> tactic) * (int -> tactic)) -> string -> context attribute list
    53   val assume: ((int -> tactic) * (int -> tactic))
    54     -> (string * (string list * string list)) list
    54     -> (string * context attribute list * (string * (string list * string list)) list) list
    55     -> context -> context * ((string * thm list) * thm list)
    55     -> context -> context * ((string * thm list) list * thm list)
    56   val assume_i: ((int -> tactic) * (int -> tactic)) -> string -> context attribute list
    56   val assume_i: ((int -> tactic) * (int -> tactic))
    57     -> (term * (term list * term list)) list
    57     -> (string * context attribute list * (term * (term list * term list)) list) list
    58     -> context -> context * ((string * thm list) * thm list)
    58     -> context -> context * ((string * thm list) list * thm list)
    59   val fix: (string * string option) list -> context -> context
    59   val fix: (string * string option) list -> context -> context
    60   val fix_i: (string * typ) list -> context -> context
    60   val fix_i: (string * typ) list -> context -> context
    61   val transfer_used_names: context -> context -> context
    61   val transfer_used_names: context -> context -> context
    62   val setup: (theory -> theory) list
    62   val setup: (theory -> theory) list
    63 end;
    63 end;
   104   make_context (f (thy, data, asms, binds, thms, defs));
   104   make_context (f (thy, data, asms, binds, thms, defs));
   105 
   105 
   106 fun theory_of (Context {thy, ...}) = thy;
   106 fun theory_of (Context {thy, ...}) = thy;
   107 val sign_of = Theory.sign_of o theory_of;
   107 val sign_of = Theory.sign_of o theory_of;
   108 
   108 
       
   109 fun prems_of (Context {asms = ((_, asms), _), ...}) = flat (map #2 asms);
       
   110 
   109 
   111 
   110 
   112 
   111 (** print context information **)
   113 (** print context information **)
   112 
   114 
   113 val show_hyps = ref false;
   115 val show_hyps = ref false;
   155 val print_thms = seq writeln o strings_of_thms;
   157 val print_thms = seq writeln o strings_of_thms;
   156 
   158 
   157 
   159 
   158 (* main context *)
   160 (* main context *)
   159 
   161 
   160 fun strings_of_context (ctxt as Context {thy, data = _, asms = ((_, prems), (fixes, _)), binds = _,
   162 fun strings_of_context (ctxt as Context {thy, data = _, asms = (_, (fixes, _)), binds = _,
   161     thms = _, defs = (types, sorts, maxidx, used)}) =
   163     thms = _, defs = (types, sorts, maxidx, used)}) =
   162   let
   164   let
   163     val sign = Theory.sign_of thy;
   165     val sign = Theory.sign_of thy;
       
   166     val prems = prems_of ctxt;
   164 
   167 
   165     val prt_term = Sign.pretty_term sign;
   168     val prt_term = Sign.pretty_term sign;
   166     val prt_typ = Sign.pretty_typ sign;
   169     val prt_typ = Sign.pretty_typ sign;
   167     val prt_sort = Sign.pretty_sort sign;
   170     val prt_sort = Sign.pretty_sort sign;
   168 
   171 
   189     val prt_defS = prt_atom prt_varT prt_sort;
   192     val prt_defS = prt_atom prt_varT prt_sort;
   190   in
   193   in
   191     verb_string pretty_thy @
   194     verb_string pretty_thy @
   192     (if null fixes andalso not (! verbose) then []
   195     (if null fixes andalso not (! verbose) then []
   193       else [Pretty.string_of (prt_fixes (rev fixes))]) @
   196       else [Pretty.string_of (prt_fixes (rev fixes))]) @
   194     strings_of_items (prt_term o #prop o Thm.rep_thm) "Assumptions:" prems @
   197     (if null prems andalso not (! verbose) then []
       
   198       else [Pretty.string_of (Pretty.big_list "Assumptions:"
       
   199         (map (prt_term o #prop o Thm.rep_thm) prems))]) @
   195     verb strings_of_binds ctxt @
   200     verb strings_of_binds ctxt @
   196     verb strings_of_thms ctxt @
   201     verb strings_of_thms ctxt @
   197     verb_string (Pretty.big_list "Type constraints:" (map prt_defT (Vartab.dest types))) @
   202     verb_string (Pretty.big_list "Type constraints:" (map prt_defT (Vartab.dest types))) @
   198     verb_string (Pretty.big_list "Default sorts:" (map prt_defS (Vartab.dest sorts))) @
   203     verb_string (Pretty.big_list "Default sorts:" (map prt_defS (Vartab.dest sorts))) @
   199     verb_string (Pretty.str ("Maxidx: " ^ string_of_int maxidx)) @
   204     verb_string (Pretty.str ("Maxidx: " ^ string_of_int maxidx)) @
   425 end;
   430 end;
   426 
   431 
   427 
   432 
   428 (* read terms *)
   433 (* read terms *)
   429 
   434 
       
   435 fun warn_vars ctxt tm =
       
   436   if null (term_vars tm) andalso null (term_tvars tm) then tm
       
   437   else (warning "Illegal schematic variable(s) in term"; tm);
       
   438 
   430 fun gen_read read app is_pat (ctxt as Context {binds, defs = (types, sorts, _, used), ...}) s =
   439 fun gen_read read app is_pat (ctxt as Context {binds, defs = (types, sorts, _, used), ...}) s =
   431   let
   440   let
   432     val sign = sign_of ctxt;
   441     val sign = sign_of ctxt;
   433 
   442 
   434     fun def_type xi =
   443     fun def_type xi =
   442       handle TERM (msg, _) => raise CONTEXT (msg, ctxt)
   451       handle TERM (msg, _) => raise CONTEXT (msg, ctxt)
   443       | ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt))
   452       | ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt))
   444     |> app (intern_skolem ctxt true)
   453     |> app (intern_skolem ctxt true)
   445     |> app (if is_pat then I else norm_term ctxt)
   454     |> app (if is_pat then I else norm_term ctxt)
   446     |> app (if is_pat then prepare_dummies else (reject_dummies ctxt))
   455     |> app (if is_pat then prepare_dummies else (reject_dummies ctxt))
       
   456     |> app (if is_pat then I else warn_vars ctxt)
   447   end;
   457   end;
   448 
   458 
   449 val read_termTs = gen_read (read_def_termTs false) (apfst o map) false;
   459 val read_termTs = gen_read (read_def_termTs false) (apfst o map) false;
   450 val read_term = gen_read (read_term_sg true) I false;
   460 val read_term = gen_read (read_term_sg true) I false;
   451 val read_prop = gen_read (read_prop_sg true) I false;
   461 val read_prop = gen_read (read_prop_sg true) I false;
   653 fun fixed_names (Context {asms = (_, (fixes, _)), ...}) = map #2 fixes;
   663 fun fixed_names (Context {asms = (_, (fixes, _)), ...}) = map #2 fixes;
   654 
   664 
   655 
   665 
   656 (* assume *)
   666 (* assume *)
   657 
   667 
   658 fun prems (Context {asms = ((_, asms), _), ...}) = flat (map #2 asms);
   668 local
   659 
   669 
   660 fun gen_assume prepp tac name attrs raw_prop_pats ctxt =
   670 fun gen_assm prepp tac (ctxt, (name, attrs, raw_prop_pats)) =
   661   let
   671   let
   662     val (ctxt', props) = foldl_map prepp (ctxt, raw_prop_pats);
   672     val (ctxt', props) = foldl_map prepp (ctxt, raw_prop_pats);
   663     val sign = sign_of ctxt';
   673     val sign = sign_of ctxt';
   664     val Context {defs = (_, _, maxidx, _), ...} = ctxt';
   674     val Context {defs = (_, _, maxidx, _), ...} = ctxt';
   665 
   675 
   675 
   685 
   676     val ctxt''' =
   686     val ctxt''' =
   677       ctxt''
   687       ctxt''
   678       |> map_context (fn (thy, data, ((asms_ct, asms_th), fixes), binds, thms, defs) =>
   688       |> map_context (fn (thy, data, ((asms_ct, asms_th), fixes), binds, thms, defs) =>
   679         (thy, data, ((asms_ct @ cprops_tac, asms_th @ [(name, asms)]), fixes), binds, thms, defs));
   689         (thy, data, ((asms_ct @ cprops_tac, asms_th @ [(name, asms)]), fixes), binds, thms, defs));
   680   in (ctxt''', ((name, thms), prems ctxt''')) end;
   690   in (ctxt''', (name, thms)) end;
   681 
   691 
   682 val assume = gen_assume bind_propp;
   692 fun gen_assms prepp tac args ctxt =
   683 val assume_i = gen_assume bind_propp_i;
   693   let val (ctxt', thmss) = foldl_map (gen_assm prepp tac) (ctxt, args)
       
   694   in (ctxt', (thmss, prems_of ctxt')) end;
       
   695 
       
   696 in
       
   697 
       
   698 val assume = gen_assms bind_propp;
       
   699 val assume_i = gen_assms bind_propp_i;
       
   700 
       
   701 end;
   684 
   702 
   685 
   703 
   686 (* fix *)
   704 (* fix *)
   687 
   705 
   688 fun read_skolemT (Context {defs = (_, _, _, used), ...}) None = Type.param used ("'z", logicS)
   706 fun read_skolemT (Context {defs = (_, _, _, used), ...}) None = Type.param used ("'z", logicS)