test/Pure/Isar/Struct_Deriv.thy
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 23 Nov 2010 08:38:32 +0100
branchdecompose-isar
changeset 38072 a6ce90b2f06a
parent 38071 679dd9ebb17b
child 42047 f6a001b47a84
permissions -rw-r--r--
tuned
neuper@37908
     1
(*
neuper@37908
     2
$ cd /usr/local/isabisac/src/Pure/isac/smltest/Pure/Isar
neuper@38067
     3
$ /usr/local/isabisac/bin/isabelle emacs Struct_Deriv.thy &
neuper@38067
     4
$ /usr/local/isabisac/bin/isabelle jedit Struct_Deriv.thy &
neuper@37908
     5
*)
neuper@37908
     6
neuper@37908
     7
header {* structured derivations (SD) according to R.J.Back *}
neuper@37908
     8
neuper@38067
     9
theory Struct_Deriv
neuper@37908
    10
imports Main
neuper@37908
    11
begin
neuper@38072
    12
text {* table of contents
neuper@38072
    13
1. fun parse for SDs by minimal copy from Isabelle code
neuper@38072
    14
1.1. keywords and outer syntax preparing parser setup
neuper@38067
    15
1.1.1. keywords according to src/Pure/Isar/keyword.ML
neuper@38067
    16
1.1.2. outer syntax according to src/Pure/Isar/outer_syntax.ML
neuper@38072
    17
1.1.3. parser setup according to src/Pure/Isar/isar_syn.ML
neuper@38072
    18
1.2. minimalized fun parse by Stefan Berghofer
neuper@38071
    19
2. provisional parser for SD
neuper@38072
    20
2.1. parsers for the elements of a calculation
neuper@38071
    21
2.1.1. named_rule
neuper@38071
    22
2.1.2. term_rule
neuper@38071
    23
2.1.3. rule
neuper@38071
    24
2.1.4. PBLheadline
neuper@38071
    25
2.1.5. CASheadline
neuper@38071
    26
2.1.6. headline
neuper@38071
    27
2.1.7. calcline
neuper@38072
    28
2.2. combine the parsers for elements to a whole SD-parser
neuper@38072
    29
2.2.1. provisional SD-parser setup
neuper@38071
    30
2.2.2. parser applied to example 1
neuper@38071
    31
2.2.3. parser applied to example 2
neuper@38067
    32
*}
neuper@37908
    33
neuper@38072
    34
section {* 1. fun parse for SDs by minimal copy from Isabelle code *}
neuper@37908
    35
neuper@38072
    36
subsection {* 1.1. keywords, outer syntax and parser setup *}
neuper@38067
    37
text {* this is a minimal copy from respective Isabelle sourcefiles,
neuper@38067
    38
  minimal with respect to the goal to parse simple SDs, see ex1, ex2 below.
neuper@38067
    39
neuper@38067
    40
  Actually, the code below has been selected from the function calls at the bottom,
neuper@38067
    41
  up to the initial definitions below.
neuper@38067
    42
neuper@38067
    43
  Some functions have been simplified; code is kept as (* original *)
neuper@38067
    44
  Problems arising with the simplifications will teach the reasons for the original source.
neuper@38067
    45
*}
neuper@37908
    46
neuper@38072
    47
subsubsection {* 1.1.1. keywords according to src/Pure/Isar/keyword.ML*}
neuper@37908
    48
ML {*
neuper@38067
    49
signature KEYWORDC = (*minimal C-copy from KEYWORD*)
neuper@37908
    50
sig
neuper@37908
    51
  type T
neuper@37908
    52
  val kind_of: T -> string
neuper@37908
    53
  val calc_begin: T
neuper@37908
    54
  val keyword: string -> unit
neuper@37908
    55
  val command: string -> T -> unit
neuper@37908
    56
  val tag_calc: T -> T
neuper@37908
    57
end;
neuper@37908
    58
neuper@37908
    59
structure KeywordC: KEYWORDC =
neuper@37908
    60
struct
neuper@37908
    61
neuper@37908
    62
datatype T = KeywordC of string * string list;
neuper@37908
    63
neuper@37908
    64
fun kind s = KeywordC (s, []);
neuper@37908
    65
fun kind_of (KeywordC (s, _)) = s;
neuper@37908
    66
neuper@37908
    67
val calc_begin = kind "calc-begin";
neuper@37908
    68
neuper@37908
    69
(*
neuper@37908
    70
fun change_commands f = CRITICAL (fn () => Unsynchronized.change global_commands f);
neuper@37908
    71
fun change_lexicons f = CRITICAL (fn () => Unsynchronized.change global_lexicons f);
neuper@37908
    72
fun report_message s =
neuper@37908
    73
  (if print_mode_active keyword_status_reportN then Output.status else writeln) s;*)
neuper@37908
    74
fun report_message s =
neuper@37908
    75
  (if true (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) then Output.status else writeln) s;
neuper@37908
    76
fun report_keyword name =
neuper@37908
    77
  report_message (Markup.markup (Markup.keyword_decl name)
neuper@37908
    78
    ("Outer syntax keyword: " ^ quote name));
neuper@37908
    79
fun report_command (name, kind) =
neuper@37908
    80
  report_message (Markup.markup (Markup.command_decl name (kind_of kind))
neuper@37908
    81
    ("Outer syntax command: " ^ quote name ^ " (" ^ kind_of kind ^ ")"));
neuper@37908
    82
neuper@37908
    83
fun keyword name =
neuper@37908
    84
 (apfst (Scan.extend_lexicon (Symbol.explode name));
neuper@37908
    85
  report_keyword name);
neuper@37908
    86
(* see CRITICAL above
neuper@37908
    87
fun command name kind =
neuper@37908
    88
 (change_lexicons (apsnd (Scan.extend_lexicon (Symbol.explode name)));
neuper@37908
    89
  change_commands (Symtab.update (name, kind));
neuper@37908
    90
  report_command (name, kind));*)
neuper@37908
    91
fun command name kind =
neuper@37908
    92
 (apsnd (Scan.extend_lexicon (Symbol.explode name));
neuper@37908
    93
  Symtab.update (name, kind);
neuper@37908
    94
  report_command (name, kind));
neuper@37908
    95
neuper@37908
    96
fun update_tags t ts = t :: remove (op = : string * string -> bool) t ts;
neuper@37908
    97
fun tag t (KeywordC (s, ts)) = KeywordC (s, update_tags t ts);
neuper@37908
    98
val tag_calc = tag "calculation"; (* <----------------------------------------*)
neuper@37908
    99
neuper@37908
   100
end; *}
neuper@37908
   101
neuper@38072
   102
subsubsection {* 1.1.2. outer syntax according to src/Pure/Isar/outer_syntax.ML*}
neuper@37908
   103
ML {* 
neuper@37908
   104
signature OUTER_SYNTAXC = 
neuper@37908
   105
sig
neuper@37908
   106
  val command: string -> string -> KeywordC.T ->
neuper@37908
   107
    (Toplevel.transition -> Toplevel.transition) parser -> unit
neuper@37908
   108
  val scan: Position.T -> string -> Token.T list
neuper@37908
   109
end;
neuper@37908
   110
neuper@37908
   111
structure Outer_SyntaxC: OUTER_SYNTAXC =
neuper@37908
   112
struct
neuper@37908
   113
neuper@37908
   114
datatype command = CommandC of
neuper@37908
   115
 {comment: string,
neuper@37908
   116
  markup: Thy_Output.markup option,
neuper@37908
   117
  int_only: bool,
neuper@37908
   118
  parse: (Toplevel.transition -> Toplevel.transition) parser};
neuper@37908
   119
neuper@37908
   120
fun make_command comment markup int_only parse =
neuper@37908
   121
  CommandC {comment = comment, markup = markup, int_only = int_only, parse = parse};
neuper@37908
   122
neuper@37908
   123
val global_commands = Unsynchronized.ref (Symtab.empty: command Symtab.table);
neuper@37908
   124
val global_markups = Unsynchronized.ref ([]: (string * Thy_Output.markup) list);
neuper@37908
   125
neuper@37908
   126
fun change_commands f = CRITICAL (fn () =>
neuper@37908
   127
 (Unsynchronized.change global_commands f;
neuper@37908
   128
  global_markups :=
neuper@37908
   129
    Symtab.fold (fn (name, CommandC {markup = SOME m, ...}) => cons (name, m) | _ => I)
neuper@37908
   130
      (! global_commands) []));
neuper@37908
   131
fun get_commands () = ! global_commands;
neuper@37908
   132
fun add_command name kind cmd = CRITICAL (fn () =>
neuper@37908
   133
 (KeywordC.command name kind;
neuper@37908
   134
  if not (Symtab.defined (get_commands ()) name) then ()
neuper@37908
   135
  else warning ("Redefining outer syntax command " ^ quote name);
neuper@37908
   136
  change_commands (Symtab.update (name, cmd))));
neuper@37908
   137
neuper@37908
   138
fun command name comment kind parse =
neuper@37908
   139
  add_command name kind (make_command comment NONE false parse);
neuper@37908
   140
neuper@37908
   141
fun scan pos str =
neuper@37908
   142
  Source.of_string str
neuper@37908
   143
  |> Symbol.source {do_recover = false}
neuper@37908
   144
  |> Token.source {do_recover = SOME false} Keyword.get_lexicons pos
neuper@37908
   145
  |> Source.exhaust;
neuper@37908
   146
end; *}
neuper@37908
   147
neuper@38072
   148
subsubsection {* 1.1.3. parser setup according to src/Pure/Isar/isar_syn.ML *}
neuper@38072
   149
ML {* 
neuper@37908
   150
structure Isac_Syn: sig end =
neuper@37908
   151
struct
neuper@37908
   152
neuper@37918
   153
val _ = List.app (*contrib/polyml-5.3.0/src/basis/List.sml*) KeywordC.keyword
neuper@37918
   154
 ["(", ")", "[", "]", ",",
neuper@37918
   155
  "=>", "<=", 
neuper@37918
   156
  "==",              (* simplification without "=" in term      *)
neuper@37918
   157
  "equiv",           (* equations, etc                          *)
neuper@37918
   158
  "bullet",          (* indicates a subproblem TODO rewrite_set *)
neuper@37918
   159
  "CAS", "Problem",  (* "headlines" of subproblems              *)
neuper@37918
   160
  "dots",            (* end of subproblem TODO of rewrite_set   *)
neuper@37918
   161
(*"bigtriangledown",    indicates a rule *)
neuper@37918
   162
  "THM", "MET",      (* a ruleconcerning a theorem, a method    *)
neuper@37918
   163
  "Calculate", "Rewrite", "Rewrite_Set", "Rewrite_Inst", "Rewrite_Set_Inst",
neuper@37918
   164
                     (* rules; TODO?!? Take REFERENCE           *)
neuper@37918
   165
  "top",             (* term not following from previous term   *)
neuper@37918
   166
  "Box"              (* qed                                     *)
neuper@37918
   167
 ];             
neuper@37908
   168
neuper@37908
   169
val _ =
neuper@37908
   170
  Outer_SyntaxC.command "calculation" "begin calc" (KeywordC.tag_calc KeywordC.calc_begin)
neuper@37908
   171
    (Thy_Header.args >> (Toplevel.print oo Isar_Cmd.init_theory)); (*TODO*)
neuper@37908
   172
end; *}
neuper@37908
   173
neuper@38072
   174
subsection {* 1.2. minimalized fun parse by Stefan Berghofer *}
neuper@37908
   175
text {* see ~/devel/IsaDevWS/IsaDevWS-10/T05_Methods.thy by Stefan Berghofer *}
neuper@37908
   176
ML {*
neuper@37908
   177
fun filtered_input str =
neuper@37908
   178
  filter Token.is_proper (Outer_SyntaxC.scan Position.none str);
neuper@38072
   179
(*################################ fun parse ###############################################*)
neuper@37908
   180
fun parse p str = Scan.finite Token.stopper p (filtered_input str);
neuper@38072
   181
(*################################ fun parse ###############################################*)
neuper@37908
   182
*}
neuper@37908
   183
neuper@37908
   184
neuper@38072
   185
section {* 2. provisional parser for SD *}
neuper@38072
   186
subsection {* 2.1. parsers for the elements of a calculation *}
neuper@37917
   187
neuper@38072
   188
subsubsection {* 2.1.1. named_rule *}
neuper@37918
   189
ML {*
neuper@37918
   190
"---1----------------------------------------";
neuper@37918
   191
val named_rule' = (Args.$$$ "Calculate" || Args.$$$ "Rewrite" || Args.$$$ "Rewrite_Set"
neuper@37918
   192
                || Args.$$$ "Rewrite_Inst" || Args.$$$ "Rewrite_Set_Inst")
neuper@37918
   193
               -- Args.name;
neuper@37918
   194
parse named_rule' "Calculate times";
neuper@37918
   195
(*(("Calculate", "times"), []) : (string * string) * Token.T list*)
neuper@37918
   196
neuper@37918
   197
fun exec2 (nam, rul) = 
neuper@37918
   198
  "*** notebook->ML: " ^ nam ^ " " ^ rul
neuper@37918
   199
  |> (fn x => (x, x))
neuper@37918
   200
  |>> writeln
neuper@37918
   201
  |> #2;
neuper@37918
   202
(*fn : string * string -> string*)
neuper@37918
   203
val named_rule = named_rule' >> exec2;
neuper@37918
   204
"---2----------------------------------------";
neuper@37918
   205
neuper@37918
   206
parse named_rule "Calculate times";
neuper@37918
   207
(*("*** notebook->ML: Calculate times", []) : string * Token.T list*)
neuper@37918
   208
neuper@37918
   209
"---3--- output on top ----------------------";
neuper@37918
   210
(*** notebook->ML: Calculate times*)
neuper@37918
   211
*}
neuper@37918
   212
neuper@38072
   213
subsubsection {* 2.1.2. term_rule *}
neuper@37918
   214
ML {*
neuper@37918
   215
"---1----------------------------------------";
neuper@37918
   216
val term_rule' = Args.$$$ "THM" -- Parse.term;
neuper@37918
   217
parse term_rule' "THM \"(a+x=b)=(x=-a*b)\"  ";
neuper@37918
   218
(*(("THM", "\^E\^Ftoken\^Ea+x=b = x=-a*b\^E\^F\^E"), []) : (string * string) * Token.T list*)
neuper@37918
   219
val term_rule = term_rule' >> exec2;
neuper@37918
   220
"---2----------------------------------------";
neuper@37918
   221
neuper@37918
   222
parse term_rule "THM \"(a+x=b)=(x=-a*b)\"  ";
neuper@37918
   223
(*("*** notebook->ML: THM \^E\^Ftoken\^E(a+x=b)=(x=-a*b)\^E\^F\^E", []) : string * Token.T list*)
neuper@37918
   224
neuper@37918
   225
"---3--- output on top ----------------------";
neuper@37918
   226
(*** notebook->ML: THM (a+x=b)=(x=-a*b)*)
neuper@37918
   227
*}
neuper@37918
   228
neuper@38072
   229
subsubsection {* 2.1.3. rule *}
neuper@37918
   230
ML {*
neuper@37918
   231
val rule = named_rule || term_rule;
neuper@37918
   232
*}
neuper@37918
   233
neuper@37918
   234
neuper@38072
   235
subsubsection {* 2.1.4. PBLheadline *}
neuper@37917
   236
ML {*
neuper@37917
   237
"---1----------------------------------------";
neuper@37917
   238
val PBLheadline' = Args.$$$ "Problem" -- Args.$$$ "(" -- Args.name -- Args.$$$ ","
neuper@37917
   239
  -- (Parse.$$$ "[" |-- Parse.list Parse.name --| Parse.$$$ "]") 
neuper@37917
   240
  -- Args.$$$ ")";
neuper@37917
   241
parse PBLheadline' "Problem (Biegelinie.thy, [Biegelinien])";
neuper@37917
   242
(*val it = (((((("Problem", "("), "Biegelinie.thy"), ","), ["Biegelinien"]), ")"), [])
neuper@37917
   243
   : (((((string * string) * string) * string) * bstring list) * string) * Token.T list*)
neuper@37917
   244
neuper@37917
   245
fun execN ((((("Problem", "("), thy             ), ","), pbl            ), ")") =
neuper@37917
   246
  "*** notebook->ML: Problem (" ^ thy ^ ", " ^ ((fn ss => "[" ^ commas ss ^ "]") pbl) ^ ")"
neuper@37917
   247
  |> (fn x => (x, x))
neuper@37917
   248
  |>> writeln
neuper@37917
   249
  |> #2;
neuper@37917
   250
(*fn : ((((string * string) * string) * string) * string list) * string -> string*)
neuper@37917
   251
"---2----------------------------------------";
neuper@37917
   252
execN     ((((("Problem", "("), "Biegelinie.thy"), ","), ["Biegelinien"]), ")");
neuper@37917
   253
(*"*** notebook->ML: Problem (Biegelinie.thy, [Biegelinien])" : string
neuper@37917
   254
 +see top*)
neuper@37917
   255
neuper@37917
   256
val PBLheadline = PBLheadline' >> execN;
neuper@37917
   257
parse PBLheadline "Problem (Biegelinie.thy, [Biegelinien])";
neuper@37917
   258
(*("*** notebook->ML: Problem (Biegelinie.thy, [Biegelinien])", []) : string * Token.T list
neuper@37917
   259
 +see top*)
neuper@37917
   260
parse PBLheadline "Problem (Biegelinie.thy, [setzeRandbedingungen, Biegelinien])";
neuper@37917
   261
(*("*** notebook->ML: Problem (Biegelinie.thy, [setzeRandbedingungen, Biegelinien])", [])
neuper@37917
   262
 +see top*)
neuper@37917
   263
neuper@37917
   264
"---3--- output on top ----------------------";
neuper@37917
   265
(** notebook->ML: Problem (Biegelinie.thy, [Biegelinien])
neuper@37917
   266
*** notebook->ML: Problem (Biegelinie.thy, [Biegelinien])
neuper@37917
   267
*** notebook->ML: Problem (Biegelinie.thy, [setzeRandbedingungen, Biegelinien])*)
neuper@37917
   268
*}
neuper@37917
   269
neuper@38072
   270
subsubsection {* 2.1.5. CASheadline *}
neuper@37917
   271
ML {*
neuper@37917
   272
"---1----------------------------------------";
neuper@37917
   273
val CASheadline' = Args.$$$ "CAS" -- Parse.term;
neuper@37917
   274
parse CASheadline' "CAS \"solve(x+1=2,x)\"";
neuper@37917
   275
(*(("CAS", "\^E\^Ftoken\^Esolve(x+1=2,x)\^E\^F\^E"), []) : (string * string) * Token.T list*)
neuper@37917
   276
neuper@37917
   277
fun exec2b ("CAS", trm) = 
neuper@37917
   278
  "*** notebook->ML: \"" ^ trm ^ "\""
neuper@37917
   279
  |> (fn x => (x, x))
neuper@37917
   280
  |>> writeln
neuper@37917
   281
  |> #2;
neuper@37917
   282
(*fn : string * string -> string*)
neuper@37917
   283
val CASheadline = CASheadline' >> exec2b;
neuper@37917
   284
"---2----------------------------------------";
neuper@37917
   285
neuper@37917
   286
parse CASheadline "CAS \"solve(x+1=2,x)\"";
neuper@37917
   287
(*("*** notebook->ML: \^E\^Ftoken\^Esolve(x+1=2,x)\^E\^F\^E", []) : string * Token.T list*)
neuper@37917
   288
neuper@37917
   289
"---3--- output on top ----------------------";
neuper@37917
   290
(*** notebook->ML: solve(x+1=2,x)*)
neuper@37917
   291
*}
neuper@37917
   292
neuper@38072
   293
subsubsection {* 2.1.6. headline *}
neuper@37917
   294
ML {*
neuper@37918
   295
val headline = (PBLheadline || CASheadline) -- Scan.option rule;
neuper@37918
   296
neuper@37918
   297
parse headline "Problem (Biegelinie.thy, [setzeRandbedingungen, Biegelinien])";
neuper@37918
   298
parse headline "CAS \"solve(x+1=2,x)\"";
neuper@37918
   299
parse headline "CAS \"solve(x+1=2,x)\" Calculate times";
neuper@37918
   300
parse headline "CAS \"solve(x+1=2,x)\" THM \"(a+x=b)=(x=-a*b)\" ";
neuper@37917
   301
*}
neuper@37917
   302
neuper@38072
   303
subsubsection {* 2.1.7. calcline *}
neuper@37917
   304
ML {*
neuper@37917
   305
"---1----------------------------------------";
neuper@37918
   306
val calcline' = Parse.term ;
neuper@37917
   307
parse calcline' "  \"-1 + x = 0\"  ";
neuper@37917
   308
(*("\^E\^Ftoken\^E-1 + x = 0\^E\^F\^E", []) : string * Token.T list*)
neuper@37917
   309
neuper@37917
   310
fun exec1 trm = 
neuper@37917
   311
  "*** notebook->ML: \"" ^ trm ^ "\""
neuper@37917
   312
  |> (fn x => (x, x))
neuper@37917
   313
  |>> writeln
neuper@37917
   314
  |> #2;
neuper@37917
   315
(*fn : string -> string*)
neuper@37917
   316
val calcline = calcline' >> exec1;
neuper@37917
   317
"---2----------------------------------------";
neuper@37917
   318
neuper@37917
   319
parse calcline "  \"-1 + x = 0\"  ";
neuper@37917
   320
(*("*** notebook->ML: \"\^E\^Ftoken\^E-1 + x = 0\^E\^F\^E\"", []) : string * Token.T list*)
neuper@37917
   321
neuper@37917
   322
"---3--- output on top ----------------------";
neuper@37917
   323
(*** notebook->ML: "-1 + x = 0"*)
neuper@37917
   324
*}
neuper@37917
   325
neuper@38072
   326
subsection {* 2.2. combine the parsers for elements to a whole SD-parser *}
neuper@37917
   327
neuper@38072
   328
subsubsection {* 2.2.1. provisional SD-parser setup *}
neuper@37917
   329
text {* Prefixes, which are complete enough to trigger a semantic action,
neuper@37917
   330
        have already be handled by exec*.
neuper@37917
   331
        Thus combining such prefixes allows to drop these prefixes. *}
neuper@37917
   332
ML {*
neuper@37917
   333
fun drop_prefixes _ = "DROPPED PREFIXES";
neuper@37917
   334
*}
neuper@37917
   335
neuper@37917
   336
ML {*
neuper@37918
   337
(*val line = headline || calcline; ...this would prevent separation of rewrite_set *)
neuper@37917
   338
val level_up = Args.$$$ "dots" -- calcline;
neuper@37917
   339
*}
neuper@37917
   340
neuper@37917
   341
ML {* (* see IsaDevWS-10/T06_System.thy "recursive parsers" *)
neuper@37917
   342
fun body _ source = 
neuper@37917
   343
   (  Scan.repeat(    Args.$$$ "top" -- calcline -- 
neuper@37917
   344
                        (Scan.repeat (Args.$$$ "equiv" -- calcline)) >> drop_prefixes
neuper@37917
   345
(* GOON            || (Scan.repeat (Args.$$$ "equiv" -- calcline))   >> drop_prefixes  *)
neuper@37917
   346
                   || Args.$$$ "bullet" -- headline -- body ""       >> drop_prefixes
neuper@37917
   347
                 ) 
neuper@37917
   348
      -- level_up
neuper@37917
   349
   ) source;
neuper@37917
   350
neuper@37917
   351
writeln "---0-------";
neuper@37917
   352
parse (body "") "top \"1+2\" equiv \"3+4\" dots \"5+6\" ";
neuper@37917
   353
neuper@37917
   354
writeln "---1-------";
neuper@37917
   355
parse (body "") "bullet CAS \"solve(x+1=2,x)\" \
neuper@37917
   356
                \top \"1+2\" equiv \"3+4\" dots \"5+6\" dots \"999\" ";
neuper@37917
   357
writeln "---2-------";
neuper@37917
   358
parse (body "") "    bullet CAS \"solve (-1 + x = 0, x)\"          \n\
neuper@37917
   359
                \       top \"-1 + x = 0\"                         \n\
neuper@37917
   360
                \       equiv \"[x = 1]\"                          \n\
neuper@37917
   361
                \    dots \"[x = 1]\"                              \n\
neuper@37917
   362
                \ dots \"[x = 1]\"                                 ";
neuper@37917
   363
*}
neuper@37917
   364
neuper@37917
   365
ML {*
neuper@38072
   366
(*################################ the parser ##############################################*)
neuper@37917
   367
val SD = Args.$$$ "calculation" -- Args.$$$ "bullet" -- headline 
neuper@37917
   368
         -- (body "") 
neuper@37917
   369
         -- (Scan.option (Args.$$$ "Box"));
neuper@38072
   370
(*################################ the parser ##############################################*)
neuper@37917
   371
neuper@37918
   372
writeln "---0----------------------------------------";
neuper@37917
   373
parse SD "calculation                      \n\
neuper@37917
   374
         \ bullet CAS \"solve(x+1=2,x)\"   \n\
neuper@37917
   375
         \ dots \"[x = 1]\"                ";
neuper@37918
   376
writeln "---1-----------------------------------------";
neuper@37917
   377
parse SD "calculation                              \n\
neuper@37917
   378
         \ bullet CAS \"solve(x+1=2,x)\"           \n\
neuper@37917
   379
         \    top \"x + 1 = 2\"                    \n\
neuper@37917
   380
         \    equiv \"-1 + x = 0\"                 \n\
neuper@37917
   381
         \    bullet CAS \"solve (-1 + x = 0, x)\" \n\
neuper@37917
   382
         \       top \"-1 + x = 0\"                \n\
neuper@37917
   383
         \       equiv \"[x = 1]\"                 \n\
neuper@37917
   384
         \    dots \"[x = 1]\"                     \n\
neuper@37917
   385
         \ dots \"[x = 1]\"                        \n\
neuper@37917
   386
         \ Box                                     ";
neuper@37918
   387
writeln "---2-----------------------------------------";
neuper@37918
   388
neuper@37918
   389
(* TODO ?!?
neuper@37917
   390
parse SD "calculation                              \n\
neuper@37917
   391
         \ bullet CAS \"solve(x+1=2,x)\"           \n\
neuper@37918
   392
         \                Calculate times          \n\
neuper@37917
   393
         \    top \"x + 1 = 2\"                    \n\
neuper@37918
   394
         \    equiv \"-1 + x = 0\"                 \n\
neuper@37918
   395
         \                THM \"(a+x=b)=(x=-a*b)\" \n\
neuper@37918
   396
         \ dots \"[x = 1]\"                        \n\
neuper@37918
   397
         \ Box                                     ";
neuper@37918
   398
*)
neuper@37918
   399
neuper@37918
   400
writeln "---3-----------------------------------------";
neuper@37918
   401
(* GOON: make equiv a viable prefix at this position !
neuper@37918
   402
parse SD "calculation                              \n\
neuper@37918
   403
         \ bullet CAS \"solve(x+1=2,x)\"           \n\
neuper@37917
   404
         \    bullet CAS \"solve (-1 + x = 0, x)\" \n\
neuper@37917
   405
         \    dots \"[x = 1]\"                     \n\
neuper@37917
   406
         \    equiv \"-1 + x = 0\"                 \n\
neuper@37917
   407
         \ dots \"[x = 1]\"                        \n\
neuper@37917
   408
         \ Box                                     ";
neuper@37917
   409
*)
neuper@37918
   410
writeln "---4-----------------------------------------";
neuper@37917
   411
neuper@37917
   412
*}
neuper@37917
   413
neuper@37917
   414
neuper@38072
   415
subsubsection {* 2.2.2. parser applied to example 1 *}
neuper@37908
   416
ML {*
neuper@37916
   417
val ex1 = "calculation                      \n\
neuper@37916
   418
  \ bullet CAS \"solve(x+1=2,x)\"           \n\
neuper@37916
   419
  \    top \"x + 1 = 2\"                    \n\
neuper@37916
   420
  \    equiv \"x + 1 - 2 = 0\"              \n\
neuper@37916
   421
  \    equiv \"-1 + x = 0\"                 \n\
neuper@37918
   422
  \    bullet CAS \"solve (-1 + x = 0, x)\" \n\
neuper@37916
   423
  \       top \"-1 + x = 0\"                \n\
neuper@37916
   424
  \       equiv \"x = -1 * -1\"             \n\
neuper@37916
   425
  \       equiv \"x = 1\"                   \n\
neuper@37916
   426
  \       equiv \"[x = 1]\"                 \n\
neuper@37916
   427
  \    dots \"[x = 1]\"                     \n\
neuper@37916
   428
  \ dots \"[x = 1]\"                        \n\
neuper@37908
   429
  \ Box ";
neuper@37908
   430
neuper@37918
   431
parse SD ex1;
neuper@37917
   432
*}
neuper@37917
   433
neuper@38072
   434
subsubsection {* 2.2.3. parser applied to example 2 *}
neuper@37917
   435
ML {*
neuper@37916
   436
val ex2 = "calculation                                                                                                             \n\
neuper@37916
   437
  \ bullet Problem (Biegelinie.thy, [Biegelinien])                                                                                 \n\
neuper@37916
   438
  \    bullet Problem (Biegelinie.thy, [vonBelastungZu, Biegelinien])                                                              \n\
neuper@37916
   439
  \    dots \"[Q x = c + -1 * q_0 * x, M_b x = c_2 + c * x + -1 * q_0 / 2 * x ^ 2,                                                 \n\
neuper@37916
   440
  \          y' x = c_3 + 1 / (-1 * EI) * (c_2 * x + c / 2 * x ^ 2 + -1 * q_0 / 6 * x ^ 3),                                        \n\
neuper@37916
   441
  \          y x = c_4 + c_3 * x + 1 / (-1 * EI) * (c_2 / 2 * x ^ 2 + c / 6 * x ^ 3 + -1 * q_0 / 24 * x ^ 4)]\"                    \n\
neuper@37916
   442
  \    bullet Problem (Biegelinie.thy, [setzeRandbedingungen, Biegelinien])                                                        \n\
neuper@37916
   443
  \    dots \"[L * q_0 = c, 0 = (2 * c_2 + 2 * L * c + -1 * L ^ 2 * q_0) / 2, 0 = c_4, 0 = c_3]\"                                  \n\
neuper@37916
   444
  \    bullet CAS \"solveSystem [0 = c_3] [c_4]\"                                                                                  \n\
neuper@37916
   445
  \    dots \"[c = L * q_0, c_2 = -1 * L ^ 2 * q_0 / 2, c_3 = 0, c_4 = 0]\"                                                        \n\
neuper@37916
   446
  \    top \"y x = c_4 + c_3 * x + 1 / (-1 * EI) * (c_2 / 2 * x ^ 2 + c / 6 * x ^ 3 + -1 * q_0 / 24 * x ^ 4)\"                     \n\
neuper@37916
   447
  \    equiv \"y x = 0 + 0 * x + 1 / (-1 * EI) * (-1 * L ^ 2 * q_0 / 2 / 2 * x ^ 2 + L * q_0 / 6 * x ^ 3 + -1 * q_0 / 24 * x ^ 4)\"\n\
neuper@37916
   448
  \    equiv \"y x = -6 * q_0 * L ^ 2 / (-24 * EI) * x ^ 2 + 4 * L * q_0 / (-24 * EI) * x ^ 3 + -1 * q_0 / (-24 * EI) * x ^ 4\"    \n\
neuper@37916
   449
  \ dots \"y x = -6 * q_0 * L ^ 2 / (-24 * EI) * x ^ 2 + 4 * L * q_0 / (-24 * EI) * x ^ 3 + -1 * q_0 / (-24 * EI) * x ^ 4\"        \n\
neuper@37908
   450
  \ Box";
neuper@37918
   451
neuper@37918
   452
parse SD ex2;
neuper@37908
   453
*}
neuper@37908
   454
neuper@37908
   455
end