src/Tools/isac/MathEngBasic/tactic.sml
author Walther Neuper <walther.neuper@jku.at>
Fri, 17 Jan 2020 13:14:11 +0100
changeset 59773 d88bb023c380
parent 59749 cc3b1807f72e
child 59778 148d369e6b71
permissions -rw-r--r--
lucin: introduce Calc.T and Program.T
wneuper@59571
     1
(* Title:  Tactics; tac_ for interaction with frontend, input for internal use.
wneuper@59304
     2
   Author: Walther Neuper 170121
wneuper@59304
     3
   (c) due to copyright terms
wneuper@59304
     4
wneuper@59304
     5
regular expression for search:
wneuper@59304
     6
wneuper@59304
     7
Add_Find|Add_Given|Add_Relation|Apply_Assumption|Apply_Method|Begin_Sequ|Begin_Trans|Split_And|Split_Or|Split_Intersect|Conclude_And|Conclude_Or|Collect_Trues|End_Sequ|End_Trans|End_Ruleset|End_Subproblem|End_Intersect|End_Proof|CAScmd|Calculate|Check_Postcond|Check_elementwise|Del_Find|Del_Given|Del_Relation|Derive|Detail_Set|Detail_Set_Inst|End_Detail|Empty_Tac|Free_Solve|Init_Proof|Model_Problem Or_to_List|Refine_Problem|Refine_Tacitly| Rewrite|Rewrite_Asm|Rewrite_Inst|Rewrite_Set|Rewrite_Set_Inst|Specify_Method|Specify_Problem|Specify_Theory|Subproblem|Substitute|Tac|Take|Take_Inst
wneuper@59304
     8
wneuper@59304
     9
*)
wneuper@59298
    10
signature TACTIC =
wneuper@59298
    11
sig
walther@59741
    12
  datatype T =
walther@59741
    13
    Add_Find' of Rule.cterm' * Model.itm list | Add_Given' of Rule.cterm' * Model.itm list 
walther@59741
    14
  | Add_Relation' of Rule.cterm' * Model.itm list
walther@59741
    15
  | Apply_Assumption' of term list * term
walther@59741
    16
  | Apply_Method' of Celem.metID * term option * Istate_Def.T * Proof.context
walther@59741
    17
walther@59741
    18
  | Begin_Sequ' | Begin_Trans' of term
walther@59741
    19
  | Split_And' of term | Split_Or' of term | Split_Intersect' of term
walther@59741
    20
  | Conclude_And' of term | Conclude_Or' of term | Collect_Trues' of term
walther@59741
    21
  | End_Sequ' | End_Trans' of Selem.result
walther@59741
    22
  | End_Ruleset' of term | End_Subproblem' of term | End_Intersect' of term | End_Proof''
walther@59741
    23
walther@59741
    24
  | CAScmd' of term
walther@59741
    25
  | Calculate' of Rule.theory' * string * term * (term * Celem.thm')
walther@59741
    26
  | Check_Postcond' of Celem.pblID * Selem.result
walther@59741
    27
  | Check_elementwise' of term * Rule.cterm' * Selem.result
walther@59741
    28
  | Del_Find' of Rule.cterm' | Del_Given' of Rule.cterm' | Del_Relation' of Rule.cterm'
walther@59741
    29
walther@59741
    30
  | Derive' of Rule.rls
walther@59741
    31
  | Detail_Set' of Rule.theory' * bool * Rule.rls * term * Selem.result
walther@59741
    32
  | Detail_Set_Inst' of Rule.theory' * bool * Rule.subst * Rule.rls * term * Selem.result
walther@59741
    33
  | End_Detail' of Selem.result
walther@59741
    34
walther@59741
    35
  | Empty_Tac_
walther@59741
    36
  | Free_Solve'
walther@59741
    37
walther@59741
    38
  | Init_Proof' of Rule.cterm' list * Celem.spec
walther@59741
    39
  | Model_Problem' of Celem.pblID * Model.itm list * Model.itm list
walther@59741
    40
  | Or_to_List' of term * term
walther@59741
    41
  | Refine_Problem' of Celem.pblID * (Model.itm list * (bool * term) list)
walther@59741
    42
  | Refine_Tacitly' of Celem.pblID * Celem.pblID * Rule.domID * Celem.metID * Model.itm list
walther@59741
    43
walther@59741
    44
  | Rewrite' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Celem.thm'' * term * Selem.result
walther@59741
    45
  | Rewrite_Asm' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Celem.thm'' * term * Selem.result
walther@59741
    46
  | Rewrite_Inst' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Rule.subst * Celem.thm'' * term * Selem.result
walther@59741
    47
  | Rewrite_Set' of Rule.theory' * bool * Rule.rls * term * Selem.result
walther@59741
    48
  | Rewrite_Set_Inst' of Rule.theory' * bool * Rule.subst * Rule.rls * term * Selem.result
walther@59741
    49
walther@59741
    50
  | Specify_Method' of Celem.metID * Model.ori list * Model.itm list
walther@59741
    51
  | Specify_Problem' of Celem.pblID * (bool * (Model.itm list * (bool * term) list))
walther@59741
    52
  | Specify_Theory' of Rule.domID
walther@59741
    53
  | Subproblem' of Celem.spec * Model.ori list * term * Selem.fmz_ * Proof.context * term
walther@59741
    54
  | Substitute' of Rule.rew_ord_ * Rule.rls * Selem.subte * term * term
walther@59741
    55
  | Tac_ of theory * string * string * string
walther@59741
    56
  | Take' of term | Take_Inst' of term
walther@59728
    57
  val string_of : T -> string
wneuper@59302
    58
walther@59741
    59
  datatype input =
walther@59741
    60
    Add_Find of Rule.cterm' | Add_Given of Rule.cterm' | Add_Relation of Rule.cterm'
walther@59741
    61
  | Apply_Assumption of Rule.cterm' list
walther@59741
    62
  | Apply_Method of Celem.metID
walther@59741
    63
  (*/--- TODO: re-design ? -----------------------------------------------------------------\*)
walther@59741
    64
  | Begin_Sequ | Begin_Trans
walther@59741
    65
  | Split_And | Split_Or | Split_Intersect
walther@59741
    66
  | Conclude_And | Conclude_Or | Collect_Trues
walther@59741
    67
  | End_Sequ | End_Trans
walther@59741
    68
  | End_Ruleset | End_Subproblem | End_Intersect | End_Proof'
walther@59741
    69
  (*\--- TODO: re-design ? -----------------------------------------------------------------/*)
walther@59741
    70
  | CAScmd of Rule.cterm'
walther@59741
    71
  | Calculate of string
walther@59741
    72
  | Check_Postcond of Celem.pblID
walther@59741
    73
  | Check_elementwise of Rule.cterm'
walther@59741
    74
  | Del_Find of Rule.cterm' | Del_Given of Rule.cterm' | Del_Relation of Rule.cterm'
walther@59741
    75
walther@59741
    76
  | Derive of Rule.rls'
walther@59741
    77
  | Detail_Set of Rule.rls'
walther@59741
    78
  | Detail_Set_Inst of Selem.subs * Rule.rls'
walther@59741
    79
  | End_Detail
walther@59741
    80
walther@59741
    81
  | Empty_Tac
walther@59741
    82
  | Free_Solve
walther@59741
    83
walther@59741
    84
  | Init_Proof of Rule.cterm' list * Celem.spec
walther@59741
    85
  | Model_Problem
walther@59741
    86
  | Or_to_List
walther@59741
    87
  | Refine_Problem of Celem.pblID
walther@59741
    88
  | Refine_Tacitly of Celem.pblID
walther@59741
    89
walther@59741
    90
  | Rewrite of Celem.thm''
walther@59741
    91
  | Rewrite_Asm of Celem.thm''
walther@59741
    92
  | Rewrite_Inst of Selem.subs * Celem.thm''
walther@59741
    93
  | Rewrite_Set of Rule.rls'
walther@59741
    94
  | Rewrite_Set_Inst of Selem.subs * Rule.rls'
walther@59741
    95
walther@59741
    96
  | Specify_Method of Celem.metID
walther@59741
    97
  | Specify_Problem of Celem.pblID
walther@59741
    98
  | Specify_Theory of Rule.domID
walther@59741
    99
  | Subproblem of Rule.domID * Celem.pblID
walther@59741
   100
walther@59741
   101
  | Substitute of Selem.sube
walther@59741
   102
  | Tac of string
walther@59741
   103
  | Take of Rule.cterm' | Take_Inst of Rule.cterm'
wneuper@59571
   104
  val tac2str : input -> string
wneuper@59302
   105
walther@59728
   106
  val eq_tac : input * input -> bool
walther@59728
   107
  val is_empty_tac : input -> bool
walther@59728
   108
  val is_rewtac : input -> bool
walther@59728
   109
  val is_rewset : input -> bool
walther@59728
   110
  val rls_of : input -> Rule.rls'
wneuper@59571
   111
  val tac2IDstr : input -> string
walther@59728
   112
  val rule2tac : theory -> (term * term) list ->  Rule.rule -> input
walther@59704
   113
  val input_from_T : T -> input
walther@59728
   114
  val result : T -> term
walther@59728
   115
  val creates_assms: T -> term list
walther@59728
   116
  val insert_assumptions: T -> Proof.context -> Proof.context
walther@59749
   117
  val for_specify: input -> bool
walther@59749
   118
  val for_specify': T -> bool
walther@59735
   119
wneuper@59310
   120
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
wneuper@59310
   121
  (* NONE *)
walther@59702
   122
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
wneuper@59310
   123
  (* NONE *)
walther@59702
   124
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
wneuper@59298
   125
wneuper@59310
   126
(*----- unused code, kept as hints to design ideas ---------------------------------------------*)
wneuper@59310
   127
  (* NONE *)
wneuper@59298
   128
end
wneuper@59298
   129
walther@59728
   130
(**)
wneuper@59571
   131
structure Tactic(**): TACTIC(**) =
wneuper@59298
   132
struct
walther@59728
   133
(**)
wneuper@59298
   134
wneuper@59302
   135
(* tactics for user at front-end.
wneuper@59571
   136
   input propagates the construction of the calc-tree;
wneuper@59302
   137
   there are
wneuper@59302
   138
   (a) 'specsteps' for the specify-phase, and others for the solve-phase
wneuper@59302
   139
   (b) those of the solve-phase are 'initac's and others;
wneuper@59302
   140
       initacs start with a formula different from the preceding formula.
wneuper@59302
   141
   see 'type tac_' for the internal representation of tactics
wneuper@59302
   142
*)
walther@59741
   143
datatype input =
walther@59741
   144
    Add_Find of Rule.cterm' | Add_Given of Rule.cterm' | Add_Relation of Rule.cterm'
walther@59741
   145
  | Apply_Assumption of Rule.cterm' list
walther@59741
   146
  | Apply_Method of Celem.metID
walther@59741
   147
    (* creates an "istate" in PblObj.env; in case of "init_form" 
walther@59741
   148
      creates a formula at ((lev_on o lev_dn) p, Frm) and in this "ppobj.loc"
walther@59741
   149
      a "SOME istate" at fst of "loc".
walther@59741
   150
      As each step (in the solve-phase) has a resulting formula (at the front-end)
walther@59741
   151
      Apply_Method also does the 1st step in the script (an "initac") if there is no "init_form" *)  
walther@59741
   152
  (*/--- TODO: re-design ? -----------------------------------------------------------------\*)
walther@59741
   153
  | Begin_Sequ | Begin_Trans
walther@59741
   154
  | Split_And | Split_Or | Split_Intersect
walther@59741
   155
  | Conclude_And | Conclude_Or | Collect_Trues
walther@59741
   156
  | End_Sequ | End_Trans
walther@59741
   157
  | End_Ruleset | End_Subproblem (* WN0509 drop *) | End_Intersect | End_Proof'
walther@59741
   158
  (*\--- TODO: re-design ? -----------------------------------------------------------------/*)
walther@59741
   159
  | CAScmd of Rule.cterm'
walther@59741
   160
  | Calculate of string
walther@59741
   161
  | Check_Postcond of Celem.pblID
walther@59741
   162
  | Check_elementwise of Rule.cterm'
walther@59741
   163
  | Del_Find of Rule.cterm' | Del_Given of Rule.cterm' | Del_Relation of Rule.cterm'
wneuper@59302
   164
walther@59741
   165
  | Derive of Rule.rls'                 (* WN0509 drop *)
walther@59741
   166
  | Detail_Set of Rule.rls'             (* WN0509 drop *)
walther@59741
   167
  | Detail_Set_Inst of Selem.subs * Rule.rls' (* WN0509 drop *)
walther@59741
   168
  | End_Detail                     (* WN0509 drop *)
wneuper@59302
   169
walther@59741
   170
  | Empty_Tac
walther@59741
   171
  | Free_Solve
walther@59741
   172
walther@59741
   173
  | Init_Proof of Rule.cterm' list * Celem.spec
walther@59741
   174
  | Model_Problem
walther@59741
   175
  | Or_to_List
walther@59741
   176
  | Refine_Problem of Celem.pblID
walther@59741
   177
  | Refine_Tacitly of Celem.pblID
walther@59741
   178
walther@59741
   179
   (* rewrite-tactics can transport a (thmID, thm) to and (!) from the java-front-end
walther@59741
   180
     because there all the thms are present with both (thmID, thm)
walther@59741
   181
     (where user-views can show both or only one of (thmID, thm)),
walther@59741
   182
     and thm is created from ThmID by assoc_thm'' when entering isabisac *)
walther@59741
   183
  | Rewrite of Celem.thm''
walther@59741
   184
  | Rewrite_Asm of Celem.thm''
walther@59741
   185
  | Rewrite_Inst of Selem.subs * Celem.thm''
walther@59741
   186
  | Rewrite_Set of Rule.rls'
walther@59741
   187
  | Rewrite_Set_Inst of Selem.subs * Rule.rls'
walther@59741
   188
walther@59741
   189
  | Specify_Method of Celem.metID
walther@59741
   190
  | Specify_Problem of Celem.pblID
walther@59741
   191
  | Specify_Theory of Rule.domID
walther@59741
   192
  | Subproblem of Rule.domID * Celem.pblID (* WN0509 drop *)
walther@59741
   193
walther@59741
   194
  | Substitute of Selem.sube
walther@59741
   195
  | Tac of string               (* WN0509 drop *)
walther@59741
   196
  | Take of Rule.cterm' | Take_Inst of Rule.cterm'
walther@59741
   197
walther@59741
   198
fun tac2str ma = case ma of
walther@59741
   199
    Init_Proof (ppc, spec)  => 
walther@59741
   200
      "Init_Proof "^(pair2str (strs2str ppc, Celem.spec2str spec))
walther@59741
   201
  | Model_Problem           => "Model_Problem "
walther@59741
   202
  | Refine_Tacitly pblID    => "Refine_Tacitly " ^ strs2str pblID 
walther@59741
   203
  | Refine_Problem pblID    => "Refine_Problem " ^ strs2str pblID 
walther@59741
   204
  | Add_Given cterm'        => "Add_Given " ^ cterm'
walther@59741
   205
  | Del_Given cterm'        => "Del_Given " ^ cterm'
walther@59741
   206
  | Add_Find cterm'         => "Add_Find " ^ cterm'
walther@59741
   207
  | Del_Find cterm'         => "Del_Find " ^ cterm'
walther@59741
   208
  | Add_Relation cterm'     => "Add_Relation " ^ cterm'
walther@59741
   209
  | Del_Relation cterm'     => "Del_Relation " ^ cterm'
walther@59741
   210
walther@59741
   211
  | Specify_Theory domID    => "Specify_Theory " ^ quote domID
walther@59741
   212
  | Specify_Problem pblID   => "Specify_Problem " ^ strs2str pblID
walther@59741
   213
  | Specify_Method metID    => "Specify_Method " ^ strs2str metID
walther@59741
   214
  | Apply_Method metID      => "Apply_Method " ^ strs2str metID
walther@59741
   215
  | Check_Postcond pblID    => "Check_Postcond " ^ strs2str pblID
walther@59741
   216
  | Free_Solve              => "Free_Solve"
walther@59741
   217
walther@59741
   218
  | Rewrite_Inst (subs, (id, thm)) =>
walther@59741
   219
    "Rewrite_Inst " ^ (pair2str (subs2str subs, spair2str (id, thm |> Thm.prop_of |> Rule.term2str)))
walther@59741
   220
  | Rewrite (id, thm) => "Rewrite " ^ spair2str (id, thm |> Thm.prop_of |> Rule.term2str)
walther@59741
   221
  | Rewrite_Asm (id, thm) => "Rewrite_Asm " ^ spair2str (id, thm |> Thm.prop_of |> Rule.term2str)
walther@59741
   222
  | Rewrite_Set_Inst (subs, rls) => 
walther@59741
   223
    "Rewrite_Set_Inst " ^ pair2str (subs2str subs, quote rls)
walther@59741
   224
  | Rewrite_Set rls         => "Rewrite_Set " ^ quote rls
walther@59741
   225
  | Detail_Set rls          => "Detail_Set " ^ quote rls
walther@59741
   226
  | Detail_Set_Inst (subs, rls) =>  "Detail_Set_Inst " ^ pair2str (subs2str subs, quote rls)
walther@59741
   227
  | End_Detail              => "End_Detail"
walther@59741
   228
  | Derive rls'             => "Derive " ^ rls' 
walther@59741
   229
  | Calculate op_           => "Calculate " ^ op_ 
walther@59741
   230
  | Substitute sube         => "Substitute " ^ Selem.sube2str sube	     
walther@59741
   231
  | Apply_Assumption ct's   => "Apply_Assumption " ^ strs2str ct's
walther@59741
   232
walther@59741
   233
  | Take cterm'             => "Take " ^ quote cterm'
walther@59741
   234
  | Take_Inst cterm'        => "Take_Inst " ^ quote cterm'
walther@59741
   235
  | Subproblem (domID, pblID) => "Subproblem " ^ pair2str (domID, strs2str pblID)
walther@59741
   236
  | End_Subproblem          => "End_Subproblem"
walther@59741
   237
  | CAScmd cterm'           => "CAScmd " ^ quote cterm'
walther@59741
   238
walther@59741
   239
  | Check_elementwise cterm'=> "Check_elementwise " ^ quote cterm'
walther@59741
   240
  | Or_to_List              => "Or_to_List "
walther@59741
   241
  | Collect_Trues           => "Collect_Trues"
walther@59741
   242
walther@59741
   243
  | Empty_Tac               => "Empty_Tac"
walther@59741
   244
  | Tac string              => "Tac " ^ string
walther@59741
   245
  | End_Proof'              => "input End_Proof'"
walther@59741
   246
  | _                       => "tac2str not impl. for ?!";
walther@59741
   247
walther@59741
   248
fun is_empty_tac input = case input of Empty_Tac => true | _ => false
wneuper@59302
   249
wneuper@59302
   250
fun eq_tac (Rewrite (id1, _), Rewrite (id2, _)) = id1 = id2
wneuper@59302
   251
  | eq_tac (Rewrite_Inst (_, (id1, _)), Rewrite_Inst (_, (id2, _))) = id1 = id2
wneuper@59302
   252
  | eq_tac (Rewrite_Set id1, Rewrite_Set id2) = id1 = id2
wneuper@59302
   253
  | eq_tac (Rewrite_Set_Inst (_, id1), Rewrite_Set_Inst (_, id2)) = id1 = id2
wneuper@59302
   254
  | eq_tac (Calculate id1, Calculate id2) = id1 = id2
wneuper@59302
   255
  | eq_tac _ = false
wneuper@59302
   256
wneuper@59302
   257
fun is_rewset (Rewrite_Set_Inst _) = true
wneuper@59302
   258
  | is_rewset (Rewrite_Set _) = true 
wneuper@59302
   259
  | is_rewset _ = false;
wneuper@59302
   260
fun is_rewtac (Rewrite _) = true
wneuper@59302
   261
  | is_rewtac (Rewrite_Inst _) = true
wneuper@59302
   262
  | is_rewtac (Rewrite_Asm _) = true
wneuper@59571
   263
  | is_rewtac input = is_rewset input;
wneuper@59302
   264
wneuper@59302
   265
fun tac2IDstr ma = case ma of
wneuper@59302
   266
    Model_Problem => "Model_Problem"
wneuper@59302
   267
  | Refine_Tacitly _ => "Refine_Tacitly"
wneuper@59302
   268
  | Refine_Problem _ => "Refine_Problem"
wneuper@59302
   269
  | Add_Given _ => "Add_Given"
wneuper@59302
   270
  | Del_Given _ => "Del_Given"
wneuper@59302
   271
  | Add_Find _ => "Add_Find"
wneuper@59302
   272
  | Del_Find _ => "Del_Find"
wneuper@59302
   273
  | Add_Relation _ => "Add_Relation"
wneuper@59302
   274
  | Del_Relation _ => "Del_Relation"
wneuper@59302
   275
wneuper@59302
   276
  | Specify_Theory _ => "Specify_Theory"
wneuper@59302
   277
  | Specify_Problem _ => "Specify_Problem"
wneuper@59302
   278
  | Specify_Method _ => "Specify_Method"
wneuper@59302
   279
  | Apply_Method _ => "Apply_Method"
wneuper@59302
   280
  | Check_Postcond _ => "Check_Postcond"
wneuper@59302
   281
  | Free_Solve => "Free_Solve"
wneuper@59302
   282
wneuper@59302
   283
  | Rewrite_Inst _ => "Rewrite_Inst"
wneuper@59302
   284
  | Rewrite _ => "Rewrite"
wneuper@59302
   285
  | Rewrite_Asm _ => "Rewrite_Asm"
wneuper@59302
   286
  | Rewrite_Set_Inst _ => "Rewrite_Set_Inst"
wneuper@59302
   287
  | Rewrite_Set _ => "Rewrite_Set"
wneuper@59302
   288
  | Detail_Set _ => "Detail_Set"
wneuper@59302
   289
  | Detail_Set_Inst _ => "Detail_Set_Inst"
wneuper@59302
   290
  | Derive _ => "Derive "
wneuper@59302
   291
  | Calculate _ => "Calculate "
wneuper@59302
   292
  | Substitute _ => "Substitute" 
wneuper@59302
   293
  | Apply_Assumption _ => "Apply_Assumption"
wneuper@59302
   294
wneuper@59302
   295
  | Take _ => "Take"
wneuper@59302
   296
  | Take_Inst _ => "Take_Inst"
wneuper@59302
   297
  | Subproblem _ => "Subproblem"
wneuper@59302
   298
  | End_Subproblem => "End_Subproblem"
wneuper@59302
   299
  | CAScmd _ => "CAScmd"
wneuper@59302
   300
wneuper@59302
   301
  | Check_elementwise _ => "Check_elementwise"
wneuper@59302
   302
  | Or_to_List => "Or_to_List "
wneuper@59302
   303
  | Collect_Trues => "Collect_Trues"
wneuper@59302
   304
wneuper@59302
   305
  | Empty_Tac => "Empty_Tac"
wneuper@59302
   306
  | Tac _ => "Tac "
wneuper@59302
   307
  | End_Proof' => "End_Proof'"
wneuper@59302
   308
  | _ => "tac2str not impl. for ?!";
wneuper@59302
   309
wneuper@59302
   310
fun rls_of (Rewrite_Set_Inst (_, rls)) = rls
wneuper@59302
   311
  | rls_of (Rewrite_Set rls) = rls
wneuper@59571
   312
  | rls_of input = error ("rls_of: called with input \"" ^ tac2IDstr input ^ "\"");
wneuper@59302
   313
walther@59773
   314
fun rule2tac thy _ (Rule.Num_Calc (opID, _)) = Calculate (assoc_calc thy opID)
wneuper@59416
   315
  | rule2tac _ [] (Rule.Thm thm'') = Rewrite thm''
wneuper@59416
   316
  | rule2tac _ subst (Rule.Thm thm'') = 
wneuper@59302
   317
    Rewrite_Inst (Selem.subst2subs subst, thm'')
wneuper@59416
   318
  | rule2tac _ [] (Rule.Rls_ rls) = Rewrite_Set (Rule.id_rls rls)
wneuper@59416
   319
  | rule2tac _ subst (Rule.Rls_ rls) = 
wneuper@59416
   320
    Rewrite_Set_Inst (Selem.subst2subs subst, (Rule.id_rls rls))
wneuper@59302
   321
  | rule2tac _ _ rule = 
wneuper@59416
   322
    error ("rule2tac: called with \"" ^ Rule.rule2str rule ^ "\"");
wneuper@59302
   323
wneuper@59571
   324
(* tactics for for internal use, compare "input" for user at the front-end.
wneuper@59302
   325
  tac_ contains results from check in 'fun applicable_in'.
wneuper@59302
   326
  This is useful for costly results, e.g. from rewriting;
wneuper@59302
   327
  however, these results might be changed by Scripts like
wneuper@59499
   328
      "      eq = (Rewrite_Set ''ansatz_rls'' False) eql;" ^
wneuper@59302
   329
      "      eq = (Rewrite_Set equival_trans False) eq;" ^
wneuper@59302
   330
  TODO.WN120106 ANALOGOUSLY TO Substitute':
wneuper@59302
   331
  So tac_ contains the term t the result was calculated from
wneuper@59302
   332
  in order to compare t with t' possibly changed by "Expr "
wneuper@59302
   333
  and re-calculate result if t<>t'
wneuper@59302
   334
  TODO.WN161219: replace *every* cterm' by term
wneuper@59302
   335
*)
walther@59741
   336
  datatype T =
walther@59741
   337
    Add_Find' of Rule.cterm' * Model.itm list | Add_Given' of Rule.cterm' * Model.itm list 
walther@59741
   338
  | Add_Relation' of Rule.cterm' * Model.itm list
walther@59741
   339
  | Apply_Assumption' of term list * term
walther@59741
   340
  | Apply_Method' of Celem.metID * term option * Istate_Def.T * Proof.context
walther@59741
   341
  (*/--- TODO: re-design ? -----------------------------------------------------------------\*)
walther@59741
   342
  | Begin_Sequ' | Begin_Trans' of term
walther@59741
   343
  | Split_And' of term | Split_Or' of term | Split_Intersect' of term
walther@59741
   344
  | Conclude_And' of term | Conclude_Or' of term | Collect_Trues' of term
walther@59741
   345
  | End_Sequ' | End_Trans' of Selem.result
walther@59741
   346
  | End_Ruleset' of term | End_Subproblem' of term | End_Intersect' of term | End_Proof''
walther@59741
   347
  (*\--- TODO: re-design ? -----------------------------------------------------------------/*)
walther@59741
   348
  | CAScmd' of term
walther@59741
   349
  | Calculate' of Rule.theory' * string * term * (term * Celem.thm')
walther@59741
   350
  | Check_Postcond' of Celem.pblID *
walther@59741
   351
    Selem.result (* returnvalue of script in solve *)
walther@59741
   352
  | Check_elementwise' of (*special case:*)
walther@59741
   353
    term *       (* (1) the current formula: [x=1,x=...]     *)
walther@59741
   354
    string *     (* (2) the pred from Check_elementwise      *)
walther@59741
   355
    Selem.result (* (3) composed from (1) and (2): {x. pred} *)
walther@59741
   356
  | Del_Find' of Rule.cterm' | Del_Given' of Rule.cterm' | Del_Relation' of Rule.cterm'
wneuper@59302
   357
walther@59741
   358
  | Derive' of Rule.rls
walther@59741
   359
  | Detail_Set' of Rule.theory' * bool * Rule.rls * term * Selem.result
walther@59741
   360
  | Detail_Set_Inst' of Rule.theory' * bool * Rule.subst * Rule.rls * term * Selem.result
walther@59741
   361
  | End_Detail' of Selem.result
walther@59741
   362
walther@59741
   363
  | Empty_Tac_
walther@59741
   364
  | Free_Solve'
walther@59741
   365
walther@59741
   366
  | Init_Proof' of Rule.cterm' list * Celem.spec
walther@59741
   367
  | Model_Problem' of Celem.pblID * 
walther@59741
   368
    Model.itm list *  (* the 'untouched' pbl        *)
walther@59741
   369
    Model.itm list    (* the casually completed met *)
walther@59741
   370
  | Or_to_List' of term * term
walther@59741
   371
  | Refine_Problem' of Celem.pblID * (Model.itm list * (bool * term) list)
walther@59741
   372
  | Refine_Tacitly' of
walther@59741
   373
    Celem.pblID *     (* input*)
walther@59741
   374
    Celem.pblID *     (* the refined from applicable_in                                       *)
walther@59741
   375
    Rule.domID *     (* from new pbt?! filled in specify                                     *)
walther@59741
   376
    Celem.metID *     (* from new pbt?! filled in specify                                     *)
walther@59741
   377
    Model.itm list    (* drop ! 9.03: remains [] for Model_Problem recognizing its activation *)
walther@59741
   378
  | Rewrite' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Celem.thm'' * term * Selem.result
walther@59741
   379
  | Rewrite_Asm' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Celem.thm'' * term * Selem.result
walther@59741
   380
  | Rewrite_Inst' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Rule.subst * Celem.thm'' * term * Selem.result
walther@59741
   381
  | Rewrite_Set' of Rule.theory' * bool * Rule.rls * term * Selem.result
walther@59741
   382
  | Rewrite_Set_Inst' of Rule.theory' * bool * Rule.subst * Rule.rls * term * Selem.result
walther@59741
   383
walther@59741
   384
  | Specify_Method' of Celem.metID * Model.ori list * Model.itm list
walther@59741
   385
  | Specify_Problem' of Celem.pblID * 
walther@59741
   386
    (bool *                  (* matches	                                  *)
walther@59741
   387
      (Model.itm list *      (* ppc	                                      *)
walther@59741
   388
        (bool * term) list)) (* preconditions                             *)
walther@59741
   389
  | Specify_Theory' of Rule.domID
walther@59741
   390
  | Subproblem' of
walther@59741
   391
    Celem.spec * 
walther@59741
   392
		(Model.ori list) *       (* filled in associate Subproblem'           *)
walther@59741
   393
		term *                   (* filled -"-, headline of calc-head         *)
walther@59741
   394
		Selem.fmz_ *             
walther@59741
   395
    Proof.context *          (* DEPRECATED shifted into loc for all ppobj *)
walther@59741
   396
		term                     (* Subproblem (thyID, pbl) OR cascmd         *)  
walther@59741
   397
  | Substitute' of           
walther@59741
   398
    Rule.rew_ord_ *          (* for re-calculation                        *)
walther@59741
   399
    Rule.rls *               (* for re-calculation                        *)
walther@59741
   400
    Selem.subte *            (* the 'substitution': terms of type bool    *)
walther@59741
   401
    term *                   (* to be substituted into                    *)
walther@59741
   402
    term                     (* resulting from the substitution           *)
walther@59741
   403
  | Tac_ of theory * string * string * string
walther@59741
   404
  | Take' of term | Take_Inst' of term
walther@59741
   405
walther@59741
   406
fun string_of ma = case ma of
walther@59741
   407
    Init_Proof' (ppc, spec)  => "Init_Proof' " ^ pair2str (strs2str ppc, Celem.spec2str spec)
walther@59741
   408
  | Model_Problem' (pblID, _, _) => "Model_Problem' " ^ strs2str pblID
walther@59741
   409
  | Refine_Tacitly'(p, prefin, domID, metID, _) => "Refine_Tacitly' (" ^ strs2str p ^ ", " ^
walther@59741
   410
    strs2str prefin ^ ", " ^ domID ^ ", " ^ strs2str metID ^ ", pbl-itms)"
walther@59741
   411
  | Refine_Problem' _ => "Refine_Problem' (" ^ (*matchs2str ms*)"..." ^ ")"
walther@59741
   412
  | Add_Given' _ => "Add_Given' "(*^cterm'*)
walther@59741
   413
  | Del_Given' _ => "Del_Given' "(*^cterm'*)
walther@59741
   414
  | Add_Find' _ => "Add_Find' "(*^cterm'*)
walther@59741
   415
  | Del_Find' _ => "Del_Find' "(*^cterm'*)
walther@59741
   416
  | Add_Relation' _ => "Add_Relation' "(*^cterm'*)
walther@59741
   417
  | Del_Relation' _ => "Del_Relation' "(*^cterm'*)
walther@59741
   418
walther@59741
   419
  | Specify_Theory' domID => "Specify_Theory' " ^ quote domID
walther@59741
   420
  | Specify_Problem' (pI, (ok, _)) =>  "Specify_Problem' " ^ 
walther@59741
   421
    spair2str (strs2str pI, spair2str (bool2str ok, spair2str ("itms2str_ itms", "items2str pre")))
walther@59741
   422
  | Specify_Method' (pI, oris, _) => "Specify_Method' (" ^ 
walther@59741
   423
    Celem.metID2str pI ^ ", " ^ Model.oris2str oris ^ ", )"
walther@59741
   424
walther@59741
   425
  | Apply_Method' (metID, _, _, _) => "Apply_Method' " ^ strs2str metID
walther@59741
   426
  | Check_Postcond' (pblID, (scval, asm)) => "Check_Postcond' " ^
walther@59741
   427
      (spair2str (strs2str pblID, spair2str (Rule.term2str scval, Rule.terms2str asm)))
walther@59741
   428
walther@59741
   429
  | Free_Solve' => "Free_Solve'"
walther@59741
   430
walther@59741
   431
  | Rewrite_Inst' (*subs,thm'*) _ => "Rewrite_Inst' "(*^(pair2str (subs2str subs, spair2str thm'))*)
walther@59741
   432
  | Rewrite' _(*thm'*) => "Rewrite' "(*^(spair2str thm')*)
walther@59741
   433
  | Rewrite_Asm' _(*thm'*) => "Rewrite_Asm' "(*^(spair2str thm')*)
walther@59741
   434
  | Rewrite_Set_Inst' _(*subs,thm'*) => "Rewrite_Set_Inst' "(*^(pair2str (subs2str subs, quote rls))*)
walther@59741
   435
  | Rewrite_Set' (thy', pasm, rls', f, (f', asm)) => "Rewrite_Set' (" ^ thy' ^ "," ^ bool2str pasm ^
walther@59741
   436
    "," ^ Rule.id_rls rls' ^ "," ^ Rule.term2str f ^ ",(" ^ Rule.term2str f' ^ "," ^ Rule.terms2str asm ^ "))"
walther@59741
   437
  | End_Detail' _ => "End_Detail' xxx"
walther@59741
   438
  | Detail_Set' _ => "Detail_Set' xxx"
walther@59741
   439
  | Detail_Set_Inst' _ => "Detail_Set_Inst' xxx"
walther@59741
   440
walther@59741
   441
  | Derive' rls => "Derive' " ^ Rule.id_rls rls
walther@59741
   442
  | Calculate'  _ => "Calculate' "
walther@59741
   443
  | Substitute' _ => "Substitute' "(*^(subs2str subs)*)    
walther@59741
   444
  | Apply_Assumption' _(* ct's*) => "Apply_Assumption' "(*^(strs2str ct's)*)
walther@59741
   445
walther@59741
   446
  | Take' _(*cterm'*) => "Take' "(*^(quote cterm'	)*)
walther@59741
   447
  | Take_Inst' _(*cterm'*) => "Take_Inst' "(*^(quote cterm' )*)
walther@59741
   448
  | Subproblem' _(*(spec, oris, _, _, _, pbl_form)*) => 
walther@59741
   449
    "Subproblem' "(*^(pair2str (domID, strs2str ,))*)
walther@59741
   450
  | End_Subproblem' _ => "End_Subproblem'"
walther@59741
   451
  | CAScmd' _(*cterm'*) => "CAScmd' "(*^(quote cterm')*)
walther@59741
   452
walther@59741
   453
  | Empty_Tac_ => "Empty_Tac_"
walther@59741
   454
  | Tac_ (_, form, id, result) => "Tac_ (thy," ^ form ^ "," ^ id ^ "," ^ result ^ ")"
walther@59741
   455
  | _  => "string_of not impl. for arg";
wneuper@59302
   456
walther@59704
   457
fun input_from_T (Refine_Tacitly' (pI, _, _, _, _)) = Refine_Tacitly pI
walther@59704
   458
  | input_from_T (Model_Problem' (_, _, _)) = Model_Problem
walther@59704
   459
  | input_from_T (Add_Given' (t, _)) = Add_Given t
walther@59704
   460
  | input_from_T (Add_Find' (t, _)) = Add_Find t
walther@59704
   461
  | input_from_T (Add_Relation' (t, _)) = Add_Relation t
walther@59704
   462
 
walther@59704
   463
  | input_from_T (Specify_Theory' dI) = Specify_Theory dI
walther@59704
   464
  | input_from_T (Specify_Problem' (dI, _)) = Specify_Problem dI
walther@59704
   465
  | input_from_T (Specify_Method' (dI, _, _)) = Specify_Method dI
walther@59704
   466
  
walther@59704
   467
  | input_from_T (Rewrite' (_, _, _, _, thm, _, _)) = Rewrite thm
walther@59704
   468
  | input_from_T (Rewrite_Inst' (_, _, _, _, sub, thm, _, _)) = Rewrite_Inst (Selem.subst2subs sub, thm)
walther@59704
   469
walther@59704
   470
  | input_from_T (Rewrite_Set' (_, _, rls, _, _)) = Rewrite_Set (Rule.id_rls rls)
walther@59704
   471
  | input_from_T (Detail_Set' (_, _, rls, _, _)) = Detail_Set (Rule.id_rls rls)
walther@59704
   472
walther@59704
   473
  | input_from_T (Rewrite_Set_Inst' (_, _, sub, rls, _, _)) = 
walther@59704
   474
    Rewrite_Set_Inst (Selem.subst2subs sub, Rule.id_rls rls)
walther@59704
   475
  | input_from_T (Detail_Set_Inst' (_, _, sub, rls, _, _)) = 
walther@59704
   476
    Detail_Set_Inst (Selem.subst2subs sub, Rule.id_rls rls)
walther@59704
   477
walther@59704
   478
  | input_from_T (Calculate' (_, op_, _, _)) = Calculate (op_)
walther@59704
   479
  | input_from_T (Check_elementwise' (_, pred, _)) = Check_elementwise pred
walther@59704
   480
walther@59704
   481
  | input_from_T (Or_to_List' _) = Or_to_List
walther@59704
   482
  | input_from_T (Take' term) = Take (Rule.term2str term)
walther@59704
   483
  | input_from_T (Substitute' (_, _, subte, _, _)) = Substitute (Selem.subte2sube subte) 
walther@59704
   484
  | input_from_T (Tac_ (_, _, id, _)) = Tac id
walther@59704
   485
walther@59704
   486
  | input_from_T (Subproblem' ((domID, pblID, _), _, _, _,_ ,_)) = Subproblem (domID, pblID)
walther@59704
   487
  | input_from_T (Check_Postcond' (pblID, _)) = Check_Postcond pblID
walther@59704
   488
  | input_from_T Empty_Tac_ = Empty_Tac
walther@59728
   489
  | input_from_T m = error (": not impl. for "^(string_of m));
walther@59704
   490
walther@59728
   491
fun res (Rewrite_Inst' (_ , _, _, _, _, _, _, res)) = res
walther@59728
   492
  | res (Rewrite' (_, _, _, _, _, _, res)) = res
walther@59728
   493
  | res (Rewrite_Set_Inst' (_, _, _, _, _, res)) = res
walther@59728
   494
  | res (Rewrite_Set' (_, _, _, _, res)) = res
walther@59728
   495
  | res (Calculate' (_, _, _, (t, _))) = (t, [])
walther@59728
   496
  | res (Check_elementwise' (_, _, res)) = res
walther@59728
   497
  | res (Subproblem' (_, _, _, _, _, t)) = (t, [])
walther@59728
   498
  | res (Take' t) = (t, [])
walther@59728
   499
  | res (Substitute' (_, _, _, _, t)) = (t, [])
walther@59728
   500
  | res (Or_to_List' (_,  t)) = (t, [])
walther@59728
   501
  | res m = raise ERROR ("result: not impl.for " ^ string_of m)
walther@59728
   502
walther@59728
   503
(*fun result m = (fst o res) m; TODO*)
walther@59728
   504
fun result tac = (fst o res) tac;
walther@59728
   505
fun creates_assms tac = (snd o res) tac;
walther@59728
   506
walther@59728
   507
fun insert_assumptions tac ctxt  = ContextC.insert_assumptions (creates_assms tac) ctxt
walther@59728
   508
walther@59749
   509
fun for_specify (Init_Proof _) = true
walther@59749
   510
  | for_specify Model_Problem  = true
walther@59749
   511
  | for_specify (Refine_Tacitly _) = true
walther@59749
   512
  | for_specify (Refine_Problem _) = true
walther@59749
   513
  | for_specify (Add_Given _) = true
walther@59749
   514
  | for_specify (Del_Given _) = true
walther@59749
   515
  | for_specify (Add_Find _) = true
walther@59749
   516
  | for_specify (Del_Find _) = true
walther@59749
   517
  | for_specify (Add_Relation _) = true
walther@59749
   518
  | for_specify (Del_Relation _) = true
walther@59749
   519
  | for_specify (Specify_Theory _) = true
walther@59749
   520
  | for_specify (Specify_Problem _) = true
walther@59749
   521
  | for_specify (Specify_Method _) = true
walther@59749
   522
  | for_specify _ = false
walther@59749
   523
fun for_specify' (Init_Proof' _) = true
walther@59749
   524
  | for_specify' (Model_Problem' _) = true
walther@59749
   525
  | for_specify' (Refine_Tacitly' _) = true
walther@59749
   526
  | for_specify' (Refine_Problem' _) = true
walther@59749
   527
  | for_specify' (Add_Given' _) = true
walther@59749
   528
  | for_specify' (Del_Given' _) = true
walther@59749
   529
  | for_specify' (Add_Find' _) = true
walther@59749
   530
  | for_specify' (Del_Find' _) = true
walther@59749
   531
  | for_specify' (Add_Relation' _) = true
walther@59749
   532
  | for_specify' (Del_Relation' _) = true
walther@59749
   533
  | for_specify' (Specify_Theory' _) = true
walther@59749
   534
  | for_specify' (Specify_Problem' _) = true
walther@59749
   535
  | for_specify' (Specify_Method' _) = true
walther@59749
   536
  | for_specify' _ = false
walther@59749
   537
walther@59728
   538
(**)end(**)