src/Pure/Thy/thm_deps.ML
author berghofe
Fri, 28 Sep 2001 11:04:44 +0200
changeset 11612 ae8450657bf0
parent 11543 d61b913431c5
child 11819 9283b3c11234
permissions -rw-r--r--
Exchanged % and %%.
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
  val enable : unit -> unit
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    17
  val disable : unit -> unit
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    18
end;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    19
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    20
structure ThmDeps : THM_DEPS =
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    21
struct
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    22
11530
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    23
open Proofterm;
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    24
11543
d61b913431c5 renamed `keep_derivs' to `proofs', and made an integer;
wenzelm
parents: 11530
diff changeset
    25
fun enable () = if ! proofs = 0 then proofs := 1 else ();
d61b913431c5 renamed `keep_derivs' to `proofs', and made an integer;
wenzelm
parents: 11530
diff changeset
    26
fun disable () = proofs := 0;
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    27
11530
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    28
fun dest_thm_axm (PThm (nt, prf, _, _)) = (nt, prf)
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    29
  | dest_thm_axm (PAxm (n, _, _)) = ((n ^ " (Ax)", []), MinProof [])
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    30
  | dest_thm_axm _ = (("", []), MinProof []);
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    31
11530
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    32
fun make_deps_graph (p, AbsP (_, _, prf)) = make_deps_graph (p, prf)
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    33
  | make_deps_graph (p, Abst (_, _, prf)) = make_deps_graph (p, prf)
11612
ae8450657bf0 Exchanged % and %%.
berghofe
parents: 11543
diff changeset
    34
  | make_deps_graph (p, prf1 %% prf2) =
11530
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    35
      make_deps_graph (make_deps_graph (p, prf1), prf2)
11612
ae8450657bf0 Exchanged % and %%.
berghofe
parents: 11543
diff changeset
    36
  | make_deps_graph (p, prf % _) = make_deps_graph (p, prf)
11530
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    37
  | make_deps_graph (p, MinProof prfs) = foldl make_deps_graph (p, prfs)
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    38
  | make_deps_graph (p as (gra, parents), prf) =
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    39
      let val ((name, tags), prf') = dest_thm_axm prf
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    40
      in
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    41
        if name <> "" andalso not (Drule.has_internal tags) then
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    42
          if is_none (Symtab.lookup (gra, name)) then
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    43
            let
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    44
              val (gra', parents') = make_deps_graph ((gra, []), prf');
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    45
              val prefx = #1 (Library.split_last (NameSpace.unpack name));
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    46
              val session =
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    47
                (case prefx of
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    48
                  (x :: _) =>
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    49
                    (case ThyInfo.lookup_theory x of
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    50
                      Some thy =>
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    51
                        let val name = #name (Present.get_info thy)
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    52
                        in if name = "" then [] else [name] end 
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    53
                    | None => [])
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    54
                 | _ => ["global"]);
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    55
            in
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    56
              (Symtab.update ((name,
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    57
                {name = Sign.base_name name, ID = name,
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    58
                 dir = space_implode "/" (session @ prefx),
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    59
                 unfold = false, path = "", parents = parents'}), gra'),
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    60
               name ins parents)
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    61
            end
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    62
          else (gra, name ins parents)
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    63
        else
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    64
          make_deps_graph ((gra, parents), prf')
b6e21f6cfacd Adapted to new proof terms.
berghofe
parents: 9502
diff changeset
    65
      end;
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    66
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    67
fun thm_deps thms =
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    68
  let
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    69
    val _ = writeln "Generating graph ...";
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    70
    val gra = map snd (Symtab.dest (fst (foldl make_deps_graph ((Symtab.empty, []),
9502
50ec59aff389 adapted deriv;
wenzelm
parents: 9450
diff changeset
    71
      map (#2 o #der o Thm.rep_thm) thms))));
7765
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    72
    val path = File.tmp_path (Path.unpack "theorems.graph");
9450
wenzelm
parents: 7853
diff changeset
    73
    val _ = Present.write_graph gra path;
7853
a4acf1b4d5a8 system;
wenzelm
parents: 7786
diff changeset
    74
    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
    75
  in () end;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    76
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    77
end;
fa28bac7903c New function thm_deps for visualizing dependencies of theorems.
berghofe
parents:
diff changeset
    78
7785
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    79
structure BasicThmDeps : BASIC_THM_DEPS = ThmDeps;
c06825c396e8 Added functions for enabling and disabling derivations.
berghofe
parents: 7783
diff changeset
    80
open BasicThmDeps;