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@59234
|
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@59234
|
17 |
"----------- check 'type xlist' [||1, 2, 3||] --------------------------------";
|
wneuper@59234
|
18 |
"----------- check 'type xlist' [||1, 2, 3||] --------------------------------";
|
wneuper@59234
|
19 |
"----------- check 'type xlist' [||1, 2, 3||] --------------------------------";
|
wneuper@59234
|
20 |
(* ML representation *)
|
wneuper@59234
|
21 |
val t1 = @{term "[|| ||]"};
|
wneuper@59234
|
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@59234
|
27 |
= "[|| ||]"
|
wneuper@59234
|
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@59234
|
32 |
= "[||1::'a, 2::'a, 3::'a||]"
|
wneuper@59234
|
33 |
then () else error "CHANGED pretty printing of '[||1,2,3||]'"
|
wneuper@59234
|
34 |
|
wneuper@59234
|
35 |
(* parsing *)
|
wneuper@59234
|
36 |
Syntax.read_term_global @{theory} "[|| ||]";
|
wneuper@59234
|
37 |
Syntax.read_term_global @{theory} "[||1,2,3||]";
|
neuper@42185
|
38 |
|
neuper@52148
|
39 |
"--------------------- NTH ---------------------------------------------------";
|
neuper@52148
|
40 |
"--------------------- NTH ---------------------------------------------------";
|
neuper@52148
|
41 |
"--------------------- NTH ---------------------------------------------------";
|
neuper@52148
|
42 |
val list_rls = assoc_rls "list_rls"
|
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;
|
neuper@52148
|
48 |
val SOME (t', _) = rewrite_ thy dummy_ord list_rls 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;
|
neuper@52148
|
59 |
val SOME (t', _) = rewrite_ thy dummy_ord list_rls 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;
|
neuper@52148
|
66 |
trace_rewrite := true;
|
neuper@52148
|
67 |
val SOME (t', _) = rewrite_set_ thy false list_rls 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 ------------------------------------------------";
|
neuper@52148
|
75 |
val list_rls = assoc_rls "list_rls"
|
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]";
|
neuper@52148
|
92 |
val SOME (t, asm) = rewrite_set_ thy false list_rls t;
|
neuper@52148
|
93 |
if term2str t = "3" then ()
|
neuper@52148
|
94 |
else error "LENGTH [1, 1, 1] = 3 ..list_rls changed";
|
neuper@42185
|
95 |
|
neuper@52148
|
96 |
val t = str2term "LENGTH [1, 1, 1]";
|
neuper@52148
|
97 |
val t = eval_listexpr_ thy list_rls t;
|
neuper@52148
|
98 |
case t of Free ("3", _) => ()
|
neuper@52148
|
99 |
| _ => error "LENGTH [1, 1, 1] = 3 ..eval_listexpr_ changed";
|
neuper@42185
|
100 |
|