src/Pure/Isar/element.ML
changeset 41581 72a02e3dec7e
parent 41425 9acb7c501530
child 42287 d98eb048a2e4
equal deleted inserted replaced
41580:220bc60c2387 41581:72a02e3dec7e
   199 
   199 
   200 (* pretty_statement *)
   200 (* pretty_statement *)
   201 
   201 
   202 local
   202 local
   203 
   203 
       
   204 fun standard_elim th =
       
   205   (case Object_Logic.elim_concl th of
       
   206     SOME C =>
       
   207       let
       
   208         val cert = Thm.cterm_of (Thm.theory_of_thm th);
       
   209         val thesis = Var ((Auto_Bind.thesisN, Thm.maxidx_of th + 1), fastype_of C);
       
   210         val th' = Thm.instantiate ([], [(cert C, cert thesis)]) th;
       
   211       in (th', true) end
       
   212   | NONE => (th, false));
       
   213 
   204 fun thm_name kind th prts =
   214 fun thm_name kind th prts =
   205   let val head =
   215   let val head =
   206     if Thm.has_name_hint th then
   216     if Thm.has_name_hint th then
   207       Pretty.block [Pretty.command kind,
   217       Pretty.block [Pretty.command kind,
   208         Pretty.brk 1, Pretty.str (Long_Name.base_name (Thm.get_name_hint th) ^ ":")]
   218         Pretty.brk 1, Pretty.str (Long_Name.base_name (Thm.get_name_hint th) ^ ":")]
   209     else Pretty.command kind
   219     else Pretty.command kind
   210   in Pretty.block (Pretty.fbreaks (head :: prts)) end;
   220   in Pretty.block (Pretty.fbreaks (head :: prts)) end;
   211 
   221 
   212 fun fix (x, T) = (Binding.name x, SOME T);
       
   213 
       
   214 fun obtain prop ctxt =
   222 fun obtain prop ctxt =
   215   let
   223   let
   216     val ((xs, prop'), ctxt') = Variable.focus prop ctxt;
   224     val ((ps, prop'), ctxt') = Variable.focus prop ctxt;
       
   225     fun fix (x, T) = (Binding.name (ProofContext.revert_skolem ctxt' x), SOME T);
       
   226     val xs = map (fix o Term.dest_Free o Thm.term_of o #2) ps;
   217     val As = Logic.strip_imp_prems (Thm.term_of prop');
   227     val As = Logic.strip_imp_prems (Thm.term_of prop');
   218   in ((Binding.empty, (map (fix o Term.dest_Free o Thm.term_of o #2) xs, As)), ctxt') end;
   228   in ((Binding.empty, (xs, As)), ctxt') end;
   219 
   229 
   220 in
   230 in
   221 
   231 
   222 fun pretty_statement ctxt kind raw_th =
   232 fun pretty_statement ctxt kind raw_th =
   223   let
   233   let
   224     val thy = ProofContext.theory_of ctxt;
   234     val thy = ProofContext.theory_of ctxt;
   225     val cert = Thm.cterm_of thy;
   235     val cert = Thm.cterm_of thy;
   226 
   236 
   227     val th = Raw_Simplifier.norm_hhf raw_th;
   237     val (th, is_elim) = standard_elim (Raw_Simplifier.norm_hhf raw_th);
   228     val is_elim = Object_Logic.is_elim th;
   238     val ((_, [th']), ctxt') = Variable.import true [th] (Variable.set_body true ctxt);
   229 
       
   230     val ((_, [th']), ctxt') = Variable.import true [th] (Variable.set_body false ctxt);
       
   231     val prop = Thm.prop_of th';
   239     val prop = Thm.prop_of th';
   232     val (prems, concl) = Logic.strip_horn prop;
   240     val (prems, concl) = Logic.strip_horn prop;
   233     val concl_term = Object_Logic.drop_judgment thy concl;
   241     val concl_term = Object_Logic.drop_judgment thy concl;
   234 
   242 
   235     val fixes = fold_aterms (fn v as Free (x, T) =>
   243     val fixes = fold_aterms (fn v as Free (x, T) =>
   236         if Variable.newly_fixed ctxt' ctxt x andalso not (v aconv concl_term)
   244         if Variable.newly_fixed ctxt' ctxt x andalso not (v aconv concl_term)
   237         then insert (op =) (x, T) else I | _ => I) prop [] |> rev;
   245         then insert (op =) (ProofContext.revert_skolem ctxt' x, T) else I | _ => I) prop [] |> rev;
   238     val (assumes, cases) = take_suffix (fn prem =>
   246     val (assumes, cases) = take_suffix (fn prem =>
   239       is_elim andalso concl aconv Logic.strip_assums_concl prem) prems;
   247       is_elim andalso concl aconv Logic.strip_assums_concl prem) prems;
   240   in
   248   in
   241     pretty_ctxt ctxt' (Fixes (map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) fixes)) @
   249     pretty_ctxt ctxt' (Fixes (map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) fixes)) @
   242     pretty_ctxt ctxt' (Assumes (map (fn t => (Attrib.empty_binding, [(t, [])])) assumes)) @
   250     pretty_ctxt ctxt' (Assumes (map (fn t => (Attrib.empty_binding, [(t, [])])) assumes)) @