test/Tools/isac/ProgLang/listC.sml
author wneuper <Walther.Neuper@jku.at>
Thu, 04 Aug 2022 12:48:37 +0200
changeset 60509 2e0b7ca391dc
parent 60500 59a3af532717
child 60543 9555ee96e046
permissions -rw-r--r--
polish naming in Rewrite_Order
neuper@42185
     1
(* Title: tests for ListC
neuper@42185
     2
   Author: Walther Neuper 030501
neuper@42185
     3
   (c) copyright due to lincense terms.
neuper@42185
     4
*)
neuper@42185
     5
neuper@52148
     6
"-----------------------------------------------------------------------------";
neuper@52148
     7
"-----------------------------------------------------------------------------";
neuper@52148
     8
"table of contents -----------------------------------------------------------";
neuper@52148
     9
"-----------------------------------------------------------------------------";
walther@60317
    10
"----------- correct list_erls -----------------------------------------------------------------";
wneuper@59244
    11
"----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
neuper@52148
    12
"--------------------- NTH ---------------------------------------------------";
walther@60121
    13
"--------------------- Length ------------------------------------------------";
neuper@52148
    14
"--------------------- tl ----------------------------------------------------";
neuper@52148
    15
"-----------------------------------------------------------------------------";
neuper@52148
    16
"-----------------------------------------------------------------------------";
neuper@42185
    17
walther@60317
    18
"----------- correct list_erls -----------------------------------------------------------------";
walther@60317
    19
"----------- correct list_erls -----------------------------------------------------------------";
walther@60317
    20
"----------- correct list_erls -----------------------------------------------------------------";
walther@60317
    21
wneuper@59244
    22
"----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
wneuper@59244
    23
"----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
wneuper@59244
    24
"----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
wneuper@59234
    25
(* ML representation *)
wneuper@59244
    26
val t1 = @{term "{|| ||}"};
wneuper@59244
    27
val t2 = @{term "{||1,2,3||}"};
wneuper@59234
    28
wneuper@59234
    29
(* pretty printing *)
wneuper@59234
    30
if Print_Mode.setmp [] 
wneuper@59234
    31
  (Syntax.string_of_term (Config.put show_markup false (Proof_Context.init_global @{theory}))) t1
wneuper@59244
    32
  = "{|| ||}"
wneuper@59244
    33
then () else error "CHANGED pretty printing of '{|| ||}'";
wneuper@59234
    34
wneuper@59234
    35
if Print_Mode.setmp [] 
wneuper@59234
    36
  (Syntax.string_of_term (Config.put show_markup false (Proof_Context.init_global @{theory}))) t2
wneuper@59244
    37
  = "{|| 1::'a, 2::'a, 3::'a ||}"
wneuper@59244
    38
then () else error "CHANGED pretty printing of '{||1,2,3||}'"
wneuper@59234
    39
wneuper@59234
    40
(* parsing *)
wneuper@59244
    41
Syntax.read_term_global @{theory} "{|| ||}";
wneuper@59244
    42
Syntax.read_term_global @{theory} "{||1,2,3||}";
neuper@42185
    43
neuper@52148
    44
"--------------------- NTH ---------------------------------------------------";
neuper@52148
    45
"--------------------- NTH ---------------------------------------------------";
neuper@52148
    46
"--------------------- NTH ---------------------------------------------------";
Walther@60500
    47
val ctxt = Proof_Context.init_global @{theory}
walther@59801
    48
val prog_expr = assoc_rls "prog_expr"
neuper@52148
    49
walther@60230
    50
val t = TermC.str2term "NTH 1 [a,b,c,d,e]";
walther@60230
    51
TermC.atomty t;
walther@60337
    52
val thm = Thm.prop_of @{thm NTH_NIL};
walther@60230
    53
TermC.atomty thm;
Walther@60509
    54
val SOME (t', _) = rewrite_ ctxt Rewrite_Ord.function_empty prog_expr false @{thm NTH_NIL} t;
walther@59868
    55
if UnparseC.term t' = "a" then () 
neuper@52148
    56
else error "NTH 1 [a,b,c,d,e] = a ..changed";
neuper@52148
    57
walther@60230
    58
val t = TermC.str2term "NTH 3 [a,b,c,d,e]";
walther@60317
    59
case TermC.str2term "NTH 3 [a,b,c,d,e]" of
walther@60336
    60
 Const (\<^const_name>\<open>NTH\<close>, _) $ (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit1\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _))) $
walther@60336
    61
     (Const (\<^const_name>\<open>Cons\<close>, _) $ Free ("a", _) $
walther@60336
    62
       (Const (\<^const_name>\<open>Cons\<close>, _) $ Free ("b", _) $
walther@60336
    63
         (Const (\<^const_name>\<open>Cons\<close>, _) $ Free ("c", _) $
walther@60336
    64
           (Const (\<^const_name>\<open>Cons\<close>, _) $ Free ("d", _) $
walther@60336
    65
             (Const (\<^const_name>\<open>Cons\<close>, _) $ Free ("e", _) $ Const (\<^const_name>\<open>Nil\<close>, _)))))) => ()
walther@60317
    66
| _ => error "ListC.NTH changed";
walther@60337
    67
val thm = Thm.prop_of @{thm NTH_CONS};
walther@60230
    68
TermC.atomty thm;
Walther@60509
    69
val SOME (t', _) = rewrite_ ctxt Rewrite_Ord.function_empty prog_expr false  @{thm NTH_CONS} t;
walther@60317
    70
if UnparseC.term t' = "NTH (3 + - 1) [b, c, d, e]" then () 
neuper@52148
    71
else error "NTH 3 [a,b,c,d,e] = NTH (3 + - 1) [b, c, d, e] ..changed";
neuper@42185
    72
neuper@52148
    73
(* now the argument "(3 + - 1)" etc needs to be evaluated in the assumption of NTH_CONS *)
walther@60230
    74
val t = TermC.str2term "NTH 3 [a,b,c,d,e]";
walther@60230
    75
TermC.atomty t;
Walther@60500
    76
Walther@60500
    77
val SOME (t', _) = rewrite_set_ ctxt false prog_expr t;
walther@59868
    78
if UnparseC.term t' = "c" then () 
neuper@52148
    79
else error "NTH 3 [a,b,c,d,e] = c ..changed";
neuper@42185
    80
walther@60121
    81
"--------------------- Length ------------------------------------------------";
walther@60121
    82
"--------------------- Length ------------------------------------------------";
walther@60121
    83
"--------------------- Length ------------------------------------------------";
walther@59801
    84
val prog_expr = assoc_rls "prog_expr"
neuper@42185
    85
neuper@52148
    86
val thy = @{theory ListC};
walther@60230
    87
val t = TermC.str2term "Length [1, 1, 1]";
Walther@60500
    88
val SOME (t, asm) = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_CONS} t;
walther@60121
    89
UnparseC.term t = "1 + Length [1, 1]";
Walther@60500
    90
val SOME (t, asm) = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_CONS} t;
walther@60121
    91
UnparseC.term t = "1 + (1 + Length [1])";
Walther@60500
    92
val SOME (t, asm) = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_CONS} t;
walther@60121
    93
UnparseC.term t = "1 + (1 + (1 + Length []))";
Walther@60500
    94
val NONE          = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_CONS} t;
Walther@60500
    95
val SOME (t, asm) = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_NIL} t;
Walther@60500
    96
val NONE          = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_NIL} t;
walther@59868
    97
if UnparseC.term t = "1 + (1 + (1 + 0))" then () 
walther@60121
    98
else error "Length [1, 1, 1] = 1 + (1 + (1 + 0))  ..changed";
neuper@42185
    99
walther@60230
   100
val t = TermC.str2term "Length [1, 1, 1]";
Walther@60500
   101
val SOME (t, asm) = rewrite_set_ ctxt false prog_expr t;
walther@59868
   102
if UnparseC.term t = "3" then ()
walther@60121
   103
else error "Length [1, 1, 1] = 3  ..prog_expr changed";
neuper@42185
   104
walther@60230
   105
val t = TermC.str2term "Length [1, 1, 1]";
Walther@60500
   106
val t = eval_prog_expr ctxt prog_expr t;
walther@60317
   107
case t of 
walther@60336
   108
  Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit1\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)) => () 
walther@60121
   109
| _ => error "Length [1, 1, 1] = 3  ..eval_prog_expr changed";
neuper@42185
   110