src/Pure/Thy/thm_deps.ML
author wenzelm
Wed, 13 Oct 1999 19:41:35 +0200
changeset 7853 a4acf1b4d5a8
parent 7786 cf9d07ad62af
child 9450 c97dba47e504
permissions -rw-r--r--
system;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
     1
(*  Title:      Pure/Thy/thm_deps.ML
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
     2
    ID:         $Id$
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
     3
    Author:     Stefan Berghofer, TU Muenchen
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
     4
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
     5
Visualize dependencies of theorems.
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
     6
*)
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
     7
7785
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
     8
signature BASIC_THM_DEPS =
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
     9
sig
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    10
  val thm_deps : thm list -> unit
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    11
end;
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    12
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    13
signature THM_DEPS =
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    14
sig
7785
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    15
  include BASIC_THM_DEPS
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    16
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    17
  val enable : unit -> unit
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    18
  val disable : unit -> unit
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    19
end;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    20
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    21
structure ThmDeps : THM_DEPS =
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    22
struct
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    23
7785
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    24
fun enable () = Thm.keep_derivs := ThmDeriv;
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    25
fun disable () = Thm.keep_derivs := MinDeriv;
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    26
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    27
fun get_sess thy = if Theory.eq_thy (thy, ProtoPure.thy) then ["Pure"]
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    28
  else
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    29
    (case #session (Present.get_info thy) of
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    30
        [x] => [x, "base"]
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    31
      | xs => xs);
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    32
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    33
fun put_graph gr path =
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    34
    File.write path (cat_lines (map (fn {name, ID, dir, unfold, path, parents} =>
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    35
      "\"" ^ name ^ "\" \"" ^ ID ^ "\" \"" ^ dir ^ (if unfold then "\" + \"" else "\" \"") ^
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    36
      path ^ "\" > " ^ space_implode " " (map quote parents) ^ " ;") gr));
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    37
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    38
fun is_thm_axm (Theorem _) = true
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    39
  | is_thm_axm (Axiom _) = true
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    40
  | is_thm_axm _ = false;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    41
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    42
fun get_name (Theorem (s, _)) = s
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    43
  | get_name (Axiom (s, _)) = s
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    44
  | get_name _ = "";
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    45
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    46
fun make_deps_graph ((gra, parents), Join (ta, ders)) =
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    47
  let
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    48
    val name = get_name ta;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    49
  in
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    50
    if is_thm_axm ta then
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    51
      if is_none (Symtab.lookup (gra, name)) then
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    52
        let
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    53
          val (gra', parents') = foldl make_deps_graph ((gra, []), ders);
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    54
          val prefx = rev (tl (rev (NameSpace.unpack name)));
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    55
          val session = (case prefx of
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    56
               (x :: _) => (case ThyInfo.lookup_theory x of
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    57
                     (Some thy) => get_sess thy
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    58
                   | None => [])
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    59
             | _ => ["global"])
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    60
        in
7786
cf9d07ad62af Replaced update_new by update.
berghofe
parents: 7785
diff changeset
    61
          (Symtab.update ((name,
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    62
            {name = Sign.base_name name, ID = name,
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    63
             dir = space_implode "/" (session @ prefx),
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    64
             unfold = false, path = "", parents = parents'}), gra'), name ins parents)
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    65
        end
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    66
      else (gra, name ins parents)
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    67
    else
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    68
      foldl make_deps_graph ((gra, parents), ders)
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    69
  end;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    70
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    71
fun thm_deps thms =
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    72
  let
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    73
    val _ = writeln "Generating graph ...";
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    74
    val gra = map snd (Symtab.dest (fst (foldl make_deps_graph ((Symtab.empty, []),
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    75
      map (#der o rep_thm) thms))));
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    76
    val path = File.tmp_path (Path.unpack "theorems.graph");
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    77
    val _ = put_graph gra path;
7853
a4acf1b4d5a8 system;
wenzelm
parents: 7786
diff changeset
    78
    val _ = system ("$ISATOOL browser -d " ^ Path.pack (Path.expand path) ^ " &");
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    79
  in () end;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    80
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    81
end;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    82
7785
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    83
structure BasicThmDeps : BASIC_THM_DEPS = ThmDeps;
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    84
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    85
open BasicThmDeps;