test/Tools/isac/ProgLang/listC.sml
author Walther Neuper <walther.neuper@jku.at>
Sun, 09 Feb 2020 16:55:41 +0100
changeset 59801 17d807bf28fb
parent 59718 bc4b000caa39
child 59861 65ec9f679c3f
permissions -rw-r--r--
cleanup TODO
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
"-----------------------------------------------------------------------------";
wneuper@59244
    10
"----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
neuper@52148
    11
"--------------------- NTH ---------------------------------------------------";
neuper@52148
    12
"--------------------- LENGTH ------------------------------------------------";
neuper@52148
    13
"--------------------- tl ----------------------------------------------------";
neuper@52148
    14
"-----------------------------------------------------------------------------";
neuper@52148
    15
"-----------------------------------------------------------------------------";
neuper@42185
    16
wneuper@59244
    17
"----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
wneuper@59244
    18
"----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
wneuper@59244
    19
"----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
wneuper@59234
    20
(* ML representation *)
wneuper@59244
    21
val t1 = @{term "{|| ||}"};
wneuper@59244
    22
val t2 = @{term "{||1,2,3||}"};
wneuper@59234
    23
wneuper@59234
    24
(* pretty printing *)
wneuper@59234
    25
if Print_Mode.setmp [] 
wneuper@59234
    26
  (Syntax.string_of_term (Config.put show_markup false (Proof_Context.init_global @{theory}))) t1
wneuper@59244
    27
  = "{|| ||}"
wneuper@59244
    28
then () else error "CHANGED pretty printing of '{|| ||}'";
wneuper@59234
    29
wneuper@59234
    30
if Print_Mode.setmp [] 
wneuper@59234
    31
  (Syntax.string_of_term (Config.put show_markup false (Proof_Context.init_global @{theory}))) t2
wneuper@59244
    32
  = "{|| 1::'a, 2::'a, 3::'a ||}"
wneuper@59244
    33
then () else error "CHANGED pretty printing of '{||1,2,3||}'"
wneuper@59234
    34
wneuper@59234
    35
(* parsing *)
wneuper@59244
    36
Syntax.read_term_global @{theory} "{|| ||}";
wneuper@59244
    37
Syntax.read_term_global @{theory} "{||1,2,3||}";
neuper@42185
    38
neuper@52148
    39
"--------------------- NTH ---------------------------------------------------";
neuper@52148
    40
"--------------------- NTH ---------------------------------------------------";
neuper@52148
    41
"--------------------- NTH ---------------------------------------------------";
walther@59801
    42
val prog_expr = assoc_rls "prog_expr"
neuper@52148
    43
neuper@52148
    44
val t = str2term "NTH 1 [a,b,c,d,e]";
neuper@52148
    45
atomty t;
wneuper@59188
    46
val thm = (#prop o Thm.rep_thm o num_str) @{thm NTH_NIL};
neuper@52148
    47
atomty thm;
walther@59801
    48
val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false (num_str @{thm NTH_NIL}) t;
neuper@52148
    49
if term2str t' = "a" then () 
neuper@52148
    50
else error "NTH 1 [a,b,c,d,e] = a ..changed";
neuper@52148
    51
neuper@52148
    52
val t = str2term "NTH 3 [a,b,c,d,e]";
neuper@52148
    53
val Const ("ListC.NTH", _) $ Free ("3", _) $ (Const ("List.list.Cons", _) $ Free ("a", _) $
neuper@52148
    54
  (Const ("List.list.Cons", _) $ Free ("b", _) $ 
neuper@52148
    55
    (Const _ $ Free _ $ (Const _ $ Free _ $ (Const _ $ Free _ $ Const _))))) = t;
neuper@42185
    56
atomty t;
wneuper@59188
    57
val thm = (#prop o Thm.rep_thm o num_str) @{thm NTH_CONS};
neuper@42185
    58
atomty thm;
walther@59801
    59
val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false (num_str @{thm NTH_CONS}) t;
neuper@52148
    60
if term2str t' = "NTH (3 + -1) [b, c, d, e]" then () 
neuper@52148
    61
else error "NTH 3 [a,b,c,d,e] = NTH (3 + - 1) [b, c, d, e] ..changed";
neuper@42185
    62
neuper@52148
    63
(* now the argument "(3 + - 1)" etc needs to be evaluated in the assumption of NTH_CONS *)
neuper@52148
    64
val t = str2term "NTH 3 [a,b,c,d,e]";
neuper@42185
    65
atomty t;
walther@59627
    66
trace_rewrite := false;
walther@59801
    67
val SOME (t', _) = rewrite_set_ thy false prog_expr t;
neuper@52148
    68
trace_rewrite := false;
neuper@52148
    69
if term2str t' = "c" then () 
neuper@52148
    70
else error "NTH 3 [a,b,c,d,e] = c ..changed";
neuper@42185
    71
neuper@52148
    72
"--------------------- LENGTH ------------------------------------------------";
neuper@52148
    73
"--------------------- LENGTH ------------------------------------------------";
neuper@52148
    74
"--------------------- LENGTH ------------------------------------------------";
walther@59801
    75
val prog_expr = assoc_rls "prog_expr"
neuper@42185
    76
neuper@52148
    77
val thy = @{theory ListC};
neuper@52148
    78
val t = str2term "LENGTH [1, 1, 1]";
neuper@52148
    79
val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
neuper@52148
    80
term2str t = "1 + LENGTH [1, 1]";
neuper@52148
    81
val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
neuper@52148
    82
term2str t = "1 + (1 + LENGTH [1])";
neuper@52148
    83
val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
neuper@52148
    84
term2str t = "1 + (1 + (1 + LENGTH []))";
neuper@52148
    85
val NONE          = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
neuper@52148
    86
val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_NIL} t;
neuper@52148
    87
val NONE          = rewrite_ thy tless_true tval_rls false @{thm LENGTH_NIL} t;
neuper@52148
    88
if term2str t = "1 + (1 + (1 + 0))" then () 
neuper@52148
    89
else error "LENGTH [1, 1, 1] = 1 + (1 + (1 + 0))  ..changed";
neuper@42185
    90
neuper@52148
    91
val t = str2term "LENGTH [1, 1, 1]";
walther@59801
    92
val SOME (t, asm) = rewrite_set_ thy false prog_expr t;
neuper@52148
    93
if term2str t = "3" then ()
walther@59801
    94
else error "LENGTH [1, 1, 1] = 3  ..prog_expr changed";
neuper@42185
    95
neuper@52148
    96
val t = str2term "LENGTH [1, 1, 1]";
walther@59801
    97
val t = eval_prog_expr thy prog_expr t;
neuper@52148
    98
case t of Free ("3", _) => () 
walther@59718
    99
| _ => error "LENGTH [1, 1, 1] = 3  ..eval_prog_expr changed";
neuper@42185
   100