src/Pure/Tools/find_theorems.ML
changeset 63080 8326aa594273
parent 62969 9f394a16c557
child 63429 baedd4724f08
equal deleted inserted replaced
63079:e9ad90ce926c 63080:8326aa594273
   333 val index_ord = option_ord (K EQUAL);
   333 val index_ord = option_ord (K EQUAL);
   334 val hidden_ord = bool_ord o apply2 Long_Name.is_hidden;
   334 val hidden_ord = bool_ord o apply2 Long_Name.is_hidden;
   335 val qual_ord = int_ord o apply2 Long_Name.qualification;
   335 val qual_ord = int_ord o apply2 Long_Name.qualification;
   336 val txt_ord = int_ord o apply2 size;
   336 val txt_ord = int_ord o apply2 size;
   337 
   337 
   338 fun nicer_name (x, i) (y, j) =
   338 fun nicer_name ((a, x), i) ((b, y), j) =
   339   (case hidden_ord (x, y) of EQUAL =>
   339   (case bool_ord (a, b) of EQUAL =>
   340     (case index_ord (i, j) of EQUAL =>
   340     (case hidden_ord (x, y) of EQUAL =>
   341       (case qual_ord (x, y) of EQUAL => txt_ord (x, y) | ord => ord)
   341       (case index_ord (i, j) of EQUAL =>
       
   342         (case qual_ord (x, y) of EQUAL => txt_ord (x, y) | ord => ord)
       
   343       | ord => ord)
   342     | ord => ord)
   344     | ord => ord)
   343   | ord => ord) <> GREATER;
   345   | ord => ord) <> GREATER;
   344 
   346 
   345 fun rem_cdups nicer xs =
   347 fun rem_cdups nicer xs =
   346   let
   348   let
   355 in
   357 in
   356 
   358 
   357 fun nicer_shortest ctxt =
   359 fun nicer_shortest ctxt =
   358   let
   360   let
   359     fun extern_shortest name =
   361     fun extern_shortest name =
   360       Name_Space.extern_shortest ctxt
   362       let
   361         (Facts.space_of (Proof_Context.facts_of_fact ctxt name)) name;
   363         val facts = Proof_Context.facts_of_fact ctxt name;
       
   364         val space = Facts.space_of facts;
       
   365       in (Facts.is_dynamic facts name, Name_Space.extern_shortest ctxt space name) end;
   362 
   366 
   363     fun nicer (Facts.Named ((x, _), i)) (Facts.Named ((y, _), j)) =
   367     fun nicer (Facts.Named ((x, _), i)) (Facts.Named ((y, _), j)) =
   364           nicer_name (extern_shortest x, i) (extern_shortest y, j)
   368           nicer_name (extern_shortest x, i) (extern_shortest y, j)
   365       | nicer (Facts.Fact _) (Facts.Named _) = true
   369       | nicer (Facts.Fact _) (Facts.Named _) = true
   366       | nicer (Facts.Named _) (Facts.Fact _) = false
   370       | nicer (Facts.Named _) (Facts.Fact _) = false
   387     val thy = Proof_Context.theory_of ctxt;
   391     val thy = Proof_Context.theory_of ctxt;
   388     val transfer = Global_Theory.transfer_theories thy;
   392     val transfer = Global_Theory.transfer_theories thy;
   389     val local_facts = Proof_Context.facts_of ctxt;
   393     val local_facts = Proof_Context.facts_of ctxt;
   390     val global_facts = Global_Theory.facts_of thy;
   394     val global_facts = Global_Theory.facts_of thy;
   391   in
   395   in
   392    (Facts.dest_static false [global_facts] local_facts @
   396    (Facts.dest_all (Context.Proof ctxt) false [global_facts] local_facts @
   393      Facts.dest_static false [] global_facts)
   397      Facts.dest_all (Context.Proof ctxt) false [] global_facts)
   394    |> maps Facts.selections
   398    |> maps Facts.selections
   395    |> map (apsnd transfer)
   399    |> map (apsnd transfer)
   396   end;
   400   end;
   397 
   401 
   398 fun filter_theorems ctxt theorems query =
   402 fun filter_theorems ctxt theorems query =
   457     val (name, sel) =
   461     val (name, sel) =
   458       (case thmref of
   462       (case thmref of
   459         Facts.Named ((name, _), sel) => (name, sel)
   463         Facts.Named ((name, _), sel) => (name, sel)
   460       | Facts.Fact _ => raise Fail "Illegal literal fact");
   464       | Facts.Fact _ => raise Fail "Illegal literal fact");
   461   in
   465   in
   462     [Pretty.mark (#1 (Proof_Context.markup_extern_fact ctxt name)) (Pretty.str name),
   466     [Pretty.marks_str (#1 (Proof_Context.markup_extern_fact ctxt name), name),
   463       Pretty.str (Facts.string_of_selection sel), Pretty.str ":", Pretty.brk 1]
   467       Pretty.str (Facts.string_of_selection sel), Pretty.str ":", Pretty.brk 1]
   464   end;
   468   end;
   465 
   469 
   466 in
   470 in
   467 
   471