src/Tools/isac/TODO.thy
author Walther Neuper <walther.neuper@jku.at>
Sat, 02 May 2020 16:55:14 +0200
changeset 59930 c68c6868f636
parent 59927 877d6bc38715
child 59932 87336f3b021f
permissions -rw-r--r--
simplify Specify_Step.chek
     1 (* Title:  todo's for isac core
     2    Author: Walther Neuper 111013
     3    (c) copyright due to lincense terms.
     4 *)
     5 theory TODO
     6 imports "~~/src/Doc/Prog_Prove/LaTeXsugar"
     7 begin
     8 
     9 text \<open>
    10 Legend: here + code since 200120
    11   \<open>(*DOC\<close> identifies stuff dedicated for isac/Doc/Lucas_Interpreter
    12   \<open>(*?!?\<close> identifies a design question
    13 
    14 Distillation of "rounds of reforms":
    15   \<open>TODOs from current changesets\<close> \<rightarrow> \<open>Postponed from current changeset\<close> \<rightarrow>
    16   (*to be removed..*) \<rightarrow> \<open>Separated tasks\<close> (*.. to be removed*)
    17   \<rightarrow> subsection of \<open>Major reforms\<close>
    18 \<close>
    19 
    20 section \<open>TODOs from current changesets\<close>
    21 text\<open>
    22   Shift more complicated issues from  \<open>Current changeset\<close> to \<open>Postponed from current changeset\<close>
    23 \<close>
    24 subsection \<open>Current changeset\<close>
    25 text \<open>
    26 (*/------- to  -------\*)
    27 (*\------- to  -------/*)
    28   \begin{itemize}
    29   \item xxx
    30   \item rm warnings from solve-step.sml
    31   \item xxx
    32   \item rename/relocate: Selem.result -> Calc.result ?OR? (NEW..)Formula.result
    33   \item xxx
    34   \item replace src/ Erls by Rule_Set.Empty
    35   \item xxx
    36   \item rename ptyps.sml -> specify-etc.sml
    37         rename Specify -> Specify_Etc
    38         rename SpecifyNEW -> Specify
    39   \item xxx
    40   \item specific_from_prog in..end: replace o by |> (Test_Isac or Test_Some!)
    41   \item xxx
    42   \item cleanup ThmC in MathEngBasic
    43   \item xxx
    44   \item xxx
    45   \item xxx
    46   \item xxx
    47   \item xxx
    48   \item xxx
    49   \item xxx
    50   \item xxx
    51   \end{itemize}
    52 \<close>
    53 subsection \<open>Postponed from current changeset\<close>
    54 text \<open>
    55   \begin{itemize}
    56   \item xxx
    57   \item Solve_Check: postponed parsing input to _ option
    58   \item xxx
    59   \item ? "fetch-tactics.sml" from Mathengine -> BridgeLibisabelle ?
    60   \item xxx
    61   \item ? unify struct.Step and struct.Solve in MathEngine ?
    62   \item xxx
    63   \item use "Eval_Def" for renaming identifiers
    64   \item xxx
    65   \item why does Test_Build_Thydata.thy depend on ProgLang and not on CalcElements ?
    66   \item xxx
    67   \item xxx
    68   \begin{itemize}
    69   \item LI.do_next (*TODO RM..*) ???
    70   \item generate.sml: RM datatype edit TOGETHER WITH datatype inout
    71   \item TermC.list2isalist: typ -> term list -> term  .. should NOT requires typ
    72   \item get_ctxt_LI should replace get_ctxt
    73   \item ALL CODE: rename spec(ification) --> know(ledge), in Specification: Relation -> Knowledge
    74   \item rename   Base_Tool.thy  <---         Base_Tools
    75   \item adopt naming conventions in Knowledge: EqSystem --> Equation_System, etc
    76   \item rename field scr in meth
    77   \item DEL double code: nxt_specify_init_calc IN specify.sml + step-specify.sml
    78   \item xxx
    79   \item xxx
    80   \item xxx
    81   \item xxx
    82   \item xxx
    83   \item xxx
    84   \item xxx
    85   \item clarify Tactic.Subproblem (domID, pblID) as term in Pstate {act_arg, ...}
    86      there it is Free ("Subproblem", "char list \<times> ..
    87      instead of  Const (|???.Subproblem", "char list \<times> ..
    88      AND THE STRING REPRESENTATION IS STRANGE: 
    89        Subproblem (''Test'',
    90         ??.\ <^const> String.char.Char ''LINEAR'' ''univariate'' ''equation''
    91          ''test'')
    92      ML \<open>
    93      \<close> ML \<open>
    94      term2str; (*defined by..*)
    95      fun term_to_string''' thy t =
    96        let
    97          val ctxt' = Config.put show_markup false (Proof_Context.init_global thy)
    98        in Print_Mode.setmp [] (Syntax.string_of_term ctxt') t end;
    99      \<close> ML \<open>
   100      val t = @{term "aaa + bbb"}
   101      val t = @{term "Subproblem (''Test'', [''LINEAR'', ''univariate'', ''equation''])"};
   102      \<close> ML \<open>
   103      val sss = Print_Mode.setmp [] (Syntax.string_of_term @{context}) t
   104      \<close> ML \<open>
   105      writeln sss (*.. here perfect: Subproblem (''Test'', [''LINEAR'', ''univariate'', ''equation'']) *)
   106      \<close> ML \<open>
   107      \<close>
   108   \item xxx
   109   \item xxx
   110   \item cleanup fun me:
   111     fun me (*(_, Empty_Tac) p _ _ = raise ERROR ("me:  Empty_Tac at " ^ pos'2str p)
   112       | me*) (_, tac) p _(*NEW remove*) pt =
   113     + -------------------------^^^^^^
   114     # see test-code.sml fun me_trace
   115       use this also for me, not only for me_ist_ctxt; del. me
   116       this requires much updating in all test/*
   117   \item xxx
   118   \item xxx
   119   \item generate, generate1: NO thy as arg.
   120         Generate.generate1 thy is redundant: is the same during pbl, thus lookup spec
   121         redesign return value (originally for output by fun me?)
   122   \item xxx
   123   \item shift tests into NEW model.sml (upd, upds_envv, ..)
   124   \item xxx
   125   \item xxx
   126   \item clarify handling of contexts ctxt ContextC
   127     \begin{itemize}
   128     \item xxx
   129     \item Specify/ works with thy | Interpret/ works with ctxt | MathEngine.step works with ?!?ctxt
   130     \item xxx
   131     \item Check_Elementwise "Assumptions": prerequisite for ^^goal
   132       rm tactic Check_elementwise "Assumptions" in a way, which keeps it for Minisubpbl
   133       rm Assumptions  :: bool  (* TODO: remove with making ^^^ idle *)
   134     \item xxx
   135     \item xxx
   136     \end{itemize}
   137   \item xxx
   138   \item xxx
   139   \item complete mstools.sml (* survey on handling contexts:
   140   \item xxx
   141   \item xxx
   142   \item xxx
   143   \item xxx
   144   \item librarys.ml --> libraryC.sml + text from termC.sml
   145   \item xxx
   146   \item xxx
   147   \item xxx
   148   \item xxx
   149   \item xxx
   150   \item xxx
   151   \item concentrate "insert_assumptions" for locate_input_tactic in "associate", ?OR? Tactic.insert_assumptions
   152                                    DONE  for find_next_step by Tactic.insert_assumptions m' ctxt 
   153     \begin{itemize}
   154     \item rm from "generate1" ("Detail_Set_Inst'", Tactic.Detail_Set' ?)
   155     \item shift from "applicable_in..Apply_Method" to ? ? ? (is ONLY use-case in appl.sml))
   156     \item ?"insert_assumptions" necessary in "init_pstate" ?+++? in "applicable_in" ?+++? "associate"
   157     \item xxx
   158     \item xxx
   159     \item DO DELETIONS AFTER analogous concentrations in find_next_step
   160     \end{itemize}
   161   \item xxx
   162   \item ? what is the difference headline <--> cascmd in
   163     Subproblem' (spec, oris, headline, fmz_, context, cascmd)
   164   \item Substitute' what does "re-calculation mean in the datatype comment?
   165   \item xxx
   166   \item inform: TermC.parse (ThyC.get_theory "Isac_Knowledge") istr --> parseNEW context istr
   167   \item xxx
   168   \item unify/clarify stac2tac_ | 
   169     \begin{itemize}
   170     \item xxx
   171     \item extract common code from associate.. stac2tac_xxx
   172     \item rename LItool.tac_from_prog -> Tactic.from_prog_tac ? Solve_Tac.from_prog_tac,
   173     \item xxx
   174     \item xxx
   175     \end{itemize}
   176   \item xxx
   177   \item unify in signature LANGUAGE_TOOLS =\\
   178     val pblterm: ThyC.id -> Problem.id -> term     vvv        vvv\\
   179     val subpbl: string -> string list -> term          unify with ^^^
   180   \item xxx
   181   \item Telem.safe is questionable: has it been replaced by Safe_Step, Not_Derivable, Helpless, etc?
   182     Note: replacement of Istate.safe by Istate.appy_ didn't care much about Telem.safe.
   183     If Telem.safe is kept, consider merge with CTbasic.ostate
   184   \item xxx
   185   \item remove find_next_step from solve Apply_Method';
   186     this enforces Pos.at_first_tactic, which should be dropped, too.
   187   \item xxx
   188   \item xxx
   189   \item xxx
   190   \end{itemize}
   191 \<close>
   192 subsection \<open>Postponed --> Major reforms\<close>
   193 text \<open>
   194   \begin{itemize}
   195   \item xxx          
   196   \item revisit bootstrap Calcelements. rule->calcelems->termC
   197     would be nice, but is hard: UnparseC.terms -> TermC.s_to_string
   198   \item xxx
   199   \item replace all Ctree.update_* with Ctree.cupdate_problem
   200   \item xxx
   201   \item rename (ist as {eval, ...}) -> (ist as {eval_rls, ...})
   202   \item xxx
   203   \item exception PROG analogous to TERM
   204   \item xxx
   205   \item sig/struc ..elems --> ..elem
   206   \item xxx          
   207   \item distille CAS-command, CAScmd, etc into a struct
   208   \item xxx          
   209   \item check location of files:
   210         test/Tools/isac/Interpret/ptyps.thy
   211         test/Tools/isac/Specify.ptyps.sml
   212   \item xxx
   213   \item check occurences of Atools in src/ test/
   214   \item Const ("Atools.pow", _) ---> Const ("Base_Tool.pow", _) 
   215   \item xxx          
   216   \item rm Float
   217   \item xxx
   218   \item Diff.thy: differentiateX --> differentiate after removal of script-constant
   219   \item Test.thy: met_test_sqrt2: deleted?!
   220   \item xxx          
   221   \item Rewrite_Ord.rew_ord' := overwritel (! Rewrite_Ord.rew_ord', (*<<<---- use Know_Store.xxx, too*)
   222   \item xxx
   223     \item automatically extrac rls from program-code 
   224       ? take ["SignalProcessing", "Z_Transform", "Inverse_sub"] as an example ?
   225   \item xxx          
   226   \item finish output of LItool.trace with Check_Postcond (useful for SubProblem)
   227   \item xxx
   228   \item replace Rule_Set.empty by Rule_Set.Empty
   229     latter is more clear, but replacing ***breaks rewriting over all examples***,
   230     e.g. see ERROR: rewrite__set_ called with 'Erls' for 'precond_rootpbl x'
   231     in Minisubplb/200-start-method-NEXT_STEP.sml:
   232      (*+* )------- in f3cac3053e7b (Rule_Set.empty just renamed, NOT deleted) we had
   233      (*+*)  prls =
   234      (*+*)    Rls {calc = [], erls = Erls, errpatts = [], id = "empty", preconds = [], rew_ord =
   235      (*+*)      ("dummy_ord", fn), rules = [], scr = Empty_Prog, srls = Erls}:
   236      (*+*).. THIS IS Rule_Set.empty, BUT IT DID not CAUSE ANY ERROR !
   237      (*+*)------- WITH Rule_Set.empty REMOVED (based on f3cac3053e7b) we had
   238      (*+*)val Empty = prls (* <---ERROR: rewrite__set_ called with 'Erls' for 'precond_rootpbl x' *)
   239      ( *+*)val ["sqroot-test", "univariate", "equation", "test"] = cpI
   240     THAT INDICATES, that much rewriting/evaluating JUST WORKED BY CHANCE?!?
   241   \item xxx          
   242   \item xxx
   243   \item xxx          
   244   \item xxx
   245   \item xxx          
   246   \item xxx
   247   \item xxx          
   248   \end{itemize}
   249 \<close>
   250 
   251 section \<open>Major reforms\<close>
   252 text \<open>
   253 \<close>
   254 subsection \<open>Exception Size raised\<close>
   255 text \<open>
   256   During update Isabelle2018 --> Isabelle2019 we noticed, that
   257   "isabelle build" uses resources more efficiently than "isabelle jedit".
   258   The former works, but the latter causes 
   259   \begin{itemize}
   260   \item "Exception- Size raised"
   261     in Build_Thydata.thy
   262   \item "exception Size raised (line 169 of "./basis/LibrarySupport.sml")"
   263     in test/../biegelinie-*.xml.
   264   \end{itemize}
   265   This has been detected after changeset (30cd47104ad7) "lucin: reorganise theories in ProgLang".
   266 
   267   Find tools to investigate the Exception, and find ways around it eventually.
   268 \<close>
   269 subsection \<open>Cleanup & review signatures wrt. implementation.pdf canonical argument order\<close>
   270 text \<open>
   271   \begin{itemize}
   272   \item there are comments in several signatures
   273   \item ML_file "~~/src/Tools/isac/Interpret/specification-elems.sml" can be (almost) deleted
   274   \item src/../Frontend/: signatures missing
   275   \item xxx
   276   \end{itemize}
   277 \<close>
   278 subsection \<open>overall structure of code\<close>
   279 text \<open>
   280   \begin{itemize}
   281   \item try to separate Isac_Knowledge from MathEngine
   282     common base: Knowledge_Author / ..??
   283   \item xxx
   284   \item  ML_file "~~/src/Tools/isac/Interpret/ctree.sml" (*shift to base in common with Interpret*)
   285   \item xxx
   286   \item xxx
   287   \item xxx
   288   \end{itemize}
   289 \<close>
   290 subsection \<open>Separate MathEngineBasic/ Specify/ Interpret/ MathEngine/\<close>
   291 text \<open>
   292   \begin{itemize}
   293   \item xxx
   294   \item xxx
   295   \item re-organise code for Interpret
   296     \begin{itemize}
   297     \item Step*: Step_Specify | Step_Solve | Step
   298       \begin{itemize}
   299       \item *.check | *.add
   300         Specify_Step.add <-- Generate.generate1
   301         Solve_Step.add   <-- Generate.generate1
   302       \item xxx
   303       \end{itemize}
   304     \item xxx
   305     \item Prog_Tac: fun get_first_argument takes both Prog_Tac + Program --- wait for separate Tactical
   306       then shift into common descendant
   307     \item xxx
   308     \end{itemize}
   309   \item xxx
   310   \item xxx
   311   \item ??????????? WHY CAN LI.by_tactic NOT BE REPLACED BY Step_Solve.by_tactic ???????????
   312   \item xxx
   313   \item xxx
   314   \end{itemize}
   315 \<close>
   316 subsection \<open>Review modelling- + specification-phase\<close>
   317 text \<open>
   318   \begin{itemize}
   319   \item xxx
   320   \item xxx
   321   \item xxx
   322   \item check match between args of partial_function and model-pattern of meth;
   323      provide error message.
   324   \item xxx
   325   \item "--- hack for funpack: generalise handling of meths which extend problem items ---"
   326     \begin{itemize}
   327     \item see several locations of hack in code
   328     \item these locations are NOT sufficient, see
   329       test/../biegelinie-3.sml --- IntegrierenUndKonstanteBestimmen2: Bsp.7.70. auto ---
   330     \item "fun associate" "match_ags ..dI" instead "..pI" breaks many tests, however,
   331       this would be according to survey Notes (3) in src/../calchead.sml.
   332     \end{itemize}
   333   \item see "failed trial to generalise handling of meths"98298342fb6d
   334   \item abstract specify + nxt_specif to common aux-funs;
   335     see e.g. "--- hack for funpack: generalise handling of meths which extend problem items ---"
   336   \item xxx
   337   \item type model = itm list ?
   338   \item review survey Notes in src/../calchead.sml: they are questionable
   339   \item review copy-named, probably two issues commingled 
   340     \begin{itemize}
   341     \item special handling of "#Find#, because it is not a formal argument of partial_function
   342     \item special naming for solutions of equation solving: x_1, x_2, ...
   343     \end{itemize}
   344   \item xxx
   345   \item structure Tactic Specify -?-> Proglang (would require Model., Selem.)
   346   \item xxx
   347   \item this has been written in one go:
   348     \begin{itemize}
   349     \item reconsidering Model.max_vt, use problem with meth ["DiffApp","max_by_calculus"]
   350     \item reconsider add_field': where is it used for what? Shift into mk_oris
   351     \item reconsider match_itms_oris: where is it used for what? max_vt ONLY???
   352     \item in Specify_Method search root-oris for items (e.g. "errorBound"), #1# in survey
   353     \item Specify_Problem, Specify_Method: check respective identifiers after re-Specify_
   354       (relevant for pre-condition)
   355     \item unify match_ags to mk_oris1..N with different args (fmz | pat list, pbl | meth
   356     \item 
   357     \end{itemize}
   358   \end{itemize}
   359 \<close>
   360 subsection \<open>taci list, type step\<close>
   361 text \<open>
   362 taci was, most likely, invented to make "fun me" more efficient by avoiding duplicate rewrite,
   363 and probably, because the Kernel interface separated setNextTactic and applyTactic.
   364 Both are no good reasons to make code more complicated.
   365 
   366 !!! taci list is used in do_next !!!
   367 
   368   \begin{itemize}
   369   \item xxx
   370   \item can lev_on_total replace lev_on ? ..Test_Isac_Short + rename lev_on_total -> lev_on
   371   \item xxx
   372   \item Step* functions should return Calc.T instead of Chead.calcstate'
   373   \item xxx
   374   \item states.sml: check, when "length tacis > 1"
   375   \item in Test_Isac.thy there is only 1 error in Interpret/inform.sml
   376   \item (*WN190713 REMOVE: "creating a new node" was never implemented for more than one node?!?
   377   \item xxx
   378   \item brute force setting all empty ([], [], ptp) works!?! but ptp causes errors -- investigate!
   379   \item xxx
   380   \end{itemize}
   381 \<close>
   382 subsection \<open>Ctree\<close>
   383 text \<open>
   384 analysis
   385 # mixture pos' .. pos in cappend_*, append_* is confusing
   386 # existpt p pt andalso Tactic.is_empty DIFFERENT IN append_*, cappend_* is confusing
   387   "exception PTREE "get_obj: pos =" ^^^^^: ^^^^ due to cut !!!
   388   NOTE: exn IN if..andalso.. IS NOT!!! DETECTED, THIS                       is confusing
   389   see test/../--- Minisubpbl/800-append-on-Frm.sml ---
   390 # ?!? "cut branches below cannot be decided here" in append_atomic
   391 # sign. of functions too different ?!?canonical arg.order ?!?
   392   \begin{itemize}
   393   \item xxx
   394   \item remove update_branch, update_*? -- make branch, etc args of append_*
   395   \item xxx
   396   \item close sig Ctree, contains cappend_* ?only? --- ?make parallel to ?Pide_Store?
   397   \item xxx
   398   \item unify args to Ctree.state (pt, p)
   399   \item  fun update_env       .. repl_env                   \<rightarrow>updatempty
   400   \item xxx
   401   \item xxx
   402   \item xxx
   403   \item xxx
   404   \end{itemize}
   405 \<close>
   406 subsection \<open>replace theory/thy by context/ctxt\<close>
   407 text \<open>
   408   \begin{itemize}
   409   \item xxx
   410   \item Specify/ works with thy | Interpret/ works with ctxt | MathEngine.step works with ?!?ctxt
   411     special case: Tactic.Refine_Problem
   412   \item xxx
   413   \item theory can be retrieved from ctxt by Proof_Context.theory_of
   414   \item xxx
   415   \item cleaup the many conversions string -- theory
   416   \item make dest_spec --> (theory, pblID, metID) ?+ common_subthy ?
   417   \item 1. Rewrite.eval_true_, then
   418     LItool.check_leaf, Rewrite.eval_prog_expr, Generate.generate1, LItool.tac_from_prog.
   419   \item fun associate
   420     let val thy = ThyC.get_theory "Isac_Knowledge";(*TODO*)
   421   \item xxx
   422   \item xxx
   423   \item in locate_input_tactic .. ?scan_dn1?; Program.is_eval_expr   .use  Term.exists_Const
   424   \item push srls into pstate
   425   \item lucas-intrpreter.locate_input_tactic: scan_to_tactic1 srls tac cstate (progr, Rule_Set.Empty)
   426                                                                                       ^^^^^^^^^^^^^^^
   427   \item xxx
   428   \end{itemize}
   429 \<close>
   430 subsection \<open>Rfuns, Begin_/End_Detail', Rrls, Istate\<close>
   431 text \<open>
   432 remove refactor Rfuns, Rule.Prog, Rule.Empty_Prog, RrlsState: this is a concept never brought to work.
   433   Clarify relation to reverse rewriting!
   434   \begin{itemize}
   435   \item separate mut.recursion program with rule and rls by deleting fild scr in rls
   436     (possible since CS 43160c1e775a
   437   ` "replace Prog. in prep_rls by Auto_Prog.gen, which generates Prog. on the fly" )
   438   \item xxx
   439   \item probably only "normal_form" seems to be needed
   440   \item deleted Rfuns in NEW "locate_input_tactic": no active test for "locate_rule"
   441     but that seems desirable
   442   \item ?how is the relation to reverse-rewriting ???
   443   \item "Rfuns" markers in test/../rational
   444   \item xxx
   445   \item datatype istate (Istate.T): remove RrlsState, pstate: use Rrls only for creating results beyond
   446     rewriting and/or respective intermediate steps (e.g. cancellation of fractions).
   447     Thus we get a 1-step-action which does NOT require a state beyond istate/pstate.
   448     Thus we drastically reduce complexity, also get rid of "fun from_pblobj_or_detail_calc" , etc.
   449   \item debug ^^^ related: is there an occurence of Steps with more than 1 element?
   450   \item xxx
   451   \item and do_next (* WN1907: ?only for Begin_/End_Detail' DEL!!!*)
   452   \item xxx
   453   \item shouldn't go Rfuns from Rewrite --> Rewrite_Set; they behave similar to "fun interSteps" ?
   454   \item xxx
   455   \item ?finally Prog could go from Calcelems to ProgLang?
   456   \end{itemize}
   457 \<close>
   458 subsection \<open>Inverse_Z_Transform.thy\<close>
   459 text \<open>
   460   \begin{itemize}
   461   \item\label{new-var-rhs} rule1..6, ruleZY introduce new variables on the rhs of the rewrite-rule.
   462   ? replace rewriting with substitution ?!?
   463   The problem is related to the decision of typing for "d_d" and making bound variables free (while
   464   shifting specific handling in equation solving etc. to the meta-logic). 
   465   \item Find "stepResponse (x[n::real]::bool)" is superfluous, because immediately used by
   466     rewrite-rules; see \ref{new-var-rhs}.
   467   \item Reconsider whole problem:
   468     input only the polynomial as argument of partial_function, in ([1], Frm) compile lhs "X z" ?
   469   \end{itemize}
   470 \<close>
   471 subsection \<open>Adopt Isabelle's numerals for Isac\<close>
   472 text \<open>
   473   \begin{itemize}
   474   \item replace numerals of type "real" by "nat" in some specific functions from ListC.thy
   475     and have both representations in parallel for "nat".
   476   \item xxx
   477   \item xxx
   478   \end{itemize}
   479 \<close>
   480 subsection \<open>Redesign equation solver\<close>
   481 text \<open>
   482   Existing solver is structured along the WRONG assumption,
   483   that Poly.thy must be the LAST thy among all thys involved -- while the opposite is the case.
   484 
   485   Preliminary solution: all inappropriately located thms are collected in Base_Tools.thy
   486 \<close>
   487 subsection \<open>Finetunig required for xmldata in kbase\<close>
   488 text \<open>
   489   See xmldata https://intra.ist.tugraz.at/hg/isac/rev/5b222a649390
   490   and in kbase html-representation generated from these xmldata.
   491   Notes in ~~/xmldata/TODO.txt.
   492 \<close>
   493 
   494 section \<open>Hints for further development\<close>
   495 text \<open>
   496 \<close>
   497 subsection \<open>Coding standards & some explanations for math-authors\<close>
   498 text \<open>copy from doc/math-eng.tex WN.28.3.03
   499 WN071228 extended\<close>
   500 
   501 subsubsection \<open>Identifiers\<close>
   502 text \<open>Naming is particularily crucial, because Isabelles name space is global, and isac does
   503   not yet use the novel locale features introduces by Isar. For instance, {\tt probe} sounds
   504   reasonable as (1) a description in the model of a problem-pattern, (2) as an element of the
   505   problem hierarchies key, (3) as a socalled CAS-command, (4) as the name of a related script etc.
   506   However, all the cases (1)..(4) require different typing for one and the same
   507   identifier {\tt probe} which is impossible, and actually leads to strange errors
   508   (for instance (1) is used as string, except in a script addressing a Subproblem).
   509 
   510   These are the preliminary rules for naming identifiers>
   511   \begin{description}
   512   \item [elements of a key] into the hierarchy of problems or methods must not contain
   513     capital letters and may contain underscrores, e.g. {\tt probe, for_polynomials}.
   514   \item [descriptions in problem-patterns] must contain at least 1 capital letter and
   515     must not contain underscores, e.g. {\tt Probe, forPolynomials}.
   516   \item [CAS-commands] follow the same rules as descriptions in problem-patterns above, thus
   517     beware of conflicts~!
   518   \item [script identifiers] always end with {\tt Program}, e.g. {\tt ProbeScript}.
   519   \item [???] ???
   520   \item [???] ???
   521   \end{description}
   522 %WN071228 extended\<close>
   523 
   524 subsubsection \<open>Rule sets\<close>
   525 text \<open>The actual version of the coding standards for rulesets is in {\tt /IsacKnowledge/Atools.ML
   526   where it can be viewed using the knowledge browsers.
   527 
   528   There are rulesets visible to the student, and there are rulesets visible (in general) only for
   529   math authors. There are also rulesets which {\em must} exist for {\em each} theory;
   530   these contain the identifier of the respective theory (including all capital letters) 
   531   as indicated by {\it Thy} below.
   532 
   533   \begin{description}
   534   \item [norm\_{\it Thy}] exists for each theory, and {\em efficiently} calculates a
   535     normalform for all terms which can be expressed by the definitions of the respective theory
   536     (and the respective parents).
   537   \item [simplify\_{\it Thy}] exists for each theory, and calculates a normalform for all terms
   538     which can be expressed by the definitions of the respective theory (and the respective parents)
   539     such, that the rewrites can be presented to the student.
   540   \item [calculate\_{\it Thy}] exists for each theory, and evaluates terms with 
   541     numerical constants only (i.e. all terms which can be expressed by the definitions of
   542     the respective theory and the respective parent theories). In particular, this ruleset includes
   543     evaluating in/equalities with numerical constants only.
   544     WN.3.7.03: may be dropped due to more generality: numericals and non-numericals
   545     are logically equivalent, where the latter often add to the assumptions
   546     (e.g. in Check_elementwise).
   547   \end{description}
   548 
   549   The above rulesets are all visible to the user, and also may be input; 
   550   thus they must be contained in {\tt Theory_Data} (KEStore_Elems.add_rlss,
   551   KEStore_Elems.get_rlss). All these rulesets must undergo a preparation
   552   using the function {\tt prep_rls'}, which generates a script for stepwise rewriting etc.
   553   The following rulesets are used for internal purposes and usually invisible to the (naive) user:
   554 
   555   \begin{description}
   556   \item [*\_erls] TODO
   557   \item [*\_prls] 
   558   \item [*\_srls] 
   559   \end{description}
   560 {\tt Rule_Set.append_rules, Rule_Set.merge, remove_rls} TODO
   561 \<close>
   562 
   563 subsection \<open>get proof-state\<close>
   564 text \<open>
   565   Re: [isabelle] Programatically get "this"
   566   ----------------------------------------------------
   567   So here is my (Makarius') version of your initial example, following these principles:
   568   begin{verbatim}
   569     notepad
   570     begin
   571       assume a: A
   572       ML_val \<open>
   573         val ctxt = @{context};
   574     
   575         val this_name =
   576           Name_Space.full_name (Proof_Context.naming_of ctxt) (Binding.name Auto_Bind.thisN);
   577         val this = #thms (the (Proof_Context.lookup_fact ctxt this_name));
   578       \<close>
   579     end
   580   end{verbatim}
   581 \<close>
   582 subsection \<open>write Specification to jEdit\<close>
   583 text \<open>
   584   Re: [isabelle] Printing terms with type annotations
   585   ----------------------------------------------------
   586   On 06/02/2019 17:52, Moa Johansson wrote:
   587   >
   588   > I’m writing some code that should create a snippet of Isar script.
   589   
   590   This is how Sledgehammer approximates this:
   591   
   592   http://isabelle.in.tum.de/repos/isabelle/file/Isabelle2018/src/HOL/Tools/Sledgehammer/sledgehammer_isar_proof.ML#l299
   593   
   594   (The module name already shows that the proper terminology is "Isar
   595   proof" (or "Isar proof text").  Proof scripts are a thing from the past,
   596   before Isar. You can emulate old-style proof scripts via a sequence of
   597   'apply' commands, but this is improper Isar.)
   598   
   599   Note that there is no standard function in Isabelle/Pure, because the
   600   problem to print just the right amount of type information is very
   601   complex and not fully solved. One day, after 1 or 2 rounds of
   602   refinements over the above approach, it might become generally available.
   603 \<close>
   604 subsection \<open>follow Isabelle conventions (*Does not yet work in Isabelle2018\<close>
   605 text \<open>
   606   isabelle update -u path_cartouches
   607   isabelle update -u inner_syntax_cartouches
   608 \<close>
   609 section \<open>Questions to Isabelle experts\<close>
   610 text \<open>
   611 \begin{itemize}
   612 \item ad ERROR Undefined fact "all_left"        in Test_Isac: error-pattern.sml
   613                Undefined fact: "xfoldr_Nil"                   inssort.sml
   614     (* probably two different reasons:
   615     src/../LinEq.thy
   616       (*WN0509 compare PolyEq.all_left "[|Not(b=!=0)|] ==> (a = b) = (a - b = 0)"*)
   617       all_left:          "[|Not(b=!=0)|] ==> (a=b) = (a+(-1)*b=0)" and
   618     
   619     src/../PolyEq.thy
   620       (*WN0509 compare LinEq.all_left "[|Not(b=!=0)|] ==> (a=b) = (a+(-1)*b=0)"*)
   621       all_left:              "[|Not(b=!=0)|] ==> (a = b) = (a - b = 0)" and
   622     
   623     test/../partial_fractions.sml
   624     (*[7], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["PolyEq", "normalise_poly"])*)
   625     (*[7, 1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite ("all_left", "\<not> ?b =!= 0 \<Longrightarrow> (?a = ?b) = (?a - ?b = 0)"))*)
   626     
   627     test/../mathengine-stateless.sml
   628     (*if ThmC.string_of_thm @ {thm rnorm_equation_add} =  "\<not> ?b =!= 0 \<Longrightarrow> (?a = ?b) = (?a + - 1 * ?b = 0)"
   629     then () else error "string_of_thm changed";*)
   630     
   631     (*---------------------------------------------------------------------------------------------*)
   632     src/../LinEq.thy
   633     primrec xfoldr :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'a xlist \<Rightarrow> 'b \<Rightarrow> 'b" where
   634     xfoldr_Nil:  "xfoldr f {|| ||} = id" |
   635     xfoldr_Cons: "xfoldr f (x @# xs) = f x \<circ> xfoldr f xs"
   636     
   637     src/../InsSort.thy
   638         srls = Rule_Set.empty, calc = [], rules = [
   639           Rule.Thm ("xfoldr_Nil",(*num_str*) @{thm xfoldr_Nil} (* foldr ?f [] = id *)),
   640     *)
   641 \item xxx
   642 \item xxx
   643 \item ?OK Test_Isac_Short with
   644     LI.by_tactic tac (get_istate_LI pt p, get_ctxt_LI pt p) ptp
   645   instead
   646     LI.by_tactic tac (Istate.empty, ContextC.empty) ptp
   647   in step-solve ?
   648 \item xxx
   649 \item test from last CS with outcommented re-def of code -> 
   650   -> \<open>further tests additional to src/.. files\<close>
   651       ADDTESTS/redefined-code.sml
   652 \item xxx
   653 \item efb749b79361 Test_Some_Short.thy has 2 errors, which disappear in thy ?!?:
   654   ML_file "Interpret/error-pattern.sml" Undefined fact: "all_left"
   655   ML_file "Knowledge/inssort.sml" Undefined fact: "xfoldr_Nil"
   656 \item xxx
   657 \item what is the actual replacement of "hg log --follow" ?
   658 \item xxx
   659 \item how HANDLE these exceptions, e.g.:
   660     Syntax.read_term ctxt "Randbedingungen y 0 = (0::real), y L = 0, M_b 0 = 0, M_b L = 0]"
   661   GIVES
   662     "Inner syntax error
   663      Failed to parse term"
   664 \item xxx
   665 \item how cope with "exception Size raised (line 171 of "./basis/LibrarySupport.sml")"
   666   e.g. in test/Interpret/lucas-interpreter.sml
   667 \item xxx
   668 \item xxx
   669 \end{itemize}
   670 \<close>
   671 
   672 section \<open>For copy & paste\<close>
   673 text \<open>
   674 \begin{itemize}
   675 \item xxx
   676   \begin{itemize}
   677   \item xxx
   678     \begin{itemize}
   679     \item xxx
   680       \begin{itemize}
   681       \item xxx
   682         \begin{itemize}
   683         \item xxx
   684         \end{itemize}
   685       \end{itemize}
   686     \end{itemize}
   687   \end{itemize}
   688 \end{itemize}
   689 \<close>
   690 subsection \<open>xxx\<close>
   691 subsubsection \<open>xxx\<close>
   692 end