src/Tools/IsaPlanner/isand.ML
author wenzelm
Wed, 12 Sep 2012 22:00:29 +0200
changeset 49339 d1fcb4de8349
parent 46777 1ce61ee1571a
child 49340 25fc6e0da459
permissions -rw-r--r--
eliminated some old material that is unused in the visible universe;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23175
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
     1
(*  Title:      Tools/IsaPlanner/isand.ML
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
     2
    Author:     Lucas Dixon, University of Edinburgh
23175
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
     3
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
     4
Natural Deduction tools.
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
     5
23175
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
     6
For working with Isabelle theorems in a natural detuction style.
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
     7
ie, not having to deal with meta level quantified varaibles,
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
     8
instead, we work with newly introduced frees, and hide the
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
     9
"all"'s, exporting results from theorems proved with the frees, to
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    10
solve the all cases of the previous goal. This allows resolution
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    11
to do proof search normally.
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    12
23175
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    13
Note: A nice idea: allow exporting to solve any subgoal, thus
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    14
allowing the interleaving of proof, or provide a structure for the
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    15
ordering of proof, thus allowing proof attempts in parrell, but
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    16
recording the order to apply things in.
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    17
23175
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    18
THINK: are we really ok with our varify name w.r.t the prop - do
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    19
we also need to avoid names in the hidden hyps? What about
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    20
unification contraints in flex-flex pairs - might they also have
267ba70e7a9d tuned headers -- adapted to usual conventions;
wenzelm
parents: 23171
diff changeset
    21
extra free vars?
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    22
*)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    23
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    24
signature ISA_ND =
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    25
sig
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    26
  (* inserting meta level params for frees in the conditions *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    27
  val allify_conditions : (term -> cterm) -> (string * typ) list -> thm -> thm * cterm list
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    28
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    29
  (* meta level fixed params (i.e. !! vars) *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    30
  val fix_alls_term : int -> term -> term * term list
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    31
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    32
  val unfix_frees : cterm list -> thm -> thm
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    33
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    34
  (* assumptions/subgoals *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    35
  val fixed_subgoal_thms : thm -> thm list * (thm list -> thm)
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    36
end
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    37
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    38
structure IsaND : ISA_ND =
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    39
struct
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    40
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    41
(* Given ctertmify function, (string,type) pairs capturing the free
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    42
vars that need to be allified in the assumption, and a theorem with
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    43
assumptions possibly containing the free vars, then we give back the
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    44
assumptions allified as hidden hyps.
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    45
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    46
Given: x
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    47
th: A vs ==> B vs
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    48
Results in: "B vs" [!!x. A x]
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    49
*)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    50
fun allify_conditions ctermify Ts th =
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    51
    let
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    52
      val premts = Thm.prems_of th;
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    53
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    54
      fun allify_prem_var (vt as (n,ty),t)  =
46217
7b19666f0e3d renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents: 44121
diff changeset
    55
          (Logic.all_const ty) $ (Abs(n,ty,Term.abstract_over (Free vt, t)))
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    56
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 29270
diff changeset
    57
      fun allify_prem Ts p = List.foldr allify_prem_var p Ts
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    58
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    59
      val cTs = map (ctermify o Free) Ts
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    60
      val cterm_asms = map (ctermify o allify_prem Ts) premts
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    61
      val allifyied_asm_thms = map (Drule.forall_elim_list cTs o Thm.assume) cterm_asms
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    62
    in
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    63
      (Library.foldl (fn (x,y) => y COMP x) (th, allifyied_asm_thms), cterm_asms)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    64
    end;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    65
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    66
(* make free vars into schematic vars with index zero *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    67
fun unfix_frees frees =
46777
wenzelm
parents: 46217
diff changeset
    68
     fold (K (Thm.forall_elim_var 0)) frees
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    69
     o Drule.forall_intr_list frees;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    70
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    71
(* datatype to capture an exported result, ie a fix or assume. *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    72
datatype export =
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    73
         export of {fixes : Thm.cterm list, (* fixed vars *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    74
                    assumes : Thm.cterm list, (* hidden hyps/assumed prems *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    75
                    sgid : int,
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    76
                    gth :  Thm.thm}; (* subgoal/goalthm *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    77
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    78
(* exporting function that takes a solution to the fixed/assumed goal,
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    79
and uses this to solve the subgoal in the main theorem *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    80
fun export_solution (export {fixes = cfvs, assumes = hcprems,
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    81
                             sgid = i, gth = gth}) solth =
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    82
    let
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    83
      val solth' =
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    84
          solth |> Drule.implies_intr_list hcprems
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    85
                |> Drule.forall_intr_list cfvs
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    86
    in Drule.compose_single (solth', i, gth) end;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    87
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    88
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    89
(* fix parameters of a subgoal "i", as free variables, and create an
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    90
exporting function that will use the result of this proved goal to
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    91
show the goal in the original theorem.
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    92
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    93
Note, an advantage of this over Isar is that it supports instantiation
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    94
of unkowns in the earlier theorem, ie we can do instantiation of meta
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    95
vars!
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    96
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
    97
avoids constant, free and vars names.
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    98
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
    99
loosely corresponds to:
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   100
Given "[| SG0; ... !! x. As ==> SGi x; ... SGm |] ==> G" : thm
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   101
Result:
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   102
  ("(As ==> SGi x') ==> (As ==> SGi x')" : thm,
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   103
   expf :
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   104
     ("As ==> SGi x'" : thm) ->
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   105
     ("[| SG0; ... SGi-1; SGi+1; ... SGm |] ==> G") : thm)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   106
*)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   107
fun fix_alls_term i t =
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   108
    let
44121
44adaa6db327 old term operations are legacy;
wenzelm
parents: 43324
diff changeset
   109
      val varnames = map (fst o fst o Term.dest_Var) (Misc_Legacy.term_vars t)
44adaa6db327 old term operations are legacy;
wenzelm
parents: 43324
diff changeset
   110
      val names = Misc_Legacy.add_term_names (t,varnames);
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   111
      val gt = Logic.get_goal t i;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   112
      val body = Term.strip_all_body gt;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   113
      val alls = rev (Term.strip_all_vars gt);
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   114
      val fvs = map Free
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   115
                    (Name.variant_list names (map fst alls)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   116
                       ~~ (map snd alls));
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   117
    in ((subst_bounds (fvs,body)), fvs) end;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   118
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   119
fun fix_alls_cterm i th =
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   120
    let
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   121
      val ctermify = Thm.cterm_of (Thm.theory_of_thm th);
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   122
      val (fixedbody, fvs) = fix_alls_term i (Thm.prop_of th);
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   123
      val cfvs = rev (map ctermify fvs);
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   124
      val ct_body = ctermify fixedbody
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   125
    in
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   126
      (ct_body, cfvs)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   127
    end;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   128
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   129
fun fix_alls' i =
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   130
     (apfst Thm.trivial) o (fix_alls_cterm i);
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   131
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   132
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   133
(* hide other goals *)
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   134
(* note the export goal is rotated by (i - 1) and will have to be
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   135
unrotated to get backto the originial position(s) *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   136
fun hide_other_goals th =
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   137
    let
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   138
      (* tl beacuse fst sg is the goal we are interested in *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   139
      val cprems = tl (Drule.cprems_of th)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   140
      val aprems = map Thm.assume cprems
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   141
    in
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   142
      (Drule.implies_elim_list (Drule.rotate_prems 1 th) aprems,
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   143
       cprems)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   144
    end;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   145
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   146
(* a nicer version of the above that leaves only a single subgoal (the
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   147
other subgoals are hidden hyps, that the exporter suffles about)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   148
namely the subgoal that we were trying to solve. *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   149
(* loosely corresponds to:
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   150
Given "[| SG0; ... !! x. As ==> SGi x; ... SGm |] ==> G" : thm
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   151
Result:
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   152
  ("(As ==> SGi x') ==> SGi x'" : thm,
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   153
   expf :
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   154
     ("SGi x'" : thm) ->
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   155
     ("[| SG0; ... SGi-1; SGi+1; ... SGm |] ==> G") : thm)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   156
*)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   157
fun fix_alls i th =
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   158
    let
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   159
      val (fixed_gth, fixedvars) = fix_alls' i th
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   160
      val (sml_gth, othergoals) = hide_other_goals fixed_gth
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   161
    in
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   162
      (sml_gth, export {fixes = fixedvars,
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   163
                        assumes = othergoals,
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   164
                        sgid = i, gth = th})
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   165
    end;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   166
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   167
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   168
(* Fixme: allow different order of subgoals given to expf *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   169
(* make each subgoal into a separate thm that needs to be proved *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   170
(* loosely corresponds to:
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   171
Given
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   172
  "[| SG0; ... SGm |] ==> G" : thm
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   173
Result:
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   174
(["SG0 ==> SG0", ... ,"SGm ==> SGm"] : thm list, -- goals
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   175
 ["SG0", ..., "SGm"] : thm list ->   -- export function
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   176
   "G" : thm)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   177
*)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   178
fun subgoal_thms th =
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   179
    let
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   180
      val t = (prop_of th);
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   181
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   182
      val prems = Logic.strip_imp_prems t;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   183
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   184
      val sgn = Thm.theory_of_thm th;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   185
      val ctermify = Thm.cterm_of sgn;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   186
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   187
      val aprems = map (Thm.trivial o ctermify) prems;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   188
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   189
      fun explortf premths =
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   190
          Drule.implies_elim_list th premths
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   191
    in
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   192
      (aprems, explortf)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   193
    end;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   194
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   195
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   196
(* Fixme: allow different order of subgoals in exportf *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   197
(* as above, but also fix all parameters in all subgoals, and uses
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   198
fix_alls, not fix_alls', ie doesn't leave extra asumptions as apparent
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   199
subgoals. *)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   200
(* loosely corresponds to:
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   201
Given
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   202
  "[| !! x0s. A0s x0s ==> SG0 x0s;
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   203
      ...; !! xms. Ams xms ==> SGm xms|] ==> G" : thm
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   204
Result:
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   205
(["(A0s x0s' ==> SG0 x0s') ==> SG0 x0s'",
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   206
  ... ,"(Ams xms' ==> SGm xms') ==> SGm xms'"] : thm list, -- goals
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   207
 ["SG0 x0s'", ..., "SGm xms'"] : thm list ->   -- export function
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   208
   "G" : thm)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   209
*)
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   210
(* requires being given solutions! *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   211
fun fixed_subgoal_thms th =
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   212
    let
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   213
      val (subgoals, expf) = subgoal_thms th;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   214
(*       fun export_sg (th, exp) = exp th; *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   215
      fun export_sgs expfs solthms =
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   216
          expf (map2 (curry (op |>)) solthms expfs);
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   217
(*           expf (map export_sg (ths ~~ expfs)); *)
49339
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   218
    in
d1fcb4de8349 eliminated some old material that is unused in the visible universe;
wenzelm
parents: 46777
diff changeset
   219
      apsnd export_sgs (Library.split_list (map (apsnd export_solution o
23171
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   220
                                                 fix_alls 1) subgoals))
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   221
    end;
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   222
861f63a35d31 moved IsaPlanner from Provers to Tools;
wenzelm
parents:
diff changeset
   223
end;