test/Tools/isac/ProgLang/listC.sml
author Walther Neuper <walther.neuper@jku.at>
Wed, 22 Apr 2020 11:06:48 +0200
changeset 59901 07a042166900
parent 59900 4e6fc3336336
child 60121 e6cd6dd07d7a
permissions -rw-r--r--
shift Unsynchronized.ref for tracing to respect.struct.
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;
walther@59871
    46
val thm = (#prop o Thm.rep_thm o ThmC.numerals_to_Free) @{thm NTH_NIL};
neuper@52148
    47
atomty thm;
walther@59871
    48
val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false (ThmC.numerals_to_Free @{thm NTH_NIL}) t;
walther@59868
    49
if UnparseC.term 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;
walther@59871
    57
val thm = (#prop o Thm.rep_thm o ThmC.numerals_to_Free) @{thm NTH_CONS};
neuper@42185
    58
atomty thm;
walther@59871
    59
val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false (ThmC.numerals_to_Free @{thm NTH_CONS}) t;
walther@59868
    60
if UnparseC.term 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@59901
    66
Rewrite.trace_on := false;
walther@59801
    67
val SOME (t', _) = rewrite_set_ thy false prog_expr t;
walther@59901
    68
Rewrite.trace_on := false;
walther@59868
    69
if UnparseC.term 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;
walther@59868
    80
UnparseC.term t = "1 + LENGTH [1, 1]";
neuper@52148
    81
val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
walther@59868
    82
UnparseC.term t = "1 + (1 + LENGTH [1])";
neuper@52148
    83
val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
walther@59868
    84
UnparseC.term 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;
walther@59868
    88
if UnparseC.term 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;
walther@59868
    93
if UnparseC.term 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