fun map_ctxt_attrib attrib =
map_ctxt {binding = I, typ = I, term = I, pattern = I, fact = I, attrib = attrib};
val trim_context_ctxt: context_i -> context_i = map_ctxt
{binding = I, typ = I, term = I, pattern = I,
fact = map Thm.trim_context,
attrib = map Token.trim_context};
fun transfer_ctxt thy: context_i -> context_i = map_ctxt
{binding = I, typ = I, term = I, pattern = I,
fact = map (Thm.transfer thy),
attrib = map (Token.transfer thy)};
fun transform_ctxt phi = map_ctxt
{binding = Morphism.binding phi,
typ = Morphism.typ phi,
term = Morphism.term phi,
pattern = Morphism.term phi,
fact = Morphism.fact phi,
attrib = map (Token.transform phi)};
fun pretty_stmt ctxt = let val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt; val prt_term = Pretty.quote o Syntax.pretty_term ctxt; val prt_terms = separate (Pretty.keyword2 "and") o map prt_term; val prt_binding = Attrib.pretty_binding ctxt; val prt_name = Thy_Header.pretty_name' ctxt;
fun prt_show (a, ts) =
Pretty.block (Pretty.breaks (prt_binding a ":" @ prt_terms (map fst ts)));
fun prt_var (x, SOME T, _) = Pretty.block
[prt_name (Binding.name_of x), Pretty.str " ::", Pretty.brk 1, prt_typ T]
| prt_var (x, NONE, _) = prt_name (Binding.name_of x); val prt_vars = separate (Pretty.keyword2 "and") o map prt_var;
fun gen_pretty_ctxt show_attribs ctxt = let val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt; val prt_term = Pretty.quote o Syntax.pretty_term ctxt; val prt_thm = Pretty.cartouche o Thm.pretty_thm ctxt; val prt_name = Thy_Header.pretty_name' ctxt;
fun prt_binding (b, atts) =
Attrib.pretty_binding ctxt (b, if show_attribs then atts else []);
val pretty_ctxt = gen_pretty_ctxt true; val pretty_ctxt_no_attribs = gen_pretty_ctxt false;
(* pretty_statement *)
local
fun standard_elim ctxt th =
(case Object_Logic.elim_concl ctxt th of
SOME C => let val thesis = Var ((Auto_Bind.thesisN, Thm.maxidx_of th + 1), fastype_of C); val insts = (TVars.empty, Vars.make1 (Term.dest_Var C, Thm.cterm_of ctxt thesis)); val th' = Thm.instantiate insts th; in (th', true) end
| NONE => (th, false));
fun thm_name ctxt kind th prts = letval head =
(casetry Thm.the_name_hint th of
SOME (name, _) =>
Pretty.block [Pretty.keyword1 kind, Pretty.brk 1,
Thy_Header.pretty_name' ctxt (Long_Name.base_name name),
Pretty.str ":"]
| NONE => Pretty.keyword1 kind) in Pretty.block (Pretty.fbreaks (head :: prts)) end;
fun obtain prop ctxt = let val ((ps, prop'), ctxt') = Variable.focus NONE prop ctxt; fun fix (x, T) = (Binding.name (Variable.revert_fixed ctxt' x), SOME T, NoSyn); val xs = map (fix o #2) ps; val As = Logic.strip_imp_prems prop'; in ((Binding.empty, (xs, As)), ctxt') end;
in
fun pretty_statement ctxt kind raw_th = let val (th, is_elim) = standard_elim ctxt (Raw_Simplifier.norm_hhf ctxt raw_th); val ((_, [th']), ctxt') = Variable.import true [th] (Variable.set_body true ctxt); val prop = Thm.prop_of th'; val (prems, concl) = Logic.strip_horn prop; val concl_term = Object_Logic.drop_judgment ctxt concl;
val (assumes, cases) =
chop_suffix (fn prem => is_elim andalso concl aconv Logic.strip_assums_concl prem) prems; val is_thesis = if null cases then K falseelse fn v => v aconv concl_term; val fixes =
rev (fold_aterms (fn v as Free (x, T) => if Variable.is_newly_fixed ctxt' ctxt x andalso not (is_thesis v) then insert (op =) (Variable.revert_fixed ctxt' x, T) else I | _ => I) prop []); in
pretty_ctxt ctxt' (Fixes (map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) fixes)) @
pretty_ctxt ctxt' (Assumes (map (fn t => (Binding.empty_atts, [(t, [])])) assumes)) @
(if null cases then pretty_stmt ctxt' (Shows [(Binding.empty_atts, [(concl, [])])]) else letval (clauses, ctxt'') = fold_map obtain cases ctxt' in pretty_stmt ctxt'' (Obtains clauses) end) end |> thm_name ctxt kind raw_th;
end;
(** logical operations **)
(* witnesses -- hypotheses as protected facts *)
datatype witness = Witness of term * thm;
val mark_witness = Logic.protect; fun witness_prop (Witness (t, _)) = t; fun witness_hyps (Witness (_, th)) = Thm.hyps_of th; fun map_witness f (Witness witn) = Witness (f witn);
val norm_term = Envir.beta_eta_contract; val norm_conv = Drule.beta_eta_conversion; val norm_cterm = Thm.rhs_of o norm_conv;
fun find_witness witns hyp =
(case find_first (fn Witness (t, _) => hyp aconv t) witns of
NONE => letval hyp' = norm_term hyp in find_first (fn Witness (t, _) => hyp' aconv norm_term t) witns end
| some => some);
fun compose_witness (Witness (_, th)) r = let val th' = Goal.conclude (Thm.transfer (Thm.theory_of_thm r) th); val A = Thm.cprem_of r 1; in
Thm.implies_elim
(Conv.gconv_rule norm_conv 1 r)
(Conv.fconv_rule norm_conv
(Thm.instantiate (Thm.match (apply2 norm_cterm (Thm.cprop_of th', A))) th')) end;
in
fun satisfy_thm witns thm =
(Thm.chyps_of thm, thm) |-> fold (fn hyp =>
(case find_witness witns (Thm.term_of hyp) of
NONE => I
| SOME w => Thm.implies_intr hyp #> compose_witness w));
val satisfy_morphism = Morphism.thm_morphism "Element.satisfy" o satisfy_thm;
end;
(* rewriting with equalities *)
fun decomp_simp ctxt prop = let val _ = Logic.no_prems prop orelse
error ("Bad conditional rewrite rule " ^ Syntax.string_of_term ctxt prop); in
Logic.dest_equals prop handle TERM _ =>
error ("Rewrite rule not a meta-equality " ^ Syntax.string_of_term ctxt prop) end;
(* for activating declarations only *) fun eq_term_morphism _ [] = NONE
| eq_term_morphism ctxt0 props = let val simps = map (decomp_simp ctxt0) props;
fun rewrite_term thy = letval ctxt = Proof_Context.init_global thy in Pattern.rewrite_term thy simps [] end; val phi =
Morphism.morphism "Element.eq_term_morphism"
{binding = [],
typ = [],
term = [rewrite_term o Morphism.the_theory],
fact = [fn _ => fn _ => error "Illegal application of Element.eq_term_morphism"]}; in SOME phi end;
fun eq_morphism _ [] = NONE
| eq_morphism ctxt0 thms = let val simpset = Raw_Simplifier.simpset_of (Raw_Simplifier.init_simpset thms ctxt0); val simps = map (decomp_simp ctxt0 o Thm.full_prop_of o #2) (Raw_Simplifier.dest_simps simpset);
fun rewrite_term thy = Pattern.rewrite_term thy simps []; val rewrite =
Proof_Context.init_global #>
Raw_Simplifier.put_simpset simpset #>
Raw_Simplifier.rewrite0_rule; val phi =
Morphism.morphism "Element.eq_morphism"
{binding = [],
typ = [],
term = [rewrite_term o Morphism.the_theory],
fact = [map o rewrite o Morphism.the_theory]}; in SOME phi end;
fun activate_i elem ctxt = let val elem' =
(case (map_ctxt_attrib o map) Token.init_assignable elem of
Defines defs =>
Defines (defs |> map (fn ((a, atts), (t, ps)) =>
((Thm.def_binding_optional
(Binding.name (#1 (#1 (Local_Defs.cert_def ctxt (K []) t)))) a, atts),
(t, ps))))
| e => e); val ctxt' = Context.proof_map (init elem') ctxt; in ((map_ctxt_attrib o map) Token.closure elem', ctxt') end;
fun activate raw_elem ctxt = letval elem = raw_elem |> map_ctxt
{binding = I,
typ = I,
term = I,
pattern = I,
fact = Proof_Context.get_fact ctxt,
attrib = Attrib.check_src ctxt} in activate_i elem ctxt end;
end;
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.