test/Tools/isac/ProgLang/prog_expr.sml
author wneuper <walther.neuper@jku.at>
Mon, 19 Jul 2021 17:29:35 +0200
changeset 60336 dcb37736d573
parent 60331 40eb8aa2b0d6
child 60339 0d22a6bf1fc6
permissions -rw-r--r--
introduce ALL valid const_name in test/*
walther@60278
     1
(* Title:  ProgLang/program.sml
walther@59633
     2
   Author: Walther Neuper 190922
walther@59633
     3
   (c) due to copyright terms
walther@59633
     4
*)
walther@59633
     5
walther@59633
     6
"-----------------------------------------------------------------------------------------------";
walther@59633
     7
"-----------------------------------------------------------------------------------------------";
walther@59633
     8
"table of contents -----------------------------------------------------------------------------";
walther@59633
     9
"-----------------------------------------------------------------------------------------------";
walther@60322
    10
"-------- fun eval_is_atom ---------------------------------------------------------------------";
walther@60318
    11
"-------- fun eval_is_even ---------------------------------------------------------------------";
walther@60318
    12
"-------- fun eval_const -----------------------------------------------------------------------";
walther@60317
    13
"-------- fun eval_cancel ----------------------------------------------------------------------";
walther@60317
    14
"-------- fun eval_equ -------------------------------------------------------------------------";
walther@59841
    15
"-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------";
walther@59847
    16
"-------- occurs_in ----------------------------------------------------------------------------";
walther@59847
    17
"-------- fun eval_occurs_in -------------------------------------------------------------------";
walther@59847
    18
"-------- fun eval_argument_of -----------------------------------------------------------------";
walther@59847
    19
"-------- fun eval_sameFunId -------------------------------------------------------------------";
walther@59847
    20
"-------- fun eval_filter_sameFunId ------------------------------------------------------------";
walther@59847
    21
"-------- fun eval_boollist2sum ----------------------------------------------------------------";
walther@60317
    22
"-------- REBUILD fun eval_binop FOR Isabelle's NUMERALS ---------------------------------------";
walther@59847
    23
"-------- fun matchsub -------------------------------------------------------------------------";
walther@59847
    24
"-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
walther@59633
    25
"-----------------------------------------------------------------------------------------------";
walther@59633
    26
"-----------------------------------------------------------------------------------------------";
walther@59633
    27
"-----------------------------------------------------------------------------------------------";
walther@59633
    28
walther@59633
    29
walther@60322
    30
"-------- fun eval_is_atom ---------------------------------------------------------------------";
walther@60322
    31
"-------- fun eval_is_atom ---------------------------------------------------------------------";
walther@60322
    32
"-------- fun eval_is_atom ---------------------------------------------------------------------";
walther@60322
    33
if is_atom   @{term  0} then () else error "is_atom 0 CHANGED";
walther@60322
    34
val eval_t = @{term "0 is_atom"};
walther@60322
    35
case Prog_Expr.eval_is_atom "#is_atom_" "Prog_Expr.is_atom" eval_t () of
walther@60322
    36
  SOME ("#is_atom_0_", _) => ()
walther@60322
    37
| _ => error "eval_is_atom 0 CHANGED";
walther@60322
    38
walther@60322
    39
if is_atom   @{term  1} then () else error "is_atom 1 CHANGED";
walther@60322
    40
val eval_t = @{term "1 is_atom"};
walther@60322
    41
case Prog_Expr.eval_is_atom "#is_atom_" "Prog_Expr.is_atom" eval_t () of
walther@60322
    42
  SOME ("#is_atom_1_", _) => ()
walther@60322
    43
| _ => error "eval_is_atom 1 CHANGED";
walther@60322
    44
walther@60322
    45
if is_atom   @{term  123} then () else error "is_atom 123 CHANGED";
walther@60322
    46
val eval_t = @{term "123 is_atom"};
walther@60322
    47
case Prog_Expr.eval_is_atom "#is_atom_" "Prog_Expr.is_atom" eval_t () of
walther@60322
    48
  SOME ("#is_atom_123_", _) => ()
walther@60322
    49
| _ => error "eval_is_atom 123 CHANGED";
walther@60322
    50
walther@60322
    51
if is_atom   @{term  abc} then () else error "is_atom abc CHANGED";
walther@60322
    52
val eval_t = @{term "abc is_atom"};
walther@60322
    53
case Prog_Expr.eval_is_atom "#is_atom_" "Prog_Expr.is_atom" eval_t () of
walther@60322
    54
  SOME ("#is_atom_abc_", _) => ()
walther@60322
    55
| _ => error "eval_is_atom abc CHANGED";
walther@60322
    56
walther@60322
    57
walther@60318
    58
"-------- fun eval_is_even ---------------------------------------------------------------------";
walther@60318
    59
"-------- fun eval_is_even ---------------------------------------------------------------------";
walther@60318
    60
"-------- fun eval_is_even ---------------------------------------------------------------------";
walther@60318
    61
val t = TermC.str2term "2 is_even";
walther@60318
    62
           eval_is_even "aaa" "Prog_Expr.is_even" t "ccc";
walther@60318
    63
"~~~~~ fun eval_is_even , args:"; val ((thmid:string), "Prog_Expr.is_even", (t as (Const _ $ arg)), _) =
walther@60318
    64
  ("aaa", "Prog_Expr.is_even", t, "ccc");
walther@60318
    65
    (*if*) TermC.is_num arg (*then*);
walther@60318
    66
        val i = arg |> HOLogic.dest_number |> snd;
walther@60318
    67
	      (*if*) even i (*then*);
walther@60318
    68
val SOME ("aaa1_", t') =
walther@60318
    69
    SOME (TermC.mk_thmid thmid (string_of_int n) "", 
walther@60318
    70
				  HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})));
walther@60318
    71
if UnparseC.term t' = "(2 is_even) = True" then () else error "(2 is_even) = True  CHANGED";
walther@60318
    72
walther@60318
    73
walther@60318
    74
val t = TermC.str2term "3 is_even";
walther@60318
    75
case eval_is_even "aaa" "Prog_Expr.is_even" t "ccc" of
walther@60318
    76
  SOME (str, t') => 
walther@60318
    77
    if str = "aaa_" andalso UnparseC.term t' = "(3 is_even) = False" then ()
walther@60318
    78
    else error "eval_is_even (3 is_even) CHANGED 1"
walther@60318
    79
| NONE => error "eval_is_even (3 is_even) CHANGED 2";
walther@60318
    80
walther@60318
    81
val t = TermC.str2term "a ::real";
walther@60318
    82
val NONE =
walther@60318
    83
           eval_is_even "aaa" "Prog_Expr.is_even" t "ccc";
walther@60318
    84
case eval_is_even "aaa" "Prog_Expr.is_even" t "ccc" of
walther@60318
    85
  SOME _ => error "eval_is_even (a is_even) CHANGED"
walther@60318
    86
| NONE => ();
walther@60318
    87
walther@60318
    88
walther@60318
    89
"-------- fun eval_const -----------------------------------------------------------------------";
walther@60318
    90
"-------- fun eval_const -----------------------------------------------------------------------";
walther@60318
    91
"-------- fun eval_const -----------------------------------------------------------------------";
walther@60318
    92
val t = (Thm.term_of o the o (TermC.parse @{theory Test})) "2 is_const";
walther@60318
    93
case rewrite_set_ @{theory Test} false tval_rls t of
walther@60336
    94
  SOME (Const (\<^const_name>\<open>True\<close>, _), []) => ()
walther@60318
    95
| _ => error "2 is_const CHANGED";
walther@60318
    96
walther@60318
    97
val t = TermC.str2term "2 * x is_const";
walther@60318
    98
val SOME (str, t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
walther@60318
    99
if UnparseC.term t' = "(2 * x is_const) = False" then ()
walther@60318
   100
else error "(2 * x is_const) = False CHANGED";
walther@60318
   101
walther@60318
   102
val t = TermC.str2term "- 2 is_const";
walther@60318
   103
val SOME (str, t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
walther@60318
   104
if UnparseC.term t' = "(- 2 is_const) = True" then ()
walther@60318
   105
else error "(- 2 is_const) = False CHANGED";
walther@60318
   106
walther@60318
   107
val t = TermC.str2term "- 1 is_const";
walther@60318
   108
val SOME (str, t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
walther@60318
   109
if UnparseC.term t' = "(- 1 is_const) = True" then ()
walther@60318
   110
else error "(- 1 is_const) = False CHANGED";
walther@60318
   111
walther@60318
   112
val t = TermC.str2term "0 is_const";
walther@60318
   113
val SOME (str, t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
walther@60318
   114
if UnparseC.term t' = "(0 is_const) = True" then ()
walther@60318
   115
else error "(0 is_const) = False CHANGED";
walther@60318
   116
walther@60318
   117
val t = TermC.str2term "AA is_const";
walther@60318
   118
val SOME (str, t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
walther@60318
   119
if UnparseC.term t' = "(AA is_const) = False" then ()
walther@60318
   120
else error "(0 is_const) = False CHANGED";
walther@60318
   121
walther@60318
   122
walther@60317
   123
"-------- fun eval_cancel ----------------------------------------------------------------------";
walther@60317
   124
"-------- fun eval_cancel ----------------------------------------------------------------------";
walther@60317
   125
"-------- fun eval_cancel ----------------------------------------------------------------------";
walther@60317
   126
val t = @{term  "3 / 2 :: real"};
walther@60317
   127
val NONE = eval_cancel "cancel_"  "Rings.divide_class.divide" t ""
walther@60317
   128
walther@60317
   129
val t = @{term  "6 / 4 :: real"};
walther@60317
   130
case eval_cancel "cancel_" "Rings.divide_class.divide" t "" of
walther@60317
   131
  SOME ("cancel_6_4", t') =>
walther@60317
   132
    if UnparseC.term t'  = "6 / 4 = 3 / 2" then ()
walther@60317
   133
    else error "eval_cancel  - 6 / 4 = - 3 / 2  CHANGED 1"
walther@60317
   134
| _ => error "eval_cancel  - 6 / 4 = - 3 / 2  CHANGED 2";
walther@60317
   135
walther@60317
   136
val t = @{term  "- 6 / 4 :: real"};
walther@60317
   137
case eval_cancel "cancel_"  "Rings.divide_class.divide" t "" of
walther@60317
   138
  SOME ("cancel_~6_4", t') =>
walther@60317
   139
    if UnparseC.term t'  = "- 6 / 4 = - 3 / 2" then ()
walther@60317
   140
    else error "eval_cancel  - 6 / 4 = - 3 / 2  CHANGED 1"
walther@60317
   141
| _ => error "eval_cancel  - 6 / 4 = - 3 / 2  CHANGED 2";
walther@60317
   142
walther@60317
   143
val t = @{term  "6 / - 4 :: real"};
walther@60317
   144
case eval_cancel "cancel_"  "Rings.divide_class.divide" t "" of
walther@60317
   145
  SOME ("cancel_6_~4", t') =>
walther@60317
   146
    if UnparseC.term t' = "6 / - 4 = - 3 / 2" then ()
walther@60317
   147
    else error "eval_cancel  6 / - 4 = - 3 / 2  CHANGED 1"
walther@60317
   148
| _ => error "eval_cancel  6 / - 4 = - 3 / 2  CHANGED 2";
walther@60317
   149
walther@60317
   150
val t = @{term  "- 6 /- 4 :: real"};
walther@60317
   151
case eval_cancel "cancel_"  "Rings.divide_class.divide" t "" of
walther@60317
   152
  SOME ("cancel_~6_~4", t') =>
walther@60317
   153
    if UnparseC.term t' = "- 6 / - 4 = 3 / 2" then ()
walther@60317
   154
    else error "eval_cancel  - 6 / - 4 = 3 / 2  CHANGED 1"
walther@60317
   155
| _ => error "eval_cancel  - 6 / - 4 = 3 / 2  CHANGED 2";
walther@60317
   156
walther@60317
   157
val t = @{term  "- (6 / 4) :: real"};
walther@60317
   158
val NONE = eval_cancel "adhoc_thm_cancel"  "Rings.divide_class.divide" t "";
walther@60317
   159
walther@60317
   160
walther@60317
   161
"-------- fun eval_equ -------------------------------------------------------------------------";
walther@60317
   162
"-------- fun eval_equ -------------------------------------------------------------------------";
walther@60317
   163
"-------- fun eval_equ -------------------------------------------------------------------------";
walther@60317
   164
eval_equ: string -> string -> term -> 'a -> (string * term) option;
walther@60317
   165
walther@60317
   166
case eval_equ "#less_" "Orderings.ord_class.less" @{term "1 < (2::real)"} "" of
walther@60317
   167
SOME
walther@60317
   168
    ("#less_1_2",
walther@60336
   169
     Const (\<^const_name>\<open>Trueprop\<close>, _) $
walther@60336
   170
       (Const (\<^const_name>\<open>HOL.eq\<close>, _) $
walther@60336
   171
         (Const (\<^const_name>\<open>ord_class.less\<close>, _) $ Const (\<^const_name>\<open>one_class.one\<close>, _) $
walther@60336
   172
           (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) $
walther@60336
   173
         Const (\<^const_name>\<open>True\<close>, _))) => ()
walther@60317
   174
| _ => error "eval_equ   1 < 2   CHANGED";
walther@60317
   175
walther@60317
   176
case eval_equ "#less_" "Orderings.ord_class.less" @{term "1 < (1::real)"} "" of
walther@60317
   177
SOME
walther@60317
   178
    ("#less_1_1",
walther@60336
   179
     Const (\<^const_name>\<open>Trueprop\<close>, _) $
walther@60336
   180
       (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ (Const (\<^const_name>\<open>ord_class.less\<close>, _) $ Const (\<^const_name>\<open>one_class.one\<close>, _) $ Const (\<^const_name>\<open>one_class.one\<close>, _)) $
walther@60336
   181
         Const (\<^const_name>\<open>False\<close>, _))) => ()
walther@60317
   182
| _ => error "eval_equ   1 < 1   CHANGED";
walther@60317
   183
walther@60317
   184
walther@59841
   185
"-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------";
walther@59841
   186
"-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------";
walther@59841
   187
"-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------";
walther@59841
   188
val thy = @{theory}
walther@59841
   189
walther@60230
   190
val t = TermC.str2term "x = 0";
wenzelm@60309
   191
val NONE(*= indetermined*) = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t thy;
walther@59841
   192
walther@60230
   193
val t = TermC.str2term "(x + 1) = (x + 1)";
walther@59841
   194
val (Const _(*op0,t0*) $ t1 $ t2 ) = t
wenzelm@60309
   195
val SOME ("equal_(x + 1)_(x + 1)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t thy;
walther@59868
   196
if UnparseC.term t' = "(x + 1 = x + 1) = True" then () else error "(x + 1) = (x + 1) CHANGED";
walther@59841
   197
walther@60230
   198
val t as Const _ $ v $ c = TermC.str2term "1 = 0";
walther@59841
   199
val false = variable_constant_pair (v, c);
wenzelm@60309
   200
val SOME ("equal_(1)_(0)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t thy;
walther@59868
   201
if UnparseC.term t' = "(1 = 0) = False" then () else error "1 = 0 CHANGED";
walther@59841
   202
walther@60230
   203
val t = TermC.str2term "0 = 0";
wenzelm@60309
   204
val SOME ("equal_(0)_(0)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t thy;
walther@59868
   205
if UnparseC.term t' = "(0 = 0) = True" then () else error "0 = 0 CHANGED";
walther@59847
   206
walther@59847
   207
walther@59847
   208
"-------- occurs_in ----------------------------------------------------------------------------";
walther@59847
   209
"-------- occurs_in ----------------------------------------------------------------------------";
walther@59847
   210
"-------- occurs_in ----------------------------------------------------------------------------";
walther@60317
   211
val t = @{term "x::real"};
walther@59847
   212
if occurs_in t t then "OK" else error "occurs_in x x -> f ..changed";
walther@59847
   213
walther@60230
   214
val t = TermC.str2term "x occurs_in x";
walther@60278
   215
val SOME (str, t') = eval_occurs_in 0 "Prog_Expr.occurs_in" t 0;
walther@59868
   216
if UnparseC.term t' = "x occurs_in x = True" then ()
walther@59847
   217
else error "x occurs_in x = True ..changed";
walther@59847
   218
walther@59847
   219
"------- some_occur_in";
walther@60317
   220
if some_occur_in [@{term "c::real"}, @{term "c_2::real"}] @{term "a + b + c::real"} then ()
walther@60317
   221
else error "";
walther@60317
   222
walther@60317
   223
val t = @{term "some_of [c, c_2, c_3, c_4] occur_in -1 * q_0 * L \<up> 2 / 2 + L * c + c_2"};
walther@60317
   224
val SOME (str, t') = eval_some_occur_in 0 "Prog_Expr.some_occur_in" t 0;
walther@60317
   225
if UnparseC.term t' =
walther@60317
   226
   "some_of [c, c_2, c_3,\n         c_4] occur_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2 =\nTrue" then ()
walther@60317
   227
else error "atools.sml: some_occur_in true";
walther@60317
   228
walther@60317
   229
val t = @{term "some_of [c_3, c_4] occur_in -1 * q_0 * L \<up> 2 / 2 + L * c + c_2"};
walther@60278
   230
val SOME (str,t') = eval_some_occur_in 0 "Prog_Expr.some_occur_in" t 0;
walther@59868
   231
if UnparseC.term t' =
walther@60317
   232
  "some_of [c_3, c_4] occur_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2 = False" then ()
walther@59847
   233
else error "atools.sml: some_occur_in false";
walther@59847
   234
walther@59847
   235
walther@59847
   236
"-------- fun eval_occurs_in -------------------------------------------------------------------";
walther@59847
   237
"-------- fun eval_occurs_in -------------------------------------------------------------------";
walther@59847
   238
"-------- fun eval_occurs_in -------------------------------------------------------------------";
walther@60230
   239
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   240
val t = (Thm.term_of o the o (TermC.parse thy)) "1";
walther@59847
   241
if occurs_in v t then error "factor_right_deg (1) x ..changed" else ();
walther@59847
   242
walther@60230
   243
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   244
val t = (Thm.term_of o the o (TermC.parse thy)) "1";
walther@59847
   245
if occurs_in v t then error "factor_right_deg (1) AA ..changed" else ();
walther@59847
   246
walther@59847
   247
(*----------*)
walther@60230
   248
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   249
val t = (Thm.term_of o the o (TermC.parse thy)) "a*b+c";
walther@59847
   250
if occurs_in v t then error "factor_right_deg (a*b+c) x ..changed" else ();
walther@59847
   251
walther@60230
   252
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   253
val t = (Thm.term_of o the o (TermC.parse thy)) "a*b+c";
walther@59847
   254
if occurs_in v t then error "factor_right_deg (a*b+c) AA ..changed" else ();
walther@59847
   255
walther@59847
   256
(*----------*)
walther@60230
   257
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   258
val t = (Thm.term_of o the o (TermC.parse thy)) "a*x+c";
walther@59847
   259
if occurs_in v t then () else error "factor_right_deg (a*x+c) x ..changed";
walther@59847
   260
walther@60230
   261
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   262
val t = (Thm.term_of o the o (TermC.parse thy)) "a*AA+c";
walther@59847
   263
if occurs_in v t then () else error "factor_right_deg (a*AA+c) AA ..changed";
walther@59847
   264
walther@59847
   265
(*----------*)
walther@60230
   266
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60242
   267
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x \<up> 7";
walther@60242
   268
if occurs_in v t then () else error "factor_right_deg (a*b+c)*x \<up> 7) x ..changed";
walther@59847
   269
walther@60230
   270
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60242
   271
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA \<up> 7";
walther@60242
   272
if occurs_in v t then () else error "factor_right_deg (a*b+c)*AA \<up> 7) AA ..changed";
walther@59847
   273
walther@59847
   274
(*----------*)
walther@60230
   275
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60242
   276
val t = (Thm.term_of o the o (TermC.parse thy)) "x \<up> 7";
walther@60242
   277
if occurs_in v t then () else error "factor_right_deg (x \<up> 7) x ..changed";
walther@59847
   278
walther@60230
   279
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60242
   280
val t = (Thm.term_of o the o (TermC.parse thy)) "AA \<up> 7";
walther@60242
   281
if occurs_in v t then () else error "factor_right_deg (AA \<up> 7) AA ..changed";
walther@59847
   282
walther@59847
   283
(*----------*)
walther@60230
   284
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   285
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x";
walther@59847
   286
if occurs_in v t then () else error "factor_right_deg ((a*b+c)*x) x ..changed";
walther@59847
   287
walther@60230
   288
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   289
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA";
walther@59847
   290
if occurs_in v t then () else error "factor_right_deg ((a*b+c)*AA) AA ..changed";
walther@59847
   291
walther@59847
   292
(*----------*)
walther@60230
   293
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   294
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+x)*x";
walther@59847
   295
if occurs_in v t then () else error "factor_right_deg ((a*b+x)*x) x ..changed";
walther@59847
   296
walther@60230
   297
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   298
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+AA)*AA";
walther@59847
   299
if occurs_in v t then () else error "factor_right_deg ((a*b+AA)*AA) AA ..changed";
walther@59847
   300
walther@59847
   301
(*----------*)
walther@60230
   302
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   303
val t = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@59847
   304
if occurs_in v t then () else error "factor_right_deg (x) x ..changed";
walther@59847
   305
walther@60230
   306
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   307
val t = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@59847
   308
if occurs_in v t then () else error "factor_right_deg (AA) AA ..changed";
walther@59847
   309
walther@59847
   310
(*----------*)
walther@60230
   311
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   312
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*x";
walther@59847
   313
if occurs_in v t then () else error "factor_right_deg (ab - (a*b)*x) x ..changed";
walther@59847
   314
walther@60230
   315
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   316
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*AA";
walther@59847
   317
if occurs_in v t then () else error "factor_right_deg (ab - (a*b)*AA) AA ..changed";
walther@59847
   318
walther@59847
   319
walther@59847
   320
"---------fun eval_argument_of -----------------------------------------------------------------";
walther@59847
   321
"---------fun eval_argument_of -----------------------------------------------------------------";
walther@59847
   322
"---------fun eval_argument_of -----------------------------------------------------------------";
walther@60230
   323
val t = TermC.str2term "argument_in (M_b x)";
walther@60278
   324
val SOME (str, t') = eval_argument_in "0" "Prog_Expr.argument_in" t 0;
walther@59868
   325
if UnparseC.term t' = "(argument_in M_b x) = x" then ()
walther@59847
   326
else error "atools.sml:(argument_in M_b x) = x  ???";
walther@59847
   327
walther@59847
   328
walther@59847
   329
"---------fun eval_sameFunId -------------------------------------------------------------------";
walther@59847
   330
"---------fun eval_sameFunId -------------------------------------------------------------------";
walther@59847
   331
"---------fun eval_sameFunId -------------------------------------------------------------------";
walther@60317
   332
val t = @{term "M_b L"}; TermC.atomty t;
walther@60317
   333
val t as f1 $ _ = @{term "M_b L"};
walther@60336
   334
val t as Const (\<^const_name>\<open>HOL.eq\<close>, _) $ (f2 $ _) $ _ = @{term "M_b x = c + L*x"};
walther@59847
   335
f1 = f2 (*true*);
walther@60336
   336
val (p as Const (\<^const_name>\<open>sameFunId\<close>, _) $ 
walther@59847
   337
			(f1 $ _) $ 
wenzelm@60309
   338
			(Const (\<^const_name>\<open>HOL.eq\<close>, _) $ (f2 $ _) $ _)) = 
walther@60317
   339
    @{term "sameFunId (M_b L) (M_b x = c + L*x)"};
walther@59847
   340
f1 = f2 (*true*);
walther@59847
   341
eval_sameFunId "" "Prog_Expr.sameFunId" 
walther@60317
   342
		 (@{term "sameFunId (M_b L) (M_b x = c + L*x)"})""(*true*);
walther@59847
   343
eval_sameFunId "" "Prog_Expr.sameFunId" 
walther@60317
   344
		 (@{term  "sameFunId (M_b L) ( y' x = c + L*x)"})""(*false*);
walther@59847
   345
eval_sameFunId "" "Prog_Expr.sameFunId" 
walther@60317
   346
		 (@{term  "sameFunId (M_b L) (  y x = c + L*x)"})""(*false*);
walther@59847
   347
eval_sameFunId "" "Prog_Expr.sameFunId" 
walther@60317
   348
		 (@{term  "sameFunId (  y L) (M_b x = c + L*x)"})""(*false*);
walther@59847
   349
eval_sameFunId "" "Prog_Expr.sameFunId" 
walther@60317
   350
		 (@{term  "sameFunId (  y L) (  y x = c + L*x)"})""(*true*);
walther@59847
   351
walther@59847
   352
walther@59847
   353
"---------fun eval_filter_sameFunId ------------------------------------------------------------";
walther@59847
   354
"---------fun eval_filter_sameFunId ------------------------------------------------------------";
walther@59847
   355
"---------fun eval_filter_sameFunId ------------------------------------------------------------";
walther@60317
   356
val flhs as (fid $ _) = @{term "y' L"};
walther@60317
   357
val fs = @{term "[M_b x = c + L*x, y' x = c + L*x, y x = c + L*x]"};
walther@60336
   358
val (p as Const (\<^const_name>\<open>filter_sameFunId\<close>,_) $ (fid $ _) $ fs) = 
walther@60317
   359
    @{term "filter_sameFunId (y' L) [M_b x = c + L*x, y' x = c + L*x, y x = c + L*x]"};
walther@60278
   360
val SOME (str, es) = eval_filter_sameFunId "" "Prog_Expr.filter_sameFunId" p "";
walther@59868
   361
if UnparseC.term es = "(filter_sameFunId y' L [M_b x = c + L * x, y' x = c + L * x,\n                        y x = c + L * x]) =\n[y' x = c + L * x]" then ()
walther@59847
   362
else error "atools.slm diff.behav. in filter_sameFunId";
walther@59847
   363
walther@59847
   364
walther@59847
   365
"---------fun eval_boollist2sum ----------------------------------------------------------------";
walther@59847
   366
"---------fun eval_boollist2sum ----------------------------------------------------------------";
walther@59847
   367
"---------fun eval_boollist2sum ----------------------------------------------------------------";
walther@60336
   368
fun lhs (Const (\<^const_name>\<open>HOL.eq\<close>,_) $ l $ _) = l
walther@59868
   369
  | lhs t = error("lhs called with (" ^ UnparseC.term t ^ ")");
walther@60242
   370
"----------- \<up> redefined due to overwritten identifier -----------";
walther@60317
   371
val u_ = @{term "[]"};
walther@60317
   372
val u_ = @{term "[b1 = k - 2*q]"};
walther@60317
   373
val u_ = @{term "[b1 = k - 2*q, b2 = k - 2*q, b3 = k - 2*q, b4 = k - 2*q]"};
walther@59847
   374
val ut_ = isalist2list u_;
walther@59847
   375
val sum_ = map lhs ut_;
walther@59847
   376
val t = list2sum sum_;
walther@59868
   377
UnparseC.term t;
walther@59847
   378
walther@60317
   379
val t = @{term "boollist2sum [b1 = k - 2*(q::real), b2 = k - 2*q, b3 = k - 2*q, b4 = k - 2*q]"};
walther@60317
   380
case t of
walther@60336
   381
Const (\<^const_name>\<open>boollist2sum\<close>, _) $
walther@60336
   382
     (Const (\<^const_name>\<open>Cons\<close>, _) $
walther@60336
   383
       (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Free ("b1", _) $ _ ) $
walther@60336
   384
       (Const (\<^const_name>\<open>Cons\<close>, _) $
walther@60336
   385
         (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Free ("b2", _) $ _ ) $
walther@60336
   386
         (Const (\<^const_name>\<open>Cons\<close>, _) $
walther@60336
   387
           (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Free ("b3", _) $ _ ) $
walther@60336
   388
           (Const (\<^const_name>\<open>Cons\<close>, _) $
walther@60336
   389
             (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Free ("b4", _) $ _ ) $
walther@60336
   390
             Const (\<^const_name>\<open>Nil\<close>, _))))) => ()
walther@60317
   391
| _ => error "boollist2sum CHANGED";
walther@59847
   392
val SOME (str, pred) = eval_boollist2sum "" "Prog_Expr.boollist2sum" t "";
walther@59868
   393
if UnparseC.term pred = "boollist2sum\n [b1 = k - 2 * q, b2 = k - 2 * q, b3 = k - 2 * q, b4 = k - 2 * q] =\nb1 + b2 + b3 + b4" then () 
walther@59847
   394
else error "atools.sml diff.behav. in eval_boollist2sum";
walther@59847
   395
walther@60330
   396
Rewrite.trace_on := false; (*true false*)
walther@59852
   397
val srls_ = Rule_Set.append_rules "srls_..Berechnung-erstSymbolisch" Rule_Set.empty 
walther@59878
   398
		      [Eval ("Prog_Expr.boollist2sum", eval_boollist2sum "")];
walther@60317
   399
val t = @{term "boollist2sum [b1 = k - 2*(q::real), b2 = k - 2*q, b3 = k - 2*q, b4 = k - 2*q]"};
walther@60317
   400
case rewrite_set_ @{theory} false srls_ t of SOME _ => ()
walther@59847
   401
| _ => error "atools.sml diff.rewrite boollist2sum";
walther@60330
   402
Rewrite.trace_on := false; (*true false*)
walther@59847
   403
walther@59847
   404
walther@60317
   405
"-------- REBUILD fun eval_binop FOR Isabelle's NUMERALS ---------------------------------------";
walther@60317
   406
"-------- REBUILD fun eval_binop FOR Isabelle's NUMERALS ---------------------------------------";
walther@60317
   407
"-------- REBUILD fun eval_binop FOR Isabelle's NUMERALS ---------------------------------------";
walther@59847
   408
val (op_, ef) = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "TIMES"));
walther@60230
   409
val t = (Thm.term_of o the o (TermC.parse thy)) "2 * 3";
walther@59847
   410
(*val SOME (thmid,t') = *)get_pair thy op_ ef t;
walther@59847
   411
;
walther@59847
   412
"~~~~~ fun get_pair, args:"; val (thy, op_, ef, (t as (Const (op0,_) $ t1 $ t2))) =
walther@59847
   413
  (thy, op_, ef, t);
walther@60317
   414
op_ = op0 = true;val (op_, ef) = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "TIMES"));
walther@60317
   415
val t = (Thm.term_of o the o (TermC.parse thy)) "2 * 3";
walther@60317
   416
walther@60317
   417
           ef op_ t thy;
walther@60317
   418
"~~~~~ fun eval_binop , args:"; val ((thmid : string), (op_: string), 
walther@60317
   419
      (t as (Const (op0, _) $ t1 $ t2)), _) =
walther@60317
   420
  ("#mult_", op_, t, thy);                                                (* binary . n1.n2 *)
walther@60317
   421
    (*if*) TermC.is_num t1 andalso TermC.is_num t2 (*then*);
walther@60317
   422
        val res = Eval.calcul op0 (t1, t2);
walther@60317
   423
        val prop = HOLogic.Trueprop $ (HOLogic.mk_eq (t, res));
walther@59868
   424
val SOME (thmid, tm) = SOME ("#: " ^ UnparseC.term prop, prop)
walther@59847
   425
;
walther@59868
   426
if thmid = "#: 2 * 3 = 6" andalso UnparseC.term prop = "2 * 3 = 6" then ()
walther@59847
   427
else error "eval_binop changed"
walther@59847
   428
;
walther@59847
   429
val SOME (thmid, tm) = eval_binop "#mult_"  op_ t thy;
walther@59868
   430
if thmid = "#: 2 * 3 = 6" andalso UnparseC.term prop = "2 * 3 = 6" then ()
walther@59847
   431
else error "eval_binop changed 2"
walther@59847
   432
walther@59847
   433
walther@59847
   434
"-------- fun matchsub -------------------------------------------------------------------------";
walther@59847
   435
"-------- fun matchsub -------------------------------------------------------------------------";
walther@59847
   436
"-------- fun matchsub -------------------------------------------------------------------------";
walther@60230
   437
if matchsub thy (TermC.str2term "(a + (b + c))") (TermC.str2term "?x + (?y + ?z)")
walther@59847
   438
then () else error "tools.sml matchsub a + (b + c)";
walther@59847
   439
walther@60230
   440
if matchsub thy (TermC.str2term "(a + (b + c)) + d") (TermC.str2term "?x + (?y + ?z)")
walther@59847
   441
then () else error "tools.sml matchsub (a + (b + c)) + d";
walther@59847
   442
walther@59847
   443
walther@59847
   444
"-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
walther@59847
   445
"-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
walther@59847
   446
"-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
walther@59847
   447
"see: --------- search for Or_to_List ---";
walther@60336
   448
case or2list @{term True} of Const (\<^const_name>\<open>UniversalList\<close>, _) => ()
walther@59847
   449
  | _ => error "TermC.UniversalList changed 1";
wenzelm@60309
   450
case or2list @{term False} of Const (\<^const_name>\<open>Nil\<close>, _) => ()
walther@59847
   451
  | _ => error "TermC.UniversalList changed 2";
walther@60230
   452
val t =  (TermC.str2term "x=3");
walther@59868
   453
if UnparseC.term (or2list t) = "[x = 3]" then ()
walther@59847
   454
else error "or2list changed";
walther@60230
   455
val t =  (TermC.str2term "x=3 | x=-3 | x=0");
walther@60317
   456
if UnparseC.term (or2list t) = "[x = 3, x = - 3, x = 0]" then ()
walther@59847
   457
else error "HOL.eq ? HOL.disj ? changed";