doc-src/isac/mat-eng-de.tex
branchlatex-isac-doc
changeset 37877 3b63f6bcf05f
child 37882 d354cdcc0a5d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/doc-src/isac/mat-eng-de.tex	Fri Jul 23 11:45:15 2010 +0200
     1.3 @@ -0,0 +1,2010 @@
     1.4 +\documentclass[11pt,a4paper,headline,headcount,towside,nocenter]{report}
     1.5 +\usepackage{latexsym} 
     1.6 +%\usepackage{ngerman}
     1.7 +%\grmn@dq@error ...and \dq \string #1 is undefined}
     1.8 +%l.989 ...tch the problem type \\{\tt["squareroot",
     1.9 +%                                                  "univ
    1.10 +\bibliographystyle{alpha}
    1.11 +
    1.12 +\def\isac{${\cal I}\mkern-2mu{\cal S}\mkern-5mu{\cal AC}$}
    1.13 +
    1.14 +\title{\isac --- Interface for\\
    1.15 +  Developers of Math Knowledge\\[1.0ex]
    1.16 +  and\\[1.0ex]
    1.17 +  Tools for Experiments in\\
    1.18 +  Symbolic Computation\\[1.0ex]}
    1.19 +\author{The \isac-Team\\
    1.20 +  \tt isac-users@ist.tugraz.at\\[1.0ex]}
    1.21 +\date{\today}
    1.22 +
    1.23 +\begin{document}
    1.24 +\maketitle
    1.25 +\newpage
    1.26 +\tableofcontents
    1.27 +\newpage
    1.28 +\listoftables
    1.29 +\newpage
    1.30 +
    1.31 +\chapter{Einleitung}
    1.32 +\section{``Authoring'' und ``Tutoring''}
    1.33 +{TO DO} Mathematik lernen -- verschiedene Autoren -- Isabelle
    1.34 +Die Grundlage f\"ur \isac{} bildet Isabelle. Dies ist ein ``theorem prover'', der von L. Paulson und T. Nipkow entwickelt wird und Hard- und Software pr\"uft.
    1.35 +\section{Der Inhalt des Dokuments}
    1.36 +\paragraph{TO DO} {Als Anleitung:} Dieses Dokument beschreibt das Kerngebiet (KE) von \isac{}, das Gebiet der mathematics engine (ME) im Kerngebiet und die verschiedenen Funktionen wie das Umschreiben und der Vergleich.
    1.37 +
    1.38 +\isac{} und KE wurden in SML geschrieben, die Sprache in Verbindung mit dem Vorg\"anger des Theorem Provers Isabelle entwickelt. So kam es, dass in diesem Dokument die Ebene ASCII als SML Code pr\"asentiert wird. Der Leser wird vermutlich erkennen, dass der \isac{} Benutzer eine vollkommen andere Sichtweise auf eine grafische Benutzeroberfl\"ache bekommt.
    1.39 +
    1.40 +Das Dokument ist eigenst\"andig; Basiswissen \"uber SML (für eine Einf\"uhrung siehe \cite{Paulson:91}), Terme und Umschreibung wird vorrausgesetzt.
    1.41 +
    1.42 +%The interfaces will be moderately exended during the first phase of development of the mathematics knowledge. The work on the subprojects defined should {\em not} create interfaces of any interest to a user or another author of knowledge except identifiers (of type string) for theorems, rulesets etc.
    1.43 +
    1.44 +Hinweis: SML Code, Verzeichnis, Dateien sind {\tt in 'tt' geschrieben}; besonders in {\tt ML>} ist das Kerngebiet schnell.
    1.45 +
    1.46 +\paragraph{Versuchen Sie es!}  Ein weiteres Anliegen dieses Textes ist, dem Leser Tipps f\"ur Versuche mit den Anwendungen zu geben.
    1.47 +
    1.48 +\section{Gleich am Computer ausprobieren!}\label{get-started}
    1.49 +\paragraph{TO DO screenshot} Bevor Sie mit Ihren Versuchen beginnen, m\"ochten wir Ihnen noch einige Hinweise geben.
    1.50 +\begin{itemize}
    1.51 + \item System starten
    1.52 + \item Shell aufmachen und die Datei mat-eng-de.sml \"offnen.
    1.53 + \item $>$  :  Hinter diesem Zeichen (``Prompt'') stehen jene, die Sie selbst eingeben bzw. mit Copy und Paste aus der Datei kopieren.
    1.54 + \item Die Eingabe wird mit ``;'' und ``Enter'' abgeschlossen.
    1.55 + \item Zeilen, die nicht mit Prompt beginnen, werden vom Computer ausgegeben.
    1.56 + 
    1.57 +\end{itemize}
    1.58 +
    1.59 +\part{Experimentelle Ann\"aherung}
    1.60 +
    1.61 +\chapter{Terme und Theorien}
    1.62 +Wie bereits erw\"ahnt, geht es um Computer-Mathematik. In den letzten Jahren hat die ``computer science'' grosse Fortschritte darin gemacht, Mathematik auf dem Computer verst\"andlich darzustellen. Dies gilt f\"ur mathematische Formeln, f\"ur die Beschreibung von Problem (behandelt in Abs.\ref{pbl}), f\"ur L\"osungsmethoden (behandelt in Abs.\ref{met}) etc. Wir beginnen mit mathematischen Formeln --- gleich zum Ausprobieren wie in Abs.\ref{get-started} oben vorbereitet.
    1.63 +
    1.64 +\section{Von der Formel zum Term}
    1.65 +Um ein Beispiel zu nennen: Die Formel $a+b\cdot 3$ l\"asst sich in lesbarer Form so eingeben:
    1.66 +{\footnotesize\begin{verbatim}
    1.67 +  > "a + b * 3";
    1.68 +  val it = "a + b * 3" : string
    1.69 +\end{verbatim}}
    1.70 +\noindent ``a + b * 3'' ist also ein String (=Zeichenfolge). In dieser Form weiss der Computer nicht, dass z.B. eine Multiplikation {\em vor} einer Addition zu rechnen ist. Isabelle braucht Formeln in einer anderen Form; Diese kann man mit der Funktion ``str2term'' (= string to term) umrechnen:
    1.71 +{\footnotesize\begin{verbatim}
    1.72 +  > str2term "a + b * 3";
    1.73 +  val it =
    1.74 +     Const ("op +", "[RealDef.real, RealDef.real] => RealDef.real") $
    1.75 +           Free ("a", "RealDef.real") $
    1.76 +        (Const ("op *", "[RealDef.real, RealDef.real] => RealDef.real") $ ... $
    1.77 +           ...) : Term.term
    1.78 +\end{verbatim}}
    1.79 +\noindent Jene Form braucht Isabelle intern zum rechnen. Sie heisst Term und ist nicht lesbar, daf\"ur aber speicherbar mit Hilfe von ``val'' (=value) 
    1.80 +{\footnotesize\begin{verbatim}
    1.81 +  > val term = str2term "a + b * 3";
    1.82 +  val term =  
    1.83 +     Const ("op +", "[RealDef.real, RealDef.real] => RealDef.real") $
    1.84 +           Free ("a", "RealDef.real") $
    1.85 +        (Const ("op *", "[RealDef.real, RealDef.real] => RealDef.real") $ ... $
    1.86 +           ...) : Term.term
    1.87 +\end{verbatim}
    1.88 +Der gespeicherte Term kann einer Funktion ``atomty'' \"ubergeben werden, die jenen in einer abstrakten Struktur zeigt:
    1.89 +{\footnotesize\begin{verbatim}
    1.90 +  > atomty term;
    1.91 + 
    1.92 +  ***
    1.93 +  *** Const (op +, [real, real] => real)
    1.94 +  *** . Free (a, real)
    1.95 +  *** . Const (op *, [real, real] => real)
    1.96 +  *** . . Free (b, real)
    1.97 +  *** . . Free (3, real)
    1.98 +  ***
    1.99 + 
   1.100 +  val it = () : unit
   1.101 +\end{verbatim}%size
   1.102 +
   1.103 +
   1.104 +\section{``Theory'' und ``Parsing``}
   1.105 +Die theory gibt an, welcher Ausdruck wo steht. Eine derzeitige theory wird intern als \texttt{thy} gekennzeichnet. Jene theory, die alles Wissen ent\"ahlt ist \isac{}. 
   1.106 +
   1.107 +{\footnotesize\begin{verbatim}
   1.108 +  > Isac.thy;
   1.109 +       val it =
   1.110 +          {ProtoPure, CPure, HOL, Set, Typedef, Fun, Product_Type, Lfp, Gfp,
   1.111 +          Sum_Type, Relation, Record, Inductive, Transitive_Closure,
   1.112 +          Wellfounded_Recursion, NatDef, Nat, NatArith, Divides, Power,
   1.113 +          SetInterval, Finite_Set, Equiv, IntDef, Int, Datatype_Universe,
   1.114 +          Datatype, Numeral, Bin, IntArith, Wellfounded_Relations, Recdef, IntDiv,
   1.115 +          IntPower, NatBin, NatSimprocs, Relation_Power, PreList, List, Map,
   1.116 +          Hilbert_Choice, Main, Lubs, PNat, PRat, PReal, RealDef, RealOrd,
   1.117 +          RealInt, RealBin, RealArith0, RealArith, RComplete, RealAbs, RealPow,
   1.118 +          Ring_and_Field, Complex_Numbers, Real, ListG, Tools, Script, Typefix,
   1.119 +          Float, ComplexI, Descript, Atools, Simplify, Poly, Rational, PolyMinus,
   1.120 +          Equation, LinEq, Root, RootEq, RatEq, RootRat, RootRatEq, PolyEq, Vect,
   1.121 +          Calculus, Trig, LogExp, Diff, DiffApp, Integrate, EqSystem, Biegelinie,
   1.122 +          AlgEin, Test, Isac} : Theory.theory
   1.123 +\end{verbatim}
   1.124 +Die, die ein Mal enth\"alt ist groups.thy. Suchen Sie nach '*' unter der Adresse:
   1.125 +
   1.126 +http://www.cl.cam.ac.uk/research/hvg/Isabelle/dist/library/HOL/Groups.html
   1.127 +Hier wird Ihnen erkl\"art, wie das Mal vom Computer gelesen wird.
   1.128 +{\footnotesize\begin{verbatim}
   1.129 +  > Group.thy
   1.130 +      fixes f :: "'a => 'a => 'a" (infixl "*" 70)
   1.131 +      assumes assoc [ac_simps]: "a * b * c = a * (b * c)"
   1.132 +\end{verbatim}
   1.133 +Der ''infix`` ist der Operator, der zwischen zwei Argumenten steht. 70 bedeutet, dass Mal eine hohe Priorit\"at hat (bei einem Plus liegt der Wert bei 50 oder 60). 
   1.134 +
   1.135 +Parsing entsteht durch einen string und eine theory. Es verwendet Informationen, die in der theory von Isabelle enthalten sind.
   1.136 +{\footnotesize\begin{verbatim}
   1.137 +  > parse;
   1.138 +       val it = fn : Theory.theory -> string -> Thm.cterm Library.option
   1.139 +\end{verbatim}
   1.140 +Dieser term kann wieder in seine einzelnen Teile zerlegt werden.
   1.141 +{\footnotesize\begin{verbatim}
   1.142 +   > val it = (term_of o the) it;
   1.143 +        val it =
   1.144 +           Const ("op +", "[RealDef.real, RealDef.real] => RealDef.real") $
   1.145 +               Free ("a", "RealDef.real") $
   1.146 +           (Const ("op *", "[RealDef.real, RealDef.real] => RealDef.real") $ ... $
   1.147 +               ...) : Term.term
   1.148 +\end{verbatim}
   1.149 +
   1.150 +\paragraph{Versuchen Sie es!} Das mathematische Wissen w\"achst, indem man zu den Urspr\"ungen schaut. In den folgenden Beispielen werden verschiedene Meldungen genauer erkl\"art.
   1.151 +
   1.152 +{\footnotesize\begin{verbatim}
   1.153 +   > (*-1-*);
   1.154 +   > parse HOL.thy "2^^^3";
   1.155 +      *** Inner lexical error at: "^^^3"
   1.156 +      val it = None : Thm.cterm Library.option         
   1.157 +\end{verbatim}
   1.158 +''Inner lexical error`` bedeutet, dass ein Fehler aufgetreten ist, vermutlich hat man sich vertippt.
   1.159 +
   1.160 +{\footnotesize\begin{verbatim}
   1.161 +   > (*-2-*);
   1.162 +   > parse HOL.thy "d_d x (a + x)";
   1.163 +      val it = None : Thm.cterm Library.option               
   1.164 +\end{verbatim}
   1.165 +Fehlt ''Inner lexical error`` wurde der Parse nicht gefunden.
   1.166 +
   1.167 +{\footnotesize\begin{verbatim}
   1.168 +   > (*-3-*);
   1.169 +   > parse Rational.thy "2^^^3";
   1.170 +      val it = Some "2 ^^^ 3" : Thm.cterm Library.option               
   1.171 +\end{verbatim}
   1.172 +
   1.173 +{\footnotesize\begin{verbatim}
   1.174 +   > (*-4-*);
   1.175 +   > val Some t4 = parse Rational.thy "d_d x (a + x)";
   1.176 +      val t4 = "d_d x (a + x)" : Thm.cterm              
   1.177 +\end{verbatim}
   1.178 +
   1.179 +{\footnotesize\begin{verbatim}
   1.180 +   > (*-5-*);
   1.181 +   > val Some t5 = parse Diff.thy  "d_d x (a + x)";
   1.182 +      val t5 = "d_d x (a + x)" : Thm.cterm             
   1.183 +\end{verbatim}
   1.184 +
   1.185 +Der Pase liefert hier einen ''zu sch\"onen`` Ausdruck in Form eines cterms, der wie ein string aussieht. Am verl\"asslichsten sind terme, die sich selbst erzeugen lassen.
   1.186 +
   1.187 +\section{Details von Termen}
   1.188 +Mit Hilfe der darunterliegenden Darstellung sieht man, dass ein cterm in einen term umgewandelt werden kann.
   1.189 +{\footnotesize\begin{verbatim}
   1.190 +   > term_of;
   1.191 +      val it = fn : Thm.cterm -> Term.term
   1.192 +\end{verbatim}
   1.193 +Durch die Umwandlung eines cterms in einen term sieht man die einzelnen Teile des Terms. ''Free`` bedeutet, dass man die Variable \"andern kann.
   1.194 +{\footnotesize\begin{verbatim}
   1.195 +   > term_of t4;
   1.196 +      val it =
   1.197 +         Free ("d_d", "[RealDef.real, RealDef.real] => RealDef.real") $ ... $
   1.198 +         ...: Term.term
   1.199 +
   1.200 +\end{verbatim}
   1.201 +In diesem Fall sagt uns das ''Const``, dass die Variable eine Konstante ist, also ein Fixwert ist und immer die selbe Funktion hat.
   1.202 +{\footnotesize\begin{verbatim}
   1.203 +   > term_of t5;
   1.204 +      val it =
   1.205 +         Const ("Diff.d_d", "[RealDef.real, RealDef.real] => RealDef.real") $ ... $
   1.206 +         ... : Term.term
   1.207 +\end{verbatim}
   1.208 +Sollten verschiedene Teile des Output nicht sichtbar sein, kann die Schriftgr\"osse ge\"andert werden.
   1.209 +{\footnotesize\begin{verbatim}
   1.210 +   > print_depth;
   1.211 +      val it = fn : int -> unit
   1.212 + \end{verbatim}
   1.213 +Zuerst gibt man die Schriftgr\"osse ein, danach den term, der gr\"osser werden soll.
   1.214 +{\footnotesize\begin{verbatim}
   1.215 +   > print_depth 10;
   1.216 +      val it = () : unit
   1.217 +   > term_of t4;
   1.218 +         val it =
   1.219 +            Free ("d_d", "[RealDef.real, RealDef.real] => RealDef.real") $
   1.220 +                Free ("x", "RealDef.real") $
   1.221 +            (Const ("op +", "[RealDef.real, RealDef.real] => RealDef.real") $
   1.222 +                Free ("a", "RealDef.real") $ Free ("x", "RealDef.real"))
   1.223 +         : Term.term
   1.224 +
   1.225 +   > print_depth 10;
   1.226 +         val it = () : unit
   1.227 +   > term_of t5;
   1.228 +         val it =
   1.229 +            Const ("Diff.d_d", "[RealDef.real, RealDef.real] => RealDef.real") $
   1.230 +                Free ("x", "RealDef.real") $
   1.231 +            (Const ("op +", "[RealDef.real, RealDef.real] => RealDef.real") $
   1.232 +                Free ("a", "RealDef.real") $ Free ("x", "RealDef.real"))
   1.233 +         : Term.term
   1.234 +\end{verbatim}
   1.235 +
   1.236 +Eine andere Variante um den Unterschied der beiden Terme zu sehen ist folgende: 
   1.237 +{\footnotesize\begin{verbatim}
   1.238 +   > (*-4-*) val thy = Rational.thy;
   1.239 +      val thy =
   1.240 +         {ProtoPure, CPure, HOL, Set, Typedef, Fun, Product_Type, Lfp, Gfp,
   1.241 +         Sum_Type, Relation, Record, Inductive, Transitive_Closure,
   1.242 +         Wellfounded_Recursion, NatDef, Nat, NatArith, Divides, Power,
   1.243 +         SetInterval, Finite_Set, Equiv, IntDef, Int, Datatype_Universe,
   1.244 +         Datatype, Numeral, Bin, IntArith, Wellfounded_Relations, Recdef, IntDiv,
   1.245 +         IntPower, NatBin, NatSimprocs, Relation_Power, PreList, List, Map,
   1.246 +         Hilbert_Choice, Main, Lubs, PNat, PRat, PReal, RealDef, RealOrd,
   1.247 +         RealInt, RealBin, RealArith0, RealArith, RComplete, RealAbs, RealPow,
   1.248 +         Ring_and_Field, Complex_Numbers, Real, ListG, Tools, Script, Typefix,
   1.249 +         Float, ComplexI, Descript, Atools, Simplify, Poly, Rational}
   1.250 +     : Theory.theory
   1.251 +   > ((atomty) o term_of o the o (parse thy)) "d_d x (a + x)";
   1.252 + 
   1.253 +      ***
   1.254 +      *** Free (d_d, [real, real] => real)
   1.255 +      *** . Free (x, real)
   1.256 +      *** . Const (op +, [real, real] => real)
   1.257 +      *** . . Free (a, real)
   1.258 +      *** . . Free (x, real)
   1.259 +      ***
   1.260 + 
   1.261 +      val it = () : unit
   1.262 +
   1.263 +
   1.264 +   > (*-5-*) val thy = Diff.thy;
   1.265 +      val thy =
   1.266 +         {ProtoPure, CPure, HOL, Set, Typedef, Fun, Product_Type, Lfp, Gfp,
   1.267 +         Sum_Type, Relation, Record, Inductive, Transitive_Closure,
   1.268 +         Wellfounded_Recursion, NatDef, Nat, NatArith, Divides, Power,
   1.269 +         SetInterval, Finite_Set, Equiv, IntDef, Int, Datatype_Universe,
   1.270 +         Datatype, Numeral, Bin, IntArith, Wellfounded_Relations, Recdef, IntDiv,
   1.271 +         IntPower, NatBin, NatSimprocs, Relation_Power, PreList, List, Map,
   1.272 +         Hilbert_Choice, Main, Lubs, PNat, PRat, PReal, RealDef, RealOrd,
   1.273 +         RealInt, RealBin, RealArith0, RealArith, RComplete, RealAbs, RealPow,
   1.274 +         Ring_and_Field, Complex_Numbers, Real, Calculus, Trig, ListG, Tools,
   1.275 +         Script, Typefix, Float, ComplexI, Descript, Atools, Simplify, Poly,
   1.276 +         Equation, LinEq, Root, RootEq, Rational, RatEq, RootRat, RootRatEq,
   1.277 +         PolyEq, LogExp, Diff} : Theory.theory
   1.278 + 
   1.279 +   > ((atomty) o term_of o the o (parse thy)) "d_d x (a + x)";
   1.280 + 
   1.281 +      ***
   1.282 +      *** Const (Diff.d_d, [real, real] => real)
   1.283 +      *** . Free (x, real)
   1.284 +      *** . Const (op +, [real, real] => real)
   1.285 +      *** . . Free (a, real)
   1.286 +      *** . . Free (x, real)
   1.287 +      ***
   1.288 + 
   1.289 +      val it = () : unit
   1.290 +\end{verbatim}
   1.291 +
   1.292 +
   1.293 +{\chapter{''Rewriting``}}
   1.294 +{\section{}}
   1.295 +Bei Rewriting handelt es sich um die Vereinfachung eines Terms in vielen kleinen Schritten und nach bestimmten Regeln. Der Computer wendet dabei hintereinander verschiedene Rechengesetze an, weil er den Term ansonsten nicht l\"osen kann.
   1.296 +
   1.297 +{\footnotesize\begin{verbatim}
   1.298 +> rewrite_;
   1.299 +val it = fn
   1.300 +:
   1.301 +   Theory.theory ->
   1.302 +   ((Term.term * Term.term) list -> Term.term * Term.term -> bool) ->
   1.303 +   rls ->
   1.304 +   bool ->
   1.305 +   Thm.thm -> Term.term -> (Term.term * Term.term list) Library.option
   1.306 +
   1.307 +> rewrite;
   1.308 +val it = fn
   1.309 +:
   1.310 +   theory' ->
   1.311 +   rew_ord' ->
   1.312 +   rls' -> bool -> thm' -> cterm' -> (string * string list) Library.option
   1.313 +
   1.314 +\end{verbatim}
   1.315 +\textbf{Versuchen Sie es!} Um zu sehen, wie der Computer vorgeht und welche Rechengesetze er anwendet, zeigen wir Ihnen durch Differenzieren von (a + a * (2 + b)), die einzelnen Schritte. Sie k\"onnen nat\"urlichauch selbst einige Beispiele ausprobieren!
   1.316 +
   1.317 +Zuerst legt man fest, dass es sich um eine Differenzierung handelt.
   1.318 +{\footnotesize\begin{verbatim}
   1.319 +   > val thy' = "Diff.thy";
   1.320 +      val thy' = "Diff.thy" : string
   1.321 +\end{verbatim}
   1.322 +Dann gibt man die zu l\"osende Rechnung ein.
   1.323 +{\footnotesize\begin{verbatim}
   1.324 +   > val ct = "d_d x (a + a * (2 + b))";
   1.325 +      val ct = "d_d x (a + a * (2 + b))" : string
   1.326 +\end{verbatim}
   1.327 +Anschließend gibt man bekannt, dass die Summenregel angewandt werden soll.
   1.328 +{\footnotesize\begin{verbatim}
   1.329 +   > val thm = ("diff_sum","");
   1.330 +      val thm = ("diff_sum", "") : string * string
   1.331 +\end{verbatim}
   1.332 +Schliesslich wird die erste Ableitung angezeigt.
   1.333 +{\footnotesize\begin{verbatim}
   1.334 +   > val Some (ct,_) = rewrite_inst thy' "tless_true" "eval_rls" true
   1.335 +                        [("bdv","x::real")] thm ct;#
   1.336 +      val ct = "d_d x a + d_d x (a * (2 + b))" : cterm'
   1.337 +\end{verbatim}
   1.338 +Will man auch die zweite Ableitung sehen, geht man so vor:
   1.339 +{\footnotesize\begin{verbatim}
   1.340 +   > val thm = ("diff_prod_const","");
   1.341 +      val thm = ("diff_prod_const", "") : string * string
   1.342 +\end{verbatim} 
   1.343 +Auch die zweite Ableitung wird sichtbar.
   1.344 +{\footnotesize\begin{verbatim}
   1.345 +   > val Some (ct,_) = rewrite_inst thy' "tless_true" "eval_rls" true
   1.346 +                        [("bdv","x::real")] thm ct;#
   1.347 +      val ct = "d_d x a + a * d_d x (2 + b)" : cterm'
   1.348 +\end{verbatim}
   1.349 +
   1.350 +
   1.351 +
   1.352 +
   1.353 +
   1.354 +
   1.355 +
   1.356 +
   1.357 +
   1.358 +
   1.359 +
   1.360 +\newpage
   1.361 +------------------------------- ALTER TEXT -------------------------------
   1.362 +
   1.363 +Ein Term ist eine Zeichenfolge. Das heisst Es gibt zwei Arten von Termen in Isabelle, 'raw terms' und 'certified terms'. \isac{} arbeitet mit raw terms, die effizient sind. 
   1.364 +{\footnotesize\begin{verbatim}
   1.365 +   datatype term = 
   1.366 +       Const of string * typ
   1.367 +     | Free  of string * typ 
   1.368 +     | Var   of indexname * typ
   1.369 +     | Bound of int
   1.370 +     | Abs   of string * typ * term
   1.371 +     | op $  of term * term;
   1.372 +
   1.373 +   datatype typ = Type  of string * typ list
   1.374 +                | TFree of string * sort
   1.375 +                | TVar  of indexname * sort;
   1.376 +\end{verbatim}}%size % $
   1.377 +Die Definition und der Indexname sind in diesem Zusammenhang nicht relevant. Der {\tt typ}e wird w\"ahrend der Parse angedeutet. Diese ist der Hauptbestandteil f\"ur andere Terms, {\tt cterm}. Sie {\tt cterm}s sind zusammengefasste Aufzeichnungen, die ohne die jeweiligen Isabelle-Funktionen nicht zusammengesetzt werden k\"onnen (type--Richtigkeit \"Uberpr\"ufen), aber dann g\"unstig als string dargestellt werden (Verwendung von SML Compiler Internals -- siehe unten).
   1.378 +
   1.379 +\section{Theorien und Terme}
   1.380 +Die Parse verwendet Informationen, die in der Theorie von Isabelle $\sim${\tt /src/HOL}enthalten sind. Die derzeitige Theorie wird international als {\tt thy} gekennzeichnet; auf diese kann unterschiedlich zugegriffen werden.
   1.381 +{\footnotesize\begin{verbatim}
   1.382 +   ML> thy;
   1.383 +   val it =
   1.384 +   {ProtoPure, CPure, HOL, Set, Typedef, Fun, Product_Type, Lfp, Gfp,
   1.385 +     Sum_Type, Relation, Record, Inductive, Transitive_Closure,
   1.386 +     Wellfounded_Recursion, NatDef, Nat, NatArith, Divides, Power,
   1.387 +     SetInterval, Finite_Set, Equiv, IntDef, Int, Datatype_Universe,
   1.388 +     Datatype, Numeral, Bin, IntArith, Wellfounded_Relations, Recdef, IntDiv,
   1.389 +     IntPower, NatBin, NatSimprocs, Relation_Power, PreList, List, Map,
   1.390 +     Hilbert_Choice, Main, Lubs, PNat, PRat, PReal, RealDef, RealOrd,
   1.391 +     RealInt, RealBin, RealArith0, RealArith, RComplete, RealAbs, RealPow,
   1.392 +     Ring_and_Field, Complex_Numbers, Real, ListG, Tools, Script, Typefix,
   1.393 +     Float, ComplexI, Descript, Atools, Simplify, Poly, Rational, PolyMinus,
   1.394 +     Equation, LinEq, Root, RootEq, RatEq, RootRat, RootRatEq, PolyEq, Vect,
   1.395 +     Calculus, Trig, LogExp, Diff, DiffApp, Integrate, EqSystem, Biegelinie,
   1.396 +     AlgEin, Test, Isac} : Theory.theory                                           
   1.397 +   ML> HOL.thy;
   1.398 +   val it = {ProtoPure, CPure, HOL} : Theory.theory 
   1.399 +   ML>
   1.400 +   ML> parse;
   1.401 +   val it = fn : Theory.theory -> string -> Thm.cterm Library.option
   1.402 +   ML> parse thy "a + b * 3";
   1.403 +   val it = Some "a + b * 3" : Thm.cterm Library.option
   1.404 +   ML>
   1.405 +   ML> val t = (term_of o the) it;
   1.406 +  val t =
   1.407 +   Const ("op +", "[RealDef.real, RealDef.real] => RealDef.real") $
   1.408 +         Free ("a", "RealDef.real") $
   1.409 +      (Const ("op *", "[RealDef.real, RealDef.real] => RealDef.real") $ ... $
   1.410 +         ...) : Term.term
   1.411 +
   1.412 +\end{verbatim}}%size
   1.413 +Die Ausdr\"ucke {\tt term\_of} und {\tt the} werden weiter unten erkl\"art. Den Syntax aus der Liste der Funktionen kann man aus den Theorien von Isabelle \cite{Isa-obj} {\tt [isabelle]/src/HOL/}\footnote{Oder Sie schauen ins Internet unter {\tt [isabelle]/browser\_info}.} und aus den entwickelten Theorien von \isac{} unter {\tt [isac-src]/knowledge/} herauslesen. Beachten Sie, dass der Syntax von diesem Ausdruck anders ist, als jene die bei \isac vom Vorrechner nach der Umrechnung zu MathML angezeigt werden.
   1.414 +
   1.415 +
   1.416 +\section{Anzeigen von Termen}
   1.417 +Die Drucktiefe auf der höchsten Ebene des SML kann in Ordnung gebracht werden, um den output in der Menge des gewünschten Details zu erzeugen:
   1.418 +{\footnotesize\begin{verbatim}
   1.419 +   ML> Compiler.Control.Print.printDepth;
   1.420 +   val it = ref 4 : int ref
   1.421 +   ML>
   1.422 +   ML> Compiler.Control.Print.printDepth:= 2;
   1.423 +   val it = () : unit
   1.424 +   ML> t;
   1.425 +   val it =
   1.426 +   Const ("op +", "[RealDef.real, RealDef.real] => RealDef.real") $
   1.427 +         Free ("a", "RealDef.real") $
   1.428 +      (Const ("op *", "[RealDef.real, RealDef.real] => RealDef.real") $ ... $
   1.429 +         ...) : Term.term
   1.430 +   ML>
   1.431 +   ML> Compiler.Control.Print.printDepth:= 6;
   1.432 +   val it = () : unit
   1.433 +   ML> t;
   1.434 +   val it =
   1.435 +     Const ("op +","[RealDef.real, RealDef.real] => RealDef.real") $
   1.436 +     Free ("a","RealDef.real") $
   1.437 +     (Const ("op *","[RealDef.real, RealDef.real] => RealDef.real") $
   1.438 +      Free ("b","RealDef.real") $ Free ("#3","RealDef.real")) : term
   1.439 +\end{verbatim}}%size % $
   1.440 +Ein n\"aherer Blick zum letzten output zeigt, dass {\tt typ} wie der string {\tt cterm} ausgegeben worden ist. Andere n\"utzliche Einstellungen für den output sind:
   1.441 +{\footnotesize\begin{verbatim}
   1.442 +   ML> Compiler.Control.Print.printLength;
   1.443 +   val it = ref 8 : int ref
   1.444 +   ML> Compiler.Control.Print.stringDepth;
   1.445 +   val it = ref 250 : int ref
   1.446 +\end{verbatim}}%size
   1.447 +Die SML der Terme ist nicht lesbar; es gibt Funktionen im KE, um sie zu zeigen:
   1.448 +{\footnotesize\begin{verbatim}
   1.449 +   ML> atomt;
   1.450 +   val it = fn : Term.term -> string
   1.451 +   ML> atomt t; 
   1.452 +  "*** -------------"
   1.453 +  "*** Const (op +)"
   1.454 +  "*** . Free (a, )"
   1.455 +  "*** . Const (op *)"
   1.456 +  "*** . . Free (b, )"
   1.457 +  "*** . . Free (3, )"
   1.458 +  "\n"
   1.459 +val it = "\n" : string
   1.460 +   ML>
   1.461 +   ML> atomty;
   1.462 +  val it = fn : Term.term -> unit
   1.463 +   ML> atomty thy t;
   1.464 +   *** -------------
   1.465 +   *** Const ( op +, [real, real] => real)
   1.466 +   *** . Free ( a, real)
   1.467 +   *** . Const ( op *, [real, real] => real)
   1.468 +   *** . . Free ( b, real)
   1.469 +   *** . . Free ( #3, real)
   1.470 +   val it = () : unit
   1.471 +\end{verbatim}}%size
   1.472 +{\tt typ} wird als string wiedergegeben. Diesaml aber durch die Informationen von {\tt thy} in besserer Darstellung.
   1.473 +
   1.474 +\paragraph{Versuchen Sie es!} {\bf Das mathematische Wissen w\"achst} wie es in Isabelle schrittweise beschrieben ist. Schauen Sie ins Internet um diese Beschreibungen aufzurufen {\tt [isabelle]/src/HOL/HOL.thy} und zu sehen, ob es Kindern auf Ihrem System zur Verf\"ugung steht. Oder Sie sehen sich die verschiedenen Dateien unter {\tt [isabelle]/browser\_info} an.
   1.475 +{\footnotesize\begin{verbatim}
   1.476 +   ML> (*-1-*) parse HOL.thy "#2^^^#3";
   1.477 +   *** Inner lexical error at: "^^^3"
   1.478 +   val it = None : Thm.cterm Library.option
   1.479 +   ML>
   1.480 +   ML> (*-2-*) parse HOL.thy "d_d x (a + x)";
   1.481 +   val it = None : Thm.cterm Library.option
   1.482 +   ML>
   1.483 +   ML>
   1.484 +   ML> (*-3-*) parse RatArith.thy "#2^^^#3";
   1.485 +   val it = Some "#2 ^^^ #3" : cterm option
   1.486 +   ML>
   1.487 +   ML> (*-4-*) parse RatArith.thy "d_d x (a + x)";
   1.488 +   val it = Some "d_d x (a + x)" : cterm option
   1.489 +   ML>
   1.490 +   ML>
   1.491 +   ML> (*-5-*) parse Differentiate.thy "d_d x (a + x)";
   1.492 +   val it = Some "d_d x (a + x)" : cterm option
   1.493 +   ML>
   1.494 +   ML> (*-6-*) parse Differentiate.thy "#2^^^#3";
   1.495 +   val it = Some "#2 ^^^ #3" : cterm option
   1.496 +\end{verbatim}}%size
   1.497 +Vertrauen sie nicht der string Darstellung: Wenn wir {\tt(*-4-*)} und {\tt(*-6-*)} zu folgenden Ausdr\"ucken umwandel:\dots
   1.498 +{\footnotesize\begin{verbatim}
   1.499 +   ML> (*-4-*) val thy = RatArith.thy;
   1.500 +   ML> ((atomty thy) o term_of o the o (parse thy)) "d_d x (a + x)";
   1.501 +   *** -------------
   1.502 +   *** Free ( d_d, [real, real] => real)
   1.503 +   *** . Free ( x, real)
   1.504 +   *** . Const ( op +, [real, real] => real)
   1.505 +   *** . . Free ( a, real)
   1.506 +   *** . . Free ( x, real)
   1.507 +   val it = () : unit
   1.508 +   ML>
   1.509 +   ML> (*-6-*) val thy = Differentiate.thy;
   1.510 +   ML> ((atomty thy) o term_of o the o (parse thy)) "d_d x (a + x)";
   1.511 +   *** -------------
   1.512 +   *** Const ( Differentiate.d_d, [real, real] => real)
   1.513 +   *** . Free ( x, real)
   1.514 +   *** . Const ( op +, [real, real] => real)
   1.515 +   *** . . Free ( a, real)
   1.516 +   *** . . Free ( x, real)
   1.517 +   val it = () : unit
   1.518 +\end{verbatim}}%size
   1.519 +\dots Wir sehen: Bei {\tt(*-4-*)} handelt es sich um eine willk\"urliche Funktion {\tt Free ( d\_d, \_)} und bei {\tt(*-6-*)} um eine spezielle unver\"anderliche Funktion {\tt Const ( Differentiate.d\_d, \_)} für das Differenzieren, welches in {\tt Differentiate.thy} erkl\"art wird und vermutlich gemeint ist.
   1.520 +
   1.521 +
   1.522 +\section{Terme umwandeln}
   1.523 +Die Umwandlung von {\tt cterm} zu {\tt term} wurde bereits oberhalb gezeigt:
   1.524 +{\footnotesize\begin{verbatim}
   1.525 +   ML> term_of;
   1.526 +   val it = fn : Thm.cterm -> Term.term
   1.527 +   ML>
   1.528 +   ML> the;
   1.529 +   val it = fn : 'a Library.option -> 'a
   1.530 +   ML>
   1.531 +   ML> val t = (term_of o the o (parse thy)) "a + b * 3";
   1.532 +   val t = Const (#,#) $ Free (#,#) $ (Const # $ Free # $ Free (#,#)) : term
   1.533 +\end{verbatim}}%size
   1.534 +{\tt the} wird dabei von {\tt term option} ausgewickelt --- eine hilfreiche Funktion von Larry Paulsons Grundlagen {\tt [isabelle]/src/Pure/library.ML}, die für jeden SML Programmierer sehr wertvoll ist.
   1.535 +
   1.536 +Die anderen Umwandlungen sind folgende, wobei einige {\it signature} {\tt sign} als Theorie verwenden:
   1.537 +{\footnotesize\begin{verbatim}
   1.538 +   ML> sign_of;
   1.539 +   val it = fn : theory -> Sign.sg
   1.540 +   ML>
   1.541 +   ML> cterm_of;
   1.542 +   val it = fn : Sign.sg -> term -> cterm
   1.543 +   ML> val ct = cterm_of (sign_of thy) t;
   1.544 +   val ct = "a + b * #3" : cterm
   1.545 +   ML>
   1.546 +   ML> Sign.string_of_term;
   1.547 +   val it = fn : Sign.sg -> term -> string
   1.548 +   ML> Sign.string_of_term (sign_of thy) t;
   1.549 +   val it = "a + b * #3" : ctem'
   1.550 +   ML>
   1.551 +   ML> string_of_cterm;
   1.552 +   val it = fn : cterm -> string
   1.553 +   ML> string_of_cterm ct;
   1.554 +   val it = "a + b * #3" : ctem'
   1.555 +\end{verbatim}}%size
   1.556 +
   1.557 +\section{Lehrs\"atze}
   1.558 +Theorems sind types, {\tt thm}, gesch\"utzter als {\tt cterms}: Sie sind als axioms beschrieben und haben sich in Isabelle bew\"ahrt. Diese Definitionen und Beweise sind in den Theorien im Verzeichnis {\tt[isac-src]/knowledge/} enthalten, zum Beispiel der Lehrsatz {\tt diff\_sum} in der Theorie {\tt[isac-src]/knowledge/Differentiate.thy}. Zus\"atzlich muss jeder Lehrsatz für \isac{} im zugeh\"origen {\tt *.ML}, wie etwa {\tt diff\_sum} in {\tt[isac-src]/knowledge/Differentiate.ML} aufgenommen werden, wie das Folgende:
   1.559 +{\footnotesize\begin{verbatim}
   1.560 +   ML> theorem' := overwritel (!theorem',
   1.561 +   [("diff_const",num_str diff_const)
   1.562 +   ]);
   1.563 +\end{verbatim}}%size
   1.564 +The additional recording of theorems and other values will disappear in later versions of \isac.
   1.565 +
   1.566 +\chapter{Umschreiben}
   1.567 +\section{Argumente f\"ur Umschreibungen}
   1.568 +Die Bezeichnung des type der Argumente und Werte der Umschreibfunktionen in \ref{rewrite} unterscheiden sich durch ein Apostroph: Die types mit einem Apostroph sind umbenannte strings um die Lesbarkeit aufrecht zu erhalten.
   1.569 +{\footnotesize\begin{verbatim}
   1.570 +   ML> HOL.thy;
   1.571 +   val it = {ProtoPure, CPure, HOL} : theory
   1.572 +   ML> "HOL.thy" : theory';
   1.573 +   val it = "HOL.thy" : theory'
   1.574 +   ML>
   1.575 +   ML> sqrt_right;
   1.576 +   val it = fn : rew_ord (* term * term -> bool *)
   1.577 +   ML> "sqrt_right" : rew_ord';
   1.578 +   val it = "sqrt_right" : rew_ord'
   1.579 +   ML>
   1.580 +   ML> eval_rls;
   1.581 +   val it =
   1.582 +     Rls
   1.583 +       {preconds=[],rew_ord=("sqrt_right",fn),
   1.584 +        rules=[Thm #,Thm #,Thm #,Thm #,Thm #,Thm #,Thm #,Thm #,
   1.585 +               Thm #,Thm #,Thm #,Thm #,Thm #,Calc #,Calc #,...],
   1.586 +        scr=Script (Free #)} : rls
   1.587 +   ML> "eval_rls" : rls';
   1.588 +   val it = "eval_rls" : rls'
   1.589 +   ML>
   1.590 +   ML> diff_sum;
   1.591 +   val it = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" : thm
   1.592 +   ML> ("diff_sum", "") : thm';
   1.593 +   val it = ("diff_sum","") : thm'
   1.594 +\end{verbatim}}%size
   1.595 +{\tt thm'} ist ein Teil, eventuell mit strin-Darstellung von dem zugeh\"origen Lehrsatz.
   1.596 + 
   1.597 +\section{Die Funktionen des Umschreibens}\label{rewrite}
   1.598 +Das Umschreiben wird von zwei equvalenten Funktionen begleitet, wobei die erste im KE verwendet wird und sie zweite n\"utzlich für Tests ist: 
   1.599 +{\footnotesize\begin{verbatim}
   1.600 +   ML> rewrite_;
   1.601 +   val it = fn
   1.602 +     : theory
   1.603 +       -> rew_ord
   1.604 +          -> rls -> bool -> thm -> term -> (term * term list) option
   1.605 +   ML>
   1.606 +   ML> rewrite;
   1.607 +   val it = fn
   1.608 +     : theory'
   1.609 +       -> rew_ord'
   1.610 +          -> rls' -> bool -> thm' -> cterm' -> (cterm' * cterm' list) option
   1.611 +\end{verbatim}}%size
   1.612 +The arguments are the following:\\
   1.613 +\tabcolsep=4mm
   1.614 +\def\arraystretch{1.5}
   1.615 +\begin{tabular}{lp{11.0cm}}
   1.616 +  {\tt theory}  & the Isabelle theory containing the definitions necessary for parsing the {\tt term} \\
   1.617 +  {\tt rew\_ord}& the rewrite order \cite{nipk:rew-all-that} for ordered rewriting -- see the section \ref{term-order} below. For {\em no} ordered rewriting take {\tt tless\_true}, a dummy order yielding true for all arguments \\
   1.618 +  {\tt rls}     & the rule set for evaluating the condition within {\tt thm} in case {\tt thm} is a conditional rule \\
   1.619 +  {\tt bool}    & a flag which triggers the evaluation of the eventual condition in {\tt thm}: if {\tt false} then evaluate the condition and according to the result of the evaluation apply {\tt thm} or not (conditional rewriting \cite{nipk:rew-all-that}), if {\tt true} then don't evaluate the condition, but put it into the set of assumptions \\
   1.620 +  {\tt thm}     & the theorem used to try to rewrite {\tt term} \\
   1.621 +  {\tt term}    & the term eventually rewritten by {\tt thm} \\
   1.622 +\end{tabular}\\
   1.623 +
   1.624 +\noindent The respective values of {\tt rewrite\_} and {\tt rewrite} are an {\tt option} of a pair, i.e. {\tt Some(\_,\_)} in case the {\tt term} can be rewritten by {\tt thm} w.r.t. {\tt rew\_ord} and/or {\tt rls}, or {\tt None} if no rewrite is found:\\
   1.625 +\begin{tabular}{lp{10.4cm}}
   1.626 +  {\tt term}     & the term rewritten \\
   1.627 +  {\tt term list}& the assumptions eventually generated if the {\tt bool} flag is set to {\tt true} and {\tt thm} is applicable. \\
   1.628 +\end{tabular}\\
   1.629 +
   1.630 +\paragraph{Give it a try !} {\bf\dots rewriting is fun~!} many examples can be found in {\tt [isac-src]/tests/\dots}. In {\tt [isac-src]/tests/differentiate.sml} the following can be found:
   1.631 +{\footnotesize\begin{verbatim}
   1.632 +   ML> val thy' = "Differentiate.thy";
   1.633 +   val thy' = "Differentiate.thy" : string
   1.634 +   ML> val ct = "d_d x (x ^^^ #2 + #3 * x + #4)";
   1.635 +   val ct = "d_d x (x ^^^ #2 + #3 * x + #4)" : cterm'
   1.636 +   ML>
   1.637 +   ML> val thm = ("diff_sum","");
   1.638 +   val thm = ("diff_sum","") : thm'
   1.639 +   ML> val Some (ct,_) = rewrite_inst thy' "tless_true" "eval_rls" true
   1.640 +                     [("bdv","x::real")] thm ct;
   1.641 +   val ct = "d_d x (x ^^^ #2 + #3 * x) + d_d x #4" : cterm'
   1.642 +   ML>
   1.643 +   ML> val Some (ct,_) = rewrite_inst thy' "tless_true" "eval_rls" true
   1.644 +                     [("bdv","x::real")] thm ct;
   1.645 +   val ct = "d_d x (x ^^^ #2) + d_d x (#3 * x) + d_d x #4" : cterm'
   1.646 +   ML>
   1.647 +   ML> val thm = ("diff_prod_const","");
   1.648 +   val thm = ("diff_prod_const","") : thm'
   1.649 +   ML> val Some (ct,_) = rewrite_inst thy' "tless_true" "eval_rls" true
   1.650 +                     [("bdv","x::real")] thm ct;
   1.651 +   val ct = "d_d x (x ^^^ #2) + #3 * d_d x x + d_d x #4" : cterm'
   1.652 +\end{verbatim}}%size
   1.653 +Sie k\"onnen unter {\tt [isac-src]/knowledge/Differentiate.thy} die Lehrs\"atze nachschlagen und versuchen Sie, diese anzuwenden bis Sie die Ergebnisse bekommen.
   1.654 +\footnote{Hinweis: Am Ende werden Sie {\tt val (ct,\_) = the (rewrite\_set thy' "eval\_rls" false "SqRoot\_simplify" ct);} benötigen.}
   1.655 +
   1.656 +\paragraph{Versuchen Sie es!}\label{cond-rew} {\bf Conditional rewriting} ist eine besser Technik als \"ubliche Umschreibungen und \"ahnelt den Programmiersprachen mehr (siehe n\"achstes 'Versuchen Sie es'~!). Das folgende Beispiel liegt im Bereich der ??poynomial form??:
   1.657 +{\footnotesize\begin{verbatim}
   1.658 +   ML> val thy' = "Isac.thy";
   1.659 +   val thy' = "Isac.thy" : string
   1.660 +   ML> val ct' = "#3 * a + #2 * (a + #1)";
   1.661 +   val ct' = "#3 * a + #2 * (a + #1)" : cterm'
   1.662 +   ML>
   1.663 +   ML> val thm' = ("radd_mult_distrib2","?k * (?m + ?n) = ?k * ?m + ?k * ?n");
   1.664 +   val thm' = ("radd_mult_distrib2","?k * (?m + ?n) = ?k * ?m + ?k * ?n")
   1.665 +     : thm'
   1.666 +   ML> (*1*) val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
   1.667 +   val ct' = "#3 * a + (#2 * a + #2 * #1)" : cterm'
   1.668 +   ML>
   1.669 +   ML> val thm' = ("radd_assoc_RS_sym","?m1 + (?n1 + ?k1) = ?m1 + ?n1 + ?k1");
   1.670 +   val thm' = ("radd_assoc_RS_sym","?m1 + (?n1 + ?k1) = ?m1 + ?n1 + ?k1")
   1.671 +     : thm'
   1.672 +   ML> (*2*) val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
   1.673 +   val ct' = "#3 * a + #2 * a + #2 * #1" : cterm'
   1.674 +   ML>
   1.675 +   ML> val thm' = ("rcollect_right",
   1.676 +     "[| ?l is_const; ?m is_const |] ==> ?l * ?n + ?m * ?n = (?l + ?m) * ?n");
   1.677 +   val thm' =
   1.678 +     ("rcollect_right",
   1.679 +      "[| ?l is_const; ?m is_const |] ==> ?l * ?n + ?m * ?n = (?l + ?m) * ?n")
   1.680 +     : thm'
   1.681 +   ML> (*3*) val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
   1.682 +   val ct' = "(#3 + #2) * a + #2 * #1" : cterm'
   1.683 +   ML>
   1.684 +   ML> (*4*) val Some (ct',_) = calculate' thy' "plus" ct';
   1.685 +   val ct' = "#5 * a + #2 * #1" : cterm'
   1.686 +   ML>
   1.687 +   ML> (*5*) val Some (ct',_) = calculate' thy' "times" ct';
   1.688 +   val ct' = "#5 * a + #2" : cterm'
   1.689 +\end{verbatim}}%size
   1.690 +Beachten Sie, dass es zwei Regeln gibt {\tt radd\_mult\_distrib2} in {\tt(*1*)} und {\tt rcollect\_right} in {\tt(*3*)}, die einander aufheben, (das heißt, eine angesetzte Regel w\"urde es nicht beenden), wenn es diese Bedinung nicht vorhanden ist {\tt is\_const}.
   1.691 +
   1.692 +\paragraph{Versuchen Sie es!} {\bf Funktionelle Programmierung} kann, innerhalb einer bestimmten Reihe, durch das Umschreiben bearbeitet werden. In {\tt [isac-src]/\dots/tests/InsSort.thy} k\"onnen die Regeln gefunden werden, mit denen man eine Liste sortieren kann ('insertion sort'):
   1.693 +{\footnotesize\begin{verbatim}
   1.694 +   sort_def   "sort ls = foldr ins ls []"
   1.695 +
   1.696 +   ins_base   "ins [] a = [a]"
   1.697 +   ins_rec    "ins (x#xs) a = (if x < a then x#(ins xs a) else a#(x#xs))"  
   1.698 +
   1.699 +   foldr_base "foldr f [] a = a"
   1.700 +   foldr_rec  "foldr f (x#xs) a = foldr f xs (f a x)"
   1.701 +
   1.702 +   if_True    "(if True then ?x else ?y) = ?x"
   1.703 +   if_False   "(if False then ?x else ?y) = ?y"
   1.704 +\end{verbatim}}%size
   1.705 +{\tt\#} ist ein Listenersteller, {\tt foldr} ist die bekannte Funktion beim funktionellen Programmieren und {\tt if\_True, if\_False} sind die Hilfsregeln. Dann kann das Sortieren mit den folgenden Umschreibungen durchgef\"uhrt werden.
   1.706 +{\footnotesize\begin{verbatim}
   1.707 +   ML>  val thy' = "InsSort.thy";
   1.708 +   val thy' = "InsSort.thy" : theory'
   1.709 +   ML>  val ct = "sort [#1,#3,#2]" : cterm';
   1.710 +   val ct = "sort [#1,#3,#2]" : cterm'
   1.711 +   ML>
   1.712 +   ML>  val thm = ("sort_def","");
   1.713 +   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
   1.714 +   val ct = "foldr ins [#1, #3, #2] []" : cterm'
   1.715 +   ML>
   1.716 +   ML>  val thm = ("foldr_rec","");
   1.717 +   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
   1.718 +   val ct = "foldr ins [#3, #2] (ins [] #1)" : cterm'
   1.719 +   ML>
   1.720 +   ML>  val thm = ("ins_base","");
   1.721 +   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
   1.722 +   val ct = "foldr ins [#3, #2] [#1]" : cterm'
   1.723 +   ML>
   1.724 +   ML>  val thm = ("foldr_rec","");
   1.725 +   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
   1.726 +   val ct = "foldr ins [#2] (ins [#1] #3)" : cterm'
   1.727 +   ML>
   1.728 +   ML>  val thm = ("ins_rec","");
   1.729 +   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
   1.730 +   val ct = "foldr ins [#2] (if #1 < #3 then #1 # ins [] #3 else [#3, #1])"
   1.731 +     : cterm'
   1.732 +   ML>
   1.733 +   ML>  val (ct,_) = the (calculate' thy' "le" ct);
   1.734 +   val ct = "foldr ins [#2] (if True then #1 # ins [] #3 else [#3, #1])" : cterm'
   1.735 +   ML>
   1.736 +   ML>  val thm = ("if_True","(if True then ?x else ?y) = ?x");
   1.737 +   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
   1.738 +   val ct = "foldr ins [#2] (#1 # ins [] #3)" : cterm'
   1.739 +   ML> 
   1.740 +   ...
   1.741 +   val ct = "sort [#1,#3,#2]" : cterm'
   1.742 +\end{verbatim}}%size
   1.743 +
   1.744 +
   1.745 +\section{Varianten des Umschreibens}
   1.746 +Einige der genannten Beispiele verwendeten schon Methoden von {\tt rewrite}, welche den selben Wert haben und sehr \"ahnliche Argumente verwenden:
   1.747 +{\footnotesize\begin{verbatim}
   1.748 +   ML> rewrite_inst_;
   1.749 +   val it = fn
   1.750 +     : theory
   1.751 +       -> rew_ord
   1.752 +          -> rls
   1.753 +             -> bool
   1.754 +             -> (cterm' * cterm') list
   1.755 +                   -> thm -> term -> (term * term list) option
   1.756 +   ML> rewrite_inst;
   1.757 +   val it = fn
   1.758 +     : theory'
   1.759 +       -> rew_ord'
   1.760 +          -> rls'
   1.761 +             -> bool
   1.762 +                -> (cterm' * cterm') list
   1.763 +                   -> thm' -> cterm' -> (cterm' * cterm' list) option
   1.764 +   ML>
   1.765 +   ML> rewrite_set_;
   1.766 +   val it = fn 
   1.767 +     : theory -> rls -> bool -> rls -> term -> (term * term list) option
   1.768 +   ML> rewrite_set;
   1.769 +   val it = fn
   1.770 +     : theory' -> rls' -> bool -> rls' -> cterm' -> (cterm' * cterm' list) option
   1.771 +   ML>
   1.772 +   ML> rewrite_set_inst_;
   1.773 +   val it = fn
   1.774 +     : theory
   1.775 +       -> rls
   1.776 +          -> bool
   1.777 +             -> (cterm' * cterm') list
   1.778 +                -> rls -> term -> (term * term list) option
   1.779 +   ML> rewrite_set_inst;
   1.780 +   val it = fn
   1.781 +     : theory'
   1.782 +       -> rls'
   1.783 +          -> bool
   1.784 +             -> (cterm' * cterm') list
   1.785 +                -> rls' -> cterm' -> (cterm' * cterm' list) option
   1.786 +\end{verbatim}}%size
   1.787 +
   1.788 +\noindent Die Variante {\tt rewrite\_inst} \"andert {\tt (term * term) list} zu {\tt thm} vor dem Umschreiben,\\
   1.789 +Die Variante {\tt rewrite\_set} umschreibt {\tt rls} mit einem ganzen Regelsatz (anstatt mit {\tt thm}),\\
   1.790 +Die Variante {\tt rewrite\_set\_inst} ist eine Kombination aus den letzten zwei Varianten. Um zu sehen wie ein Ausdruck umgeschreiben wird, gibt es einen Schalter {\tt trace\_rewrite}:
   1.791 +{\footnotesize\begin{verbatim}
   1.792 +   ML> toggle;
   1.793 +   val it = fn : bool ref -> bool
   1.794 +   ML>
   1.795 +   ML> toggle trace_rewrite;
   1.796 +   val it = true : bool
   1.797 +   ML> toggle trace_rewrite;
   1.798 +   val it = false : bool
   1.799 +\end{verbatim}}%size
   1.800 +
   1.801 +\section{Regels\"atze}
   1.802 +Eine Varianten von {\tt rewrite} oberhalb gelten nicht nur für einen Lehrsatz, sondern für eine Vielzahl von Lehrs\"atzen, die 'Regels\"atze' genannt werden. Ein Regelsatz wird so lange angewendet, bis eines seiner Elemente f\"ur das Umschreiben verwendet werden kann (das kann ewig dauern, zum Beispiel, wenn ein Regelsatz nicht endet).
   1.803 +
   1.804 +Ein einfaches Beispiel für einen Regelsatz ist {\tt rearrange\_assoc}, welches in {\tt knowledge/RatArith.ML} beschrieben wird:
   1.805 +{\footnotesize\begin{verbatim}
   1.806 +   val rearrange_assoc = 
   1.807 +     Rls{preconds = [], rew_ord = ("tless_true",tless_true), 
   1.808 +         rules = 
   1.809 +         [Thm ("radd_assoc_RS_sym",num_str (radd_assoc RS sym)),
   1.810 +          Thm ("rmult_assoc_RS_sym",num_str (rmult_assoc RS sym))],
   1.811 +         scr = Script ((term_of o the o (parse thy)) 
   1.812 +         "empty_script")
   1.813 +         }:rls;
   1.814 +\end{verbatim}}%size
   1.815 +
   1.816 +\begin{description}
   1.817 +\item [\tt preconds] sind Bedinungen, die zutreffen m\"ussen, um den Regelsatz anwendbar zu machen (eine leere Liste berechnet {\tt true}).
   1.818 +\item [\tt rew\_ord] betrifft die Anordnung der Ausdr\"ucke, dei weiter unten in \ref{term-order} vorgestellt werden.
   1.819 +\item [\tt rules] sind die angewandten Lehrs\"atze -- grunds\"atzlich in beliebiger Anordnung, weil die Regels\"atze vervollst\"andigt werden sollten \cite{nipk:rew-all-that} (und die Lehrs\"atze werden tats\"achlich in der Reihenfolge, in der sie auf der Liste erscheinen, angewendet). Die Funktion {\tt num\_str}, muss bei den Lehrs\"atzen, die viele Konstanten enthalten, angewendet werden (und demnach ist das bei diesem Beispiel veraltert). {\tt RS} ist eine eingef\"ugte Funktion, die im Lehrsatz {\tt sym} zu {\tt radd\_assoc} vor der Abspeicherung angewendet wird (siehe 'Effekt')
   1.820 +\item [\tt scr] auch wenn das script den Regelsatz anwendet, wird es in späteren Versionen von \isac verschwinden.
   1.821 +\end{description}
   1.822 +Diese Variablen bestimmen folgendes:
   1.823 +{\footnotesize\begin{verbatim}
   1.824 +   ML> sym;
   1.825 +   val it = "?s = ?t ==> ?t = ?s" : thm 
   1.826 +   ML> rearrange_assoc;
   1.827 +   val it =
   1.828 +     Rls
   1.829 +       {preconds=[],rew_ord=("tless_true",fn),
   1.830 +        rules=[Thm ("radd_assoc_RS_sym","?m1 + (?n1 + ?k1) = ?m1 + ?n1 + ?k1"),
   1.831 +               Thm ("rmult_assoc_RS_sym","?m1 * (?n1 * ?k1) = ?m1 * ?n1 * ?k1")],
   1.832 +        scr=Script (Free ("empty_script","RealDef.real"))} : rls 
   1.833 +\end{verbatim}}%size
   1.834 +
   1.835 +\paragraph{Versuchen Sie es!} Der obengenannte Regel-Satz l\"asst eine beliebige Zahl von Parenthesen verschwinden, die auf Grund von Assoziation auf {\tt +} nicht notwendig sind. 
   1.836 +{\footnotesize\begin{verbatim}
   1.837 +   ML> val ct = (string_of_cterm o the o (parse RatArith.thy))
   1.838 +                "a + (b * (c * d) + e)";
   1.839 +   val ct = "a + ((b * (c * d) + e) + f)" : cterm'
   1.840 +   ML> rewrite_set "RatArith.thy" "eval_rls" false "rearrange_assoc" ct;
   1.841 +   val it = Some ("a + b * c * d + e + f",[]) : (string * string list) option
   1.842 +\end{verbatim}}%size
   1.843 +Um dieses Ergebnis zu erreichen muss der Regelsatz \"uberraschend schnell sein:
   1.844 +{\footnotesize\begin{verbatim}
   1.845 +   ML> toggle trace_rewrite;
   1.846 +   val it = true : bool
   1.847 +   ML> rewrite_set "RatArith.thy" "eval_rls" false "rearrange_assoc" ct;
   1.848 +   ### trying thm 'radd_assoc_RS_sym'
   1.849 +   ### rewrite_set_: a + b * (c * d) + e
   1.850 +   ### trying thm 'radd_assoc_RS_sym'
   1.851 +   ### trying thm 'rmult_assoc_RS_sym'
   1.852 +   ### rewrite_set_: a + b * c * d + e
   1.853 +   ### trying thm 'rmult_assoc_RS_sym'
   1.854 +   ### trying thm 'radd_assoc_RS_sym'
   1.855 +   ### trying thm 'rmult_assoc_RS_sym'
   1.856 +   val it = Some ("a + b * c * d + e",[]) : (string * string list) option
   1.857 +\end{verbatim}}%size
   1.858 + 
   1.859 +
   1.860 +\section{Berechnung von numerischen Konstanten}
   1.861 +Sobald numerische Konstanten in angrenzenden Subfristen sind, können sie durch die Funktion berechnet werden (siehe p.\pageref{cond-rew}):
   1.862 +{\footnotesize\begin{verbatim}
   1.863 +   ML> calculate;
   1.864 +   val it = fn : theory' -> string -> cterm' -> (cterm' * thm') option
   1.865 +   ML> calculate_;
   1.866 +   val it = fn : theory -> string -> term -> (term * (string * thm)) option
   1.867 +\end{verbatim}}%size
   1.868 +{\tt string} beschreibt in den Angaben die mathematisch zu berechnende Operation. Die Funktion gibt das Ergebnis der Berechnung, und als zweites Element in der Reihe gilt der Lehrsatz. Die folgenden mathematischen Operationen sind verfügbar:
   1.869 +{\footnotesize\begin{verbatim}
   1.870 +   ML> calc_list;
   1.871 +   val it =
   1.872 +     ref
   1.873 +       [("plus",("op +",fn)),
   1.874 +        ("times",("op *",fn)),
   1.875 +        ("cancel_",("cancel",fn)),
   1.876 +        ("power",("pow",fn)),
   1.877 +        ("sqrt",("sqrt",fn)),
   1.878 +        ("Var",("Var",fn)),
   1.879 +        ("Length",("Length",fn)),
   1.880 +        ("Nth",("Nth",fn)),
   1.881 +        ("power",("pow",fn)),
   1.882 +        ("le",("op <",fn)),
   1.883 +        ("leq",("op <=",fn)),
   1.884 +        ("is_const",("is'_const",fn)),
   1.885 +        ("is_root_free",("is'_root'_free",fn)),
   1.886 +        ("contains_root",("contains'_root",fn)),
   1.887 +        ("ident",("ident",fn))]
   1.888 +     : (string * (string * (string -> term -> theory -> 
   1.889 +        (string * term) option))) list ref
   1.890 +\end{verbatim}}%size
   1.891 +Diese Vorgänge k\"onnen so verwendet werden:
   1.892 +{\footnotesize\begin{verbatim}
   1.893 +   ML> calculate' "Isac.thy" "plus" "#1 + #2";
   1.894 +   val it = Some ("#3",("#add_#1_#2","\"#1 + #2 = #3\"")) : (string * thm') option
   1.895 +   ML>
   1.896 +   ML> calculate' "Isac.thy" "times" "#2 * #3";
   1.897 +   val it = Some ("#6",("#mult_#2_#3","\"#2 * #3 = #6\""))
   1.898 +     : (string * thm') option
   1.899 +   ML>
   1.900 +   ML> calculate' "Isac.thy" "power" "#2 ^^^ #3";
   1.901 +   val it = Some ("#8",("#power_#2_#3","\"#2 ^^^ #3 = #8\""))
   1.902 +     : (string * thm') option
   1.903 +   ML>
   1.904 +   ML> calculate' "Isac.thy" "cancel_" "#9 // #12";
   1.905 +   val it = Some ("#3 // #4",("#cancel_#9_#12","\"#9 // #12 = #3 // #4\""))
   1.906 +     : (string * thm') option
   1.907 +   ML>
   1.908 +   ML> ...
   1.909 +\end{verbatim}}%size
   1.910 +          
   1.911 +
   1.912 +
   1.913 +\chapter{Begriff-Ordnung}\label{term-order}
   1.914 +Die Anordnungen der Terme sind unverzichtbar f\"ur den Gebrauch des Umschreibens von normalen Funktionen in inhaltsorientierten - kommunikativen Breichen, wie \cite{nipk:rew-all-that}, und zum Umschreiben von normalen Formeln, die n\"otig sind um passende Modelle f\"ur Probleme zu finden, siehe \ref{pbt}.
   1.915 +\section{Beispiel f\"ur Begriff-Ordnungen}
   1.916 +Es ist nicht unbedeutend, eine Verbindung $<$ zu Termen herzustellen, die wirklich eine Anordnung besitzen, wie eine transitive und antisymmetrische Verbindung. Diese Anordnungen sind 'rekursive Bahnanordnungen' \cite{nipk:rew-all-that}. Einige Anordnungen sind im Basiswissen bei {\tt [isac-src]/knowledge/\dots}, angeführt. %FIXXXmat0201a
   1.917 +unter anderem
   1.918 +{\footnotesize\begin{verbatim}
   1.919 +   ML> sqrt_right;
   1.920 +   val it = fn : bool -> theory -> term * term -> bool
   1.921 +   ML> tless_true;
   1.922 +   val it = fn : 'a -> bool 
   1.923 +\end{verbatim}}%size
   1.924 +Das bool Argument ist ein Schalter um die Kontrolle zur\"uck zu den zugeh\"origen Unterordnungen zu verfolgen (diese Theorie ist notwendig um die Unterordnungen als strings, sollten sie 'true' sein, anzuzeigen). Die Anordnung {\tt tless\_true} ist belanglos und tr\"agt immer {\tt true}, und {\tt sqrt\_right} bevorzugt eine Quadratwurzel, die nach rechts im Ausdruck geschoben wird:
   1.925 +{\footnotesize\begin{verbatim}
   1.926 +   ML> val t1 = (term_of o the o (parse thy)) "(sqrt a) + b";
   1.927 +   val t1 = Const # $ (# $ #) $ Free (#,#) : term
   1.928 +   ML>
   1.929 +   ML> val t2 = (term_of o the o (parse thy)) "b + (sqrt a)";
   1.930 +   val t2 = Const # $ Free # $ (Const # $ Free #) : term
   1.931 +   ML>
   1.932 +   ML> sqrt_right false SqRoot.thy (t1, t2);
   1.933 +   val it = false : bool
   1.934 +   ML> sqrt_right false SqRoot.thy (t2, t1);
   1.935 +   val it = true : bool
   1.936 +\end{verbatim}}%size
   1.937 +Die vielen Kontrollen, die rekursiv durch alle Subbegriffe durchgef\"uhrt werden, können überall im Algorithmus in {\tt [isac-src]/knowledge/SqRoot.ML} verfolgt werden, wenn man die flag auf true setzt:
   1.938 +{\footnotesize\begin{verbatim}
   1.939 +   ML> val t1 = (term_of o the o (parse thy)) "a + b*(sqrt c) + d";
   1.940 +   val t1 = Const (#,#) $ (# $ # $ (# $ #)) $ Free ("d","RealDef.real") : term
   1.941 +   ML>
   1.942 +   ML> val t2 = (term_of o the o (parse thy)) "a + (sqrt b)*c + d";
   1.943 +   val t2 = Const (#,#) $ (# $ # $ (# $ #)) $ Free ("d","RealDef.real") : term
   1.944 +   ML>
   1.945 +   ML> sqrt_right true SqRoot.thy (t1, t2);
   1.946 +   t= f@ts= "op +" @ "[a + b * sqrt c,d]"
   1.947 +   u= g@us= "op +" @ "[a + sqrt b * c,d]"
   1.948 +   size_of_term(t,u)= (8, 8)
   1.949 +   hd_ord(f,g)      = EQUAL
   1.950 +   terms_ord(ts,us) = LESS
   1.951 +   -------
   1.952 +   t= f@ts= "op +" @ "[a,b * sqrt c]"
   1.953 +   u= g@us= "op +" @ "[a,sqrt b * c]"
   1.954 +   size_of_term(t,u)= (6, 6)
   1.955 +   hd_ord(f,g)      = EQUAL
   1.956 +   terms_ord(ts,us) = LESS
   1.957 +   -------
   1.958 +   t= f@ts= "a" @ "[]"
   1.959 +   u= g@us= "a" @ "[]"
   1.960 +   size_of_term(t,u)= (1, 1)
   1.961 +   hd_ord(f,g)      = EQUAL
   1.962 +   terms_ord(ts,us) = EQUAL
   1.963 +   -------
   1.964 +   t= f@ts= "op *" @ "[b,sqrt c]"
   1.965 +   u= g@us= "op *" @ "[sqrt b,c]"
   1.966 +   size_of_term(t,u)= (4, 4)
   1.967 +   hd_ord(f,g)      = EQUAL
   1.968 +   terms_ord(ts,us) = LESS
   1.969 +   -------
   1.970 +   t= f@ts= "b" @ "[]"
   1.971 +   u= g@us= "sqrt" @ "[b]"
   1.972 +   size_of_term(t,u)= (1, 2)
   1.973 +   hd_ord(f,g)      = LESS
   1.974 +   terms_ord(ts,us) = LESS
   1.975 +   -------
   1.976 +   val it = true : bool 
   1.977 +\end{verbatim}}%size
   1.978 +
   1.979 +
   1.980 +
   1.981 +\section{Geordnetes Umschreiben}
   1.982 +Das Umschreiben beinhaltet in fast allen elementaren Bereichen Probleme, die alle assoziieren und ausgewechselt werden k\"onnen, im Bezug auf {\tt +} und {\tt *} --- Das Gesetz der Wandelbarkeit angewendet mit einem Regelsatzes, veranlasst den Satz, nicht zu enden! Ein Weg mit dieser Schwierigkeit umzugehen ist das geordnete Umschreiben, bei dem die Umschreibung erst beendet ist, wenn der Begriff des Ergebnisses kleiner ist, im Bezug auf eine Begriff-Ordnung (mit einigen zus\"atzlichen Eigenschaften, die 'rewrite orders' \cite{nipk:rew-all-that} genannt werden).
   1.983 +
   1.984 +Ein solcher Regelsatz {\tt ac\_plus\_times}, der als AC-rewrite system bezeichnet wird, kann in {\tt[isac-src]/knowledge/RathArith.ML} gefunden werden:
   1.985 +{\footnotesize\begin{verbatim}
   1.986 +   val ac_plus_times =
   1.987 +     Rls{preconds = [], rew_ord = ("term_order",term_order),
   1.988 +         rules =
   1.989 +         [Thm ("radd_commute",radd_commute),
   1.990 +          Thm ("radd_left_commute",radd_left_commute),
   1.991 +          Thm ("radd_assoc",radd_assoc),
   1.992 +          Thm ("rmult_commute",rmult_commute),
   1.993 +          Thm ("rmult_left_commute",rmult_left_commute),
   1.994 +          Thm ("rmult_assoc",rmult_assoc)],
   1.995 +         scr = Script ((term_of o the o (parse thy))
   1.996 +         "empty_script")
   1.997 +         }:rls;
   1.998 +   val ac_plus_times =
   1.999 +     Rls
  1.1000 +       {preconds=[],rew_ord=("term_order",fn),
  1.1001 +        rules=[Thm ("radd_commute","?m + ?n = ?n + ?m"),
  1.1002 +               Thm ("radd_left_commute","?x + (?y + ?z) = ?y + (?x + ?z)"),
  1.1003 +               Thm ("radd_assoc","?m + ?n + ?k = ?m + (?n + ?k)"),
  1.1004 +               Thm ("rmult_commute","?m * ?n = ?n * ?m"),
  1.1005 +               Thm ("rmult_left_commute","?x * (?y * ?z) = ?y * (?x * ?z)"),
  1.1006 +               Thm ("rmult_assoc","?m * ?n * ?k = ?m * (?n * ?k)")],
  1.1007 +        scr=Script (Free ("empty_script","RealDef.real"))} : rls 
  1.1008 +\end{verbatim}}%size
  1.1009 +Beachten Sie, dass die Lehrs\"atze {\tt radd\_left\_commute} und {\tt rmult\_left\_commute} notwendig sind, um den Regelsatz 'confluent' zu machen!
  1.1010 +
  1.1011 +
  1.1012 +\paragraph{Versuchen Sie es!} Das geordnete Umschreiben ist eine Technik um ein normales Polynom von willk\"urlich, ganzzahligen Termen zu schafffen.:
  1.1013 +{\footnotesize\begin{verbatim}
  1.1014 +   ML> val ct' = "#3 * a + b + #2 * a";
  1.1015 +   val ct' = "#3 * a + b + #2 * a" : cterm'
  1.1016 +   ML>
  1.1017 +   ML> (*-1-*) radd_commute; val thm' = ("radd_commute","") : thm';
  1.1018 +   val it = "?m + ?n = ?n + ?m" : thm
  1.1019 +   val thm' = ("radd_commute","") : thm'
  1.1020 +   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
  1.1021 +   val ct' = "#2 * a + (#3 * a + b)" : cterm'
  1.1022 +   ML>
  1.1023 +   ML> (*-2-*) rdistr_right_assoc_p; val thm' = ("rdistr_right_assoc_p","") : thm';
  1.1024 +   val it = "?l * ?n + (?m * ?n + ?k) = (?l + ?m) * ?n + ?k" : thm
  1.1025 +   val thm' = ("rdistr_right_assoc_p","") : thm'
  1.1026 +   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
  1.1027 +   val ct' = "(#2 + #3) * a + b" : cterm'
  1.1028 +   ML>
  1.1029 +   ML> (*-3-*)
  1.1030 +   ML> val Some (ct',_) = calculate thy' "plus" ct';
  1.1031 +   val ct' = "#5 * a + b" : cterm'
  1.1032 +\end{verbatim}}%size %FIXXXmat0201b ... calculate !
  1.1033 +Das sieht toll aus, aber wenn {\tt radd\_commute} automatisch angewendet wird {\tt (*-1-*)} ohne zu \"uberpr\"ufen, ob ide daraus entstehenden Terme kleiner werden im Bezug auf die Begriffsordnung, dann geht das Umschreiben endlos weiter. (das heißt, es wird nicht beendet) \dots
  1.1034 +{\footnotesize\begin{verbatim}
  1.1035 +   ML> val ct' = "#3 * a + b + #2 * a" : cterm';
  1.1036 +   val ct' = "#3 * a + b + #2 * a" : cterm'
  1.1037 +   ML> val thm' = ("radd_commute","") : thm';
  1.1038 +   val thm' = ("radd_commute","") : thm'
  1.1039 +   ML>
  1.1040 +   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
  1.1041 +   val ct' = "#2 * a + (#3 * a + b)" : cterm'
  1.1042 +   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
  1.1043 +   val ct' = "#3 * a + b + #2 * a" : cterm'
  1.1044 +   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
  1.1045 +   val ct' = "#2 * a + (#3 * a + b)" : cterm'
  1.1046 +              ..........
  1.1047 +\end{verbatim}}%size
  1.1048 +
  1.1049 +Geordnetes Umschreiben mit dem obrigen AC-rewrite system {\tt ac\_plus\_times} verursacht eine Art Durcheinander, dem man auf die Spur kommen kann:
  1.1050 +{\footnotesize\begin{verbatim}
  1.1051 +   ML> toggle trace_rewrite;
  1.1052 +   val it = true : bool
  1.1053 +   ML>
  1.1054 +   ML> rewrite_set "RatArith.thy" "eval_rls" false "ac_plus_times" ct;
  1.1055 +   ### trying thm 'radd_commute'
  1.1056 +   ### not: "a + (b * (c * d) + e)" > "b * (c * d) + e + a"
  1.1057 +   ### rewrite_set_: a + (e + b * (c * d))
  1.1058 +   ### trying thm 'radd_commute'
  1.1059 +   ### not: "a + (e + b * (c * d))" > "e + b * (c * d) + a"
  1.1060 +   ### not: "e + b * (c * d)" > "b * (c * d) + e"
  1.1061 +   ### trying thm 'radd_left_commute'
  1.1062 +   ### not: "a + (e + b * (c * d))" > "e + (a + b * (c * d))"
  1.1063 +   ### trying thm 'radd_assoc'
  1.1064 +   ### trying thm 'rmult_commute'
  1.1065 +   ### not: "b * (c * d)" > "c * d * b"
  1.1066 +   ### not: "c * d" > "d * c"
  1.1067 +   ### trying thm 'rmult_left_commute'
  1.1068 +   ### not: "b * (c * d)" > "c * (b * d)"
  1.1069 +   ### trying thm 'rmult_assoc'
  1.1070 +   ### trying thm 'radd_commute'
  1.1071 +   ### not: "a + (e + b * (c * d))" > "e + b * (c * d) + a"
  1.1072 +   ### not: "e + b * (c * d)" > "b * (c * d) + e"
  1.1073 +   ### trying thm 'radd_left_commute'
  1.1074 +   ### not: "a + (e + b * (c * d))" > "e + (a + b * (c * d))"
  1.1075 +   ### trying thm 'radd_assoc'
  1.1076 +   ### trying thm 'rmult_commute'
  1.1077 +   ### not: "b * (c * d)" > "c * d * b"
  1.1078 +   ### not: "c * d" > "d * c"
  1.1079 +   ### trying thm 'rmult_left_commute'
  1.1080 +   ### not: "b * (c * d)" > "c * (b * d)"
  1.1081 +   ### trying thm 'rmult_assoc'
  1.1082 +   val it = Some ("a + (e + b * (c * d))",[]) : (string * string list) option     \end{verbatim}}%size
  1.1083 +Beachten Sie, dass {\tt +} nach links ausgerichtet ist, bei dem die Parenthesen f\"ur {\tt (a + b) + c = a + b + c}, aber nicht f\"ur {\tt a + (b + c)} weggelassen werden. Geordnetes Umschreiben endet unbedingt mit Parenthesen, die auf Grund der Assoziation weggelassen werden k\"onnen.
  1.1084 +
  1.1085 +
  1.1086 +\chapter{The hierarchy of problem types}\label{pbt}
  1.1087 +\section{The standard-function for 'matching'}
  1.1088 +Matching \cite{nipk:rew-all-that} is a technique used within rewriting, and used by \isac{} also for (a generalized) 'matching' a problem with a problem type. The function which tests for matching has the following signature:
  1.1089 +{\footnotesize\begin{verbatim}
  1.1090 +   ML> matches;
  1.1091 +   val it = fn : theory -> term -> term -> bool
  1.1092 +\end{verbatim}}%size
  1.1093 +where the first of the two {\tt term} arguments is the particular term to be tested, and the second one is the pattern:
  1.1094 +{\footnotesize\begin{verbatim}
  1.1095 +   ML> val t = (term_of o the o (parse thy)) "#3 * x^^^#2 = #1";
  1.1096 +   val t = Const (#,#) $ (# $ # $ (# $ #)) $ Free ("#1","RealDef.real") : term
  1.1097 +   ML>
  1.1098 +   ML> val p = (term_of o the o (parse thy)) "a * b^^^#2 = c";
  1.1099 +   val p = Const (#,#) $ (# $ # $ (# $ #)) $ Free ("c","RealDef.real") : term
  1.1100 +   ML> atomt p;
  1.1101 +   *** -------------
  1.1102 +   *** Const ( op =)
  1.1103 +   *** . Const ( op *)
  1.1104 +   *** . . Free ( a, )
  1.1105 +   *** . . Const ( RatArith.pow)
  1.1106 +   *** . . . Free ( b, )
  1.1107 +   *** . . . Free ( #2, )
  1.1108 +   *** . Free ( c, )
  1.1109 +   val it = () : unit
  1.1110 +   ML>
  1.1111 +   ML> free2var;
  1.1112 +   val it = fn : term -> term
  1.1113 +   ML>
  1.1114 +   ML> val pat = free2var p;
  1.1115 +   val pat = Const (#,#) $ (# $ # $ (# $ #)) $ Var ((#,#),"RealDef.real") : term
  1.1116 +   ML> Sign.string_of_term (sign_of thy) pat;
  1.1117 +   val it = "?a * ?b ^^^ #2 = ?c" : cterm' 
  1.1118 +   ML> atomt pat;
  1.1119 +   *** -------------
  1.1120 +   *** Const ( op =)
  1.1121 +   *** . Const ( op *)
  1.1122 +   *** . . Var ((a, 0), )
  1.1123 +   *** . . Const ( RatArith.pow)
  1.1124 +   *** . . . Var ((b, 0), )
  1.1125 +   *** . . . Free ( #2, )
  1.1126 +   *** . Var ((c, 0), )
  1.1127 +   val it = () : unit
  1.1128 +\end{verbatim}}%size % $ 
  1.1129 +Note that the pattern {\tt pat} contains so-called {\it scheme variables} decorated with a {\tt ?} (analoguous to theorems). The pattern is generated by the function {\tt free2var}. This format of the pattern is necessary in order to obtain results like these:
  1.1130 +{\footnotesize\begin{verbatim}
  1.1131 +   ML> matches thy t pat;
  1.1132 +   val it = true : bool
  1.1133 +   ML>
  1.1134 +   ML> val t2 = (term_of o the o (parse thy)) "x^^^#2 = #1";
  1.1135 +   val t2 = Const (#,#) $ (# $ # $ Free #) $ Free ("#1","RealDef.real") : term
  1.1136 +   ML> matches thy t2 pat;
  1.1137 +   val it = false : bool    
  1.1138 +   ML>
  1.1139 +   ML> val pat2 = (term_of o the o (parse thy)) "?u^^^#2 = ?v";
  1.1140 +   val pat2 = Const (#,#) $ (# $ # $ Free #) $ Var ((#,#),"RealDef.real") : term
  1.1141 +   ML> matches thy t2 pat2;
  1.1142 +   val it = true : bool 
  1.1143 +\end{verbatim}}%size % $
  1.1144 +
  1.1145 +\section{Accessing the hierarchy}
  1.1146 +The hierarchy of problem types is encapsulated; it can be accessed by the following functions. {\tt show\_ptyps} retrieves all leaves of the hierarchy (here in an early version for testing):
  1.1147 +{\footnotesize\begin{verbatim}
  1.1148 +   ML> show_ptyps;
  1.1149 +   val it = fn : unit -> unit
  1.1150 +   ML> show_ptyps();
  1.1151 +   [
  1.1152 +    ["e_pblID"],
  1.1153 +    ["equation", "univariate", "linear"],
  1.1154 +    ["equation", "univariate", "plain_square"],
  1.1155 +    ["equation", "univariate", "polynomial", "degree_two", "pq_formula"],
  1.1156 +    ["equation", "univariate", "polynomial", "degree_two", "abc_formula"],
  1.1157 +    ["equation", "univariate", "squareroot"],
  1.1158 +    ["equation", "univariate", "normalize"],
  1.1159 +    ["equation", "univariate", "sqroot-test"],
  1.1160 +    ["function", "derivative_of"],
  1.1161 +    ["function", "maximum_of", "on_interval"],
  1.1162 +    ["function", "make"],
  1.1163 +    ["tool", "find_values"],
  1.1164 +    ["functional", "inssort"]
  1.1165 +   ]
  1.1166 +   val it = () : unit
  1.1167 +\end{verbatim}}%size
  1.1168 +The retrieve function for individual problem types is {\tt get\_pbt}
  1.1169 +\footnote{A function providing better readable output is in preparation}. Note that its argument, the 'problem identifier' {\tt pblID}, has the strings listed in reverse order w.r.t. the hierarchy, i.e. from the leave to the root. This order makes the {\tt pblID} closer to a natural description:
  1.1170 +{\footnotesize\begin{verbatim}
  1.1171 +   ML> get_pbt;
  1.1172 +   val it = fn : pblID -> pbt
  1.1173 +   ML> get_pbt ["squareroot", "univariate", "equation"];
  1.1174 +   val it =
  1.1175 +     {met=[("SqRoot.thy","square_equation")],
  1.1176 +      ppc=[("#Given",(Const (#,#),Free (#,#))),
  1.1177 +           ("#Given",(Const (#,#),Free (#,#))),
  1.1178 +           ("#Given",(Const (#,#),Free (#,#))),
  1.1179 +           ("#Find",(Const (#,#),Free (#,#)))],
  1.1180 +      thy={ProtoPure, CPure, HOL, Ord, Set, subset, equalities, mono, Vimage, Fun,
  1.1181 +            Prod, Lfp, Relation, Trancl, WF, NatDef, Gfp, Sum, Inductive, Nat,
  1.1182 +            Arith, Divides, Power, Finite, Equiv, IntDef, Int, Univ, Datatype,
  1.1183 +            Numeral, Bin, IntArith, WF_Rel, Recdef, IntDiv, NatBin, List, Option,
  1.1184 +            Map, Record, RelPow, Sexp, String, Calculation, SVC_Oracle, Main,
  1.1185 +            Zorn, Filter, PNat, PRat, PReal, RealDef, RealOrd, RealInt, RealBin,
  1.1186 +            HyperDef, Descript, ListG, Tools, Script, Typefix, Atools, RatArith,
  1.1187 +            SqRoot},
  1.1188 +      where_=[Const ("SqRoot.contains'_root","bool => bool") $
  1.1189 +              Free ("e_","bool")]} : pbt
  1.1190 +\end{verbatim}}%size %$
  1.1191 +where the records fields hold the following data:
  1.1192 +\begin{description}
  1.1193 +\item [\tt thy]: the theory necessary for parsing the formulas
  1.1194 +\item [\tt ppc]: the items of the problem type, divided into those {\tt Given}, the precondition {\tt Where} and the output item(s) {\tt Find}. The items of {\tt Given} and {\tt Find} are all headed by so-called descriptions, which determine the type. These descriptions are defined in {\tt [isac-src]/Isa99/Descript.thy}.
  1.1195 +\item [\tt met]: the list of methods solving this problem type.\\
  1.1196 +\end{description}
  1.1197 +
  1.1198 +The following function adds or replaces a problem type (after having it prepared using {\tt prep\_pbt})
  1.1199 +{\footnotesize\begin{verbatim}
  1.1200 +   ML> store_pbt;
  1.1201 +   val it = fn : pbt * pblID -> unit
  1.1202 +   ML> store_pbt
  1.1203 +    (prep_pbt SqRoot.thy
  1.1204 +    (["newtype","univariate","equation"],
  1.1205 +     [("#Given" ,["equality e_","solveFor v_","errorBound err_"]),
  1.1206 +      ("#Where" ,["contains_root (e_::bool)"]),
  1.1207 +      ("#Find"  ,["solutions v_i_"])
  1.1208 +     ],
  1.1209 +     [("SqRoot.thy","square_equation")]));
  1.1210 +   val it = () : unit
  1.1211 +\end{verbatim}}%size
  1.1212 +When adding a new type with argument {\tt pblID}, an immediate parent must already exist in the hierarchy (this is the one with the tail of {\tt pblID}).
  1.1213 +
  1.1214 +\section{Internals of the datastructure}
  1.1215 +This subsection only serves for the implementation of the hierarchy browser and can be skipped by the authors of math knowledge.
  1.1216 +
  1.1217 +A problem type is described by the following record type (in the file {\tt [isac-src]/globals.sml}, the respective functions are in {\tt [isac-src]/ME/ptyps.sml}), and held in a global reference variable:
  1.1218 +{\footnotesize\begin{verbatim}
  1.1219 +   type pbt = 
  1.1220 +        {thy   : theory,       (* the nearest to the root,
  1.1221 +                                  which allows to compile that pbt  *)
  1.1222 +         where_: term list,    (* where - predicates                *)
  1.1223 +         ppc   : ((string *    (* fields "#Given","#Find"           *)
  1.1224 +                   (term *     (* description                       *)
  1.1225 +                    term))     (* id                                *)
  1.1226 +                      list),                                        
  1.1227 +         met   : metID list};  (* methods solving the pbt           *)
  1.1228 +   datatype ptyp = 
  1.1229 +            Ptyp of string *   (* key within pblID                  *)
  1.1230 +                    pbt list * (* several pbts with different domIDs*)
  1.1231 +                    ptyp list;
  1.1232 +   val e_Ptyp = Ptyp ("empty",[],[]);
  1.1233 +   
  1.1234 +   type ptyps = ptyp list;
  1.1235 +   val ptyps = ref ([e_Ptyp]:ptyps);
  1.1236 +\end{verbatim}}%size
  1.1237 +The predicates in {\tt where\_} (i.e. the preconditions) usually are defined in the respective theory in {\tt[isac-src]/knowledge}. Most of the predicates are not defined by rewriting, but by SML-code contained in the respective {\tt *.ML} file.
  1.1238 +
  1.1239 +Each item is headed by a so-called description which provides some guidance for interactive input. The descriptions are defined in {\tt[isac-src]/Isa99/Descript.thy}.
  1.1240 +
  1.1241 +
  1.1242 +
  1.1243 +\section{Match a formalization with a problem type}\label{pbl}
  1.1244 +A formalization is {\it match}ed with a problem type which yields a problem. A formal description of this kind of {\it match}ing can be found in \\{\tt ftp://ft.ist.tugraz.at/projects/isac/publ/calculemus01.ps.gz}. A formalization of an equation is e.g.
  1.1245 +{\footnotesize\begin{verbatim}
  1.1246 +   ML> val fmz = ["equality (#1 + #2 * x = #0)",
  1.1247 +                  "solveFor x",
  1.1248 +                  "solutions L"] : fmz;
  1.1249 +   val fmz = ["equality (#1 + #2 * x = #0)","solveFor x","solutions L"] : fmz
  1.1250 +\end{verbatim}}%size
  1.1251 +Given a formalization (and a specification of the problem, i.e. a theory, a problemtype, and a method) \isac{} can solve the respective problem automatically. The formalization must match the problem type for this purpose:
  1.1252 +{\footnotesize\begin{verbatim}
  1.1253 +   ML> match_pbl;
  1.1254 +   val it = fn : fmz -> pbt -> match'
  1.1255 +   ML>
  1.1256 +   ML> match_pbl fmz (get_pbt ["univariate","equation"]);
  1.1257 +   val it =
  1.1258 +     Matches'
  1.1259 +       {Find=[Correct "solutions L"],
  1.1260 +        Given=[Correct "equality (#1 + #2 * x = #0)",Correct "solveFor x"],
  1.1261 +        Relate=[],Where=[Correct "matches (?a = ?b) (#1 + #2 * x = #0)"],With=[]}
  1.1262 +     : match'
  1.1263 +   ML>
  1.1264 +   ML> match_pbl fmz (get_pbt ["linear","univariate","equation"]);
  1.1265 +   val it =
  1.1266 +     Matches'
  1.1267 +       {Find=[Correct "solutions L"],
  1.1268 +        Given=[Correct "equality (#1 + #2 * x = #0)",Correct "solveFor x"],
  1.1269 +        Relate=[],
  1.1270 +        Where=[Correct
  1.1271 +                 "matches (          x = #0) (#1 + #2 * x = #0) |
  1.1272 +                  matches (     ?b * x = #0) (#1 + #2 * x = #0) |
  1.1273 +                  matches (?a      + x = #0) (#1 + #2 * x = #0) |
  1.1274 +                  matches (?a + ?b * x = #0) (#1 + #2 * x = #0)"],
  1.1275 +        With=[]} : match'
  1.1276 +   ML>
  1.1277 +   ML> match_pbl fmz (get_pbt ["squareroot","univariate","equation"]);
  1.1278 +   val it =
  1.1279 +     NoMatch'
  1.1280 +       {Find=[Correct "solutions L"],
  1.1281 +        Given=[Correct "equality (#1 + #2 * x = #0)",Correct "solveFor x",
  1.1282 +               Missing "errorBound err_"],Relate=[],
  1.1283 +        Where=[False "contains_root #1 + #2 * x = #0 "],With=[]} : match'
  1.1284 +\end{verbatim}}%size
  1.1285 +The above formalization does not match the problem type \\{\tt["squareroot","univariate","equation"]} which is explained by the tags:
  1.1286 +\begin{tabbing}
  1.1287 +123\=\kill
  1.1288 +\> {\tt Missing:} the item is missing in the formalization as required by the problem type\\
  1.1289 +\> {\tt Superfl:} the item is not required by the problem type\\
  1.1290 +\> {\tt Correct:} the item is correct, or the precondition ({\tt Where}) is true\\
  1.1291 +\> {\tt False:} the precondition ({\tt Where}) is false\\
  1.1292 +\> {\tt Incompl:} the item is incomlete, or not yet input.\\
  1.1293 +\end{tabbing}
  1.1294 +
  1.1295 +
  1.1296 +
  1.1297 +\section{Refine a problem specification}
  1.1298 +The challenge in constructing the problem hierarchy is, to design the branches in such a way, that problem refinement can be done automatically (as it is done in algebra system e.g. by a internal hierarchy of equations).
  1.1299 +
  1.1300 +For this purpose the hierarchy must be built using the following rules: Let $F$ be a formalization and $P$ and $P_i,\:i=1\cdots n$ problem types, where the $P_i$ are specialized problem types w.r.t. $P$ (i.e. $P$ is a parent node of $P_i$), then
  1.1301 +{\small
  1.1302 +\begin{enumerate}
  1.1303 +\item for all $F$ matching some $P_i$ must follow, that $F$ matches $P$
  1.1304 +\item an $F$ matching $P$ should not have more than {\em one} $P_i,\:i=1\cdots n-1$ with $F$ matching $P_i$ (if there are more than one $P_i$, the first one will be taken)
  1.1305 +\item for all $F$ matching some $P$ must follow, that $F$ matches $P_n$\\
  1.1306 +\end{enumerate}}%small
  1.1307 +\noindent Let us give an example for the point (1.) and (2.) first:
  1.1308 +{\footnotesize\begin{verbatim}
  1.1309 +   ML> refine;
  1.1310 +   val it = fn : fmz -> pblID -> match list
  1.1311 +   ML>
  1.1312 +   ML> val fmz = ["equality (sqrt(#9+#4*x)=sqrt x + sqrt(#5+x))",
  1.1313 +              "solveFor x","errorBound (eps=#0)",
  1.1314 +              "solutions L"];
  1.1315 +   ML>
  1.1316 +   ML> refine fmz ["univariate","equation"];
  1.1317 +   *** pass ["equation","univariate"]
  1.1318 +   *** pass ["equation","univariate","linear"]
  1.1319 +   *** pass ["equation","univariate","plain_square"]
  1.1320 +   *** pass ["equation","univariate","polynomial"]
  1.1321 +   *** pass ["equation","univariate","squareroot"]
  1.1322 +   val it =
  1.1323 +     [Matches
  1.1324 +        (["univariate","equation"],
  1.1325 +         {Find=[Correct "solutions L"],
  1.1326 +          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
  1.1327 +                 Correct "solveFor x",Superfl "errorBound (eps = #0)"],Relate=[],
  1.1328 +          Where=[Correct
  1.1329 +                   "matches (?a = ?b) (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))"],
  1.1330 +          With=[]}),
  1.1331 +      NoMatch
  1.1332 +        (["linear","univariate","equation"],
  1.1333 +         {Find=[Correct "solutions L"],
  1.1334 +          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
  1.1335 +                 Correct "solveFor x",Superfl "errorBound (eps = #0)"],Relate=[],
  1.1336 +          Where=[False "(?a + ?b * x = #0) (sqrt (#9 + #4 * x#"],
  1.1337 +          With=[]}),
  1.1338 +      NoMatch
  1.1339 +        (["plain_square","univariate","equation"],
  1.1340 +         {Find=[Correct "solutions L"],
  1.1341 +          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
  1.1342 +                 Correct "solveFor x",Superfl "errorBound (eps = #0)"],Relate=[],
  1.1343 +          Where=[False
  1.1344 +                   "matches (?a + ?b * x ^^^ #2 = #0)"],
  1.1345 +          With=[]}),
  1.1346 +      NoMatch
  1.1347 +        (["polynomial","univariate","equation"],
  1.1348 +         {Find=[Correct "solutions L"],
  1.1349 +          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
  1.1350 +                 Correct "solveFor x",Superfl "errorBound (eps = #0)"],Relate=[],
  1.1351 +          Where=[False 
  1.1352 +                 "is_polynomial_in sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x) x"],
  1.1353 +          With=[]}),
  1.1354 +      Matches
  1.1355 +        (["squareroot","univariate","equation"],
  1.1356 +         {Find=[Correct "solutions L"],
  1.1357 +          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
  1.1358 +                 Correct "solveFor x",Correct "errorBound (eps = #0)"],Relate=[],
  1.1359 +          Where=[Correct
  1.1360 +                   "contains_root sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x) "],
  1.1361 +          With=[]})] : match list
  1.1362 +\end{verbatim}}%size}%footnotesize\label{refine}
  1.1363 +This example shows, that in order to refine an {\tt["univariate","equation"]}, the formalization must match respective respective problem type (rule (1.)) and one of the descendants which should match selectively (rule (2.)).
  1.1364 +
  1.1365 +If no one of the descendants of {\tt["univariate","equation"]} match, rule (3.) comes into play: The {\em last} problem type on this level ($P_n$) provides for a special 'problem type' {\tt["normalize"]}. This node calls a method transforming the equation to a (or another) normal form, which then may match. Look at this example:
  1.1366 +{\footnotesize\begin{verbatim}
  1.1367 +   ML>  val fmz = ["equality (x+#1=#2)",
  1.1368 +               "solveFor x","errorBound (eps=#0)",
  1.1369 +               "solutions L"];
  1.1370 +   [...]
  1.1371 +   ML>
  1.1372 +   ML>  refine fmz ["univariate","equation"];
  1.1373 +   *** pass ["equation","univariate"]
  1.1374 +   *** pass ["equation","univariate","linear"]
  1.1375 +   *** pass ["equation","univariate","plain_square"]
  1.1376 +   *** pass ["equation","univariate","polynomial"]
  1.1377 +   *** pass ["equation","univariate","squareroot"]
  1.1378 +   *** pass ["equation","univariate","normalize"]
  1.1379 +   val it =
  1.1380 +     [Matches
  1.1381 +        (["univariate","equation"],
  1.1382 +         {Find=[Correct "solutions L"],
  1.1383 +          Given=[Correct "equality (x + #1 = #2)",Correct "solveFor x",
  1.1384 +                 Superfl "errorBound (eps = #0)"],Relate=[],
  1.1385 +          Where=[Correct "matches (?a = ?b) (x + #1 = #2)"],With=[]}),
  1.1386 +      NoMatch
  1.1387 +        (["linear","univariate","equation"],
  1.1388 +   [...]
  1.1389 +          With=[]}),
  1.1390 +      NoMatch
  1.1391 +        (["squareroot","univariate","equation"],
  1.1392 +         {Find=[Correct "solutions L"],
  1.1393 +          Given=[Correct "equality (x + #1 = #2)",Correct "solveFor x",
  1.1394 +                 Correct "errorBound (eps = #0)"],Relate=[],
  1.1395 +          Where=[False "contains_root x + #1 = #2 "],With=[]}),
  1.1396 +      Matches
  1.1397 +        (["normalize","univariate","equation"],
  1.1398 +         {Find=[Correct "solutions L"],
  1.1399 +          Given=[Correct "equality (x + #1 = #2)",Correct "solveFor x",
  1.1400 +                 Superfl "errorBound (eps = #0)"],Relate=[],Where=[],With=[]})]
  1.1401 +     : match list
  1.1402 +\end{verbatim}}%size
  1.1403 +The problem type $P_n$, {\tt["normalize","univariate","equation"]}, will transform the equation {\tt x + \#1 = \#2} to the normal form {\tt \#-1 + x = \#0}, which then will match {\tt["linear","univariate","equation"]}.
  1.1404 +
  1.1405 +This recursive search on the problem hierarchy can be  done within a proof state. This leads to the next section.
  1.1406 +
  1.1407 +
  1.1408 +\chapter{Methods}\label{met}
  1.1409 +A problem type can have one ore more methods solving a respective problem. A method is described by means of another new program language. The language itself looks like a simple functional language, but constructs an imperative proof-state behind the scenes (thus liberating the programer from dealing with technical details and also prohibiting incorrect construction of the proof tree). The interpreter of 'scripts' written in this language evaluates the scriptexpressions, and also delivers certain parts of the script itself for discussion with the user.
  1.1410 +
  1.1411 +\section{The scripts' syntax}
  1.1412 +The syntax of scripts follows the definition given in Backus-normal-form:
  1.1413 +{\it
  1.1414 +\begin{tabbing}
  1.1415 +123\=123\=expr ::=\=$|\;\;$\=\kill
  1.1416 +\>script ::= {\tt Script} id arg$\,^*$ = body\\
  1.1417 +\>\>arg ::= id $\;|\;\;($ ( id :: type ) $)$\\
  1.1418 +\>\>body ::= expr\\
  1.1419 +\>\>expr ::= \>\>{\tt let} id = expr $($ ; id = expr$)^*$ {\tt in} expr\\
  1.1420 +\>\>\>$|\;$\>{\tt if} prop {\tt then} expr {\tt else} expr\\
  1.1421 +\>\>\>$|\;$\>listexpr\\
  1.1422 +\>\>\>$|\;$\>id\\
  1.1423 +\>\>\>$|\;$\>seqex id\\
  1.1424 +\>\>seqex ::= \>\>{\tt While} prop {\tt Do} seqex\\
  1.1425 +\>\>\>$|\;$\>{\tt Repeat} seqex\\
  1.1426 +\>\>\>$|\;$\>{\tt Try} seqex\\
  1.1427 +\>\>\>$|\;$\>seqex {\tt Or} seqex\\
  1.1428 +\>\>\>$|\;$\>seqex {\tt @@} seqex\\
  1.1429 +\>\>\>$|\;$\>tac $($ id $|$ listexpr $)^*$\\
  1.1430 +\>\>type ::= id\\
  1.1431 +\>\>tac ::= id
  1.1432 +\end{tabbing}}
  1.1433 +where {\it id} is an identifier with the usual syntax, {\it prop} is a proposition constructed by Isabelles logical operators (see \cite{Isa-obj} {\tt [isabelle]/src/HOL/HOL.thy}), {\it listexpr} (called {\bf list-expression}) is constructed by Isabelles list functions like {\tt hd, tl, nth} described in {\tt [isabelle]/src/HOL/List.thy}, and {\it type} are (virtually) all types declared in Isabelles version 99.
  1.1434 +
  1.1435 +Expressions containing some of the keywords {\tt let}, {\tt if} etc. are called {\bf script-expressions}.
  1.1436 +
  1.1437 +Tactics {\it tac} are (curried) functions. For clarity and simplicity reasons, {\it listexpr} must not contain a {\it tac}, and {\it tac}s must not be nested,
  1.1438 +
  1.1439 +
  1.1440 +\section{Control the flow of evaluation}
  1.1441 +The flow of control is managed by the following script-expressions called {\it tacticals}.
  1.1442 +\begin{description}
  1.1443 +\item{{\tt while} prop {\tt Do} expr id} 
  1.1444 +\item{{\tt if} prop {\tt then} expr {\tt else} expr}
  1.1445 +\end{description}
  1.1446 +While the the above script-expressions trigger the flow of control by evaluating the current formula, the other expressions depend on the applicability of the tactics within their respective subexpressions (which in turn depends on the proofstate)
  1.1447 +\begin{description}
  1.1448 +\item{{\tt Repeat} expr id}
  1.1449 +\item{{\tt Try} expr id}
  1.1450 +\item{expr {\tt Or} expr id}
  1.1451 +\item{expr {\tt @@} expr id}
  1.1452 +\end{description}
  1.1453 +
  1.1454 +\begin{description}
  1.1455 +\item xxx
  1.1456 +
  1.1457 +\end{description}
  1.1458 +
  1.1459 +\chapter{Do a calculational proof}
  1.1460 +First we list all the tactics available so far (this list may be extended during further development of \isac).
  1.1461 +
  1.1462 +\section{Tactics for doing steps in calculations}
  1.1463 +\input{tactics}
  1.1464 +
  1.1465 +\section{The functionality of the math engine}
  1.1466 +A proof is being started in the math engine {\tt me} by the tactic
  1.1467 +\footnote{In the present version a tactic is of type {\tt mstep}.}
  1.1468 + {\tt Init\_Proof}, and interactively promoted by other tactics. On input of each tactic the {\tt me} returns the resulting formula and the next tactic applicable. The proof is finished, when the {\tt me} proposes {\tt End\_Proof} as the next tactic.
  1.1469 +
  1.1470 +We show a calculation (calculational proof) concerning equation solving, where the type of equation is refined automatically: The equation is given by the respective formalization ...
  1.1471 +{\footnotesize\begin{verbatim}
  1.1472 +   ML> val fmz = ["equality ((x+#1)*(x+#2)=x^^^#2+#8)","solveFor x",
  1.1473 +                  "errorBound (eps=#0)","solutions L"];
  1.1474 +   val fmz =
  1.1475 +     ["equality ((x+#1)*(x+#2)=x^^^#2+#8)","solveFor x","errorBound (eps=#0)",
  1.1476 +      "solutions L"] : string list
  1.1477 +   ML>
  1.1478 +   ML> val spec as (dom, pbt, met) = ("SqRoot.thy",["univariate","equation"],
  1.1479 +                                 ("SqRoot.thy","no_met"));
  1.1480 +   val dom = "SqRoot.thy" : string
  1.1481 +   val pbt = ["univariate","equation"] : string list
  1.1482 +   val met = ("SqRoot.thy","no_met") : string * string
  1.1483 +\end{verbatim}}%size
  1.1484 +... and the specification {\tt spec} of a domain {\tt dom}, a problem type {\tt pbt} and a method {\tt met}. Note that the equation is such, that it is not immediatly clear, what type it is in particular (it could be a polynomial of degree 2; but, for sure, the type is some specialized type of a univariate equation). Thus, no method ({\tt no\_met}) can be specified for solving the problem.
  1.1485 +
  1.1486 +Nevertheless this specification is sufficient for automatically solving the equation --- the appropriate method will be found by refinement within the hierarchy of problem types.
  1.1487 +
  1.1488 +
  1.1489 +\section{Initialize the calculation}
  1.1490 +The start of a new proof requires the following initializations: The proof state is given by a proof tree {\tt ptree} and a position {\tt pos'}; both are empty at the beginning. The tactic {\tt Init\_Proof} is, like all other tactics, paired with an identifier of type {\tt string} for technical reasons.
  1.1491 +{\footnotesize\begin{verbatim}
  1.1492 +   ML>  val (mID,m) = ("Init_Proof",Init_Proof (fmz, (dom,pbt,met)));
  1.1493 +   val mID = "Init_Proof" : string
  1.1494 +   val m =
  1.1495 +     Init_Proof
  1.1496 +       (["equality ((x+#1)*(x+#2)=x^^^#2+#8)","solveFor x","errorBound (eps=#0)",
  1.1497 +         "solutions L"],("SqRoot.thy",[#,#],(#,#))) : mstep
  1.1498 +   ML>
  1.1499 +   ML>  val (p,_,f,nxt,_,pt) = me (mID,m) e_pos' c EmptyPtree;
  1.1500 +   val p = ([],Pbl) : pos'
  1.1501 +   val f = Form' (PpcKF (0,EdUndef,0,Nundef,(#,#))) : mout
  1.1502 +   val nxt = ("Refine_Tacitly",Refine_Tacitly ["univariate","equation"])
  1.1503 +     : string * mstep
  1.1504 +   val pt =
  1.1505 +     Nd
  1.1506 +       (PblObj
  1.1507 +          {branch=#,cell=#,env=#,loc=#,meth=#,model=#,origin=#,ostate=#,probl=#,
  1.1508 +           result=#,spec=#},[]) : ptree
  1.1509 +   \end{verbatim}}%size
  1.1510 +The mathematics engine {\tt me} returns the resulting formula {\tt f} of type {\tt mout} (which in this case is a problem), the next tactic {\tt nxt}, and a new proof state ({\tt ptree}, {\tt pos'}).
  1.1511 +
  1.1512 +We can convince ourselves, that the problem is still empty, by increasing {\tt Compiler.Control.Print.printDepth}:
  1.1513 +{\footnotesize\begin{verbatim}
  1.1514 +   ML> Compiler.Control.Print.printDepth:=8; (*4 default*)
  1.1515 +   val it = () : unit
  1.1516 +   ML>
  1.1517 +   ML> f;
  1.1518 +   val it =
  1.1519 +     Form'
  1.1520 +       (PpcKF
  1.1521 +          (0,EdUndef,0,Nundef,
  1.1522 +           (Problem [],
  1.1523 +            {Find=[Incompl "solutions []"],
  1.1524 +             Given=[Incompl "equality",Incompl "solveFor"],Relate=[],
  1.1525 +             Where=[False "matches (?a = ?b) e_"],With=[]}))) : mout
  1.1526 +\end{verbatim}}%size
  1.1527 +Recall, please, the format of a problem as presented in sect.\ref{pbl} on p.\pageref{pbl}; such an 'empty' problem can be found above encapsulated by several constructors containing additional data (necessary for the dialog guide, not relevant here).\\
  1.1528 +
  1.1529 +{\it In the sequel we will omit output of the {\tt me} if it is not important for the respective context}.\\
  1.1530 +
  1.1531 +In general, the dialog guide will hide the following two tactics {\tt Refine\_Tacitly} and {\tt Model\_Problem} from the user.
  1.1532 +{\footnotesize\begin{verbatim}
  1.1533 +   ML>  nxt;
  1.1534 +   val it = ("Refine_Tacitly",Refine_Tacitly ["univariate","equation"])
  1.1535 +     : string * mstep
  1.1536 +   ML>
  1.1537 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1538 +   val nxt = ("Model_Problem",Model_Problem ["normalize","univariate","equation"])
  1.1539 +     : string * mstep
  1.1540 +   ML>
  1.1541 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1542 +\end{verbatim}}%size
  1.1543 +
  1.1544 +
  1.1545 +\section{The phase of modeling} 
  1.1546 +comprises the input of the items of the problem; the {\tt me} can help by use of the formalization tacitly transferred by {\tt Init\_Proof}. In particular, the {\tt me} in general 'knows' the next promising tactic; the first one has been returned by the (hidden) tactic {\tt Model\_Problem}.
  1.1547 +
  1.1548 +{\footnotesize\begin{verbatim}
  1.1549 +   ML>  nxt;
  1.1550 +   val it =
  1.1551 +     ("Add_Given",Add_Given "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)")
  1.1552 +     : string * mstep
  1.1553 +   ML>
  1.1554 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1555 +   val nxt = ("Add_Given",Add_Given "solveFor x") : string * mstep
  1.1556 +   ML>
  1.1557 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1558 +   val nxt = ("Add_Find",Add_Find "solutions L") : string * mstep
  1.1559 +   ML>
  1.1560 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt; 
  1.1561 +   val f = Form' (PpcKF (0,EdUndef,0,Nundef,(#,#))) : mout
  1.1562 +\end{verbatim}}%size
  1.1563 +\noindent Now the problem is 'modeled', all items are input. We convince ourselves by increasing {\tt Compiler.Control.Print.printDepth} once more.
  1.1564 +{\footnotesize\begin{verbatim}
  1.1565 +   ML>  Compiler.Control.Print.printDepth:=8;
  1.1566 +   ML>  f;
  1.1567 +   val it =
  1.1568 +     Form'
  1.1569 +       (PpcKF
  1.1570 +          (0,EdUndef,0,Nundef,
  1.1571 +           (Problem [],
  1.1572 +            {Find=[Correct "solutions L"],
  1.1573 +             Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
  1.1574 +                    Correct "solveFor x"],Relate=[],Where=[],With=[]}))) : mout
  1.1575 +\end{verbatim}}%size
  1.1576 +%One of the input items is considered {\tt Superfluous} by the {\tt me} consulting the problem type {\tt ["univariate","equation"]}. The {\tt ErrorBound}, however, could become important in case the equation only could be solved by some iteration method.
  1.1577 +
  1.1578 +\section{The phase of specification} 
  1.1579 +This phase provides for explicit determination of the domain, the problem type, and the method to be used. In particular, the search for the appropriate problem type is being supported. There are two tactics for this purpose: {\tt Specify\_Problem} generates feedback on how a candidate of a problem type matches the current problem, and {\tt Refine\_Problem} provides help by the system, if the user gets lost.
  1.1580 +{\footnotesize\begin{verbatim}
  1.1581 +ML> nxt;
  1.1582 +   val it = ("Specify_Domain",Specify_Domain "SqRoot.thy") : string * mstep
  1.1583 +   ML>
  1.1584 +   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1585 +   val nxt =
  1.1586 +     ("Specify_Problem",Specify_Problem ["normalize","univariate","equation"])
  1.1587 +     : string * mstep
  1.1588 +   val pt =
  1.1589 +     Nd
  1.1590 +       (PblObj
  1.1591 +          {branch=#,cell=#,env=#,loc=#,meth=#,model=#,origin=#,ostate=#,probl=#,
  1.1592 +              result=#,spec=#},[]) : ptree
  1.1593 +\end{verbatim}}%size
  1.1594 +The {\tt me} is smart enough to know the appropriate problem type (transferred tacitly with {\tt Init\_Proof}). In order to challenge the student, the dialog guide may hide this information; then the {\tt me} works as follows.
  1.1595 +{\footnotesize\begin{verbatim}
  1.1596 +   ML> val nxt = ("Specify_Problem",
  1.1597 +               Specify_Problem ["polynomial","univariate","equation"]);
  1.1598 +   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1599 +   val f = Form' (PpcKF (0,EdUndef,0,Nundef,(#,#))) : mout
  1.1600 +   val nxt =
  1.1601 +     ("Refine_Problem",Refine_Problem ["normalize","univariate","equation"])
  1.1602 +     : string * mstep
  1.1603 +   ML>
  1.1604 +   ML> val nxt = ("Specify_Problem",
  1.1605 +               Specify_Problem ["linear","univariate","equation"]);
  1.1606 +   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1607 +   val f =
  1.1608 +     Form'
  1.1609 +       (PpcKF
  1.1610 +          (0,EdUndef,0,Nundef,
  1.1611 +           (Problem ["linear","univariate","equation"],
  1.1612 +            {Find=[Correct "solutions L"],
  1.1613 +             Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
  1.1614 +                    Correct "solveFor x"],Relate=[],
  1.1615 +             Where=[False
  1.1616 +                    "matches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],
  1.1617 +             With=[]}))) : mout 
  1.1618 +\end{verbatim}}%size
  1.1619 +Again assuming that the dialog guide hide the next tactic proposed by the {\tt me}, and the student gets lost, {\tt Refine\_Problem} always 'knows' the way out, if applied to the problem type {\tt["univariate","equation"]}.
  1.1620 +{\footnotesize\begin{verbatim}
  1.1621 +   ML> val nxt = ("Refine_Problem",
  1.1622 +                  Refine_Problem ["linear","univariate","equation
  1.1623 +   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1624 +   val f = Problems (RefinedKF [NoMatch #]) : mout
  1.1625 +   ML>
  1.1626 +   ML>  Compiler.Control.Print.printDepth:=9;f;Compiler.Control.Print.printDepth:=4;
  1.1627 +   val f =
  1.1628 +     Problems
  1.1629 +       (RefinedKF
  1.1630 +          [NoMatch
  1.1631 +             (["linear","univariate","equation"],
  1.1632 +              {Find=[Correct "solutions L"],
  1.1633 +               Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
  1.1634 +                      Correct "solveFor x"],Relate=[],
  1.1635 +               Where=[False
  1.1636 +                     "matches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],
  1.1637 +               With=[]})]) : mout
  1.1638 +   ML>
  1.1639 +   ML> val nxt = ("Refine_Problem",Refine_Problem ["univariate","equation"]);
  1.1640 +   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1641 +   val f =
  1.1642 +     Problems
  1.1643 +       (RefinedKF [Matches #,NoMatch #,NoMatch #,NoMatch #,NoMatch #,Matches #])
  1.1644 +     : mout
  1.1645 +   ML>
  1.1646 +   ML>
  1.1647 +   ML>  Compiler.Control.Print.printDepth:=9;f;Compiler.Control.Print.printDepth:=4;
  1.1648 +   val f =
  1.1649 +     Problems
  1.1650 +       (RefinedKF
  1.1651 +          [Matches
  1.1652 +             (["univariate","equation"],
  1.1653 +              {Find=[Correct "solutions L"],
  1.1654 +               Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
  1.1655 +                      Correct "solveFor x"],Relate=[],
  1.1656 +               Where=[Correct
  1.1657 +               With=[]}),
  1.1658 +           NoMatch
  1.1659 +             (["linear","univariate","equation"],
  1.1660 +              {Find=[Correct "solutions L"],
  1.1661 +               Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
  1.1662 +                      Correct "solveFor x"],Relate=[],
  1.1663 +               Where=[False
  1.1664 +                      "matches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],
  1.1665 +                  With=[]}),
  1.1666 +           NoMatch
  1.1667 +             ...
  1.1668 +             ...   
  1.1669 +           Matches
  1.1670 +             (["normalize","univariate","equation"],
  1.1671 +              {Find=[Correct "solutions L"],
  1.1672 +               Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
  1.1673 +                      Correct "solveFor x"],Relate=[],Where=[],With=[]})]) : mout
  1.1674 +\end{verbatim}}%size
  1.1675 +The tactic {\tt Refine\_Problem} returns all matches to problem types along the path traced in the problem hierarchy (anlogously to the authoring tool for refinement in sect.\ref{refine} on p.\pageref{refine}) --- a lot of information to be displayed appropriately in the hiearchy browser~!
  1.1676 +
  1.1677 +\section{The phase of solving} 
  1.1678 +This phase starts by invoking a method, which acchieves the normal form within two tactics, {\tt Rewrite rnorm\_equation\_add} and {\tt Rewrite\_Set SqRoot\_simplify}:
  1.1679 +{\footnotesize\begin{verbatim} 
  1.1680 +   ML> nxt;
  1.1681 +   val it = ("Apply_Method",Apply_Method ("SqRoot.thy","norm_univar_equation"))
  1.1682 +     : string * mstep
  1.1683 +   ML>
  1.1684 +   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1685 +   val f =
  1.1686 +     Form' (FormKF (~1,EdUndef,1,Nundef,"(x + #1) * (x + #2) = x ^^^ #2 + #8"))
  1.1687 +   val nxt =
  1.1688 +     ("Rewrite", Rewrite
  1.1689 +        ("rnorm_equation_add","~ ?b =!= #0 ==> (?a = ?b) = (?a + #-1 * ?b = #0)"))
  1.1690 +   ML>
  1.1691 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1692 +   val f =
  1.1693 +     Form' (FormKF (~1,EdUndef,1,Nundef,
  1.1694 +           "(x + #1) * (x + #2) + #-1 * (x ^^^ #2 + #8) = #0")) : mout
  1.1695 +   val nxt = ("Rewrite_Set",Rewrite_Set "SqRoot_simplify") : string * mstep
  1.1696 +   ML>
  1.1697 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1698 +   val f = Form' (FormKF (~1,EdUndef,1,Nundef,"#-6 + #3 * x = #0")) : mout
  1.1699 +   val nxt = ("Subproblem",Subproblem ("SqRoot.thy",[#,#])) : string * mstep
  1.1700 +\end{verbatim}}%size
  1.1701 +Now the normal form {\tt \#-6 + \#3 * x = \#0} is the input to a subproblem, which again allows for specification of the type of equation, and the respective method:
  1.1702 +{\footnotesize\begin{verbatim}
  1.1703 +   ML> nxt;
  1.1704 +   val it = ("Subproblem",Subproblem ("SqRoot.thy",["univariate","equation"]))
  1.1705 +   ML>   
  1.1706 +   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1707 +   val f =
  1.1708 +     Form' (FormKF
  1.1709 +          (~1,EdUndef,1,Nundef,"Subproblem (SqRoot.thy, [univariate, equation])"))
  1.1710 +     : mout
  1.1711 +   val nxt = ("Refine_Tacitly",Refine_Tacitly ["univariate","equation"])
  1.1712 +   ML>
  1.1713 +   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1714 +   val nxt = ("Model_Problem",Model_Problem ["linear","univariate","equation"])
  1.1715 +\end{verbatim}}%size
  1.1716 +As required, the tactic {\tt Refine ["univariate","equation"]} selects the appropriate type of equation from the problem hierarchy, which can be seen by the tactic {\tt Model\_Problem ["linear","univariate","equation"]} prosed by the system.
  1.1717 +
  1.1718 +Again the whole phase of modeling and specification follows; we skip it here, and \isac's dialog guide may decide to do so as well.
  1.1719 +
  1.1720 +
  1.1721 +\section{The final phase: check the post-condition}
  1.1722 +The type of problems solved by \isac{} are so-called 'example construction problems' as shown above. The most characteristic point of such a problem is the post-condition. The handling of the post-condition in the given context is an open research question.
  1.1723 +
  1.1724 +Thus the post-condition is just mentioned, in our example for both, the problem and the subproblem:
  1.1725 +{\footnotesize\begin{verbatim}
  1.1726 +   ML> nxt;
  1.1727 +   val it = ("Check_Postcond",Check_Postcond ["linear","univariate","equation"])
  1.1728 +   ML>
  1.1729 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1730 +   val f = Form' (FormKF (~1,EdUndef,1,Nundef,"[x = #2]")) : mout
  1.1731 +   val nxt =
  1.1732 +     ("Check_Postcond",Check_Postcond ["normalize","univariate","equation"])
  1.1733 +   ML>
  1.1734 +   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
  1.1735 +   val f = Form' (FormKF (~1,EdUndef,0,Nundef,"[x = #2]")) : mout
  1.1736 +   val nxt = ("End_Proof'",End_Proof') : string * mstep
  1.1737 +\end{verbatim}}%size
  1.1738 +The next tactic proposed by the system, {\tt End\_Proof'} indicates that the proof has finished successfully.\\
  1.1739 +
  1.1740 +{\it The tactics proposed by the system need {\em not} be followed by the user; the user is free to choose other tactics, and the system will report, if this is applicable at the respective proof state, or not~! The reader may try out~!}
  1.1741 +
  1.1742 +
  1.1743 +
  1.1744 +\part{Systematic description}
  1.1745 +
  1.1746 +
  1.1747 +\chapter{The structure of the knowledge base}
  1.1748 +
  1.1749 +\section{Tactics and data}
  1.1750 +First we view the ME from outside, i.e. we regard tactics and relate them to the knowledge base (KB). W.r.t. the KB we address the atomic items which have to be implemented in detail by the authors of the KB
  1.1751 +\footnote{Some of these items are fetched by the tactics from intermediate storage within the ME, and not directly from the KB.}
  1.1752 +. The items are listed in alphabetical order in Tab.\ref{kb-items} on p.\pageref{kb-items}.
  1.1753 +{\begin{table}[h]
  1.1754 +\caption{Atomic items of the KB} \label{kb-items}
  1.1755 +%\tabcolsep=0.3mm
  1.1756 +\begin{center}
  1.1757 +\def\arraystretch{1.0}
  1.1758 +\begin{tabular}{lp{9.0cm}}
  1.1759 +abbrevation & description \\
  1.1760 +\hline
  1.1761 +&\\
  1.1762 +{\it calc\_list}
  1.1763 +& associationlist of the evaluation-functions {\it eval\_fn}\\
  1.1764 +{\it eval\_fn}
  1.1765 +& evaluation-function for numerals and for predicates coded in SML\\
  1.1766 +{\it eval\_rls   }
  1.1767 +& ruleset {\it rls} for simplifying expressions with {\it eval\_fn}s\\
  1.1768 +{\it fmz}
  1.1769 +& formalization, i.e. a minimal formula representation of an example \\
  1.1770 +{\it met}
  1.1771 +& a method, i.e. a datastructure holding all informations for the solving phase ({\it rew\_ord}, {\it scr}, etc.)\\
  1.1772 +{\it metID}
  1.1773 +& reference to a {\it met}\\
  1.1774 +{\it op}
  1.1775 +& operator as key to an {\it eval\_fn} in a {\it calc\_list}\\
  1.1776 +{\it pbl}
  1.1777 +& problem, i.e. a node in the problem-hierarchy\\
  1.1778 +{\it pblID}
  1.1779 +& reference to a {\it pbl}\\
  1.1780 +{\it rew\_ord}
  1.1781 +& rewrite-order\\
  1.1782 +{\it rls}
  1.1783 +& ruleset, i.e. a datastructure holding theorems {\it thm} and operators {\it op} for simplification (with a {\it rew\_ord})\\
  1.1784 +{\it Rrls}
  1.1785 +& ruleset for 'reverse rewriting' (an \isac-technique generating stepwise rewriting, e.g. for cancelling fractions)\\
  1.1786 +{\it scr}
  1.1787 +& script describing algorithms by tactics, part of a {\it met} \\
  1.1788 +{\it norm\_rls}
  1.1789 +& special ruleset calculating a normalform, associated with a {\it thy}\\
  1.1790 +{\it spec}
  1.1791 +& specification, i.e. a tripel ({\it thyID, pblID, metID})\\
  1.1792 +{\it subs}
  1.1793 +& substitution, i.e. a list of variable-value-pairs\\
  1.1794 +{\it term}
  1.1795 +& Isabelle term, i.e. a formula\\
  1.1796 +{\it thm}
  1.1797 +& theorem\\     
  1.1798 +{\it thy}
  1.1799 +& theory\\
  1.1800 +{\it thyID}
  1.1801 +& reference to a {\it thy} \\
  1.1802 +\end{tabular}\end{center}\end{table}
  1.1803 +}
  1.1804 +The relations between tactics and data items are shown in Tab.\ref{tac-kb}on p.\pageref{tac-kb}.
  1.1805 +{\def\arraystretch{1.2}
  1.1806 +\begin{table}[h]
  1.1807 +\caption{Which tactic uses which KB's item~?} \label{tac-kb}
  1.1808 +\tabcolsep=0.3mm
  1.1809 +\begin{center}
  1.1810 +\begin{tabular}{|ll||cccc|ccc|cccc|} \hline
  1.1811 +tactic  &input &    &    &    &norm\_&   &rew\_&rls &eval\_&eval\_&calc\_&   \\
  1.1812 +        &      &thy &scr &Rrls&rls  &thm &ord  &Rrls&fn    &rls   &list  &dsc\\
  1.1813 +\hline\hline
  1.1814 +Init\_Proof
  1.1815 +        &fmz   & x  &    &    & x   &    &     &    &      &      &      & x \\
  1.1816 +        &spec  &    &    &    &     &    &     &    &      &      &      &   \\
  1.1817 +\hline
  1.1818 +\multicolumn{13}{|l|}{model phase}\\
  1.1819 +\hline
  1.1820 +Add\_*  &term  & x  &    &    & x   &    &     &    &      &      &      & x \\
  1.1821 +FormFK  &model & x  &    &    & x   &    &     &    &      &      &      & x \\
  1.1822 +\hline
  1.1823 +\multicolumn{13}{|l|}{specify phase}\\
  1.1824 +\hline
  1.1825 +Specify\_Theory 
  1.1826 +        &thyID & x  &    &    & x   &    &     &    & x    & x    &      & x \\
  1.1827 +Specify\_Problem 
  1.1828 +        &pblID & x  &    &    & x   &    &     &    & x    & x    &      & x \\
  1.1829 +Refine\_Problem 
  1.1830 +           &pblID & x  &    &    & x   &    &     &    & x    & x    &      & x \\
  1.1831 +Specify\_Method 
  1.1832 +        &metID & x  &    &    & x   &    &     &    & x    & x    &      & x \\
  1.1833 +Apply\_Method 
  1.1834 +        &metID & x  & x  &    & x   &    &     &    & x    & x    &      & x \\
  1.1835 +\hline
  1.1836 +\multicolumn{13}{|l|}{solve phase}\\
  1.1837 +\hline
  1.1838 +Rewrite,\_Inst 
  1.1839 +        &thm   & x  & x  &    &     & x  &met  &    & x    &met   &      &   \\
  1.1840 +Rewrite, Detail
  1.1841 +        &thm   & x  & x  &    &     & x  &rls  &    & x    &rls   &      &   \\
  1.1842 +Rewrite, Detail
  1.1843 +        &thm   & x  & x  &    &     & x  &Rrls &    & x    &Rrls  &      &   \\
  1.1844 +Rewrite\_Set,\_Inst
  1.1845 +        &rls   & x  & x  &    &     &    &     & x  & x    & x    &      &   \\
  1.1846 +Calculate  
  1.1847 +        &op    & x  & x  &    &     &    &     &    &      &      & x    &   \\
  1.1848 +Substitute 
  1.1849 +        &subs  & x  &    &    & x   &    &     &    &      &      &      &   \\
  1.1850 +        &      &    &    &    &     &    &     &    &      &      &      &   \\
  1.1851 +SubProblem 
  1.1852 +        &spec  & x  & x  &    & x   &    &     &    & x    & x    &      & x \\
  1.1853 +        &fmz   &    &    &    &     &    &     &    &      &      &      &   \\
  1.1854 +\hline
  1.1855 +\end{tabular}\end{center}\end{table}
  1.1856 +}
  1.1857 +
  1.1858 +\section{\isac's theories}
  1.1859 +\isac's theories build upon Isabelles theories for high-order-logic (HOL) up to the respective development of real numbers ({\tt HOL/Real}). Theories have a special format defined in \cite{Isa-ref} and the suffix {\tt *.thy}; usually theories are paired with SML-files having the same filename and the suffix {\tt *.ML}.
  1.1860 +
  1.1861 +\isac's theories represent the deductive part of \isac's knowledge base, the hierarchy of theories is structured accordingly. The {\tt *.ML}-files, however, contain {\em all} data of the other two axes of the knowledge base, the problems and the methods (without presenting their respective structure, which is done by the problem browser and the method browser, see \ref{pbt}).
  1.1862 +
  1.1863 +Tab.\ref{theories} on p.\pageref{theories} lists the basic theories planned to be implemented in version \isac.1. We expext the list to be expanded in the near future, actually, have a look to the theory browser~!
  1.1864 +
  1.1865 +The first three theories in the list do {\em not} belong to \isac's knowledge base; they are concerned with \isac's script-language for methods and listed here for completeness.
  1.1866 +{\begin{table}[h]
  1.1867 +\caption{Theories in \isac-version I} \label{theories}
  1.1868 +%\tabcolsep=0.3mm
  1.1869 +\begin{center}
  1.1870 +\def\arraystretch{1.0}
  1.1871 +\begin{tabular}{lp{9.0cm}}
  1.1872 +theory & description \\
  1.1873 +\hline
  1.1874 +&\\
  1.1875 +ListI.thy
  1.1876 +& assigns identifiers to the functions defined in {\tt Isabelle2002/src/HOL/List.thy} and (intermediatly~?) defines some more list functions\\
  1.1877 +ListI.ML
  1.1878 +& {\tt eval\_fn} for the additional list functions\\
  1.1879 +Tools.thy
  1.1880 +& functions required for the evaluation of scripts\\
  1.1881 +Tools.ML
  1.1882 +& the respective {\tt eval\_fn}s\\
  1.1883 +Script.thy
  1.1884 +& prerequisites for scripts: types, tactics, tacticals,\\
  1.1885 +Script.ML
  1.1886 +& sets of tactics and functions for internal use\\
  1.1887 +& \\
  1.1888 +\hline
  1.1889 +& \\
  1.1890 +Typefix.thy
  1.1891 +& an intermediate hack for escaping type errors\\
  1.1892 +Descript.thy
  1.1893 +& {\it description}s for the formulas in {\it model}s and {\it problem}s\\
  1.1894 +Atools
  1.1895 +& (re-)definition of operators; general predicates and functions for preconditions; theorems for the {\tt eval\_rls}\\
  1.1896 +Float
  1.1897 +& floating point numerals\\
  1.1898 +Equation
  1.1899 +& basic notions for equations and equational systems\\
  1.1900 +Poly
  1.1901 +& polynomials\\
  1.1902 +PolyEq
  1.1903 +& polynomial equations and equational systems \\
  1.1904 +Rational.thy
  1.1905 +& additional theorems for rationals\\
  1.1906 +Rational.ML
  1.1907 +& cancel, add and simplify rationals using (a generalization of) Euclids algorithm; respective reverse rulesets\\
  1.1908 +RatEq
  1.1909 +& equations on rationals\\
  1.1910 +Root
  1.1911 +& radicals; calculate normalform; respective reverse rulesets\\
  1.1912 +RootEq
  1.1913 +& equations on roots\\
  1.1914 +RatRootEq
  1.1915 +& equations on rationals and roots (i.e. on terms containing both operations)\\
  1.1916 +Vect
  1.1917 +& vector analysis\\
  1.1918 +Trig
  1.1919 +& trigonometriy\\
  1.1920 +LogExp
  1.1921 +& logarithms and exponential functions\\
  1.1922 +Calculus
  1.1923 +& nonstandard analysis\\
  1.1924 +Diff
  1.1925 +& differentiation\\
  1.1926 +DiffApp
  1.1927 +& applications of differentiaten (maxima-minima-problems)\\
  1.1928 +Test
  1.1929 +& (old) data for the test suite\\
  1.1930 +Isac
  1.1931 +& collects all \isac-theoris.\\
  1.1932 +\end{tabular}\end{center}\end{table}
  1.1933 +}
  1.1934 +
  1.1935 +
  1.1936 +\section{Data in {\tt *.thy}- and {\tt *.ML}-files}
  1.1937 +As already mentioned, theories come in pairs of {\tt *.thy}- and {\tt *.ML}-files with the same respective filename. How data are distributed between the two files is shown in Tab.\ref{thy-ML} on p.\pageref{thy-ML}.
  1.1938 +{\begin{table}[h]
  1.1939 +\caption{Data in {\tt *.thy}- and {\tt *.ML}-files} \label{thy-ML}
  1.1940 +\tabcolsep=2.0mm
  1.1941 +\begin{center}
  1.1942 +\def\arraystretch{1.0}
  1.1943 +\begin{tabular}{llp{7.7cm}}
  1.1944 +file & data & description \\
  1.1945 +\hline
  1.1946 +& &\\
  1.1947 +{\tt *.thy}
  1.1948 +& consts 
  1.1949 +& operators, predicates, functions, script-names ('{\tt Script} name \dots{\tt arguments}')
  1.1950 +\\
  1.1951 +& rules  
  1.1952 +& theorems: \isac{} uses Isabelles theorems if possible; additional theorems analoguous to such existing in Isabelle get the Isabelle-identifier attached an {\it I}
  1.1953 +\\& &\\
  1.1954 +{\tt *.ML}
  1.1955 +& {\tt theory' :=} 
  1.1956 +& the theory defined by the actual {\tt *.thy}-file is made accessible to \isac
  1.1957 +\\
  1.1958 +& {\tt eval\_fn}
  1.1959 +& evaluation function for operators and predicates, coded on the meta-level (SML); the identifier of such a function is a combination of the keyword {\tt eval\_} with the identifier of the function as defined in {\tt *.thy}
  1.1960 +\\
  1.1961 +& {\tt *\_simplify} 
  1.1962 +& the canonical simplifier for the actual theory, i.e. the identifier for this ruleset is a combination of the theories identifier and the keyword {\tt *\_simplify}
  1.1963 +\\
  1.1964 +& {\tt norm\_rls :=}
  1.1965 +& the canonical simplifier {\tt *\_simplify} is stored such that it is accessible for \isac
  1.1966 +\\
  1.1967 +& {\tt rew\_ord' :=}
  1.1968 +& the same for rewrite orders, if needed outside of one particular ruleset
  1.1969 +\\
  1.1970 +& {\tt ruleset' :=}
  1.1971 +& the same for rulesets (ordinary rulesets, reverse rulesets and {\tt eval\_rls})
  1.1972 +\\
  1.1973 +& {\tt calc\_list :=}
  1.1974 +& the same for {\tt eval\_fn}s, if needed outside of one particular ruleset (e.g. for a tactic {\tt Calculate} in a script)
  1.1975 +\\
  1.1976 +& {\tt store\_pbl}
  1.1977 +& problems defined within this {\tt *.ML}-file are made accessible for \isac
  1.1978 +\\
  1.1979 +& {\tt methods :=}
  1.1980 +& methods defined within this {\tt *.ML}-file are made accessible for \isac
  1.1981 +\\
  1.1982 +\end{tabular}\end{center}\end{table}
  1.1983 +}
  1.1984 +The order of the data-items within the theories should adhere to the order given in this list.
  1.1985 +
  1.1986 +\section{Formal description of the problem-hierarchy}
  1.1987 +%for Richard Lang
  1.1988 +
  1.1989 +\section{Script tactics}
  1.1990 +The tactics actually promote the calculation: they construct the prooftree behind the scenes, and they are the points during evaluation where the script-interpreter transfers control to the user. Here we only describe the sytax of the tactics; the semantics is described on p.\pageref{user-tactics} below in context with the tactics the student uses ('user-tactics'): there is a 1-to-1 correspondence between user-tactics and script-tactics.
  1.1991 +
  1.1992 +
  1.1993 +
  1.1994 +
  1.1995 +
  1.1996 +\part{Authoring on the knowledge}
  1.1997 +
  1.1998 +
  1.1999 +\section{Add a theorem}
  1.2000 +\section{Define and add a problem}
  1.2001 +\section{Define and add a predicate}
  1.2002 +\section{Define and add a method}
  1.2003 +\section{}
  1.2004 +\section{}
  1.2005 +\section{}
  1.2006 +\section{}
  1.2007 +
  1.2008 +
  1.2009 +
  1.2010 +\newpage
  1.2011 +\bibliography{bib/isac,bib/from-theses}
  1.2012 +
  1.2013 +\end{document}