neuper@42185: (* Title: tests for ListC neuper@42185: Author: Walther Neuper 030501 neuper@42185: (c) copyright due to lincense terms. neuper@42185: *) neuper@42185: neuper@52148: "-----------------------------------------------------------------------------"; neuper@52148: "-----------------------------------------------------------------------------"; neuper@52148: "table of contents -----------------------------------------------------------"; neuper@52148: "-----------------------------------------------------------------------------"; wneuper@59244: "----------- check 'type xlist' {||1, 2, 3||} --------------------------------"; neuper@52148: "--------------------- NTH ---------------------------------------------------"; walther@60121: "--------------------- Length ------------------------------------------------"; neuper@52148: "--------------------- tl ----------------------------------------------------"; neuper@52148: "-----------------------------------------------------------------------------"; neuper@52148: "-----------------------------------------------------------------------------"; neuper@42185: wneuper@59244: "----------- check 'type xlist' {||1, 2, 3||} --------------------------------"; wneuper@59244: "----------- check 'type xlist' {||1, 2, 3||} --------------------------------"; wneuper@59244: "----------- check 'type xlist' {||1, 2, 3||} --------------------------------"; wneuper@59234: (* ML representation *) wneuper@59244: val t1 = @{term "{|| ||}"}; wneuper@59244: val t2 = @{term "{||1,2,3||}"}; wneuper@59234: wneuper@59234: (* pretty printing *) wneuper@59234: if Print_Mode.setmp [] wneuper@59234: (Syntax.string_of_term (Config.put show_markup false (Proof_Context.init_global @{theory}))) t1 wneuper@59244: = "{|| ||}" wneuper@59244: then () else error "CHANGED pretty printing of '{|| ||}'"; wneuper@59234: wneuper@59234: if Print_Mode.setmp [] wneuper@59234: (Syntax.string_of_term (Config.put show_markup false (Proof_Context.init_global @{theory}))) t2 wneuper@59244: = "{|| 1::'a, 2::'a, 3::'a ||}" wneuper@59244: then () else error "CHANGED pretty printing of '{||1,2,3||}'" wneuper@59234: wneuper@59234: (* parsing *) wneuper@59244: Syntax.read_term_global @{theory} "{|| ||}"; wneuper@59244: Syntax.read_term_global @{theory} "{||1,2,3||}"; neuper@42185: neuper@52148: "--------------------- NTH ---------------------------------------------------"; neuper@52148: "--------------------- NTH ---------------------------------------------------"; neuper@52148: "--------------------- NTH ---------------------------------------------------"; walther@59801: val prog_expr = assoc_rls "prog_expr" neuper@52148: neuper@52148: val t = str2term "NTH 1 [a,b,c,d,e]"; neuper@52148: atomty t; walther@59871: val thm = (#prop o Thm.rep_thm o ThmC.numerals_to_Free) @{thm NTH_NIL}; neuper@52148: atomty thm; walther@59871: val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false (ThmC.numerals_to_Free @{thm NTH_NIL}) t; walther@59868: if UnparseC.term t' = "a" then () neuper@52148: else error "NTH 1 [a,b,c,d,e] = a ..changed"; neuper@52148: neuper@52148: val t = str2term "NTH 3 [a,b,c,d,e]"; neuper@52148: val Const ("ListC.NTH", _) $ Free ("3", _) $ (Const ("List.list.Cons", _) $ Free ("a", _) $ neuper@52148: (Const ("List.list.Cons", _) $ Free ("b", _) $ neuper@52148: (Const _ $ Free _ $ (Const _ $ Free _ $ (Const _ $ Free _ $ Const _))))) = t; neuper@42185: atomty t; walther@59871: val thm = (#prop o Thm.rep_thm o ThmC.numerals_to_Free) @{thm NTH_CONS}; neuper@42185: atomty thm; walther@59871: val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false (ThmC.numerals_to_Free @{thm NTH_CONS}) t; walther@59868: if UnparseC.term t' = "NTH (3 + -1) [b, c, d, e]" then () neuper@52148: else error "NTH 3 [a,b,c,d,e] = NTH (3 + - 1) [b, c, d, e] ..changed"; neuper@42185: neuper@52148: (* now the argument "(3 + - 1)" etc needs to be evaluated in the assumption of NTH_CONS *) neuper@52148: val t = str2term "NTH 3 [a,b,c,d,e]"; neuper@42185: atomty t; walther@59901: Rewrite.trace_on := false; walther@59801: val SOME (t', _) = rewrite_set_ thy false prog_expr t; walther@59901: Rewrite.trace_on := false; walther@59868: if UnparseC.term t' = "c" then () neuper@52148: else error "NTH 3 [a,b,c,d,e] = c ..changed"; neuper@42185: walther@60121: "--------------------- Length ------------------------------------------------"; walther@60121: "--------------------- Length ------------------------------------------------"; walther@60121: "--------------------- Length ------------------------------------------------"; walther@59801: val prog_expr = assoc_rls "prog_expr" neuper@42185: neuper@52148: val thy = @{theory ListC}; walther@60121: val t = str2term "Length [1, 1, 1]"; neuper@52148: val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t; walther@60121: UnparseC.term t = "1 + Length [1, 1]"; neuper@52148: val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t; walther@60121: UnparseC.term t = "1 + (1 + Length [1])"; neuper@52148: val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t; walther@60121: UnparseC.term t = "1 + (1 + (1 + Length []))"; neuper@52148: val NONE = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t; neuper@52148: val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_NIL} t; neuper@52148: val NONE = rewrite_ thy tless_true tval_rls false @{thm LENGTH_NIL} t; walther@59868: if UnparseC.term t = "1 + (1 + (1 + 0))" then () walther@60121: else error "Length [1, 1, 1] = 1 + (1 + (1 + 0)) ..changed"; neuper@42185: walther@60121: val t = str2term "Length [1, 1, 1]"; walther@59801: val SOME (t, asm) = rewrite_set_ thy false prog_expr t; walther@59868: if UnparseC.term t = "3" then () walther@60121: else error "Length [1, 1, 1] = 3 ..prog_expr changed"; neuper@42185: walther@60121: val t = str2term "Length [1, 1, 1]"; walther@59801: val t = eval_prog_expr thy prog_expr t; neuper@52148: case t of Free ("3", _) => () walther@60121: | _ => error "Length [1, 1, 1] = 3 ..eval_prog_expr changed"; neuper@42185: