src/Tools/isac/Test_Code/test-code.sml
author Walther Neuper <walther.neuper@jku.at>
Tue, 12 May 2020 10:14:09 +0200
changeset 59968 5dd1d96cb467
parent 59962 6a59d252345d
child 59969 a159bcaa58fa
permissions -rw-r--r--
distribute code from old Specify/ptyps.sml
walther@59814
     1
(*  Title:      ~~/test/../Testcode/test-code.sml
walther@59814
     2
    Author:     Walther Neuper 200222
walther@59814
     3
walther@59814
     4
Code used ONLY for ~~/test/*
walther@59814
     5
*)
walther@59814
     6
walther@59814
     7
signature TEST_CODE =
walther@59814
     8
sig
walther@59814
     9
  type NEW (* TODO: refactor "fun me" with calcstate and remove *)
walther@59959
    10
  val f2str : Test_Out.mout -> TermC.as_string
walther@59959
    11
  val TESTg_form : Calc.T -> Test_Out.mout
walther@59901
    12
walther@59959
    13
  val CalcTreeTEST : Formalise.T list -> Pos.pos' * NEW * Test_Out.mout * Tactic.input * Celem.safe * Ctree.ctree
walther@59846
    14
  val me : Tactic.input -> Pos.pos' -> NEW -> Ctree.ctree ->
walther@59959
    15
    Pos.pos' * NEW * Test_Out.mout * Tactic.input * Celem.safe * Ctree.ctree
walther@59901
    16
walther@59814
    17
  val trace_ist_ctxt: Calc.T -> Tactic.input -> unit
walther@59814
    18
  val me_trace: Calc.T -> Tactic.input -> (Calc.T -> Tactic.input -> unit) ->
walther@59959
    19
    Calc.T * Tactic.input * Test_Out.mout
walther@59922
    20
walther@59922
    21
  val tac2tac_ : Ctree.ctree -> Pos.pos' -> Tactic.input -> Tactic.T
walther@59814
    22
end
walther@59814
    23
walther@59814
    24
(**)
walther@59814
    25
structure Test_Code(**): TEST_CODE(**) =
walther@59814
    26
struct
walther@59814
    27
(**)
walther@59814
    28
open Tactic
walther@59814
    29
open Ctree
walther@59814
    30
walther@59814
    31
(** test Step.by_tactic + Step.do_next **)
walther@59814
    32
walther@59814
    33
type NEW = int list; (*TODO remove*)
walther@59814
    34
walther@59814
    35
(* 15.8.03 for me with loc_specify/solve, nxt_specify/solve
walther@59814
    36
   delete as soon as TESTg_form -> _mout_ dropped           *)
walther@59814
    37
fun TESTg_form ptp =
walther@59814
    38
  let
walther@59814
    39
    val (form, _, _) = Chead.pt_extract ptp
walther@59814
    40
  in
walther@59814
    41
    case form of
walther@59959
    42
      Ctree.Form t => Test_Out.FormKF (UnparseC.term t)
walther@59814
    43
    | Ctree.ModSpec (_, p_, _, gfr, pre, _) =>
walther@59959
    44
      Test_Out.PpcKF (
walther@59959
    45
        (case p_ of Pos.Pbl => Test_Out.Problem []
walther@59959
    46
          | Pos.Met => Test_Out.Method []
walther@59962
    47
          | _ => raise ERROR "TESTg_form: uncovered case",
walther@59968
    48
 			P_Model.itms2itemppc (ThyC.get_theory"Isac_Knowledge") gfr pre))
walther@59814
    49
   end
walther@59814
    50
(* for quick test-print-out, until 'type inout' is removed *)
walther@59959
    51
fun f2str (Test_Out.FormKF cterm') = cterm'
walther@59962
    52
  | f2str _ = raise ERROR "f2str: uncovered case in fun.def.";                           
walther@59814
    53
walther@59814
    54
(* create a calc-tree; for use within sml: thus "^^^" NOT decoded to "^" etc;
walther@59814
    55
   compare "fun CalcTree" which DOES decode                        *)
walther@59814
    56
fun CalcTreeTEST [(fmz, sp)] = 
walther@59814
    57
  let
walther@59946
    58
    val ((pt, p), tacis) = Step_Specify.nxt_specify_init_calc (fmz, sp)
walther@59814
    59
	  val tac = case tacis of [] => Tactic.Empty_Tac | _ => (#1 o hd) tacis
walther@59814
    60
	  val f = TESTg_form (pt,p)
walther@59937
    61
  in (p, []:NEW, f, tac, Celem.Sundef, pt) end
walther@59962
    62
| CalcTreeTEST _ = raise ERROR "CalcTreeTEST: uncovered case"
walther@59814
    63
       
walther@59814
    64
fun me (*(Empty_Tac) p _ _ = raise ERROR ("me:  Empty_Tac at " ^ pos'2str p)
walther@59814
    65
  | me*) tac p _(*NEW remove*) pt =
walther@59814
    66
    let 
walther@59814
    67
      val (pt, p) = 
walther@59814
    68
  	    (*Step.by_tactic is here for testing by me; do_next would suffice in me*)
walther@59814
    69
  	    case Step.by_tactic tac (pt, p) of
walther@59814
    70
  		    ("ok", (_, _, ptp)) => ptp
walther@59814
    71
  	    | ("unsafe-ok", (_, _, ptp)) => ptp
walther@59814
    72
  	    | ("not-applicable",_) => (pt, p)
walther@59814
    73
  	    | ("end-of-calculation", (_, _, ptp)) => ptp
walther@59962
    74
  	    | ("failure", _) => raise ERROR "sys-raise ERROR"
walther@59962
    75
  	    | _ => raise ERROR "me: uncovered case Step.by_tactic"
walther@59814
    76
  	  val (_, ts) =
walther@59814
    77
        (*step's correct ctree is not tested in me, but in autocalc or Step.by_term*)
walther@59814
    78
  	    (case Step.do_next p ((pt, Pos.e_pos'), []) of
walther@59814
    79
  		    ("ok", (ts as (_, _, _) :: _, _, _)) => ("", ts)
walther@59814
    80
  	    | ("helpless", _) => ("helpless: cannot propose tac", [])
walther@59814
    81
  	    | ("dummy", (ts as (_, _, _) :: _, _, _)) => ("", ts) (*intermed.from specify*)
walther@59814
    82
  	    | ("end-of-calculation", (ts, _, _)) => ("", ts)
walther@59962
    83
  	    | _ => raise ERROR  "me: uncovered case do_next")
walther@59814
    84
  	  val tac = 
walther@59814
    85
        case ts of 
walther@59814
    86
          tacis as (_::_) => let val (tac, _, _) = last_elem tacis in tac end 
walther@59814
    87
  		  | _ => if p = ([], Pos.Res) then Tactic.End_Proof' else Tactic.Empty_Tac;
walther@59814
    88
    in
walther@59814
    89
      (p, [] : NEW, TESTg_form (pt, p) (* form output comes from Step.by_tactic *), 
walther@59937
    90
  	    tac, Celem.Sundef, pt)
walther@59814
    91
    end
walther@59814
    92
walther@59814
    93
walther@59814
    94
(** traces for me_trace **)
walther@59814
    95
walther@59814
    96
fun (*quiet (Model_Problem) = true
walther@59814
    97
  |*) quiet (Add_Given _) = true
walther@59814
    98
  | quiet (Add_Find _) = true
walther@59814
    99
  | quiet (Add_Relation _) = true
walther@59814
   100
  | quiet (Specify_Method _) = true
walther@59814
   101
  | quiet (Specify_Problem _) = true
walther@59814
   102
  | quiet (Specify_Theory _) = true
walther@59814
   103
  | quiet _ = false
walther@59814
   104
walther@59814
   105
fun mk_string (ist, ctxt) =
walther@59844
   106
  ("(" ^ Istate.string_of' ist ^ ",\n" 
walther@59868
   107
  ^ "... ctxt:    " ^ (ctxt |> ContextC.get_assumptions |> UnparseC.terms) ^ ")")
walther@59814
   108
walther@59814
   109
fun trace_ist_ctxt (EmptyPtree , ([], Pos.Und)) _ = ()
walther@59814
   110
  | trace_ist_ctxt (pt, (p, _)) tac =
walther@59814
   111
  if quiet tac
walther@59814
   112
  then ()
walther@59814
   113
  else
walther@59814
   114
    case get_obj g_loc pt p of
walther@59814
   115
      (NONE, NONE) =>
walther@59814
   116
        writeln   "Frm, Res: (NONE, NONE)"
walther@59814
   117
    | (SOME ist_ctxt, NONE) =>
walther@59814
   118
        (writeln ("Frm ..... (SOME " ^ mk_string ist_ctxt ^ " ,");
walther@59814
   119
         writeln ("Res .....  NONE)"))
walther@59814
   120
    | (NONE, SOME ist_ctxt) =>
walther@59814
   121
        (writeln ("Frm .....  (NONE,");
walther@59814
   122
         writeln ("Res .....  SOME " ^ mk_string ist_ctxt ^ " )"))
walther@59814
   123
    | (SOME ic_frm, SOME ic_res) =>
walther@59814
   124
        (writeln ("Frm ..... (SOME " ^ mk_string ic_frm ^ " ,");
walther@59814
   125
         writeln ("Res .....  SOME " ^ mk_string ic_res ^ " )"))
walther@59814
   126
walther@59814
   127
walther@59814
   128
(** test Step.by_tactic + Step.do_next with tracing **)
walther@59814
   129
walther@59814
   130
fun me_trace (*(Empty_Tac) p _ _ = raise ERROR ("me:  Empty_Tac at " ^ pos'2str p)
walther@59814
   131
  | me*) (pt, p) tac trace =
walther@59814
   132
    let
walther@59814
   133
      val _ = if quiet tac then () else
walther@59846
   134
        writeln ("========= " ^ Pos.pos'2str p ^ "========= Step.by_tactic: " ^ Tactic.input_to_string tac ^ " ==================================");
walther@59814
   135
      val (pt', p') = 
walther@59814
   136
  	    (*Step.by_tactic is here for testing by me; do_next would suffice for doing steps*)
walther@59814
   137
  	    case Step.by_tactic tac (pt, p) of
walther@59814
   138
  		    ("ok", (_, _, ptp)) => ptp
walther@59814
   139
  	    | ("unsafe-ok", (_, _, ptp)) => ptp
walther@59814
   140
  	    | ("not-applicable",_) => (pt, p)
walther@59814
   141
  	    | ("end-of-calculation", (_, _, ptp)) => ptp
walther@59962
   142
  	    | ("failure", _) => raise ERROR "sys-raise ERROR"
walther@59962
   143
  	    | _ => raise ERROR "me: uncovered case Step.by_tactic"
walther@59814
   144
      val _ = trace (pt', p') tac
walther@59814
   145
  	  val (_, ts, (pt'', p'')) =
walther@59814
   146
        (*step's correct ctree is not tested in me, but in autocalc or Step.by_term*)
walther@59814
   147
  	    (case Step.do_next p' ((pt', Pos.e_pos'), []) of
walther@59814
   148
  		    ("ok", (ts as [(_, _, _)(*, _, _, ...*)], _, (pt'', p''))) => ("", ts, (pt'', p''))
walther@59814
   149
  	    | ("helpless", _) => ("helpless: cannot propose tac", [], Ctree.e_state)
walther@59814
   150
  	    | ("dummy", (ts as (_, _, _) :: _, _, _)) => ("", ts, Ctree.e_state) (*intermed.from specify*)
walther@59814
   151
  	    | ("end-of-calculation", (ts, _, _)) => ("", ts, Ctree.e_state)
walther@59962
   152
  	    | _ => raise ERROR  "me: uncovered case do_next")
walther@59814
   153
  	  val tac'' = 
walther@59814
   154
        case ts of 
walther@59814
   155
          tacis as (_::_) => let val (tac, _, _) = last_elem tacis in tac end 
walther@59814
   156
  		  | _ => if p' = ([], Pos.Res) then Tactic.End_Proof' else Tactic.Empty_Tac;
walther@59814
   157
      val _ = if quiet tac then () else
walther@59846
   158
        writeln ("--------- " ^ Pos.pos'2str p' ^ "--------- Step.do_next \<rightarrow> " ^ Tactic.input_to_string tac'' ^ "----------------------------------");
walther@59814
   159
      val _ = trace (pt'', p'') tac
walther@59814
   160
    in
walther@59814
   161
      ((pt', p'), tac'', TESTg_form (pt', p') (* form output comes from Step.by_tactic *))
walther@59814
   162
    end
walther@59814
   163
walther@59922
   164
fun tac2tac_ pt p m = 
walther@59922
   165
  case Step.check m (pt, p) of
walther@59922
   166
	  Applicable.Yes m' => m' 
walther@59962
   167
  | Applicable.No _ => raise ERROR ("tac2mstp': fails with" ^ Tactic.input_to_string m);
walther@59922
   168
walther@59814
   169
(**)end(**)