doc/mat-eng.tex
author Walther Neuper <wneuper@ist.tugraz.at>
Wed, 28 Nov 2018 08:59:29 +0100
changeset 5232 34f18fdc3103
parent 3020 dbb7b2e708ac
permissions -rwxr-xr-x
update Scala 2.10 to 2.12.3
wneuper@2988
     1
%WN051006 dropped in code, but interesting for case study 'order a list'
wneuper@2988
     2
%EqSystem.thy
wneuper@2988
     3
%---------------------------------------------------------------------------
wneuper@2988
     4
%
wneuper@2988
     5
% order'_system      :: "bool list => bool list " ("order'_system _")
wneuper@2988
     6
%
wneuper@2988
     7
%EqSystem.ML
wneuper@2988
     8
%---------------------------------------------------------------------------
wneuper@2988
     9
%(*("order_system", ("EqSystem.order'_system", 
wneuper@2988
    10
%                   eval_order_system "#eval_order_system_"))*)
wneuper@2988
    11
%fun eval_order_system _ "EqSystem.order'_system"
wneuper@2988
    12
%                         (p as (Const ("EqSystem.order'_system",_) $ ts)) _ =
wneuper@2988
    13
%    let val ts' = sort (ord_simplify_Integral_ false (assoc_thy"Isac.thy") [])
wneuper@2988
    14
%                (isalist2list ts)
wneuper@2988
    15
%       val ts'' = list2isalist HOLogic.boolT ts'
wneuper@2988
    16
%    in if ts <> ts''
wneuper@2988
    17
%       then Some (term2str p ^ " = " ^ term2str ts'',
wneuper@2988
    18
%              Trueprop $ (mk_equality (p,ts'')))
wneuper@2988
    19
%       else None
wneuper@2988
    20
%    end
wneuper@2988
    21
%  | eval_order_system _ _ _ _ = None;
wneuper@2988
    22
%
wneuper@2988
    23
%
wneuper@2988
    24
%"Script Norm2SystemScript (es_::bool list) (vs_::real list) = \
wneuper@2988
    25
%\  (let es__ = Try (Rewrite_Set simplify_Integral_parenthesized False) es_; \
wneuper@2988
    26
%\       es__ = (Try (Calculate order_system_) (order_system es__))\
wneuper@2988
    27
%\in (SubProblem (Biegelinie_,[linear,system],[no_met])\
wneuper@2988
    28
%\                  [bool_list_ es__, real_list_ vs_]))"
wneuper@2988
    29
%              ));
wneuper@2988
    30
%
wneuper@2988
    31
%eqsystem.sml
wneuper@2988
    32
%---------------------------------------------------------------------------
wneuper@2988
    33
%"----------- eval_sort -------------------------------------------";
wneuper@2988
    34
%"----------- eval_sort -------------------------------------------";
wneuper@2988
    35
%"----------- eval_sort -------------------------------------------";
wneuper@2988
    36
%val ts = str2term "[c_2 = 0, -1 * (q_0 * L ^^^ 2) / 2 + (L * c + c_2) = 0]";
wneuper@2988
    37
%val ts' = sort (ord_simplify_Integral_ false (assoc_thy"Isac.thy") [])
wneuper@2988
    38
%              (isalist2list ts);
wneuper@2988
    39
%terms2str ts';
wneuper@2988
    40
%val ts'' = list2isalist HOLogic.boolT ts';
wneuper@2988
    41
%if term2str ts'' = "[-1 * (q_0 * L ^^^ 2) / 2 + (L * c + c_2) = 0, c_2 = 0]"
wneuper@2988
    42
%then () else raise error "eqsystem.sml eval_sort 1";
wneuper@2988
    43
%
wneuper@2988
    44
%val t = str2term "order_system [c_2 = 0,\
wneuper@2988
    45
%                \-1 * (q_0 * L ^^^ 2) / 2 + (L * c + c_2) = 0]";
wneuper@2988
    46
%val Some (str,_) = eval_order_system "" "EqSystem.order'_system" t "";
wneuper@2988
    47
%if str = "order_system [c_2 = 0, -1 * (q_0 * L ^^^ 2) / 2 + (L * c + c_2) = 0] = [-1 * (q_0 * L ^^^ 2) / 2 + (L * c + c_2) = 0, c_2 = 0]" then ()
wneuper@2988
    48
%else raise error "eqsystem.sml eval_sort 2";
wneuper@2988
    49
%
wneuper@2988
    50
%
wneuper@2988
    51
%
wneuper@2988
    52
%  calculate_ thy ("EqSystem.order'_system", 
wneuper@2988
    53
%                 eval_order_system "#eval_order_system_") t;
wneuper@2988
    54
%
wneuper@2988
    55
%---------------------------------------------------------------------------
wneuper@2988
    56
%---------------------------------------------------------------------------
wneuper@2988
    57
%---------------------------------------------------------------------------
wneuper@2988
    58
wneuper@2988
    59
agriesma@306
    60
%In the following this text is not compatible with isac-code:
agriesma@306
    61
%* move termorder to knowledge: FIXXXmat0201a
agriesma@306
    62
%
agriesma@306
    63
%
agriesma@306
    64
agriesma@306
    65
\documentclass[11pt,a4paper,headline,headcount,towside,nocenter]{report}
agriesma@306
    66
\usepackage{latexsym}           % recommended by Ch.Schinagl 10.98
agriesma@306
    67
\bibliographystyle{alpha}
agriesma@306
    68
agriesma@306
    69
\def\isac{${\cal I}\mkern-2mu{\cal S}\mkern-5mu{\cal AC}$}
agriesma@306
    70
agriesma@306
    71
\title{\isac --- Interface for\\
agriesma@306
    72
  Developers of Math Knowledge\\[1.0ex]
agriesma@306
    73
  and\\[1.0ex]
agriesma@306
    74
  Tools for Experiments in\\
agriesma@306
    75
  Symbolic Computation\\[1.0ex]}
agriesma@306
    76
\author{The \isac-Team\\
agriesma@306
    77
  \tt isac-users@ist.tugraz.at\\[1.0ex]}
agriesma@306
    78
\date{\today}
agriesma@306
    79
agriesma@306
    80
\begin{document}
agriesma@306
    81
\maketitle
agriesma@306
    82
\newpage
agriesma@306
    83
\tableofcontents
agriesma@306
    84
\newpage
agriesma@306
    85
\listoftables
agriesma@306
    86
\newpage
agriesma@306
    87
akremp@766
    88
\chapter{Introduction}
akremp@766
    89
\section{The scope of this document}
agriesma@306
    90
\paragraph{As a manual:} This document describes the interface to \isac's kernel (KE), the interface to the mathematics engine (ME) included in the KE, and to the various tools like rewriting, matching etc.
agriesma@306
    91
agriesma@306
    92
\isac's KE is written in SML, the language developed in conjunction with predecessors of the theorem prover Isabelle. Thus, in this document we use the plain ASCII representation of SML code. The reader may note that the \isac-user is presented a completely different view on a graphical user interface.
agriesma@306
    93
agriesma@306
    94
The document is selfcontained; basic knowledge about SML (as an introduction \cite{Paulson:91} is recommended), terms and rewriting is assumed.
agriesma@306
    95
agriesma@306
    96
%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.
agriesma@306
    97
agriesma@306
    98
Notation: SML code, directories, file names are {\tt written in 'tt'}; in particular {\tt ML>} is the KE prompt.
agriesma@306
    99
agriesma@306
   100
\paragraph{Give it a try !} Another aim of this text is to give the reader hints for experiments with the tools introduced.
agriesma@306
   101
akremp@766
   102
\section{Related documents}\label{related-docs}
agriesma@306
   103
Isabelle reference manual \cite{Isa-ref}, also contained in the Isabelle distribution under $\sim${\tt /doc/}.
agriesma@306
   104
agriesma@306
   105
{\bf The actual locations of files is being recorded in \\{\tt /software/services/isac/README}
agriesma@306
   106
\footnote{The KEs current version is {\tt isac.020120-math/} which is based on the version Isabelle99 at {\tt http://isabelle.in.tum.de}.\\
agriesma@306
   107
The current locations at IST are\\
agriesma@306
   108
{\tt [isabelle]\hspace{3em}      /software/sol26/Isabelle99/}\\
agriesma@306
   109
{\tt [isac-src]\hspace{3em}      /software/services/isac/src/ke/}\\ 
agriesma@306
   110
{\tt [isac-bin]\hspace{3em}      /software/services/isac/bin/ke/}
agriesma@306
   111
} 
agriesma@306
   112
and rigorously updated.} In this document we refer to the following directories
agriesma@306
   113
\begin{tabbing}
agriesma@306
   114
xxx\=Isabelle sources1234 \=\kill
agriesma@306
   115
\>Isabelle sources \> {\tt [isabelle]/}\\
agriesma@306
   116
\>KE sources       \> {\tt [isac-src]/\dots{version}\dots/}\\
agriesma@306
   117
\>KE binary        \> {\tt [isac-bin]/\dots{version}\dots/}
agriesma@306
   118
\end{tabbing}
agriesma@306
   119
where {\tt\dots version\dots} stands for a directory-name containing information on the version.
agriesma@306
   120
akremp@766
   121
\section{Getting started}
agriesma@306
   122
Change to the directory {\tt [isac-bin]} where \isac's binary is located and type to the unix-prompt '$>$' (ask your system administrator where the directory {\tt [isac-bin]} is on your system):
agriesma@306
   123
\begin{verbatim}
agriesma@306
   124
   > [isac-bin]/sml @SMLload=isac.020120-math
agriesma@306
   125
   val it = false : bool
agriesma@306
   126
   ML>
agriesma@306
   127
\end{verbatim}
agriesma@306
   128
yielding the message {\tt val it = false : bool} followed by the prompt of the KE. Having been successful so far, just type in the input presented below -- all of it belongs to {\em one} session~!
agriesma@306
   129
akremp@766
   130
\part{Experimental approach}
agriesma@306
   131
akremp@766
   132
\chapter{Basics, terms and parsing}
agriesma@306
   133
Isabelle implements terms of the {\it simply typed lambda calculus} \cite{typed-lambda} defined in $\sim${\tt/src/Pure.ML}. 
akremp@766
   134
\section{The definition of terms}
agriesma@306
   135
There are two kinds of terms in Isabelle, 'raw terms' and 'certified terms'. \isac{} works on raw terms, which are efficient but hard to comprehend. 
agriesma@306
   136
{\footnotesize\begin{verbatim}
agriesma@306
   137
   datatype term = 
agriesma@306
   138
       Const of string * typ
agriesma@306
   139
     | Free  of string * typ 
agriesma@306
   140
     | Var   of indexname * typ
agriesma@306
   141
     | Bound of int
agriesma@306
   142
     | Abs   of string * typ * term
agriesma@306
   143
     | op $  of term * term;
agriesma@306
   144
agriesma@306
   145
   datatype typ = Type  of string * typ list
agriesma@306
   146
                | TFree of string * sort
agriesma@306
   147
                | TVar  of indexname * sort;
agriesma@306
   148
\end{verbatim}}%size % $
agriesma@306
   149
where the definitions of sort and indexname is not relevant in this context. The {\tt typ}e is being inferred during parsing. Parsing creates the other kind of terms, {\tt cterm}. These {\tt cterm}s are encapsulated records, which cannot be composed without the respective Isabelle functions (checking for type correctness), but which then are conveniently displayed as strings (using SML compiler internals -- see below).
agriesma@306
   150
akremp@766
   151
\section{Theories and parsing}
agriesma@306
   152
Parsing uses information contained in Isabelles theories $\sim${\tt /src/HOL}. The currently active theory is held in a global variable {\tt thy}; theories can be accessed individually;
agriesma@306
   153
{\footnotesize\begin{verbatim}
agriesma@306
   154
   ML> thy;
agriesma@306
   155
   val it =
agriesma@306
   156
     {ProtoPure, CPure, HOL, Ord, Set, subset, equalities, mono, Vimage, Fun,
agriesma@306
   157
       Prod, Lfp, Relation, Trancl, WF, NatDef, Gfp, Sum, Inductive, Nat, Arith,
agriesma@306
   158
       Divides, Power, Finite, Equiv, IntDef, Int, Univ, Datatype, Numeral, Bin,
agriesma@306
   159
       IntArith, WF_Rel, Recdef, IntDiv, NatBin, List, Option, Map, Record,
agriesma@306
   160
       RelPow, Sexp, String, Calculation, SVC_Oracle, Main, Zorn, Filter, PNat,
agriesma@306
   161
       PRat, PReal, RealDef, RealOrd, RealInt, RealBin, HyperDef, Descript, ListG,
agriesma@306
   162
       Tools, Script, Typefix, Atools, RatArith, SqRoot, Differentiate, DiffAppl,
agriesma@306
   163
       InsSort, Isac} : theory                                                    ML>
agriesma@306
   164
   ML> HOL.thy;
agriesma@306
   165
   val it = {ProtoPure, CPure, HOL} : theory 
agriesma@306
   166
   ML>
agriesma@306
   167
   ML> parse;
agriesma@306
   168
   val it = fn : theory -> string -> cterm option
agriesma@306
   169
   ML> parse thy "a + b * #3";
agriesma@306
   170
   val it = Some "a + b * #3" : cterm option
agriesma@306
   171
   ML>
agriesma@306
   172
   ML> val t = (term_of o the) it;
agriesma@306
   173
   val t = Const (#,#) $ Free (#,#) $ (Const # $ Free # $ Free (#,#)) : term
agriesma@306
   174
\end{verbatim}}%size
agriesma@306
   175
where {\tt term\_of} and {\tt the} are explained below. The syntax of the list of characters can be read out of Isabelles theories \cite{Isa-obj} {\tt [isabelle]/src/HOL/}\footnote{Or you may use your internetbrowser to look at the files in {\tt [isabelle]/browser\_info}.} 
agriesma@306
   176
and from theories developed with in \isac{} at {\tt [isac-src]/knowledge/}. Note that the syntax of the terms is different from those displayed at \isac's frontend after conversion to MathML.
agriesma@306
   177
agriesma@306
   178
akremp@766
   179
\section{Displaying terms}
agriesma@306
   180
The print depth on the SML top-level can be set in order to produce output in the amount of detail desired:
agriesma@306
   181
{\footnotesize\begin{verbatim}
agriesma@306
   182
   ML> Compiler.Control.Print.printDepth;
agriesma@306
   183
   val it = ref 4 : int ref
agriesma@306
   184
   ML>
agriesma@306
   185
   ML> Compiler.Control.Print.printDepth:= 2;
agriesma@306
   186
   val it = () : unit
agriesma@306
   187
   ML> t;
agriesma@306
   188
   val it = # $ # $ (# $ #) : term
agriesma@306
   189
   ML>
agriesma@306
   190
   ML> Compiler.Control.Print.printDepth:= 6;
agriesma@306
   191
   val it = () : unit
agriesma@306
   192
   ML> t;
agriesma@306
   193
   val it =
agriesma@306
   194
     Const ("op +","[RealDef.real, RealDef.real] => RealDef.real") $
agriesma@306
   195
     Free ("a","RealDef.real") $
agriesma@306
   196
     (Const ("op *","[RealDef.real, RealDef.real] => RealDef.real") $
agriesma@306
   197
      Free ("b","RealDef.real") $ Free ("#3","RealDef.real")) : term
agriesma@306
   198
\end{verbatim}}%size % $
agriesma@306
   199
A closer look to the latter output shows that {\tt typ} is output as a string like {\tt cterm}. Other useful settings for the output are:
agriesma@306
   200
{\footnotesize\begin{verbatim}
agriesma@306
   201
   ML> Compiler.Control.Print.printLength;
agriesma@306
   202
   val it = ref 8 : int ref
agriesma@306
   203
   ML> Compiler.Control.Print.stringDepth;
agriesma@306
   204
   val it = ref 250 : int ref
agriesma@306
   205
\end{verbatim}}%size
agriesma@306
   206
Anyway, the SML output of terms is not very readable; there are functions in the KE to display them:
agriesma@306
   207
{\footnotesize\begin{verbatim}
agriesma@306
   208
   ML> atomt;
agriesma@306
   209
   val it = fn : term -> unit
agriesma@306
   210
   ML> atomt t; 
agriesma@306
   211
   *** -------------
agriesma@306
   212
   *** Const ( op +)
agriesma@306
   213
   *** . Free ( a, )
agriesma@306
   214
   *** . Const ( op *)
agriesma@306
   215
   *** . . Free ( b, )
agriesma@306
   216
   *** . . Free ( #3, )
agriesma@306
   217
   val it = () : unit
agriesma@306
   218
   ML>
agriesma@306
   219
   ML> atomty;
agriesma@306
   220
   val it = fn : theory -> term -> unit
agriesma@306
   221
   ML> atomty thy t;
agriesma@306
   222
   *** -------------
agriesma@306
   223
   *** Const ( op +, [real, real] => real)
agriesma@306
   224
   *** . Free ( a, real)
agriesma@306
   225
   *** . Const ( op *, [real, real] => real)
agriesma@306
   226
   *** . . Free ( b, real)
agriesma@306
   227
   *** . . Free ( #3, real)
agriesma@306
   228
   val it = () : unit
agriesma@306
   229
\end{verbatim}}%size
agriesma@306
   230
where again the {\tt typ}s are rendered as strings, but more elegantly by use of the information contained in {\tt thy}..
agriesma@306
   231
agriesma@306
   232
\paragraph{Give it a try !} {\bf The mathematics knowledge grows} as it is defined in Isabelle theory by theory. Have a look by your internet browser to the hierarchy of those theories at {\tt [isabelle]/src/HOL/HOL.thy} and its children available on your system. Or you may use your internetbrowser to look at the files in {\tt [isabelle]/browser\_info}.
agriesma@306
   233
{\footnotesize\begin{verbatim}
agriesma@306
   234
   ML> (*-1-*) parse HOL.thy "#2^^^#3";
agriesma@306
   235
   *** Inner lexical error at: "^^^#3"
agriesma@306
   236
   val it = None : cterm option
agriesma@306
   237
   ML>
agriesma@306
   238
   ML> (*-2-*) parse HOL.thy "d_d x (a + x)";
agriesma@306
   239
   val it = None : cterm option
agriesma@306
   240
   ML>
agriesma@306
   241
   ML>
agriesma@306
   242
   ML> (*-3-*) parse RatArith.thy "#2^^^#3";
agriesma@306
   243
   val it = Some "#2 ^^^ #3" : cterm option
agriesma@306
   244
   ML>
agriesma@306
   245
   ML> (*-4-*) parse RatArith.thy "d_d x (a + x)";
agriesma@306
   246
   val it = Some "d_d x (a + x)" : cterm option
agriesma@306
   247
   ML>
agriesma@306
   248
   ML>
agriesma@306
   249
   ML> (*-5-*) parse Differentiate.thy "d_d x (a + x)";
agriesma@306
   250
   val it = Some "d_d x (a + x)" : cterm option
agriesma@306
   251
   ML>
agriesma@306
   252
   ML> (*-6-*) parse Differentiate.thy "#2^^^#3";
agriesma@306
   253
   val it = Some "#2 ^^^ #3" : cterm option
agriesma@306
   254
\end{verbatim}}%size
agriesma@306
   255
Don't trust the string representation: if we convert {\tt(*-4-*)} and {\tt(*-6-*)} to terms \dots
agriesma@306
   256
{\footnotesize\begin{verbatim}
agriesma@306
   257
   ML> (*-4-*) val thy = RatArith.thy;
agriesma@306
   258
   ML> ((atomty thy) o term_of o the o (parse thy)) "d_d x (a + x)";
agriesma@306
   259
   *** -------------
agriesma@306
   260
   *** Free ( d_d, [real, real] => real)
agriesma@306
   261
   *** . Free ( x, real)
agriesma@306
   262
   *** . Const ( op +, [real, real] => real)
agriesma@306
   263
   *** . . Free ( a, real)
agriesma@306
   264
   *** . . Free ( x, real)
agriesma@306
   265
   val it = () : unit
agriesma@306
   266
   ML>
agriesma@306
   267
   ML> (*-6-*) val thy = Differentiate.thy;
agriesma@306
   268
   ML> ((atomty thy) o term_of o the o (parse thy)) "d_d x (a + x)";
agriesma@306
   269
   *** -------------
agriesma@306
   270
   *** Const ( Differentiate.d_d, [real, real] => real)
agriesma@306
   271
   *** . Free ( x, real)
agriesma@306
   272
   *** . Const ( op +, [real, real] => real)
agriesma@306
   273
   *** . . Free ( a, real)
agriesma@306
   274
   *** . . Free ( x, real)
agriesma@306
   275
   val it = () : unit
agriesma@306
   276
\end{verbatim}}%size
agriesma@306
   277
\dots we see: in {\tt(*-4-*)} we have an arbitrary function {\tt Free ( d\_d, \_)} and in {\tt(*-6-*)} we have the special function constant {\tt Const ( Differentiate.d\_d, \_)} for differentiation, which is defined in {\tt Differentiate.thy} and presumerably is meant.
agriesma@306
   278
agriesma@306
   279
akremp@766
   280
\section{Converting terms}
agriesma@306
   281
The conversion from {\tt cterm} to {\tt term} has been shown above:
agriesma@306
   282
{\footnotesize\begin{verbatim}
agriesma@306
   283
   ML> term_of;
agriesma@306
   284
   val it = fn : cterm -> term
agriesma@306
   285
   ML>
agriesma@306
   286
   ML> the;
agriesma@306
   287
   val it = fn : 'a option -> 'a
agriesma@306
   288
   ML>
agriesma@306
   289
   ML> val t = (term_of o the o (parse thy)) "a + b * #3";
agriesma@306
   290
   val t = Const (#,#) $ Free (#,#) $ (Const # $ Free # $ Free (#,#)) : term
agriesma@306
   291
\end{verbatim}}%size
agriesma@306
   292
where {\tt the} unwraps the {\tt term option} --- an auxiliary function from Larry Paulsons basic library at {\tt [isabelle]/src/Pure/library.ML}, which is really worthwile to study for any SML programmer.
agriesma@306
   293
agriesma@306
   294
The other conversions are the following, some of which use the {\it signature} {\tt sign} of a theory:
agriesma@306
   295
{\footnotesize\begin{verbatim}
agriesma@306
   296
   ML> sign_of;
agriesma@306
   297
   val it = fn : theory -> Sign.sg
agriesma@306
   298
   ML>
agriesma@306
   299
   ML> cterm_of;
agriesma@306
   300
   val it = fn : Sign.sg -> term -> cterm
agriesma@306
   301
   ML> val ct = cterm_of (sign_of thy) t;
agriesma@306
   302
   val ct = "a + b * #3" : cterm
agriesma@306
   303
   ML>
agriesma@306
   304
   ML> Sign.string_of_term;
agriesma@306
   305
   val it = fn : Sign.sg -> term -> string
agriesma@306
   306
   ML> Sign.string_of_term (sign_of thy) t;
agriesma@306
   307
   val it = "a + b * #3" : ctem'
agriesma@306
   308
   ML>
agriesma@306
   309
   ML> string_of_cterm;
agriesma@306
   310
   val it = fn : cterm -> string
agriesma@306
   311
   ML> string_of_cterm ct;
agriesma@306
   312
   val it = "a + b * #3" : ctem'
agriesma@306
   313
\end{verbatim}}%size
agriesma@306
   314
akremp@766
   315
\section{Theorems}
agriesma@306
   316
Theorems are a type, {\tt thm}, even more protected than {\tt cterms}: they are defined as axioms or proven in Isabelle. These definitions and proofs are contained in theories in the directory {\tt[isac-src]/knowledge/}, e.g. the theorem {\tt diff\_sum} in the theory {\tt[isac-src]/knowledge/Differentiate.thy}. Additionally, each theorem has to be recorded for \isac{} in the respective {\tt *.ML}, e.g. {\tt diff\_sum} in {\tt[isac-src]/knowledge/Differentiate.ML} as follows:
agriesma@306
   317
{\footnotesize\begin{verbatim}
agriesma@306
   318
   ML> theorem' := overwritel (!theorem',
agriesma@306
   319
   [("diff_const",num_str diff_const)
agriesma@306
   320
   ]);
agriesma@306
   321
\end{verbatim}}%size
agriesma@306
   322
The additional recording of theorems and other values will disappear in later versions of \isac.
agriesma@306
   323
akremp@766
   324
\chapter{Rewriting}
akremp@766
   325
\section{The arguments for rewriting}
agriesma@306
   326
The type identifiers of the arguments and values of the rewrite-functions in \ref{rewrite} differ only in an apostroph: the apostrohped types are re-named strings in order to maintain readability.
agriesma@306
   327
{\footnotesize\begin{verbatim}
agriesma@306
   328
   ML> HOL.thy;
agriesma@306
   329
   val it = {ProtoPure, CPure, HOL} : theory
agriesma@306
   330
   ML> "HOL.thy" : theory';
agriesma@306
   331
   val it = "HOL.thy" : theory'
agriesma@306
   332
   ML>
agriesma@306
   333
   ML> sqrt_right;
agriesma@306
   334
   val it = fn : rew_ord (* term * term -> bool *)
agriesma@306
   335
   ML> "sqrt_right" : rew_ord';
agriesma@306
   336
   val it = "sqrt_right" : rew_ord'
agriesma@306
   337
   ML>
agriesma@306
   338
   ML> eval_rls;
agriesma@306
   339
   val it =
agriesma@306
   340
     Rls
agriesma@306
   341
       {preconds=[],rew_ord=("sqrt_right",fn),
agriesma@306
   342
        rules=[Thm #,Thm #,Thm #,Thm #,Thm #,Thm #,Thm #,Thm #,
agriesma@306
   343
               Thm #,Thm #,Thm #,Thm #,Thm #,Calc #,Calc #,...],
agriesma@306
   344
        scr=Script (Free #)} : rls
agriesma@306
   345
   ML> "eval_rls" : rls';
agriesma@306
   346
   val it = "eval_rls" : rls'
agriesma@306
   347
   ML>
agriesma@306
   348
   ML> diff_sum;
agriesma@306
   349
   val it = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" : thm
agriesma@306
   350
   ML> ("diff_sum", "") : thm';
agriesma@306
   351
   val it = ("diff_sum","") : thm'
agriesma@306
   352
\end{verbatim}}%size
agriesma@306
   353
where a {\tt thm'} is a pair, eventually with the string-representation of the respective theorem.
agriesma@306
   354
 
akremp@766
   355
\section{The functions for rewriting}\label{rewrite}
agriesma@306
   356
Rewriting comes along with two equivalent functions, where the first is being actually used within the KE, and the second one is useful for tests: 
agriesma@306
   357
{\footnotesize\begin{verbatim}
agriesma@306
   358
   ML> rewrite_;
agriesma@306
   359
   val it = fn
agriesma@306
   360
     : theory
agriesma@306
   361
       -> rew_ord
agriesma@306
   362
          -> rls -> bool -> thm -> term -> (term * term list) option
agriesma@306
   363
   ML>
agriesma@306
   364
   ML> rewrite;
agriesma@306
   365
   val it = fn
agriesma@306
   366
     : theory'
agriesma@306
   367
       -> rew_ord'
agriesma@306
   368
          -> rls' -> bool -> thm' -> cterm' -> (cterm' * cterm' list) option
agriesma@306
   369
\end{verbatim}}%size
agriesma@306
   370
The arguments are the following:\\
agriesma@306
   371
\tabcolsep=4mm
agriesma@306
   372
\def\arraystretch{1.5}
agriesma@306
   373
\begin{tabular}{lp{11.0cm}}
agriesma@306
   374
  {\tt theory}  & the Isabelle theory containing the definitions necessary for parsing the {\tt term} \\
agriesma@306
   375
  {\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 \\
agriesma@306
   376
  {\tt rls}     & the rule set for evaluating the condition within {\tt thm} in case {\tt thm} is a conditional rule \\
agriesma@306
   377
  {\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 \\
agriesma@306
   378
  {\tt thm}     & the theorem used to try to rewrite {\tt term} \\
agriesma@306
   379
  {\tt term}    & the term eventually rewritten by {\tt thm} \\
agriesma@306
   380
\end{tabular}\\
agriesma@306
   381
agriesma@306
   382
\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:\\
agriesma@306
   383
\begin{tabular}{lp{10.4cm}}
agriesma@306
   384
  {\tt term}     & the term rewritten \\
agriesma@306
   385
  {\tt term list}& the assumptions eventually generated if the {\tt bool} flag is set to {\tt true} and {\tt thm} is applicable. \\
agriesma@306
   386
\end{tabular}\\
agriesma@306
   387
agriesma@306
   388
\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:
agriesma@306
   389
{\footnotesize\begin{verbatim}
agriesma@306
   390
   ML> val thy' = "Differentiate.thy";
agriesma@306
   391
   val thy' = "Differentiate.thy" : string
agriesma@306
   392
   ML> val ct = "d_d x (x ^^^ #2 + #3 * x + #4)";
agriesma@306
   393
   val ct = "d_d x (x ^^^ #2 + #3 * x + #4)" : cterm'
agriesma@306
   394
   ML>
agriesma@306
   395
   ML> val thm = ("diff_sum","");
agriesma@306
   396
   val thm = ("diff_sum","") : thm'
agriesma@306
   397
   ML> val Some (ct,_) = rewrite_inst thy' "tless_true" "eval_rls" true
agriesma@306
   398
                     [("bdv","x::real")] thm ct;
agriesma@306
   399
   val ct = "d_d x (x ^^^ #2 + #3 * x) + d_d x #4" : cterm'
agriesma@306
   400
   ML>
agriesma@306
   401
   ML> val Some (ct,_) = rewrite_inst thy' "tless_true" "eval_rls" true
agriesma@306
   402
                     [("bdv","x::real")] thm ct;
agriesma@306
   403
   val ct = "d_d x (x ^^^ #2) + d_d x (#3 * x) + d_d x #4" : cterm'
agriesma@306
   404
   ML>
agriesma@306
   405
   ML> val thm = ("diff_prod_const","");
agriesma@306
   406
   val thm = ("diff_prod_const","") : thm'
agriesma@306
   407
   ML> val Some (ct,_) = rewrite_inst thy' "tless_true" "eval_rls" true
agriesma@306
   408
                     [("bdv","x::real")] thm ct;
agriesma@306
   409
   val ct = "d_d x (x ^^^ #2) + #3 * d_d x x + d_d x #4" : cterm'
agriesma@306
   410
\end{verbatim}}%size
agriesma@306
   411
You can look up the theorems in {\tt [isac-src]/knowledge/Differentiate.thy} and try to apply them until you get the result you would expect if calculating by hand.
agriesma@306
   412
\footnote{Hint: At the end you will need {\tt val (ct,\_) = the (rewrite\_set thy' "eval\_rls" false "SqRoot\_simplify" ct);}}
agriesma@306
   413
agriesma@306
   414
\paragraph{Give it a try !}\label{cond-rew} {\bf Conditional rewriting} is a more powerful technique then ordinary rewriting, and is closer to the power of programming languages (see the subsequent 'try it out'~!). The following example expands a term to poynomial form:
agriesma@306
   415
{\footnotesize\begin{verbatim}
agriesma@306
   416
   ML> val thy' = "Isac.thy";
agriesma@306
   417
   val thy' = "Isac.thy" : string
agriesma@306
   418
   ML> val ct' = "#3 * a + #2 * (a + #1)";
agriesma@306
   419
   val ct' = "#3 * a + #2 * (a + #1)" : cterm'
agriesma@306
   420
   ML>
agriesma@306
   421
   ML> val thm' = ("radd_mult_distrib2","?k * (?m + ?n) = ?k * ?m + ?k * ?n");
agriesma@306
   422
   val thm' = ("radd_mult_distrib2","?k * (?m + ?n) = ?k * ?m + ?k * ?n")
agriesma@306
   423
     : thm'
agriesma@306
   424
   ML> (*1*) val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
agriesma@306
   425
   val ct' = "#3 * a + (#2 * a + #2 * #1)" : cterm'
agriesma@306
   426
   ML>
agriesma@306
   427
   ML> val thm' = ("radd_assoc_RS_sym","?m1 + (?n1 + ?k1) = ?m1 + ?n1 + ?k1");
agriesma@306
   428
   val thm' = ("radd_assoc_RS_sym","?m1 + (?n1 + ?k1) = ?m1 + ?n1 + ?k1")
agriesma@306
   429
     : thm'
agriesma@306
   430
   ML> (*2*) val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
agriesma@306
   431
   val ct' = "#3 * a + #2 * a + #2 * #1" : cterm'
agriesma@306
   432
   ML>
agriesma@306
   433
   ML> val thm' = ("rcollect_right",
agriesma@306
   434
     "[| ?l is_const; ?m is_const |] ==> ?l * ?n + ?m * ?n = (?l + ?m) * ?n");
agriesma@306
   435
   val thm' =
agriesma@306
   436
     ("rcollect_right",
agriesma@306
   437
      "[| ?l is_const; ?m is_const |] ==> ?l * ?n + ?m * ?n = (?l + ?m) * ?n")
agriesma@306
   438
     : thm'
agriesma@306
   439
   ML> (*3*) val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
agriesma@306
   440
   val ct' = "(#3 + #2) * a + #2 * #1" : cterm'
agriesma@306
   441
   ML>
agriesma@306
   442
   ML> (*4*) val Some (ct',_) = calculate' thy' "plus" ct';
agriesma@306
   443
   val ct' = "#5 * a + #2 * #1" : cterm'
agriesma@306
   444
   ML>
agriesma@306
   445
   ML> (*5*) val Some (ct',_) = calculate' thy' "times" ct';
agriesma@306
   446
   val ct' = "#5 * a + #2" : cterm'
agriesma@306
   447
\end{verbatim}}%size
agriesma@306
   448
Note, that the two rules, {\tt radd\_mult\_distrib2} in {\tt(*1*)} and {\tt rcollect\_right} in {\tt(*3*)} would neutralize each other (i.e. a rule set would not terminate), if there would not be the condition {\tt is\_const}.
agriesma@306
   449
agriesma@306
   450
\paragraph{Give it a try !} {\bf Functional programming} can, within a certain range, modeled by rewriting. In {\tt [isac-src]/\dots/tests/InsSort.thy} the following rules can be found, which are able to sort a list ('insertion sort'):
agriesma@306
   451
{\footnotesize\begin{verbatim}
agriesma@306
   452
   sort_def   "sort ls = foldr ins ls []"
agriesma@306
   453
agriesma@306
   454
   ins_base   "ins [] a = [a]"
agriesma@306
   455
   ins_rec    "ins (x#xs) a = (if x < a then x#(ins xs a) else a#(x#xs))"  
agriesma@306
   456
agriesma@306
   457
   foldr_base "foldr f [] a = a"
agriesma@306
   458
   foldr_rec  "foldr f (x#xs) a = foldr f xs (f a x)"
agriesma@306
   459
agriesma@306
   460
   if_True    "(if True then ?x else ?y) = ?x"
agriesma@306
   461
   if_False   "(if False then ?x else ?y) = ?y"
agriesma@306
   462
\end{verbatim}}%size
agriesma@306
   463
where {\tt\#} is the list-constructor, {\tt foldr} is the well-known standard function of functional programming, and {\tt if\_True, if\_False} are auxiliary rules. Then the sort may be done by the following rewrites:
agriesma@306
   464
{\footnotesize\begin{verbatim}
agriesma@306
   465
   ML>  val thy' = "InsSort.thy";
agriesma@306
   466
   val thy' = "InsSort.thy" : theory'
agriesma@306
   467
   ML>  val ct = "sort [#1,#3,#2]" : cterm';
agriesma@306
   468
   val ct = "sort [#1,#3,#2]" : cterm'
agriesma@306
   469
   ML>
agriesma@306
   470
   ML>  val thm = ("sort_def","");
agriesma@306
   471
   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
agriesma@306
   472
   val ct = "foldr ins [#1, #3, #2] []" : cterm'
agriesma@306
   473
   ML>
agriesma@306
   474
   ML>  val thm = ("foldr_rec","");
agriesma@306
   475
   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
agriesma@306
   476
   val ct = "foldr ins [#3, #2] (ins [] #1)" : cterm'
agriesma@306
   477
   ML>
agriesma@306
   478
   ML>  val thm = ("ins_base","");
agriesma@306
   479
   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
agriesma@306
   480
   val ct = "foldr ins [#3, #2] [#1]" : cterm'
agriesma@306
   481
   ML>
agriesma@306
   482
   ML>  val thm = ("foldr_rec","");
agriesma@306
   483
   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
agriesma@306
   484
   val ct = "foldr ins [#2] (ins [#1] #3)" : cterm'
agriesma@306
   485
   ML>
agriesma@306
   486
   ML>  val thm = ("ins_rec","");
agriesma@306
   487
   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
agriesma@306
   488
   val ct = "foldr ins [#2] (if #1 < #3 then #1 # ins [] #3 else [#3, #1])"
agriesma@306
   489
     : cterm'
agriesma@306
   490
   ML>
agriesma@306
   491
   ML>  val (ct,_) = the (calculate' thy' "le" ct);
agriesma@306
   492
   val ct = "foldr ins [#2] (if True then #1 # ins [] #3 else [#3, #1])" : cterm'
agriesma@306
   493
   ML>
agriesma@306
   494
   ML>  val thm = ("if_True","(if True then ?x else ?y) = ?x");
agriesma@306
   495
   ML>  val (ct,_) = the (rewrite thy' "tless_true" "eval_rls" false thm ct);
agriesma@306
   496
   val ct = "foldr ins [#2] (#1 # ins [] #3)" : cterm'
agriesma@306
   497
   ML> 
agriesma@306
   498
   ...
agriesma@306
   499
   val ct = "sort [#1,#3,#2]" : cterm'
agriesma@306
   500
\end{verbatim}}%size
agriesma@306
   501
agriesma@306
   502
akremp@766
   503
\section{Variants of rewriting}
agriesma@306
   504
Some of the above examples already used variants of {\tt rewrite} all of which have the same value, and very similar arguments:
agriesma@306
   505
{\footnotesize\begin{verbatim}
agriesma@306
   506
   ML> rewrite_inst_;
agriesma@306
   507
   val it = fn
agriesma@306
   508
     : theory
agriesma@306
   509
       -> rew_ord
agriesma@306
   510
          -> rls
agriesma@306
   511
             -> bool
agriesma@306
   512
             -> (cterm' * cterm') list
agriesma@306
   513
                   -> thm -> term -> (term * term list) option
agriesma@306
   514
   ML> rewrite_inst;
agriesma@306
   515
   val it = fn
agriesma@306
   516
     : theory'
agriesma@306
   517
       -> rew_ord'
agriesma@306
   518
          -> rls'
agriesma@306
   519
             -> bool
agriesma@306
   520
                -> (cterm' * cterm') list
agriesma@306
   521
                   -> thm' -> cterm' -> (cterm' * cterm' list) option
agriesma@306
   522
   ML>
agriesma@306
   523
   ML> rewrite_set_;
agriesma@306
   524
   val it = fn 
agriesma@306
   525
     : theory -> rls -> bool -> rls -> term -> (term * term list) option
agriesma@306
   526
   ML> rewrite_set;
agriesma@306
   527
   val it = fn
agriesma@306
   528
     : theory' -> rls' -> bool -> rls' -> cterm' -> (cterm' * cterm' list) option
agriesma@306
   529
   ML>
agriesma@306
   530
   ML> rewrite_set_inst_;
agriesma@306
   531
   val it = fn
agriesma@306
   532
     : theory
agriesma@306
   533
       -> rls
agriesma@306
   534
          -> bool
agriesma@306
   535
             -> (cterm' * cterm') list
agriesma@306
   536
                -> rls -> term -> (term * term list) option
agriesma@306
   537
   ML> rewrite_set_inst;
agriesma@306
   538
   val it = fn
agriesma@306
   539
     : theory'
agriesma@306
   540
       -> rls'
agriesma@306
   541
          -> bool
agriesma@306
   542
             -> (cterm' * cterm') list
agriesma@306
   543
                -> rls' -> cterm' -> (cterm' * cterm' list) option
agriesma@306
   544
\end{verbatim}}%size
agriesma@306
   545
agriesma@306
   546
\noindent The variant {\tt rewrite\_inst} substitutes {\tt (term * term) list} in {\tt thm} before rewriting,\\
agriesma@306
   547
the variant {\tt rewrite\_set} rewrites with a whole rule set {\tt rls} (instead with a {\tt thm} only),\\
agriesma@306
   548
the variant {\tt rewrite\_set\_inst} is a combination of the latter two variants. In order to watch how a term is rewritten theorem by theorem, there is a switch {\tt trace\_rewrite}:
agriesma@306
   549
{\footnotesize\begin{verbatim}
agriesma@306
   550
   ML> toggle;
agriesma@306
   551
   val it = fn : bool ref -> bool
agriesma@306
   552
   ML>
agriesma@306
   553
   ML> toggle trace_rewrite;
agriesma@306
   554
   val it = true : bool
agriesma@306
   555
   ML> toggle trace_rewrite;
agriesma@306
   556
   val it = false : bool
agriesma@306
   557
\end{verbatim}}%size
agriesma@306
   558
akremp@766
   559
\section{Rule sets}
agriesma@306
   560
Some of the variants of {\tt rewrite} above do not only apply one theorem, but a whole set of theorems, called a 'rule set'. Such a rule set is applied as long one of its elements can be used for a rewrite (which can go forever, i.e. the rule set eventually does not 'terminate').
agriesma@306
   561
agriesma@306
   562
A simple example of a rule set is {\tt rearrange\_assoc} which is defined in {\tt knowledge/RatArith.ML} as:
agriesma@306
   563
{\footnotesize\begin{verbatim}
agriesma@306
   564
   val rearrange_assoc = 
agriesma@306
   565
     Rls{preconds = [], rew_ord = ("tless_true",tless_true), 
agriesma@306
   566
         rules = 
agriesma@306
   567
         [Thm ("radd_assoc_RS_sym",num_str (radd_assoc RS sym)),
agriesma@306
   568
          Thm ("rmult_assoc_RS_sym",num_str (rmult_assoc RS sym))],
agriesma@306
   569
         scr = Script ((term_of o the o (parse thy)) 
agriesma@306
   570
         "empty_script")
agriesma@306
   571
         }:rls;
agriesma@306
   572
\end{verbatim}}%size
agriesma@306
   573
where 
agriesma@306
   574
\begin{description}
agriesma@306
   575
\item [\tt preconds] are conditions which must be true in order to make the rule set applicable (the empty list evaluates to {\tt true})
agriesma@306
   576
\item [\tt rew\_ord] concerns term orders introduced below in \ref{term-order}
agriesma@306
   577
\item [\tt rules] are the theorems to be applied -- in priciple applied in arbitrary order, because all these rule sets should be 'complete' \cite{nipk:rew-all-that} (and actually the theorems are applied in the sequence they appear in this list). The function {\tt num\_str} must be applied to theorems containing numeral constants (and thus is obsolete in this example). {\tt RS} is an infix function applying the theorem {\tt sym} to {\tt radd\_assoc} before storage (the effect see below)
agriesma@306
   578
\item [\tt scr] is the script applying the ruleset; it will disappear in later versions of \isac.
agriesma@306
   579
\end{description}
agriesma@306
   580
These variables evaluate to
agriesma@306
   581
{\footnotesize\begin{verbatim}
agriesma@306
   582
   ML> sym;
agriesma@306
   583
   val it = "?s = ?t ==> ?t = ?s" : thm 
agriesma@306
   584
   ML> rearrange_assoc;
agriesma@306
   585
   val it =
agriesma@306
   586
     Rls
agriesma@306
   587
       {preconds=[],rew_ord=("tless_true",fn),
agriesma@306
   588
        rules=[Thm ("radd_assoc_RS_sym","?m1 + (?n1 + ?k1) = ?m1 + ?n1 + ?k1"),
agriesma@306
   589
               Thm ("rmult_assoc_RS_sym","?m1 * (?n1 * ?k1) = ?m1 * ?n1 * ?k1")],
agriesma@306
   590
        scr=Script (Free ("empty_script","RealDef.real"))} : rls 
agriesma@306
   591
\end{verbatim}}%size
agriesma@306
   592
agriesma@306
   593
\paragraph{Give it a try !} The above rule set makes an arbitrary number of parentheses disappear which are not necessary due to associativity of {\tt +} and 
agriesma@306
   594
{\footnotesize\begin{verbatim}
agriesma@306
   595
   ML> val ct = (string_of_cterm o the o (parse RatArith.thy))
agriesma@306
   596
                "a + (b * (c * d) + e)";
agriesma@306
   597
   val ct = "a + ((b * (c * d) + e) + f)" : cterm'
agriesma@306
   598
   ML> rewrite_set "RatArith.thy" "eval_rls" false "rearrange_assoc" ct;
agriesma@306
   599
   val it = Some ("a + b * c * d + e + f",[]) : (string * string list) option
agriesma@306
   600
\end{verbatim}}%size
agriesma@306
   601
For acchieving this result the rule set has to be surprisingly busy:
agriesma@306
   602
{\footnotesize\begin{verbatim}
agriesma@306
   603
   ML> toggle trace_rewrite;
agriesma@306
   604
   val it = true : bool
agriesma@306
   605
   ML> rewrite_set "RatArith.thy" "eval_rls" false "rearrange_assoc" ct;
agriesma@306
   606
   ### trying thm 'radd_assoc_RS_sym'
agriesma@306
   607
   ### rewrite_set_: a + b * (c * d) + e
agriesma@306
   608
   ### trying thm 'radd_assoc_RS_sym'
agriesma@306
   609
   ### trying thm 'rmult_assoc_RS_sym'
agriesma@306
   610
   ### rewrite_set_: a + b * c * d + e
agriesma@306
   611
   ### trying thm 'rmult_assoc_RS_sym'
agriesma@306
   612
   ### trying thm 'radd_assoc_RS_sym'
agriesma@306
   613
   ### trying thm 'rmult_assoc_RS_sym'
agriesma@306
   614
   val it = Some ("a + b * c * d + e",[]) : (string * string list) option
agriesma@306
   615
\end{verbatim}}%size
agriesma@306
   616
 
agriesma@306
   617
akremp@766
   618
\section{Calculate numeric constants}
agriesma@306
   619
As soon as numeric constants are in adjacent subterms (see the example on p.\pageref{cond-rew}), they can be calculated by the function
agriesma@306
   620
{\footnotesize\begin{verbatim}
agriesma@306
   621
   ML> calculate;
agriesma@306
   622
   val it = fn : theory' -> string -> cterm' -> (cterm' * thm') option
agriesma@306
   623
   ML> calculate_;
agriesma@306
   624
   val it = fn : theory -> string -> term -> (term * (string * thm)) option
agriesma@306
   625
\end{verbatim}}%size
agriesma@306
   626
where the {\tt string} in the arguments defines the algebraic operation to be calculated. The function returns the result of the calculation, and as second element in the pair the theorem applied. The following algebraic operations are available:
agriesma@306
   627
{\footnotesize\begin{verbatim}
agriesma@306
   628
   ML> calc_list;
agriesma@306
   629
   val it =
agriesma@306
   630
     ref
agriesma@306
   631
       [("plus",("op +",fn)),
agriesma@306
   632
        ("times",("op *",fn)),
agriesma@306
   633
        ("cancel_",("cancel",fn)),
agriesma@306
   634
        ("power",("pow",fn)),
agriesma@306
   635
        ("sqrt",("sqrt",fn)),
agriesma@306
   636
        ("Var",("Var",fn)),
agriesma@306
   637
        ("Length",("Length",fn)),
agriesma@306
   638
        ("Nth",("Nth",fn)),
agriesma@306
   639
        ("power",("pow",fn)),
agriesma@306
   640
        ("le",("op <",fn)),
agriesma@306
   641
        ("leq",("op <=",fn)),
agriesma@306
   642
        ("is_const",("is'_const",fn)),
agriesma@306
   643
        ("is_root_free",("is'_root'_free",fn)),
agriesma@306
   644
        ("contains_root",("contains'_root",fn)),
agriesma@306
   645
        ("ident",("ident",fn))]
agriesma@306
   646
     : (string * (string * (string -> term -> theory -> 
agriesma@306
   647
        (string * term) option))) list ref
agriesma@306
   648
\end{verbatim}}%size
agriesma@306
   649
These operations can be used in the following way.
agriesma@306
   650
{\footnotesize\begin{verbatim}
agriesma@306
   651
   ML> calculate' "Isac.thy" "plus" "#1 + #2";
agriesma@306
   652
   val it = Some ("#3",("#add_#1_#2","\"#1 + #2 = #3\"")) : (string * thm') option
agriesma@306
   653
   ML>
agriesma@306
   654
   ML> calculate' "Isac.thy" "times" "#2 * #3";
agriesma@306
   655
   val it = Some ("#6",("#mult_#2_#3","\"#2 * #3 = #6\""))
agriesma@306
   656
     : (string * thm') option
agriesma@306
   657
   ML>
agriesma@306
   658
   ML> calculate' "Isac.thy" "power" "#2 ^^^ #3";
agriesma@306
   659
   val it = Some ("#8",("#power_#2_#3","\"#2 ^^^ #3 = #8\""))
agriesma@306
   660
     : (string * thm') option
agriesma@306
   661
   ML>
agriesma@306
   662
   ML> calculate' "Isac.thy" "cancel_" "#9 // #12";
agriesma@306
   663
   val it = Some ("#3 // #4",("#cancel_#9_#12","\"#9 // #12 = #3 // #4\""))
agriesma@306
   664
     : (string * thm') option
agriesma@306
   665
   ML>
agriesma@306
   666
   ML> ...
agriesma@306
   667
\end{verbatim}}%size
agriesma@306
   668
          
agriesma@306
   669
agriesma@306
   670
akremp@766
   671
\chapter{Term orders}\label{term-order}
agriesma@306
   672
Orders on terms are indispensable for the purpose of rewriting to normal forms in associative - commutative domains \cite{nipk:rew-all-that}, and for rewriting to normal forms necessary for matching models to problems, see sect.\ref{pbt}.
akremp@766
   673
\section{Examples for term orders}
agriesma@306
   674
It is not trivial to construct a relation $<$ on terms such that it is really an order, i.e. a transitive and antisymmetric relation. These orders are 'recursive path orders' \cite{nipk:rew-all-that}. Some orders implemented in the knowledgebase at {\tt [isac-src]/knowledge/\dots}, %FIXXXmat0201a
agriesma@306
   675
e.g.
agriesma@306
   676
{\footnotesize\begin{verbatim}
agriesma@306
   677
   ML> sqrt_right;
agriesma@306
   678
   val it = fn : bool -> theory -> term * term -> bool
agriesma@306
   679
   ML> tless_true;
agriesma@306
   680
   val it = fn : 'a -> bool 
agriesma@306
   681
\end{verbatim}}%size
agriesma@306
   682
where the bool argument is a switch for tracing the checks on the respective subterms (and theory is necessary for displyinging the (sub-)terms as strings in the case of 'true'). The order {\tt tless\_true} is a dummy always yielding {\tt true}, and {\tt sqrt\_right} prefers a square root shifted to the right within a term:
agriesma@306
   683
{\footnotesize\begin{verbatim}
agriesma@306
   684
   ML> val t1 = (term_of o the o (parse thy)) "(sqrt a) + b";
agriesma@306
   685
   val t1 = Const # $ (# $ #) $ Free (#,#) : term
agriesma@306
   686
   ML>
agriesma@306
   687
   ML> val t2 = (term_of o the o (parse thy)) "b + (sqrt a)";
agriesma@306
   688
   val t2 = Const # $ Free # $ (Const # $ Free #) : term
agriesma@306
   689
   ML>
agriesma@306
   690
   ML> sqrt_right false SqRoot.thy (t1, t2);
agriesma@306
   691
   val it = false : bool
agriesma@306
   692
   ML> sqrt_right false SqRoot.thy (t2, t1);
agriesma@306
   693
   val it = true : bool
agriesma@306
   694
\end{verbatim}}%size
agriesma@306
   695
The many checks performed recursively through all subterms can be traced throughout the algorithm in {\tt [isac-src]/knowledge/SqRoot.ML} by setting the flag to true:
agriesma@306
   696
{\footnotesize\begin{verbatim}
agriesma@306
   697
   ML> val t1 = (term_of o the o (parse thy)) "a + b*(sqrt c) + d";
agriesma@306
   698
   val t1 = Const (#,#) $ (# $ # $ (# $ #)) $ Free ("d","RealDef.real") : term
agriesma@306
   699
   ML>
agriesma@306
   700
   ML> val t2 = (term_of o the o (parse thy)) "a + (sqrt b)*c + d";
agriesma@306
   701
   val t2 = Const (#,#) $ (# $ # $ (# $ #)) $ Free ("d","RealDef.real") : term
agriesma@306
   702
   ML>
agriesma@306
   703
   ML> sqrt_right true SqRoot.thy (t1, t2);
agriesma@306
   704
   t= f@ts= "op +" @ "[a + b * sqrt c,d]"
agriesma@306
   705
   u= g@us= "op +" @ "[a + sqrt b * c,d]"
agriesma@306
   706
   size_of_term(t,u)= (8, 8)
agriesma@306
   707
   hd_ord(f,g)      = EQUAL
agriesma@306
   708
   terms_ord(ts,us) = LESS
agriesma@306
   709
   -------
agriesma@306
   710
   t= f@ts= "op +" @ "[a,b * sqrt c]"
agriesma@306
   711
   u= g@us= "op +" @ "[a,sqrt b * c]"
agriesma@306
   712
   size_of_term(t,u)= (6, 6)
agriesma@306
   713
   hd_ord(f,g)      = EQUAL
agriesma@306
   714
   terms_ord(ts,us) = LESS
agriesma@306
   715
   -------
agriesma@306
   716
   t= f@ts= "a" @ "[]"
agriesma@306
   717
   u= g@us= "a" @ "[]"
agriesma@306
   718
   size_of_term(t,u)= (1, 1)
agriesma@306
   719
   hd_ord(f,g)      = EQUAL
agriesma@306
   720
   terms_ord(ts,us) = EQUAL
agriesma@306
   721
   -------
agriesma@306
   722
   t= f@ts= "op *" @ "[b,sqrt c]"
agriesma@306
   723
   u= g@us= "op *" @ "[sqrt b,c]"
agriesma@306
   724
   size_of_term(t,u)= (4, 4)
agriesma@306
   725
   hd_ord(f,g)      = EQUAL
agriesma@306
   726
   terms_ord(ts,us) = LESS
agriesma@306
   727
   -------
agriesma@306
   728
   t= f@ts= "b" @ "[]"
agriesma@306
   729
   u= g@us= "sqrt" @ "[b]"
agriesma@306
   730
   size_of_term(t,u)= (1, 2)
agriesma@306
   731
   hd_ord(f,g)      = LESS
agriesma@306
   732
   terms_ord(ts,us) = LESS
agriesma@306
   733
   -------
agriesma@306
   734
   val it = true : bool 
agriesma@306
   735
\end{verbatim}}%size
agriesma@306
   736
agriesma@306
   737
agriesma@306
   738
akremp@766
   739
\section{Ordered rewriting}
agriesma@306
   740
Rewriting faces problems in just the most elementary domains, which are all associative and commutative w.r.t. {\tt +} and {\tt *} --- the law of commutativity applied within a rule set causes this set not to terminate~! One method to cope with this difficulty is ordered rewriting, where a rewrite is only done if the resulting term is smaller w.r.t. a term order (with some additional properties called 'rewrite orders' \cite{nipk:rew-all-that}).
agriesma@306
   741
agriesma@306
   742
Such a rule set {\tt ac\_plus\_times}, called an AC-rewrite system, can be found in {\tt[isac-src]/knowledge/RathArith.ML}:
agriesma@306
   743
{\footnotesize\begin{verbatim}
agriesma@306
   744
   val ac_plus_times =
agriesma@306
   745
     Rls{preconds = [], rew_ord = ("term_order",term_order),
agriesma@306
   746
         rules =
agriesma@306
   747
         [Thm ("radd_commute",radd_commute),
agriesma@306
   748
          Thm ("radd_left_commute",radd_left_commute),
agriesma@306
   749
          Thm ("radd_assoc",radd_assoc),
agriesma@306
   750
          Thm ("rmult_commute",rmult_commute),
agriesma@306
   751
          Thm ("rmult_left_commute",rmult_left_commute),
agriesma@306
   752
          Thm ("rmult_assoc",rmult_assoc)],
agriesma@306
   753
         scr = Script ((term_of o the o (parse thy))
agriesma@306
   754
         "empty_script")
agriesma@306
   755
         }:rls;
agriesma@306
   756
   val ac_plus_times =
agriesma@306
   757
     Rls
agriesma@306
   758
       {preconds=[],rew_ord=("term_order",fn),
agriesma@306
   759
        rules=[Thm ("radd_commute","?m + ?n = ?n + ?m"),
agriesma@306
   760
               Thm ("radd_left_commute","?x + (?y + ?z) = ?y + (?x + ?z)"),
agriesma@306
   761
               Thm ("radd_assoc","?m + ?n + ?k = ?m + (?n + ?k)"),
agriesma@306
   762
               Thm ("rmult_commute","?m * ?n = ?n * ?m"),
agriesma@306
   763
               Thm ("rmult_left_commute","?x * (?y * ?z) = ?y * (?x * ?z)"),
agriesma@306
   764
               Thm ("rmult_assoc","?m * ?n * ?k = ?m * (?n * ?k)")],
agriesma@306
   765
        scr=Script (Free ("empty_script","RealDef.real"))} : rls 
agriesma@306
   766
\end{verbatim}}%size
agriesma@306
   767
Note that the theorems {\tt radd\_left\_commute} and {\tt rmult\_left\_commute} are really necessary in order to make the rule set 'confluent'~!
agriesma@306
   768
agriesma@306
   769
agriesma@306
   770
\paragraph{Give it a try !} Ordered rewriting is one technique to produce polynomial normal from from arbitrary integer terms:
agriesma@306
   771
{\footnotesize\begin{verbatim}
agriesma@306
   772
   ML> val ct' = "#3 * a + b + #2 * a";
agriesma@306
   773
   val ct' = "#3 * a + b + #2 * a" : cterm'
agriesma@306
   774
   ML>
agriesma@306
   775
   ML> (*-1-*) radd_commute; val thm' = ("radd_commute","") : thm';
agriesma@306
   776
   val it = "?m + ?n = ?n + ?m" : thm
agriesma@306
   777
   val thm' = ("radd_commute","") : thm'
agriesma@306
   778
   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
agriesma@306
   779
   val ct' = "#2 * a + (#3 * a + b)" : cterm'
agriesma@306
   780
   ML>
agriesma@306
   781
   ML> (*-2-*) rdistr_right_assoc_p; val thm' = ("rdistr_right_assoc_p","") : thm';
agriesma@306
   782
   val it = "?l * ?n + (?m * ?n + ?k) = (?l + ?m) * ?n + ?k" : thm
agriesma@306
   783
   val thm' = ("rdistr_right_assoc_p","") : thm'
agriesma@306
   784
   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
agriesma@306
   785
   val ct' = "(#2 + #3) * a + b" : cterm'
agriesma@306
   786
   ML>
agriesma@306
   787
   ML> (*-3-*)
agriesma@306
   788
   ML> val Some (ct',_) = calculate thy' "plus" ct';
agriesma@306
   789
   val ct' = "#5 * a + b" : cterm'
agriesma@306
   790
\end{verbatim}}%size %FIXXXmat0201b ... calculate !
agriesma@306
   791
This looks nice, but if {\tt radd\_commute} is applied automatically in {\tt (*-1-*)} without checking the resulting term to be 'smaller' w.r.t. a term order, then rewritin goes on forever (i.e. it does not 'terminate') \dots
agriesma@306
   792
{\footnotesize\begin{verbatim}
agriesma@306
   793
   ML> val ct' = "#3 * a + b + #2 * a" : cterm';
agriesma@306
   794
   val ct' = "#3 * a + b + #2 * a" : cterm'
agriesma@306
   795
   ML> val thm' = ("radd_commute","") : thm';
agriesma@306
   796
   val thm' = ("radd_commute","") : thm'
agriesma@306
   797
   ML>
agriesma@306
   798
   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
agriesma@306
   799
   val ct' = "#2 * a + (#3 * a + b)" : cterm'
agriesma@306
   800
   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
agriesma@306
   801
   val ct' = "#3 * a + b + #2 * a" : cterm'
agriesma@306
   802
   ML> val Some (ct',_) = rewrite thy' "tless_true" "eval_rls" true thm' ct';
agriesma@306
   803
   val ct' = "#2 * a + (#3 * a + b)" : cterm'
agriesma@306
   804
              ..........
agriesma@306
   805
\end{verbatim}}%size
agriesma@306
   806
agriesma@306
   807
Ordered rewriting with the above AC-rewrite system {\tt ac\_plus\_times} performs a kind of bubble sort which can be traced:
agriesma@306
   808
{\footnotesize\begin{verbatim}
agriesma@306
   809
   ML> toggle trace_rewrite;
agriesma@306
   810
   val it = true : bool
agriesma@306
   811
   ML>
agriesma@306
   812
   ML> rewrite_set "RatArith.thy" "eval_rls" false "ac_plus_times" ct;
agriesma@306
   813
   ### trying thm 'radd_commute'
agriesma@306
   814
   ### not: "a + (b * (c * d) + e)" > "b * (c * d) + e + a"
agriesma@306
   815
   ### rewrite_set_: a + (e + b * (c * d))
agriesma@306
   816
   ### trying thm 'radd_commute'
agriesma@306
   817
   ### not: "a + (e + b * (c * d))" > "e + b * (c * d) + a"
agriesma@306
   818
   ### not: "e + b * (c * d)" > "b * (c * d) + e"
agriesma@306
   819
   ### trying thm 'radd_left_commute'
agriesma@306
   820
   ### not: "a + (e + b * (c * d))" > "e + (a + b * (c * d))"
agriesma@306
   821
   ### trying thm 'radd_assoc'
agriesma@306
   822
   ### trying thm 'rmult_commute'
agriesma@306
   823
   ### not: "b * (c * d)" > "c * d * b"
agriesma@306
   824
   ### not: "c * d" > "d * c"
agriesma@306
   825
   ### trying thm 'rmult_left_commute'
agriesma@306
   826
   ### not: "b * (c * d)" > "c * (b * d)"
agriesma@306
   827
   ### trying thm 'rmult_assoc'
agriesma@306
   828
   ### trying thm 'radd_commute'
agriesma@306
   829
   ### not: "a + (e + b * (c * d))" > "e + b * (c * d) + a"
agriesma@306
   830
   ### not: "e + b * (c * d)" > "b * (c * d) + e"
agriesma@306
   831
   ### trying thm 'radd_left_commute'
agriesma@306
   832
   ### not: "a + (e + b * (c * d))" > "e + (a + b * (c * d))"
agriesma@306
   833
   ### trying thm 'radd_assoc'
agriesma@306
   834
   ### trying thm 'rmult_commute'
agriesma@306
   835
   ### not: "b * (c * d)" > "c * d * b"
agriesma@306
   836
   ### not: "c * d" > "d * c"
agriesma@306
   837
   ### trying thm 'rmult_left_commute'
agriesma@306
   838
   ### not: "b * (c * d)" > "c * (b * d)"
agriesma@306
   839
   ### trying thm 'rmult_assoc'
agriesma@306
   840
   val it = Some ("a + (e + b * (c * d))",[]) : (string * string list) option     \end{verbatim}}%size
agriesma@306
   841
Notice that {\tt +} is left-associative where the parentheses are omitted for {\tt (a + b) + c = a + b + c}, but not for {\tt a + (b + c)}. Ordered rewriting necessarily terminates with parentheses which could be omitted due to associativity.
agriesma@306
   842
agriesma@306
   843
akremp@766
   844
\chapter{The hierarchy of problem types}\label{pbt}
akremp@766
   845
\section{The standard-function for 'matching'}
agriesma@306
   846
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:
agriesma@306
   847
{\footnotesize\begin{verbatim}
agriesma@306
   848
   ML> matches;
agriesma@306
   849
   val it = fn : theory -> term -> term -> bool
agriesma@306
   850
\end{verbatim}}%size
agriesma@306
   851
where the first of the two {\tt term} arguments is the particular term to be tested, and the second one is the pattern:
agriesma@306
   852
{\footnotesize\begin{verbatim}
agriesma@306
   853
   ML> val t = (term_of o the o (parse thy)) "#3 * x^^^#2 = #1";
agriesma@306
   854
   val t = Const (#,#) $ (# $ # $ (# $ #)) $ Free ("#1","RealDef.real") : term
agriesma@306
   855
   ML>
agriesma@306
   856
   ML> val p = (term_of o the o (parse thy)) "a * b^^^#2 = c";
agriesma@306
   857
   val p = Const (#,#) $ (# $ # $ (# $ #)) $ Free ("c","RealDef.real") : term
agriesma@306
   858
   ML> atomt p;
agriesma@306
   859
   *** -------------
agriesma@306
   860
   *** Const ( op =)
agriesma@306
   861
   *** . Const ( op *)
agriesma@306
   862
   *** . . Free ( a, )
agriesma@306
   863
   *** . . Const ( RatArith.pow)
agriesma@306
   864
   *** . . . Free ( b, )
agriesma@306
   865
   *** . . . Free ( #2, )
agriesma@306
   866
   *** . Free ( c, )
agriesma@306
   867
   val it = () : unit
agriesma@306
   868
   ML>
agriesma@306
   869
   ML> free2var;
agriesma@306
   870
   val it = fn : term -> term
agriesma@306
   871
   ML>
agriesma@306
   872
   ML> val pat = free2var p;
agriesma@306
   873
   val pat = Const (#,#) $ (# $ # $ (# $ #)) $ Var ((#,#),"RealDef.real") : term
agriesma@306
   874
   ML> Sign.string_of_term (sign_of thy) pat;
agriesma@306
   875
   val it = "?a * ?b ^^^ #2 = ?c" : cterm' 
agriesma@306
   876
   ML> atomt pat;
agriesma@306
   877
   *** -------------
agriesma@306
   878
   *** Const ( op =)
agriesma@306
   879
   *** . Const ( op *)
agriesma@306
   880
   *** . . Var ((a, 0), )
agriesma@306
   881
   *** . . Const ( RatArith.pow)
agriesma@306
   882
   *** . . . Var ((b, 0), )
agriesma@306
   883
   *** . . . Free ( #2, )
agriesma@306
   884
   *** . Var ((c, 0), )
agriesma@306
   885
   val it = () : unit
agriesma@306
   886
\end{verbatim}}%size % $ 
agriesma@306
   887
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:
agriesma@306
   888
{\footnotesize\begin{verbatim}
agriesma@306
   889
   ML> matches thy t pat;
agriesma@306
   890
   val it = true : bool
agriesma@306
   891
   ML>
agriesma@306
   892
   ML> val t2 = (term_of o the o (parse thy)) "x^^^#2 = #1";
agriesma@306
   893
   val t2 = Const (#,#) $ (# $ # $ Free #) $ Free ("#1","RealDef.real") : term
agriesma@306
   894
   ML> matches thy t2 pat;
agriesma@306
   895
   val it = false : bool    
agriesma@306
   896
   ML>
agriesma@306
   897
   ML> val pat2 = (term_of o the o (parse thy)) "?u^^^#2 = ?v";
agriesma@306
   898
   val pat2 = Const (#,#) $ (# $ # $ Free #) $ Var ((#,#),"RealDef.real") : term
agriesma@306
   899
   ML> matches thy t2 pat2;
agriesma@306
   900
   val it = true : bool 
agriesma@306
   901
\end{verbatim}}%size % $
agriesma@306
   902
akremp@766
   903
\section{Accessing the hierarchy}
agriesma@306
   904
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):
agriesma@306
   905
{\footnotesize\begin{verbatim}
agriesma@306
   906
   ML> show_ptyps;
agriesma@306
   907
   val it = fn : unit -> unit
agriesma@306
   908
   ML> show_ptyps();
agriesma@306
   909
   [
agriesma@306
   910
    ["e_pblID"],
agriesma@306
   911
    ["equation", "univariate", "linear"],
agriesma@306
   912
    ["equation", "univariate", "plain_square"],
agriesma@306
   913
    ["equation", "univariate", "polynomial", "degree_two", "pq_formula"],
agriesma@306
   914
    ["equation", "univariate", "polynomial", "degree_two", "abc_formula"],
agriesma@306
   915
    ["equation", "univariate", "squareroot"],
agriesma@306
   916
    ["equation", "univariate", "normalize"],
agriesma@306
   917
    ["equation", "univariate", "sqroot-test"],
agriesma@306
   918
    ["function", "derivative_of"],
agriesma@306
   919
    ["function", "maximum_of", "on_interval"],
agriesma@306
   920
    ["function", "make"],
agriesma@306
   921
    ["tool", "find_values"],
agriesma@306
   922
    ["functional", "inssort"]
agriesma@306
   923
   ]
agriesma@306
   924
   val it = () : unit
agriesma@306
   925
\end{verbatim}}%size
agriesma@306
   926
The retrieve function for individual problem types is {\tt get\_pbt}
agriesma@306
   927
\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:
agriesma@306
   928
{\footnotesize\begin{verbatim}
agriesma@306
   929
   ML> get_pbt;
agriesma@306
   930
   val it = fn : pblID -> pbt
agriesma@306
   931
   ML> get_pbt ["squareroot", "univariate", "equation"];
agriesma@306
   932
   val it =
agriesma@306
   933
     {met=[("SqRoot.thy","square_equation")],
agriesma@306
   934
      ppc=[("#Given",(Const (#,#),Free (#,#))),
agriesma@306
   935
           ("#Given",(Const (#,#),Free (#,#))),
agriesma@306
   936
           ("#Given",(Const (#,#),Free (#,#))),
agriesma@306
   937
           ("#Find",(Const (#,#),Free (#,#)))],
agriesma@306
   938
      thy={ProtoPure, CPure, HOL, Ord, Set, subset, equalities, mono, Vimage, Fun,
agriesma@306
   939
            Prod, Lfp, Relation, Trancl, WF, NatDef, Gfp, Sum, Inductive, Nat,
agriesma@306
   940
            Arith, Divides, Power, Finite, Equiv, IntDef, Int, Univ, Datatype,
agriesma@306
   941
            Numeral, Bin, IntArith, WF_Rel, Recdef, IntDiv, NatBin, List, Option,
agriesma@306
   942
            Map, Record, RelPow, Sexp, String, Calculation, SVC_Oracle, Main,
agriesma@306
   943
            Zorn, Filter, PNat, PRat, PReal, RealDef, RealOrd, RealInt, RealBin,
agriesma@306
   944
            HyperDef, Descript, ListG, Tools, Script, Typefix, Atools, RatArith,
agriesma@306
   945
            SqRoot},
agriesma@306
   946
      where_=[Const ("SqRoot.contains'_root","bool => bool") $
agriesma@306
   947
              Free ("e_","bool")]} : pbt
agriesma@306
   948
\end{verbatim}}%size %$
agriesma@306
   949
where the records fields hold the following data:
agriesma@306
   950
\begin{description}
agriesma@306
   951
\item [\tt thy]: the theory necessary for parsing the formulas
agriesma@306
   952
\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}.
agriesma@306
   953
\item [\tt met]: the list of methods solving this problem type.\\
agriesma@306
   954
\end{description}
agriesma@306
   955
agriesma@306
   956
The following function adds or replaces a problem type (after having it prepared using {\tt prep\_pbt})
agriesma@306
   957
{\footnotesize\begin{verbatim}
agriesma@306
   958
   ML> store_pbt;
agriesma@306
   959
   val it = fn : pbt * pblID -> unit
agriesma@306
   960
   ML> store_pbt
agriesma@306
   961
    (prep_pbt SqRoot.thy
agriesma@306
   962
    (["newtype","univariate","equation"],
agriesma@306
   963
     [("#Given" ,["equality e_","solveFor v_","errorBound err_"]),
agriesma@306
   964
      ("#Where" ,["contains_root (e_::bool)"]),
agriesma@306
   965
      ("#Find"  ,["solutions v_i_"])
agriesma@306
   966
     ],
agriesma@306
   967
     [("SqRoot.thy","square_equation")]));
agriesma@306
   968
   val it = () : unit
agriesma@306
   969
\end{verbatim}}%size
agriesma@306
   970
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}).
agriesma@306
   971
akremp@766
   972
\section{Internals of the datastructure}
agriesma@306
   973
This subsection only serves for the implementation of the hierarchy browser and can be skipped by the authors of math knowledge.
agriesma@306
   974
agriesma@306
   975
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:
agriesma@306
   976
{\footnotesize\begin{verbatim}
agriesma@306
   977
   type pbt = 
agriesma@306
   978
        {thy   : theory,       (* the nearest to the root,
agriesma@306
   979
                                  which allows to compile that pbt  *)
agriesma@306
   980
         where_: term list,    (* where - predicates                *)
agriesma@306
   981
         ppc   : ((string *    (* fields "#Given","#Find"           *)
agriesma@306
   982
                   (term *     (* description                       *)
agriesma@306
   983
                    term))     (* id                                *)
agriesma@306
   984
                      list),                                        
agriesma@306
   985
         met   : metID list};  (* methods solving the pbt           *)
agriesma@306
   986
   datatype ptyp = 
agriesma@306
   987
            Ptyp of string *   (* key within pblID                  *)
agriesma@306
   988
                    pbt list * (* several pbts with different domIDs*)
agriesma@306
   989
                    ptyp list;
agriesma@306
   990
   val e_Ptyp = Ptyp ("empty",[],[]);
agriesma@306
   991
   
agriesma@306
   992
   type ptyps = ptyp list;
agriesma@306
   993
   val ptyps = ref ([e_Ptyp]:ptyps);
agriesma@306
   994
\end{verbatim}}%size
agriesma@306
   995
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.
agriesma@306
   996
agriesma@306
   997
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}.
agriesma@306
   998
agriesma@306
   999
agriesma@306
  1000
akremp@766
  1001
\section{Match a formalization with a problem type}\label{pbl}
agriesma@306
  1002
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.
agriesma@306
  1003
{\footnotesize\begin{verbatim}
agriesma@306
  1004
   ML> val fmz = ["equality (#1 + #2 * x = #0)",
agriesma@306
  1005
                  "solveFor x",
agriesma@306
  1006
                  "solutions L"] : fmz;
agriesma@306
  1007
   val fmz = ["equality (#1 + #2 * x = #0)","solveFor x","solutions L"] : fmz
agriesma@306
  1008
\end{verbatim}}%size
agriesma@306
  1009
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:
agriesma@306
  1010
{\footnotesize\begin{verbatim}
agriesma@306
  1011
   ML> match_pbl;
agriesma@306
  1012
   val it = fn : fmz -> pbt -> match'
agriesma@306
  1013
   ML>
agriesma@306
  1014
   ML> match_pbl fmz (get_pbt ["univariate","equation"]);
agriesma@306
  1015
   val it =
agriesma@306
  1016
     Matches'
agriesma@306
  1017
       {Find=[Correct "solutions L"],
agriesma@306
  1018
        Given=[Correct "equality (#1 + #2 * x = #0)",Correct "solveFor x"],
agriesma@306
  1019
        Relate=[],Where=[Correct "matches (?a = ?b) (#1 + #2 * x = #0)"],With=[]}
agriesma@306
  1020
     : match'
agriesma@306
  1021
   ML>
agriesma@306
  1022
   ML> match_pbl fmz (get_pbt ["linear","univariate","equation"]);
agriesma@306
  1023
   val it =
agriesma@306
  1024
     Matches'
agriesma@306
  1025
       {Find=[Correct "solutions L"],
agriesma@306
  1026
        Given=[Correct "equality (#1 + #2 * x = #0)",Correct "solveFor x"],
agriesma@306
  1027
        Relate=[],
agriesma@306
  1028
        Where=[Correct
agriesma@306
  1029
                 "matches (          x = #0) (#1 + #2 * x = #0) |
agriesma@306
  1030
                  matches (     ?b * x = #0) (#1 + #2 * x = #0) |
agriesma@306
  1031
                  matches (?a      + x = #0) (#1 + #2 * x = #0) |
agriesma@306
  1032
                  matches (?a + ?b * x = #0) (#1 + #2 * x = #0)"],
agriesma@306
  1033
        With=[]} : match'
agriesma@306
  1034
   ML>
agriesma@306
  1035
   ML> match_pbl fmz (get_pbt ["squareroot","univariate","equation"]);
agriesma@306
  1036
   val it =
agriesma@306
  1037
     NoMatch'
agriesma@306
  1038
       {Find=[Correct "solutions L"],
agriesma@306
  1039
        Given=[Correct "equality (#1 + #2 * x = #0)",Correct "solveFor x",
agriesma@306
  1040
               Missing "errorBound err_"],Relate=[],
agriesma@306
  1041
        Where=[False "contains_root #1 + #2 * x = #0 "],With=[]} : match'
agriesma@306
  1042
\end{verbatim}}%size
agriesma@306
  1043
The above formalization does not match the problem type \\{\tt["squareroot","univariate","equation"]} which is explained by the tags:
agriesma@306
  1044
\begin{tabbing}
agriesma@306
  1045
123\=\kill
agriesma@306
  1046
\> {\tt Missing:} the item is missing in the formalization as required by the problem type\\
agriesma@306
  1047
\> {\tt Superfl:} the item is not required by the problem type\\
agriesma@306
  1048
\> {\tt Correct:} the item is correct, or the precondition ({\tt Where}) is true\\
agriesma@306
  1049
\> {\tt False:} the precondition ({\tt Where}) is false\\
agriesma@306
  1050
\> {\tt Incompl:} the item is incomlete, or not yet input.\\
agriesma@306
  1051
\end{tabbing}
agriesma@306
  1052
agriesma@306
  1053
agriesma@306
  1054
akremp@766
  1055
\section{Refine a problem specification}
agriesma@306
  1056
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).
agriesma@306
  1057
agriesma@306
  1058
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
agriesma@306
  1059
{\small
agriesma@306
  1060
\begin{enumerate}
agriesma@306
  1061
\item for all $F$ matching some $P_i$ must follow, that $F$ matches $P$
agriesma@306
  1062
\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)
agriesma@306
  1063
\item for all $F$ matching some $P$ must follow, that $F$ matches $P_n$\\
agriesma@306
  1064
\end{enumerate}}%small
agriesma@306
  1065
\noindent Let us give an example for the point (1.) and (2.) first:
agriesma@306
  1066
{\footnotesize\begin{verbatim}
agriesma@306
  1067
   ML> refine;
agriesma@306
  1068
   val it = fn : fmz -> pblID -> match list
agriesma@306
  1069
   ML>
agriesma@306
  1070
   ML> val fmz = ["equality (sqrt(#9+#4*x)=sqrt x + sqrt(#5+x))",
agriesma@306
  1071
              "solveFor x","errorBound (eps=#0)",
agriesma@306
  1072
              "solutions L"];
agriesma@306
  1073
   ML>
agriesma@306
  1074
   ML> refine fmz ["univariate","equation"];
agriesma@306
  1075
   *** pass ["equation","univariate"]
agriesma@306
  1076
   *** pass ["equation","univariate","linear"]
agriesma@306
  1077
   *** pass ["equation","univariate","plain_square"]
agriesma@306
  1078
   *** pass ["equation","univariate","polynomial"]
agriesma@306
  1079
   *** pass ["equation","univariate","squareroot"]
agriesma@306
  1080
   val it =
agriesma@306
  1081
     [Matches
agriesma@306
  1082
        (["univariate","equation"],
agriesma@306
  1083
         {Find=[Correct "solutions L"],
agriesma@306
  1084
          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
agriesma@306
  1085
                 Correct "solveFor x",Superfl "errorBound (eps = #0)"],Relate=[],
agriesma@306
  1086
          Where=[Correct
agriesma@306
  1087
                   "matches (?a = ?b) (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))"],
agriesma@306
  1088
          With=[]}),
agriesma@306
  1089
      NoMatch
agriesma@306
  1090
        (["linear","univariate","equation"],
agriesma@306
  1091
         {Find=[Correct "solutions L"],
agriesma@306
  1092
          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
agriesma@306
  1093
                 Correct "solveFor x",Superfl "errorBound (eps = #0)"],Relate=[],
agriesma@306
  1094
          Where=[False "(?a + ?b * x = #0) (sqrt (#9 + #4 * x#"],
agriesma@306
  1095
          With=[]}),
agriesma@306
  1096
      NoMatch
agriesma@306
  1097
        (["plain_square","univariate","equation"],
agriesma@306
  1098
         {Find=[Correct "solutions L"],
agriesma@306
  1099
          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
agriesma@306
  1100
                 Correct "solveFor x",Superfl "errorBound (eps = #0)"],Relate=[],
agriesma@306
  1101
          Where=[False
agriesma@306
  1102
                   "matches (?a + ?b * x ^^^ #2 = #0)"],
agriesma@306
  1103
          With=[]}),
agriesma@306
  1104
      NoMatch
agriesma@306
  1105
        (["polynomial","univariate","equation"],
agriesma@306
  1106
         {Find=[Correct "solutions L"],
agriesma@306
  1107
          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
agriesma@306
  1108
                 Correct "solveFor x",Superfl "errorBound (eps = #0)"],Relate=[],
agriesma@306
  1109
          Where=[False 
agriesma@306
  1110
                 "is_polynomial_in sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x) x"],
agriesma@306
  1111
          With=[]}),
agriesma@306
  1112
      Matches
agriesma@306
  1113
        (["squareroot","univariate","equation"],
agriesma@306
  1114
         {Find=[Correct "solutions L"],
agriesma@306
  1115
          Given=[Correct "equality (sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x))",
agriesma@306
  1116
                 Correct "solveFor x",Correct "errorBound (eps = #0)"],Relate=[],
agriesma@306
  1117
          Where=[Correct
agriesma@306
  1118
                   "contains_root sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x) "],
agriesma@306
  1119
          With=[]})] : match list
agriesma@306
  1120
\end{verbatim}}%size}%footnotesize\label{refine}
agriesma@306
  1121
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.)).
agriesma@306
  1122
agriesma@306
  1123
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:
agriesma@306
  1124
{\footnotesize\begin{verbatim}
agriesma@306
  1125
   ML>  val fmz = ["equality (x+#1=#2)",
agriesma@306
  1126
               "solveFor x","errorBound (eps=#0)",
agriesma@306
  1127
               "solutions L"];
agriesma@306
  1128
   [...]
agriesma@306
  1129
   ML>
agriesma@306
  1130
   ML>  refine fmz ["univariate","equation"];
agriesma@306
  1131
   *** pass ["equation","univariate"]
agriesma@306
  1132
   *** pass ["equation","univariate","linear"]
agriesma@306
  1133
   *** pass ["equation","univariate","plain_square"]
agriesma@306
  1134
   *** pass ["equation","univariate","polynomial"]
agriesma@306
  1135
   *** pass ["equation","univariate","squareroot"]
agriesma@306
  1136
   *** pass ["equation","univariate","normalize"]
agriesma@306
  1137
   val it =
agriesma@306
  1138
     [Matches
agriesma@306
  1139
        (["univariate","equation"],
agriesma@306
  1140
         {Find=[Correct "solutions L"],
agriesma@306
  1141
          Given=[Correct "equality (x + #1 = #2)",Correct "solveFor x",
agriesma@306
  1142
                 Superfl "errorBound (eps = #0)"],Relate=[],
agriesma@306
  1143
          Where=[Correct "matches (?a = ?b) (x + #1 = #2)"],With=[]}),
agriesma@306
  1144
      NoMatch
agriesma@306
  1145
        (["linear","univariate","equation"],
agriesma@306
  1146
   [...]
agriesma@306
  1147
          With=[]}),
agriesma@306
  1148
      NoMatch
agriesma@306
  1149
        (["squareroot","univariate","equation"],
agriesma@306
  1150
         {Find=[Correct "solutions L"],
agriesma@306
  1151
          Given=[Correct "equality (x + #1 = #2)",Correct "solveFor x",
agriesma@306
  1152
                 Correct "errorBound (eps = #0)"],Relate=[],
agriesma@306
  1153
          Where=[False "contains_root x + #1 = #2 "],With=[]}),
agriesma@306
  1154
      Matches
agriesma@306
  1155
        (["normalize","univariate","equation"],
agriesma@306
  1156
         {Find=[Correct "solutions L"],
agriesma@306
  1157
          Given=[Correct "equality (x + #1 = #2)",Correct "solveFor x",
agriesma@306
  1158
                 Superfl "errorBound (eps = #0)"],Relate=[],Where=[],With=[]})]
agriesma@306
  1159
     : match list
agriesma@306
  1160
\end{verbatim}}%size
agriesma@306
  1161
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"]}.
agriesma@306
  1162
agriesma@306
  1163
This recursive search on the problem hierarchy can be  done within a proof state. This leads to the next section.
agriesma@306
  1164
agriesma@306
  1165
akremp@766
  1166
\chapter{Methods}
agriesma@306
  1167
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.
agriesma@306
  1168
akremp@766
  1169
\section{The scripts' syntax}
agriesma@306
  1170
The syntax of scripts follows the definition given in Backus-normal-form:
agriesma@306
  1171
{\it
agriesma@306
  1172
\begin{tabbing}
agriesma@306
  1173
123\=123\=expr ::=\=$|\;\;$\=\kill
agriesma@306
  1174
\>script ::= {\tt Script} id arg$\,^*$ = body\\
agriesma@306
  1175
\>\>arg ::= id $\;|\;\;($ ( id :: type ) $)$\\
agriesma@306
  1176
\>\>body ::= expr\\
agriesma@306
  1177
\>\>expr ::= \>\>{\tt let} id = expr $($ ; id = expr$)^*$ {\tt in} expr\\
agriesma@306
  1178
\>\>\>$|\;$\>{\tt if} prop {\tt then} expr {\tt else} expr\\
agriesma@306
  1179
\>\>\>$|\;$\>listexpr\\
agriesma@306
  1180
\>\>\>$|\;$\>id\\
agriesma@306
  1181
\>\>\>$|\;$\>seqex id\\
agriesma@306
  1182
\>\>seqex ::= \>\>{\tt While} prop {\tt Do} seqex\\
agriesma@306
  1183
\>\>\>$|\;$\>{\tt Repeat} seqex\\
agriesma@306
  1184
\>\>\>$|\;$\>{\tt Try} seqex\\
agriesma@306
  1185
\>\>\>$|\;$\>seqex {\tt Or} seqex\\
agriesma@306
  1186
\>\>\>$|\;$\>seqex {\tt @@} seqex\\
agriesma@306
  1187
\>\>\>$|\;$\>tac $($ id $|$ listexpr $)^*$\\
agriesma@306
  1188
\>\>type ::= id\\
agriesma@306
  1189
\>\>tac ::= id
agriesma@306
  1190
\end{tabbing}}
agriesma@306
  1191
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.
agriesma@306
  1192
agriesma@306
  1193
Expressions containing some of the keywords {\tt let}, {\tt if} etc. are called {\bf script-expressions}.
agriesma@306
  1194
agriesma@306
  1195
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,
agriesma@306
  1196
agriesma@306
  1197
akremp@766
  1198
\section{Control the flow of evaluation}
agriesma@306
  1199
The flow of control is managed by the following script-expressions called {\it tacticals}.
agriesma@306
  1200
\begin{description}
agriesma@306
  1201
\item{{\tt while} prop {\tt Do} expr id} 
agriesma@306
  1202
\item{{\tt if} prop {\tt then} expr {\tt else} expr}
agriesma@306
  1203
\end{description}
agriesma@306
  1204
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)
agriesma@306
  1205
\begin{description}
agriesma@306
  1206
\item{{\tt Repeat} expr id}
agriesma@306
  1207
\item{{\tt Try} expr id}
agriesma@306
  1208
\item{expr {\tt Or} expr id}
agriesma@306
  1209
\item{expr {\tt @@} expr id}
agriesma@306
  1210
\end{description}
agriesma@306
  1211
agriesma@306
  1212
\begin{description}
agriesma@306
  1213
\item xxx
agriesma@306
  1214
agriesma@306
  1215
\end{description}
agriesma@306
  1216
akremp@766
  1217
\chapter{Do a calculational proof}
agriesma@306
  1218
First we list all the tactics available so far (this list may be extended during further development of \isac).
agriesma@306
  1219
akremp@766
  1220
\section{Tactics for doing steps in calculations}
agriesma@306
  1221
\input{tactics}
agriesma@306
  1222
akremp@766
  1223
\section{The functionality of the math engine}
agriesma@306
  1224
A proof is being started in the math engine {\tt me} by the tactic
agriesma@306
  1225
\footnote{In the present version a tactic is of type {\tt mstep}.}
agriesma@306
  1226
 {\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.
agriesma@306
  1227
agriesma@306
  1228
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 ...
agriesma@306
  1229
{\footnotesize\begin{verbatim}
agriesma@306
  1230
   ML> val fmz = ["equality ((x+#1)*(x+#2)=x^^^#2+#8)","solveFor x",
agriesma@306
  1231
                  "errorBound (eps=#0)","solutions L"];
agriesma@306
  1232
   val fmz =
agriesma@306
  1233
     ["equality ((x+#1)*(x+#2)=x^^^#2+#8)","solveFor x","errorBound (eps=#0)",
agriesma@306
  1234
      "solutions L"] : string list
agriesma@306
  1235
   ML>
agriesma@306
  1236
   ML> val spec as (dom, pbt, met) = ("SqRoot.thy",["univariate","equation"],
agriesma@306
  1237
                                 ("SqRoot.thy","no_met"));
agriesma@306
  1238
   val dom = "SqRoot.thy" : string
agriesma@306
  1239
   val pbt = ["univariate","equation"] : string list
agriesma@306
  1240
   val met = ("SqRoot.thy","no_met") : string * string
agriesma@306
  1241
\end{verbatim}}%size
agriesma@306
  1242
... 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.
agriesma@306
  1243
agriesma@306
  1244
Nevertheless this specification is sufficient for automatically solving the equation --- the appropriate method will be found by refinement within the hierarchy of problem types.
agriesma@306
  1245
agriesma@306
  1246
akremp@766
  1247
\section{Initialize the calculation}
agriesma@306
  1248
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.
agriesma@306
  1249
{\footnotesize\begin{verbatim}
agriesma@306
  1250
   ML>  val (mID,m) = ("Init_Proof",Init_Proof (fmz, (dom,pbt,met)));
agriesma@306
  1251
   val mID = "Init_Proof" : string
agriesma@306
  1252
   val m =
agriesma@306
  1253
     Init_Proof
agriesma@306
  1254
       (["equality ((x+#1)*(x+#2)=x^^^#2+#8)","solveFor x","errorBound (eps=#0)",
agriesma@306
  1255
         "solutions L"],("SqRoot.thy",[#,#],(#,#))) : mstep
agriesma@306
  1256
   ML>
agriesma@306
  1257
   ML>  val (p,_,f,nxt,_,pt) = me (mID,m) e_pos' c EmptyPtree;
agriesma@306
  1258
   val p = ([],Pbl) : pos'
agriesma@306
  1259
   val f = Form' (PpcKF (0,EdUndef,0,Nundef,(#,#))) : mout
agriesma@306
  1260
   val nxt = ("Refine_Tacitly",Refine_Tacitly ["univariate","equation"])
agriesma@306
  1261
     : string * mstep
agriesma@306
  1262
   val pt =
agriesma@306
  1263
     Nd
agriesma@306
  1264
       (PblObj
agriesma@306
  1265
          {branch=#,cell=#,env=#,loc=#,meth=#,model=#,origin=#,ostate=#,probl=#,
agriesma@306
  1266
           result=#,spec=#},[]) : ptree
agriesma@306
  1267
   \end{verbatim}}%size
agriesma@306
  1268
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'}).
agriesma@306
  1269
agriesma@306
  1270
We can convince ourselves, that the problem is still empty, by increasing {\tt Compiler.Control.Print.printDepth}:
agriesma@306
  1271
{\footnotesize\begin{verbatim}
agriesma@306
  1272
   ML> Compiler.Control.Print.printDepth:=8; (*4 default*)
agriesma@306
  1273
   val it = () : unit
agriesma@306
  1274
   ML>
agriesma@306
  1275
   ML> f;
agriesma@306
  1276
   val it =
agriesma@306
  1277
     Form'
agriesma@306
  1278
       (PpcKF
agriesma@306
  1279
          (0,EdUndef,0,Nundef,
agriesma@306
  1280
           (Problem [],
agriesma@306
  1281
            {Find=[Incompl "solutions []"],
agriesma@306
  1282
             Given=[Incompl "equality",Incompl "solveFor"],Relate=[],
agriesma@306
  1283
             Where=[False "matches (?a = ?b) e_"],With=[]}))) : mout
agriesma@306
  1284
\end{verbatim}}%size
agriesma@306
  1285
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).\\
agriesma@306
  1286
agriesma@306
  1287
{\it In the sequel we will omit output of the {\tt me} if it is not important for the respective context}.\\
agriesma@306
  1288
agriesma@306
  1289
In general, the dialog guide will hide the following two tactics {\tt Refine\_Tacitly} and {\tt Model\_Problem} from the user.
agriesma@306
  1290
{\footnotesize\begin{verbatim}
agriesma@306
  1291
   ML>  nxt;
agriesma@306
  1292
   val it = ("Refine_Tacitly",Refine_Tacitly ["univariate","equation"])
agriesma@306
  1293
     : string * mstep
agriesma@306
  1294
   ML>
agriesma@306
  1295
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1296
   val nxt = ("Model_Problem",Model_Problem ["normalize","univariate","equation"])
agriesma@306
  1297
     : string * mstep
agriesma@306
  1298
   ML>
agriesma@306
  1299
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1300
\end{verbatim}}%size
agriesma@306
  1301
agriesma@306
  1302
akremp@766
  1303
\section{The phase of modeling} 
agriesma@306
  1304
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}.
agriesma@306
  1305
agriesma@306
  1306
{\footnotesize\begin{verbatim}
agriesma@306
  1307
   ML>  nxt;
agriesma@306
  1308
   val it =
agriesma@306
  1309
     ("Add_Given",Add_Given "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)")
agriesma@306
  1310
     : string * mstep
agriesma@306
  1311
   ML>
agriesma@306
  1312
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1313
   val nxt = ("Add_Given",Add_Given "solveFor x") : string * mstep
agriesma@306
  1314
   ML>
agriesma@306
  1315
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1316
   val nxt = ("Add_Find",Add_Find "solutions L") : string * mstep
agriesma@306
  1317
   ML>
agriesma@306
  1318
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt; 
agriesma@306
  1319
   val f = Form' (PpcKF (0,EdUndef,0,Nundef,(#,#))) : mout
agriesma@306
  1320
\end{verbatim}}%size
agriesma@306
  1321
\noindent Now the problem is 'modeled', all items are input. We convince ourselves by increasing {\tt Compiler.Control.Print.printDepth} once more.
agriesma@306
  1322
{\footnotesize\begin{verbatim}
agriesma@306
  1323
   ML>  Compiler.Control.Print.printDepth:=8;
agriesma@306
  1324
   ML>  f;
agriesma@306
  1325
   val it =
agriesma@306
  1326
     Form'
agriesma@306
  1327
       (PpcKF
agriesma@306
  1328
          (0,EdUndef,0,Nundef,
agriesma@306
  1329
           (Problem [],
agriesma@306
  1330
            {Find=[Correct "solutions L"],
agriesma@306
  1331
             Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
agriesma@306
  1332
                    Correct "solveFor x"],Relate=[],Where=[],With=[]}))) : mout
agriesma@306
  1333
\end{verbatim}}%size
agriesma@306
  1334
%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.
agriesma@306
  1335
akremp@766
  1336
\section{The phase of specification} 
agriesma@306
  1337
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.
agriesma@306
  1338
{\footnotesize\begin{verbatim}
agriesma@306
  1339
ML> nxt;
agriesma@306
  1340
   val it = ("Specify_Domain",Specify_Domain "SqRoot.thy") : string * mstep
agriesma@306
  1341
   ML>
agriesma@306
  1342
   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1343
   val nxt =
agriesma@306
  1344
     ("Specify_Problem",Specify_Problem ["normalize","univariate","equation"])
agriesma@306
  1345
     : string * mstep
agriesma@306
  1346
   val pt =
agriesma@306
  1347
     Nd
agriesma@306
  1348
       (PblObj
agriesma@306
  1349
          {branch=#,cell=#,env=#,loc=#,meth=#,model=#,origin=#,ostate=#,probl=#,
agriesma@306
  1350
              result=#,spec=#},[]) : ptree
agriesma@306
  1351
\end{verbatim}}%size
agriesma@306
  1352
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.
agriesma@306
  1353
{\footnotesize\begin{verbatim}
agriesma@306
  1354
   ML> val nxt = ("Specify_Problem",
agriesma@306
  1355
               Specify_Problem ["polynomial","univariate","equation"]);
agriesma@306
  1356
   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1357
   val f = Form' (PpcKF (0,EdUndef,0,Nundef,(#,#))) : mout
agriesma@306
  1358
   val nxt =
agriesma@306
  1359
     ("Refine_Problem",Refine_Problem ["normalize","univariate","equation"])
agriesma@306
  1360
     : string * mstep
agriesma@306
  1361
   ML>
agriesma@306
  1362
   ML> val nxt = ("Specify_Problem",
agriesma@306
  1363
               Specify_Problem ["linear","univariate","equation"]);
agriesma@306
  1364
   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1365
   val f =
agriesma@306
  1366
     Form'
agriesma@306
  1367
       (PpcKF
agriesma@306
  1368
          (0,EdUndef,0,Nundef,
agriesma@306
  1369
           (Problem ["linear","univariate","equation"],
agriesma@306
  1370
            {Find=[Correct "solutions L"],
agriesma@306
  1371
             Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
agriesma@306
  1372
                    Correct "solveFor x"],Relate=[],
agriesma@306
  1373
             Where=[False
agriesma@306
  1374
                    "matches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],
agriesma@306
  1375
             With=[]}))) : mout 
agriesma@306
  1376
\end{verbatim}}%size
agriesma@306
  1377
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"]}.
agriesma@306
  1378
{\footnotesize\begin{verbatim}
agriesma@306
  1379
   ML> val nxt = ("Refine_Problem",
agriesma@306
  1380
                  Refine_Problem ["linear","univariate","equation
agriesma@306
  1381
   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1382
   val f = Problems (RefinedKF [NoMatch #]) : mout
agriesma@306
  1383
   ML>
agriesma@306
  1384
   ML>  Compiler.Control.Print.printDepth:=9;f;Compiler.Control.Print.printDepth:=4;
agriesma@306
  1385
   val f =
agriesma@306
  1386
     Problems
agriesma@306
  1387
       (RefinedKF
agriesma@306
  1388
          [NoMatch
agriesma@306
  1389
             (["linear","univariate","equation"],
agriesma@306
  1390
              {Find=[Correct "solutions L"],
agriesma@306
  1391
               Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
agriesma@306
  1392
                      Correct "solveFor x"],Relate=[],
agriesma@306
  1393
               Where=[False
agriesma@306
  1394
                     "matches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],
agriesma@306
  1395
               With=[]})]) : mout
agriesma@306
  1396
   ML>
agriesma@306
  1397
   ML> val nxt = ("Refine_Problem",Refine_Problem ["univariate","equation"]);
agriesma@306
  1398
   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1399
   val f =
agriesma@306
  1400
     Problems
agriesma@306
  1401
       (RefinedKF [Matches #,NoMatch #,NoMatch #,NoMatch #,NoMatch #,Matches #])
agriesma@306
  1402
     : mout
agriesma@306
  1403
   ML>
agriesma@306
  1404
   ML>
agriesma@306
  1405
   ML>  Compiler.Control.Print.printDepth:=9;f;Compiler.Control.Print.printDepth:=4;
agriesma@306
  1406
   val f =
agriesma@306
  1407
     Problems
agriesma@306
  1408
       (RefinedKF
agriesma@306
  1409
          [Matches
agriesma@306
  1410
             (["univariate","equation"],
agriesma@306
  1411
              {Find=[Correct "solutions L"],
agriesma@306
  1412
               Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
agriesma@306
  1413
                      Correct "solveFor x"],Relate=[],
agriesma@306
  1414
               Where=[Correct
agriesma@306
  1415
               With=[]}),
agriesma@306
  1416
           NoMatch
agriesma@306
  1417
             (["linear","univariate","equation"],
agriesma@306
  1418
              {Find=[Correct "solutions L"],
agriesma@306
  1419
               Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
agriesma@306
  1420
                      Correct "solveFor x"],Relate=[],
agriesma@306
  1421
               Where=[False
agriesma@306
  1422
                      "matches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],
agriesma@306
  1423
                  With=[]}),
agriesma@306
  1424
           NoMatch
agriesma@306
  1425
             ...
agriesma@306
  1426
             ...   
agriesma@306
  1427
           Matches
agriesma@306
  1428
             (["normalize","univariate","equation"],
agriesma@306
  1429
              {Find=[Correct "solutions L"],
agriesma@306
  1430
               Given=[Correct "equality ((x + #1) * (x + #2) = x ^^^ #2 + #8)",
agriesma@306
  1431
                      Correct "solveFor x"],Relate=[],Where=[],With=[]})]) : mout
agriesma@306
  1432
\end{verbatim}}%size
agriesma@306
  1433
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~!
agriesma@306
  1434
akremp@766
  1435
\section{The phase of solving} 
agriesma@306
  1436
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}:
agriesma@306
  1437
{\footnotesize\begin{verbatim} 
agriesma@306
  1438
   ML> nxt;
agriesma@306
  1439
   val it = ("Apply_Method",Apply_Method ("SqRoot.thy","norm_univar_equation"))
agriesma@306
  1440
     : string * mstep
agriesma@306
  1441
   ML>
agriesma@306
  1442
   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1443
   val f =
agriesma@306
  1444
     Form' (FormKF (~1,EdUndef,1,Nundef,"(x + #1) * (x + #2) = x ^^^ #2 + #8"))
agriesma@306
  1445
   val nxt =
agriesma@306
  1446
     ("Rewrite", Rewrite
agriesma@306
  1447
        ("rnorm_equation_add","~ ?b =!= #0 ==> (?a = ?b) = (?a + #-1 * ?b = #0)"))
agriesma@306
  1448
   ML>
agriesma@306
  1449
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1450
   val f =
agriesma@306
  1451
     Form' (FormKF (~1,EdUndef,1,Nundef,
agriesma@306
  1452
           "(x + #1) * (x + #2) + #-1 * (x ^^^ #2 + #8) = #0")) : mout
agriesma@306
  1453
   val nxt = ("Rewrite_Set",Rewrite_Set "SqRoot_simplify") : string * mstep
agriesma@306
  1454
   ML>
agriesma@306
  1455
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1456
   val f = Form' (FormKF (~1,EdUndef,1,Nundef,"#-6 + #3 * x = #0")) : mout
agriesma@306
  1457
   val nxt = ("Subproblem",Subproblem ("SqRoot.thy",[#,#])) : string * mstep
agriesma@306
  1458
\end{verbatim}}%size
agriesma@306
  1459
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:
agriesma@306
  1460
{\footnotesize\begin{verbatim}
agriesma@306
  1461
   ML> nxt;
agriesma@306
  1462
   val it = ("Subproblem",Subproblem ("SqRoot.thy",["univariate","equation"]))
agriesma@306
  1463
   ML>   
agriesma@306
  1464
   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1465
   val f =
agriesma@306
  1466
     Form' (FormKF
agriesma@306
  1467
          (~1,EdUndef,1,Nundef,"Subproblem (SqRoot.thy, [univariate, equation])"))
agriesma@306
  1468
     : mout
agriesma@306
  1469
   val nxt = ("Refine_Tacitly",Refine_Tacitly ["univariate","equation"])
agriesma@306
  1470
   ML>
agriesma@306
  1471
   ML> val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1472
   val nxt = ("Model_Problem",Model_Problem ["linear","univariate","equation"])
agriesma@306
  1473
\end{verbatim}}%size
agriesma@306
  1474
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.
agriesma@306
  1475
agriesma@306
  1476
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.
agriesma@306
  1477
agriesma@306
  1478
akremp@766
  1479
\section{The final phase: check the post-condition}
agriesma@306
  1480
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.
agriesma@306
  1481
agriesma@306
  1482
Thus the post-condition is just mentioned, in our example for both, the problem and the subproblem:
agriesma@306
  1483
{\footnotesize\begin{verbatim}
agriesma@306
  1484
   ML> nxt;
agriesma@306
  1485
   val it = ("Check_Postcond",Check_Postcond ["linear","univariate","equation"])
agriesma@306
  1486
   ML>
agriesma@306
  1487
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1488
   val f = Form' (FormKF (~1,EdUndef,1,Nundef,"[x = #2]")) : mout
agriesma@306
  1489
   val nxt =
agriesma@306
  1490
     ("Check_Postcond",Check_Postcond ["normalize","univariate","equation"])
agriesma@306
  1491
   ML>
agriesma@306
  1492
   ML>  val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
agriesma@306
  1493
   val f = Form' (FormKF (~1,EdUndef,0,Nundef,"[x = #2]")) : mout
agriesma@306
  1494
   val nxt = ("End_Proof'",End_Proof') : string * mstep
agriesma@306
  1495
\end{verbatim}}%size
agriesma@306
  1496
The next tactic proposed by the system, {\tt End\_Proof'} indicates that the proof has finished successfully.\\
agriesma@306
  1497
agriesma@306
  1498
{\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~!}
agriesma@306
  1499
agriesma@306
  1500
agriesma@306
  1501
akremp@766
  1502
\part{Systematic description}
agriesma@306
  1503
agriesma@306
  1504
akremp@766
  1505
\chapter{The structure of the knowledge base}
agriesma@306
  1506
akremp@766
  1507
\section{Tactics and data}
agriesma@306
  1508
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
agriesma@306
  1509
\footnote{Some of these items are fetched by the tactics from intermediate storage within the ME, and not directly from the KB.}
agriesma@306
  1510
. The items are listed in alphabetical order in Tab.\ref{kb-items} on p.\pageref{kb-items}.
agriesma@306
  1511
{\begin{table}[h]
agriesma@306
  1512
\caption{Atomic items of the KB} \label{kb-items}
agriesma@306
  1513
%\tabcolsep=0.3mm
agriesma@306
  1514
\begin{center}
agriesma@306
  1515
\def\arraystretch{1.0}
agriesma@306
  1516
\begin{tabular}{lp{9.0cm}}
agriesma@306
  1517
abbrevation & description \\
agriesma@306
  1518
\hline
agriesma@306
  1519
&\\
agriesma@306
  1520
{\it calc\_list}
agriesma@306
  1521
& associationlist of the evaluation-functions {\it eval\_fn}\\
agriesma@306
  1522
{\it eval\_fn}
agriesma@306
  1523
& evaluation-function for numerals and for predicates coded in SML\\
agriesma@306
  1524
{\it eval\_rls   }
agriesma@306
  1525
& ruleset {\it rls} for simplifying expressions with {\it eval\_fn}s\\
agriesma@306
  1526
{\it fmz}
agriesma@306
  1527
& formalization, i.e. a minimal formula representation of an example \\
agriesma@306
  1528
{\it met}
agriesma@306
  1529
& a method, i.e. a datastructure holding all informations for the solving phase ({\it rew\_ord}, {\it scr}, etc.)\\
agriesma@306
  1530
{\it metID}
agriesma@306
  1531
& reference to a {\it met}\\
agriesma@306
  1532
{\it op}
agriesma@306
  1533
& operator as key to an {\it eval\_fn} in a {\it calc\_list}\\
agriesma@306
  1534
{\it pbl}
agriesma@306
  1535
& problem, i.e. a node in the problem-hierarchy\\
agriesma@306
  1536
{\it pblID}
agriesma@306
  1537
& reference to a {\it pbl}\\
agriesma@306
  1538
{\it rew\_ord}
agriesma@306
  1539
& rewrite-order\\
agriesma@306
  1540
{\it rls}
agriesma@306
  1541
& ruleset, i.e. a datastructure holding theorems {\it thm} and operators {\it op} for simplification (with a {\it rew\_ord})\\
agriesma@306
  1542
{\it Rrls}
agriesma@306
  1543
& ruleset for 'reverse rewriting' (an \isac-technique generating stepwise rewriting, e.g. for cancelling fractions)\\
agriesma@306
  1544
{\it scr}
agriesma@306
  1545
& script describing algorithms by tactics, part of a {\it met} \\
agriesma@306
  1546
{\it norm\_rls}
agriesma@306
  1547
& special ruleset calculating a normalform, associated with a {\it thy}\\
agriesma@306
  1548
{\it spec}
agriesma@306
  1549
& specification, i.e. a tripel ({\it thyID, pblID, metID})\\
agriesma@306
  1550
{\it subs}
agriesma@306
  1551
& substitution, i.e. a list of variable-value-pairs\\
agriesma@306
  1552
{\it term}
agriesma@306
  1553
& Isabelle term, i.e. a formula\\
agriesma@306
  1554
{\it thm}
agriesma@306
  1555
& theorem\\     
agriesma@306
  1556
{\it thy}
agriesma@306
  1557
& theory\\
agriesma@306
  1558
{\it thyID}
agriesma@306
  1559
& reference to a {\it thy} \\
agriesma@306
  1560
\end{tabular}\end{center}\end{table}
agriesma@306
  1561
}
agriesma@306
  1562
The relations between tactics and data items are shown in Tab.\ref{tac-kb}on p.\pageref{tac-kb}.
agriesma@306
  1563
{\def\arraystretch{1.2}
agriesma@306
  1564
\begin{table}[h]
agriesma@306
  1565
\caption{Which tactic uses which KB's item~?} \label{tac-kb}
agriesma@306
  1566
\tabcolsep=0.3mm
agriesma@306
  1567
\begin{center}
agriesma@306
  1568
\begin{tabular}{|ll||cccc|ccc|cccc|} \hline
agriesma@306
  1569
tactic  &input &    &    &    &norm\_&   &rew\_&rls &eval\_&eval\_&calc\_&   \\
agriesma@306
  1570
        &      &thy &scr &Rrls&rls  &thm &ord  &Rrls&fn    &rls   &list  &dsc\\
agriesma@306
  1571
\hline\hline
agriesma@306
  1572
Init\_Proof
agriesma@306
  1573
        &fmz   & x  &    &    & x   &    &     &    &      &      &      & x \\
agriesma@306
  1574
        &spec  &    &    &    &     &    &     &    &      &      &      &   \\
agriesma@306
  1575
\hline
agriesma@306
  1576
\multicolumn{13}{|l|}{model phase}\\
agriesma@306
  1577
\hline
agriesma@306
  1578
Add\_*  &term  & x  &    &    & x   &    &     &    &      &      &      & x \\
agriesma@306
  1579
FormFK  &model & x  &    &    & x   &    &     &    &      &      &      & x \\
agriesma@306
  1580
\hline
agriesma@306
  1581
\multicolumn{13}{|l|}{specify phase}\\
agriesma@306
  1582
\hline
agriesma@306
  1583
Specify\_Theory 
agriesma@306
  1584
        &thyID & x  &    &    & x   &    &     &    & x    & x    &      & x \\
agriesma@306
  1585
Specify\_Problem 
agriesma@306
  1586
        &pblID & x  &    &    & x   &    &     &    & x    & x    &      & x \\
agriesma@306
  1587
Refine\_Problem 
agriesma@306
  1588
           &pblID & x  &    &    & x   &    &     &    & x    & x    &      & x \\
agriesma@306
  1589
Specify\_Method 
agriesma@306
  1590
        &metID & x  &    &    & x   &    &     &    & x    & x    &      & x \\
agriesma@306
  1591
Apply\_Method 
agriesma@306
  1592
        &metID & x  & x  &    & x   &    &     &    & x    & x    &      & x \\
agriesma@306
  1593
\hline
agriesma@306
  1594
\multicolumn{13}{|l|}{solve phase}\\
agriesma@306
  1595
\hline
agriesma@306
  1596
Rewrite,\_Inst 
agriesma@306
  1597
        &thm   & x  & x  &    &     & x  &met  &    & x    &met   &      &   \\
agriesma@306
  1598
Rewrite, Detail
agriesma@306
  1599
        &thm   & x  & x  &    &     & x  &rls  &    & x    &rls   &      &   \\
agriesma@306
  1600
Rewrite, Detail
agriesma@306
  1601
        &thm   & x  & x  &    &     & x  &Rrls &    & x    &Rrls  &      &   \\
agriesma@306
  1602
Rewrite\_Set,\_Inst
agriesma@306
  1603
        &rls   & x  & x  &    &     &    &     & x  & x    & x    &      &   \\
agriesma@306
  1604
Calculate  
agriesma@306
  1605
        &op    & x  & x  &    &     &    &     &    &      &      & x    &   \\
agriesma@306
  1606
Substitute 
agriesma@306
  1607
        &subs  & x  &    &    & x   &    &     &    &      &      &      &   \\
agriesma@306
  1608
        &      &    &    &    &     &    &     &    &      &      &      &   \\
agriesma@306
  1609
SubProblem 
agriesma@306
  1610
        &spec  & x  & x  &    & x   &    &     &    & x    & x    &      & x \\
agriesma@306
  1611
        &fmz   &    &    &    &     &    &     &    &      &      &      &   \\
agriesma@306
  1612
\hline
agriesma@306
  1613
\end{tabular}\end{center}\end{table}
agriesma@306
  1614
}
agriesma@306
  1615
akremp@766
  1616
\section{\isac's theories}
agriesma@306
  1617
\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}.
agriesma@306
  1618
agriesma@306
  1619
\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}).
agriesma@306
  1620
agriesma@306
  1621
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~!
agriesma@306
  1622
agriesma@306
  1623
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.
agriesma@306
  1624
{\begin{table}[h]
agriesma@306
  1625
\caption{Theories in \isac-version I} \label{theories}
agriesma@306
  1626
%\tabcolsep=0.3mm
agriesma@306
  1627
\begin{center}
agriesma@306
  1628
\def\arraystretch{1.0}
agriesma@306
  1629
\begin{tabular}{lp{9.0cm}}
agriesma@306
  1630
theory & description \\
agriesma@306
  1631
\hline
agriesma@306
  1632
&\\
agriesma@306
  1633
ListI.thy
agriesma@306
  1634
& assigns identifiers to the functions defined in {\tt Isabelle2002/src/HOL/List.thy} and (intermediatly~?) defines some more list functions\\
agriesma@306
  1635
ListI.ML
agriesma@306
  1636
& {\tt eval\_fn} for the additional list functions\\
agriesma@306
  1637
Tools.thy
agriesma@306
  1638
& functions required for the evaluation of scripts\\
agriesma@306
  1639
Tools.ML
agriesma@306
  1640
& the respective {\tt eval\_fn}s\\
agriesma@306
  1641
Script.thy
agriesma@306
  1642
& prerequisites for scripts: types, tactics, tacticals,\\
agriesma@306
  1643
Script.ML
agriesma@306
  1644
& sets of tactics and functions for internal use\\
agriesma@306
  1645
& \\
agriesma@306
  1646
\hline
agriesma@306
  1647
& \\
agriesma@306
  1648
Typefix.thy
agriesma@306
  1649
& an intermediate hack for escaping type errors\\
agriesma@306
  1650
Descript.thy
agriesma@306
  1651
& {\it description}s for the formulas in {\it model}s and {\it problem}s\\
agriesma@306
  1652
Atools
agriesma@306
  1653
& (re-)definition of operators; general predicates and functions for preconditions; theorems for the {\tt eval\_rls}\\
agriesma@306
  1654
Float
agriesma@306
  1655
& floating point numerals\\
agriesma@306
  1656
Equation
agriesma@306
  1657
& basic notions for equations and equational systems\\
agriesma@306
  1658
Poly
agriesma@306
  1659
& polynomials\\
agriesma@306
  1660
PolyEq
agriesma@306
  1661
& polynomial equations and equational systems \\
agriesma@306
  1662
Rational.thy
agriesma@306
  1663
& additional theorems for rationals\\
agriesma@306
  1664
Rational.ML
agriesma@306
  1665
& cancel, add and simplify rationals using (a generalization of) Euclids algorithm; respective reverse rulesets\\
agriesma@306
  1666
RatEq
agriesma@306
  1667
& equations on rationals\\
agriesma@306
  1668
Root
agriesma@306
  1669
& radicals; calculate normalform; respective reverse rulesets\\
agriesma@306
  1670
RootEq
agriesma@306
  1671
& equations on roots\\
agriesma@306
  1672
RatRootEq
agriesma@306
  1673
& equations on rationals and roots (i.e. on terms containing both operations)\\
agriesma@306
  1674
Vect
agriesma@306
  1675
& vector analysis\\
agriesma@306
  1676
Trig
agriesma@306
  1677
& trigonometriy\\
agriesma@306
  1678
LogExp
agriesma@306
  1679
& logarithms and exponential functions\\
agriesma@306
  1680
Calculus
agriesma@306
  1681
& nonstandard analysis\\
agriesma@306
  1682
Diff
agriesma@306
  1683
& differentiation\\
agriesma@306
  1684
DiffApp
agriesma@306
  1685
& applications of differentiaten (maxima-minima-problems)\\
agriesma@306
  1686
Test
agriesma@306
  1687
& (old) data for the test suite\\
agriesma@306
  1688
Isac
agriesma@306
  1689
& collects all \isac-theoris.\\
agriesma@306
  1690
\end{tabular}\end{center}\end{table}
agriesma@306
  1691
}
agriesma@306
  1692
agriesma@306
  1693
akremp@766
  1694
\section{Data in {\tt *.thy}- and {\tt *.ML}-files}
agriesma@306
  1695
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}.
agriesma@306
  1696
{\begin{table}[h]
agriesma@306
  1697
\caption{Data in {\tt *.thy}- and {\tt *.ML}-files} \label{thy-ML}
agriesma@306
  1698
\tabcolsep=2.0mm
agriesma@306
  1699
\begin{center}
agriesma@306
  1700
\def\arraystretch{1.0}
agriesma@306
  1701
\begin{tabular}{llp{7.7cm}}
agriesma@306
  1702
file & data & description \\
agriesma@306
  1703
\hline
agriesma@306
  1704
& &\\
agriesma@306
  1705
{\tt *.thy}
agriesma@306
  1706
& consts 
agriesma@306
  1707
& operators, predicates, functions, script-names ('{\tt Script} name \dots{\tt arguments}')
agriesma@306
  1708
\\
agriesma@306
  1709
& rules  
agriesma@306
  1710
& theorems: \isac{} uses Isabelles theorems if possible; additional theorems analoguous to such existing in Isabelle get the Isabelle-identifier attached an {\it I}
agriesma@306
  1711
\\& &\\
agriesma@306
  1712
{\tt *.ML}
agriesma@306
  1713
& {\tt theory' :=} 
agriesma@306
  1714
& the theory defined by the actual {\tt *.thy}-file is made accessible to \isac
agriesma@306
  1715
\\
agriesma@306
  1716
& {\tt eval\_fn}
agriesma@306
  1717
& 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}
agriesma@306
  1718
\\
agriesma@306
  1719
& {\tt *\_simplify} 
agriesma@306
  1720
& 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}
agriesma@306
  1721
\\
agriesma@306
  1722
& {\tt norm\_rls :=}
agriesma@306
  1723
& the canonical simplifier {\tt *\_simplify} is stored such that it is accessible for \isac
agriesma@306
  1724
\\
agriesma@306
  1725
& {\tt rew\_ord' :=}
agriesma@306
  1726
& the same for rewrite orders, if needed outside of one particular ruleset
agriesma@306
  1727
\\
agriesma@306
  1728
& {\tt ruleset' :=}
agriesma@306
  1729
& the same for rulesets (ordinary rulesets, reverse rulesets and {\tt eval\_rls})
agriesma@306
  1730
\\
agriesma@306
  1731
& {\tt calc\_list :=}
agriesma@306
  1732
& the same for {\tt eval\_fn}s, if needed outside of one particular ruleset (e.g. for a tactic {\tt Calculate} in a script)
agriesma@306
  1733
\\
agriesma@306
  1734
& {\tt store\_pbl}
agriesma@306
  1735
& problems defined within this {\tt *.ML}-file are made accessible for \isac
agriesma@306
  1736
\\
agriesma@306
  1737
& {\tt methods :=}
agriesma@306
  1738
& methods defined within this {\tt *.ML}-file are made accessible for \isac
agriesma@306
  1739
\\
agriesma@306
  1740
\end{tabular}\end{center}\end{table}
agriesma@306
  1741
}
agriesma@306
  1742
The order of the data-items within the theories should adhere to the order given in this list.
agriesma@306
  1743
akremp@766
  1744
\section{Formal description of the problem-hierarchy}
agriesma@306
  1745
%for Richard Lang
agriesma@306
  1746
akremp@766
  1747
\section{Script tactics}
agriesma@306
  1748
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.
agriesma@306
  1749
agriesma@306
  1750
agriesma@306
  1751
agriesma@306
  1752
agriesma@306
  1753
akremp@766
  1754
\part{Authoring on the knowledge}
agriesma@306
  1755
agriesma@306
  1756
akremp@766
  1757
\section{Add a theorem}
akremp@766
  1758
\section{Define and add a problem}
akremp@766
  1759
\section{Define and add a predicate}
akremp@766
  1760
\section{Define and add a method}
akremp@766
  1761
\section{}
akremp@766
  1762
\section{}
akremp@766
  1763
\section{}
akremp@766
  1764
\section{}
agriesma@306
  1765
agriesma@306
  1766
agriesma@306
  1767
agriesma@306
  1768
\newpage
wneuper@3020
  1769
\bibliography{bib/isac,bib/from-theses}
agriesma@306
  1770
akremp@766
  1771
\end{document}