test/Tools/isac/ProgLang/listC.sml
author wenzelm
Sat, 17 Apr 2021 21:10:27 +0200
changeset 60203 eb278178c278
parent 60121 e6cd6dd07d7a
child 60230 0ca0f9363ad3
permissions -rw-r--r--
more direct use of Thm.prop_of;
     1 (* Title: tests for ListC
     2    Author: Walther Neuper 030501
     3    (c) copyright due to lincense terms.
     4 *)
     5 
     6 "-----------------------------------------------------------------------------";
     7 "-----------------------------------------------------------------------------";
     8 "table of contents -----------------------------------------------------------";
     9 "-----------------------------------------------------------------------------";
    10 "----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
    11 "--------------------- NTH ---------------------------------------------------";
    12 "--------------------- Length ------------------------------------------------";
    13 "--------------------- tl ----------------------------------------------------";
    14 "-----------------------------------------------------------------------------";
    15 "-----------------------------------------------------------------------------";
    16 
    17 "----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
    18 "----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
    19 "----------- check 'type xlist' {||1, 2, 3||} --------------------------------";
    20 (* ML representation *)
    21 val t1 = @{term "{|| ||}"};
    22 val t2 = @{term "{||1,2,3||}"};
    23 
    24 (* pretty printing *)
    25 if Print_Mode.setmp [] 
    26   (Syntax.string_of_term (Config.put show_markup false (Proof_Context.init_global @{theory}))) t1
    27   = "{|| ||}"
    28 then () else error "CHANGED pretty printing of '{|| ||}'";
    29 
    30 if Print_Mode.setmp [] 
    31   (Syntax.string_of_term (Config.put show_markup false (Proof_Context.init_global @{theory}))) t2
    32   = "{|| 1::'a, 2::'a, 3::'a ||}"
    33 then () else error "CHANGED pretty printing of '{||1,2,3||}'"
    34 
    35 (* parsing *)
    36 Syntax.read_term_global @{theory} "{|| ||}";
    37 Syntax.read_term_global @{theory} "{||1,2,3||}";
    38 
    39 "--------------------- NTH ---------------------------------------------------";
    40 "--------------------- NTH ---------------------------------------------------";
    41 "--------------------- NTH ---------------------------------------------------";
    42 val prog_expr = assoc_rls "prog_expr"
    43 
    44 val t = str2term "NTH 1 [a,b,c,d,e]";
    45 atomty t;
    46 val thm = (Thm.prop_of o ThmC.numerals_to_Free) @{thm NTH_NIL};
    47 atomty thm;
    48 val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false (ThmC.numerals_to_Free @{thm NTH_NIL}) t;
    49 if UnparseC.term t' = "a" then () 
    50 else error "NTH 1 [a,b,c,d,e] = a ..changed";
    51 
    52 val t = str2term "NTH 3 [a,b,c,d,e]";
    53 val Const ("ListC.NTH", _) $ Free ("3", _) $ (Const ("List.list.Cons", _) $ Free ("a", _) $
    54   (Const ("List.list.Cons", _) $ Free ("b", _) $ 
    55     (Const _ $ Free _ $ (Const _ $ Free _ $ (Const _ $ Free _ $ Const _))))) = t;
    56 atomty t;
    57 val thm = (Thm.prop_of o ThmC.numerals_to_Free) @{thm NTH_CONS};
    58 atomty thm;
    59 val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false (ThmC.numerals_to_Free @{thm NTH_CONS}) t;
    60 if UnparseC.term t' = "NTH (3 + -1) [b, c, d, e]" then () 
    61 else error "NTH 3 [a,b,c,d,e] = NTH (3 + - 1) [b, c, d, e] ..changed";
    62 
    63 (* now the argument "(3 + - 1)" etc needs to be evaluated in the assumption of NTH_CONS *)
    64 val t = str2term "NTH 3 [a,b,c,d,e]";
    65 atomty t;
    66 Rewrite.trace_on := false;
    67 val SOME (t', _) = rewrite_set_ thy false prog_expr t;
    68 Rewrite.trace_on := false;
    69 if UnparseC.term t' = "c" then () 
    70 else error "NTH 3 [a,b,c,d,e] = c ..changed";
    71 
    72 "--------------------- Length ------------------------------------------------";
    73 "--------------------- Length ------------------------------------------------";
    74 "--------------------- Length ------------------------------------------------";
    75 val prog_expr = assoc_rls "prog_expr"
    76 
    77 val thy = @{theory ListC};
    78 val t = str2term "Length [1, 1, 1]";
    79 val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
    80 UnparseC.term t = "1 + Length [1, 1]";
    81 val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
    82 UnparseC.term t = "1 + (1 + Length [1])";
    83 val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
    84 UnparseC.term t = "1 + (1 + (1 + Length []))";
    85 val NONE          = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
    86 val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_NIL} t;
    87 val NONE          = rewrite_ thy tless_true tval_rls false @{thm LENGTH_NIL} t;
    88 if UnparseC.term t = "1 + (1 + (1 + 0))" then () 
    89 else error "Length [1, 1, 1] = 1 + (1 + (1 + 0))  ..changed";
    90 
    91 val t = str2term "Length [1, 1, 1]";
    92 val SOME (t, asm) = rewrite_set_ thy false prog_expr t;
    93 if UnparseC.term t = "3" then ()
    94 else error "Length [1, 1, 1] = 3  ..prog_expr changed";
    95 
    96 val t = str2term "Length [1, 1, 1]";
    97 val t = eval_prog_expr thy prog_expr t;
    98 case t of Free ("3", _) => () 
    99 | _ => error "Length [1, 1, 1] = 3  ..eval_prog_expr changed";
   100